From 1916ab3024edf1af9d33d368292c63dd859eef54 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 ++-- host/sysfs/thermal_sensor.go | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/devices/bme280/bme280.go b/devices/bme280/bme280.go index dba8907bd..830a227f1 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 ad00b343c..7a61e36bf 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 b81d228f3..b60cbf507 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) } diff --git a/host/sysfs/thermal_sensor.go b/host/sysfs/thermal_sensor.go index 194a83d56..84e43c88e 100644 --- a/host/sysfs/thermal_sensor.go +++ b/host/sysfs/thermal_sensor.go @@ -97,7 +97,7 @@ func (t *ThermalSensor) Sense(env *devices.Environment) error { if i < 100 { i *= 1000 } - env.Temperature = devices.Celcius(i) + env.Temperature = devices.Celsius(i) return nil }