#!/usr/bin/env python3 """Poll VM146's framebuffer until the main menu's red buttons are up. Never sleep-and-click: the >60 s startup has cost this campaign at least five wasted runs, and it is on the board four times. A run that clicks into the Kerberos intro reads exactly like a run whose clicks did nothing. """ import subprocess, sys, time, glob, os from PIL import Image DEADLINE = float(sys.argv[1]) if len(sys.argv) > 1 else 240.0 t0 = time.time() while time.time() - t0 < DEADLINE: subprocess.run(["uv", "run", "--with", "pillow", "python3", "tools/vmshot.py", "--ssh", "--one", "146"], capture_output=True, check=False) shots = sorted(glob.glob("dumps/vmshot/vm146-*.png"), key=os.path.getmtime) if shots: im = Image.open(shots[-1]).convert("RGB") # The button column: Profiles..Exit sit at x 455-570, y 405-695, and are a saturated red # only when the menu has actually rendered. red = 0 for y in range(405, 695, 3): for x in range(455, 570, 3): r, g, b = im.getpixel((x, y)) if r > 110 and r > g * 2 and r > b * 2: red += 1 print(f"t+{time.time()-t0:5.0f}s red={red} {os.path.basename(shots[-1])}", flush=True) if red > 400: print("MENU UP") sys.exit(0) time.sleep(6) print("MENU NOT SEEN -- do not click") sys.exit(1)