altoslib: Adapt to Mag sensor value ordering changes
[fw/altos] / altoslib / AltosEepromRecordMega.java
index 0abc3fe73865c64bae21ec23d5f39c0f0fee47e7..d0da1b7ccf4b48f31f10b4ab9626c036fad08804 100644 (file)
@@ -73,8 +73,8 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
        private int gyro_y() { return data16(16); }
        private int gyro_z() { return data16(18); }
        private int mag_x() { return data16(20); }
-       private int mag_y() { return data16(22); }
-       private int mag_z() { return data16(24); }
+       private int mag_z() { return data16(22); }
+       private int mag_y() { return data16(24); }
        private int accel() { return data16(26); }
 
        /* AO_LOG_TEMP_VOLT elements */
@@ -142,8 +142,8 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                        int     gyro_pitch = gyro_x();
                        int     gyro_yaw = gyro_z();
 
-                       int     mag_along = mag_x();
-                       int     mag_across = mag_y();
+                       int     mag_along = mag_y();
+                       int     mag_across = mag_x();
                        int     mag_through = mag_z();
 
                        if (log_format == AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD)
@@ -161,11 +161,13 @@ public class AltosEepromRecordMega extends AltosEepromRecord {
                                         cal_data.mag_through(mag_through));
 
 
+                       final double lsb_per_g = 1920.0/105.5;
+
                        double acceleration = AltosConvert.acceleration_from_sensor(
                                accel(),
-                               config_data.accel_cal_plus,
-                               config_data.accel_cal_minus,
-                               AltosLib.MISSING);
+                               cal_data.ground_accel,
+                               cal_data.ground_accel + 2 * lsb_per_g,
+                               cal_data.ground_accel);
 
                        listener.set_acceleration(acceleration);
                        break;