1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-04 22:17:39 +08:00
hybridgroup.gobot/platforms/leap/leap_motion_adaptor.go

42 lines
970 B
Go
Raw Normal View History

2014-04-27 17:43:15 -07:00
package leap
import (
2014-11-07 13:15:45 -08:00
"io"
"golang.org/x/net/websocket"
2014-04-27 17:43:15 -07:00
)
type Adaptor struct {
name string
port string
2014-11-07 13:15:45 -08:00
ws io.ReadWriteCloser
2014-12-18 15:13:53 -08:00
connect func(string) (io.ReadWriteCloser, error)
2014-04-27 17:43:15 -07:00
}
// NewAdaptor creates a new leap motion adaptor using specified port
func NewAdaptor(port string) *Adaptor {
return &Adaptor{
name: "LeapMotion",
port: port,
2014-12-18 15:13:53 -08:00
connect: func(port string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+port+"/v3.json", "", "http://"+port)
2014-04-27 17:43:15 -07:00
},
}
}
func (l *Adaptor) Name() string { return l.name }
func (l *Adaptor) SetName(n string) { l.name = n }
func (l *Adaptor) Port() string { return l.port }
2014-04-27 17:43:15 -07:00
2016-07-13 10:44:47 -06:00
// Connect returns true if connection to leap motion is established successfully
func (l *Adaptor) Connect() (err error) {
if ws, e := l.connect(l.Port()); e != nil {
return e
2014-12-18 15:13:53 -08:00
} else {
l.ws = ws
}
return
2014-04-27 17:43:15 -07:00
}
// Finalize ends connection to leap motion
func (l *Adaptor) Finalize() (err error) { return }