Skip to content

Commit

Permalink
fix Celcius, fixes google#34 (google#35)
Browse files Browse the repository at this point in the history
* fix Celcius, fixes google#34

* remove stale Celsius todo
  • Loading branch information
tve authored and maruel committed Oct 31, 2016
1 parent 89c2ef4 commit 1916ab3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion devices/bme280/bme280.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions devices/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions devices/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion host/sysfs/thermal_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1916ab3

Please sign in to comment.