upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm303agr.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 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 "lsm303agr.h"
33 
34 namespace upm {
35 
68  class LSM303AGR {
69  public:
88  LSM303AGR(int bus=LSM303AGR_DEFAULT_I2C_BUS,
89  int acc_addr=LSM303AGR_DEFAULT_ACC_ADDR,
90  int mag_addr=LSM303AGR_DEFAULT_MAG_ADDR);
91 
95  ~LSM303AGR();
96 
104  void update();
105 
117  void getMagnetometer(float *x, float *y, float *z);
118 
127  std::vector<float> getMagnetometer();
128 
140  void getAccelerometer(float *x, float *y, float *z);
141 
150  std::vector<float> getAccelerometer();
151 
159  float getTemperature();
160 
181  void init(LSM303AGR_POWER_MODE_T usage=LSM303AGR_POWER_HIGH_RESOLUTION);
182 
190  void setFullScale(LSM303AGR_A_FS_T fs);
191 
201  void setPowerMode(LSM303AGR_POWER_MODE_T mode);
202 
210  void setAccelerometerODR(LSM303AGR_A_ODR_T odr);
211 
220  void setMagnetometerODR(LSM303AGR_CFG_A_M_ODR_T odr);
221 
229  uint8_t getAccelerometerInt1Config();
230 
238  uint8_t getAccelerometerInt2Config();
239 
248  void setAccelerometerInt1Config(uint8_t bits);
249 
258  void setAccelerometerInt2Config(uint8_t bits);
259 
266  uint8_t getMagnetometerIntConfig();
267 
275  void setMagnetometerIntConfig(uint8_t bits);
276 
284  uint8_t getAccelerometerInt1Src();
285 
293  uint8_t getAccelerometerInt2Src();
294 
303  uint8_t getMagnetometerIntSrc();
304 
318  void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio,
319  mraa::Edge level,
320  void (*isr)(void *), void *arg);
321 
328  void uninstallISR(LSM303AGR_INTERRUPT_PINS_T intr);
329 
330  protected:
331  // our underlying device context
332  lsm303agr_context m_lsm303agr;
333 
340  uint8_t readReg(uint8_t reg);
341 
350  int readRegs(uint8_t reg, uint8_t *buffer, int len);
351 
359  void writeReg(uint8_t reg, uint8_t val);
360 
361  private:
362  /* Disable implicit copy and assignment operators */
363  LSM303AGR(const LSM303AGR&) = delete;
364  LSM303AGR &operator=(const LSM303AGR&) = delete;
365 
366  };
367 }
std::vector< float > getAccelerometer()
Definition: lsm303agr.cxx:104
uint8_t readReg(uint8_t reg)
Definition: lsm303agr.cxx:64
void setAccelerometerInt2Config(uint8_t bits)
Definition: lsm303agr.cxx:162
float getTemperature()
Definition: lsm303agr.cxx:112
uint8_t getMagnetometerIntConfig()
Definition: lsm303agr.cxx:169
void writeReg(uint8_t reg, uint8_t val)
Definition: lsm303agr.cxx:79
std::vector< float > getMagnetometer()
Definition: lsm303agr.cxx:91
LSM303AGR(int bus=LSM303AGR_DEFAULT_I2C_BUS, int acc_addr=LSM303AGR_DEFAULT_ACC_ADDR, int mag_addr=LSM303AGR_DEFAULT_MAG_ADDR)
Definition: lsm303agr.cxx:37
void setFullScale(LSM303AGR_A_FS_T fs)
Definition: lsm303agr.cxx:117
uint8_t getMagnetometerIntSrc()
Definition: lsm303agr.cxx:191
API for the LSM303AGR 3-Axis Geomagnetic Sensor.
Definition: lsm303agr.hpp:68
C API for the lsm303agr driver.
~LSM303AGR()
Definition: lsm303agr.cxx:45
void setAccelerometerInt1Config(uint8_t bits)
Definition: lsm303agr.cxx:155
Definition: lsm303agr.h:53
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void setMagnetometerODR(LSM303AGR_CFG_A_M_ODR_T odr)
Definition: lsm303agr.cxx:138
void setAccelerometerODR(LSM303AGR_A_ODR_T odr)
Definition: lsm303agr.cxx:131
uint8_t getAccelerometerInt1Src()
Definition: lsm303agr.cxx:181
void uninstallISR(LSM303AGR_INTERRUPT_PINS_T intr)
Definition: lsm303agr.cxx:207
void init(LSM303AGR_POWER_MODE_T usage=LSM303AGR_POWER_HIGH_RESOLUTION)
Definition: lsm303agr.cxx:50
void update()
Definition: lsm303agr.cxx:57
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lsm303agr.cxx:69
void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: lsm303agr.cxx:197
void setMagnetometerIntConfig(uint8_t bits)
Definition: lsm303agr.cxx:174
uint8_t getAccelerometerInt2Config()
Definition: lsm303agr.cxx:150
void setPowerMode(LSM303AGR_POWER_MODE_T mode)
Definition: lsm303agr.cxx:124
uint8_t getAccelerometerInt2Src()
Definition: lsm303agr.cxx:186
uint8_t getAccelerometerInt1Config()
Definition: lsm303agr.cxx:145