mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-02 22:17:12 +08:00
35 lines
688 B
Go
35 lines
688 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() *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 }
|