upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm6dsl.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 "lsm6dsl.h"
33 
34 namespace upm {
35 
66  class LSM6DSL {
67  public:
68 
85  LSM6DSL(int bus=LSM6DSL_DEFAULT_I2C_BUS,
86  int addr=LSM6DSL_DEFAULT_I2C_ADDR,
87  int cs=-1);
88 
92  virtual ~LSM6DSL();
93 
99  void update();
100 
106  uint8_t getChipID();
107 
119  void getAccelerometer(float *x, float *y, float *z);
120 
129  std::vector<float> getAccelerometer();
130 
143  void getGyroscope(float *x, float *y, float *z);
144 
153  std::vector<float> getGyroscope();
154 
164  float getTemperature(bool fahrenheit=false);
165 
179  void init(LSM6DSL_XL_ODR_T acc_odr=LSM6DSL_XL_ODR_104HZ,
180  LSM6DSL_XL_FS_T acc_fs=LSM6DSL_XL_FS_2G,
181  LSM6DSL_G_ODR_T gyr_odr=LSM6DSL_G_ODR_104HZ,
182  LSM6DSL_G_FS_T gyr_fs=LSM6DSL_G_FS_245DPS);
183 
192  void reset();
193 
200  void setAccelerometerODR(LSM6DSL_XL_ODR_T odr);
201 
209  void setAccelerometerFullScale(LSM6DSL_XL_FS_T fs);
210 
217  void setGyroscopeODR(LSM6DSL_G_ODR_T odr);
218 
225  void setGyroscopeFullScale(LSM6DSL_G_FS_T fs);
226 
236  void setHighPerformance(bool enable);
237 
245  void setInterruptActiveHigh(bool high);
246 
254  void setInterruptPushPull(bool pp);
255 
261  uint8_t getStatus();
262 
278  void setAccelerometerOffsets(int x, int y, int z, bool weight);
279 
293  void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
294  mraa::Edge level,
295  void (*isr)(void *), void *arg);
296 
303  void uninstallISR(LSM6DSL_INTERRUPT_PINS_T intr);
304 
311  uint8_t readReg(uint8_t reg);
312 
321  int readRegs(uint8_t reg, uint8_t *buffer, int len);
322 
330  void writeReg(uint8_t reg, uint8_t val);
331 
332  protected:
333  lsm6dsl_context m_lsm6dsl;
334 
335  private:
336  /* Disable implicit copy and assignment operators */
337  LSM6DSL(const LSM6DSL&) = delete;
338  LSM6DSL &operator=(const LSM6DSL&) = delete;
339 
340  };
341 }
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lsm6dsl.cxx:77
LSM6DSL(int bus=LSM6DSL_DEFAULT_I2C_BUS, int addr=LSM6DSL_DEFAULT_I2C_ADDR, int cs=-1)
Definition: lsm6dsl.cxx:44
void setHighPerformance(bool enable)
Definition: lsm6dsl.cxx:169
void uninstallISR(LSM6DSL_INTERRUPT_PINS_T intr)
Definition: lsm6dsl.cxx:212
C API for the lsm6dsl driver.
void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: lsm6dsl.cxx:202
std::vector< float > getAccelerometer()
Definition: lsm6dsl.cxx:104
void setAccelerometerODR(LSM6DSL_XL_ODR_T odr)
Definition: lsm6dsl.cxx:141
virtual ~LSM6DSL()
Definition: lsm6dsl.cxx:52
void setGyroscopeFullScale(LSM6DSL_G_FS_T fs)
Definition: lsm6dsl.cxx:162
void update()
Definition: lsm6dsl.cxx:65
void setInterruptActiveHigh(bool high)
Definition: lsm6dsl.cxx:176
std::vector< float > getGyroscope()
Definition: lsm6dsl.cxx:117
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void setAccelerometerFullScale(LSM6DSL_XL_FS_T fs)
Definition: lsm6dsl.cxx:148
void setGyroscopeODR(LSM6DSL_G_ODR_T odr)
Definition: lsm6dsl.cxx:155
void writeReg(uint8_t reg, uint8_t val)
Definition: lsm6dsl.cxx:87
uint8_t getChipID()
Definition: lsm6dsl.cxx:94
API for the LSM6DSL 3-axis Accelerometer and Gyroscope.
Definition: lsm6dsl.hpp:66
uint8_t getStatus()
Definition: lsm6dsl.cxx:190
void init(LSM6DSL_XL_ODR_T acc_odr=LSM6DSL_XL_ODR_104HZ, LSM6DSL_XL_FS_T acc_fs=LSM6DSL_XL_FS_2G, LSM6DSL_G_ODR_T gyr_odr=LSM6DSL_G_ODR_104HZ, LSM6DSL_G_FS_T gyr_fs=LSM6DSL_G_FS_245DPS)
Definition: lsm6dsl.cxx:57
Definition: lsm6dsl.h:54
void reset()
Definition: lsm6dsl.cxx:134
float getTemperature(bool fahrenheit=false)
Definition: lsm6dsl.cxx:125
void setAccelerometerOffsets(int x, int y, int z, bool weight)
Definition: lsm6dsl.cxx:195
void setInterruptPushPull(bool pp)
Definition: lsm6dsl.cxx:183
uint8_t readReg(uint8_t reg)
Definition: lsm6dsl.cxx:72