upm  1.6.0
Sensor/Actuator repository for libmraa (v1.9.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 
68  class LSM303D {
69  public:
83  LSM303D(int bus=LSM303D_DEFAULT_I2C_BUS,
84  int addr=LSM303D_DEFAULT_I2C_ADDR);
85 
89  ~LSM303D();
90 
98  void update();
99 
111  void getMagnetometer(float *x, float *y, float *z);
112 
121  std::vector<float> getMagnetometer();
122 
134  void getAccelerometer(float *x, float *y, float *z);
135 
144  std::vector<float> getAccelerometer();
145 
153  float getTemperature();
154 
167  void init(LSM303D_M_RES_T res);
168 
177  void setAccelerometerFullScale(LSM303D_AFS_T fs);
178 
187  void setMagnetometerFullScale(LSM303D_MFS_T fs);
188 
196  void setAccelerometerODR(LSM303D_AODR_T odr);
197 
206  void setMagnetometerODR(LSM303D_MODR_T odr);
207 
208  protected:
209  // our underlying device context
210  lsm303d_context m_lsm303d;
211 
218  uint8_t readReg(uint8_t reg);
219 
228  int readRegs(uint8_t reg, uint8_t *buffer, int len);
229 
237  void writeReg(uint8_t reg, uint8_t val);
238 
239  private:
240  /* Disable implicit copy and assignment operators */
241  LSM303D(const LSM303D&) = delete;
242  LSM303D &operator=(const LSM303D&) = delete;
243  };
244 }
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
C++ API for the kxtj3 driver.
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:68
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.