first cut at turnon scripts for EasyTimer v2
[fw/altos] / altoslib / AltosConfigData.java
index 5d58566ecb3dc0b9836e1bd676a5857f04a1cde1..6b980be6b641dd784e06c020d07a743eea036b0c 100644 (file)
@@ -83,6 +83,14 @@ public class AltosConfigData {
        /* HAS_BEEP */
        public int              beep;
 
+       /* HAS_RADIO_10MW */
+       public int              radio_10mw;
+
+       public int              report_feet;
+
+       /* HAS_GPS_MOSAIC */
+       public int              gps_receiver;
+
        /* Storage info replies */
        public int      storage_size;
        public int      storage_erase_unit;
@@ -199,19 +207,39 @@ 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:
-               case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
                        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_TELEMEGA_5:
+               case AltosLib.AO_LOG_FORMAT_TELEMEGA_6:
                case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
+               case AltosLib.AO_LOG_FORMAT_EASYMEGA_3:
+               case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
+                       /* ADXL375 */
+                       return -value;
+               case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
+                       /* BMI088 */
                        return -value;
                default:
+                       if (product.startsWith("EasyTimer-"))
+                               return -value;
                        return AltosLib.MISSING;
                }
        }
 
        public boolean has_monitor_battery() {
+               if (product == null)
+                       return false;
                if (product.startsWith("TeleBT"))
                        return true;
                return false;
@@ -302,6 +330,12 @@ public class AltosConfigData {
 
                beep = AltosLib.MISSING;
 
+               radio_10mw = AltosLib.MISSING;
+
+               report_feet = AltosLib.MISSING;
+
+               gps_receiver = AltosLib.MISSING;
+
                tracker_motion = AltosLib.MISSING;
                tracker_interval = AltosLib.MISSING;
 
@@ -318,6 +352,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:
@@ -335,6 +372,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:
@@ -354,10 +394,10 @@ 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 &&
-                   log_format != AltosLib.AO_LOG_FORMAT_UNKNOWN)
+                   accel_cal_minus != AltosLib.MISSING)
                {
                        switch (pad_orientation) {
                        case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
@@ -486,6 +526,13 @@ public class AltosConfigData {
                /* HAS_BEEP */
                try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
 
+               /* HAS_RADIO_10MW */
+               try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
+
+               try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
+
+               try { gps_receiver = get_int(line, "GPS receiver:"); } catch (Exception e) {}
+
                /* HAS_TRACKER */
                try {
                        int[] values = get_values(line, "Tracker setting:");
@@ -536,9 +583,6 @@ public class AltosConfigData {
                                }
                        }
                } catch (Exception e) {}
-
-               /* Fix accel cal as soon as all of the necessary values appear */
-               adjust_accel_cal();
        }
 
        public AltosConfigData() {
@@ -608,6 +652,8 @@ public class AltosConfigData {
                        return false;
                if (product.startsWith("TeleMetrum-v3"))
                        return false;
+               if (product.startsWith("TeleMetrum-v4"))
+                       return true;
                if (product.startsWith("EasyMega"))
                        return false;
                return true;
@@ -634,8 +680,18 @@ public class AltosConfigData {
                                return true;
                        if (product.startsWith("TeleMetrum-v3"))
                                return true;
+                       if (product.startsWith("TeleMetrum-v4"))
+                               return true;
                        if (product.startsWith("TeleMega-v4"))
                                return true;
+                       if (product.startsWith("TeleMega-v5"))
+                               return true;
+                       if (product.startsWith("TeleMega-v6"))
+                               return true;
+                       if (product.startsWith("EasyMotor-v2"))
+                               return true;
+                       if (product.startsWith("EasyMotor-v3"))
+                               return true;
                }
                throw new AltosUnknownProduct(product);
        }
@@ -646,8 +702,19 @@ public class AltosConfigData {
                                return AltosAdxl375.X_AXIS;
                        if (product.startsWith("TeleMetrum-v3"))
                                return AltosAdxl375.X_AXIS;
+                       if (product.startsWith("TeleMetrum-v4"))
+                               return AltosAdxl375.X_AXIS;
                        if (product.startsWith("TeleMega-v4"))
                                return AltosAdxl375.X_AXIS;
+                       if (product.startsWith("TeleMega-v5"))
+                               return AltosAdxl375.X_AXIS;
+                       if (product.startsWith("TeleMega-v6"))
+                               return AltosAdxl375.X_AXIS;
+                       if (product.startsWith("EasyMotor-v2"))
+                               return AltosAdxl375.X_AXIS;
+                       if (product.startsWith("EasyMotor-v3"))
+                               return AltosAdxl375.X_AXIS;
+
                }
                throw new AltosUnknownProduct(product);
        }
@@ -709,6 +776,17 @@ public class AltosConfigData {
                /* HAS_BEEP */
                if (beep != AltosLib.MISSING)
                        beep = source.beep();
+
+               /* HAS_RADIO_10MW */
+               if (radio_10mw != AltosLib.MISSING)
+                       radio_10mw = source.radio_10mw();
+
+               if (report_feet != AltosLib.MISSING)
+                       report_feet = source.report_feet();
+
+               if (gps_receiver != AltosLib.MISSING)
+                       gps_receiver = source.gps_receiver();
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING)
                        tracker_motion = source.tracker_motion();
@@ -764,6 +842,9 @@ public class AltosConfigData {
                dest.set_aprs_format(aprs_format);
                dest.set_aprs_offset(aprs_offset);
                dest.set_beep(beep);
+               dest.set_radio_10mw(radio_10mw);
+               dest.set_report_feet(report_feet);
+               dest.set_gps_receiver(gps_receiver);
                dest.set_tracker_motion(tracker_motion);
                dest.set_tracker_interval(tracker_interval);
        }
@@ -796,33 +877,28 @@ public class AltosConfigData {
                                                        has_setting,
                                                        radio_calibration);
                        /* When remote, reset the dongle frequency at the same time */
-                       if (remote) {
-                               link.flush_output();
+                       if (remote && frequency != link.frequency) {
                                link.stop_remote();
                                link.set_radio_frequency(frequency);
-                               link.flush_output();
                                link.start_remote();
                        }
                }
 
                if (telemetry_rate != AltosLib.MISSING) {
                        link.printf("c T %d\n", telemetry_rate);
-                       if (remote) {
-                               link.flush_output();
+                       if (remote && telemetry_rate != link.telemetry_rate) {
                                link.stop_remote();
                                link.set_telemetry_rate(telemetry_rate);
-                               link.flush_output();
                                link.start_remote();
                        }
                }
 
                if (callsign != null) {
                        link.printf("c c %s\n", callsign);
-                       if (remote) {
-                               link.flush_output();
+                       if (remote && !callsign.equals(link.callsign)) {
+                               System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
                                link.stop_remote();
                                link.set_callsign(callsign);
-                               link.flush_output();
                                link.start_remote();
                        }
                }
@@ -836,8 +912,22 @@ public class AltosConfigData {
                        link.printf("c o %d\n", pad_orientation);
                int plus = accel_cal_plus(pad_orientation);
                int minus = accel_cal_minus(pad_orientation);
-               if (plus != AltosLib.MISSING && minus != AltosLib.MISSING)
-                       link.printf("c a %d %d\n", plus, minus);
+               if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
+                       if (plus < 0)
+                               plus = 65536 + plus;
+                       if (minus < 0)
+                               minus = 65536 + minus;
+                       if (accel_zero_along != AltosLib.MISSING &&
+                           accel_zero_across != AltosLib.MISSING &&
+                           accel_zero_through != AltosLib.MISSING)
+                               link.printf("c a %d %d %d %d %d\n",
+                                           plus, minus,
+                                           accel_zero_along,
+                                           accel_zero_across,
+                                           accel_zero_through);
+                       else
+                               link.printf("c a %d %d\n", plus, minus);
+               }
 
                /* HAS_LOG */
                if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
@@ -874,6 +964,17 @@ public class AltosConfigData {
                if (beep != AltosLib.MISSING)
                        link.printf("c b %d\n", beep);
 
+               /* HAS_RADIO_10MW */
+               if (radio_10mw != AltosLib.MISSING)
+                       link.printf("c p %d\n", radio_10mw);
+
+               if (report_feet != AltosLib.MISSING)
+                       link.printf("c u %d\n", report_feet);
+
+               /* HAS_GPS_MOSAIC */
+               if (gps_receiver != AltosLib.MISSING)
+                       link.printf("c g %d\n", gps_receiver);
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
                        link.printf("c t %d %d\n", tracker_motion, tracker_interval);
@@ -882,7 +983,7 @@ public class AltosConfigData {
                /* UI doesn't support accel cal */
 
                link.printf("c w\n");
-               link.flush_output();
+               read_link(link, "Saved");
        }
 
        public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
@@ -898,5 +999,6 @@ public class AltosConfigData {
                        read_link(link, "done");
                        break;
                }
+               adjust_accel_cal();
        }
 }