1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-01 13:48:57 +08:00

dragonboard: fix example and documentation (#977)

This commit is contained in:
Thomas Kohler 2023-07-07 11:35:24 +02:00 committed by GitHub
parent 11e15983ac
commit beaefb764b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 76 deletions

View File

@ -11,11 +11,11 @@ import (
"gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/chip" "gobot.io/x/gobot/v2/platforms/dragonboard"
) )
func main() { func main() {
dragonAdaptor := chip.NewAdaptor() dragonAdaptor := dragonboard.NewAdaptor()
button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A") button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A")
work := func() { work := func() {

View File

@ -40,43 +40,8 @@ Reboot the device to make sure the init script loads the overlay on boot.
## How to Use ## How to Use
Please refer to one example for your platform, e.g. [chip_button.go](https://github.com/hybridgroup/gobot/blob/release/examples/chip_button.go).
The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself. The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
```go
package main
import (
"fmt"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/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()
}
```
If you want to use the C.H.I.P. Pro, use the `NewProAdaptor()` function like this: If you want to use the C.H.I.P. Pro, use the `NewProAdaptor()` function like this:
```go ```go

View File

@ -16,43 +16,9 @@ transfer the final executable to your DragonBoard and run the program on the Dra
## How to Use ## How to Use
Please refer to one example for your platform, e.g. [dragonboard_button.go](https://github.com/hybridgroup/gobot/blob/release/examples/dragonboard_button.go).
The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself. See [here](https://www.96boards.org/db410c-getting-started/HardwareDocs/HWUserManual.md/). The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself. See [here](https://www.96boards.org/db410c-getting-started/HardwareDocs/HWUserManual.md/).
```go
package main
import (
"fmt"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/dragonboard"
)
func main() {
dragonAdaptor := dragonboard.NewAdaptor()
button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A")
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()
}
```
## How to Connect ## How to Connect
### Compiling ### Compiling
@ -60,13 +26,13 @@ func main() {
Compile your Gobot program on your workstation like this: Compile your Gobot program on your workstation like this:
```sh ```sh
GOARCH=arm64 GOOS=linux go build examples/dragon_button.go GOARCH=arm64 GOOS=linux go build examples/dragonboard_button.go
``` ```
Once you have compiled your code, you can you can upload your program and execute it on the DragonBoard from your workstation Once you have compiled your code, you can you can upload your program and execute it on the DragonBoard from your workstation
using the `scp` and `ssh` commands like this: using the `scp` and `ssh` commands like this:
```sh ```sh
scp dragon_button root@192.168.1.xx: scp dragonboard_button root@192.168.1.xx:
ssh -t root@192.168.1.xx "./dragon_button" ssh -t root@192.168.1.xx "./dragonboard_button"
``` ```