Skip to content

Commit

Permalink
Some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisjake committed Sep 2, 2013
1 parent 21d56f6 commit 06386d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 8 additions & 2 deletions device.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// The package gomotion defines a concurrent Go library that can connect to a Leap motion device over a WebSocket conection.
// By default, the LeapMotion exposes a JSON WebSocket that pumps out messages near 30 to 50 fps.
package gomotion

import (
"code.google.com/p/go.net/websocket"
"log"
)

// The LeapMotionDevice definition. Connecting to a device will return an instance of this struct.
type LeapMotionDevice struct {
Pipe chan *Frame
Connection *websocket.Conn
}

// This function acts as a constructor and connector for the gomotion package.
func GetDevice(url string) *LeapMotionDevice {
pipe := make(chan *Frame)
connection, err := websocket.Dial(url, "", "http://localhost")
Expand All @@ -19,6 +23,7 @@ func GetDevice(url string) *LeapMotionDevice {
return &LeapMotionDevice{pipe, connection}
}

// This function starts the listening on the WebSocket. By default it enables Gestures on the LeapMotionDevice.
func (device *LeapMotionDevice) Listen() {
var config struct {
enableGestures bool `json:"enableGestures"`
Expand All @@ -28,10 +33,10 @@ func (device *LeapMotionDevice) Listen() {
if err != nil {
log.Fatal(err)
}
go device.ListenRead()
go device.listenRead()
}

func (device *LeapMotionDevice) ListenRead() {
func (device *LeapMotionDevice) listenRead() {
for {
var frame Frame
err := websocket.JSON.Receive(device.Connection, &frame)
Expand All @@ -43,6 +48,7 @@ func (device *LeapMotionDevice) ListenRead() {
}
}

// This function closes the internal WebSocket connection on a LeapMotionDevice
func (device *LeapMotionDevice) Close() {
device.Connection.Close()
}
23 changes: 20 additions & 3 deletions trackables.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gomotion

// The hand is a basic trackable object through the LeapMotionDevice.
// There can be zero, one, or two that come through each Frame.
// A Hand will carry the same ID across the frames in which it is visible.
type Hand struct {
Id int
Id int `json:id`
Direction []float32 `json:direction`
PalmNormal []float32 `json:palmNormal`
PalmPosition []float32 `json:palmPosition`
Expand All @@ -15,6 +18,10 @@ type Hand struct {
TimeVisible float32 `json:timeVisible`
}

// A Frame can have a list of Gestures that are starting, updating, or ending.
// A Gesture will carry the same ID across the frames in which it is visible.
// *NOTE* Pay attention to the State of the Gesture, as it can give you an idea
// of where the gesture is going.
type Gesture struct {
Id int `json:id`
State string `json:state`
Expand All @@ -32,11 +39,16 @@ type Gesture struct {
Direction []float32 `json:direction`
}

// An InteractionBox gives you the physical bounding box in which
// the device is detecting the Hands, Gestures, etc. It's provided
// to create a perspective to map your screen view box to.
type InteractionBox struct {
Center []float32 `json:center`
Size []float32 `json:size`
}

// A Finger or Tool can be a Pointable, as well as pointables themselves.
// A Frame will have a list of pointables associated with each hand.
type Pointable struct {
Id int `json:id`
HandId int `json:handId`
Expand All @@ -51,16 +63,21 @@ type Pointable struct {
TouchZone string `json:touchZone`
}

// A Frame can have a list of Fingers, which are structured like Pointables
type Finger struct {
Id int
Id int `json:id`
*Pointable
}

// A Frame can have a list of Tools, which are structured like Pointables
type Tool struct {
Id int
Id int `json:id`
*Pointable
}

// This struct represents each Frame presented on the LeapMotionDevice WebSocket.
// The base structure will fill in with information available or for the arrays,
// empty arrays, so that you can quickly iterate over each array in the struct.
type Frame struct {
Id int `json:"id"`
Timestamp int `json:"timestamp"`
Expand Down

0 comments on commit 06386d5

Please sign in to comment.