From b939aeacd37bb36444262938378736820f399062 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Mon, 31 Oct 2016 08:43:53 -0700 Subject: [PATCH] fix Celcius, fixes #34 (#35) * fix Celcius, fixes #34 * remove stale Celsius todo --- devices/bme280/bme280.go | 2 +- devices/devices.go | 14 ++++++-------- devices/devices_test.go | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/devices/bme280/bme280.go b/devices/bme280/bme280.go index dba8907..830a227 100644 --- a/devices/bme280/bme280.go +++ b/devices/bme280/bme280.go @@ -94,7 +94,7 @@ func (d *Dev) Sense(env *devices.Environment) error { hRaw := int32(buf[6])<<8 | int32(buf[7]) t, tFine := d.c.compensateTempInt(tRaw) - env.Temperature = devices.Celcius(t * 10) + env.Temperature = devices.Celsius(t * 10) p := d.c.compensatePressureInt64(pRaw, tFine) env.Pressure = devices.KPascal((int32(p) + 127) / 256) diff --git a/devices/devices.go b/devices/devices.go index ad00b34..7a61e36 100644 --- a/devices/devices.go +++ b/devices/devices.go @@ -51,25 +51,23 @@ func (m Milli) String() string { return fmt.Sprintf("%d.%03d", m/1000, m%1000) } -// Celcius is a temperature at a precision of 0.001°C. +// Celsius is a temperature at a precision of 0.001°C. // // Expected range is [-273150, >1000000] -// -// BUG(maruel): Add function to convert to Fahrenheit for my American friends. -type Celcius Milli +type Celsius Milli // Float64 returns the value as float64 with 0.001 precision. -func (c Celcius) Float64() float64 { +func (c Celsius) Float64() float64 { return Milli(c).Float64() } // String returns the temperature formatted as a string. -func (c Celcius) String() string { +func (c Celsius) String() string { return Milli(c).String() + "°C" } // ToF returns the temperature as Fahrenheit, a unit used in the United States. -func (c Celcius) ToF() Fahrenheit { +func (c Celsius) ToF() Fahrenheit { return Fahrenheit((c*9+2)/5 + 32000) } @@ -116,7 +114,7 @@ func (r RelativeHumidity) String() string { // Environment represents measurements from an environmental sensor. type Environment struct { - Temperature Celcius + Temperature Celsius Pressure KPascal Humidity RelativeHumidity } diff --git a/devices/devices_test.go b/devices/devices_test.go index b81d228..b60cbf5 100644 --- a/devices/devices_test.go +++ b/devices/devices_test.go @@ -16,8 +16,8 @@ func TestMilli(t *testing.T) { } } -func TestCelcius(t *testing.T) { - o := Celcius(10010) +func TestCelsius(t *testing.T) { + o := Celsius(10010) if s := o.String(); s != "10.010°C" { t.Fatalf("%#v", s) }