fix Celcius, fixes #34 (#35)

* fix Celcius, fixes #34

* remove stale Celsius todo
pull/1/head
Thorsten von Eicken 10 years ago committed by M-A
parent ae8f618573
commit b939aeacd3

@ -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)

@ -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
}

@ -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)
}

Loading…
Cancel
Save