diff --git a/examples/firmata_blinkm.go b/examples/firmata_blinkm.go index 0b778634..83b3530b 100644 --- a/examples/firmata_blinkm.go +++ b/examples/firmata_blinkm.go @@ -21,7 +21,8 @@ func main() { g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) blinkm.Rgb(r, g, b) - fmt.Println("color", blinkm.Color()) + color, _ := blinkm.Color() + fmt.Println("color", color) }) } diff --git a/examples/firmata_hmc6352.go b/examples/firmata_hmc6352.go index 4972fa10..1846f739 100644 --- a/examples/firmata_hmc6352.go +++ b/examples/firmata_hmc6352.go @@ -17,7 +17,8 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { - fmt.Println("Heading", hmc6352.Heading) + heading, _ := hmc6352.Heading() + fmt.Println("Heading", heading) }) } diff --git a/platforms/firmata/firmata_adaptor.go b/platforms/firmata/firmata_adaptor.go index efe0fbab..7156a228 100644 --- a/platforms/firmata/firmata_adaptor.go +++ b/platforms/firmata/firmata_adaptor.go @@ -212,18 +212,22 @@ func (f *FirmataAdaptor) digitalPin(pin int) int { } // I2cStart initializes board with i2c configuration -func (f *FirmataAdaptor) I2cStart(address byte) { +func (f *FirmataAdaptor) I2cStart(address byte) (err error) { f.i2cAddress = address - f.board.i2cConfig([]byte{0}) + return f.board.i2cConfig([]byte{0}) } // I2cRead reads from I2c specified size // Returns empty byte array if response is timed out -func (f *FirmataAdaptor) I2cRead(size uint) []byte { +func (f *FirmataAdaptor) I2cRead(size uint) (data []byte, err error) { ret := make(chan []byte) - f.board.i2cReadRequest(f.i2cAddress, size) + if err = f.board.i2cReadRequest(f.i2cAddress, size); err != nil { + return + } - f.board.readAndProcess() + if err = f.board.readAndProcess(); err != nil { + return + } gobot.Once(f.board.events["i2c_reply"], func(data interface{}) { ret <- data.(map[string][]byte)["data"] @@ -231,13 +235,13 @@ func (f *FirmataAdaptor) I2cRead(size uint) []byte { select { case data := <-ret: - return data + return data, nil case <-time.After(10 * time.Millisecond): } - return []byte{} + return []byte{}, nil } // I2cWrite retrieves i2c data -func (f *FirmataAdaptor) I2cWrite(data []byte) { - f.board.i2cWriteRequest(f.i2cAddress, data) +func (f *FirmataAdaptor) I2cWrite(data []byte) (err error) { + return f.board.i2cWriteRequest(f.i2cAddress, data) } diff --git a/platforms/firmata/firmata_adaptor_test.go b/platforms/firmata/firmata_adaptor_test.go index ca280bd4..4ce5eefb 100644 --- a/platforms/firmata/firmata_adaptor_test.go +++ b/platforms/firmata/firmata_adaptor_test.go @@ -114,7 +114,8 @@ func TestFirmataAdaptorI2cStart(t *testing.T) { func TestFirmataAdaptorI2cRead(t *testing.T) { a := initTestFirmataAdaptor() // [] on no data - gobot.Assert(t, a.I2cRead(1), []byte{}) + data, _ := a.I2cRead(1) + gobot.Assert(t, data, []byte{}) i := []byte{100} i2cReply := map[string][]byte{} @@ -123,7 +124,8 @@ func TestFirmataAdaptorI2cRead(t *testing.T) { <-time.After(5 * time.Millisecond) gobot.Publish(a.board.events["i2c_reply"], i2cReply) }() - gobot.Assert(t, a.I2cRead(1), i) + data, _ = a.I2cRead(1) + gobot.Assert(t, data, i) } func TestFirmataAdaptorI2cWrite(t *testing.T) { a := initTestFirmataAdaptor()