Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BMA180.hxx
Go to the documentation of this file.
1 /*
2  * BMA180.h Created on: 2 Jul 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 BMA180_H_
26 #define BMA180_H_
27 #include "../bus/BusDevice.h"
28 #define BUFFER_SIZE 0x80
29 
30 namespace exploringBB {
31 
36 class BMA180 {
37 
38  enum RANGE {
39  PLUSMINUS_1_G = 0,
40  PLUSMINUS_1POINT5_G = 1,
41  PLUSMINUS_2G = 2,
42  PLUSMINUS_3G = 3,
43  PLUSMINUS_4G = 4,
44  PLUSMINUS_8G = 5,
45  PLUSMINUS_16G = 6
46  };
47 
48  enum BANDWIDTH {
49  BW_10HZ = 0,
50  BW_20HZ = 1,
51  BW_40HZ = 2,
52  BW_75HZ = 3,
53  BW_150HZ = 4,
54  BW_300HZ = 5,
55  BW_600HZ = 6,
56  BW_12OOHZ = 7,
57  BW_HIGHPASS = 8,
58  BW_BANDPASS = 9
59  };
60 
61  enum MODECONFIG {
62  MODE_LOW_NOISE = 0,
63  MODE_LOW_POWER = 3
64  };
65 
66 
67 private:
68  BusDevice *device;
69  unsigned char *registers;
70 
71  int accelerationX;
72  int accelerationY;
73  int accelerationZ;
74 
75  double pitch; //in degrees
76  double roll; //in degrees
77 
78  float temperature; //accurate to 0.5C
79  BMA180::RANGE range;
80  BMA180::BANDWIDTH bandwidth;
81  BMA180::MODECONFIG modeConfig;
82 
83  int convertAcceleration(int msb_addr, int lsb_addr);
84  void calculatePitchAndRoll();
85 
86 public:
87  BMA180(BusDevice *device);
88  void displayMode(int iterations);
89 
90  int readFullSensorState();
91  // The following do physical reads and writes of the sensors
92  int setRange(BMA180::RANGE range);
93  BMA180::RANGE getRange();
94  int setBandwidth(BMA180::BANDWIDTH bandwidth);
95  BMA180::BANDWIDTH getBandwidth();
96  int setModeConfig(BMA180::MODECONFIG mode);
97  BMA180::MODECONFIG getModeConfig();
98  float getTemperature();
99 
100  int getAccelerationX() { return accelerationX; }
101  int getAccelerationY() { return accelerationY; }
102  int getAccelerationZ() { return accelerationZ; }
103 
104  float getPitch() { return pitch; } // in degrees
105  float getRoll() { return roll; } // in degrees
106 
107  virtual ~BMA180();
108 };
109 
110 } /* namespace exploringBB */
111 
112 #endif /* BMA180_H_ */
BMA180(BusDevice *device)
Definition: BMA180.cxx:43
BMA180::MODECONFIG getModeConfig()
Definition: BMA180.cxx:164
BMA180::RANGE getRange()
Definition: BMA180.cxx:114
int readFullSensorState()
Definition: BMA180.cxx:56
float getPitch()
Definition: BMA180.hxx:104
A class to control a BMA180 accelerometer (untested)
Definition: BMA180.hxx:36
int setModeConfig(BMA180::MODECONFIG mode)
int getAccelerationY()
Definition: BMA180.hxx:101
void displayMode(int iterations)
Definition: BMA180.cxx:80
float getRoll()
Definition: BMA180.hxx:105
Definition: BusDevice.cpp:27
int getAccelerationZ()
Definition: BMA180.hxx:102
int setBandwidth(BMA180::BANDWIDTH bandwidth)
Definition: BMA180.cxx:151
This class is the parent of I2C and SPI devices, so that devices that use both SPI and I2C interfaces...
Definition: BusDevice.h:37
int getAccelerationX()
Definition: BMA180.hxx:100
float getTemperature()
Definition: BMA180.cxx:91
BMA180::BANDWIDTH getBandwidth()
Definition: BMA180.cxx:139
int setRange(BMA180::RANGE range)
Definition: BMA180.cxx:125