upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.0)
mma7660.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015-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 <mma7660.h>
27 
28 namespace upm {
29 
59  class MMA7660 {
60  public:
61 
68  MMA7660(int bus, uint8_t address=MMA7660_DEFAULT_I2C_ADDR);
69 
73  virtual ~MMA7660();
74 
82  bool writeByte(uint8_t reg, uint8_t byte);
83 
90  uint8_t readByte(uint8_t reg);
91 
99  void getRawValues(int *x, int *y, int *z);
100 
108  void getAcceleration(float *ax, float *ay, float *az);
109 
117  int getVerifiedAxis(MMA7660_REG_T axis);
118 
124  uint8_t getVerifiedTilt();
125 
132  void setModeActive();
133 
141  void setModeStandby();
142 
150  uint8_t tiltBackFront();
151 
159  uint8_t tiltLandscapePortrait();
160 
166  bool tiltTap();
167 
173  bool tiltShake();
174 
179  void uninstallISR();
180 
189  bool setInterruptBits(uint8_t ibits);
190 
198  bool setSampleRate(MMA7660_AUTOSLEEP_T sr);
199 
200 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
201 
208  float *getAcceleration()
209  {
210  static float values[3];
211  getAcceleration(&values[0], &values[1], &values[2]);
212  return values;
213  }
214 
222  int *getRawValues()
223  {
224  static int values[3];
225  getRawValues(&values[0], &values[1], &values[2]);
226  return values;
227  }
228 
229  void installISR(int pin, jobject runnable)
230  {
231  installISR(pin, mraa_java_isr_callback, runnable);
232  }
233 #else
234 
243  void installISR(int pin, void (*isr)(void *), void *arg);
244 #endif // defined(SWIGJAVA) || defined(JAVACALLBACK)
245 
246  protected:
247  mma7660_context m_mma7660;
248 
249  private:
250  /* Disable implicit copy and assignment operators */
251  MMA7660(const MMA7660&) = delete;
252  MMA7660 &operator=(const MMA7660&) = delete;
253 
254 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
255  void installISR(int pin, void (*isr)(void *), void *arg);
256 #endif
257 
258  };
259 }
bool writeByte(uint8_t reg, uint8_t byte)
Definition: mma7660.cxx:48
void setModeStandby()
Definition: mma7660.cxx:80
void installISR(int pin, void(*isr)(void *), void *arg)
Definition: mma7660.cxx:158
bool tiltTap()
Definition: mma7660.cxx:138
API for the MMA7660 I2C 3-Axis Digital Accelerometer.
Definition: mma7660.hpp:59
bool setSampleRate(MMA7660_AUTOSLEEP_T sr)
Definition: mma7660.cxx:178
bool tiltShake()
Definition: mma7660.cxx:148
Definition: a110x.hpp:29
bool setInterruptBits(uint8_t ibits)
Definition: mma7660.cxx:170
void setModeActive()
Definition: mma7660.cxx:73
void getRawValues(int *x, int *y, int *z)
Definition: mma7660.cxx:66
uint8_t readByte(uint8_t reg)
Definition: mma7660.cxx:56
uint8_t tiltBackFront()
Definition: mma7660.cxx:118
uint8_t tiltLandscapePortrait()
Definition: mma7660.cxx:128
uint8_t getVerifiedTilt()
Definition: mma7660.cxx:108
void getAcceleration(float *ax, float *ay, float *az)
Definition: mma7660.cxx:186
void uninstallISR()
Definition: mma7660.cxx:165
int getVerifiedAxis(MMA7660_REG_T axis)
Definition: mma7660.cxx:88
virtual ~MMA7660()
Definition: mma7660.cxx:43
C API for the mma7660 driver.
Definition: mma7660.h:50
MMA7660(int bus, uint8_t address=MMA7660_DEFAULT_I2C_ADDR)
Definition: mma7660.cxx:35