1//////////////////////////////////////////////////////////////////////////////////////
2// The MIT License (MIT)
3//
4// Submit Date: 03/09/2015
5// Author: Juan Jose Chong <juanjchong@gmail.com>
6// Copyright (c) 2015 Juan Jose Chong
7//
8//////////////////////////////////////////////////////////////////////////////////////
9// adis16448.js
10//////////////////////////////////////////////////////////////////////////////////////
11//
12// This example code runs on an Intel Edison and uses mraa to acquire data
13// from an ADIS16448. This data is then scaled and printed onto the terminal.
14//
15// This software has been tested to connect to an ADIS16448 through a level shifter
16// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired through
17// the level shifter and the ADIS16448 is also being powered by the Intel Edison.
18//
19// Permission is hereby granted, free of charge, to any person obtaining
20// a copy of this software and associated documentation files (the
21// "Software"), to deal in the Software without restriction, including
22// without limitation the rights to use, copy, modify, merge, publish,
23// distribute, sublicense, and/or sell copies of the Software, and to
24// permit persons to whom the Software is furnished to do so, subject to
25// the following conditions:
26//
27// The above copyright notice and this permission notice shall be
28// included in all copies or substantial portions of the Software.
29//
30// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37//
38//////////////////////////////////////////////////////////////////////////////////////
39
40//Call the ADIS16448 library
41var adis16448 = require('jsupm_adis16448');
42
43//Instantiate SPI and Reset
44var imu = new adis16448.ADIS16448(0,3);
45
46periodicActivity(); //Call the periodicActivity function
47
48function periodicActivity()
49{
50    //Read & Scale Gyro/Accel Data
51    var xgyro = imu.gyroScale(imu.regRead(0x04));
52    var ygyro = imu.gyroScale(imu.regRead(0x06));
53    var zgyro = imu.gyroScale(imu.regRead(0x08));
54    var xaccl = imu.accelScale(imu.regRead(0x0A));
55    var yaccl = imu.accelScale(imu.regRead(0x0C));
56    var zaccl = imu.accelScale(imu.regRead(0x0E));
57
58    //Display Scaled Data on the Console Log
59    console.log('XGYRO: ' + xgyro);
60    console.log('YGYRO: ' + ygyro);
61    console.log('ZGYRO: ' + zgyro);
62    console.log('XACCL: ' + xaccl);
63    console.log('YACCL: ' + yaccl);
64    console.log('ZACCL: ' + zaccl);
65    console.log(' ');
66    setTimeout(periodicActivity,200); //call the indicated function after 0.2 seconds (200 milliseconds)
67}