summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brnkl_motion.api14
-rw-r--r--motionMonitor/motionMonitor.c15
2 files changed, 21 insertions, 8 deletions
diff --git a/brnkl_motion.api b/brnkl_motion.api
index fd7c9b5..ad4262a 100644
--- a/brnkl_motion.api
+++ b/brnkl_motion.api
@@ -1,5 +1,13 @@
DEFINE N_CHANGE_BLOCKS = 200;
-FUNCTION le_result_t getSuddenImpact (double x [N_CHANGE_BLOCKS] OUT, double y [N_CHANGE_BLOCKS] OUT, double z [N_CHANGE_BLOCKS] OUT);
-FUNCTION le_result_t getCurrentAcceleration (double x OUT, double y OUT, double z OUT);
- \ No newline at end of file
+FUNCTION le_result_t getSuddenImpact(
+ double x [N_CHANGE_BLOCKS] OUT,
+ double y [N_CHANGE_BLOCKS] OUT,
+ double z [N_CHANGE_BLOCKS] OUT,
+ uint64 timestamps[N_CHANGE_BLOCKS] OUT
+);
+FUNCTION le_result_t getCurrentAcceleration(
+ double x OUT,
+ double y OUT,
+ double z OUT
+);
diff --git a/motionMonitor/motionMonitor.c b/motionMonitor/motionMonitor.c
index 0af8728..2622ea6 100644
--- a/motionMonitor/motionMonitor.c
+++ b/motionMonitor/motionMonitor.c
@@ -19,8 +19,7 @@ double yAccImpact[N_CHANGE_BLOCKS];
double zAccImpact[N_CHANGE_BLOCKS];
uint64_t timestamps[N_CHANGE_BLOCKS];
-static const char FormatStr[] =
- "/sys/devices/i2c-0/0-0068/iio:device0/in_%s_%s";
+static const char FormatStr[] = "/sys/bus/iio/devices/iio:device0/in_%s_%s";
static const char AccType[] = "accel";
static const char GyroType[] = "anglvel";
static const char CompX[] = "x_raw";
@@ -46,28 +45,31 @@ le_result_t brnkl_motion_getCurrentAcceleration(double* xAcc,
char path[256];
double scaling = 0.0;
+ snprintf(path, sizeof(path), FormatStr, AccType, CompScale);
r = ioutil_readDoubleFromFile(path, &scaling);
if (r != LE_OK) {
goto done;
}
+ snprintf(path, sizeof(path), FormatStr, AccType, CompX);
r = ioutil_readDoubleFromFile(path, xAcc);
if (r != LE_OK) {
goto done;
}
*xAcc *= scaling;
+ snprintf(path, sizeof(path), FormatStr, AccType, CompY);
r = ioutil_readDoubleFromFile(path, yAcc);
if (r != LE_OK) {
goto done;
}
*yAcc *= scaling;
+ snprintf(path, sizeof(path), FormatStr, AccType, CompZ);
r = ioutil_readDoubleFromFile(path, zAcc);
*zAcc *= scaling;
done:
- LE_INFO("Showing accel X: %f Y: %f Z: %f ", *xAcc, *yAcc, *zAcc);
return r;
}
@@ -91,20 +93,23 @@ le_result_t brnkl_motion_getSuddenImpact(double* xAcc,
double* yAcc,
size_t* ySize,
double* zAcc,
- size_t* zSize) {
+ size_t* zSize,
+ uint64_t* timestampssOut,
+ size_t* timeSize) {
if (!totalImpacts)
LE_INFO("No Sudden Impacts to Report");
else {
pthread_mutex_lock(&impactMutex);
// check
- if (totalImpacts < *xSize || totalImpacts < *ySize || totalImpacts < *zSize)
+ if (totalImpacts > *xSize || totalImpacts > *ySize || totalImpacts > *zSize)
return LE_OUT_OF_RANGE;
for (int i = 0; i < totalImpacts; i++) {
xAcc[i] = xAccImpact[i];
yAcc[i] = yAccImpact[i];
zAcc[i] = zAccImpact[i];
+ timestampssOut[i] = timestamps[i];
}
*xSize = *ySize = *zSize = totalImpacts;