altosuilib: Get the Eeprom download progress bar working again
authorKeith Packard <keithp@keithp.com>
Sun, 8 Feb 2015 04:22:19 +0000 (20:22 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 8 Feb 2015 04:22:19 +0000 (20:22 -0800)
The eeprom download code wasn't computing the start of each state
transition correctly, so the progress bar was snapping to the end of
the chunk for each state.

Invalid state values would snap the bar to the right side.

Landed state wasn't ever seen, so the bar would not ever fill.

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

index 78a1f4be6635b862963abedfde30bd8808488202..00b20272f23c9ea7b3bcef7dcadfc052ffbc4bf2 100644 (file)
@@ -75,7 +75,8 @@ public class AltosEepromDownload implements Runnable {
        }
 
        boolean                 done;
-       boolean                 start;
+       int                     prev_state;
+       int                     state_block;
 
        void LogEeprom(AltosEeprom r) throws IOException {
                if (r.cmd != AltosLib.AO_LOG_INVALID) {
@@ -140,7 +141,6 @@ public class AltosEepromDownload implements Runnable {
                state = new AltosState();
 
                done = false;
-               start = true;
 
                if (flights.config_data.serial < 0)
                        throw new IOException("no serial number found");
@@ -154,12 +154,8 @@ public class AltosEepromDownload implements Runnable {
                /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */
 
                state_block = log.start_block;
+               prev_state = AltosLib.ao_flight_startup;
                for (block = log.start_block; !done && block < log.end_block; block++) {
-                       monitor.set_value(state.state_name(),
-                                         state.state,
-                                         block - state_block,
-                                         block - log.start_block);
-
                        AltosEepromChunk        eechunk = new AltosEepromChunk(link, block, block == log.start_block);
 
                        /*
@@ -177,6 +173,16 @@ public class AltosEepromDownload implements Runnable {
                        }
 
                        CaptureEeprom (eechunk, log_format);
+
+                       if (state.state != prev_state && state.state != AltosLib.ao_flight_invalid) {
+                               state_block = block;
+                               prev_state = state.state;
+                       }
+
+                       monitor.set_value(state.state_name(),
+                                         state.state,
+                                         block - state_block,
+                                         block - log.start_block);
                }
                CheckFile(true);
                if (eeprom_file != null) {
index b72dfdf49757ae65dce59cf64b6d6a974e91e6ae..d2d956780cd9c398a8b4be7dc976593cf97a847f 100644 (file)
@@ -167,15 +167,21 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
                        pos = lblock / 1000.0;
                        s = String.format("block %d", block);
                } else {
+                       if (state == AltosLib.ao_flight_invalid)
+                               state = 0;
                        if (state_block > 100)
                                state_block = 100;
                        if (state < min_state) state = min_state;
-                       if (state >= max_state) state = max_state - 1;
+                       if (state > max_state) state = max_state;
+
+                       if (state == max_state)
+                               state_block = 0;
+
                        state -= min_state;
 
                        int     nstate = max_state - min_state;
 
-                       double  spos = (double) (state - min_state) / (double) nstate;
+                       double  spos = (double) state / (double) nstate;
                        double  bpos = state_block / 100.0;
 
                        pos = spos + bpos / nstate;