Update raspi package for new i2c interface
This commit is contained in:
parent
0541eee697
commit
fbc79e1a8f
|
@ -20,7 +20,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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -225,18 +225,20 @@ func (r *RaspiAdaptor) PwmWrite(pin string, val byte) (err error) {
|
|||
}
|
||||
|
||||
// I2cStart starts a i2c device in specified address
|
||||
func (r *RaspiAdaptor) I2cStart(address byte) {
|
||||
r.i2cDevice, _ = sysfs.NewI2cDevice(r.i2cLocation, address)
|
||||
func (r *RaspiAdaptor) I2cStart(address byte) (err error) {
|
||||
r.i2cDevice, err = sysfs.NewI2cDevice(r.i2cLocation, address)
|
||||
return err
|
||||
}
|
||||
|
||||
// I2CWrite writes data to i2c device
|
||||
func (r *RaspiAdaptor) I2cWrite(data []byte) {
|
||||
r.i2cDevice.Write(data)
|
||||
func (r *RaspiAdaptor) I2cWrite(data []byte) (err error) {
|
||||
_, err = r.i2cDevice.Write(data)
|
||||
return
|
||||
}
|
||||
|
||||
// I2cRead returns value from i2c device using specified size
|
||||
func (r *RaspiAdaptor) I2cRead(size uint) []byte {
|
||||
buf := make([]byte, size)
|
||||
r.i2cDevice.Read(buf)
|
||||
return buf
|
||||
func (r *RaspiAdaptor) I2cRead(size uint) (data []byte, err error) {
|
||||
data = make([]byte, size)
|
||||
_, err = r.i2cDevice.Read(data)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -54,5 +54,6 @@ func TestRaspiAdaptorI2c(t *testing.T) {
|
|||
a.I2cStart(0xff)
|
||||
|
||||
a.I2cWrite([]byte{0x00, 0x01})
|
||||
gobot.Assert(t, a.I2cRead(2), []byte{0x00, 0x01})
|
||||
data, _ := a.I2cRead(2)
|
||||
gobot.Assert(t, data, []byte{0x00, 0x01})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue