upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the LIS2DS12 3-axis Accelerometer. More...
The LIS2DS12 is an ultra-low-power high performance three-axis linear accelerometer belonging to the "pico" family which leverages on the robust and mature manufacturing processes already used for the production of micromachined accelerometers.
The LIS2DS12 has user-selectable full scales of 2g/4g/8g/16g and is capable of measuring accelerations with output data rates from 1 Hz to 6400 Hz.
Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.
This device requires 1.8v operation.
Public Member Functions | |
LIS2DS12 (int bus=LIS2DS12_DEFAULT_I2C_BUS, int addr=LIS2DS12_DEFAULT_I2C_ADDR, int cs=-1) | |
virtual | ~LIS2DS12 () |
void | update () |
uint8_t | getChipID () |
void | getAccelerometer (float *x, float *y, float *z) |
std::vector< float > | getAccelerometer () |
float | getTemperature (bool fahrenheit=false) |
void | init (LIS2DS12_ODR_T odr=LIS2DS12_ODR_100HZ, LIS2DS12_FS_T fs=LIS2DS12_FS_2G) |
void | reset () |
void | setODR (LIS2DS12_ODR_T odr) |
void | setFullScale (LIS2DS12_FS_T fs) |
void | enableHPFiltering (bool filter) |
void | enableInterruptLatching (bool latch) |
void | setInterruptActiveHigh (bool high) |
void | setInterruptPushPull (bool pp) |
void | setInt1Config (uint8_t cfg) |
void | setInt2Config (uint8_t cfg) |
uint8_t | getStatus () |
void | installISR (LIS2DS12_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg) |
void | uninstallISR (LIS2DS12_INTERRUPT_PINS_T intr) |
uint8_t | readReg (uint8_t reg) |
int | readRegs (uint8_t reg, uint8_t *buffer, int len) |
void | writeReg (uint8_t reg, uint8_t val) |
Protected Attributes | |
lis2ds12_context | m_lis2ds12 |
LIS2DS12 | ( | int | bus = LIS2DS12_DEFAULT_I2C_BUS , |
int | addr = LIS2DS12_DEFAULT_I2C_ADDR , |
||
int | cs = -1 |
||
) |
LIS2DS12 constructor.
This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin (like edison with arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.
bus | I2C or SPI bus to use |
addr | The address for this device. -1 for SPI |
cs | The gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin. |
std::runtime_error | on initialization failure |
void update | ( | void | ) |
Update the internal stored values from sensor data
std::runtime_error | on failure |
uint8_t getChipID | ( | ) |
Return the chip ID
void getAccelerometer | ( | float * | x, |
float * | y, | ||
float * | z | ||
) |
Return accelerometer data in gravities. update() must have been called prior to calling this method.
x | Pointer to a floating point value that will have the current x component placed into it |
y | Pointer to a floating point value that will have the current y component placed into it |
z | Pointer to a floating point value that will have the current z component placed into it |
std::vector< float > getAccelerometer | ( | ) |
Return accelerometer data in gravities in the form of a floating point vector. update() must have been called prior to calling this method.
float getTemperature | ( | bool | fahrenheit = false | ) |
Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.
fahrenheit | true to return data in Fahrenheit, false for Celicus. Celsius is the default. |
void init | ( | LIS2DS12_ODR_T | odr = LIS2DS12_ODR_100HZ , |
LIS2DS12_FS_T | fs = LIS2DS12_FS_2G |
||
) |
Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset.
odr | One of the LIS2DS12_ODR_T values. The default is LIS2DS12_ODR_100HZ |
fs | One of the LIS2DS12_FS_T values. The default is LIS2DS12_FS_2G |
std::runtime_error | on failure |
void reset | ( | ) |
void setODR | ( | LIS2DS12_ODR_T | odr | ) |
Set the output data rate (ODR) of the device
odr | One of the LIS2DS12_ODR_T values |
std::runtime_error | on failure |
void setFullScale | ( | LIS2DS12_FS_T | fs | ) |
Set the full scale (FS) of the device. This device supports a full scale of 2, 4, 8, and 16G.
fs | One of the LIS2DS12_FS_T values |
std::runtime_error | on failure |
void enableHPFiltering | ( | bool | filter | ) |
Enable high pass filtering of the accelerometer axis data. init() disables this by default. See the datasheet for details.
filter | true to enable filtering, false to disable |
std::runtime_error | on failure |
void enableInterruptLatching | ( | bool | latch | ) |
Enable or disable interrupt latching. If latching is disabled, pulsed is enabled. See the datasheet for details.
latch | true to enable latching, false to disable |
std::runtime_error | on failure |
void setInterruptActiveHigh | ( | bool | high | ) |
Indicate whether the interrupt should be active high (default) or active low. See the datasheet for details.
high | true for active high, false for active low |
std::runtime_error | on failure |
void setInterruptPushPull | ( | bool | pp | ) |
Indicate whether interrupts are push-pull (default) or open drain. See the datasheet for details.
pp | true for push-pull, false for open-drain |
std::runtime_error | on failure |
void setInt1Config | ( | uint8_t | cfg | ) |
Set interrupt 1 configuration. See the datasheet for details.
cfg | A bitmask of values from LIS2DS12_CTRL4_BITS_T |
std::runtime_error | on failure |
void setInt2Config | ( | uint8_t | cfg | ) |
Set interrupt 2 configuration. See the datasheet for details.
cfg | A bitmask of values from LIS2DS12_CTRL5_BITS_T |
std::runtime_error | on failure |
uint8_t getStatus | ( | ) |
Return the contents of the status register
void installISR | ( | LIS2DS12_INTERRUPT_PINS_T | intr, |
int | gpio, | ||
mraa::Edge | level, | ||
void(*)(void *) | isr, | ||
void * | arg | ||
) |
install an interrupt handler
intr | One of the LIS2DS12_INTERRUPT_PINS_T values specifying which interrupt pin you are installing |
gpio | GPIO pin to use as interrupt pin |
level | The interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose. |
isr | The interrupt handler, accepting a void * argument |
arg | The argument to pass the the interrupt handler |
std::runtime_error | on failure |
void uninstallISR | ( | LIS2DS12_INTERRUPT_PINS_T | intr | ) |
uninstall a previously installed interrupt handler
intr | One of the LIS2DS12_INTERRUPT_PINS_T values specifying which interrupt pin you are removing |
uint8_t readReg | ( | uint8_t | reg | ) |
Read a register
reg | The register to read |
int readRegs | ( | uint8_t | reg, |
uint8_t * | buffer, | ||
int | len | ||
) |
Read contiguous registers into a buffer
reg | The register to start the read from |
buffer | The buffer to store the results |
len | The number of registers to read |
std::runtime_error | on failure |
void writeReg | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Write to a register
reg | The register to write to |
val | The value to write |
std::runtime_error | on failure |