gobot
gobot copied to clipboard
platforms/chip: quickstart sample/doc broken
I'm following https://gobot.io/documentation/platforms/chip/ on macOS and seeing a compilation error in the sample program:
undefined: gobot.On
Repro steps
I ran go get -d -u gobot.io/x/gobot/... (worked)
Pasted the sample listed to main.go:
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/chip"
)
func main() {
chipAdaptor := chip.NewAdaptor()
button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0")
work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})
gobot.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{chipAdaptor},
[]gobot.Device{button},
work,
)
robot.Start()
}
then I ran GOARM=7 GOARCH=arm GOOS=linux go build . as instructed and this cmd gives error:
./main.go:16:9: undefined: gobot.On
./main.go:20:9: undefined: gobot.On
similarly chip-pro instructions are broken, too https://gobot.io/documentation/platforms/chip-pro/
It seems like gobot.On isn't really a thing anymore. But I can't really find an On method for platforms/chip package to handle button press to refactor/fix the example code.
Hello, @ahmetb the event handling is now attached to each driver, instead of to the main package. You should be able to use the following syntax:
button.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})
There are also now const values for the event names. For example:
button.On(gpio.ButtonRelease, func(data interface{}) {
fmt.Println("button released")
})
Seems like we need to update those docs. Been a while since I used that platform.
Also there is a mismatch in dragonboard docu and example. I will fix this together.
available since v2.2.0