Unit testing and development for 9DOF sparkfun sensor stick

Dependencies:   ADXL345 HMC5883L ITG3200 mbed

Revision:
2:d7e66940541d
Parent:
1:dc730a26cdc2
Child:
3:5e21a352e236
--- a/main.cpp	Tue Oct 30 23:47:14 2012 +0000
+++ b/main.cpp	Thu Nov 01 18:46:58 2012 +0000
@@ -1,5 +1,5 @@
 /**
- 10 second 9-dof data log
+ 9-dof unit testing
 
  The purpose of this program is to demonstrate and calibrate the three
  sensors on teh 9-doft board.
@@ -10,147 +10,39 @@
  See: http://mbed.org/users/gltest26/code/ITG3200/wiki/Thermal-Drift
 
  The second versoin of this will test the HMC5883L 3 axis magnometer
+
+ The thrid version tests the ADXL345 library.
 */
 
 #include "mbed.h"
 //#include "ITG3200.h"
-
-// configuration register a
-#define AVG1_SAMPLES    0x00
-#define AVG2_SAMPLES    0x20
-#define AVG4_SAMPLES    0x80
-#define AVG8_SAMPLES    0xC0
-
-#define OUTPUT_RATE_0_75    0x00
-#define OUTPUT_RATE_1_5     0x04
-#define OUTPUT_RATE_3       0x08
-#define OUTPUT_RATE_7_5     0x0C
-#define OUTPUT_RATE_15      0x10
-#define OUTPUT_RATE_30      0x14
-#define OUTPUT_RATE_75      0x18
-
-#define NORMAL_MEASUREMENT  0x00
-#define POSITIVE_BIAS       0x01
-#define NEGATIVE_BIAS       0x02
-
-// mode register
-#define CONTINUOUS_MODE     0x00
-#define SINGLE_MODE         0x01
-#define IDLE_MODE           0x02
-
-// status register 
-#define LOCK        0x02
-#define READY       0x01
-
-char addr = 0x3D;
-
-I2C i2c_(p28, p27); // sda, scl
-
-void setConfigurationA(char,char,char);
-char getConfigurationA();
-void setConfigurationB(char);
-char getConfigurationB();
-void setMode(char);
-char getMode();
-void getXYZ(int*);
-char getStatus();
-
-void setConfigurationA(char averaged_samples = AVG1_SAMPLES, char output_rate = OUTPUT_RATE_15, char measurement_mode = NORMAL_MEASUREMENT)
-{
-    char cmd[2];
-    cmd[0] = 0x00; // register a address
-    cmd[1] = averaged_samples | output_rate | measurement_mode;
-    
-    i2c_.write(addr, cmd, 2);
-}
+//#include "HMC5883L.h"
 
-char getConfigurationA()
-{
-    char cmd[2];
-    cmd[0] = 0x00; // register a address
-    i2c_.write(addr, cmd, 1, true);
-    i2c_.read(addr, &cmd[1], 1, false);
-    return cmd[1];
-}
-
-void setConfigurationB(char gain = 0x20) // default value 0x20
-{
-    char cmd[2];
-    cmd[0] = 0x01;
-    cmd[1] = gain;
-    
-    i2c_.write(addr, cmd, 2);
-}
-
-char getConfigurationB()
-{
-    char cmd[2];
-    cmd[0] = 0x01; // register b address
-    i2c_.write(addr, cmd, 1, true);
-    i2c_.read(addr, &cmd[1], 1, false);
-    return cmd[1];
-}
-
-void setMode(char mode = SINGLE_MODE)
-{
-    char cmd[2];
-    cmd[0] = 0x02; // mode register address
-    cmd[1] = mode;
-    i2c_.write(addr,cmd,2);
-}
-
-char getMode()
-{
-    char cmd[2];
-    cmd[0] = 0x02; // mode register address
-    i2c_.write(addr, cmd, 1, true);
-    i2c_.read(addr, &cmd[1], 1, false);
-    return cmd[1];
-}
-
-void getXYZ(int output[3])
-{
-    char cmd[2];
-    char data[6];
-    cmd[0] = 0x03; // starting point for reading
-    i2c_.write(addr, cmd, 1, true); // set the pointer to the start of x
-    i2c_.read(addr, data, 6, false);
-    
-    for(int i = 0; i < 3; i++) // fill the output variables
-        output[i] = (data[i*2] << 8) + data[i*2+1];
-}
-
-char getStatus()
-{
-    char cmd[2];
-    cmd[0] = 0x09; // status register address
-    i2c_.write(addr, cmd, 1, true);
-    i2c_.read(addr, &cmd[1], 1, false);
-    return cmd[1];
-}
+I2C i2c_bus(p28, p27);
 
 int main()
 {
+
+}
+
+/*
+void hmc5883l_test()
+{
     Serial pc(USBTX, USBRX);
-    
+
     pc.baud(9600);
     
+    HMC5883L compass(i2c_bus);
+
     int data[3];
-    
-    // configure
-    setConfigurationA(AVG8_SAMPLES); // 8 sample average, 15Hz, normal mode
-    setConfigurationB(); // default (0x20)
-    setMode(CONTINUOUS_MODE); // continuous sample mode
-    wait(0.006); // 6 milisecond pause to allow registers to fill up
-    
-    while(1)
-    {
-        getXYZ(data);
-        pc.printf("x: 0x%4x, y: 0x%4x, z: 0x%4x\r\n", data[0], data[1], data[2]);
+
+    while(1) {
+        compass.getXYZ(data);
+        pc.printf("x: %4d, y: %4d, z: %4d\r\n", data[0], data[1], data[2]);
         wait(0.067);
     }
 }
-
+*/
 /*
 void itg3200_test()
 {