upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmg160.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 "bmg160.h"
33 
34 namespace upm {
35 
74  class BMG160 {
75  public:
92  BMG160(int bus=BMG160_DEFAULT_I2C_BUS, int addr=BMG160_DEFAULT_ADDR,
93  int cs=-1);
94 
98  ~BMG160();
99 
105  void update();
106 
112  uint8_t getChipID();
113 
125  void getGyroscope(float *x, float *y, float *z);
126 
135  std::vector<float> getGyroscope();
136 
146  float getTemperature(bool fahrenheit=false);
147 
161  void init(BMG160_POWER_MODE_T pwr=BMG160_POWER_MODE_NORMAL,
162  BMG160_RANGE_T range=BMG160_RANGE_250,
163  BMG160_BW_T bw=BMG160_BW_400_47);
164 
173  void reset();
174 
182  void setRange(BMG160_RANGE_T range);
183 
190  void setBandwidth(BMG160_BW_T bw);
191 
201  void setPowerMode(BMG160_POWER_MODE_T power);
202 
218  void enableFIFO(bool useFIFO);
219 
227  void fifoSetWatermark(int wm);
228 
238  void fifoConfig(BMG160_FIFO_MODE_T mode, BMG160_FIFO_DATA_SEL_T axes);
239 
247  uint8_t getInterruptEnable0();
248 
256  void setInterruptEnable0(uint8_t bits);
257 
265  uint8_t getInterruptMap0();
266 
275  void setInterruptMap0(uint8_t bits);
276 
283  uint8_t getInterruptMap1();
284 
292  void setInterruptMap1(uint8_t bits);
293 
302  uint8_t getInterruptSrc();
303 
313  void setInterruptSrc(uint8_t bits);
314 
323  uint8_t getInterruptOutputControl();
324 
334  void setInterruptOutputControl(uint8_t bits);
335 
341  void clearInterruptLatches();
342 
349  BMG160_RST_LATCH_T getInterruptLatchBehavior();
350 
358  void setInterruptLatchBehavior(BMG160_RST_LATCH_T latch);
359 
367  uint8_t getInterruptStatus0();
368 
375  uint8_t getInterruptStatus1();
376 
383  uint8_t getInterruptStatus2();
384 
391  uint8_t getInterruptStatus3();
392 
406  void enableRegisterShadowing(bool shadow);
407 
416  void enableOutputFiltering(bool filter);
417 
432  void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio,
433  mraa::Edge level,
434  void (*isr)(void *), void *arg);
435 
442  void uninstallISR(BMG160_INTERRUPT_PINS_T intr);
443 
450  uint8_t readReg(uint8_t reg);
451 
460  int readRegs(uint8_t reg, uint8_t *buffer, int len);
461 
469  void writeReg(uint8_t reg, uint8_t val);
470 
471  protected:
472  bmg160_context m_bmg160;
473 
474  private:
475  /* Disable implicit copy and assignment operators */
476  BMG160(const BMG160&) = delete;
477  BMG160 &operator=(const BMG160&) = delete;
478 
479  };
480 }
void clearInterruptLatches()
Definition: bmg160.cxx:228
void setInterruptLatchBehavior(BMG160_RST_LATCH_T latch)
Definition: bmg160.cxx:240
void setRange(BMG160_RANGE_T range)
Definition: bmg160.cxx:133
void uninstallISR(BMG160_INTERRUPT_PINS_T intr)
Definition: bmg160.cxx:291
void init(BMG160_POWER_MODE_T pwr=BMG160_POWER_MODE_NORMAL, BMG160_RANGE_T range=BMG160_RANGE_250, BMG160_BW_T bw=BMG160_BW_400_47)
Definition: bmg160.cxx:57
uint8_t getInterruptStatus3()
Definition: bmg160.cxx:276
void enableRegisterShadowing(bool shadow)
Definition: bmg160.cxx:247
float getTemperature(bool fahrenheit=false)
Definition: bmg160.cxx:117
uint8_t getInterruptStatus0()
Definition: bmg160.cxx:261
void setInterruptMap0(uint8_t bits)
Definition: bmg160.cxx:185
uint8_t readReg(uint8_t reg)
Definition: bmg160.cxx:77
uint8_t getInterruptOutputControl()
Definition: bmg160.cxx:216
BMG160(int bus=BMG160_DEFAULT_I2C_BUS, int addr=BMG160_DEFAULT_ADDR, int cs=-1)
Definition: bmg160.cxx:44
std::vector< float > getGyroscope()
Definition: bmg160.cxx:109
uint8_t getChipID()
Definition: bmg160.cxx:99
API for the BMG160 16 bit Triaxial Gyroscope.
Definition: bmg160.hpp:74
void writeReg(uint8_t reg, uint8_t val)
Definition: bmg160.cxx:92
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
BMG160_RST_LATCH_T getInterruptLatchBehavior()
Definition: bmg160.cxx:235
uint8_t getInterruptEnable0()
Definition: bmg160.cxx:168
void setBandwidth(BMG160_BW_T bw)
Definition: bmg160.cxx:140
void fifoConfig(BMG160_FIFO_MODE_T mode, BMG160_FIFO_DATA_SEL_T axes)
Definition: bmg160.cxx:161
~BMG160()
Definition: bmg160.cxx:52
uint8_t getInterruptStatus1()
Definition: bmg160.cxx:266
uint8_t getInterruptStatus2()
Definition: bmg160.cxx:271
void setInterruptEnable0(uint8_t bits)
Definition: bmg160.cxx:173
void setInterruptSrc(uint8_t bits)
Definition: bmg160.cxx:209
void setPowerMode(BMG160_POWER_MODE_T power)
Definition: bmg160.cxx:147
void enableFIFO(bool useFIFO)
Definition: bmg160.cxx:72
void enableOutputFiltering(bool filter)
Definition: bmg160.cxx:254
void reset()
Definition: bmg160.cxx:126
uint8_t getInterruptMap0()
Definition: bmg160.cxx:180
uint8_t getInterruptMap1()
Definition: bmg160.cxx:192
C API for the bmg160 driver.
uint8_t getInterruptSrc()
Definition: bmg160.cxx:204
void update()
Definition: bmg160.cxx:65
void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bmg160.cxx:281
void setInterruptOutputControl(uint8_t bits)
Definition: bmg160.cxx:221
void setInterruptMap1(uint8_t bits)
Definition: bmg160.cxx:197
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bmg160.cxx:82
void fifoSetWatermark(int wm)
Definition: bmg160.cxx:154
Definition: bmg160.h:54