Skip to content

Commit

Permalink
First
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisjake committed Aug 30, 2013
0 parents commit 6588240
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
48 changes: 48 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package gomotion

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

type LeapMotionDevice struct {
Pipe chan *Frame
Connection *websocket.Conn
}

func GetDevice(url string) *LeapMotionDevice {
pipe := make(chan *Frame)
connection, err := websocket.Dial(url, "", "http://localhost")
if err != nil {
log.Fatal(err)
}
return &LeapMotionDevice{pipe, connection}
}

func (device *LeapMotionDevice) Listen() {
var config struct {
enableGestures bool `json:"enableGestures"`
}
config.enableGestures = true
err := websocket.JSON.Send(device.Connection, &config)
if err != nil {
log.Fatal(err)
}
go device.ListenRead()
}

func (device *LeapMotionDevice) ListenRead() {
for {
var frame Frame
err := websocket.JSON.Receive(device.Connection, &frame)
if err == nil {
device.Pipe <- &frame
} else {
log.Fatal(err)
}
}
}

func (device *LeapMotionDevice) Close() {
device.Connection.Close()
}
76 changes: 76 additions & 0 deletions trackables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gomotion

type Hand struct {
Id int
Direction []float32 `json:direction`
PalmNormal []float32 `json:palmNormal`
PalmPosition []float32 `json:palmPosition`
PalmVelocity []float32 `json:palmVelocity`
SphereCenter []float32 `json:sphereCenter`
SphereRadius float32 `json:"sphereRadius"`
StabilizedPalmPosition []float32 `json:StabilizedPalmPosition`
R [][]float32 `json:"r"`
S float32 `json:"s"`
T []float32 `json:"t"`
TimeVisible float32 `json:timeVisible`
}

type Gesture struct {
Id int `json:id`
State string `json:state`
GestureType string `json:type`
Duration int `json:duration`
HandIds []int `json:handIds`
PointableIds []int `json:pointableIds`
Speed float32 `json:speed`
Radius float32 `json:radius`
Progress float32 `json:progress`
Center []float32 `json:center`
Normal []float32 `json:normal`
StartPosition []float32 `json:startPosition`
Position []float32 `json:position`
Direction []float32 `json:direction`
}

type InteractionBox struct {
Center []float32 `json:center`
Size []float32 `json:size`
}

type Pointable struct {
Id int `json:id`
HandId int `json:handId`
Direction []float32 `json:direction`
Length float32 `json:length`
StabilizedTipPosition []float32 `json:stabilizedTipPosition`
TimeVisible float32 `json:timeVisible`
TipPosition []float32 `json:tipPosition`
TipVelocity []float32 `json:tipVelocity`
Tool bool `json:tool`
TouchDistance float32 `json:touchDistance`
TouchZone string `json:touchZone`
}

type Finger struct {
Id int
*Pointable
}

type Tool struct {
Id int
*Pointable
}

type Frame struct {
Id int `json:"id"`
Timestamp int `json:"timestamp"`
InteractionBox InteractionBox `json:interactionBox`
Hands []Hand `json:"hands"`
Pointables []Pointable `json:"pointables"`
Fingers []Finger `json:"fingers"`
Tools []Tool `json:"tools"`
Gestures []Gesture `json:"gestures"`
R [][]float32 `json:"r"`
S float32 `json:"s"`
T []float32 `json:"t"`
}

0 comments on commit 6588240

Please sign in to comment.