Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.
Fork of ADXL345 by
Revision 10:d81793e01ec4, committed 2012-11-06
- Comitter:
- tylerjw
- Date:
- Tue Nov 06 17:36:40 2012 +0000
- Parent:
- 9:cc0260a2404b
- Commit message:
- removed config.txt, hardcoded offset, int to int16_t
Changed in this revision
ADXL345.cpp | Show annotated file Show diff for this revision Revisions of this file |
ADXL345.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r cc0260a2404b -r d81793e01ec4 ADXL345.cpp --- a/ADXL345.cpp Tue Nov 06 16:40:36 2012 +0000 +++ b/ADXL345.cpp Tue Nov 06 17:36:40 2012 +0000 @@ -66,28 +66,19 @@ delete myI2c; } - void ADXL345::init() { - setDataRate(ADXL345_6HZ25); // 6.25 Hz - + setDataRate(ADXL345_25HZ); + setPowerMode(0); // high power setDataFormatControl(ADXL345_FULL_RES | ADXL345_2G); // full resolution, right justified, 2g range - - LocalFileSystem local("local"); + setFifoControl(0x00); // bypass mode + setPowerControl(0x08); // start measurements - if(FILE *fp = fopen("/local/config.txt", "r")) { // Open "config.txt" for reading - if it doesn't exist, pass over it - int8_t calibration_offset[3]; - DigitalOut led(LED1); - led = 1; - fscanf(fp, "ADXL345 x:%d,y:%d,z:%d", &calibration_offset[0], &calibration_offset[1], &calibration_offset[2]); - fclose(fp); - for(char axis = 0x00; axis < 0x03; axis++) - setOffset(axis,calibration_offset[axis]); - led = 0; - } + int8_t calibration_offset[3] = {-5,-4,2}; // calibration offset values + for(char axis = 0x00; axis < 0x03; axis++) + setOffset(axis,calibration_offset[axis]); } - char ADXL345::SingleByteRead(char address) { char tx = address; @@ -133,7 +124,7 @@ } -void ADXL345::getOutput(int16_t* readings) +void ADXL345::getXYZ(int16_t* readings) { char buffer[6]; multiByteRead(ADXL345_DATAX0_REG, buffer, 6); @@ -420,7 +411,7 @@ for(int sample = 0; sample < 100; sample++) { start_time = t->read(); - getOutput(buffer[sample]); + getXYZ(buffer[sample]); wait(period - (start_time - t->read())); }
diff -r cc0260a2404b -r d81793e01ec4 ADXL345.h --- a/ADXL345.h Tue Nov 06 16:40:36 2012 +0000 +++ b/ADXL345.h Tue Nov 06 17:36:40 2012 +0000 @@ -163,7 +163,7 @@ * @param Pointer to a buffer to hold the accelerometer value for the * x-axis, y-axis and z-axis [in that order]. */ - void getOutput(int16_t* readings); + void getXYZ(int16_t* readings); /** * Read the device ID register on the device.