altosui: Sanity check values from device configuration
authorKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 05:54:17 +0000 (22:54 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 05:54:17 +0000 (22:54 -0700)
If someone has down-graded and re up-graded the firmware, the config
entries may be garbage. Sanity check them to avoid crashing the UI.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfig.java
altosui/AltosConfigData.java
altosui/AltosConfigUI.java

index 84261ec7a5523753f00387835beadb0da261d719..8eb71e1f8bb3b3d380ae3e2fa8e8426ddf987b3f 100644 (file)
@@ -194,7 +194,9 @@ public class AltosConfig implements ActionListener {
                get_int(line, "Ignite mode:", ignite_mode);
                get_int(line, "Pad orientation:", pad_orientation);
                get_int(line, "Radio setting:", radio_setting);
-               get_int(line, "Frequency:", radio_frequency);
+               if (get_int(line, "Frequency:", radio_frequency))
+                       if (radio_frequency.get() < 0)
+                               radio_frequency.set(434550);
                get_int(line, "Radio enable:", radio_enable);
                get_int(line, "Storage size:", storage_size);
                get_int(line, "Storage erase unit:", storage_erase_unit);
index 0608b4d396ef2b98d7190a8d6529ec3e6f0a2689..53509dfad4cafa25e2e7ac8cd24a2a65088c3612 100644 (file)
@@ -156,7 +156,11 @@ public class AltosConfigData implements Iterable<String> {
                        try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
                        try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
                        try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
-                       try { radio_frequency = get_int(line, "Frequency:"); } catch (Exception e) {}
+                       try {
+                               radio_frequency = get_int(line, "Frequency:");
+                               if (radio_frequency < 0)
+                                       radio_frequency = 434550;
+                       } catch (Exception e) {}
                        try {
                                if (line.startsWith("Accel cal")) {
                                        String[] bits = line.split("\\s+");
index c8ec06d26fc18495981735434939f0e75af8cbec..879605bc35781daad8c6a8ec80bdcd2818b5d5a4 100644 (file)
@@ -708,6 +708,8 @@ public class AltosConfigUI
        }
 
        public void set_ignite_mode(int new_ignite_mode) {
+               if (new_ignite_mode >= ignite_mode_values.length)
+                       new_ignite_mode = 0;
                if (new_ignite_mode < 0) {
                        ignite_mode_value.setEnabled(false);
                        new_ignite_mode = 0;
@@ -727,6 +729,8 @@ public class AltosConfigUI
 
 
        public void set_pad_orientation(int new_pad_orientation) {
+               if (new_pad_orientation >= pad_orientation_values.length)
+                       new_pad_orientation = 0;
                if (new_pad_orientation < 0) {
                        pad_orientation_value.setEnabled(false);
                        new_pad_orientation = 0;