mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
docs: Add missing godocs for Leap Motion platform
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
eda472890f
commit
e8b28a0df1
@ -6,6 +6,7 @@ import (
|
|||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Adaptor is the Gobot Adaptor connection to the Leap Motion
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
name string
|
name string
|
||||||
port string
|
port string
|
||||||
@ -13,27 +14,35 @@ type Adaptor struct {
|
|||||||
connect func(string) (io.ReadWriteCloser, error)
|
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 {
|
func NewAdaptor(port string) *Adaptor {
|
||||||
return &Adaptor{
|
return &Adaptor{
|
||||||
name: "LeapMotion",
|
name: "LeapMotion",
|
||||||
port: port,
|
port: port,
|
||||||
connect: func(port string) (io.ReadWriteCloser, error) {
|
connect: func(host string) (io.ReadWriteCloser, error) {
|
||||||
return websocket.Dial("ws://"+port+"/v3.json", "", "http://"+port)
|
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) 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
|
// Connect returns true if connection to leap motion is established successfully
|
||||||
func (l *Adaptor) Connect() (err error) {
|
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
|
return e
|
||||||
} else {
|
|
||||||
l.ws = ws
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.ws = ws
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ const (
|
|||||||
GestureEvent = "gesture"
|
GestureEvent = "gesture"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Driver the Gobot software device to the Leap Motion
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
name string
|
name string
|
||||||
connection gobot.Connection
|
connection gobot.Connection
|
||||||
@ -27,7 +28,7 @@ var receive = func(ws io.ReadWriteCloser, msg *[]byte) {
|
|||||||
websocket.Message.Receive(ws.(*websocket.Conn), msg)
|
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:
|
// Adds the following events:
|
||||||
// "message" - Gets triggered when receiving a message from leap motion
|
// "message" - Gets triggered when receiving a message from leap motion
|
||||||
@ -45,8 +46,14 @@ func NewDriver(a *Adaptor) *Driver {
|
|||||||
l.AddEvent(GestureEvent)
|
l.AddEvent(GestureEvent)
|
||||||
return l
|
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 }
|
func (l *Driver) Connection() gobot.Connection { return l.connection }
|
||||||
|
|
||||||
// adaptor returns leap motion adaptor
|
// adaptor returns leap motion adaptor
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Gesture is a Leap Motion gesture tht has been detected
|
||||||
type Gesture struct {
|
type Gesture struct {
|
||||||
Direction []float64 `json:"direction"`
|
Direction []float64 `json:"direction"`
|
||||||
Duration int `json:"duration"`
|
Duration int `json:"duration"`
|
||||||
@ -17,6 +18,7 @@ type Gesture struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hand is a Leap Motion hand tht has been detected
|
||||||
type Hand struct {
|
type Hand struct {
|
||||||
Direction []float64 `json:"direction"`
|
Direction []float64 `json:"direction"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
@ -32,6 +34,7 @@ type Hand struct {
|
|||||||
TimeVisible float64 `json:"TimeVisible"`
|
TimeVisible float64 `json:"TimeVisible"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pointable is a Leap Motion pointing motion tht has been detected
|
||||||
type Pointable struct {
|
type Pointable struct {
|
||||||
Direction []float64 `json:"direction"`
|
Direction []float64 `json:"direction"`
|
||||||
HandID int `json:"handId"`
|
HandID int `json:"handId"`
|
||||||
@ -46,12 +49,13 @@ type Pointable struct {
|
|||||||
TouchZone string `json:"touchZone"`
|
TouchZone string `json:"touchZone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InteractionBox is the area within which the gestural interaction has been detected
|
||||||
type InteractionBox struct {
|
type InteractionBox struct {
|
||||||
Center []int `json:"center"`
|
Center []int `json:"center"`
|
||||||
Size []float64 `json:"size"`
|
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 {
|
type Frame struct {
|
||||||
CurrentFrameRate float64 `json:"currentFrameRate"`
|
CurrentFrameRate float64 `json:"currentFrameRate"`
|
||||||
Gestures []Gesture `json:"gestures"`
|
Gestures []Gesture `json:"gestures"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user