forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minidrone.go
53 lines (41 loc) · 1003 Bytes
/
minidrone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"os"
"fmt"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/ble"
)
func main() {
gbot := gobot.NewGobot()
bleAdaptor := ble.NewBLEClientAdaptor("ble", os.Args[1])
drone := ble.NewBLEMinidroneDriver(bleAdaptor, "drone")
work := func() {
gobot.On(drone.Event("battery"), func(data interface{}) {
fmt.Printf("battery: %d\n", data)
})
gobot.On(drone.Event("status"), func(data interface{}) {
fmt.Printf("status: %d\n", data)
})
gobot.On(drone.Event("flying"), func(data interface{}) {
fmt.Println("flying!")
gobot.After(5*time.Second, func() {
fmt.Println("landing...")
drone.Land()
drone.Land()
})
})
gobot.On(drone.Event("landed"), func(data interface{}) {
fmt.Println("landed.")
})
<-time.After(1000 * time.Millisecond)
drone.TakeOff()
}
robot := gobot.NewRobot("bleBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{drone},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}