summaryrefslogtreecommitdiff
path: root/peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx')
-rwxr-xr-x[-rw-r--r--]peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx26
1 files changed, 15 insertions, 11 deletions
diff --git a/peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx b/peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx
index 0eafbb7..bf1021a 100644..100755
--- a/peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx
+++ b/peripheral/libupm/src/kxcjk1013/kxcjk1013.cxx
@@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
- * Copyright (c) 2015 Intel Corporation.
+ * 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
@@ -26,7 +26,9 @@
#include <string>
#include <stdexcept>
#include <string.h>
-#include "kxcjk1013.h"
+#include "kxcjk1013.hpp"
+
+#define NUMBER_OF_BITS_IN_BYTE 8
using namespace upm;
@@ -45,9 +47,9 @@ KXCJK1013::KXCJK1013(int device)
sprintf(trigger, "hrtimer-kxcjk1013-hr-dev%d", device);
if (mraa_iio_create_trigger(m_iio, trigger) != MRAA_SUCCESS)
- fprintf(stderr, "Create trigger failed\n");
+ fprintf(stderr, "Create trigger %s failed\n", trigger);
- if (mraa_iio_get_mounting_matrix(m_iio, m_mount_matrix) == MRAA_SUCCESS)
+ if (mraa_iio_get_mount_matrix(m_iio, "in_mount_matrix", m_mount_matrix) == MRAA_SUCCESS)
m_mount_matrix_exist = true;
else
m_mount_matrix_exist = false;
@@ -58,7 +60,8 @@ KXCJK1013::KXCJK1013(int device)
KXCJK1013::~KXCJK1013()
{
- // mraa_iio_stop(m_iio);
+ if (m_iio)
+ mraa_iio_close(m_iio);
}
void
@@ -70,21 +73,20 @@ KXCJK1013::installISR(void (*isr)(char*), void* arg)
int64_t
KXCJK1013::getChannelValue(unsigned char* input, mraa_iio_channel* chan)
{
- uint64_t u64;
+ uint64_t u64 = 0;
int i;
- int storagebits = chan->bytes * 8;
+ int storagebits = chan->bytes * NUMBER_OF_BITS_IN_BYTE;
int realbits = chan->bits_used;
int zeroed_bits = storagebits - realbits;
uint64_t sign_mask;
uint64_t value_mask;
- u64 = 0;
if (!chan->lendian)
- for (i = 0; i < storagebits / 8; i++)
- u64 = (u64 << 8) | input[i];
+ for (i = 0; i < storagebits / NUMBER_OF_BITS_IN_BYTE; i++)
+ u64 = (u64 << NUMBER_OF_BITS_IN_BYTE) | input[i];
else
- for (i = storagebits / 8 - 1; i >= 0; i--)
+ for (i = storagebits / NUMBER_OF_BITS_IN_BYTE - 1; i >= 0; i--)
u64 = (u64 << 8) | input[i];
u64 = (u64 >> chan->shift) & (~0ULL >> zeroed_bits);
@@ -142,6 +144,7 @@ KXCJK1013::disableBuffer()
bool
KXCJK1013::setScale(float scale)
{
+ m_scale = scale;
mraa_iio_write_float(m_iio, "in_accel_scale", scale);
return true;
@@ -183,6 +186,7 @@ KXCJK1013::extract3Axis(char* data, float* x, float* y, float* z)
iio_y = getChannelValue((unsigned char*) (data + channels[1].location), &channels[1]);
iio_z = getChannelValue((unsigned char*) (data + channels[2].location), &channels[2]);
+ // Raw data is acceleration in direction. Units after application of scale are m/s^2
*x = (iio_x * m_scale);
*y = (iio_y * m_scale);
*z = (iio_z * m_scale);