-
Notifications
You must be signed in to change notification settings - Fork 0
/
finger-commands.js
84 lines (77 loc) · 2.52 KB
/
finger-commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var Cylon = require('cylon');
var _ = require('lodash');
Cylon.robot({
connections: {
leapmotion: { adaptor: 'leapmotion' }
},
devices: {
leapmotion: { driver: 'leapmotion' }
},
work: function (my) {
var current_sign = '';
var prev_sign = '';
var sign_count = 0;
var sign_limit = 5;
var executed = false;
my.leapmotion.on('hand', _.throttle(function (hand) {
current_sign = _.map(hand.fingers, function(x){ return x.extended ? 1 : 0; }).join('')
if(current_sign == prev_sign){
process.stdout.write(".");
sign_count++;
if(sign_count == sign_limit && !executed) {
execute_sign(current_sign);
executed = true;
_.delay(function() { executed = false}, 2000 );
}
} else {
process.stdout.write("\n- fingers: " + current_sign + " > ");
sign_count = 0;
executed = false;
}
prev_sign = current_sign;
}, 250));
execute_sign = function(sign) {
var sign_name = "";
switch (sign) {
case "00000":
sign_name = "FIST";
break;
case "10000":
sign_name = "THUMB";
break;
case "01000":
sign_name = "ONE";
break;
case "01100":
sign_name = "TWO";
break;
case "01110":
sign_name = "THREE";
break;
case "01111":
sign_name = "FOUR";
break;
case "11111":
sign_name = "HAND";
break;
case "01001":
sign_name = "METAL";
break;
case "10001":
sign_name = "SURF";
break;
case "00100":
sign_name = "GFY";
break;
// .....
default:
sign_name = "UNDEFINED";
break;
}
process.stdout.write(" " + sign_name + " ");
}
// my.leapmotion.on('gesture', _.throttle(function (gesture) {
// console.log("# gesture: " + gesture.type);
// }, 500));
}
}).start();