2015-06-08 10:31:00 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-07-03 16:51:20 +08:00
|
|
|
"os"
|
2016-09-01 19:32:40 +08:00
|
|
|
"time"
|
2016-07-10 01:52:48 +08:00
|
|
|
|
2015-06-08 10:31:00 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
battery := ble.NewBatteryDriver(bleAdaptor)
|
2015-06-08 10:31:00 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2015-06-08 10:31:00 +08:00
|
|
|
}
|