docs: Add missing godocs for Leap Motion platform

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-12-01 11:28:22 +01:00
parent eda472890f
commit e8b28a0df1
3 changed files with 32 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import (
"golang.org/x/net/websocket"
)
// Adaptor is the Gobot Adaptor connection to the Leap Motion
type Adaptor struct {
name string
port string
@ -13,27 +14,35 @@ type Adaptor struct {
connect func(string) (io.ReadWriteCloser, error)
}
// NewAdaptor creates a new leap motion adaptor using specified port
// NewAdaptor creates a new leap motion adaptor using specified port,
// which is this case is the host IP or name of the Leap Motion daemon
func NewAdaptor(port string) *Adaptor {
return &Adaptor{
name: "LeapMotion",
port: port,
connect: func(port string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+port+"/v3.json", "", "http://"+port)
connect: func(host string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+host+"/v3.json", "", "http://"+host)
},
}
}
func (l *Adaptor) Name() string { return l.name }
// Name returns the Adaptor Name
func (l *Adaptor) Name() string { return l.name }
// SetName sets the Adaptor Name
func (l *Adaptor) SetName(n string) { l.name = n }
func (l *Adaptor) Port() string { return l.port }
// Port returns the Adaptor Port which is this case is the host IP or name
func (l *Adaptor) Port() string { return l.port }
// 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 {
ws, e := l.connect(l.Port())
if e != nil {
return e
} else {
l.ws = ws
}
l.ws = ws
return
}

View File

@ -17,6 +17,7 @@ const (
GestureEvent = "gesture"
)
// Driver the Gobot software device to the Leap Motion
type Driver struct {
name string
connection gobot.Connection
@ -27,7 +28,7 @@ var receive = func(ws io.ReadWriteCloser, msg *[]byte) {
websocket.Message.Receive(ws.(*websocket.Conn), msg)
}
// NewLDriver creates a new leap motion driver
// NewDriver creates a new leap motion driver
//
// Adds the following events:
// "message" - Gets triggered when receiving a message from leap motion
@ -45,8 +46,14 @@ func NewDriver(a *Adaptor) *Driver {
l.AddEvent(GestureEvent)
return l
}
func (l *Driver) Name() string { return l.name }
func (l *Driver) SetName(n string) { l.name = n }
// Name returns the Driver Name
func (l *Driver) Name() string { return l.name }
// SetName sets the Driver Name
func (l *Driver) SetName(n string) { l.name = n }
// Connection returns the Driver's Connection
func (l *Driver) Connection() gobot.Connection { return l.connection }
// adaptor returns leap motion adaptor

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
)
// Gesture is a Leap Motion gesture tht has been detected
type Gesture struct {
Direction []float64 `json:"direction"`
Duration int `json:"duration"`
@ -17,6 +18,7 @@ type Gesture struct {
Type string `json:"type"`
}
// Hand is a Leap Motion hand tht has been detected
type Hand struct {
Direction []float64 `json:"direction"`
ID int `json:"id"`
@ -32,6 +34,7 @@ type Hand struct {
TimeVisible float64 `json:"TimeVisible"`
}
// Pointable is a Leap Motion pointing motion tht has been detected
type Pointable struct {
Direction []float64 `json:"direction"`
HandID int `json:"handId"`
@ -46,12 +49,13 @@ type Pointable struct {
TouchZone string `json:"touchZone"`
}
// InteractionBox is the area within which the gestural interaction has been detected
type InteractionBox struct {
Center []int `json:"center"`
Size []float64 `json:"size"`
}
// Base representation returned that holds every other objects
// Frame is the base representation returned that holds every other objects
type Frame struct {
CurrentFrameRate float64 `json:"currentFrameRate"`
Gestures []Gesture `json:"gestures"`