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
bmm150.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 "bmm150.h"
33 
34 namespace upm {
35 
70  class BMM150 {
71  public:
89  BMM150(int bus=BMM150_DEFAULT_I2C_BUS,
90  int addr=BMM150_DEFAULT_ADDR,
91  int cs=-1);
92 
96  ~BMM150();
97 
103  void update();
104 
110  uint8_t getChipID();
111 
123  void getMagnetometer(float *x, float *y, float *z);
124 
133  std::vector<float> getMagnetometer();
134 
145  void init(BMM150_USAGE_PRESETS_T usage=BMM150_USAGE_HIGH_ACCURACY);
146 
156  void setPresetMode(BMM150_USAGE_PRESETS_T usage);
157 
166  void reset();
167 
175  void setOutputDataRate(BMM150_DATA_RATE_T odr);
176 
189  void setPowerBit(bool power);
190 
198  void setOpmode(BMM150_OPERATION_MODE_T opmode);
199 
206  BMM150_OPERATION_MODE_T getOpmode();
207 
215  uint8_t getInterruptEnable();
216 
224  void setInterruptEnable(uint8_t bits);
225 
234  uint8_t getInterruptConfig();
235 
245  void setInterruptConfig(uint8_t bits);
246 
254  uint8_t getInterruptStatus();
255 
265  void setRepetitionsXY(uint8_t reps);
266 
276  void setRepetitionsZ(uint8_t reps);
277 
278 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
279  void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio,
280  mraa::Edge level,
281  jobject runnable)
282  {
283  installISR(intr, gpio, level, mraa_java_isr_callback, runnable);
284  }
285 #else
286 
299  void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio,
300  mraa::Edge level,
301  void (*isr)(void *), void *arg);
302 #endif
303 
310  void uninstallISR(BMM150_INTERRUPT_PINS_T intr);
311 
318  uint8_t readReg(uint8_t reg);
319 
328  int readRegs(uint8_t reg, uint8_t *buffer, int len);
329 
337  void writeReg(uint8_t reg, uint8_t val);
338 
339  protected:
340  bmm150_context m_bmm150;
341 
342  private:
343  // Adding a private function definition for java bindings
344 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
345  void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio,
346  mraa::Edge level,
347  void (*isr)(void *), void *arg);
348 #endif
349  };
350 }
uint8_t getChipID()
Definition: bmm150.cxx:87
uint8_t getInterruptEnable()
Definition: bmm150.cxx:138
void setPowerBit(bool power)
Definition: bmm150.cxx:119
void setPresetMode(BMM150_USAGE_PRESETS_T usage)
Definition: bmm150.cxx:181
void writeReg(uint8_t reg, uint8_t val)
Definition: bmm150.cxx:80
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bmm150.cxx:70
void reset()
Definition: bmm150.cxx:105
C API for the bmm150 driver.
API for the BMM150 3-Axis Geomagnetic Sensor.
Definition: bmm150.hpp:70
~BMM150()
Definition: bmm150.cxx:46
BMM150(int bus=BMM150_DEFAULT_I2C_BUS, int addr=BMM150_DEFAULT_ADDR, int cs=-1)
Definition: bmm150.cxx:38
void setRepetitionsXY(uint8_t reps)
Definition: bmm150.cxx:167
void setRepetitionsZ(uint8_t reps)
Definition: bmm150.cxx:174
void setInterruptConfig(uint8_t bits)
Definition: bmm150.cxx:155
void setOpmode(BMM150_OPERATION_MODE_T opmode)
Definition: bmm150.cxx:126
uint8_t getInterruptConfig()
Definition: bmm150.cxx:150
void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bmm150.cxx:188
std::vector< float > getMagnetometer()
Definition: bmm150.cxx:97
void uninstallISR(BMM150_INTERRUPT_PINS_T intr)
Definition: bmm150.cxx:198
Definition: bmm150.h:54
void setInterruptEnable(uint8_t bits)
Definition: bmm150.cxx:143
void setOutputDataRate(BMM150_DATA_RATE_T odr)
Definition: bmm150.cxx:112
uint8_t getInterruptStatus()
Definition: bmm150.cxx:162
uint8_t readReg(uint8_t reg)
Definition: bmm150.cxx:65
void update()
Definition: bmm150.cxx:58
void init(BMM150_USAGE_PRESETS_T usage=BMM150_USAGE_HIGH_ACCURACY)
Definition: bmm150.cxx:51
BMM150_OPERATION_MODE_T getOpmode()
Definition: bmm150.cxx:133