upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
68  class BMG160 {
69  public:
86  BMG160(int bus=BMG160_DEFAULT_I2C_BUS, int addr=BMG160_DEFAULT_ADDR,
87  int cs=-1);
88 
92  ~BMG160();
93 
99  void update();
100 
106  uint8_t getChipID();
107 
119  void getGyroscope(float *x, float *y, float *z);
120 
129  std::vector<float> getGyroscope();
130 
140  float getTemperature(bool fahrenheit=false);
141 
155  void init(BMG160_POWER_MODE_T pwr=BMG160_POWER_MODE_NORMAL,
156  BMG160_RANGE_T range=BMG160_RANGE_250,
157  BMG160_BW_T bw=BMG160_BW_400_47);
158 
167  void reset();
168 
176  void setRange(BMG160_RANGE_T range);
177 
184  void setBandwidth(BMG160_BW_T bw);
185 
195  void setPowerMode(BMG160_POWER_MODE_T power);
196 
212  void enableFIFO(bool useFIFO);
213 
221  void fifoSetWatermark(int wm);
222 
232  void fifoConfig(BMG160_FIFO_MODE_T mode, BMG160_FIFO_DATA_SEL_T axes);
233 
241  uint8_t getInterruptEnable0();
242 
250  void setInterruptEnable0(uint8_t bits);
251 
259  uint8_t getInterruptMap0();
260 
269  void setInterruptMap0(uint8_t bits);
270 
277  uint8_t getInterruptMap1();
278 
286  void setInterruptMap1(uint8_t bits);
287 
296  uint8_t getInterruptSrc();
297 
307  void setInterruptSrc(uint8_t bits);
308 
317  uint8_t getInterruptOutputControl();
318 
328  void setInterruptOutputControl(uint8_t bits);
329 
335  void clearInterruptLatches();
336 
343  BMG160_RST_LATCH_T getInterruptLatchBehavior();
344 
352  void setInterruptLatchBehavior(BMG160_RST_LATCH_T latch);
353 
361  uint8_t getInterruptStatus0();
362 
369  uint8_t getInterruptStatus1();
370 
377  uint8_t getInterruptStatus2();
378 
385  uint8_t getInterruptStatus3();
386 
400  void enableRegisterShadowing(bool shadow);
401 
410  void enableOutputFiltering(bool filter);
411 
412 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
413  void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio,
414  mraa::Edge level, jobject runnable)
415  {
416  installISR(intr, gpio, level, mraa_java_isr_callback, runnable);
417  }
418 #else
419 
433  void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio,
434  mraa::Edge level,
435  void (*isr)(void *), void *arg);
436 #endif
437 
444  void uninstallISR(BMG160_INTERRUPT_PINS_T intr);
445 
452  uint8_t readReg(uint8_t reg);
453 
462  int readRegs(uint8_t reg, uint8_t *buffer, int len);
463 
471  void writeReg(uint8_t reg, uint8_t val);
472 
473  protected:
474  bmg160_context m_bmg160;
475 
476  private:
477  // needs to be private for SWIG Java builds
478 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
479  void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio,
480  mraa::Edge level,
481  void (*isr)(void *), void *arg);
482 #endif
483  };
484 }
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:68
void writeReg(uint8_t reg, uint8_t val)
Definition: bmg160.cxx:92
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