hybridgroup.gobot/examples/pebble.go

45 lines
827 B
Go
Raw Normal View History

// +build example
//
// Do not build by default.
2014-05-03 06:22:05 +08:00
package main
import (
"fmt"
2014-07-11 08:21:21 +08:00
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/pebble"
2014-05-03 06:22:05 +08:00
)
func main() {
master := gobot.NewMaster()
api := api.NewAPI(master)
2014-08-01 02:56:50 +08:00
api.Port = "8080"
api.Start()
2014-05-03 06:22:05 +08:00
pebbleAdaptor := pebble.NewAdaptor()
pebbleDriver := pebble.NewDriver(pebbleAdaptor)
2014-05-03 06:22:05 +08:00
work := func() {
pebbleDriver.SendNotification("Hello Pebble!")
pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) {
fmt.Println("Button pushed: " + data.(string))
})
2014-05-03 06:22:05 +08:00
pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) {
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
master.AddRobot(robot)
2014-07-11 08:21:21 +08:00
master.Start()
2014-05-03 06:22:05 +08:00
}