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

Public Member Functions

 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 ()
 

Constructor & Destructor Documentation

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
busI2C or SPI bus to use.
addrI2C address of the sensor.
chip_selectChip select pin for SPI.
spi_bus_frequencySpeed of the SPI communication bus in Hz.
Exceptions
std::runtime_erroron initialization failure.
~KX122 ( )

KX122 destructor

Here is the call graph for this function:

Member Function Documentation

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
odrOne of the KX122_ODR_T values.
resOne of the KX122_RES_T values.
grangeOne of the KX122_RANGE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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.

Here is the call graph for this function:

uint8_t getWhoAmI ( )

Gets who am i value of the sensor.

Returns
Who am I value of the sensor.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void getRawAccelerationData ( float *  x,
float *  y,
float *  z 
)

Gets raw accelerometer data from the sensor.

Parameters
xPointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted.
yPointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted.
zPointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void getAccelerationData ( float *  x,
float *  y,
float *  z 
)

Gets converted (m/s^2) accelerometer data from the sensor.

Parameters
xPointer to a floating point variable to store the x-axis value. Can be set to NULL if not wanted.
yPointer to a floating point variable to store the y-axis value. Can be set to NULL if not wanted.
zPointer to a floating point variable to store the z-axis value. Can be set to NULL if not wanted.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< float > getAccelerationDataVector ( )

Gets converted (m/s^2) accelerometer data from the sensor.

Returns
Acceleration vector [X, Y, Z]
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void softwareReset ( )

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

Here is the call graph for this function:

void enableIIR ( )

Enables sensor filter bypass.

Sensor needs to be in standby mode when enabling the filter bypass.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void disableIIR ( )

Disables sensor filter bypass.

Sensor needs to be in standby mode when enabling the filter bypass.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void selfTest ( )

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

Here is the call graph for this function:

void setSensorStandby ( )

Sets the sensor to the standby mode.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setSensorActive ( )

Sets the sensor to the active mode.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void setODR ( KX122_ODR_T  odr)

Sets the ODR of the sensor.

Sensor needs to be in standby mode when setting the ODR.

Parameters
odrOne of the KX122_ODR_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
grangeOne of the KX122_RANGE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
resOne of the KX122_RES_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
lproOne of the LPRO_STATE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
avgOne of the KX122_AVG_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
edgeOne of the mraa::Edge values. Interrupt trigger edge.
intpOne of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin you are setting.
pinThe GPIO pin to use as the interrupt pin.
isrPointer to the function to be called, when the interrupt occurs.
argThe arguments to be passed to the function.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void uninstallISR ( KX122_INTERRUPT_PIN_T  intp)

Uninstalls a previously installed interrupt handler.

Parameters
intpOne of the KX122_INTERRUPT_PIN_T values. Specifies which interrupt pin handler is uninstalled.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
polarityOne of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
polarityOne of the KX122_INTERRUPT_POLARITY_T values. Select the polarity of the interrupt.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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
bitsOne or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|)
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
bitsOne or more of the KX122_INTERRUPT_T values. Combine with bitwise OR (|)
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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.

Here is the call graph for this function:

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

Here is the call graph for this function:

void clearInterrupt ( )

Clears latching interrupts (Wakeup, Data Ready).

See datasheet for more details.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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

Here is the call graph for this function:

void disableDataReadyInterrupt ( )

Disables the data ready interrupt.

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

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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

Here is the call graph for this function:

void disableBufferFullInterrupt ( )

Disables the buffer full interrupt.

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

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void enableBuffer ( )

Enables the buffer.

Sensor needs to be in standby mode when enabling the buffer.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void disableBuffer ( )

Disables the buffer.

Sensor needs to be in standby mode when disabling the buffer.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
samplesAmount of samples to trigger the watermark interrupt.
resOne of the KX122_RES_T values.
modeOne of the KX122_BUFFER_MODE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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

Here is the call graph for this function:

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
samplesAmount of samples to trigger the watermark interrupt.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

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
modeOne of the KX122_BUFFER_MODE_T values.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint getBufferStatus ( )

Gets the current amount of samples in the buffer.

Returns
number of samples in the buffer.
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

std::vector< float > getRawBufferSamples ( uint  len)

Gets the specified amount of raw acceleration samples from the buffer.

Parameters
lenThe amount of samples to read from the buffer.
Returns
vector containing x, y & z-axis data
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

std::vector< float > getBufferSamples ( uint  len)

Gets the specified amount of converted (m/s^2) acceleration samples from the buffer.

Parameters
lenThe amount of samples to read from the buffer.
Returns
vector containing x, y & z-axis data
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

void clearBuffer ( )

Clears the buffer, removing all existing samples from the buffer.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:


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