summaryrefslogtreecommitdiff
path: root/altosuilib
diff options
context:
space:
mode:
Diffstat (limited to 'altosuilib')
-rw-r--r--altosuilib/AltosDeviceUIDialog.java51
-rw-r--r--altosuilib/AltosFlashUI.java44
-rw-r--r--altosuilib/AltosUSBDevice.java9
3 files changed, 67 insertions, 37 deletions
diff --git a/altosuilib/AltosDeviceUIDialog.java b/altosuilib/AltosDeviceUIDialog.java
index 93ab178f..8ea9e233 100644
--- a/altosuilib/AltosDeviceUIDialog.java
+++ b/altosuilib/AltosDeviceUIDialog.java
@@ -24,27 +24,39 @@ import java.awt.event.*;
public class AltosDeviceUIDialog extends AltosDeviceDialog {
+ boolean include_bluetooth;
+
public AltosDevice[] devices() {
java.util.List<AltosDevice> usb_devices = AltosUSBDevice.list(product);
int num_devices = usb_devices.size();
- java.util.List<AltosDevice> bt_devices = AltosBTKnown.bt_known().list(product);
- num_devices += bt_devices.size();
+
+ java.util.List<AltosDevice> bt_devices = null;
+
+ if (include_bluetooth) {
+ bt_devices = AltosBTKnown.bt_known().list(product);
+ num_devices += bt_devices.size();
+ }
+
AltosDevice[] devices = new AltosDevice[num_devices];
for (int i = 0; i < usb_devices.size(); i++)
devices[i] = usb_devices.get(i);
- int off = usb_devices.size();
- for (int j = 0; j < bt_devices.size(); j++)
- devices[off + j] = bt_devices.get(j);
+ if (include_bluetooth) {
+ int off = usb_devices.size();
+ for (int j = 0; j < bt_devices.size(); j++)
+ devices[off + j] = bt_devices.get(j);
+ }
return devices;
}
public void add_bluetooth() {
- JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
- manage_bluetooth_button.setActionCommand("manage");
- manage_bluetooth_button.addActionListener(this);
- buttonPane.add(manage_bluetooth_button);
- buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ if (include_bluetooth) {
+ JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
+ manage_bluetooth_button.setActionCommand("manage");
+ manage_bluetooth_button.addActionListener(this);
+ buttonPane.add(manage_bluetooth_button);
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ }
}
public void actionPerformed(ActionEvent e) {
@@ -55,16 +67,29 @@ public class AltosDeviceUIDialog extends AltosDeviceDialog {
}
}
- public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
+ public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product, boolean include_bluetooth) {
super(in_frame, location, in_product);
+ this.include_bluetooth = include_bluetooth;
}
- public static AltosDevice show (Component frameComp, int product) {
+ public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
+ this(in_frame, location, in_product, true);
+ }
+
+ public static AltosDevice show (Component frameComp, int product, boolean include_bluetooth) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
AltosDeviceUIDialog dialog;
- dialog = new AltosDeviceUIDialog(frame, frameComp, product);
+ dialog = new AltosDeviceUIDialog(frame, frameComp, product, include_bluetooth);
dialog.setVisible(true);
return dialog.getValue();
}
+
+ public static AltosDevice show (Component frameComp, int product) {
+ return show(frameComp, product, true);
+ }
+
+ public static AltosUSBDevice show_usb (Component frameComp, int product) {
+ return (AltosUSBDevice) show(frameComp, product, false);
+ }
}
diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java
index b91776aa..ffb39b8c 100644
--- a/altosuilib/AltosFlashUI.java
+++ b/altosuilib/AltosFlashUI.java
@@ -45,7 +45,7 @@ public class AltosFlashUI
File file;
// Debug connection
- AltosDevice device;
+ AltosUSBDevice device;
AltosLink link;
@@ -205,14 +205,20 @@ public class AltosFlashUI
}
static class AltosHexfileFilter extends javax.swing.filechooser.FileFilter {
- int product;
String head;
String description;
- public AltosHexfileFilter(int product, String head, String description) {
- this.product = product;
- this.head = head;
- this.description = description;
+ public AltosHexfileFilter(String usb_product) {
+ int l;
+
+ /* Trim off any trailing variants (1.0a vs 1.0) */
+ for (l = usb_product.length(); l > 0; l--) {
+ char c = usb_product.charAt(l-1);
+ if (c < 'a' || 'z' < c)
+ break;
+ }
+ head = usb_product.substring(0, l).toLowerCase();
+ description = String.format("%s Image File", usb_product);
}
public boolean accept(File file) {
@@ -224,14 +230,6 @@ public class AltosFlashUI
}
}
- static AltosHexfileFilter[] filters = {
- new AltosHexfileFilter(AltosLib.product_telemetrum, "telemetrum", "TeleMetrum Image"),
- new AltosHexfileFilter(AltosLib.product_teledongle, "teledongle", "TeleDongle Image"),
- new AltosHexfileFilter(AltosLib.product_telemega, "telemega", "TeleMega Image"),
- new AltosHexfileFilter(AltosLib.product_easymini, "easymini", "EasyMini Image"),
- new AltosHexfileFilter(AltosLib.product_easymega, "easymega", "EasyMega Image"),
- };
-
boolean select_source_file() {
JFileChooser hexfile_chooser = new JFileChooser();
@@ -241,18 +239,14 @@ public class AltosFlashUI
hexfile_chooser.setDialogTitle("Select Flash Image");
- for (int i = 0; i < filters.length; i++) {
- hexfile_chooser.addChoosableFileFilter(filters[i]);
- }
javax.swing.filechooser.FileFilter ihx_filter = new FileNameExtensionFilter("Flash Image", "ihx");
hexfile_chooser.addChoosableFileFilter(ihx_filter);
hexfile_chooser.setFileFilter(ihx_filter);
if (!is_pair_programmed() && !device.matchProduct(AltosLib.product_altusmetrum)) {
- for (int i = 0; i < filters.length; i++) {
- if (device != null && device.matchProduct(filters[i].product))
- hexfile_chooser.setFileFilter(filters[i]);
- }
+ AltosHexfileFilter filter = new AltosHexfileFilter(device.usb_product());
+ hexfile_chooser.addChoosableFileFilter(filter);
+ hexfile_chooser.setFileFilter(filter);
}
int returnVal = hexfile_chooser.showOpenDialog(frame);
@@ -270,7 +264,7 @@ public class AltosFlashUI
boolean select_device() {
int product = AltosLib.product_any;
- device = AltosDeviceUIDialog.show(frame, AltosLib.product_any);
+ device = AltosDeviceUIDialog.show_usb(frame, AltosLib.product_any);
if (device == null)
return false;
@@ -393,10 +387,12 @@ public class AltosFlashUI
else
programmer = new AltosSelfFlash(ui.file, link, this);
- final AltosRomconfig current_config = programmer.target_romconfig();
+ final AltosRomconfig current_config = programmer.target_romconfig(device.usb_id(), device.usb_product());
final AltosRomconfig image_config = programmer.image_romconfig();
+ System.out.printf("product %s current %s image %s\n", device.usb_product(), current_config, image_config);
+
final Semaphore await_rom_config = new Semaphore(0);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
@@ -539,7 +535,7 @@ public class AltosFlashUI
}
if (!matched) {
System.out.printf("Identified new device %s\n", d.toShortString());
- device = d;
+ device = (AltosUSBDevice) d;
break;
}
}
diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java
index f43d6bef..e4b94eea 100644
--- a/altosuilib/AltosUSBDevice.java
+++ b/altosuilib/AltosUSBDevice.java
@@ -20,6 +20,7 @@ package org.altusmetrum.altosuilib_13;
import java.util.*;
import libaltosJNI.*;
+import org.altusmetrum.altoslib_13.*;
public class AltosUSBDevice extends altos_device implements AltosDevice {
@@ -98,6 +99,14 @@ public class AltosUSBDevice extends altos_device implements AltosDevice {
return getVendor() ^ getProduct() ^ getSerial() ^ getPath().hashCode();
}
+ public AltosUsbId usb_id() {
+ return new AltosUsbId(getVendor(), getProduct());
+ }
+
+ public String usb_product() {
+ return getName();
+ }
+
public boolean equals(Object o) {
if (o == null)
return false;