upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
Public Member Functions | |
KXTJ3 (int bus, uint8_t addr=0x0f) | |
KXTJ3 constructor. More... | |
virtual | ~KXTJ3 () |
KXTJ3 destructor. More... | |
void | SensorInit (KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T resolution, KXTJ3_G_RANGE_T g_range) |
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. More... | |
uint8_t | GetWhoAmI () |
Gets "who am I" value of the sensor. More... | |
void | SensorActive () |
Sets the sensor to active mode. More... | |
void | SensorStandby () |
Sets the sensor to standby mode. More... | |
void | SetGRange (KXTJ3_G_RANGE_T g_range) |
Sets the acceleration range of the sensor. More... | |
void | SetResolution (KXTJ3_RESOLUTION_T resolution) |
Sets the resolution of the sensor. High resolution (14 bits and 12 bits) or low resolution (8 bits). More... | |
void | SetOdr (KXTJ3_ODR_T odr) |
Sets the ODR of the sensor. More... | |
void | SetOdrForWakeup (KXTJ3_ODR_WAKEUP_T odr) |
Sets the ODR of the wakeup function of the sensor. More... | |
void | SelfTestDigitalCommunication () |
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. More... | |
void | SensorSelfTest () |
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 (0.5 g), the test passes. More... | |
void | SensorSoftwareReset () |
Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers to pre-defined values. More... | |
std::vector< float > | GetAccelerationRawVector () |
std::vector< float > | GetAccelerationVector () |
float | GetAccelerationSamplePeriod () |
Gets the duration of one sample period (in seconds) for getting the acceleration data depending on the sampling rate of the sensor. More... | |
float | GetWakeUpSamplePeriod () |
Gets the duration of one sample period (in seconds) for the wakeup function depending on the sampling rate of the sensor wakeup function. More... | |
void | EnableDataReadyInterrupt () |
Enables the data ready interrupt. Availability of new acceleration data is reflected as an interrupt. More... | |
void | DisableDataReadyInterrupt () |
Disables the data ready interrupt. More... | |
void | EnableWakeUpInterrupt () |
Enables the wakeup function (motion detection) More... | |
void | DisableWakeUpInterrupt () |
Disables the wakeup function (motion detection) More... | |
void | EnableInterruptPin (KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type) |
Enables interrupts on the interrupt pin, sets polarity and response types. Polarity ACTIVE_HIGH or ACTIVE_LOW. Response either latch until cleared by reading INT_REL register, or transmit one pulse Pulse width of 0.03-0.05ms. More... | |
void | DisableInterruptPin () |
Disables interrupts on the interrupt pin of the sensor. More... | |
void | SetInterruptPolarity (KXTJ3_INTERRUPT_POLARITY_T polarity) |
Sets the polarity of the interrupt pin. More... | |
void | SetInerruptResponse (KXTJ3_INTERRUPT_RESPONSE_T response_type) |
Sets the response type of the interrupt pin. More... | |
bool | GetInterruptStatus () |
Gets the status of the interrupts. (Has an interrupt occurred) More... | |
uint8_t | ReadInterruptSource1 () |
Gets the source of the interrupt The value stored is one or more of the KXTJ3_INTERRUPT_SOURCE_T values. More... | |
KXTJ3_INTERRUPT_SOURCE_T | GetInterruptSource () |
Gets the source of the interrupt. More... | |
void | InstallIsr (mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args) |
Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin. More... | |
void | UninstallIsr () |
Uninstalls a previously installed interrupt handler for interrupt pin. More... | |
void | ClearInterrupt () |
Clears latching interrupts information of Wakeup (with axis and direction information) and Data Ready. More... | |
void | EnableWakeUpSingleAxisDirection (KXTJ3_WAKEUP_SOURCE_T axis) |
Enables wakeup interrupt for the given axis (axis with direction) More... | |
void | DisableWakeUpSingleAxisDirection (KXTJ3_WAKEUP_SOURCE_T axis) |
Disables wakeup interrupt for the given axis (axis with direction) More... | |
kxtj3_wakeup_axes | GetWakeUpAxisDirection () |
Gets the source axis and direction of motion detection of the wakeup function interrupt. More... | |
void | EnableWakeUpLatch () |
Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled. More... | |
void | DisableWakeUpLatch () |
Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled. (cannot use interrupt response with pulse) More... | |
void | SetWakeUpMotionCounter (uint8_t count) |
Sets the timer counter of motion before sending a wakeup interrupt. More... | |
void | SetWakeUpMotionTime (float desired_time) |
Sets the timer of motion before sending a wakeup interrupt. More... | |
float | GetWakeUpMotionTime () |
Get the current count value of the timer of motion before sending a wakeup interrupt. More... | |
void | SetWakeUpNonActivityCounter (uint8_t count) |
Sets the timer counter of non-activity before sending another wakeup interrupt. More... | |
void | SetWakeUpNonActivityTime (float desired_time) |
Sets the timer of non-activity before sending another wakeup interrupt. More... | |
float | GetWakeUpNonActivityTime () |
Get the current count value of the timer of non-activity before sending another wakeup interrupt. More... | |
void | SetWakeUpThresholdCounter (uint16_t count) |
Sets the threshold counter for acceleration difference before sending a wakeup interrupt. More... | |
void | SetWakeUpThresholdGRange (float g_threshold) |
Sets the threshold g value for acceleration difference before sending a wakeup interrupt. More... | |
float | GetWakeUpThresholdGRange () |
Get the current threshold difference value before sending wakeup interrupt. More... | |
KXTJ3 | ( | int | bus, |
uint8_t | addr = 0x0f |
||
) |
If no errors occur, the device is initialized with default values and set to active state
bus | I2C bus |
addr | I2C address of the sensor |
std::runtime_error | on initialization failure |
|
virtual |
Closes the I2C context, and removes interrupts Frees memory of the kxtj3_context
std::runtime_error | on initialization failure |
void SensorInit | ( | KXTJ3_ODR_T | odr, |
KXTJ3_RESOLUTION_T | resolution, | ||
KXTJ3_G_RANGE_T | g_range | ||
) |
Sensor is set to standby mode during the initialization and back to active after initialization.
odr | One of the KXTJ3_ODR_T values |
resolution | One of the KXTJ3_RESOLUTION_T values |
g_range | One of the KXTJ3_G_RANGE_T values |
std::runtime_error | on failure |
uint8_t GetWhoAmI | ( | ) |
std::runtime_error | on failure |
void SensorActive | ( | ) |
std::runtime_error | on failure |
void SensorStandby | ( | ) |
std::runtime_error | on failure |
void SetGRange | ( | KXTJ3_G_RANGE_T | g_range | ) |
Sensor needs to be in standby mode when setting the acceleration range value
Be cautious not to set g_range to 14-bits modes with the resolution being on LOW_RES
g_range | One of the KXTJ3_G_RANGE_T values |
std::runtime_error | on failure |
void SetResolution | ( | KXTJ3_RESOLUTION_T | resolution | ) |
LOW_RES valid only for ODR <= 200 Hz
Be cautious not to set resolution to LOW_RES with the G_RANG being on 14-bits modes
Sensor needs to be in standby mode when setting the sensor resolution
resolution | One of the KXTJ3_RESOLUTION_T values |
std::runtime_error | on failure |
void SetOdr | ( | KXTJ3_ODR_T | odr | ) |
Sensor needs to be in standby mode when setting the ODR
odr | One of the KXTJ3_ODR_T values |
std::runtime_error | on failure |
void SetOdrForWakeup | ( | KXTJ3_ODR_WAKEUP_T | odr | ) |
Sensor needs to be in standby mode when setting the ODR
odr | One of the KXTJ3_ODR_WAKEUP_T values |
std::runtime_error | on failure |
void SelfTestDigitalCommunication | ( | ) |
This method is called by SensorSelfTest also
Sensor must be in standby mode before performing this action
std::runtime_error | on failure |
void SensorSelfTest | ( | ) |
The method prints out the values before and during test and the average difference for each axis
See the datasheet for more information
std::runtime_error | on failure |
void SensorSoftwareReset | ( | ) |
You should call kxtj3_sensor_init() after the software reset
See the datasheet for more details
std::runtime_error | on failure |
std::vector< float > GetAccelerationRawVector | ( | ) |
Gets raw acceleration data from the sensor.
std::runtime_error | on failure. |
std::vector< float > GetAccelerationVector | ( | ) |
Gets acceleration data in (m/s^2) from the sensor.
std::runtime_error | on failure. |
float GetAccelerationSamplePeriod | ( | ) |
std::runtime_error | on failure |
float GetWakeUpSamplePeriod | ( | ) |
std::runtime_error | on failure |
void EnableDataReadyInterrupt | ( | ) |
Sensor must be in standby mode before performing this action
std::runtime_error | on failure |
void DisableDataReadyInterrupt | ( | ) |
Sensor must be in standby mode before performing this action
std::runtime_error | on failure |
void EnableWakeUpInterrupt | ( | ) |
Sensor must be in standby mode before performing this action
std::runtime_error | on failure |
void DisableWakeUpInterrupt | ( | ) |
Sensor must be in standby mode before performing this action
std::runtime_error | on failure |
void EnableInterruptPin | ( | KXTJ3_INTERRUPT_POLARITY_T | polarity, |
KXTJ3_INTERRUPT_RESPONSE_T | response_type | ||
) |
For Wakeup function, the response type is always latched unless set wakeup latch off Sensor needs to be in standby mode when enabling the interrupt
See datasheet for more details
polarity | Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values. |
response_type | Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values. |
std::runtime_error | on failure |
void DisableInterruptPin | ( | ) |
Sensor needs to be in standby mode when disabling the interrupt pin
std::runtime_error | on failure |
void SetInterruptPolarity | ( | KXTJ3_INTERRUPT_POLARITY_T | polarity | ) |
Polarity ACTIVE_HIGH or ACTIVE_LOW
Sensor must be in standby mode before performing this action
polarity | Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values. |
std::runtime_error | on failure |
void SetInerruptResponse | ( | KXTJ3_INTERRUPT_RESPONSE_T | response_type | ) |
Response either latch until cleared by reading INT_REL register, or transmit one pulse Pulse width of 0.03-0.05ms
For Wakeup function, the response type is always latched unless set wakeup latch off
Sensor must be in standby mode before performing this action
See datasheet for more details
response_type | Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values |
std::runtime_error | on failure |
bool GetInterruptStatus | ( | ) |
See datasheet for more details
uint8_t ReadInterruptSource1 | ( | ) |
See datasheet for more details
std::runtime_error | on failure |
KXTJ3_INTERRUPT_SOURCE_T GetInterruptSource | ( | ) |
See datasheet for more details
void InstallIsr | ( | mraa_gpio_edge_t | edge, |
int | pin, | ||
void(*)(void *) | isr, | ||
void * | isr_args | ||
) |
edge | One of the mraa_gpio_edge_t values. Interrupt trigger edge. |
pin | The GPIO pin to use as the interrupt pin |
isr | Pointer to the method to be called, when the interrupt occurs |
isr_args | The arguments to be passed to the method |
void UninstallIsr | ( | ) |
std::runtime_error | on failure |
void ClearInterrupt | ( | ) |
See datasheet for more details
std::runtime_error | on failure |
void EnableWakeUpSingleAxisDirection | ( | KXTJ3_WAKEUP_SOURCE_T | axis | ) |
Sensor must be in standby mode before performing this action
axis | The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value |
std::runtime_error | on failure |
void DisableWakeUpSingleAxisDirection | ( | KXTJ3_WAKEUP_SOURCE_T | axis | ) |
Sensor must be in standby mode before performing this action
axis | The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value |
std::runtime_error | on failure |
kxtj3_wakeup_axes GetWakeUpAxisDirection | ( | ) |
See datasheet for more details
void EnableWakeUpLatch | ( | ) |
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
std::runtime_error | on failure |
void DisableWakeUpLatch | ( | ) |
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 output will not reset until data is read or interrupt cleared.
std::runtime_error | on failure |
void SetWakeUpMotionCounter | ( | uint8_t | count | ) |
The count is limited to values from 1 to 255
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
Sensor must be in standby mode before performing this action
See datasheet for more details
count | The timer count from 1 to 255 |
std::runtime_error | on failure |
void SetWakeUpMotionTime | ( | float | desired_time | ) |
the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
Sensor must be in standby mode before performing this action
See datasheet for more details
desired_time | The desired time in seconds |
std::runtime_error | on failure |
float GetWakeUpMotionTime | ( | ) |
std::runtime_error | on failure |
void SetWakeUpNonActivityCounter | ( | uint8_t | count | ) |
The count is limited to values from 1 to 255
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
Sensor must be in standby mode before performing this action
See datasheet for more details
count | The timer count from 1 to 255 |
std::runtime_error | on failure |
void SetWakeUpNonActivityTime | ( | float | desired_time | ) |
the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
Sensor must be in standby mode before performing this action
See datasheet for more details
desired_time | The desired time in seconds |
std::runtime_error | on failure |
float GetWakeUpNonActivityTime | ( | ) |
std::runtime_error | on failure |
void SetWakeUpThresholdCounter | ( | uint16_t | count | ) |
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 in the wakeup interrupt
Sensor must be in standby mode before performing this action
See datasheet for more details
count | The timer count from 1 to 4096, that it is 16g threshold with (3.9mg/count) |
std::runtime_error | on failure |
void SetWakeUpThresholdGRange | ( | float | g_threshold | ) |
The count is limited to values up to 16g, with steps of 3.9mg. 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
See datasheet for more details
g_threshold | The acceleration threshold (in g) in g, from 3.9mg to 16g, steps of 3.9mg/count. |
std::runtime_error | on failure |
float GetWakeUpThresholdGRange | ( | ) |
std::runtime_error | on failure |