upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.0)
lsm303d.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 "lsm303d.h"
33 
34 namespace upm {
35 
69  class LSM303D {
70  public:
84  LSM303D(int bus=LSM303D_DEFAULT_I2C_BUS,
85  int addr=LSM303D_DEFAULT_I2C_ADDR);
86 
90  ~LSM303D();
91 
99  void update();
100 
112  void getMagnetometer(float *x, float *y, float *z);
113 
122  std::vector<float> getMagnetometer();
123 
135  void getAccelerometer(float *x, float *y, float *z);
136 
145  std::vector<float> getAccelerometer();
146 
154  float getTemperature();
155 
168  void init(LSM303D_M_RES_T res);
169 
178  void setAccelerometerFullScale(LSM303D_AFS_T fs);
179 
188  void setMagnetometerFullScale(LSM303D_MFS_T fs);
189 
197  void setAccelerometerODR(LSM303D_AODR_T odr);
198 
207  void setMagnetometerODR(LSM303D_MODR_T odr);
208 
209  protected:
210  // our underlying device context
211  lsm303d_context m_lsm303d;
212 
219  uint8_t readReg(uint8_t reg);
220 
229  int readRegs(uint8_t reg, uint8_t *buffer, int len);
230 
238  void writeReg(uint8_t reg, uint8_t val);
239 
240  private:
241  /* Disable implicit copy and assignment operators */
242  LSM303D(const LSM303D&) = delete;
243  LSM303D &operator=(const LSM303D&) = delete;
244  };
245 }
void init(LSM303D_M_RES_T res)
Definition: lsm303d.cxx:50
std::vector< float > getMagnetometer()
Definition: lsm303d.cxx:91
void setMagnetometerFullScale(LSM303D_MFS_T fs)
Definition: lsm303d.cxx:124
float getTemperature()
Definition: lsm303d.cxx:112
LSM303D(int bus=LSM303D_DEFAULT_I2C_BUS, int addr=LSM303D_DEFAULT_I2C_ADDR)
Definition: lsm303d.cxx:37
uint8_t readReg(uint8_t reg)
Definition: lsm303d.cxx:64
Definition: lsm303d.h:53
~LSM303D()
Definition: lsm303d.cxx:45
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: lsm303d.cxx:69
void update()
Definition: lsm303d.cxx:57
Definition: a110x.hpp:29
std::vector< float > getAccelerometer()
Definition: lsm303d.cxx:104
void writeReg(uint8_t reg, uint8_t val)
Definition: lsm303d.cxx:79
API for the LSM303D 3-Axis Geomagnetic Sensor.
Definition: lsm303d.hpp:69
void setAccelerometerFullScale(LSM303D_AFS_T fs)
Definition: lsm303d.cxx:117
void setAccelerometerODR(LSM303D_AODR_T odr)
Definition: lsm303d.cxx:130
void setMagnetometerODR(LSM303D_MODR_T odr)
Definition: lsm303d.cxx:137
C API for the lsm303d driver.