Skip to content

Commit 3283066

Browse files
authored
Feat: support device param in modem passthrough (#63)
1 parent 2b09b83 commit 3283066

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

util/modem_passthrough/modem_passthrough.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,37 @@
1616
LOG_FILE = os.path.join(SCRIPT_DIR, 'passthrough.log')
1717
WATCH_INTERVAL_MS = 200
1818

19+
def parse_args():
20+
"""Parse command line arguments."""
21+
logging = '--log' in sys.argv
22+
device = None
23+
# Look for --device or -d argument
24+
args = sys.argv[1:]
25+
for i, arg in enumerate(args):
26+
if arg in ('--device', '-d') and i + 1 < len(args):
27+
device = args[i + 1]
28+
break
29+
elif arg.startswith('--device='):
30+
device = arg.split('=', 1)[1]
31+
break
32+
# Also accept positional device (first arg that's not a flag)
33+
if device is None:
34+
for arg in args:
35+
if not arg.startswith('-') and arg != '--log':
36+
device = arg
37+
break
38+
return logging, device
39+
40+
1941
class ModemGUI:
20-
def __init__(self, root):
21-
self.logging = '--log' in sys.argv
42+
def __init__(self, root, logging=False, device=None):
43+
self.logging = logging
44+
self.device = device
2245
self.root = root
23-
self.root.title('Walter Modem Passthrough')
46+
title = 'Walter Modem Passthrough'
47+
if device:
48+
title += f' ({device})'
49+
self.root.title(title)
2450
self.root.configure(bg='gray10')
2551

2652
# Queues & state
@@ -215,8 +241,14 @@ def start_modem_process(self):
215241
if not cmd:
216242
raise FileNotFoundError('mpremote not found')
217243

244+
# Build command with optional device connection
245+
full_cmd = cmd[:]
246+
if self.device:
247+
full_cmd += ['connect', self.device]
248+
full_cmd += ['mount', '.', '+', 'run', 'esp-script.py']
249+
218250
proc = subprocess.Popen(
219-
cmd + ['mount','.','+','run','esp-script.py'],
251+
full_cmd,
220252
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
221253
text=True, bufsize=1, cwd=SCRIPT_DIR
222254
)
@@ -354,5 +386,7 @@ def run(self):
354386
if self.logging: self.log(line='===== PROGRAM STARTED =====\n', raw=True)
355387
self.root.mainloop()
356388

357-
if __name__=='__main__':
358-
root=tk.Tk(); ModemGUI(root).run()
389+
if __name__ == '__main__':
390+
logging, device = parse_args()
391+
root = tk.Tk()
392+
ModemGUI(root, logging=logging, device=device).run()

0 commit comments

Comments
 (0)