altosuilib: EEProm download from TeleGPS doesn't have states
authorKeith Packard <keithp@keithp.com>
Sat, 7 Feb 2015 04:36:44 +0000 (20:36 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 7 Feb 2015 04:36:44 +0000 (20:36 -0800)
As TeleGPS doesn't have flight states, the EEProm download progress
bar shouldn't show 'state invalid', and it should use a different
scale for each block.

Fix this by having AltosConfigData know which devices have state based
on their log format, then mark the progress bar state limits as
'invalid/invalid' instead of 'boost/landed'. Then have the progress
bar use that to set a more reasonable scale for each block.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConfigData.java
altoslib/AltosEepromDownload.java
altosuilib/AltosEepromMonitorUI.java

index 65f6346a4c00633ce6aede342c2fad71da08560d..0820bf56212b5af067022f2c968cdb793c682d5f 100644 (file)
@@ -577,6 +577,14 @@ public class AltosConfigData implements Iterable<String> {
                dest.set_tracker_interval(tracker_interval);
        }
 
+       public boolean log_has_state() {
+               switch (log_format) {
+               case AltosLib.AO_LOG_FORMAT_TELEGPS:
+                       return false;
+               }
+               return true;
+       }
+
        public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
 
                /* HAS_FLIGHT */
index a448ee645270ce6283ca743f0e3ce5bfaac03631..78a1f4be6635b862963abedfde30bd8808488202 100644 (file)
@@ -254,7 +254,10 @@ public class AltosEepromDownload implements Runnable {
                flights = given_flights;
                success = false;
 
-               monitor.set_states(AltosLib.ao_flight_boost, AltosLib.ao_flight_landed);
+               if (flights.config_data.log_has_state())
+                       monitor.set_states(AltosLib.ao_flight_boost, AltosLib.ao_flight_landed);
+               else
+                       monitor.set_states(AltosLib.ao_flight_invalid, AltosLib.ao_flight_invalid);
 
                monitor.start();
        }
index 11dd4adb3f51c062f000a6d9ff8fbb3328eb9d15..b72dfdf49757ae65dce59cf64b6d6a974e91e6ae 100644 (file)
@@ -37,6 +37,8 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
        int             min_state, max_state;
        ActionListener  listener;
 
+       static final int        progress_max = 10000;
+
        public AltosEepromMonitorUI(JFrame owner) {
                super (owner, "Download Flight Data", false);
 
@@ -102,7 +104,7 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
 
                pbar = new JProgressBar();
                pbar.setMinimum(0);
-               pbar.setMaximum(1000);
+               pbar.setMaximum(progress_max);
                pbar.setValue(0);
                pbar.setString("startup");
                pbar.setStringPainted(true);
@@ -155,16 +157,34 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
        }
 
        private void set_value_internal(String state_name, int state, int state_block, int block) {
-               if (state_block > 100)
-                       state_block = 100;
-               if (state < min_state) state = min_state;
-               if (state >= max_state) state = max_state - 1;
-               state -= min_state;
-
-               int pos = state * 100 + state_block;
+               double  pos;
+               String  s;
+
+               if (min_state == AltosLib.ao_flight_invalid) {
+                       int     lblock = block;
+                       if (lblock > 1000)
+                               lblock = 1000;
+                       pos = lblock / 1000.0;
+                       s = String.format("block %d", block);
+               } else {
+                       if (state_block > 100)
+                               state_block = 100;
+                       if (state < min_state) state = min_state;
+                       if (state >= max_state) state = max_state - 1;
+                       state -= min_state;
+
+                       int     nstate = max_state - min_state;
+
+                       double  spos = (double) (state - min_state) / (double) nstate;
+                       double  bpos = state_block / 100.0;
+
+                       pos = spos + bpos / nstate;
+
+                       s = String.format("block %d state %s", block, state_name);
+               }
 
-               pbar.setString(String.format("block %d state %s", block, state_name));
-               pbar.setValue(pos);
+               pbar.setString(s);
+               pbar.setValue((int) (pos * progress_max));
        }
 
        public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) {