Permalink
Browse files

added compatibility functions to match the api of the ADXL345 library…

… more closely.
  • Loading branch information...
1 parent 02648cb commit 71aeb0030a26994738f450c789085595ece52622 Noah committed Apr 25, 2012
Showing with 21 additions and 8 deletions.
  1. +8 −6 MMA8453_n0m1.cpp
  2. +12 −1 MMA8453_n0m1.h
  3. +1 −1 examples/MMA8453_n0m1_dataMode/MMA8453_n0m1_dataMode.ino
View
@@ -41,6 +41,7 @@ MMA8453_n0m1::MMA8453_n0m1()
shakeAxisY_ = false;
shakeAxisZ_ = false;
I2CAddr = 0x1c; //The i2C address of the MMA8453 chip. 0x1D is another common value.
+ gScaleRange_ = 2; //default 2g
}
@@ -53,7 +54,7 @@ MMA8453_n0m1::MMA8453_n0m1()
***********************************************************/
void MMA8453_n0m1::setI2CAddr(int address)
{
- I2CAddr = address; I2CAddr;
+ I2CAddr = address; I2CAddr;
}
/***********************************************************
@@ -182,6 +183,7 @@ void MMA8453_n0m1::xyz(int& x, int& y, int& z)
void MMA8453_n0m1::dataMode(boolean highRes, int gScaleRange)
{
highRes_ = highRes;
+ gScaleRange_ = gScaleRange;
dataMode_ = true;
byte statusCheck;
byte activeMask = 0x01;
@@ -194,11 +196,11 @@ void MMA8453_n0m1::dataMode(boolean highRes, int gScaleRange)
I2c.read(I2CAddr,REG_CTRL_REG1,byte(1),&statusCheck);
I2c.write(I2CAddr, REG_CTRL_REG1, byte(statusCheck & ~activeMask));
- if( gScaleRange <= 3){ gScaleRange = FULL_SCALE_RANGE_2g; } //0-3 = 2g
- else if( gScaleRange <= 5){ gScaleRange = FULL_SCALE_RANGE_4g; } //4-5 = 4g
- else if( gScaleRange <= 8){ gScaleRange = FULL_SCALE_RANGE_8g; }// 6-8 = 8g
- else if( gScaleRange > 8) { gScaleRange = FULL_SCALE_RANGE_8g; } //boundary
- I2c.write(I2CAddr,REG_XYZ_DATA_CFG, byte(gScaleRange));
+ if( gScaleRange_ <= 3){ gScaleRange_ = FULL_SCALE_RANGE_2g; } //0-3 = 2g
+ else if( gScaleRange_ <= 5){ gScaleRange_ = FULL_SCALE_RANGE_4g; } //4-5 = 4g
+ else if( gScaleRange_ <= 8){ gScaleRange_ = FULL_SCALE_RANGE_8g; }// 6-8 = 8g
+ else if( gScaleRange_ > 8) { gScaleRange_ = FULL_SCALE_RANGE_8g; } //boundary
+ I2c.write(I2CAddr,REG_XYZ_DATA_CFG, byte(gScaleRange_));
//set highres 10bit or lowres 8bit
I2c.read(I2CAddr,REG_CTRL_REG1,byte(1),&statusCheck);
View
@@ -116,7 +116,6 @@ class MMA8453_n0m1 {
***********************************************************/
void setI2CAddr(int address);
-
/***********************************************************
*
* dataMode
@@ -242,6 +241,17 @@ boolean motion() { boolean motionOut = motion_; motion_ = false; return motionOu
void regWrite(byte reg, byte val);
+//-----------------------------------------------------------
+// Compatiblity functions to match the api of the ADXL345 library
+// http://code.google.com/p/adxl345driver/
+// allows for more easy updates of code from the ADXL345 to the MMA8453
+//-----------------------------------------------------------
+void setRangeSetting(int gScaleRange) { gScaleRange_ = gScaleRange; } //call this before setFullResBit()
+void setFullResBit(boolean highRes) { dataMode(highRes,gScaleRange_); }
+void readAccel(int *x, int *y, int *z) { xyz(*x,*y,*z); }
+
+
+
private:
void xyz(int& x,int& y, int& z);
@@ -252,6 +262,7 @@ boolean motion() { boolean motionOut = motion_; motion_ = false; return motionOu
byte I2CAddr;
boolean highRes_;
+ int gScaleRange_;
boolean dataMode_;
boolean shakeMode_;
boolean motionMode_;
@@ -26,7 +26,7 @@ void setup()
void loop()
{
accel.update();
-
+
Serial.print("x: ");
Serial.print(accel.x());
Serial.print(" y: ");

0 comments on commit 71aeb00

Please sign in to comment.