2013-11-24 02:36:08 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-12-03 16:48:20 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-23 12:20:16 +08:00
|
|
|
"github.com/hybridgroup/gobot/api"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
2013-11-24 02:36:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-07-09 09:36:14 +08:00
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
api.NewAPI(gbot).Start()
|
2013-11-25 06:56:13 +08:00
|
|
|
|
|
|
|
spheros := map[string]string{
|
2013-12-31 05:56:16 +08:00
|
|
|
"Sphero-BPO": "/dev/rfcomm0",
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, port := range spheros {
|
2016-10-03 22:58:43 +08:00
|
|
|
spheroAdaptor := sphero.NewAdaptor(port)
|
|
|
|
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
|
2013-11-25 06:56:13 +08:00
|
|
|
|
|
|
|
work := func() {
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0))
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot(name,
|
|
|
|
[]gobot.Connection{spheroAdaptor},
|
|
|
|
[]gobot.Device{spheroDriver},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
robot.AddCommand("turn_blue", func(params map[string]interface{}) interface{} {
|
2014-06-12 09:59:30 +08:00
|
|
|
spheroDriver.SetRGB(uint8(0), uint8(0), uint8(255))
|
|
|
|
return nil
|
|
|
|
})
|
2014-05-23 12:20:16 +08:00
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
gbot.AddRobot(robot)
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
gbot.Start()
|
2013-11-24 02:36:08 +08:00
|
|
|
}
|