forked from speeduino/speeduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_extra_script.py
31 lines (28 loc) · 1.03 KB
/
post_extra_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Import("env")
# see https://github.com/platformio/platformio-core/issues/3742#issuecomment-1003454439
def wait_for_monitor_port(source, target, env):
# "pio test" has no delay between upload & monitoring. Unfortuneatly, the teensy
# is rebooting at that point and the port isn't available. This rasies an exception.
port = env.GetProjectOption("monitor_port")
if port is None:
from platformio.builder.tools.pioupload import AutodetectUploadPort
AutodetectUploadPort(env)
port = env.subst("$UPLOAD_PORT")
if port:
# We have a port specified, wait for it to
# activate
print(f"Waiting for port {port}...")
import serial
while True:
try:
serial.Serial(port)
print("...done!")
return
except:
pass
# No port specified, try a generic delay
print("Delay while uploading...")
import time
time.sleep(2)
print("...done!")
env.AddPostAction("upload", wait_for_monitor_port)