1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-08 19:29:16 +08:00
hybridgroup.gobot/platforms/leap/leap_motion_adaptor.go
deadprogram 6097ffefc5 tests: complete move of test interfaces into the test files where they belong
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-08-27 11:56:01 +02:00

41 lines
1.0 KiB
Go

package leap
import (
"io"
"golang.org/x/net/websocket"
)
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 successfully
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 }