Added external magnetometer functionality

Dependencies:   HMC58X31 MODI2C MPU6050 MS561101BA

Dependents:   Quadcopter_mk2

Fork of FreeIMU by Yifei Teng

Revision:
17:48a0eae27bf1
Parent:
15:ea86489d606b
--- a/FreeIMU.cpp	Wed Sep 24 01:11:50 2014 +0000
+++ b/FreeIMU.cpp	Wed Mar 04 18:50:06 2015 +0000
@@ -115,7 +115,7 @@
 
     accgyro->initialize();
     accgyro->setI2CMasterModeEnabled(0);
-    accgyro->setI2CBypassEnabled(1);
+    accgyro->setI2CBypassEnabled(0);
     accgyro->setFullScaleGyroRange(MPU6050_GYRO_FS_1000);
     accgyro->setDLPFMode(0);
     accgyro->setRate(0);
@@ -127,9 +127,9 @@
 
     // init HMC5843
     magn->init(false); // Don't set mode yet, we'll do that later on.
-    magn->setGain(0);
+    magn->setGain(1);
     // Calibrate HMC using self test, not recommended to change the gain after calibration.
-    magn->calibrate(0, 8); // Use gain 1=default, valid 0-7, 7 not recommended.
+    magn->calibrate(1, 8); // Use gain 1=default, valid 0-7, 7 not recommended.
     Thread::wait(30);
     magn->setDOR(6);
     Thread::wait(30);
@@ -410,7 +410,7 @@
 // lastUpdate = now;
     // gyro values are expressed in deg/sec, the * M_PI/180 will convert it to radians/sec
 
-    AHRSupdate(val[3] * M_PI/180.0, val[4] * M_PI/180.0, val[5] * M_PI/180.0, val[0], val[1], val[2], val[6], val[7], val[8], magn_valid);
+    AHRSupdate(val[3] * M_PI/180.0, val[4] * M_PI/180.0, val[5] * M_PI/180.0, val[0], val[1], val[2], val[6], -val[7], -val[8], magn_valid);
 
     if (q!=NULL) {
         q[0] = q0;