|
16 | 16 | LOG_FILE = os.path.join(SCRIPT_DIR, 'passthrough.log') |
17 | 17 | WATCH_INTERVAL_MS = 200 |
18 | 18 |
|
| 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 | + |
19 | 41 | 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 |
22 | 45 | 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) |
24 | 50 | self.root.configure(bg='gray10') |
25 | 51 |
|
26 | 52 | # Queues & state |
@@ -215,8 +241,14 @@ def start_modem_process(self): |
215 | 241 | if not cmd: |
216 | 242 | raise FileNotFoundError('mpremote not found') |
217 | 243 |
|
| 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 | + |
218 | 250 | proc = subprocess.Popen( |
219 | | - cmd + ['mount','.','+','run','esp-script.py'], |
| 251 | + full_cmd, |
220 | 252 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
221 | 253 | text=True, bufsize=1, cwd=SCRIPT_DIR |
222 | 254 | ) |
@@ -354,5 +386,7 @@ def run(self): |
354 | 386 | if self.logging: self.log(line='===== PROGRAM STARTED =====\n', raw=True) |
355 | 387 | self.root.mainloop() |
356 | 388 |
|
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