X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosIdleMonitorUI.java;h=949e392675b352b9a08a79afbc22f40f9b4e1197;hb=50b343d389039eae082e82b8ac0b76ae3e2b3ad4;hp=a4262caee321ae643fcf7908ca0184e2041eeb0b;hpb=11a2bb8e28df7ed87542f2ee726f877971f5d52a;p=fw%2Faltos diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index a4262cae..949e3926 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class AltosADC { int tick; @@ -90,7 +91,9 @@ class AltosADC { } class AltosGPSQuery extends AltosGPS { - public AltosGPSQuery (AltosSerial serial) throws TimeoutException, InterruptedException { + public AltosGPSQuery (AltosSerial serial, AltosConfigData config_data) + throws TimeoutException, InterruptedException { + boolean says_done = config_data.compare_version("1.0") >= 0; serial.printf("g\n"); for (;;) { String line = serial.get_reply_no_dialog(5000); @@ -140,6 +143,8 @@ class AltosGPSQuery extends AltosGPS { int status = Integer.decode(bits[1]); connected = (status & Altos.AO_GPS_RUNNING) != 0; locked = (status & Altos.AO_GPS_VALID) != 0; + if (!says_done) + break; continue; } if (line.startsWith("Sats:")) { @@ -167,7 +172,7 @@ class AltosIdleMonitor extends Thread { AltosIdleMonitorUI ui; AltosState state; boolean remote; - int channel; + double frequency; AltosState previous_state; AltosConfigData config_data; AltosADC adc; @@ -178,13 +183,13 @@ class AltosIdleMonitor extends Thread { try { if (remote) { - set_channel(channel); + serial.set_radio_frequency(frequency); serial.start_remote(); } else serial.flush_input(); config_data = new AltosConfigData(serial); adc = new AltosADC(serial); - gps = new AltosGPSQuery(serial); + gps = new AltosGPSQuery(serial, config_data); } finally { if (remote) serial.stop_remote(); @@ -193,23 +198,24 @@ class AltosIdleMonitor extends Thread { record.version = 0; record.callsign = config_data.callsign; record.serial = config_data.serial; - record.flight = 0; + record.flight = config_data.log_available() > 0 ? 255 : 0; record.rssi = 0; record.status = 0; record.state = Altos.ao_flight_idle; record.tick = adc.tick; - record.accel = adc.accel; - record.pres = adc.pres; - record.batt = adc.batt; - record.temp = adc.temp; - record.drogue = adc.drogue; - record.main = adc.main; - - record.ground_accel = record.accel; - record.ground_pres = record.pres; - record.accel_plus_g = config_data.accel_cal_plus; - record.accel_minus_g = config_data.accel_cal_minus; + +// record.accel = adc.accel; +// record.pres = adc.pres; +// record.batt = adc.batt; +// record.temp = adc.temp; +// record.drogue = adc.drogue; +// record.main = adc.main; + +// record.ground_accel = record.accel; +// record.ground_pres = record.pres; +// record.accel_plus_g = config_data.accel_cal_plus; +// record.accel_minus_g = config_data.accel_cal_minus; record.acceleration = 0; record.speed = 0; record.height = 0; @@ -217,8 +223,8 @@ class AltosIdleMonitor extends Thread { state = new AltosState (record, state); } - void set_channel(int in_channel) { - channel = in_channel; + void set_frequency(double in_frequency) { + frequency = in_frequency; } public void post_state() { @@ -237,6 +243,8 @@ class AltosIdleMonitor extends Thread { update_state(); post_state(); } catch (TimeoutException te) { + if (AltosSerial.debug) + System.out.printf ("monitor idle data timeout\n"); } Thread.sleep(1000); } @@ -246,7 +254,7 @@ class AltosIdleMonitor extends Thread { } public AltosIdleMonitor(AltosIdleMonitorUI in_ui, AltosDevice in_device, boolean in_remote) - throws FileNotFoundException, AltosSerialInUseException { + throws FileNotFoundException, AltosSerialInUseException, InterruptedException, TimeoutException { device = in_device; ui = in_ui; serial = new AltosSerial(device); @@ -255,7 +263,7 @@ class AltosIdleMonitor extends Thread { } } -public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { +public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener { AltosDevice device; JTabbedPane pane; AltosPad pad; @@ -284,7 +292,19 @@ public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { flightInfo.clear(); } + public void set_font() { + pad.set_font(); + flightInfo.set_font(); + } + + public void font_size_changed(int font_size) { + set_font(); + } + + AltosFlightStatusUpdate status_update; + public void show(AltosState state, int crc_errors) { + status_update.saved_state = state; try { pad.show(state, crc_errors); flightStatus.show(state, crc_errors); @@ -299,13 +319,14 @@ public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { } Container bag; - JComboBox channels; + AltosFreqList frequencies; - public AltosIdleMonitorUI(JFrame in_owner) throws FileNotFoundException, AltosSerialInUseException { + public AltosIdleMonitorUI(JFrame in_owner) + throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException { device = AltosDeviceDialog.show(in_owner, Altos.product_any); remote = false; - if (!device.matchProduct(Altos.product_telemetrum)) + if (!device.matchProduct(Altos.product_altimeter)) remote = true; serial = device.getSerial(); @@ -320,21 +341,23 @@ public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { setTitle(String.format("AltOS %s", device.toShortString())); - /* Stick channel selector at top of table for telemetry monitoring */ + /* Stick frequency selector at top of table for telemetry monitoring */ if (remote && serial >= 0) { - // Channel menu - channels = new AltosChannelMenu(AltosPreferences.channel(serial)); - channels.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int channel = channels.getSelectedIndex(); - thread.set_channel(channel); - } + // Frequency menu + frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial)); + frequencies.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + double frequency = frequencies.frequency(); + thread.set_frequency(frequency); + AltosUIPreferences.set_frequency(device.getSerial(), + frequency); + } }); c.gridx = 0; c.gridy = 0; c.insets = new Insets(3, 3, 3, 3); c.anchor = GridBagConstraints.WEST; - bag.add (channels, c); + bag.add (frequencies, c); } @@ -369,12 +392,16 @@ public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { bag.add(pane, c); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + AltosUIPreferences.register_font_listener(this); + addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { disconnect(); setVisible(false); dispose(); + AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this); } }); @@ -383,6 +410,10 @@ public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay { thread = new AltosIdleMonitor(this, device, remote); + status_update = new AltosFlightStatusUpdate(flightStatus); + + new javax.swing.Timer(100, status_update).start(); + thread.start(); } }