-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6588240
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |