gobot icon indicating copy to clipboard operation
gobot copied to clipboard

platforms/chip: quickstart sample/doc broken

Open ahmetb opened this issue 7 years ago • 2 comments
trafficstars

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

ahmetb avatar Sep 24 '18 20:09 ahmetb

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.

ahmetb avatar Sep 24 '18 20:09 ahmetb

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.

deadprogram avatar Sep 29 '18 17:09 deadprogram

Also there is a mismatch in dragonboard docu and example. I will fix this together.

gen2thomas avatar Jul 07 '23 09:07 gen2thomas

available since v2.2.0

gen2thomas avatar Oct 30 '23 17:10 gen2thomas