upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lis3dh.hpp
1 /*
2  * Author: Alex Tereschenko <alext.mkrs@gmail.com>
3  * Copyright (c) 2018 Alex Tereschenko.
4  *
5  * Based on LIS2DS12 module by
6  * Author: Jon Trulson <jtrulson@ics.com>
7  * Copyright (c) 2017 Intel Corporation.
8  *
9  * The MIT License
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 #pragma once
31 
32 #include <string>
33 #include <vector>
34 
35 #include "lis3dh.h"
36 #include <mraa/gpio.hpp>
37 
38 namespace upm
39 {
75 class LIS3DH
76 {
77  public:
94  LIS3DH(int bus = LIS3DH_DEFAULT_I2C_BUS, int addr = LIS3DH_DEFAULT_I2C_ADDR, int cs = -1);
95 
99  virtual ~LIS3DH();
100 
114  void
115  init(LIS3DH_ODR_T odr = LIS3DH_ODR_100HZ, LIS3DH_FS_T fs = LIS3DH_FS_2G, bool high_res = true);
116 
126  void enableAxes(bool x_axis_enable, bool y_axis_enable, bool z_axis_enable);
127 
134  void enableBDUMode(bool bdu_enable);
135 
143  void enableLPMode(bool lp_enable);
144 
152  void enableHRMode(bool hr_enable);
153 
161  void enableNormalMode();
162 
171  void enableHPFiltering(bool filter);
172 
181  void enableInterruptLatching(bool int1_latch, bool int2_latch);
182 
189  void enableADC(bool adc_enable);
190 
198  void enableTemperature(bool temperature_enable);
199 
206  void setODR(LIS3DH_ODR_T odr);
207 
215  void setFullScale(LIS3DH_FS_T fs);
216 
224  void setInterruptActiveHigh(bool high);
225 
232  void setInt1Config(uint8_t cfg);
233 
240  void setInt2Config(uint8_t cfg);
241 
248  uint8_t readReg(uint8_t reg);
249 
259  int readRegs(uint8_t reg, uint8_t* buffer, int len);
260 
268  void writeReg(uint8_t reg, uint8_t val);
269 
275  void update();
276 
282  uint8_t getChipID();
283 
295  void getAccelerometer(float* x, float* y, float* z);
296 
305  std::vector<float> getAccelerometer();
306 
316  float getTemperature(bool fahrenheit = false);
317 
323  uint8_t getStatus();
324 
330  uint8_t getStatusAux();
331 
345  void installISR(LIS3DH_INTERRUPT_PINS_T intr,
346  int gpio,
347  mraa::Edge level,
348  void (*isr)(void*),
349  void* arg);
350 
357  void uninstallISR(LIS3DH_INTERRUPT_PINS_T intr);
358 
359  protected:
360  lis3dh_context m_lis3dh;
361 
362  private:
363  // Disable implicit copy and assignment operators
364  LIS3DH(const LIS3DH&) = delete;
365  LIS3DH& operator=(const LIS3DH&) = delete;
366 
367 };
368 }
void setODR(LIS3DH_ODR_T odr)
Definition: lis3dh.cxx:143
void enableADC(bool adc_enable)
Definition: lis3dh.cxx:127
API for the LIS3DH 3-axis Accelerometer.
Definition: lis3dh.hpp:75
uint8_t readReg(uint8_t reg)
Definition: lis3dh.cxx:184
void enableHPFiltering(bool filter)
Definition: lis3dh.cxx:110
LIS3DH(int bus=LIS3DH_DEFAULT_I2C_BUS, int addr=LIS3DH_DEFAULT_I2C_ADDR, int cs=-1)
Definition: lis3dh.cxx:49
uint8_t getChipID()
Definition: lis3dh.cxx:217
void writeReg(uint8_t reg, uint8_t val)
Definition: lis3dh.cxx:201
void setInterruptActiveHigh(bool high)
Definition: lis3dh.cxx:159
void installISR(LIS3DH_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: lis3dh.cxx:261
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
uint8_t getStatusAux()
Definition: lis3dh.cxx:255
void update()
Definition: lis3dh.cxx:209
void enableAxes(bool x_axis_enable, bool y_axis_enable, bool z_axis_enable)
Definition: lis3dh.cxx:70
void enableNormalMode()
Definition: lis3dh.cxx:102
std::vector< float > getAccelerometer()
Definition: lis3dh.cxx:229
void enableLPMode(bool lp_enable)
Definition: lis3dh.cxx:86
void setFullScale(LIS3DH_FS_T fs)
Definition: lis3dh.cxx:151
void init(LIS3DH_ODR_T odr=LIS3DH_ODR_100HZ, LIS3DH_FS_T fs=LIS3DH_FS_2G, bool high_res=true)
Definition: lis3dh.cxx:62
virtual ~LIS3DH()
Definition: lis3dh.cxx:56
void uninstallISR(LIS3DH_INTERRUPT_PINS_T intr)
Definition: lis3dh.cxx:273
C API for the lis3dh driver.
void setInt2Config(uint8_t cfg)
Definition: lis3dh.cxx:176
void enableInterruptLatching(bool int1_latch, bool int2_latch)
Definition: lis3dh.cxx:118
void enableHRMode(bool hr_enable)
Definition: lis3dh.cxx:94
uint8_t getStatus()
Definition: lis3dh.cxx:249
void setInt1Config(uint8_t cfg)
Definition: lis3dh.cxx:168
void enableTemperature(bool temperature_enable)
Definition: lis3dh.cxx:135
Definition: lis3dh.h:58
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lis3dh.cxx:190
float getTemperature(bool fahrenheit=false)
Definition: lis3dh.cxx:238
void enableBDUMode(bool bdu_enable)
Definition: lis3dh.cxx:78