upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.0)
adxl335.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Adapted from the seeedstudio example
6  * https://github.com/Seeed-Studio/Accelerometer_ADXL335
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <mraa/aio.h>
31 
32 #define ADXL335_DEFAULT_AREF 5.0
33 #define ADXL335_SENSITIVITY 0.25 // 0.25v/g
34 
35 namespace upm {
36 
62  class ADXL335 {
63  public:
72  ADXL335(int pinX, int pinY, int pinZ, float aref=ADXL335_DEFAULT_AREF);
73 
77  ~ADXL335();
78 
84  void setZeroX(float zeroX) { m_zeroX = zeroX; };
85 
91  void setZeroY(float zeroY) { m_zeroY = zeroY; };
92 
98  void setZeroZ(float zeroZ) { m_zeroZ = zeroZ; };
99 
107  void values(int *xVal, int *yVal, int *zVal);
108 
109 #ifdef SWIGJAVA
110 
115  int *values();
116 #endif
117 
125  void acceleration(float *xAccel, float *yAccel, float *zAccel);
126 
127 #ifdef SWIGJAVA
128 
133  float *acceleration();
134 #endif
135 
140  void calibrate();
141 
142  private:
143  mraa_aio_context m_aioX;
144  mraa_aio_context m_aioY;
145  mraa_aio_context m_aioZ;
146  float m_aref;
147  float m_zeroX, m_zeroY, m_zeroZ;
148  };
149 }
150 
151 
void calibrate()
Definition: adxl335.cxx:113
void setZeroZ(float zeroZ)
Definition: adxl335.hpp:98
Definition: a110x.hpp:29
~ADXL335()
Definition: adxl335.cxx:66
ADXL335(int pinX, int pinY, int pinZ, float aref=ADXL335_DEFAULT_AREF)
Definition: adxl335.cxx:37
void setZeroY(float zeroY)
Definition: adxl335.hpp:91
void setZeroX(float zeroX)
Definition: adxl335.hpp:84
void values(int *xVal, int *yVal, int *zVal)
Definition: adxl335.cxx:73
void acceleration(float *xAccel, float *yAccel, float *zAccel)
Definition: adxl335.cxx:89
API for the ADXL335 3-Axis Analog Accelerometer.
Definition: adxl335.hpp:62