forked from speeduino/speeduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_extra_script.py
More file actions
41 lines (35 loc) · 1.27 KB
/
post_extra_script.py
File metadata and controls
41 lines (35 loc) · 1.27 KB
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
32
33
34
35
36
37
38
39
40
41
Import("env")
def wait_for_port(port):
print(f"Waiting for port {port}...")
import serial
while True:
try:
serial.Serial(port)
return
except:
pass
def get_env_port(env, option):
port = env.GetProjectOption(option)
if port:
print(f"Using {option} {port}...")
return port
# see https://github.com/platformio/platformio-core/issues/3742#issuecomment-1003454439
def wait_for_monitor_port(source, target, env):
# print(env.Dump())
# "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 = get_env_port(env, "monitor_port") or get_env_port(env, "upload_port") or get_env_port(env, "test_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
wait_for_port(port)
else:
# No port specified, try a generic delay
print("Delay while uploading...")
import time
time.sleep(3)
print("...done!")
env.AddPostAction("upload", wait_for_monitor_port)