hybridgroup.gobot/examples/pebble.go

41 lines
805 B
Go
Raw Normal View History

2014-05-03 06:22:05 +08:00
package main
import (
"fmt"
2014-07-11 08:21:21 +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() {
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
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
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
}