Improve firmware uploading to Arduino Leonardo based boards

This commit is contained in:
Ivan Kravets
2016-06-01 20:24:08 +03:00
parent a1e7ce415b
commit c74a2b4529
3 changed files with 25 additions and 6 deletions

View File

@ -16,6 +16,7 @@ PlatformIO 2.0
(`issue #585 <https://github.com/platformio/platformio/issues/585>`_) (`issue #585 <https://github.com/platformio/platformio/issues/585>`_)
* Use HTTP mirror for Package Manager in a case with SSL errors * Use HTTP mirror for Package Manager in a case with SSL errors
(`issue #645 <https://github.com/platformio/platformio/issues/645>`_) (`issue #645 <https://github.com/platformio/platformio/issues/645>`_)
* Improved firmware uploading to Arduino Leonardo based boards
* Fixed bug with ``env_default`` when ``pio run -e`` is used * Fixed bug with ``env_default`` when ``pio run -e`` is used
* Fixed issue with ``src_filter`` option for Windows OS * Fixed issue with ``src_filter`` option for Windows OS
(`issue #652 <https://github.com/platformio/platformio/issues/652>`_) (`issue #652 <https://github.com/platformio/platformio/issues/652>`_)

View File

@ -50,8 +50,9 @@ def TouchSerialPort(env, port, baudrate):
def WaitForNewSerialPort(env, before): def WaitForNewSerialPort(env, before):
new_port = None new_port = None
elapsed = 0 elapsed = 0
sleep(0.5)
while elapsed < 10: while elapsed < 10:
now = [i['port'] for i in get_serialports()] now = [i['port'] for i in get_serialports(use_grep=True)]
diff = list(set(now) - set(before)) diff = list(set(now) - set(before))
if diff: if diff:
new_port = diff[0] new_port = diff[0]

View File

@ -280,7 +280,24 @@ def exec_command(*args, **kwargs):
return result return result
def get_serialports(): def get_serialports(use_grep=False):
def _grep_serial_ports():
assert "Windows" != system()
result = []
if "Linux" == system():
patterns = ["/dev/%s*" % p for p in (
"ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")]
else:
patterns = ["/dev/tty.*"]
for pattern in patterns:
for port in glob(pattern):
result.append({"port": port, "description": "", "hwid": ""})
return result
if use_grep and "Windows" != system():
return _grep_serial_ports()
try: try:
from serial.tools.list_ports import comports from serial.tools.list_ports import comports
except ImportError: except ImportError:
@ -290,7 +307,7 @@ def get_serialports():
for p, d, h in comports(): for p, d, h in comports():
if not p: if not p:
continue continue
if "windows" in get_systype(): if "Windows" == system():
try: try:
d = unicode(d, errors="ignore") d = unicode(d, errors="ignore")
except TypeError: except TypeError:
@ -298,9 +315,9 @@ def get_serialports():
result.append({"port": p, "description": d, "hwid": h}) result.append({"port": p, "description": d, "hwid": h})
# fix for PySerial # fix for PySerial
if not result and system() == "Darwin": if not result:
for p in glob("/dev/tty.*"): result = _grep_serial_ports()
result.append({"port": p, "description": "", "hwid": ""})
return result return result