forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bebop_adaptor.go
63 lines (55 loc) · 1.36 KB
/
bebop_adaptor.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
54
55
56
57
58
59
60
61
62
63
package bebop
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/bebop/client"
)
var _ gobot.Adaptor = (*BebopAdaptor)(nil)
// drone defines expected drone behaviour
type drone interface {
TakeOff() error
Land() error
Up(n int) error
Down(n int) error
Left(n int) error
Right(n int) error
Forward(n int) error
Backward(n int) error
Clockwise(n int) error
CounterClockwise(n int) error
Stop() error
Connect() error
Video() chan []byte
StartRecording() error
StopRecording() error
HullProtection(protect bool) error
Outdoor(outdoor bool) error
}
// BebopAdaptor is gobot.Adaptor representation for the Bebop
type BebopAdaptor struct {
name string
drone drone
//config client.Config
connect func(*BebopAdaptor) error
}
// NewBebopAdaptor returns a new BebopAdaptor
func NewBebopAdaptor(name string) *BebopAdaptor {
return &BebopAdaptor{
name: name,
drone: client.New(),
connect: func(a *BebopAdaptor) error {
return a.drone.Connect()
},
}
}
// Name returns the BebopAdaptors Name
func (a *BebopAdaptor) Name() string { return a.name }
// Connect establishes a connection to the ardrone
func (a *BebopAdaptor) Connect() (errs []error) {
err := a.connect(a)
if err != nil {
return []error{err}
}
return
}
// Finalize terminates the connection to the ardrone
func (a *BebopAdaptor) Finalize() (errs []error) { return }