1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-11 19:29:20 +08:00
hybridgroup.gobot/platforms/leap/leap_motion_adaptor.go
2014-07-07 17:19:31 -07:00

40 lines
790 B
Go

package leap
import (
"code.google.com/p/go.net/websocket"
"fmt"
"github.com/hybridgroup/gobot"
)
type LeapMotionAdaptor struct {
gobot.Adaptor
ws *websocket.Conn
connect func(*LeapMotionAdaptor)
}
func NewLeapMotionAdaptor(name string, port string) *LeapMotionAdaptor {
return &LeapMotionAdaptor{
Adaptor: *gobot.NewAdaptor(
name,
"LeapMotionAdaptor",
port,
),
connect: func(l *LeapMotionAdaptor) {
origin := fmt.Sprintf("http://%v", l.Port)
url := fmt.Sprintf("ws://%v/v3.json", l.Port)
ws, err := websocket.Dial(url, "", origin)
if err != nil {
panic(err)
}
l.ws = ws
},
}
}
func (l *LeapMotionAdaptor) Connect() bool {
l.connect(l)
l.SetConnected(true)
return true
}
func (l *LeapMotionAdaptor) Finalize() bool { return true }