upm  1.6.0
Sensor/Actuator repository for libmraa (v1.9.0)
lis2ds12.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016-2017 Intel Corporation.
4  *
5  * The MIT License
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <vector>
30 
31 #include <mraa/gpio.hpp>
32 #include "lis2ds12.h"
33 
34 namespace upm {
35 
73  class LIS2DS12 {
74  public:
75 
92  LIS2DS12(int bus=LIS2DS12_DEFAULT_I2C_BUS,
93  int addr=LIS2DS12_DEFAULT_I2C_ADDR,
94  int cs=-1);
95 
99  virtual ~LIS2DS12();
100 
106  void update();
107 
113  uint8_t getChipID();
114 
126  void getAccelerometer(float *x, float *y, float *z);
127 
136  std::vector<float> getAccelerometer();
137 
147  float getTemperature(bool fahrenheit=false);
148 
160  void init(LIS2DS12_ODR_T odr=LIS2DS12_ODR_100HZ,
161  LIS2DS12_FS_T fs=LIS2DS12_FS_2G);
162 
171  void reset();
172 
179  void setODR(LIS2DS12_ODR_T odr);
180 
188  void setFullScale(LIS2DS12_FS_T fs);
189 
198  void enableHPFiltering(bool filter);
199 
207  void enableInterruptLatching(bool latch);
208 
216  void setInterruptActiveHigh(bool high);
217 
225  void setInterruptPushPull(bool pp);
226 
233  void setInt1Config(uint8_t cfg);
234 
241  void setInt2Config(uint8_t cfg);
242 
248  uint8_t getStatus();
249 
263  void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio,
264  mraa::Edge level,
265  void (*isr)(void *), void *arg);
266 
273  void uninstallISR(LIS2DS12_INTERRUPT_PINS_T intr);
274 
281  uint8_t readReg(uint8_t reg);
282 
292  int readRegs(uint8_t reg, uint8_t *buffer, int len);
293 
301  void writeReg(uint8_t reg, uint8_t val);
302 
303  protected:
304  lis2ds12_context m_lis2ds12;
305 
306  private:
307  /* Disable implicit copy and assignment operators */
308  LIS2DS12(const LIS2DS12&) = delete;
309  LIS2DS12 &operator=(const LIS2DS12&) = delete;
310 
311  };
312 }
void setInt2Config(uint8_t cfg)
Definition: lis2ds12.cxx:176
uint8_t getChipID()
Definition: lis2ds12.cxx:93
void setInterruptActiveHigh(bool high)
Definition: lis2ds12.cxx:155
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lis2ds12.cxx:76
void setODR(LIS2DS12_ODR_T odr)
Definition: lis2ds12.cxx:127
std::vector< float > getAccelerometer()
Definition: lis2ds12.cxx:103
void update()
Definition: lis2ds12.cxx:64
void enableHPFiltering(bool filter)
Definition: lis2ds12.cxx:141
C API for the lis2ds12 driver.
void init(LIS2DS12_ODR_T odr=LIS2DS12_ODR_100HZ, LIS2DS12_FS_T fs=LIS2DS12_FS_2G)
Definition: lis2ds12.cxx:57
API for the LIS2DS12 3-axis Accelerometer.
Definition: lis2ds12.hpp:73
uint8_t readReg(uint8_t reg)
Definition: lis2ds12.cxx:71
void setInt1Config(uint8_t cfg)
Definition: lis2ds12.cxx:169
C++ API for the kxtj3 driver.
Definition: a110x.hpp:29
uint8_t getStatus()
Definition: lis2ds12.cxx:183
void reset()
Definition: lis2ds12.cxx:120
void enableInterruptLatching(bool latch)
Definition: lis2ds12.cxx:148
LIS2DS12(int bus=LIS2DS12_DEFAULT_I2C_BUS, int addr=LIS2DS12_DEFAULT_I2C_ADDR, int cs=-1)
Definition: lis2ds12.cxx:44
float getTemperature(bool fahrenheit=false)
Definition: lis2ds12.cxx:111
void setInterruptPushPull(bool pp)
Definition: lis2ds12.cxx:162
void setFullScale(LIS2DS12_FS_T fs)
Definition: lis2ds12.cxx:134
virtual ~LIS2DS12()
Definition: lis2ds12.cxx:52
void writeReg(uint8_t reg, uint8_t val)
Definition: lis2ds12.cxx:86
void uninstallISR(LIS2DS12_INTERRUPT_PINS_T intr)
Definition: lis2ds12.cxx:198
Definition: lis2ds12.h:54
void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: lis2ds12.cxx:188