forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
leap_motion_driver.go
49 lines (41 loc) · 967 Bytes
/
leap_motion_driver.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
package leap
import (
"encoding/json"
"code.google.com/p/go.net/websocket"
"github.com/edmontongo/gobot"
)
type LeapMotionDriver struct {
gobot.Driver
}
func NewLeapMotionDriver(a *LeapMotionAdaptor, name string) *LeapMotionDriver {
l := &LeapMotionDriver{
Driver: *gobot.NewDriver(
name,
"LeapMotionDriver",
a,
),
}
l.AddEvent("message")
return l
}
func (l *LeapMotionDriver) adaptor() *LeapMotionAdaptor {
return l.Adaptor().(*LeapMotionAdaptor)
}
func (l *LeapMotionDriver) Start() bool {
enableGestures := map[string]bool{"enableGestures": true}
b, _ := json.Marshal(enableGestures)
_, err := l.adaptor().ws.Write(b)
if err != nil {
panic(err)
}
go func() {
for {
var msg []byte
websocket.Message.Receive(l.adaptor().ws, &msg)
gobot.Publish(l.Event("message"), l.ParseFrame(msg))
}
}()
return true
}
func (l *LeapMotionDriver) Init() bool { return true }
func (l *LeapMotionDriver) Halt() bool { return true }