1/*jslint node:true, vars:true, bitwise:true, unparam:true */ 2/*jshint unused:true */ 3 4/* 5* Author: Zion Orent <zorent@ics.com> 6* Copyright (c) 2015 Intel Corporation. 7* 8* Permission is hereby granted, free of charge, to any person obtaining 9* a copy of this software and associated documentation files (the 10* "Software"), to deal in the Software without restriction, including 11* without limitation the rights to use, copy, modify, merge, publish, 12* distribute, sublicense, and/or sell copies of the Software, and to 13* permit persons to whom the Software is furnished to do so, subject to 14* the following conditions: 15* 16* The above copyright notice and this permission notice shall be 17* included in all copies or substantial portions of the Software. 18* 19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26*/ 27 28var analogGyro3Axis = require("jsupm_adxl335"); 29 30var g_addnumBool = true; 31var g_cycleNum = 0.0; 32var g_cycleCount = 0; 33 34// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2 35var myAnalogGyro3Axis = new analogGyro3Axis.ADXL335(0, 1, 2); 36 37console.log("Please make sure the sensor is completely still."); 38console.log("Sleeping for 2 seconds"); 39 40var g_myInterval; 41 42setTimeout(function() 43{ 44 console.log("Calibrating..."); 45 myAnalogGyro3Axis.calibrate(); 46 // Get values from accelerometer every 0.2 seconds 47 g_myInterval = setInterval(runAccelerometer, 200); 48}, 2000); 49 50 51var x = new analogGyro3Axis.new_intPointer(); 52var y = new analogGyro3Axis.new_intPointer(); 53var z = new analogGyro3Axis.new_intPointer(); 54 55var aX = new analogGyro3Axis.new_floatPointer(); 56var aY = new analogGyro3Axis.new_floatPointer(); 57var aZ = new analogGyro3Axis.new_floatPointer(); 58 59var outputStr; 60 61function runAccelerometer() 62{ 63 myAnalogGyro3Axis.values(x, y, z); 64 outputStr = "Raw Values: X: " + 65 analogGyro3Axis.intPointer_value(x) + 66 " Y: " + analogGyro3Axis.intPointer_value(y) + 67 " Z: " + analogGyro3Axis.intPointer_value(z); 68 console.log(outputStr); 69 70 myAnalogGyro3Axis.acceleration(aX, aY, aZ); 71 outputStr = "Acceleration: X: " + 72 analogGyro3Axis.floatPointer_value(aX) + "g\n" + 73 "Acceleration: Y: " + 74 analogGyro3Axis.floatPointer_value(aY) + "g\n" + 75 "Acceleration: Z: " + 76 analogGyro3Axis.floatPointer_value(aZ) + "g"; 77 console.log(outputStr); 78 79 console.log(" "); 80} 81 82 83// When exiting: clear interval and print exit message 84process.on('SIGINT', function() 85{ 86 clearInterval(g_myInterval); 87 console.log("Exiting..."); 88 process.exit(0); 89}); 90