2015-06-08 10:31:00 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2016-03-03 14:00:05 +08:00
|
|
|
bleAdaptor := ble.NewBLEAdaptor("ble", "D0:39:72:C9:9E:5A")
|
2015-06-08 10:31:00 +08:00
|
|
|
battery := ble.NewBLEBatteryDriver(bleAdaptor, "battery")
|
|
|
|
|
|
|
|
work := func() {
|
2016-03-03 14:00:05 +08:00
|
|
|
fmt.Println("Battery level:", battery.GetBatteryLevel())
|
2015-06-08 10:31:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{battery},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|