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

35 lines
688 B
Go
Raw Normal View History

2014-04-27 17:43:15 -07:00
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() *LeapMotionAdaptor {
return &LeapMotionAdaptor{
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.Connected = true
return true
}
func (me *LeapMotionAdaptor) Finalize() bool { return true }