1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/chip_wiichuck.go
Hrishikesh Tapaswi 42475e479d Get I2C functionality before doing SMBus block I/O
In the sysfs i2cDevice implementation, use an ioctl to get the adapter
functionality mask. Prefer SMBus block I/O but if it's not available,
perform read/write calls directly on the file descriptor.

Improve Wiichuck error handling. Add a 1 ms delay between I/O operations
to the Wiichuck; this dramatically improves reliability.

Signed-off-by: Hrishikesh Tapaswi <hrishikesh195@yahoo.com>
2016-02-17 12:25:15 -08:00

44 lines
849 B
Go

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/i2c"
)
func main() {
gbot := gobot.NewGobot()
chipAdaptor := chip.NewChipAdaptor("chip")
wiichuck := i2c.NewWiichuckDriver(chipAdaptor, "wiichuck")
work := func() {
gobot.On(wiichuck.Event("joystick"), func(data interface{}) {
fmt.Println("joystick", data)
})
gobot.On(wiichuck.Event("c"), func(data interface{}) {
fmt.Println("c")
})
gobot.On(wiichuck.Event("z"), func(data interface{}) {
fmt.Println("z")
})
gobot.On(wiichuck.Event("error"), func(data interface{}) {
fmt.Println("Wiichuck error:", data)
})
}
robot := gobot.NewRobot("chuck",
[]gobot.Connection{chipAdaptor},
[]gobot.Device{wiichuck},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}