|
| KX122 (int bus, int addr, int chip_select, int spi_bus_frequency=DEFAULT_SPI_FREQUENCY) |
|
| ~KX122 () |
|
void | deviceInit (KX122_ODR_T odr, KX122_RES_T res, KX122_RANGE_T grange) |
|
float | getSamplePeriod () |
|
uint8_t | getWhoAmI () |
|
void | getRawAccelerationData (float *x, float *y, float *z) |
|
void | getAccelerationData (float *x, float *y, float *z) |
|
std::vector< float > | getAccelerationDataVector () |
|
void | softwareReset () |
|
void | enableIIR () |
|
void | disableIIR () |
|
void | selfTest () |
|
void | setSensorStandby () |
|
void | setSensorActive () |
|
void | setODR (KX122_ODR_T odr) |
|
void | setGrange (KX122_RANGE_T grange) |
|
void | setResolution (KX122_RES_T res) |
|
void | setBW (LPRO_STATE_T lpro) |
|
void | setAverage (KX122_AVG_T avg) |
|
void | installISR (mraa::Edge edge, KX122_INTERRUPT_PIN_T intp, int pin, void(*isr)(void *), void *arg) |
|
void | uninstallISR (KX122_INTERRUPT_PIN_T intp) |
|
void | enableInterrupt1 (KX122_INTERRUPT_POLARITY_T polarity) |
|
void | enableInterrupt2 (KX122_INTERRUPT_POLARITY_T polarity) |
|
void | disableInterrupt1 () |
|
void | disableInterrupt2 () |
|
void | routeInterrupt1 (uint8_t bits) |
|
void | routeInterrupt2 (uint8_t bits) |
|
bool | getInterruptStatus () |
|
uint8_t | getInterruptSource () |
|
void | clearInterrupt () |
|
void | enableDataReadyInterrupt () |
|
void | disableDataReadyInterrupt () |
|
void | enableBufferFullInterrupt () |
|
void | disableBufferFullInterrupt () |
|
void | enableBuffer () |
|
void | disableBuffer () |
|
void | bufferInit (uint samples, KX122_RES_T res, KX122_BUFFER_MODE_T mode) |
|
void | setBufferResolution (KX122_RES_T res) |
|
void | setBufferThreshold (uint samples) |
|
void | setBufferMode (KX122_BUFFER_MODE_T mode) |
|
uint | getBufferStatus () |
|
std::vector< float > | getRawBufferSamples (uint len) |
|
std::vector< float > | getBufferSamples (uint len) |
|
void | clearBuffer () |
|
KX122 |
( |
int |
bus, |
|
|
int |
addr, |
|
|
int |
chip_select, |
|
|
int |
spi_bus_frequency = DEFAULT_SPI_FREQUENCY |
|
) |
| |
KX122 constructor Set addr to -1 if using SPI. When using I2C, set chip_select_pin to -1
If no errors occur, the device gets initialized with default values and gets set to active state.
- Parameters
-
bus | I2C or SPI bus to use. |
addr | I2C address of the sensor. |
chip_select | Chip select pin for SPI. |
spi_bus_frequency | Speed of the SPI communication bus in Hz. |
- Exceptions
-
std::runtime_error | on initialization failure. |
void deviceInit |
( |
KX122_ODR_T |
odr, |
|
|
KX122_RES_T |
res, |
|
|
KX122_RANGE_T |
grange |
|
) |
| |
Initializes the sensor with given sampling rate, resolution and acceleration range. This gets called in the constructor, so it will not need to be called unless the device is reset.
Sensor is automatically set into standby mode during the initialization. Sensor is set to active mode after initialization.
- Parameters
-
odr | One of the KX122_ODR_T values. |
res | One of the KX122_RES_T values. |
grange | One of the KX122_RANGE_T values. |
- Exceptions
-
std::runtime_error | on failure. |
float getSamplePeriod |
( |
| ) |
|
Gets the length of one sample period depending on the sampling rate of the sensor.
- Returns
- Floating point value of the sampling period, or if error occurs returns -1.
Gets who am i value of the sensor.
- Returns
- Who am I value of the sensor.
- Exceptions
-
std::runtime_error | on failure. |
void getRawAccelerationData |
( |
float * |
x, |
|
|
float * |
y, |
|
|
float * |
z |
|
) |
| |
Gets raw accelerometer data from the sensor.
- Parameters
-
x | Pointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted. |
y | Pointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted. |
z | Pointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted. |
- Exceptions
-
std::runtime_error | on failure. |
void getAccelerationData |
( |
float * |
x, |
|
|
float * |
y, |
|
|
float * |
z |
|
) |
| |
Gets converted (m/s^2) accelerometer data from the sensor.
- Parameters
-
x | Pointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted. |
y | Pointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted. |
z | Pointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted. |
- Exceptions
-
std::runtime_error | on failure. |
std::vector< float > getAccelerationDataVector |
( |
| ) |
|
Gets converted (m/s^2) accelerometer data from the sensor.
- Returns
- Acceleration vector [X, Y, Z]
- Exceptions
-
std::runtime_error | on failure. |
Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers to pre-defined values.
You should call deviceInit() after the software reset.
See the datasheet for more details.
- Exceptions
-
std::runtime_error | on failure. |
Enables sensor filter bypass.
Sensor needs to be in standby mode when enabling the filter bypass.
- Exceptions
-
std::runtime_error | on failure. |
Disables sensor filter bypass.
Sensor needs to be in standby mode when enabling the filter bypass.
- Exceptions
-
std::runtime_error | on failure. |
Performs a self-test of the sensor. The test applies an electrostatic force to the sensor, simulating input acceleration. The test compares samples from all axis before and after applying the electrostatic force to the sensor. If the amount of acceleration increases according to the values defined in TABLE 1 of the datasheet, the test passes.
The function prints out the minimum, maximum and values calculated during the test for each axis, and the result of the test for each axis.
See the datasheet for more information.
- Exceptions
-
std::runtime_error | on failure. |
void setSensorStandby |
( |
| ) |
|
Sets the sensor to the standby mode.
- Exceptions
-
std::runtime_error | on failure. |
Sets the sensor to the active mode.
- Exceptions
-
std::runtime_error | on failure. |
void setODR |
( |
KX122_ODR_T |
odr | ) |
|
Sets the ODR of the sensor.
Sensor needs to be in standby mode when setting the ODR.
- Parameters
-
odr | One of the KX122_ODR_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void setGrange |
( |
KX122_RANGE_T |
grange | ) |
|
Sets the acceleration range of the sensor.
Sensor needs to be in standby mode when setting the acceleration range value.
- Parameters
-
grange | One of the KX122_RANGE_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void setResolution |
( |
KX122_RES_T |
res | ) |
|
Sets the resolution of the sensor. High resolution (16 bits) or low resolution (8 bits).
Sensor needs to be in standby mode when setting the sensor resolution.
When sensor is set to low resolution mode, the sensor runs in low power mode, which in turn enables features such as averaging.(setAverage()).
- Parameters
-
res | One of the KX122_RES_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void setBW |
( |
LPRO_STATE_T |
lpro | ) |
|
Sets the low pass filter roll off
Sensor needs to be in standby mode when setting the filter roll off value.
- Parameters
-
lpro | One of the LPRO_STATE_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void setAverage |
( |
KX122_AVG_T |
avg | ) |
|
Set the amount of samples to be averaged in low power mode.
Sensor needs to be in standby mode when setting the average value.
- Parameters
-
avg | One of the KX122_AVG_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void installISR |
( |
mraa::Edge |
edge, |
|
|
KX122_INTERRUPT_PIN_T |
intp, |
|
|
int |
pin, |
|
|
void(*)(void *) |
isr, |
|
|
void * |
arg |
|
) |
| |
Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin.
- Parameters
-
edge | One of the mraa::Edge values. Interrupt trigger edge. |
intp | One of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin you are setting. |
pin | The GPIO pin to use as the interrupt pin. |
isr | Pointer to the function to be called, when the interrupt occurs. |
arg | The arguments to be passed to the function. |
- Exceptions
-
std::runtime_error | on failure. |
void uninstallISR |
( |
KX122_INTERRUPT_PIN_T |
intp | ) |
|
Uninstalls a previously installed interrupt handler.
- Parameters
-
intp | One of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin handler is uninstalled. |
- Exceptions
-
std::runtime_error | on failure. |
void enableInterrupt1 |
( |
KX122_INTERRUPT_POLARITY_T |
polarity | ) |
|
Enables interrupts on the interrupt pin 1 of the sensor.
Pulse width = 50us (10us if data sampling rate > 1600Hz). Using pulse mode.
Sensor needs to be in standby mode when enabling the interrupt.
See datasheet for more details.
- Parameters
-
polarity | One of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt. |
- Exceptions
-
std::runtime_error | on failure. |
void enableInterrupt2 |
( |
KX122_INTERRUPT_POLARITY_T |
polarity | ) |
|
Enables interrupts on the interrupt pin 2 of the sensor.
Pulse width = 50us (10us if data sampling rate > 1600Hz). Using pulse mode.
Sensor needs to be in standby mode when enabling the interrupt.
See datasheet for more details.
- Parameters
-
polarity | One of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt. |
- Exceptions
-
std::runtime_error | on failure. |
void disableInterrupt1 |
( |
| ) |
|
Disables interrupts on the interrupt pin 1 of the sensor.
Sensor needs to be in standby mode when disabling the interrupt pin 1.
- Exceptions
-
std::runtime_error | on failure. |
void disableInterrupt2 |
( |
| ) |
|
Disables interrupts on the interrupt pin 2 of the sensor.
Sensor needs to be in standby mode when disabling the interrupt pin 2.
- Exceptions
-
std::runtime_error | on failure. |
void routeInterrupt1 |
( |
uint8_t |
bits | ) |
|
Routes the interrupts to the interrupt pin 1 of the sensor.
Sensor needs to be in standby mode when routing the interrupts.
See datasheet for more details.
- Parameters
-
bits | One or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|) |
- Exceptions
-
std::runtime_error | on failure. |
void routeInterrupt2 |
( |
uint8_t |
bits | ) |
|
Routes the interrupts to the interrupt pin 2 of the sensor.
Sensor needs to be in standby mode when routing the interrupts.
See datasheet for more details.
- Parameters
-
bits | One or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|) |
- Exceptions
-
std::runtime_error | on failure. |
bool getInterruptStatus |
( |
| ) |
|
Gets the status of the interrupts. (Has an interrupt occurred)
See datasheet for more details.
- Returns
- Return true if an interrupt event has occurred, returns false if no interrupts have occurred.
uint8_t getInterruptSource |
( |
| ) |
|
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 occurred.
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)
See datasheet for more details.
- Returns
- Interrupt source value.
- Exceptions
-
std::runtime_error | on failure. |
Clears latching interrupts (Wakeup, Data Ready).
See datasheet for more details.
- Exceptions
-
std::runtime_error | on failure. |
void enableDataReadyInterrupt |
( |
| ) |
|
Enables the data ready interrupt. Availability of new acceleration data is reflected as an interrupt.
Sensor needs to be in standby mode when enabling the interrupt.
- Exceptions
-
std::runtime_error | on failure. |
void disableDataReadyInterrupt |
( |
| ) |
|
Disables the data ready interrupt.
Sensor needs to be in standby mode when disabling the interrupt.
- Exceptions
-
std::runtime_error | on failure. |
void enableBufferFullInterrupt |
( |
| ) |
|
Enables the buffer full interrupt. Buffer can hold 681 sets of values (8 bit, low resolution mode) or 340 sets of values (16 bit, high resolution mode).
Sensor needs to be in standby mode when enabling the interrupt.
- Exceptions
-
std::runtime_error | on failure. |
void disableBufferFullInterrupt |
( |
| ) |
|
Disables the buffer full interrupt.
Sensor needs to be in standby mode when disabling the interrupt.
- Exceptions
-
std::runtime_error | on failure. |
Enables the buffer.
Sensor needs to be in standby mode when enabling the buffer.
- Exceptions
-
std::runtime_error | on failure. |
Disables the buffer.
Sensor needs to be in standby mode when disabling the buffer.
- Exceptions
-
std::runtime_error | on failure. |
void bufferInit |
( |
uint |
samples, |
|
|
KX122_RES_T |
res, |
|
|
KX122_BUFFER_MODE_T |
mode |
|
) |
| |
Initializes the buffer with the given sample watermark level, buffer resolution and buffer operating mode. Buffer is enabled after the initialization.
Sensor is automatically set into standby mode during the buffer initialization. Sensor is set to active mode after initialization.
See the other buffer functions for details about the different parameter values.
- Parameters
-
samples | Amount of samples to trigger the watermark interrupt. |
res | One of the KX122_RES_T values. |
mode | One of the KX122_BUFFER_MODE_T values. |
- Exceptions
-
std::runtime_error | on failure. |
void setBufferResolution |
( |
KX122_RES_T |
res | ) |
|
Sets the buffer resolution. Buffer resolution is independent of the sensor resolution.
Sensor needs to be in standby mode when setting the buffer resolution.
- Exceptions
-
std::runtime_error | on failure. |
void setBufferThreshold |
( |
uint |
samples | ) |
|
Sets the buffer watermark interrupt threshold. When the buffer sample count reaches the watermark, watermark interrupt will be given.
In low resolution mode, maximum number of samples is 681. In high resolution, the maximum number is 340.
See datasheet for more details.
Sensor needs to be in standby mode when setting the buffer threshold.
- Parameters
-
samples | Amount of samples to trigger the watermark interrupt. |
- Exceptions
-
std::runtime_error | on failure. |
void setBufferMode |
( |
KX122_BUFFER_MODE_T |
mode | ) |
|
Sets the buffer operating mode. The buffer can operate in FIFO,FILO or Stream mode. 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.
Sensor needs to be in standby mode when setting the buffer mode.
- Parameters
-
mode | One of the KX122_BUFFER_MODE_T values. |
- Exceptions
-
std::runtime_error | on failure. |
Gets the current amount of samples in the buffer.
- Returns
- number of samples in the buffer.
- Exceptions
-
std::runtime_error | on failure. |
std::vector< float > getRawBufferSamples |
( |
uint |
len | ) |
|
Gets the specified amount of raw acceleration samples from the buffer.
- Parameters
-
len | The amount of samples to read from the buffer. |
- Returns
- vector containing x, y & z-axis data
- Exceptions
-
std::runtime_error | on failure. |
std::vector< float > getBufferSamples |
( |
uint |
len | ) |
|
Gets the specified amount of converted (m/s^2) acceleration samples from the buffer.
- Parameters
-
len | The amount of samples to read from the buffer. |
- Returns
- vector containing x, y & z-axis data
- Exceptions
-
std::runtime_error | on failure. |
Clears the buffer, removing all existing samples from the buffer.
- Exceptions
-
std::runtime_error | on failure. |
The documentation for this class was generated from the following files: