kxtj3: A few last-minute changes to the kxtj3 src

* Removed trailing whitespace
    * Fixed a few spelling errors
    * Switched to upm_delay_us for C source

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck 2018-06-21 10:33:38 -07:00
parent 186bbfab76
commit 3e84b74bdf
7 changed files with 60 additions and 59 deletions

View File

@ -26,24 +26,24 @@ public class KXTJ3_Example {
public static void main(String[] args) throws InterruptedException {
upm_kxtj3.KXTJ3 kxtj3 = new upm_kxtj3.KXTJ3();
upm_kxtj3.KXTJ3 kxtj3 = new upm_kxtj3.KXTJ3(0);
kxtj3.SensorInit(upm_kxtj3.KXTJ3_ODR_T.KXTJ3_ODR_25,
upm_kxtj3.KXTJ3_RESOLUTION_T.HIGH_RES,
kxtj3.SensorInit(upm_kxtj3.KXTJ3_ODR_T.KXTJ3_ODR_25,
upm_kxtj3.KXTJ3_RESOLUTION_T.HIGH_RES,
upm_kxtj3.KXTJ3_G_RANGE_T.KXTJ3_RANGE_16G_14);
float waitTime = kxtj3.GetAccelerationSamplePeriod() * 1000;
int sampleCounter = 10;
System.out.println("Setting settings:\nODR: 25 Hz\nResolution: " +
"High\nAcceleration range: 16g with 14bits");
System.out.println("Acceleration");
upm_kxtj3.floatVector xyz;
int sampleCounter = 10;
System.out.println("Setting settings:\nODR: 25 Hz\nResolution: " +
"High\nAcceleration range: 16g with 14bits");
System.out.println("Acceleration");
upm_kxtj3.floatVector xyz;
while (sampleCounter-- > 0) {
xyz = kxtj3.GetAccelerationVector();
System.out.println("x = " + xyz.get(0) + " y = " + xyz.get(1) +
" z = " + xyz.get(2));
System.out.println("x = " + xyz.get(0) + " y = " + xyz.get(1) +
" z = " + xyz.get(2));
Thread.sleep((long) waitTime);
}
}
}
}

View File

@ -35,7 +35,7 @@ var waitTime = kxtj3_sensor.GetAccelerationSamplePeriod();
var counter = 10;
console.log("Setting settings:\nODR: 25 Hz\nResolution: \
High\nAcceleration range: 16g with 14bits");
console.log("Accerleration: ");
console.log("Acceleration: ");
var interval = setInterval(function() {
data = kxtj3_sensor.GetAccelerationVector();
console.log(

View File

@ -52,7 +52,7 @@ def main():
[x, y, z] = kxtj3_sensor.GetAccelerationVector()
print ("x: %0.02f, y: %0.02f, z: %0.02f" % (x, y, z))
time.sleep(waitTime)
sampleCounter -= 1

View File

@ -5,4 +5,4 @@ upm_mixed_module_init (NAME kxtj3
CPP_HDR kxtj3.hpp
CPP_SRC kxtj3.cxx
CPP_WRAPS_C
REQUIRES mraa)
REQUIRES mraa utilities-c)

View File

@ -25,6 +25,7 @@
#include <unistd.h>
#include <math.h>
#include "kxtj3.h"
#include "upm_utilities.h"
#define SW_RESET_MAX_LOOP_COUNT 10
#define SW_RESET_READ_WAIT_MICRO_S 50000
@ -80,7 +81,7 @@ const struct odr_map_t odr_map_in_Hz[] = {
{KXTJ3_ODR_800, 800.0f},
{KXTJ3_ODR_1600, 1600.0f}};
/**
* @brief ODR register values maping with ODR in Hz for
* @brief ODR register values maping with ODR in Hz for
* wake-up function
*/
const struct odr_map_t odr_map_in_Hz_wakeup[] = {
@ -136,7 +137,7 @@ static float kxtj3_odr_val_to_sec(KXTJ3_ODR_T odr);
static float kxtj3_odr_val_to_sec_wakeup(KXTJ3_ODR_WAKEUP_T odr);
/**
@brief Sets the sensor default values for ODR, resolution (with its scale),
@brief Sets the sensor default values for ODR, resolution (with its scale),
G range (both normal and wake-up modes)
@param dev The sensor context
@ -201,7 +202,7 @@ static upm_result_t kxtj3_set_bit_off(const kxtj3_context dev, uint8_t reg, uint
@param reg The register address to write to
@param val byte data to write
@param bit_mask The bits or register mask
@return A UPM resutl
@return A UPM result
*/
static upm_result_t kxtj3_set_bits_with_mask(const kxtj3_context dev, uint8_t reg, uint8_t val, uint8_t bit_mask);
@ -231,11 +232,11 @@ This is used by the self-test functionality.
static struct Coordinates kxtj3_get_sample_averaged_data(kxtj3_context dev);
/**
@brief Check whether the self-test acceleration data difference is whithin the permitted threshold (0.5g)
@brief Check whether the self-test acceleration data difference is within the permitted threshold (0.5g)
@param before The Coordinates struct before the self-test
@param during The Coordinates struct of the self-test
@return true if difference is below thresold, false otherwise
@return true if difference is below threshold, false otherwise
*/
static bool kxtj3_check_self_test_difference(struct Coordinates before, struct Coordinates during);
@ -243,14 +244,14 @@ static bool kxtj3_check_self_test_difference(struct Coordinates before, struct C
@brief Checks the digital communication register (DCST_RESP) register value with an expected value
@param dev The sensor context
@param expected_val The expted byte value of the register
@param expected_val The expected byte value of the register
@return true if values match, false otherwise.
*/
static bool kxtj3_check_digital_communication_reg_value(kxtj3_context dev, uint8_t expected_val);
/**
@brief Gets the count value from a given time (in seconds) for the wake-up function.
Used by the wake-up motion counter and non-activity counter before anothe wake-up functions.
Used by the wake-up motion counter and non-activity counter before another wake-up functions.
@param dev The sensor context
@param time_sec Time in seconds to be converted
@ -642,7 +643,7 @@ static struct Coordinates kxtj3_get_sample_averaged_data(kxtj3_context dev)
coordinates_averaged_sample.x += fabs((x / EARTH_GRAVITY));
coordinates_averaged_sample.y += fabs((y / EARTH_GRAVITY));
coordinates_averaged_sample.z += fabs((z / EARTH_GRAVITY));
usleep(wait_time);
upm_delay_us(wait_time);
}
coordinates_averaged_sample.x /= SELF_TEST_SAMPLE_COUNT;
@ -720,7 +721,7 @@ upm_result_t kxtj3_sensor_software_reset(const kxtj3_context dev)
uint8_t srst_counter = 0;
while ((ctrl_reg2_data & KXTJ3_CTRL_REG2_SRST) != 0x00 && srst_counter < SW_RESET_MAX_LOOP_COUNT)
{
usleep(SW_RESET_READ_WAIT_MICRO_S);
upm_delay_us(SW_RESET_READ_WAIT_MICRO_S);
kxtj3_read_register(dev, KXTJ3_CTRL_REG2, &ctrl_reg2_data);
srst_counter++;
}

View File

@ -42,7 +42,7 @@ extern "C"
* @brief C API for the kxtj3 driver
* @defgroup kxtj3 libupm-kxtj3
* @ingroup Kionix i2c accelerometer
*
*
* @include kxtj3.c
*/
@ -201,7 +201,7 @@ extern "C"
kxtj3_context kxtj3_init(int bus, uint8_t addr);
/**
@brief Intilializes the sensor with the given resolution and acceleration range
@brief Initializes the sensor with the given resolution and acceleration range
This gets called during the kxtj3_init(), so it will not need to be called unless the sensor is reset
@ -307,7 +307,7 @@ Sensor needs to be in standby mode when setting the ODR
upm_result_t kxtj3_set_odr_wakeup_function(const kxtj3_context dev, KXTJ3_ODR_WAKEUP_T odr);
/**
@brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
@brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
CTRL_REG2, then checks the DCST_RESP register for a 0xAA, after the register is read, its
value is 0x55 and DCST bit is cleared.
@ -370,7 +370,7 @@ See the datasheet for more details
upm_result_t kxtj3_get_acceleration_data(const kxtj3_context dev, float *x, float *y, float *z);
/**
@brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
@brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
the sampling rate of the sensor
@param dev The sensor context
@ -379,7 +379,7 @@ the sampling rate of the sensor
float kxtj3_get_acceleration_sampling_period(kxtj3_context dev);
/**
Gets the duration of one sample period (in seconds) for the wakeup function depending on
Gets the duration of one sample period (in seconds) for the wakeup function depending on
the sampling rate of the sensor wakeup function
@param dev The sensor context
@ -443,7 +443,7 @@ Sensor needs to be in standby mode when enabling the interrupt
See datasheet for more details
@param dev The sensor context
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
@param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
@return UPM result
*/
@ -467,7 +467,7 @@ Polarity ACTIVE_HIGH or ACTIVE_LOW
Sensor must be in standby mode before performing this action
@param dev The sensor context
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
@return UPM result
*/
upm_result_t kxtj3_set_interrupt_polarity(const kxtj3_context dev, KXTJ3_INTERRUPT_POLARITY_T polarity);
@ -491,12 +491,12 @@ See datasheet for more details
upm_result_t kxtj3_set_interrupt_response(const kxtj3_context dev, KXTJ3_INTERRUPT_RESPONSE_T response_type);
/**
@brief Gets the status of the interrupts. (Has an interrupt occured).
@brief Gets the status of the interrupts. (Has an interrupt occurred).
See datasheet for more details
@param dev The sensor context
@return Return true if an interrupt event has occured (DRDY or WUFS is 1), returns false if no interrupts have occured
@return Return true if an interrupt event has occurred (DRDY or WUFS is 1), returns false if no interrupts have occurred
*/
bool kxtj3_get_interrupt_status(const kxtj3_context dev);
@ -536,7 +536,7 @@ See datasheet for more details
/**
@brief Uninstalls a previously installed interrupt handler for interrupt pin
@param dev The sensor context
@return UPM result
*/
@ -585,9 +585,9 @@ See datasheet for more details
kxtj3_wakeup_axes kxtj3_get_wakeup_axis_and_direction(kxtj3_context dev);
/**
@brief Enables the Unlached mode motion interrupt (ULMODE). This mode is always by default enabled.
When this bit is set, the wakeup interrupt has to be cleared manually
@brief Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
When this bit is set, the wakeup interrupt has to be cleared manually
(cannot use interrupt response with pulse)
Sensor must be in standby mode before performing this action
@ -598,16 +598,16 @@ Sensor must be in standby mode before performing this action
upm_result_t kxtj3_enable_wakeup_latch(kxtj3_context dev);
/**
@brief Disables the Unlached mode motion interrupt (ULMODE). This mode is always by default enabled
@brief Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled
(cannot use interrupt response with pulse).
The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
an almost continuous manner
Sensor must be in standby mode before performing this action
When this bit is cleared, and the interrupt response type is set to Pulse, then upon a wakeup event
the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
output will not reset until data is read or interrupt cleared.
@param dev The sensor context
@ -703,7 +703,7 @@ See datasheet for more details
@brief Sets the threshold counter for acceleration difference before sending a wakeup interrupt
The count is limited to values from 1 to 4096, that it is 16g threshold with (3.9mg/count)
It is advised to not set the threshold to a very low value which may cause bad behaviour
It is advised to not set the threshold to a very low value which may cause bad behaviour
in the wakeup interrupt
Sensor must be in standby mode before performing this action

View File

@ -33,7 +33,7 @@
* @brief C API for the kxtj3 driver
* @defgroup kxtj3 libupm-kxtj3
* @ingroup Kionix i2c accelerometer
*
*
* @include kxtj3.cxx
*/
@ -158,7 +158,7 @@ public:
void SetOdrForWakeup(KXTJ3_ODR_WAKEUP_T odr);
/**
* @brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
* @brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
* CTRL_REG2, then checks the DCST_RESP register for a 0xAA, after the register is read, its
* value is 0x55 and DCST bit is cleared.
*
@ -198,7 +198,7 @@ public:
/**
* Gets raw acceleration data from the sensor.
*
*
* @return Acceleration vector [x, y, z]
* @throws std::runtime_error on failure.
*/
@ -206,14 +206,14 @@ public:
/**
* Gets acceleration data in (m/s^2) from the sensor.
*
*
* @return Acceleration vector [x, y, z]
* @throws std::runtime_error on failure.
*/
std::vector<float> GetAccelerationVector();
/**
* @brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
* @brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
* the sampling rate of the sensor
*
* @return Floating point value of the sampling period
@ -222,7 +222,7 @@ public:
float GetAccelerationSamplePeriod();
/**
* @brief Gets the duration of one sample period (in seconds) for the wakeup function depending on
* @brief Gets the duration of one sample period (in seconds) for the wakeup function depending on
* the sampling rate of the sensor wakeup function
*
* @return Floating point value of the sampling period
@ -278,7 +278,7 @@ public:
*
* See datasheet for more details
*
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
* @param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
* @throws std::runtime_error on failure
*/
@ -300,7 +300,7 @@ public:
*
* Sensor must be in standby mode before performing this action
*
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
* @throws std::runtime_error on failure
*/
void SetInterruptPolarity(KXTJ3_INTERRUPT_POLARITY_T polarity);
@ -323,12 +323,12 @@ public:
void SetInerruptResponse(KXTJ3_INTERRUPT_RESPONSE_T response_type);
/**
* @brief Gets the status of the interrupts. (Has an interrupt occured)
* @brief Gets the status of the interrupts. (Has an interrupt occurred)
*
* See datasheet for more details
*
* @return Return true if an interrupt event has occured (DRDY or WUFS is 1),
* returns false if no interrupts have occured
* @return Return true if an interrupt event has occurred (DRDY or WUFS is 1),
* returns false if no interrupts have occurred
*/
bool GetInterruptStatus();
@ -404,15 +404,15 @@ public:
*
* See datasheet for more details
*
* @return A kxtj3_wakeup_axes struct with values of true/false
* @return A kxtj3_wakeup_axes struct with values of true/false
* for a wakeup for each axis and its direction
*/
kxtj3_wakeup_axes GetWakeUpAxisDirection();
/**
* @brief Enables the Unlached mode motion interrupt (ULMODE). This mode is always by default enabled.
*
* When this bit is set, the wakeup interrupt has to be cleared manually
* @brief Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
*
* When this bit is set, the wakeup interrupt has to be cleared manually
* (cannot use interrupt response with pulse)
*
* Sensor must be in standby mode before performing this action
@ -422,16 +422,16 @@ public:
void EnableWakeUpLatch();
/**
* @brief Disables the Unlached mode motion interrupt (ULMODE). This mode is always by default enabled.
* @brief Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
* (cannot use interrupt response with pulse)
*
* The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
* The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
* an almost continuous manner
*
* Sensor must be in standby mode before performing this action
*
* When this bit is cleared, and the interrupt response type is set to Pulse, then upon a wakeup event
* the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
* the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
* output will not reset until data is read or interrupt cleared.
* @throws std::runtime_error on failure
@ -520,7 +520,7 @@ public:
* @brief Sets the threshold counter for acceleration difference before sending a wakeup interrupt
*
* The count is limited to values from 1 to 4096, that it is 16g threshold with (3.9mg/count)
* It is advised to not set the threshold to a very low value which may cause bad behaviour
* It is advised to not set the threshold to a very low value which may cause bad behaviour
* in the wakeup interrupt
*
* Sensor must be in standby mode before performing this action