Alvee Ahmed / virgo3_imuHandler

Fork of virgo3_imuHandler_Orion_PCB by Van Nguyen

Revision:
12:6ec427e47641
Parent:
10:31eee5f90d04
Child:
13:d329bf89c898
--- a/imuHandler.cpp	Thu Jun 16 03:27:34 2016 +0000
+++ b/imuHandler.cpp	Mon Aug 01 06:00:47 2016 +0000
@@ -561,4 +561,40 @@
     imu_BNO055.write_calibration_data();
 }
 
+/***  ***/
+
+/*** MAG3110 ***/
+MAG_3110::MAG_3110(): mag_3110(i2c_SDA, i2c_SCL)
+{
+    unsigned int movWindow_len_Mag = mag3110_MWindowSize;
+
+    if(movWindow_len_Mag <= movWindow_lenMax) movWindow_len_Mag = movWindow_len_Mag;
+    else movWindow_len_Mag = movWindow_lenMax;
+
+    movWindow_index_Mag=0;
+    
+    mag_timer.start();  
+}
+
+void MAG_3110::magUpdate()
+{
+    if(mag_timer.read_ms() >= mag_UpdatePeriodMS)
+    {
+        float mag_data[3];
+        
+        mag_3110.get_uT((float*)mag_data);
+        
+        for(int i=0; i<3; i++) {
+            movWindow_Mag[i][movWindow_index_Mag] = mag_data[i];
+            Mag[i] = generalFunctions::moving_window(movWindow_Mag[i], movWindow_len_Mag);
+        }
+        
+        movWindow_index_Mag++;
+        if(movWindow_index_Mag >= movWindow_len_Mag) movWindow_index_Mag=0;
+    
+        mag_timer.reset();
+    }
+}
+
+
 /***  ***/
\ No newline at end of file