mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
kx122: Small fix-ups for kx122 addition
A few small changes for the kx122 library. Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
e4dd6457bb
commit
1be36ec1df
@ -28,6 +28,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "kx122.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -42,23 +43,23 @@ int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT,sig_handler);
|
||||
|
||||
upm::KX122 *sensor = new upm::KX122(0,-1,24);
|
||||
//! [Interesting]
|
||||
upm::KX122 sensor(0,-1,24);
|
||||
|
||||
sensor->softwareReset();
|
||||
sensor->deviceInit(KX122_ODR_50,HIGH_RES,KX122_RANGE_2G);
|
||||
sensor.softwareReset();
|
||||
sensor.deviceInit(KX122_ODR_50,HIGH_RES,KX122_RANGE_2G);
|
||||
|
||||
float x,y,z;
|
||||
float wait_time = sensor->getSamplePeriod() * MICRO_S;
|
||||
int wait_time = sensor.getSamplePeriod() * MICRO_S;
|
||||
if (wait_time < 0) wait_time = 1000;
|
||||
|
||||
while(shouldRun){
|
||||
sensor->getAccelerationData(&x,&y,&z);
|
||||
sensor.getAccelerationData(&x,&y,&z);
|
||||
|
||||
printf("%.02f | %.02f | %.02f\n",x,y,z);
|
||||
usleep(wait_time);
|
||||
upm_delay_us(wait_time);
|
||||
}
|
||||
|
||||
delete sensor;
|
||||
sensor = nullptr;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "kx122.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -40,6 +41,8 @@ void sig_handler(int signo)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT,sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
kx122_context sensor = kx122_init(0,-1,24);
|
||||
if (!sensor)
|
||||
{
|
||||
@ -51,15 +54,18 @@ int main(int argc, char **argv)
|
||||
kx122_device_init(sensor,KX122_ODR_50,HIGH_RES,KX122_RANGE_2G);
|
||||
|
||||
float x,y,z;
|
||||
float wait_time = (kx122_get_sample_period(sensor) * MICRO_S);
|
||||
int wait_time = (kx122_get_sample_period(sensor) * MICRO_S);
|
||||
if (wait_time < 0) wait_time = 1000;
|
||||
|
||||
while(shouldRun){
|
||||
kx122_get_acceleration_data(sensor,&x,&y,&z);
|
||||
|
||||
printf("%.02f | %.02f | %.02f\n",x,y,z);
|
||||
usleep(wait_time);
|
||||
upm_delay_us(wait_time);
|
||||
}
|
||||
|
||||
kx122_close(sensor);
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace upm{
|
||||
void deviceInit(KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange);
|
||||
|
||||
/**
|
||||
Gets the length of one sample period depeding on the sampling rate of the sensor.
|
||||
Gets the length of one sample period depending on the sampling rate of the sensor.
|
||||
@return Floating point value of the sampling period, or if error occurs returns -1.
|
||||
*/
|
||||
float getSamplePeriod();
|
||||
@ -310,11 +310,11 @@ namespace upm{
|
||||
void routeInterrupt2(uint8_t bits);
|
||||
|
||||
/**
|
||||
Gets the status of the interrupts. (Has an interrupt occured)
|
||||
Gets the status of the interrupts. (Has an interrupt occurred)
|
||||
|
||||
See datasheet for more details.
|
||||
|
||||
@return Return true if an interrupt event has occured, returns false if no interrupts have occured.
|
||||
@return Return true if an interrupt event has occurred, returns false if no interrupts have occurred.
|
||||
*/
|
||||
bool getInterruptStatus();
|
||||
|
||||
@ -322,9 +322,9 @@ namespace upm{
|
||||
Gets the source of the interrupt.
|
||||
|
||||
The value stored is one or more of the KX122_INTERRUPT_T values, depending on the interrupts
|
||||
that have occured.
|
||||
that have occurred.
|
||||
|
||||
If multiple interrupts have occured, and you need to determine a specific interrupt,
|
||||
If multiple interrupts have occurred, and you need to determine a specific interrupt,
|
||||
you can use masking to get the state of the specific interrupt:
|
||||
(int_source & KX122_DATA_READY_INT) == KX122_DATA_READY_INT)
|
||||
|
||||
@ -419,7 +419,7 @@ namespace upm{
|
||||
|
||||
/**
|
||||
Sets the buffer resolution.
|
||||
Buffer resolution is indepedent of the sensor resolution.
|
||||
Buffer resolution is independent of the sensor resolution.
|
||||
|
||||
Sensor needs to be in standby mode when setting the buffer resolution.
|
||||
|
||||
@ -431,7 +431,7 @@ namespace upm{
|
||||
Sets the buffer watermark interrupt threshold.
|
||||
When the buffer sample count reaches the watermark, watermark interrupt will be given.
|
||||
|
||||
In low resolution mode, maxiumum number of samples is 681. In high resolution, the maximum
|
||||
In low resolution mode, maximum number of samples is 681. In high resolution, the maximum
|
||||
number is 340.
|
||||
|
||||
See datasheet for more details.
|
||||
@ -446,7 +446,7 @@ namespace upm{
|
||||
/**
|
||||
Sets the buffer operating mode.
|
||||
The buffer can operate in FIFO,FILO or Stream mode.
|
||||
The buffer gathers data, reports data and interracts with the status indicators
|
||||
The buffer gathers data, reports data and interacts with the status indicators
|
||||
in a slightly different way depending on the operating mode.
|
||||
|
||||
See datasheet for more details.
|
||||
@ -469,7 +469,7 @@ namespace upm{
|
||||
/**
|
||||
Gets the specified amount of raw acceleration samples from the buffer.
|
||||
|
||||
Make sure the array size is atleast the amount of samples to be read.
|
||||
Make sure the array size is at least the amount of samples to be read.
|
||||
|
||||
@param len The amount of samples to read from the buffer.
|
||||
@param x_array Pointer to an floating point array to store the x-axis data. Can be set to NULL if not wanted.
|
||||
@ -482,7 +482,7 @@ namespace upm{
|
||||
/**
|
||||
Gets the specified amount of converted (m/s^2) acceleration samples from the buffer.
|
||||
|
||||
Make sure the array size is atleast the amount of samples to be read.
|
||||
Make sure the array size is at least the amount of samples to be read.
|
||||
|
||||
@param len The amount of samples to read from the buffer.
|
||||
@param x_array Pointer to an floating point array to store the x-axis data. Can be set to NULL if not wanted.
|
||||
|
Loading…
x
Reference in New Issue
Block a user