Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
KTOWN committed Jul 10, 2013
1 parent cd96c7b commit b6118ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Adafruit_ADXL345.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static int16_t getZ(void) {
/**************************************************************************/
Adafruit_ADXL345::Adafruit_ADXL345(int32_t sensorID) {
_sensorID = sensorID;
_range = ADXL345_RANGE_2_G;
}

/**************************************************************************/
Expand Down Expand Up @@ -183,6 +184,9 @@ void Adafruit_ADXL345::setRange(range_t range)

/* Write the register back to the IC */
writeRegister(ADXL345_REG_DATA_FORMAT, format);

/* Keep track of the current range (to avoid readbacks) */
_range = range;
}

/**************************************************************************/
Expand All @@ -203,7 +207,7 @@ range_t Adafruit_ADXL345::getRange(void)
/**************************************************************************/
void Adafruit_ADXL345::setDataRate(dataRate_t dataRate)
{
/* Note: The LOW_POWER bits are currently ignore and we always keep
/* Note: The LOW_POWER bits are currently ignored and we always keep
the device in 'normal' mode */
writeRegister(ADXL345_REG_BW_RATE, dataRate);
}
Expand Down Expand Up @@ -231,9 +235,9 @@ void Adafruit_ADXL345::getEvent(sensors_event_t *event) {
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_ACCELEROMETER;
event->timestamp = 0;
event->acceleration.x = x * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
event->acceleration.y = y * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
event->acceleration.z = z * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
event->acceleration.x = getX() * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
event->acceleration.y = getY() * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
event->acceleration.z = getZ() * ADXL345_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD;
}

/**************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions Adafruit_ADXL345.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ class Adafruit_ADXL345 : public Adafruit_Sensor {

private:
int32_t _sensorID;
range_t _range;
};
6 changes: 6 additions & 0 deletions examples/sensortest/sensortest.pde
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ void setup(void)
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}

/* Set the range to whatever is appropriate for your project */
accel.setRange(ADXL345_RANGE_16_G);
// displaySetRange(ADXL345_RANGE_8_G);
// displaySetRange(ADXL345_RANGE_4_G);
// displaySetRange(ADXL345_RANGE_2_G);

/* Display some basic information on this sensor */
displaySensorDetails();
Expand Down

0 comments on commit b6118ee

Please sign in to comment.