Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ADXL345.h
Go to the documentation of this file.
1 /*
2  * ADXL345.h Created on: 17 May 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef ADXL345_H_
26 #define ADXL345_H_
27 //#include"../bus/I2CDevice.h"
28 #include "../bus/BusDevice.h"
29 
31 #define BUFFER_SIZE 0x40
32 
33 namespace exploringBB {
34 
39 class ADXL345{
40 
41 public:
43  enum RANGE {
48  };
50  enum RESOLUTION {
51  NORMAL = 0,
52  HIGH = 1
53  };
54 
55 private:
56  BusDevice *device;
57  unsigned char *registers;
58  ADXL345::RANGE range;
59  ADXL345::RESOLUTION resolution;
60  short accelerationX, accelerationY, accelerationZ; // raw 2's complement values
61  float pitch, roll; // in degrees
62  short combineRegisters(unsigned char msb, unsigned char lsb);
63  void calculatePitchAndRoll();
64  virtual int updateRegisters();
65 
66 public:
67  ADXL345(BusDevice *busDevice);
68  virtual int readSensorState();
69 
70  virtual void setRange(ADXL345::RANGE range);
71  virtual ADXL345::RANGE getRange() { return this->range; }
72  virtual void setResolution(ADXL345::RESOLUTION resolution);
73  virtual ADXL345::RESOLUTION getResolution() { return this->resolution; }
74 
75  virtual short getAccelerationX() { return accelerationX; }
76  virtual short getAccelerationY() { return accelerationY; }
77  virtual short getAccelerationZ() { return accelerationZ; }
78  virtual float getPitch() { return pitch; }
79  virtual float getRoll() { return roll; }
80 
81  // Debugging method to display and update the pitch/roll on the one line
82  virtual void displayPitchAndRoll(int iterations = 600);
83  virtual ~ADXL345();
84 };
85 
86 } /* namespace exploringBB */
87 
88 #endif /* ADXL345_H_ */
plus/minus 16g
Definition: ADXL345.h:47
RESOLUTION
The resolution of the sensor. High is only available in +/- 16g range.
Definition: ADXL345.h:50
Specific class for the ADXL345 Accelerometer.
Definition: ADXL345.h:39
virtual void setRange(ADXL345::RANGE range)
Definition: ADXL345.cpp:168
virtual float getPitch()
Definition: ADXL345.h:78
NORMAL 10-bit resolution.
Definition: ADXL345.h:51
virtual int readSensorState()
Definition: ADXL345.cpp:149
virtual ADXL345::RANGE getRange()
Definition: ADXL345.h:71
virtual short getAccelerationZ()
Definition: ADXL345.h:77
virtual void setResolution(ADXL345::RESOLUTION resolution)
Definition: ADXL345.cpp:177
virtual ADXL345::RESOLUTION getResolution()
Definition: ADXL345.h:73
Definition: BusDevice.cpp:27
plus/minus 2g
Definition: ADXL345.h:44
RANGE
An enumeration to define the gravity range of the sensor.
Definition: ADXL345.h:43
This class is the parent of I2C and SPI devices, so that devices that use both SPI and I2C interfaces...
Definition: BusDevice.h:37
HIGH 13-bit resolution.
Definition: ADXL345.h:52
virtual short getAccelerationY()
Definition: ADXL345.h:76
virtual float getRoll()
Definition: ADXL345.h:79
virtual short getAccelerationX()
Definition: ADXL345.h:75
plus/minus 4g
Definition: ADXL345.h:45
virtual void displayPitchAndRoll(int iterations=600)
Definition: ADXL345.cpp:186
plus/minus 8g
Definition: ADXL345.h:46
virtual ~ADXL345()
Definition: ADXL345.cpp:196
ADXL345(BusDevice *busDevice)
Definition: ADXL345.cpp:127