From 0d8e12dbe092025b9c0daa4619c4a760b1f2b104 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Fri, 8 Nov 2013 20:34:05 +0100 Subject: [PATCH 1/3] OSX workaround for board autodetection #223 --- .../app/macosx/SystemProfilerParser.java | 8 +- .../app/macosx/SystemProfilerParserTest.java | 5 + .../app/macosx/system_profiler_output7.txt | 151 ++++++++++++++++++ 3 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 app/test/processing/app/macosx/system_profiler_output7.txt diff --git a/app/src/processing/app/macosx/SystemProfilerParser.java b/app/src/processing/app/macosx/SystemProfilerParser.java index 82f62edde..b204c9e5d 100644 --- a/app/src/processing/app/macosx/SystemProfilerParser.java +++ b/app/src/processing/app/macosx/SystemProfilerParser.java @@ -52,12 +52,8 @@ public class SystemProfilerParser { device.put(SERIAL_NUMBER, matcher.group(1)); } else if ((matcher = locationRegex.matcher(line)).matches()) { String devicePath = devicePrefix; - String suffix = matcher.group(1).substring(2, 6); - try { - devicePath = devicePath + (Integer.parseInt(suffix) + 1); - } catch (NumberFormatException e) { - devicePath = devicePath + suffix + "1"; - } + String suffix = matcher.group(1).substring(2, 6).replaceAll("0", ""); + devicePath = devicePath + suffix + "1"; device.put(DEVICE_PATH, devicePath); } else if ((matcher = pidRegex.matcher(line)).matches()) { device.put(PID, matcher.group(1)); diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index c16c52aaa..382d92642 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -38,5 +38,10 @@ public class SystemProfilerParserTest { assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem1421")); assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem1421")); + + output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output7.txt")); + + assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem24131")); + assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131")); } } diff --git a/app/test/processing/app/macosx/system_profiler_output7.txt b/app/test/processing/app/macosx/system_profiler_output7.txt new file mode 100644 index 000000000..5247f50da --- /dev/null +++ b/app/test/processing/app/macosx/system_profiler_output7.txt @@ -0,0 +1,151 @@ +USB: + + USB Hi-Speed Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBEHCI + PCI Device ID: 0x0d9d + PCI Revision ID: 0x00a2 + PCI Vendor ID: 0x10de + Bus Number: 0x26 + + Internal Memory Card Reader: + + Product ID: 0x8403 + Vendor ID: 0x05ac (Apple Inc.) + Version: 98,33 + Serial Number: 9833 + Speed: Up to 480 Mb/sec + Manufacturer: Apple + Location ID: 0x26100000 / 2 + Current Available (mA): 500 + Current Required (mA): 500 + + USB Hi-Speed Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBEHCI + PCI Device ID: 0x0d9d + PCI Revision ID: 0x00a2 + PCI Vendor ID: 0x10de + Bus Number: 0x24 + + USB 2.0 Hub: + + Product ID: 0x0101 + Vendor ID: 0x1a40 (TERMINUS TECHNOLOGY INC.) + Version: 1,11 + Speed: Up to 480 Mb/sec + Location ID: 0x24100000 / 3 + Current Available (mA): 500 + Current Required (mA): 100 + + FT230X Basic UART: + + Product ID: 0x6015 + Vendor ID: 0x0403 (Future Technology Devices International Limited) + Version: 10,00 + Serial Number: DN0031EV + Speed: Up to 12 Mb/sec + Manufacturer: FTDI + Location ID: 0x24120000 / 7 + Current Available (mA): 500 + Current Required (mA): 90 + + Arduino Leonardo: + + Product ID: 0x8036 + Vendor ID: 0x2341 + Version: 1,00 + Speed: Up to 12 Mb/sec + Manufacturer: Arduino LLC + Location ID: 0x24130000 / 6 + Current Available (mA): 500 + Current Required (mA): 500 + + USB Receiver: + + Product ID: 0xc521 + Vendor ID: 0x046d (Logitech Inc.) + Version: 57,01 + Speed: Up to 1.5 Mb/sec + Manufacturer: Logitech + Location ID: 0x24140000 / 5 + Current Available (mA): 500 + Current Required (mA): 98 + + Built-in iSight: + + Product ID: 0x8507 + Vendor ID: 0x05ac (Apple Inc.) + Version: 4,35 + Serial Number: 8JA9E1A6TDCLNL00 + Speed: Up to 480 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0x24600000 / 2 + Current Available (mA): 500 + Current Required (mA): 500 + + USB Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBOHCI + PCI Device ID: 0x0d9c + PCI Revision ID: 0x00a1 + PCI Vendor ID: 0x10de + Bus Number: 0x06 + + BRCM2046 Hub: + + Product ID: 0x4500 + Vendor ID: 0x0a5c (Broadcom Corp.) + Version: 1,00 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0x06600000 / 4 + Current Available (mA): 500 + Current Required (mA): 0 + + Bluetooth USB Host Controller: + + Product ID: 0x8213 + Vendor ID: 0x05ac (Apple Inc.) + Version: 2,06 + Serial Number: C8BCC8B0B471 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0x06610000 / 5 + Current Available (mA): 500 + Current Required (mA): 0 + + 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: 0x06500000 / 3 + Current Available (mA): 500 + Current Required (mA): 100 + + Apple Internal Keyboard / Trackpad: + + Product ID: 0x0237 + Vendor ID: 0x05ac (Apple Inc.) + Version: 0,90 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0x06300000 / 2 + Current Available (mA): 500 + Current Required (mA): 40 + + USB Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBOHCI + PCI Device ID: 0x0d9c + PCI Revision ID: 0x00a1 + PCI Vendor ID: 0x10de + Bus Number: 0x04 + From 42a00966826e9a1d548e0b21a3ed661e5ed07572 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Mon, 11 Nov 2013 02:41:44 +0100 Subject: [PATCH 2/3] Added VID and PID for older Arduino Unos --- hardware/arduino/avr/boards.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hardware/arduino/avr/boards.txt b/hardware/arduino/avr/boards.txt index c9b341a3b..fba559010 100644 --- a/hardware/arduino/avr/boards.txt +++ b/hardware/arduino/avr/boards.txt @@ -41,8 +41,12 @@ yun.build.extra_flags={build.usb_flags} ############################################################## uno.name=Arduino Uno + uno.vid.0=0x2341 uno.pid.0=0x0043 +uno.vid.1=0x2341 +uno.pid.1=0x0001 + uno.upload.tool=avrdude uno.upload.protocol=arduino uno.upload.maximum_size=32256 From 7706fcfdde0549848ea95186c83ee8a6fe8e2a40 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Mon, 11 Nov 2013 04:42:29 +0100 Subject: [PATCH 3/3] Can now detect devices with serial number in the port number on OSX - see: https://github.com/arduino/Arduino/issues/223 It now also parses PID and VID values with text afterwards properly --- .../app/macosx/SystemProfilerParser.java | 28 ++++++++++++++----- .../app/macosx/SystemProfilerParserTest.java | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/macosx/SystemProfilerParser.java b/app/src/processing/app/macosx/SystemProfilerParser.java index b204c9e5d..bef99387c 100644 --- a/app/src/processing/app/macosx/SystemProfilerParser.java +++ b/app/src/processing/app/macosx/SystemProfilerParser.java @@ -14,7 +14,8 @@ public class SystemProfilerParser { private static final String VID = "vid"; private static final String PID = "pid"; private static final String SERIAL_NUMBER = "serial_number"; - private static final String DEV_TTY = "/dev/tty."; + private static final String DEV_TTY_USBSERIAL = "/dev/tty.usbserial-"; + private static final String DEV_CU_USBSERIAL = "/dev/cu.usbserial-"; private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem"; private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem"; @@ -34,7 +35,11 @@ public class SystemProfilerParser { BufferedReader reader = new BufferedReader(new StringReader(output)); String devicePrefix; - if (serial.startsWith(DEV_TTY)) { + if (serial.startsWith(DEV_TTY_USBSERIAL)) { + devicePrefix = DEV_TTY_USBSERIAL; + } else if (serial.startsWith(DEV_CU_USBSERIAL)) { + devicePrefix = DEV_CU_USBSERIAL; + } else if (serial.startsWith(DEV_TTY_USBMODEM)) { devicePrefix = DEV_TTY_USBMODEM; } else { devicePrefix = DEV_CU_USBMODEM; @@ -50,15 +55,24 @@ public class SystemProfilerParser { if ((matcher = serialNumberRegex.matcher(line)).matches()) { device.put(SERIAL_NUMBER, matcher.group(1)); - } else if ((matcher = locationRegex.matcher(line)).matches()) { - String devicePath = devicePrefix; + if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) { + String devicePath = devicePrefix + matcher.group(1); + device.put(DEVICE_PATH, devicePath); + } + } else if ((serial.startsWith(DEV_TTY_USBMODEM) || serial.startsWith(DEV_CU_USBMODEM)) && (matcher = locationRegex.matcher(line)).matches()) { String suffix = matcher.group(1).substring(2, 6).replaceAll("0", ""); - devicePath = devicePath + suffix + "1"; + String devicePath = devicePrefix + suffix + "1"; device.put(DEVICE_PATH, devicePath); } else if ((matcher = pidRegex.matcher(line)).matches()) { - device.put(PID, matcher.group(1)); + String pid = matcher.group(1); + if (pid.indexOf(" ") > 0) + pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number + device.put(PID, pid); } else if ((matcher = vidRegex.matcher(line)).matches()) { - device.put(VID, matcher.group(1)); + String vid = matcher.group(1); + if (vid.indexOf(" ") > 0) + vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number + device.put(VID, vid); } else if (line.equals("")) { if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) { return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index 382d92642..3f2e0b9de 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -43,5 +43,7 @@ public class SystemProfilerParserTest { assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.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/tty.usbserial-DN0031EV")); } }