Updates implementation and examples to use dynamic-friendly interface

Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
deadprogram 2016-03-18 15:28:40 -07:00 committed by Brendan Le Foll
parent 90983fde9d
commit 3ca9bfe80f
4 changed files with 108 additions and 32 deletions

View File

@ -58,7 +58,9 @@ main(int argc, char **argv)
sensor->enableShockDetection(true); sensor->enableShockDetection(true);
for(int i=0; i<300; i++) { for(int i=0; i<300; i++) {
if (sensor->isShockDetected()) { if (sensor->isShockDetected()) {
sensor->getShockDetectData(&axis, &direction); sensor->getNextShock();
axis = sensor->getAxis();
direction = sensor->getDirection();
printf("shock data is: %d, %d\n", axis, direction); printf("shock data is: %d, %d\n", axis, direction);
} }
usleep(10000); usleep(10000);

View File

@ -0,0 +1,47 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Ron Evans (@deadprogram)
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var curieImu = require('jsupm_curieimu');
var outputStr;
var myInterval = setInterval(function()
{
// get accelerometer readings
curieImu.updateAccel();
outputStr = "accel: x " + curieImu.getAccelX()
+ " - y " + curieImu.getAccelY()
+ " - z " + curieImu.getAccelZ();
console.log(outputStr);
console.log(" ");
}, 1000);
// Print message when exiting
process.on('SIGINT', function()
{
clearInterval(myInterval);
console.log("Exiting");
process.exit(0);
});

View File

@ -326,6 +326,18 @@ CurieImu::getTemperature()
return result; return result;
} }
int16_t
CurieImu::getAxis()
{
return m_axis;
}
int16_t
CurieImu::getDirection()
{
return m_direction;
}
void void
CurieImu::enableShockDetection(bool enable) CurieImu::enableShockDetection(bool enable)
{ {
@ -355,15 +367,15 @@ CurieImu::isShockDetected()
} }
void void
CurieImu::getShockDetectData(int *axis, int *direction) CurieImu::getNextShock()
{ {
if (m_shockData.size() > 0) { if (m_shockData.size() > 0) {
IMUDataItem* item = m_shockData.front(); IMUDataItem* item = m_shockData.front();
*axis = item->axis; m_axis = item->axis;
*direction = item->direction; m_direction = item->direction;
m_shockData.pop(); m_shockData.pop();
delete item; delete item;
} }
} }
void void
@ -394,13 +406,15 @@ CurieImu::isStepDetected()
return (m_stepData.size() > 0); return (m_stepData.size() > 0);
} }
void int16_t
CurieImu::getStepCount(int *count) CurieImu::getStepCount()
{ {
int16_t count = 0;
if (m_stepData.size() > 0) { if (m_stepData.size() > 0) {
*count = m_stepData.front(); count = m_stepData.front();
m_stepData.pop(); m_stepData.pop();
} }
return count;
} }
void void
@ -432,13 +446,13 @@ CurieImu::isTapDetected()
} }
void void
CurieImu::getTapDetectData(int *axis, int *direction) CurieImu::getNextTap()
{ {
if (m_tapData.size() > 0) { if (m_tapData.size() > 0) {
IMUDataItem* item = m_tapData.front(); IMUDataItem* item = m_tapData.front();
*axis = item->axis; m_axis = item->axis;
*direction = item->direction; m_direction = item->direction;
m_tapData.pop(); m_tapData.pop();
delete item; delete item;
} }
} }

View File

@ -177,6 +177,20 @@ class CurieImu {
*/ */
int16_t* getMotion(); int16_t* getMotion();
/**
* Returns last shock or tap axis reading
*
* @return axis value
*/
int16_t getAxis();
/**
* Returns last shock or tap direction reading
*
* @return direction value
*/
int16_t getDirection();
/** /**
* Turns shock detection notifications on/off * Turns shock detection notifications on/off
* *
@ -192,12 +206,10 @@ class CurieImu {
bool isShockDetected(); bool isShockDetected();
/** /**
* Gets shock detect data from queue * Gets shock detect data from queue. Then m_axis gets axis data, and
* * m_direction gets direction data
* @param axis gets axis data
* @param direction gets direction data
*/ */
void getShockDetectData(int *axis, int *direction); void getNextShock();
/** /**
* Turns step counter notifications on/off * Turns step counter notifications on/off
@ -216,9 +228,9 @@ class CurieImu {
/** /**
* Gets step count data from queue * Gets step count data from queue
* *
* @param count the total number of steps taken * @return the total number of steps taken
*/ */
void getStepCount(int *count); int16_t getStepCount();
/** /**
* Turns tap detection notifications on/off * Turns tap detection notifications on/off
@ -235,12 +247,10 @@ class CurieImu {
bool isTapDetected(); bool isTapDetected();
/** /**
* Gets tap detect data from queue * Gets tap detect data from queue. Then m_axis gets axis data, and
* * m_direction gets direction data
* @param axis gets axis data
* @param direction gets direction data
*/ */
void getTapDetectData(int *axis, int *direction); void getNextTap();
/** /**
* Locks responses from Firmata * Locks responses from Firmata
@ -289,6 +299,9 @@ class CurieImu {
int16_t m_accel[3]; int16_t m_accel[3];
int16_t m_gyro[3]; int16_t m_gyro[3];
int16_t m_motion[6]; int16_t m_motion[6];
int16_t m_axis;
int16_t m_direction;
}; };
} }