i2c: return error correctly, increase test coverage for l3gd20h
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
4ceba24991
commit
287ec68086
|
@ -133,7 +133,7 @@ func (d *L3GD20HDriver) Halt() (err error) {
|
||||||
// XYZ returns the current change in degrees per second, for the 3 axis.
|
// XYZ returns the current change in degrees per second, for the 3 axis.
|
||||||
func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) {
|
func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) {
|
||||||
if _, err = d.connection.Write([]byte{l3gd20hRegisterOutXLSB}); err != nil {
|
if _, err = d.connection.Write([]byte{l3gd20hRegisterOutXLSB}); err != nil {
|
||||||
return 0, 0, 0, nil
|
return 0, 0, 0, err
|
||||||
}
|
}
|
||||||
measurements := make([]byte, 6)
|
measurements := make([]byte, 6)
|
||||||
if _, err = d.connection.Read(measurements); err != nil {
|
if _, err = d.connection.Read(measurements); err != nil {
|
||||||
|
|
|
@ -102,6 +102,17 @@ func TestL3GD20HDriverMeasurementError(t *testing.T) {
|
||||||
gobottest.Assert(t, err, errors.New("read error"))
|
gobottest.Assert(t, err, errors.New("read error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestL3GD20HDriverMeasurementWriteError(t *testing.T) {
|
||||||
|
d, adaptor := initTestL3GD20HDriverWithStubbedAdaptor()
|
||||||
|
d.Start()
|
||||||
|
adaptor.i2cWriteImpl = func(b []byte) (int, error) {
|
||||||
|
return 0, errors.New("write error")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, _, err := d.XYZ()
|
||||||
|
gobottest.Assert(t, err, errors.New("write error"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestL3GD20HDriverSetName(t *testing.T) {
|
func TestL3GD20HDriverSetName(t *testing.T) {
|
||||||
d := initTestL3GD20HDriver()
|
d := initTestL3GD20HDriver()
|
||||||
d.SetName("TESTME")
|
d.SetName("TESTME")
|
||||||
|
|
Loading…
Reference in New Issue