2014-05-03 06:22:05 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-05-24 06:09:18 +08:00
|
|
|
"fmt"
|
2014-07-11 08:21:21 +08:00
|
|
|
|
2014-05-24 06:09:18 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/api"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/pebble"
|
2014-05-03 06:22:05 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2014-08-01 02:56:50 +08:00
|
|
|
api := api.NewAPI(gbot)
|
|
|
|
api.Port = "8080"
|
|
|
|
api.Start()
|
2014-05-03 06:22:05 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
pebbleAdaptor := pebble.NewAdaptor()
|
|
|
|
pebbleDriver := pebble.NewDriver(pebbleAdaptor)
|
2014-05-03 06:22:05 +08:00
|
|
|
|
2014-05-24 06:09:18 +08:00
|
|
|
work := func() {
|
|
|
|
pebbleDriver.SendNotification("Hello Pebble!")
|
2016-08-30 23:53:29 +08:00
|
|
|
pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) {
|
2014-05-24 06:09:18 +08:00
|
|
|
fmt.Println("Button pushed: " + data.(string))
|
|
|
|
})
|
2014-05-03 06:22:05 +08:00
|
|
|
|
2016-08-30 23:53:29 +08:00
|
|
|
pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) {
|
2014-05-24 06:09:18 +08:00
|
|
|
fmt.Println("Tap event detected")
|
|
|
|
})
|
|
|
|
}
|
2014-05-03 06:22:05 +08:00
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot("pebble",
|
|
|
|
[]gobot.Connection{pebbleAdaptor},
|
|
|
|
[]gobot.Device{pebbleDriver},
|
|
|
|
work,
|
|
|
|
)
|
2014-05-03 06:22:05 +08:00
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
gbot.AddRobot(robot)
|
2014-07-11 08:21:21 +08:00
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
gbot.Start()
|
2014-05-03 06:22:05 +08:00
|
|
|
}
|