2016-07-04 23:00:36 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2016-07-05 02:10:30 +08:00
|
|
|
"fmt"
|
2016-07-04 23:00:36 +08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
|
|
|
bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1])
|
|
|
|
drone := ble.NewBLEMinidroneDriver(bleAdaptor, "drone")
|
|
|
|
|
|
|
|
work := func() {
|
2016-07-05 01:46:42 +08:00
|
|
|
drone.Init()
|
2016-07-05 02:10:30 +08:00
|
|
|
|
|
|
|
gobot.On(drone.Event("battery"), func(data interface{}) {
|
|
|
|
fmt.Printf("battery: %d", data)
|
|
|
|
})
|
|
|
|
|
|
|
|
gobot.On(drone.Event("status"), func(data interface{}) {
|
|
|
|
fmt.Printf("status: %d", data)
|
|
|
|
})
|
2016-07-04 23:00:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{drone},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|