Skip to content

Commit 43c44d1

Browse files
author
Amadeus Stevenson
committed
Add gesture detection
1 parent f2f94c1 commit 43c44d1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

leap-arduino.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ board.on('ready', function() {
1010
led = new five.Led(13);
1111
ws.on('message', function(data, flags) {
1212
frame = JSON.parse(data);
13-
if (frame.hands && frame.hands.length > 1) {
13+
if (frame.hands && frame.hands.length >= 1) {
1414
led.on();
1515
} else {
1616
led.off();

leap-gestures.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Leap motion enables a websocket with all frame data
2+
var webSocket = require('ws'),
3+
ws = new webSocket('ws://127.0.0.1:6437');
4+
5+
// On successful connection
6+
ws.onopen = function(event) {
7+
var enableMessage = JSON.stringify({enableGestures: true});
8+
ws.send(enableMessage); // Enable gestures
9+
};
10+
11+
// We can parse this
12+
ws.on('message', function(data, flags) {
13+
frame = JSON.parse(data);
14+
if(frame.gestures && frame.gestures.length > 0){
15+
frame.gestures.forEach(function(gesture){
16+
switch (gesture.type){
17+
case "circle":
18+
console.log("Circle Gesture");
19+
break;
20+
case "keyTap":
21+
console.log("Key Tap Gesture");
22+
break;
23+
case "screenTap":
24+
console.log("Screen Tap Gesture");
25+
break;
26+
case "swipe":
27+
console.log("Swipe Gesture");
28+
break;
29+
}
30+
});
31+
}
32+
});

0 commit comments

Comments
 (0)