2023-07-08 18:04:30 +02:00
|
|
|
Import("env")
|
|
|
|
|
|
|
|
|
|
|
|
def find_jumperless_port_upload(source, target, env):
|
|
|
|
import serial
|
|
|
|
import serial.tools.list_ports
|
|
|
|
|
|
|
|
autodetected = -1
|
|
|
|
ports = serial.tools.list_ports.comports()
|
|
|
|
i = 0
|
2023-12-08 05:43:55 +01:00
|
|
|
foundports = []
|
2023-07-08 18:04:30 +02:00
|
|
|
for port, desc, hwid in ports:
|
|
|
|
|
|
|
|
print("{}: {} [{}]".format(i, port, desc))
|
|
|
|
|
|
|
|
if desc == "Jumperless":
|
|
|
|
autodetected = i
|
2023-12-08 05:43:55 +01:00
|
|
|
#print("Autodetected jumperless port: " + ports[autodetected][0]+ ' ' + ports[autodetected][1])
|
|
|
|
foundports.append(ports[autodetected][0])
|
|
|
|
#break
|
2023-07-08 18:04:30 +02:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
if autodetected != -1:
|
|
|
|
|
2023-12-08 05:43:55 +01:00
|
|
|
|
2023-07-08 18:04:30 +02:00
|
|
|
#(env, "monitor_port", ports[selection][0])
|
|
|
|
# ConfigEnvOption(env, "upload_port", ports[selection][0])
|
2023-12-08 05:43:55 +01:00
|
|
|
#print(foundports[0] + ' ' + foundports[1])
|
|
|
|
|
|
|
|
sortedports = sorted(foundports,key = lambda x:x[-1])
|
|
|
|
print(sortedports)
|
|
|
|
selection = autodetected
|
|
|
|
# env.Replace(MONITOR_PORT=ports[selection][0])
|
|
|
|
env.Replace(UPLOAD_PORT=sortedports[0])
|
|
|
|
print("Autodetected jumperless port: " + sortedports[0])
|
2023-07-08 18:04:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env.AddPreAction("upload", find_jumperless_port_upload)
|