upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.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 
264 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
265  void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,
266  mraa::Edge level, jobject runnable)
267  {
268  installISR(intr, gpio, level, mraa_java_isr_callback,
269  runnable);
270  }
271 #else
272 
285  void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,
286  mraa::Edge level,
287  void (*isr)(void *), void *arg);
288 #endif
289 
296  void uninstallISR(LSM6DS3H_INTERRUPT_PINS_T intr);
297 
304  uint8_t readReg(uint8_t reg);
305 
314  int readRegs(uint8_t reg, uint8_t *buffer, int len);
315 
323  void writeReg(uint8_t reg, uint8_t val);
324 
325  protected:
326  lsm6ds3h_context m_lsm6ds3h;
327 
328  private:
329  /* Disable implicit copy and assignment operators */
330  LSM6DS3H(const LSM6DS3H&) = delete;
331  LSM6DS3H &operator=(const LSM6DS3H&) = delete;
332 
333  // Adding a private function definition for java bindings
334 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
335  void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,
336  mraa::Edge level,
337  void (*isr)(void *), void *arg);
338 #endif
339  };
340 }
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
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.