You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

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