diff options
| author | Keith Packard <keithp@keithp.com> | 2010-07-28 12:24:53 -0700 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2010-07-28 12:24:53 -0700 |
| commit | e76b9cc32bbcc5176d9bdd6f8d79778024627382 (patch) | |
| tree | 331a16ed7d14f8362dc85af04dcf1693b3b1ee6e | |
| parent | 172a2817dde6718724f2b5fad5a7761801446fa0 (diff) | |
altosui: Catch errors opening USB devices. Limit list to relevant devices
Avoids a segfault when failing to open a device. Limit listed telemetry
devices to just TeleDongle units.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | ao-tools/altosui/AltosDevice.java | 3 | ||||
| -rw-r--r-- | ao-tools/altosui/AltosDeviceDialog.java | 4 | ||||
| -rw-r--r-- | ao-tools/altosui/AltosSerial.java | 2 | ||||
| -rw-r--r-- | ao-tools/altosui/AltosUI.java | 5 |
4 files changed, 11 insertions, 3 deletions
diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 0e7d01da..f488174c 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -42,7 +42,8 @@ public class AltosDevice extends altos_device { AltosDevice device = new AltosDevice(); if (libaltos.altos_list_next(list, device) == 0) break; - device_list.add(device); + if (product == null || device.getProduct().startsWith(product)) + device_list.add(device); } libaltos.altos_list_finish(list); } diff --git a/ao-tools/altosui/AltosDeviceDialog.java b/ao-tools/altosui/AltosDeviceDialog.java index eb70877c..08921c3d 100644 --- a/ao-tools/altosui/AltosDeviceDialog.java +++ b/ao-tools/altosui/AltosDeviceDialog.java @@ -41,6 +41,10 @@ public class AltosDeviceDialog { devices[0]); return (altos_device) o; } else { + JOptionPane.showMessageDialog(frame, + "No AltOS devices available", + "No AltOS devices", + JOptionPane.ERROR_MESSAGE); return null; } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index e84f5b63..b016c1d6 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -134,6 +134,8 @@ public class AltosSerial implements Runnable { public void open(altos_device device) throws FileNotFoundException { close(); altos = libaltos.altos_open(device); + if (altos == null) + throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 3dfc8952..5c92b9b4 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -493,8 +493,9 @@ public class AltosUI extends JFrame { run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.getPath(), - "Cannot open serial port", + String.format("Cannot open device \"%s\"", + device.getPath()), + "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, |
