1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Merge remote-tracking branch 'arduino/master'

This commit is contained in:
Cristian Maglie 2015-06-15 09:45:10 +02:00
commit 391994fbe8
5 changed files with 150 additions and 17 deletions

View File

@ -70,6 +70,8 @@ import cc.arduino.packages.uploaders.SerialUploader;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class Editor extends JFrame implements RunnerListener { public class Editor extends JFrame implements RunnerListener {
public static final int MAX_TIME_AWAITING_FOR_RESUMING_SERIAL_MONITOR = 5000;
private final Platform platform; private final Platform platform;
private JMenu recentSketchesMenu; private JMenu recentSketchesMenu;
@ -2411,6 +2413,16 @@ public class Editor extends JFrame implements RunnerListener {
// Return the serial monitor window to its initial state // Return the serial monitor window to its initial state
if (serialMonitor != null) { if (serialMonitor != null) {
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port")); BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
long sleptFor = 0;
while (boardPort == null && sleptFor < MAX_TIME_AWAITING_FOR_RESUMING_SERIAL_MONITOR) {
try {
Thread.sleep(100);
sleptFor += 100;
boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
} catch (InterruptedException e) {
// noop
}
}
try { try {
if (boardPort == null) { if (boardPort == null) {
serialMonitor.close(); serialMonitor.close();

View File

@ -74,5 +74,9 @@ public class SystemProfilerParserTest {
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131")); assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131"));
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV"));
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV"));
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt"));
assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132"));
} }
} }

View File

@ -0,0 +1,96 @@
USB:
USB Hi-Speed Bus:
Host Controller Location: Built-in USB
Host Controller Driver: AppleUSBEHCI
PCI Device ID: 0x1c2d
PCI Revision ID: 0x0005
PCI Vendor ID: 0x8086
Bus Number: 0xfa
Hub:
Product ID: 0x2513
Vendor ID: 0x0424 (SMSC)
Version: b.b3
Speed: Up to 480 Mb/sec
Location ID: 0xfa100000 / 2
Current Available (mA): 500
Current Required (mA): 2
Arduino Leonardo:
Product ID: 0x8036
Vendor ID: 0x2341
Version: 1.00
Speed: Up to 12 Mb/sec
Manufacturer: Arduino LLC
Location ID: 0xfa120000 / 5
Current Available (mA): 500
Current Required (mA): 500
BRCM20702 Hub:
Product ID: 0x4500
Vendor ID: 0x0a5c (Broadcom Corp.)
Version: 1.00
Speed: Up to 12 Mb/sec
Manufacturer: Apple Inc.
Location ID: 0xfa110000 / 3
Current Available (mA): 500
Current Required (mA): 94
Bluetooth USB Host Controller:
Product ID: 0x8281
Vendor ID: 0x05ac (Apple Inc.)
Version: 1.25
Speed: Up to 12 Mb/sec
Manufacturer: Apple Inc.
Location ID: 0xfa113000 / 4
Current Available (mA): 500
Current Required (mA): 0
USB Hi-Speed Bus:
Host Controller Location: Built-in USB
Host Controller Driver: AppleUSBEHCI
PCI Device ID: 0x1c26
PCI Revision ID: 0x0005
PCI Vendor ID: 0x8086
Bus Number: 0xfd
Hub:
Product ID: 0x2513
Vendor ID: 0x0424 (SMSC)
Version: b.b3
Speed: Up to 480 Mb/sec
Location ID: 0xfd100000 / 2
Current Available (mA): 500
Current Required (mA): 2
EDBG CMSIS-DAP:
Product ID: 0x2157
Vendor ID: 0x03eb (Atmel Corporation)
Version: 1.01
Serial Number: 00000000AZE000000310
Speed: Up to 480 Mb/sec
Manufacturer: Atmel Corp.
Location ID: 0xfd130000 / 4
Current Available (mA): 500
Current Required (mA): 500
IR Receiver:
Product ID: 0x8242
Vendor ID: 0x05ac (Apple Inc.)
Version: 0.16
Speed: Up to 1.5 Mb/sec
Manufacturer: Apple Computer, Inc.
Location ID: 0xfd110000 / 3
Current Available (mA): 500
Current Required (mA): 100

View File

@ -106,17 +106,18 @@ public class SerialUploader extends Uploader {
t = prefs.get("upload.wait_for_upload_port"); t = prefs.get("upload.wait_for_upload_port");
boolean waitForUploadPort = (t != null) && t.equals("true"); boolean waitForUploadPort = (t != null) && t.equals("true");
String uploadPort = prefs.getOrExcept("serial.port"); String userSelectedUploadPort = prefs.getOrExcept("serial.port");
String actualUploadPort = null;
if (doTouch) { if (doTouch) {
try { try {
// Toggle 1200 bps on selected serial port to force board reset. // Toggle 1200 bps on selected serial port to force board reset.
List<String> before = Serial.list(); List<String> before = Serial.list();
if (before.contains(uploadPort)) { if (before.contains(userSelectedUploadPort)) {
if (verbose) if (verbose)
System.out.println( System.out.println(
I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), uploadPort)); I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), userSelectedUploadPort));
Serial.touchForCDCReset(uploadPort); Serial.touchForCDCReset(userSelectedUploadPort);
} }
Thread.sleep(400); Thread.sleep(400);
if (waitForUploadPort) { if (waitForUploadPort) {
@ -124,18 +125,21 @@ public class SerialUploader extends Uploader {
// otherwise assert DTR, which would cancel the WDT reset if // otherwise assert DTR, which would cancel the WDT reset if
// it happened within 250 ms. So we wait until the reset should // it happened within 250 ms. So we wait until the reset should
// have already occured before we start scanning. // have already occured before we start scanning.
uploadPort = waitForUploadPort(uploadPort, before); actualUploadPort = waitForUploadPort(userSelectedUploadPort, before);
} }
} catch (SerialException e) { } catch (SerialException e) {
throw new RunnerException(e); throw new RunnerException(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RunnerException(e.getMessage()); throw new RunnerException(e.getMessage());
} }
prefs.put("serial.port", uploadPort); if (actualUploadPort == null) {
if (uploadPort.startsWith("/dev/")) { actualUploadPort = userSelectedUploadPort;
prefs.put("serial.port.file", uploadPort.substring(5)); }
prefs.put("serial.port", actualUploadPort);
if (actualUploadPort.startsWith("/dev/")) {
prefs.put("serial.port.file", actualUploadPort.substring(5));
} else { } else {
prefs.put("serial.port.file", uploadPort); prefs.put("serial.port.file", actualUploadPort);
} }
} }
@ -158,9 +162,9 @@ public class SerialUploader extends Uploader {
throw new RunnerException(e); throw new RunnerException(e);
} }
String finalUploadPort = null;
if (uploadResult && doTouch) { if (uploadResult && doTouch) {
try { try {
String previousUploadPort = PreferencesData.get("serial.port");
if (waitForUploadPort) { if (waitForUploadPort) {
// For Due/Leonardo wait until the bootloader serial port disconnects and the // For Due/Leonardo wait until the bootloader serial port disconnects and the
// sketch serial port reconnects (or timeout after a few seconds if the // sketch serial port reconnects (or timeout after a few seconds if the
@ -170,7 +174,11 @@ public class SerialUploader extends Uploader {
long started = System.currentTimeMillis(); long started = System.currentTimeMillis();
while (System.currentTimeMillis() - started < 2000) { while (System.currentTimeMillis() - started < 2000) {
List<String> portList = Serial.list(); List<String> portList = Serial.list();
if (portList.contains(previousUploadPort)) { if (portList.contains(actualUploadPort)) {
finalUploadPort = actualUploadPort;
break;
} else if (portList.contains(userSelectedUploadPort)) {
finalUploadPort = userSelectedUploadPort;
break; break;
} }
Thread.sleep(250); Thread.sleep(250);
@ -181,7 +189,13 @@ public class SerialUploader extends Uploader {
} }
} }
BaseNoGui.selectSerialPort(uploadPort); if (finalUploadPort == null) {
finalUploadPort = actualUploadPort;
}
if (finalUploadPort == null) {
finalUploadPort = userSelectedUploadPort;
}
BaseNoGui.selectSerialPort(finalUploadPort);
return uploadResult; return uploadResult;
} }

View File

@ -55,7 +55,7 @@ public class SystemProfilerParser {
if ((matcher = serialNumberRegex.matcher(line)).matches()) { if ((matcher = serialNumberRegex.matcher(line)).matches()) {
device.put(SERIAL_NUMBER, matcher.group(1)); device.put(SERIAL_NUMBER, matcher.group(1));
if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) { if (serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL)) {
String devicePath = devicePrefix + matcher.group(1); String devicePath = devicePrefix + matcher.group(1);
device.put(DEVICE_PATH, devicePath); device.put(DEVICE_PATH, devicePath);
} }
@ -65,17 +65,24 @@ public class SystemProfilerParser {
device.put(DEVICE_PATH, devicePath); device.put(DEVICE_PATH, devicePath);
} else if ((matcher = pidRegex.matcher(line)).matches()) { } else if ((matcher = pidRegex.matcher(line)).matches()) {
String pid = matcher.group(1); String pid = matcher.group(1);
if (pid.indexOf(" ") > 0) if (pid.indexOf(" ") > 0) {
pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number
}
device.put(PID, pid); device.put(PID, pid);
} else if ((matcher = vidRegex.matcher(line)).matches()) { } else if ((matcher = vidRegex.matcher(line)).matches()) {
String vid = matcher.group(1); String vid = matcher.group(1);
if (vid.indexOf(" ") > 0) if (vid.indexOf(" ") > 0) {
vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number
}
device.put(VID, vid); device.put(VID, vid);
} else if (line.equals("")) { } else if (line.equals("")) {
if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) { if (device.containsKey(DEVICE_PATH)) {
return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); String computedDevicePath = device.get(DEVICE_PATH);
String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1);
String serialMinusChar = serial.substring(0, serial.length() - 1);
if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) {
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
}
} }
device = new HashMap<String, String>(); device = new HashMap<String, String>();
} }