upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bmi160.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdint.h>
27 
28 #define BMI160_I2C_BUS 0
29 #define BMI160_DEFAULT_I2C_ADDR 0x69
30 
31 namespace upm {
32 
70  class BMI160 {
71  public:
72 
73  typedef enum {
74  ACCEL_RANGE_2G = 0, // 2 Gravities
75  ACCEL_RANGE_4G,
76  ACCEL_RANGE_8G,
77  ACCEL_RANGE_16G
78  } ACCEL_RANGE_T;
79 
80  typedef enum {
81  GYRO_RANGE_125 = 0, // 125 degrees/sec
82  GYRO_RANGE_250,
83  GYRO_RANGE_500,
84  GYRO_RANGE_1000,
85  GYRO_RANGE_2000
86  } GYRO_RANGE_T;
87 
94  BMI160(int bus=BMI160_I2C_BUS, uint8_t address=BMI160_DEFAULT_I2C_ADDR);
95 
99  ~BMI160();
100 
107  void update();
108 
114  void setAccelerometerScale(ACCEL_RANGE_T scale);
115 
121  void setGyroscopeScale(GYRO_RANGE_T scale);
122 
134  float *getAccelerometer();
135 
145  void getAccelerometer(float *x, float *y, float *z);
146 
158  float *getGyroscope();
159 
169  void getGyroscope(float *x, float *y, float *z);
170 
184  float *getMagnetometer();
185 
195  void getMagnetometer(float *x, float *y, float *z);
196 
203  void enableMagnetometer(bool enable);
204 
212  unsigned int getSensorTime();
213 
214  protected:
215  // uncompensated accelerometer and gyroscope values
216  float m_accelX;
217  float m_accelY;
218  float m_accelZ;
219 
220  float m_gyroX;
221  float m_gyroY;
222  float m_gyroZ;
223 
224  float m_magX;
225  float m_magY;
226  float m_magZ;
227 
228  unsigned int m_sensorTime;
229 
230  // accelerometer and gyro scaling factors, depending on their Full
231  // Scale (Range) settings.
232  float m_accelScale;
233  float m_gyroScale;
234 
235  // is the magnetometer enabled?
236  bool m_magEnabled;
237 
243  virtual bool init();
244 
245  private:
246  // due to the way we need to 'hook' into the bmi driver, the i2c
247  // context is a static variable defined in the .cxx implmentation.
248 
249  uint8_t m_addr;
250  };
251 }
float * getMagnetometer()
Definition: bmi160.cxx:393
void setAccelerometerScale(ACCEL_RANGE_T scale)
Definition: bmi160.cxx:255
unsigned int getSensorTime()
Definition: bmi160.cxx:430
float * getGyroscope()
Definition: bmi160.cxx:384
UPM API for the BMI160 3-axis Accelerometer, Gyroscope and Magnetometer.
Definition: bmi160.hpp:70
void enableMagnetometer(bool enable)
Definition: bmi160.cxx:402
~BMI160()
Definition: bmi160.cxx:169
void update()
Definition: bmi160.cxx:218
float * getAccelerometer()
Definition: bmi160.cxx:375
BMI160(int bus=BMI160_I2C_BUS, uint8_t address=BMI160_DEFAULT_I2C_ADDR)
Definition: bmi160.cxx:115
virtual bool init()
Definition: bmi160.cxx:175
void setGyroscopeScale(GYRO_RANGE_T scale)
Definition: bmi160.cxx:294