upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bma250e.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 "bma250e.h"
33 
34 namespace upm {
35 
76  class BMA250E {
77  public:
78 
95  BMA250E(int bus=BMA250E_DEFAULT_I2C_BUS,
96  int addr=BMA250E_DEFAULT_ADDR,
97  int cs=-1);
98 
102  ~BMA250E();
103 
109  void update();
110 
116  uint8_t getChipID();
117 
129  void getAccelerometer(float *x, float *y, float *z);
130 
139  std::vector<float> getAccelerometer();
140 
150  float getTemperature(bool fahrenheit=false);
151 
165  void init(BMA250E_POWER_MODE_T pwr=BMA250E_POWER_MODE_NORMAL,
166  BMA250E_RANGE_T range=BMA250E_RANGE_2G,
167  BMA250E_BW_T bw=BMA250E_BW_250);
168 
177  void reset();
178 
186  void setRange(BMA250E_RANGE_T range);
187 
194  void setBandwidth(BMA250E_BW_T bw);
195 
214  void setPowerMode(BMA250E_POWER_MODE_T power);
215 
233  void enableFIFO(bool useFIFO);
234 
243  void fifoSetWatermark(int wm);
244 
254  void fifoConfig(BMA250E_FIFO_MODE_T mode,
255  BMA250E_FIFO_DATA_SEL_T axes);
256 
268  void setSelfTest(bool sign, bool amp, BMA250E_SELFTTEST_AXIS_T axis);
269 
277  uint8_t getInterruptEnable0();
278 
286  void setInterruptEnable0(uint8_t bits);
287 
294  uint8_t getInterruptEnable1();
295 
303  void setInterruptEnable1(uint8_t bits);
304 
311  uint8_t getInterruptEnable2();
312 
320  void setInterruptEnable2(uint8_t bits);
321 
329  uint8_t getInterruptMap0();
330 
339  void setInterruptMap0(uint8_t bits);
340 
347  uint8_t getInterruptMap1();
348 
356  void setInterruptMap1(uint8_t bits);
357 
364  uint8_t getInterruptMap2();
365 
373  void setInterruptMap2(uint8_t bits);
374 
383  uint8_t getInterruptSrc();
384 
394  void setInterruptSrc(uint8_t bits);
395 
404  uint8_t getInterruptOutputControl();
405 
415  void setInterruptOutputControl(uint8_t bits);
416 
422  void clearInterruptLatches();
423 
430  BMA250E_RST_LATCH_T getInterruptLatchBehavior();
431 
439  void setInterruptLatchBehavior(BMA250E_RST_LATCH_T latch);
440 
448  uint8_t getInterruptStatus0();
449 
456  uint8_t getInterruptStatus1();
457 
464  uint8_t getInterruptStatus2();
465 
474  uint8_t getInterruptStatus3Bits();
475 
482  BMA250E_ORIENT_T getInterruptStatus3Orientation();
483 
497  void enableRegisterShadowing(bool shadow);
498 
508  void enableOutputFiltering(bool filter);
509 
518  void setLowPowerMode2();
519 
520 
534  void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio,
535  mraa::Edge level,
536  void (*isr)(void *), void *arg);
537 
544  void uninstallISR(BMA250E_INTERRUPT_PINS_T intr);
545 
552  uint8_t readReg(uint8_t reg);
553 
562  int readRegs(uint8_t reg, uint8_t *buffer, int len);
563 
571  void writeReg(uint8_t reg, uint8_t val);
572 
573  protected:
574  bma250e_context m_bma250e;
575 
576  private:
577  /* Disable implicit copy and assignment operators */
578  BMA250E(const BMA250E&) = delete;
579  BMA250E &operator=(const BMA250E&) = delete;
580 
581  };
582 }
void uninstallISR(BMA250E_INTERRUPT_PINS_T intr)
Definition: bma250e.cxx:347
void setPowerMode(BMA250E_POWER_MODE_T power)
Definition: bma250e.cxx:147
BMA250E(int bus=BMA250E_DEFAULT_I2C_BUS, int addr=BMA250E_DEFAULT_ADDR, int cs=-1)
Definition: bma250e.cxx:44
void fifoSetWatermark(int wm)
Definition: bma250e.cxx:154
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bma250e.cxx:82
uint8_t getInterruptEnable0()
Definition: bma250e.cxx:176
void setInterruptSrc(uint8_t bits)
Definition: bma250e.cxx:253
void setBandwidth(BMA250E_BW_T bw)
Definition: bma250e.cxx:140
void setInterruptMap1(uint8_t bits)
Definition: bma250e.cxx:229
C API for the bma250e driver.
uint8_t getInterruptEnable2()
Definition: bma250e.cxx:200
void enableRegisterShadowing(bool shadow)
Definition: bma250e.cxx:291
void writeReg(uint8_t reg, uint8_t val)
Definition: bma250e.cxx:92
uint8_t readReg(uint8_t reg)
Definition: bma250e.cxx:77
void setInterruptEnable0(uint8_t bits)
Definition: bma250e.cxx:181
uint8_t getInterruptSrc()
Definition: bma250e.cxx:248
void setInterruptOutputControl(uint8_t bits)
Definition: bma250e.cxx:265
float getTemperature(bool fahrenheit=false)
Definition: bma250e.cxx:117
void setLowPowerMode2()
Definition: bma250e.cxx:330
uint8_t getInterruptMap2()
Definition: bma250e.cxx:236
void setInterruptMap0(uint8_t bits)
Definition: bma250e.cxx:217
BMA250E_ORIENT_T getInterruptStatus3Orientation()
Definition: bma250e.cxx:325
uint8_t getInterruptStatus0()
Definition: bma250e.cxx:305
void reset()
Definition: bma250e.cxx:126
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
Definition: bma250e.h:54
void setInterruptEnable1(uint8_t bits)
Definition: bma250e.cxx:193
uint8_t getInterruptStatus2()
Definition: bma250e.cxx:315
~BMA250E()
Definition: bma250e.cxx:52
void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bma250e.cxx:337
void setSelfTest(bool sign, bool amp, BMA250E_SELFTTEST_AXIS_T axis)
Definition: bma250e.cxx:169
void clearInterruptLatches()
Definition: bma250e.cxx:272
void setInterruptEnable2(uint8_t bits)
Definition: bma250e.cxx:205
uint8_t getInterruptStatus1()
Definition: bma250e.cxx:310
void fifoConfig(BMA250E_FIFO_MODE_T mode, BMA250E_FIFO_DATA_SEL_T axes)
Definition: bma250e.cxx:161
void update()
Definition: bma250e.cxx:65
void enableFIFO(bool useFIFO)
Definition: bma250e.cxx:72
API for the BMA250E 10 bit Triaxial Accelerometer.
Definition: bma250e.hpp:76
void setInterruptMap2(uint8_t bits)
Definition: bma250e.cxx:241
std::vector< float > getAccelerometer()
Definition: bma250e.cxx:109
uint8_t getInterruptMap0()
Definition: bma250e.cxx:212
uint8_t getInterruptStatus3Bits()
Definition: bma250e.cxx:320
uint8_t getChipID()
Definition: bma250e.cxx:99
void enableOutputFiltering(bool filter)
Definition: bma250e.cxx:298
void init(BMA250E_POWER_MODE_T pwr=BMA250E_POWER_MODE_NORMAL, BMA250E_RANGE_T range=BMA250E_RANGE_2G, BMA250E_BW_T bw=BMA250E_BW_250)
Definition: bma250e.cxx:57
void setInterruptLatchBehavior(BMA250E_RST_LATCH_T latch)
Definition: bma250e.cxx:284
uint8_t getInterruptMap1()
Definition: bma250e.cxx:224
void setRange(BMA250E_RANGE_T range)
Definition: bma250e.cxx:133
BMA250E_RST_LATCH_T getInterruptLatchBehavior()
Definition: bma250e.cxx:279
uint8_t getInterruptEnable1()
Definition: bma250e.cxx:188
uint8_t getInterruptOutputControl()
Definition: bma250e.cxx:260