Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
exploringBB::BMA180 Class Reference

A class to control a BMA180 accelerometer (untested) More...

#include <BMA180.hxx>

Public Member Functions

 BMA180 (BusDevice *device)
 
void displayMode (int iterations)
 
int readFullSensorState ()
 
int setRange (BMA180::RANGE range)
 
BMA180::RANGE getRange ()
 
int setBandwidth (BMA180::BANDWIDTH bandwidth)
 
BMA180::BANDWIDTH getBandwidth ()
 
int setModeConfig (BMA180::MODECONFIG mode)
 
BMA180::MODECONFIG getModeConfig ()
 
float getTemperature ()
 
int getAccelerationX ()
 
int getAccelerationY ()
 
int getAccelerationZ ()
 
float getPitch ()
 
float getRoll ()
 
virtual ~BMA180 ()
 

Detailed Description

A class to control a BMA180 accelerometer (untested)

Constructor & Destructor Documentation

exploringBB::BMA180::BMA180 ( BusDevice device)
43  {
44  this->device = device;
46 }
int readFullSensorState()
Definition: BMA180.cxx:56
virtual exploringBB::BMA180::~BMA180 ( )
virtual

Member Function Documentation

void exploringBB::BMA180::displayMode ( int  iterations)
80  {
81  for(int i=0; i<iterations; i++){
82  this->readFullSensorState();
83  printf("Rotation (%d, %d, %d)", accelerationX, accelerationY, accelerationZ);
84  }
85 }
int readFullSensorState()
Definition: BMA180.cxx:56
int exploringBB::BMA180::getAccelerationX ( )
inline
100 { return accelerationX; }
int exploringBB::BMA180::getAccelerationY ( )
inline
101 { return accelerationY; }
int exploringBB::BMA180::getAccelerationZ ( )
inline
102 { return accelerationZ; }
BMA180::BANDWIDTH exploringBB::BMA180::getBandwidth ( )
139  {
140  this->readFullSensorState();
141  char temp = *(registers+BMA_BANDWIDTH); //bits 7->4
142  //char temp = this->readI2CDeviceByte(BANDWIDTH); //bits 7,6,5,4
143 // cout << "The value of bandwidth returned is: " << (int)temp << endl;
144  temp = temp & 0b11110000;
145  temp = temp>>4;
146 // cout << "The current bandwidth is: " << (int)temp << endl;
147  this->bandwidth = (BMA180::BANDWIDTH) temp;
148  return this->bandwidth;
149 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define BMA_BANDWIDTH
Definition: BMA180.cxx:38
BMA180::MODECONFIG exploringBB::BMA180::getModeConfig ( )
164  {
165  //char temp = dataBuffer[MODE_CONFIG]; //bits 1,0
166  //char temp = this->readI2CDeviceByte(MODE_CONFIG); //bits 1,0
167  this->readFullSensorState();
168  char temp = *(registers+MODE_CONFIG);
169  temp = temp & 0b00000011;
170  this->modeConfig = (BMA180::MODECONFIG) temp;
171  return this->modeConfig;
172 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define MODE_CONFIG
Definition: BMA180.cxx:39
float exploringBB::BMA180::getPitch ( )
inline
104 { return pitch; } // in degrees
BMA180::RANGE exploringBB::BMA180::getRange ( )
114  {
115  this->readFullSensorState();
116  char temp = *(registers+BMA_RANGE);
117  //char temp = this->readI2CDeviceByte(RANGE); //bits 3,2,1
118  temp = temp & 0b00001110;
119  temp = temp>>1;
120  //cout << "The current range is: " << (int)temp << endl;
121  this->range = (BMA180::RANGE) temp;
122  return this->range;
123 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define BMA_RANGE
Definition: BMA180.cxx:37
float exploringBB::BMA180::getRoll ( )
inline
105 { return roll; } // in degrees
float exploringBB::BMA180::getTemperature ( )
91  {
92 
93  int offset = -40; // -40 degrees C
94  this->readFullSensorState();
95  char temp = *(registers+BMA_TEMP); // = -80C 0b10000000 0b00000010; = +25C
96  //char temp = this->readI2CDeviceByte(TEMP);
97  //this->readFullSensorState();
98  //char temp = dataBuffer[TEMP];
99  int temperature;
100  if(temp&0x80) {
101  temp = ~temp + 0b00000001;
102  temperature = 128 - temp;
103  }
104  else {
105  temperature = 128 + temp;
106  }
107  this->temperature = offset + ((float)temperature*0.5f);
108  //cout << "The temperature is " << this->temperature << endl;
109  //int temp_off = dataBuffer[0x37]>>1;
110  //cout << "Temperature offset raw value is: " << temp_off << endl;
111  return this->temperature;
112 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define BMA_TEMP
Definition: BMA180.cxx:36
int exploringBB::BMA180::readFullSensorState ( )
56  {
57  this->registers = this->device->readRegisters(BUFFER_SIZE, 0x00);
58  if(*this->registers!=0x03){
59  perror("BMA180: Failure Condition - Sensor ID not Verified");
60  return -1;
61  }
62  this->accelerationX = convertAcceleration(ACC_X_MSB, ACC_X_LSB);
63  this->accelerationY = convertAcceleration(ACC_Y_MSB, ACC_Y_LSB);
64  this->accelerationZ = convertAcceleration(ACC_Z_MSB, ACC_Z_LSB);
65  this->calculatePitchAndRoll();
66  //cout << "Pitch:" << this->getPitch() << " Roll:" << this->getRoll() << endl;
67  return 0;
68 }
#define ACC_X_MSB
Definition: BMA180.cxx:31
#define ACC_Z_MSB
Definition: BMA180.cxx:35
#define BUFFER_SIZE
The ADXL345 has 0x40 registers (0x01 to 0x1C are reserved and should not be accessed) ...
Definition: ADXL345.h:31
#define ACC_Y_LSB
Definition: BMA180.cxx:32
#define ACC_Y_MSB
Definition: BMA180.cxx:33
#define ACC_X_LSB
Definition: BMA180.cxx:30
#define ACC_Z_LSB
Definition: BMA180.cxx:34
virtual unsigned char * readRegisters(unsigned int number, unsigned int fromAddress=0)=0
int exploringBB::BMA180::setBandwidth ( BMA180::BANDWIDTH  bandwidth)
151  {
152  this->readFullSensorState();
153  char current = *(registers+BMA_BANDWIDTH); //bits 7->4
154  char temp = bandwidth << 4; //move value into bits 7,6,5,4
155  current = current & 0b00001111; //clear the current bits 7,6,5,4
156  temp = current | temp;
157  if(this->device->writeRegister(BMA_BANDWIDTH,temp)!=0){
158  perror("Failure to update BANDWIDTH value\n");
159  return 1;
160  }
161  return 0;
162 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define BMA_BANDWIDTH
Definition: BMA180.cxx:38
virtual int writeRegister(unsigned int registerAddress, unsigned char value)=0
int exploringBB::BMA180::setModeConfig ( BMA180::MODECONFIG  mode)
int exploringBB::BMA180::setRange ( BMA180::RANGE  range)
125  {
126  //char current = this->readI2CDeviceByte(RANGE); //bits 3,2,1
127  this->readFullSensorState();
128  char current = *(registers+BMA_RANGE);
129  char temp = range << 1; //move value into bits 3,2,1
130  current = current & 0b11110001; //clear the current bits 3,2,1
131  temp = current | temp;
132  if(this->device->writeRegister(BMA_RANGE,temp)!=0){
133  perror("Failure to update RANGE value\n");
134  return 1;
135  }
136  return 0;
137 }
int readFullSensorState()
Definition: BMA180.cxx:56
#define BMA_RANGE
Definition: BMA180.cxx:37
virtual int writeRegister(unsigned int registerAddress, unsigned char value)=0

The documentation for this class was generated from the following files: