2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2015-06-07 19:31:00 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-07-03 10:51:20 +02:00
|
|
|
"os"
|
2016-09-01 13:32:40 +02:00
|
|
|
"time"
|
2016-07-09 11:52:48 -06:00
|
|
|
|
2016-12-08 13:24:03 +01:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/ble"
|
2015-06-07 19:31:00 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 16:58:43 +02:00
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
battery := ble.NewBatteryDriver(bleAdaptor)
|
2015-06-07 19:31:00 -07:00
|
|
|
|
|
|
|
work := func() {
|
2016-07-03 10:51:20 +02:00
|
|
|
gobot.Every(5*time.Second, func() {
|
|
|
|
fmt.Println("Battery level:", battery.GetBatteryLevel())
|
|
|
|
})
|
2015-06-07 19:31:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{battery},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-18 21:08:25 +02:00
|
|
|
robot.Start()
|
2015-06-07 19:31:00 -07:00
|
|
|
}
|