Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ssozonoff
Date:
Sun May 01 13:53:30 2011 +0000
Commit message:
Basic test code

Changed in this revision

HMC6343.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ee865ceb2360 HMC6343.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HMC6343.lib	Sun May 01 13:53:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ssozonoff/code/HMC6343/#2645c4d75671
diff -r 000000000000 -r ee865ceb2360 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 01 13:53:30 2011 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "HMC6343.h"
+
+HMC6343 compass(p9, p10);
+Serial pc(USBTX, USBRX);
+
+Ticker t;
+Ticker t1;
+Heading heading;
+
+volatile bool display_values = true;
+volatile bool sample_sensor = true;
+
+void do_display_values() {
+    display_values = true;
+}
+
+void do_sample_sensor() { sample_sensor = true; }
+
+int main() {
+    pc.baud(115200);
+    t.attach(&do_display_values, 1);
+    t1.attach_us(&do_sample_sensor, 100 * 500);
+    
+    int opMode = compass.getOpMode();
+    printf("Op mode %d\r\n", opMode);    
+    opMode |= HMC6343_CM_MR_5HZ;
+    
+    //opMode &= ~HMC6343_STDBY;
+    //opMode |= HMC6343_RUN;
+    
+    printf("Op mode %d\r\n", opMode);
+    compass.setOpMode(opMode);
+
+    printf("Op mode %d\r\n", compass.getOpMode());
+    
+    printf("Compass software version %d\r\n", compass.getSoftwareVersion());
+    printf("Compass variation %f \r\n", compass.getMagneticVariation()); 
+    printf("Compass measurement rate %d\r\n", compass.getMeasurementRate());   
+
+    //compass.setMagneticVariation(0.52);
+    //printf("Compass variation %f \r\n", compass.getMagneticVariation());
+    
+    printf("IIR Filter : %d\r\n", compass.isOpModeFlagSet(HMC6343_FILTER));    
+    printf("IIR Filter bias : %d\r\n", compass.getIIRFilter());
+
+    //compass.setIIRFilter(4);
+    //printf("IIR Filter bias : %d\r\n", compass.getIIRFilter());
+
+    // seems a restart is needed for this change to happen in the module
+    // compass.setOpMode(opMode &= ~HMC6343_FILTER);
+    // printf("IIR Filter : %d\r\n", compass.isOpModeFlagSet(HMC6343_FILTER));        
+    
+    compass.setReset();
+    
+    while (1) {
+        if (sample_sensor) {
+            compass.sampleHeading(&heading);
+            sample_sensor = false;
+        }
+
+        if (display_values) {
+            pc.printf("bearing %3.1f \r\n", heading.heading);
+            pc.printf("roll %f \r\n", heading.roll);
+            pc.printf("pitch %f \r\n", heading.pitch);
+            display_values = false;
+        }
+    }
+
+}
\ No newline at end of file
diff -r 000000000000 -r ee865ceb2360 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun May 01 13:53:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912