diff options
author | Keith Packard <keithp@keithp.com> | 2017-05-27 16:12:31 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-05-27 16:12:31 -0700 |
commit | 855a7d243a5a85728a7b23fdfe9485d4ecaf71cf (patch) | |
tree | 19a8189f462119b9e9790f2768c7bcd8480d41b5 /telegps | |
parent | b6b5c64f93fa56bcb22ea1c4279e4f754e6e6f1c (diff) |
telegps: Get telegps application working again
Many minor API tweaks
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'telegps')
-rw-r--r-- | telegps/TeleGPS.java | 46 | ||||
-rw-r--r-- | telegps/TeleGPSDisplayThread.java | 14 | ||||
-rw-r--r-- | telegps/TeleGPSGraphUI.java | 70 | ||||
-rw-r--r-- | telegps/TeleGPSState.java | 8 | ||||
-rw-r--r-- | telegps/TeleGPSStatus.java | 26 |
5 files changed, 107 insertions, 57 deletions
diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index cf2cbd4f..5e500e02 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -152,7 +152,7 @@ public class TeleGPS status_update.saved_listener_state = listener_state; if (state == null) - state = new AltosState(); + state = new AltosState(new AltosCalData()); int i = 0; for (AltosFlightDisplay display : displays) { @@ -287,23 +287,30 @@ public class TeleGPS new TeleGPSConfig(this); } + private static AltosFlightSeries make_series(AltosRecordSet set) { + AltosFlightSeries series = new AltosFlightSeries(set.cal_data()); + set.capture_series(series); + series.finish(); + return series; + } + void export() { - AltosDataChooser chooser; - chooser = new AltosDataChooser(this); - AltosStateIterable states = chooser.runDialog(); - if (states == null) + AltosDataChooser chooser = new AltosDataChooser(this); + + AltosRecordSet set = chooser.runDialog(); + if (set == null) return; - new AltosCSVUI(this, states, chooser.file()); + AltosFlightSeries series = make_series(set); + new AltosCSVUI(this, series, series.cal_data, chooser.file()); } void graph() { - AltosDataChooser chooser; - chooser = new AltosDataChooser(this); - AltosStateIterable states = chooser.runDialog(); - if (states == null) + AltosDataChooser chooser = new AltosDataChooser(this); + AltosRecordSet set = chooser.runDialog(); + if (set == null) return; try { - new TeleGPSGraphUI(states, chooser.file()); + new TeleGPSGraphUI(set, chooser.file()); } catch (InterruptedException ie) { } catch (IOException ie) { } @@ -612,7 +619,7 @@ public class TeleGPS connect(device); } - static AltosStateIterable record_iterable(File file) { + static AltosRecordSet record_set(File file) { FileInputStream in; if (file.getName().endsWith("telem")) { try { @@ -624,8 +631,7 @@ public class TeleGPS } else { try { - AltosEepromFile f = new AltosEepromFile(new FileReader(file)); - return f; + return new AltosEepromFile(new FileReader(file)); } catch (Exception e) { System.out.printf("Failed to open file '%s'\n", file); } @@ -634,18 +640,18 @@ public class TeleGPS } static AltosReplayReader replay_file(File file) { - AltosStateIterable states = record_iterable(file); - if (states == null) + AltosRecordSet set = record_set(file); + if (set == null) return null; - return new AltosReplayReader(states.iterator(), file); + return new AltosReplayReader(set, file); } static boolean process_graph(File file) { - AltosStateIterable states = record_iterable(file); - if (states == null) + AltosRecordSet set = record_set(file); + if (set == null) return false; try { - new TeleGPSGraphUI(states, file); + new TeleGPSGraphUI(set, file); } catch (Exception e) { return false; } diff --git a/telegps/TeleGPSDisplayThread.java b/telegps/TeleGPSDisplayThread.java index a9c80dc0..c311dd7e 100644 --- a/telegps/TeleGPSDisplayThread.java +++ b/telegps/TeleGPSDisplayThread.java @@ -31,7 +31,9 @@ public class TeleGPSDisplayThread extends Thread { IdleThread idle_thread; AltosVoice voice; AltosFlightReader reader; - AltosState old_state, state; + AltosState state; + int old_state = AltosLib.ao_flight_invalid; + boolean old_gps_ready = false; AltosListenerState listener_state; AltosFlightDisplay display; @@ -130,11 +132,12 @@ public class TeleGPSDisplayThread extends Thread { } public synchronized void notice(boolean spoken) { - if (old_state != null && old_state.state() != state.state()) { + if (old_state != state.state()) { report_time = now(); this.notify(); } else if (spoken) set_report_time(); + old_state = state.state(); } public IdleThread() { @@ -144,17 +147,17 @@ public class TeleGPSDisplayThread extends Thread { synchronized boolean tell() { boolean ret = false; - if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (old_gps_ready != state.gps_ready) { if (state.gps_ready) { voice.speak("GPS ready"); ret = true; } - else if (old_state != null) { + else if (old_gps_ready) { voice.speak("GPS lost"); ret = true; } + old_gps_ready = state.gps_ready; } - old_state = state; return ret; } @@ -173,7 +176,6 @@ public class TeleGPSDisplayThread extends Thread { listener_state.running = false; break; } - reader.update(state); show_safely(); told = tell(); idle_thread.notice(told); diff --git a/telegps/TeleGPSGraphUI.java b/telegps/TeleGPSGraphUI.java index 55ee370e..3e765640 100644 --- a/telegps/TeleGPSGraphUI.java +++ b/telegps/TeleGPSGraphUI.java @@ -34,21 +34,41 @@ import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.ui.RefineryUtilities; -public class TeleGPSGraphUI extends AltosUIFrame +public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener { JTabbedPane pane; - AltosGraph graph; + AltosGraphNew graph; AltosUIEnable enable; AltosUIMap map; AltosState state; AltosFlightStats stats; - AltosGraphDataSet graphDataSet; AltosFlightStatsTable statsTable; - - void fill_map(AltosStateIterable states) { - for (AltosState state : states) { - if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) - map.show(state, null); + AltosGPS gps; + boolean has_gps; + + void fill_map(AltosFlightSeries flight_series) { + boolean any_gps = false; + AltosGPSTimeValue gtv_last = null; + + if (flight_series.gps_series != null) { + for (AltosGPSTimeValue gtv : flight_series.gps_series) { + gtv_last = gtv; + AltosGPS gps = gtv.gps; + if (gps != null && + gps.locked && + gps.nsat >= 4) { + if (map == null) + map = new AltosUIMap(); + map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time)); + this.gps = gps; + has_gps = true; + } + } + } + if (gtv_last != null) { + int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time); + if (state == AltosLib.ao_flight_landed) + map.show(gtv_last.gps, state); } } @@ -58,16 +78,35 @@ public class TeleGPSGraphUI extends AltosUIFrame TeleGPS.subtract_window(); } - TeleGPSGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException { + public void font_size_changed(int font_size) { + if (map != null) + map.font_size_changed(font_size); + if (statsTable != null) + statsTable.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + if (map != null) + map.units_changed(imperial_units); + if (enable != null) + enable.units_changed(imperial_units); + } + + TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException { super(file.getName()); - state = null; + AltosCalData cal_data = set.cal_data(); + + AltosUIFlightSeries flight_series = new AltosUIFlightSeries(cal_data); + set.capture_series(flight_series); + flight_series.finish(); pane = new JTabbedPane(); enable = new AltosUIEnable(); - stats = new AltosFlightStats(states); - graphDataSet = new AltosGraphDataSet(states); - graph = new AltosGraph(enable, stats, graphDataSet); + stats = new AltosFlightStats(flight_series); + + graph = new AltosGraphNew(enable, stats, flight_series, cal_data); + statsTable = new AltosFlightStatsTable(stats); map = new AltosUIMap(); @@ -75,11 +114,14 @@ public class TeleGPSGraphUI extends AltosUIFrame pane.add("Graph", graph.panel); pane.add("Configure Graph", enable); pane.add("Statistics", statsTable); - fill_map(states); + fill_map(flight_series); pane.add("Map", map); setContentPane (pane); + AltosUIPreferences.register_font_listener(this); + AltosPreferences.register_units_listener(this); + addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java index 9ba0b7a5..2e39037c 100644 --- a/telegps/TeleGPSState.java +++ b/telegps/TeleGPSState.java @@ -124,10 +124,10 @@ public class TeleGPSState extends AltosUIFlightTab { class FirmwareVersion extends AltosUIIndicator { public void show(AltosState state, AltosListenerState listener_state) { - if (state.firmware_version == null) + if (state.cal_data.firmware_version == null) show("Missing"); else - show(state.firmware_version); + show(state.cal_data.firmware_version); } public FirmwareVersion(Container container, int y) { @@ -137,9 +137,7 @@ public class TeleGPSState extends AltosUIFlightTab { class FlightLogMax extends AltosUIIndicator { public void show(AltosState state, AltosListenerState listener_state) { - int storage = state.flight_log_max; - if (storage == AltosLib.MISSING) - storage = state.log_space >> 10; + int storage = state.cal_data.flight_log_max; if (storage == AltosLib.MISSING) show("Missing"); else diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java index 5479f43a..a6ddd1b0 100644 --- a/telegps/TeleGPSStatus.java +++ b/telegps/TeleGPSStatus.java @@ -75,11 +75,13 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { String call; void show(AltosState state, AltosListenerState listener_state) { - if (state.callsign != call) { - value.setText(state.callsign); - call = state.callsign; + if (state.cal_data == null) + System.out.printf("null cal data?\n"); + if (state.cal_data.callsign != call) { + value.setText(state.cal_data.callsign); + call = state.cal_data.callsign; } - if (state.callsign == null) + if (state.cal_data.callsign == null) setVisible(false); else setVisible(true); @@ -100,12 +102,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { class Serial extends Value { int serial = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.serial != serial) { - if (state.serial == AltosLib.MISSING) + if (state.cal_data.serial != serial) { + if (state.cal_data.serial == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.serial)); - serial = state.serial; + value.setText(String.format("%d", state.cal_data.serial)); + serial = state.cal_data.serial; } } @@ -126,12 +128,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { int last_flight = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.flight != last_flight) { - if (state.flight == AltosLib.MISSING) + if (state.cal_data.flight != last_flight) { + if (state.cal_data.flight == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.flight)); - last_flight = state.flight; + value.setText(String.format("%d", state.cal_data.flight)); + last_flight = state.cal_data.flight; } } |