arnaucube
arnaucube/comunicationLeapPublic Self-hosted repository
comunicationLeap/clientLeap/scriptOld.js
clientLeap/scriptOld.jsRaw
 1function concatData(id, data){
 2  return id + ": " + data + "<br>";
 3
 4}
 5
 6var output = document.getElementById("output");
 7var frameString= "", handString="", fingerString="";
 8var hand, finger;
 9
10
11
12
13
14
15
16var options = { enableGestures: true};
17
18//main leap loop
19Leap.loop(options, function(frame) {
20  frameString = concatData("frame_id", frame.id);
21  frameString += concatData("num_hands", frame.hands.length);
22  frameString += concatData("num_fingers", frame.fingers.length);
23  frameString += "<br>";
24
25  //showcase some new v2 features
26  for(var i=0; i<frame.hands.length; i++){
27    hand= frame.hands[i];
28    handString = concatData("hand_type", hand.type);
29    handString += concatData("confidence", hand.confidence);
30    handString += concatData("pinch_strength", hand.pinchStrength);
31    handString += concatData("grab_strength", hand.grabStrength);
32
33    handString += "<br>";
34    frameString += handString;
35  }
36
37
38  if(frame.valid && frame.gestures.length > 0){
39    frame.gestures.forEach(function(gesture){
40        switch (gesture.type){
41          case "circle":
42              /*console.log("Circle Gesture");
43              toastr.info("Circle Gesture");*/
44              break;
45          case "keyTap":
46              console.log("Key Tap Gesture");
47              toastr.info("Key Tap Gesture");
48              break;
49          case "screenTap":
50              console.log("Screen Tap Gesture");
51              toastr.info("Screen Tap Gesture");
52              break;
53          case "swipe":
54              console.log("Swipe Gesture");
55              toastr.info("Swipe Gesture");
56              break;
57        }
58    });
59
60  }
61
62  output.innerHTML = frameString;
63});