2015-06-08 10:31:00 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-07-03 16:51:20 +08:00
|
|
|
"time"
|
|
|
|
"os"
|
|
|
|
|
2015-06-08 10:31:00 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2016-07-03 16:51:20 +08:00
|
|
|
bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1])
|
2015-06-08 10:31:00 +08:00
|
|
|
battery := ble.NewBLEBatteryDriver(bleAdaptor, "battery")
|
|
|
|
|
|
|
|
work := func() {
|
2016-07-03 16:51:20 +08:00
|
|
|
gobot.Every(5*time.Second, func() {
|
|
|
|
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()
|
|
|
|
}
|