i2c: add test coverage for bme280
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
e14bfb726f
commit
3d7bf12156
|
@ -1,6 +1,7 @@
|
|||
package i2c
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
|
@ -47,9 +48,29 @@ func TestBME280DriverHalt(t *testing.T) {
|
|||
gobottest.Assert(t, bme280.Halt(), nil)
|
||||
}
|
||||
|
||||
// TODO: implement test
|
||||
func TestBME280DriverMeasurements(t *testing.T) {
|
||||
|
||||
bme280, adaptor := initTestBME280DriverWithStubbedAdaptor()
|
||||
adaptor.i2cReadImpl = func(b []byte) (int, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
// Values produced by dumping data from actual sensor
|
||||
if adaptor.written[len(adaptor.written)-1] == bmp280RegisterCalib00 {
|
||||
buf.Write([]byte{126, 109, 214, 102, 50, 0, 54, 149, 220, 213, 208, 11, 64, 30, 166, 255, 249, 255, 172, 38, 10, 216, 189, 16})
|
||||
} else if adaptor.written[len(adaptor.written)-1] == bme280RegisterCalibDigH1 {
|
||||
buf.Write([]byte{75})
|
||||
} else if adaptor.written[len(adaptor.written)-1] == bmp280RegisterTempData {
|
||||
buf.Write([]byte{129, 0, 0})
|
||||
} else if adaptor.written[len(adaptor.written)-1] == bme280RegisterCalibDigH2LSB {
|
||||
buf.Write([]byte{112, 1, 0, 19, 1, 0, 30})
|
||||
} else if adaptor.written[len(adaptor.written)-1] == bme280RegisterHumidityMSB {
|
||||
buf.Write([]byte{111, 83})
|
||||
}
|
||||
copy(b, buf.Bytes())
|
||||
return buf.Len(), nil
|
||||
}
|
||||
bme280.Start()
|
||||
hum, err := bme280.Humidity()
|
||||
gobottest.Assert(t, err, nil)
|
||||
gobottest.Assert(t, hum, float32(51.20179))
|
||||
}
|
||||
|
||||
func TestBME280DriverSetName(t *testing.T) {
|
||||
|
|
|
@ -140,8 +140,6 @@ func (d *BMP280Driver) Altitude() (alt float32, err error) {
|
|||
|
||||
// initialization reads the calibration coefficients.
|
||||
func (d *BMP280Driver) initialization() (err error) {
|
||||
// TODO: set sleep mode here...
|
||||
|
||||
var coefficients []byte
|
||||
if coefficients, err = d.read(bmp280RegisterCalib00, 24); err != nil {
|
||||
return err
|
||||
|
@ -162,9 +160,6 @@ func (d *BMP280Driver) initialization() (err error) {
|
|||
|
||||
d.connection.WriteByteData(bmp280RegisterControl, 0x3F)
|
||||
|
||||
// TODO: set usage mode here...
|
||||
// TODO: set default sea level here
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ func TestBMP280DriverHalt(t *testing.T) {
|
|||
gobottest.Assert(t, bmp280.Halt(), nil)
|
||||
}
|
||||
|
||||
// TODO: implement test
|
||||
func TestBMP280DriverMeasurements(t *testing.T) {
|
||||
bmp280, adaptor := initTestBMP280DriverWithStubbedAdaptor()
|
||||
adaptor.i2cReadImpl = func(b []byte) (int, error) {
|
||||
|
|
Loading…
Reference in New Issue