2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2014-05-02 17:22:05 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-05-23 17:09:18 -05:00
|
|
|
"fmt"
|
2014-07-10 17:21:21 -07:00
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/api"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/pebble"
|
2014-05-02 17:22:05 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-13 16:30:25 +01:00
|
|
|
manager := gobot.NewManager()
|
|
|
|
api := api.NewAPI(manager)
|
2014-07-31 13:56:50 -05:00
|
|
|
api.Port = "8080"
|
|
|
|
api.Start()
|
2014-05-02 17:22:05 -05:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
pebbleAdaptor := pebble.NewAdaptor()
|
|
|
|
pebbleDriver := pebble.NewDriver(pebbleAdaptor)
|
2014-05-02 17:22:05 -05:00
|
|
|
|
2014-05-23 17:09:18 -05:00
|
|
|
work := func() {
|
|
|
|
pebbleDriver.SendNotification("Hello Pebble!")
|
2024-02-11 15:34:50 +01:00
|
|
|
_ = pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) {
|
2014-05-23 17:09:18 -05:00
|
|
|
fmt.Println("Button pushed: " + data.(string))
|
|
|
|
})
|
2014-05-02 17:22:05 -05:00
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
_ = pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) {
|
2014-05-23 17:09:18 -05:00
|
|
|
fmt.Println("Tap event detected")
|
|
|
|
})
|
|
|
|
}
|
2014-05-02 17:22:05 -05:00
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("pebble",
|
|
|
|
[]gobot.Connection{pebbleAdaptor},
|
|
|
|
[]gobot.Device{pebbleDriver},
|
|
|
|
work,
|
|
|
|
)
|
2014-05-02 17:22:05 -05:00
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
manager.AddRobot(robot)
|
2014-07-10 17:21:21 -07:00
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
if err := manager.Start(); err != nil {
|
2024-02-11 15:34:50 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2014-05-02 17:22:05 -05:00
|
|
|
}
|