forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leap_motion_adaptor.go
43 lines (36 loc) · 1.1 KB
/
leap_motion_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
package leap
import (
"io"
"code.google.com/p/go.net/websocket"
"github.com/hybridgroup/gobot"
)
var _ gobot.Adaptor = (*LeapMotionAdaptor)(nil)
type LeapMotionAdaptor struct {
name string
port string
ws io.ReadWriteCloser
connect func(string) (io.ReadWriteCloser, error)
}
// NewLeapMotionAdaptor creates a new leap motion adaptor using specified name and port
func NewLeapMotionAdaptor(name string, port string) *LeapMotionAdaptor {
return &LeapMotionAdaptor{
name: name,
port: port,
connect: func(port string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+port+"/v3.json", "", "http://"+port)
},
}
}
func (l *LeapMotionAdaptor) Name() string { return l.name }
func (l *LeapMotionAdaptor) Port() string { return l.port }
// Connect returns true if connection to leap motion is established succesfully
func (l *LeapMotionAdaptor) Connect() (errs []error) {
if ws, err := l.connect(l.Port()); err != nil {
return []error{err}
} else {
l.ws = ws
}
return
}
// Finalize ends connection to leap motion
func (l *LeapMotionAdaptor) Finalize() (errs []error) { return }