No Description

nunchuck.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Zion Orent <zorent@ics.com>
  5. * Copyright (c) 2015 Intel Corporation.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. var nunchuck_lib = require('jsupm_nunchuck');
  27. // Instantiate a nunchuck controller bus 0
  28. var nunchuck_obj = new nunchuck_lib.NUNCHUCK(0);
  29. // always do this first
  30. console.log("Initializing... ");
  31. if (!nunchuck_obj.init())
  32. {
  33. console.log("nunchuck->init() failed.");
  34. process.exit(0);
  35. }
  36. setInterval(function()
  37. {
  38. nunchuck_obj.update();
  39. var outputStr = "stickX: " + nunchuck_obj.stickX +
  40. ", stickY: " + nunchuck_obj.stickY;
  41. console.log(outputStr);
  42. outputStr = "accelX: " + nunchuck_obj.accelX +
  43. ", accelY: " + nunchuck_obj.accelY +
  44. ", accelZ: " + nunchuck_obj.accelZ;
  45. console.log(outputStr);
  46. outputStr = "button C: " +
  47. ((nunchuck_obj.buttonC) ? "pressed" : "not pressed");
  48. console.log(outputStr);
  49. outputStr = "button Z: " +
  50. ((nunchuck_obj.buttonZ) ? "pressed" : "not pressed");
  51. console.log(outputStr);
  52. }, 100);
  53. // Print message when exiting
  54. process.on('SIGINT', function()
  55. {
  56. console.log("Exiting...");
  57. process.exit(0);
  58. });