upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions
KXTJ3 Class Reference

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...
 

Constructor & Destructor Documentation

KXTJ3 ( int  bus,
uint8_t  addr = 0x0f 
)

If no errors occur, the device is initialized with default values and set to active state

Parameters
busI2C bus
addrI2C address of the sensor
Exceptions
std::runtime_erroron initialization failure
~KXTJ3 ( )
virtual

Closes the I2C context, and removes interrupts Frees memory of the kxtj3_context

Exceptions
std::runtime_erroron initialization failure

Member Function Documentation

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.

Parameters
odrOne of the KXTJ3_ODR_T values
resolutionOne of the KXTJ3_RESOLUTION_T values
g_rangeOne of the KXTJ3_G_RANGE_T values
Exceptions
std::runtime_erroron failure
uint8_t GetWhoAmI ( )
Returns
Who am I value of the sensor
Exceptions
std::runtime_erroron failure
void SensorActive ( )
Exceptions
std::runtime_erroron failure
void SensorStandby ( )
Exceptions
std::runtime_erroron 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

Parameters
g_rangeOne of the KXTJ3_G_RANGE_T values
Exceptions
std::runtime_erroron 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

Parameters
resolutionOne of the KXTJ3_RESOLUTION_T values
Exceptions
std::runtime_erroron failure
void SetOdr ( KXTJ3_ODR_T  odr)

Sensor needs to be in standby mode when setting the ODR

Parameters
odrOne of the KXTJ3_ODR_T values
Exceptions
std::runtime_erroron failure
void SetOdrForWakeup ( KXTJ3_ODR_WAKEUP_T  odr)

Sensor needs to be in standby mode when setting the ODR

Parameters
odrOne of the KXTJ3_ODR_WAKEUP_T values
Exceptions
std::runtime_erroron failure
void SelfTestDigitalCommunication ( )

This method is called by SensorSelfTest also

Sensor must be in standby mode before performing this action

Exceptions
std::runtime_erroron 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

Exceptions
std::runtime_erroron failure
void SensorSoftwareReset ( )

You should call kxtj3_sensor_init() after the software reset

See the datasheet for more details

Exceptions
std::runtime_erroron failure
std::vector< float > GetAccelerationRawVector ( )

Gets raw acceleration data from the sensor.

Returns
Acceleration vector [x, y, z]
Exceptions
std::runtime_erroron failure.
std::vector< float > GetAccelerationVector ( )

Gets acceleration data in (m/s^2) from the sensor.

Returns
Acceleration vector [x, y, z]
Exceptions
std::runtime_erroron failure.
float GetAccelerationSamplePeriod ( )
Returns
Floating point value of the sampling period
Exceptions
std::runtime_erroron failure
float GetWakeUpSamplePeriod ( )
Returns
Floating point value of the sampling period
Exceptions
std::runtime_erroron failure
void EnableDataReadyInterrupt ( )

Sensor must be in standby mode before performing this action

Exceptions
std::runtime_erroron failure
void DisableDataReadyInterrupt ( )

Sensor must be in standby mode before performing this action

Exceptions
std::runtime_erroron failure
void EnableWakeUpInterrupt ( )

Sensor must be in standby mode before performing this action

Exceptions
std::runtime_erroron failure
void DisableWakeUpInterrupt ( )

Sensor must be in standby mode before performing this action

Exceptions
std::runtime_erroron 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

Parameters
polaritySelect the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
response_typeSelect the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
Exceptions
std::runtime_erroron failure
void DisableInterruptPin ( )

Sensor needs to be in standby mode when disabling the interrupt pin

Exceptions
std::runtime_erroron failure
void SetInterruptPolarity ( KXTJ3_INTERRUPT_POLARITY_T  polarity)

Polarity ACTIVE_HIGH or ACTIVE_LOW

Sensor must be in standby mode before performing this action

Parameters
polaritySelect the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
Exceptions
std::runtime_erroron 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

Parameters
response_typeSelect the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values
Exceptions
std::runtime_erroron failure
bool GetInterruptStatus ( )

See datasheet for more details

Returns
Return true if an interrupt event has occurred (DRDY or WUFS is 1), returns false if no interrupts have occurred
uint8_t ReadInterruptSource1 ( )

See datasheet for more details

Returns
Value of the interrupt source register
Exceptions
std::runtime_erroron failure
KXTJ3_INTERRUPT_SOURCE_T GetInterruptSource ( )

See datasheet for more details

Returns
One of the KXTJ3_INTERRUPT_SOURCE_T values/types
void InstallIsr ( mraa_gpio_edge_t  edge,
int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
edgeOne of the mraa_gpio_edge_t values. Interrupt trigger edge.
pinThe GPIO pin to use as the interrupt pin
isrPointer to the method to be called, when the interrupt occurs
isr_argsThe arguments to be passed to the method
Returns
std::runtime_error on failure
void UninstallIsr ( )
Exceptions
std::runtime_erroron failure
void ClearInterrupt ( )

See datasheet for more details

Exceptions
std::runtime_erroron failure
void EnableWakeUpSingleAxisDirection ( KXTJ3_WAKEUP_SOURCE_T  axis)

Sensor must be in standby mode before performing this action

Parameters
axisThe axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
Exceptions
std::runtime_erroron failure
void DisableWakeUpSingleAxisDirection ( KXTJ3_WAKEUP_SOURCE_T  axis)

Sensor must be in standby mode before performing this action

Parameters
axisThe axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
Exceptions
std::runtime_erroron failure
kxtj3_wakeup_axes GetWakeUpAxisDirection ( )

See datasheet for more details

Returns
A kxtj3_wakeup_axes struct with values of true/false for a wakeup for each axis and its direction
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

Exceptions
std::runtime_erroron 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.

Exceptions
std::runtime_erroron 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

Parameters
countThe timer count from 1 to 255
Exceptions
std::runtime_erroron 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

Parameters
desired_timeThe desired time in seconds
Exceptions
std::runtime_erroron failure
float GetWakeUpMotionTime ( )
Returns
Time value in seconds
Exceptions
std::runtime_erroron 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

Parameters
countThe timer count from 1 to 255
Exceptions
std::runtime_erroron 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

Parameters
desired_timeThe desired time in seconds
Exceptions
std::runtime_erroron failure
float GetWakeUpNonActivityTime ( )
Returns
Time value in seconds
Exceptions
std::runtime_erroron 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

Parameters
countThe timer count from 1 to 4096, that it is 16g threshold with (3.9mg/count)
Exceptions
std::runtime_erroron 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

Parameters
g_thresholdThe acceleration threshold (in g) in g, from 3.9mg to 16g, steps of 3.9mg/count.
Exceptions
std::runtime_erroron failure
float GetWakeUpThresholdGRange ( )
Returns
Threshold value in g
Exceptions
std::runtime_erroron failure

The documentation for this class was generated from the following files: