No Description

mpu9150.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Jon Trulson <jtrulson@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 sensorObj = require('jsupm_mpu9150');
  27. // Instantiate an MPU9105 on default I2C bus and address
  28. var sensor = new sensorObj.MPU9150();
  29. // Initialize the device with default values
  30. sensor.init();
  31. var x = new sensorObj.new_floatp();
  32. var y = new sensorObj.new_floatp();
  33. var z = new sensorObj.new_floatp();
  34. // Output data every half second until interrupted
  35. setInterval(function()
  36. {
  37. sensor.update();
  38. sensor.getAccelerometer(x, y, z);
  39. console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) +
  40. " AY: " + sensorObj.floatp_value(y) +
  41. " AZ: " + sensorObj.floatp_value(z));
  42. sensor.getGyroscope(x, y, z);
  43. console.log("Gyroscope: GX: " + sensorObj.floatp_value(x) +
  44. " AY: " + sensorObj.floatp_value(y) +
  45. " AZ: " + sensorObj.floatp_value(z));
  46. sensor.getMagnetometer(x, y, z);
  47. console.log("Magnetometer: MX: " + sensorObj.floatp_value(x) +
  48. " MY: " + sensorObj.floatp_value(y) +
  49. " MZ: " + sensorObj.floatp_value(z));
  50. console.log("Temperature: " + sensor.getTemperature());
  51. console.log();
  52. }, 500);
  53. // exit on ^C
  54. process.on('SIGINT', function()
  55. {
  56. sensor = null;
  57. sensorObj.cleanUp();
  58. sensorObj = null;
  59. console.log("Exiting.");
  60. process.exit(0);
  61. });