altos: Add bit-bang i2c driver
[fw/altos] / altoslib / AltosConfigData.java
index bb7f5bcc374a8ef725df606761dae2607a3b5d52..b6105f92fc3cb27265e087fb530d84da2f2f79e8 100644 (file)
@@ -199,10 +199,18 @@ public class AltosConfigData {
                case AltosLib.AO_LOG_FORMAT_FULL:
                        return 0x7fff - value;
                case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
-               case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
                case AltosLib.AO_LOG_FORMAT_TELEMEGA:
                case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
                        return 4095 - value;
+               case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
+                       /*
+                        * TeleMetrum v2 and later use the same log format, but
+                        * have different accelerometers. This is the only place
+                        * it matters in altoslib.
+                        */
+                       if (product.startsWith("TeleMetrum-v2"))
+                               return 4095 - value;
+                       /* fall through */
                case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
                case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
                case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
@@ -215,6 +223,8 @@ public class AltosConfigData {
        }
 
        public boolean has_monitor_battery() {
+               if (product == null)
+                       return false;
                if (product.startsWith("TeleBT"))
                        return true;
                return false;
@@ -321,6 +331,9 @@ public class AltosConfigData {
        /* Return + accel calibration relative to a specific pad orientation */
        public int accel_cal_plus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -338,6 +351,9 @@ public class AltosConfigData {
        /* Return - accel calibration relative to a specific pad orientation */
        public int accel_cal_minus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -357,6 +373,7 @@ public class AltosConfigData {
         */
        private void adjust_accel_cal() {
                if (!accel_cal_adjusted &&
+                   product != null &&
                    pad_orientation != AltosLib.MISSING &&
                    accel_cal_plus != AltosLib.MISSING &&
                    accel_cal_minus != AltosLib.MISSING)
@@ -538,9 +555,6 @@ public class AltosConfigData {
                                }
                        }
                } catch (Exception e) {}
-
-               /* Fix accel cal as soon as all of the necessary values appear */
-               adjust_accel_cal();
        }
 
        public AltosConfigData() {
@@ -914,5 +928,6 @@ public class AltosConfigData {
                        read_link(link, "done");
                        break;
                }
+               adjust_accel_cal();
        }
 }