From 22005da598921ef6fe1a7f1bb5e56e41f44fe12f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 22 Aug 2018 00:58:14 -0700 Subject: [PATCH] altosuilib: Don't show radio parameter when reflashing radioless devices Signed-off-by: Keith Packard --- altoslib/AltosLib.java | 4 ++ altosuilib/AltosRomconfigUI.java | 75 ++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 4bb46346..254448d0 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -180,6 +180,10 @@ public class AltosLib { return device_type == product_telemega || device_type == product_easymega; } + public static boolean has_radio(int device_type) { + return device_type != product_easymini && device_type != product_easymega; + } + public static boolean has_gps(int device_type) { return device_type == product_telemetrum || device_type == product_telemega || diff --git a/altosuilib/AltosRomconfigUI.java b/altosuilib/AltosRomconfigUI.java index 0ca63c4e..fd670d4e 100644 --- a/altosuilib/AltosRomconfigUI.java +++ b/altosuilib/AltosRomconfigUI.java @@ -40,10 +40,10 @@ public class AltosRomconfigUI JButton cancel; /* Build the UI using a grid bag */ - public AltosRomconfigUI(JFrame in_owner) { - super (in_owner, "Configure TeleMetrum Rom Values", true); + public AltosRomconfigUI(JFrame frame, AltosRomconfig config) { + super (frame, "Configure Rom Values", true); - owner = in_owner; + owner = frame; GridBagConstraints c; Insets il = new Insets(4,4,4,4); @@ -52,9 +52,11 @@ public class AltosRomconfigUI pane = getContentPane(); pane.setLayout(new GridBagLayout()); + int y = 0; + /* Serial */ c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; + c.gridx = 0; c.gridy = y; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; @@ -63,7 +65,7 @@ public class AltosRomconfigUI pane.add(serial_label, c); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 0; + c.gridx = 3; c.gridy = y; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; @@ -72,31 +74,37 @@ public class AltosRomconfigUI serial_value = new JTextField("00000000"); pane.add(serial_value, c); - /* Radio calibration value */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 1; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - c.ipady = 5; - radio_calibration_label = new JLabel("Radio Calibration:"); - pane.add(radio_calibration_label, c); - - c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 1; - c.gridwidth = 3; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - c.ipady = 5; - radio_calibration_value = new JTextField("00000000"); - pane.add(radio_calibration_value, c); + y++; + + if (AltosLib.has_radio(config.usb_id.pid)) { + /* Radio calibration value */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = y; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("Radio Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = y; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField("00000000"); + pane.add(radio_calibration_value, c); + + y++; + } /* Buttons */ c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 2; + c.gridx = 0; c.gridy = y; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; @@ -107,7 +115,7 @@ public class AltosRomconfigUI ok.setActionCommand("ok"); c = new GridBagConstraints(); - c.gridx = 3; c.gridy = 2; + c.gridx = 3; c.gridy = y; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; @@ -117,12 +125,10 @@ public class AltosRomconfigUI cancel.addActionListener(this); cancel.setActionCommand("cancel"); + y++; + pack(); setLocationRelativeTo(owner); - } - - public AltosRomconfigUI(JFrame frame, AltosRomconfig config) { - this(frame); set(config); } @@ -155,10 +161,15 @@ public class AltosRomconfigUI } int radio_calibration() { + if (radio_calibration_value == null) + return 0; + return Integer.parseInt(radio_calibration_value.getText()); } void set_radio_calibration(int calibration) { + if (radio_calibration_value == null) + return; radio_calibration_value.setText(String.format("%d", calibration)); } -- 2.30.2