Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.

Dependents:   9Dof_unit_testing

Fork of ADXL345 by James Watanabe

Revision:
10:d81793e01ec4
Parent:
9:cc0260a2404b
--- 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()));
     }