upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm6ds3h.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 "lsm6ds3h.h"
33 
34 namespace upm {
35 
67  class LSM6DS3H {
68  public:
69 
86  LSM6DS3H(int bus=LSM6DS3H_DEFAULT_I2C_BUS,
87  int addr=LSM6DS3H_DEFAULT_I2C_ADDR,
88  int cs=-1);
89 
93  virtual ~LSM6DS3H();
94 
100  void update();
101 
107  uint8_t getChipID();
108 
120  void getAccelerometer(float *x, float *y, float *z);
121 
130  std::vector<float> getAccelerometer();
131 
144  void getGyroscope(float *x, float *y, float *z);
145 
154  std::vector<float> getGyroscope();
155 
165  float getTemperature(bool fahrenheit=false);
166 
180  void init(LSM6DS3H_XL_ODR_T acc_odr=LSM6DS3H_XL_ODR_104HZ,
181  LSM6DS3H_XL_FS_T acc_fs=LSM6DS3H_XL_FS_2G,
182  LSM6DS3H_G_ODR_T gyr_odr=LSM6DS3H_G_ODR_104HZ,
183  LSM6DS3H_G_FS_T gyr_fs=LSM6DS3H_G_FS_245DPS);
184 
193  void reset();
194 
201  void setAccelerometerODR(LSM6DS3H_XL_ODR_T odr);
202 
210  void setAccelerometerFullScale(LSM6DS3H_XL_FS_T fs);
211 
218  void setGyroscopeODR(LSM6DS3H_G_ODR_T odr);
219 
226  void setGyroscopeFullScale(LSM6DS3H_G_FS_T fs);
227 
237  void setHighPerformance(bool enable);
238 
246  void setInterruptActiveHigh(bool high);
247 
255  void setInterruptPushPull(bool pp);
256 
262  uint8_t getStatus();
263 
277  void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,
278  mraa::Edge level,
279  void (*isr)(void *), void *arg);
280 
287  void uninstallISR(LSM6DS3H_INTERRUPT_PINS_T intr);
288 
295  uint8_t readReg(uint8_t reg);
296 
305  int readRegs(uint8_t reg, uint8_t *buffer, int len);
306 
314  void writeReg(uint8_t reg, uint8_t val);
315 
316  protected:
317  lsm6ds3h_context m_lsm6ds3h;
318 
319  private:
320  /* Disable implicit copy and assignment operators */
321  LSM6DS3H(const LSM6DS3H&) = delete;
322  LSM6DS3H &operator=(const LSM6DS3H&) = delete;
323 
324  };
325 }
API for the LSM6DS3H 3-axis Accelerometer and Gyroscope.
Definition: lsm6ds3h.hpp:67
void setGyroscopeFullScale(LSM6DS3H_G_FS_T fs)
Definition: lsm6ds3h.cxx:162
void setGyroscopeODR(LSM6DS3H_G_ODR_T odr)
Definition: lsm6ds3h.cxx:155
void reset()
Definition: lsm6ds3h.cxx:134
void init(LSM6DS3H_XL_ODR_T acc_odr=LSM6DS3H_XL_ODR_104HZ, LSM6DS3H_XL_FS_T acc_fs=LSM6DS3H_XL_FS_2G, LSM6DS3H_G_ODR_T gyr_odr=LSM6DS3H_G_ODR_104HZ, LSM6DS3H_G_FS_T gyr_fs=LSM6DS3H_G_FS_245DPS)
Definition: lsm6ds3h.cxx:57
void setInterruptPushPull(bool pp)
Definition: lsm6ds3h.cxx:183
void setAccelerometerODR(LSM6DS3H_XL_ODR_T odr)
Definition: lsm6ds3h.cxx:141
void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: lsm6ds3h.cxx:195
uint8_t readReg(uint8_t reg)
Definition: lsm6ds3h.cxx:72
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lsm6ds3h.cxx:77
void update()
Definition: lsm6ds3h.cxx:65
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
float getTemperature(bool fahrenheit=false)
Definition: lsm6ds3h.cxx:125
uint8_t getChipID()
Definition: lsm6ds3h.cxx:94
std::vector< float > getAccelerometer()
Definition: lsm6ds3h.cxx:104
uint8_t getStatus()
Definition: lsm6ds3h.cxx:190
void writeReg(uint8_t reg, uint8_t val)
Definition: lsm6ds3h.cxx:87
void setInterruptActiveHigh(bool high)
Definition: lsm6ds3h.cxx:176
Definition: lsm6ds3h.h:54
void setAccelerometerFullScale(LSM6DS3H_XL_FS_T fs)
Definition: lsm6ds3h.cxx:148
void setHighPerformance(bool enable)
Definition: lsm6ds3h.cxx:169
void uninstallISR(LSM6DS3H_INTERRUPT_PINS_T intr)
Definition: lsm6ds3h.cxx:205
std::vector< float > getGyroscope()
Definition: lsm6ds3h.cxx:117
LSM6DS3H(int bus=LSM6DS3H_DEFAULT_I2C_BUS, int addr=LSM6DS3H_DEFAULT_I2C_ADDR, int cs=-1)
Definition: lsm6ds3h.cxx:44
virtual ~LSM6DS3H()
Definition: lsm6ds3h.cxx:52
C API for the lsm6ds3h driver.