diff --git a/devices/bmxx80/bmp180_test.go b/devices/bmxx80/bmp180_test.go index 9b86b95..9a23e6b 100644 --- a/devices/bmxx80/bmp180_test.go +++ b/devices/bmxx80/bmp180_test.go @@ -332,6 +332,39 @@ func TestSenseContinuous180_success(t *testing.T) { } } +func TestBmp180Precision(t *testing.T) { + bus := i2ctest.Playback{ + Ops: []i2ctest.IO{ + // Chip ID detection. + {Addr: 0x77, W: []byte{0xd0}, R: []byte{0x55}}, + // Calibration data. + { + Addr: 0x77, + W: []byte{0xaa}, + R: []byte{35, 136, 251, 103, 199, 169, 135, 91, 98, 137, 80, 22, 25, 115, 0, 46, 128, 0, 209, 246, 10, 123}, + }, + }, + } + dev, err := NewI2C(&bus, 0x77, &DefaultOpts) + if err != nil { + t.Fatal(err) + } + e := physic.Env{} + dev.Precision(&e) + if e.Temperature != 100*physic.MilliKelvin { + t.Fatal(e.Temperature) + } + if e.Pressure != physic.Pascal { + t.Fatal(e.Pressure) + } + if e.Humidity != 0 { + t.Fatal(e.Humidity) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + /* func TestOversampling(t *testing.T) { data := []struct { diff --git a/devices/bmxx80/bmx280_test.go b/devices/bmxx80/bmx280_test.go index 34b3170..b7ca131 100644 --- a/devices/bmxx80/bmx280_test.go +++ b/devices/bmxx80/bmx280_test.go @@ -734,6 +734,43 @@ func TestCalibration280_limits_419430400(t *testing.T) { // TODO(maruel): Reverse the equation to overflow 419430400 } +func TestBme280Precision(t *testing.T) { + bus := i2ctest.Playback{ + Ops: []i2ctest.IO{ + // Chip ID detection. + {Addr: 0x76, W: []byte{0xd0}, R: []byte{0x60}}, + // Calibration data. + { + Addr: 0x76, + W: []byte{0x88}, + R: []byte{0x10, 0x6e, 0x6c, 0x66, 0x32, 0x0, 0x5d, 0x95, 0xb8, 0xd5, 0xd0, 0xb, 0x77, 0x1e, 0x9d, 0xff, 0xf9, 0xff, 0xac, 0x26, 0xa, 0xd8, 0xbd, 0x10, 0x0, 0x4b}, + }, + // Calibration data humidity. + {Addr: 0x76, W: []byte{0xe1}, R: []byte{0x6e, 0x1, 0x0, 0x13, 0x5, 0x0, 0x1e}}, + // Configuration. + {Addr: 0x76, W: []byte{0xf4, 0x6c, 0xf2, 0x3, 0xf5, 0xa0, 0xf4, 0x6c}, R: nil}, + }, + } + dev, err := NewI2C(&bus, 0x76, &DefaultOpts) + if err != nil { + t.Fatal(err) + } + e := physic.Env{} + dev.Precision(&e) + if e.Temperature != 10*physic.MilliKelvin { + t.Fatal(e.Temperature) + } + if e.Pressure != 15625*physic.MicroPascal/4 { + t.Fatal(e.Pressure) + } + if e.Humidity != physic.MicroRH*1000/1024 { + t.Fatal(int(e.Humidity)) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + // func TestOversampling(t *testing.T) { diff --git a/devices/bmxx80/bmxx80.go b/devices/bmxx80/bmxx80.go index f22f30b..eaf1031 100644 --- a/devices/bmxx80/bmxx80.go +++ b/devices/bmxx80/bmxx80.go @@ -8,6 +8,7 @@ // BMx280 // // https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf +// https://www.mouser.com/datasheet/2/783/BST-BME280_DS001-11-844833.pdf // // https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001-18.pdf // @@ -320,6 +321,21 @@ func (d *Dev) SenseContinuous(interval time.Duration) (<-chan physic.Env, error) return sensing, nil } +// Precision implements physic.SenseEnv. +func (d *Dev) Precision(e *physic.Env) { + if d.is280 { + e.Temperature = 10 * physic.MilliKelvin + e.Pressure = 15625 * physic.MicroPascal / 4 + } else { + e.Temperature = 100 * physic.MilliKelvin + e.Pressure = physic.Pascal + } + + if d.isBME { + e.Humidity = physic.MicroRH * 1000 / 1024 + } +} + // Halt stops the BMxx80 from acquiring measurements as initiated by // SenseContinuous(). //