#!/usr/bin/env python3 """Reserved K230 landscape run; injected uinput, temporary labeled Foot apps.""" import os,sys,time,json,struct,fcntl,socket,subprocess,shlex,importlib.util from pathlib import Path mode=sys.argv[1];out=Path(sys.argv[2]);count=int(sys.argv[3]) if len(sys.argv)>3 else 6 if mode not in ('full','reduced') or not 1<=count<=12:raise SystemExit('invalid run') out.mkdir(mode=0o700) root=Path(__file__).parent spec=importlib.util.spec_from_file_location('session_export',root/'card-shell-board-session.py');export=importlib.util.module_from_spec(spec);spec.loader.exec_module(export) def cmd(args):return subprocess.check_output(args,text=True,timeout=25).strip() def ipc(command='',kind=0): payload=command.encode() with socket.socket(socket.AF_UNIX) as s: s.settimeout(20);s.connect('/run/shell/sway-ipc.sock');s.sendall(b'i3-ipc'+struct.pack('=II',len(payload),kind)+payload) def read(n): b=b'' while len(b) native panel, then the controller's measured ranges. nx=y/567;ny=1-x/1231 def raw(a,f):return round(info[a][1]+f*(info[a][2]-info[a][1])) return [(3,0x35,raw(0x35,nx)),(3,0x36,raw(0x36,ny)),(3,0,raw(0,nx)),(3,1,raw(1,ny))] armed=False try: # The Rust overlay route is already in the installed closure. subprocess.run(['sudo','-u','shell','env','XDG_RUNTIME_DIR=/run/shell','/run/current-system/sw/bin/k230-shell-rust','--surface','hide'],check=True,timeout=20) for n,color in [('one','44'),('two','43')]: shell="printf '\\033["+color+"m\\033[2J\\033[HMotion trace "+n+"\\n'; sleep 300" ipc('exec foot --app-id=k230.motion.'+n+' --title=Motion-'+n+' sh -c '+shlex.quote(shell)) end=time.monotonic()+15 while not {'k230.motion.one','k230.motion.two'}<=apps(): if time.monotonic()>end:raise RuntimeError('test apps failed to map') time.sleep(.1) ipc('card_shell back') ipc('[app_id="k230.motion.one"] focus');time.sleep(.5) start_epoch=time.time();metadata['start_monotonic_ns']=time.monotonic_ns() ipc('card_shell benchmark injected');armed=True;time.sleep(3.2) ipc('card_shell enter');time.sleep(1.0);capture('before') for i in range(count): x0,x1=616,(366 if i%2==0 else 866);y=280 g={'index':i,'from':[x0,y],'to':[x1,y],'down_monotonic_ns':time.monotonic_ns()} frame([(3,0x2f,0),(3,0x39,100+i),(3,0x30,20),(1,0x14a,1),*position(x0,y)]) time.sleep(.05);begin=time.monotonic() steps=35 if count>1 else 16;duration=.7 if count>1 else .32 for k in range(1,steps+1): time.sleep(max(0,begin+duration*k/steps-time.monotonic()));frame(position(x0+(x1-x0)*k/steps,y)) if i==0 and count==1:capture('held') frame([(3,0x39,-1),(1,0x14a,0)]);g['up_monotonic_ns']=time.monotonic_ns() time.sleep(.8);metadata['gestures'].append(g) capture('after');time.sleep(3.2);ipc('card_shell benchmark-stop');armed=False raw=cmd(['journalctl','-u','shell.service','--since','@'+str(int(start_epoch)),'--no-pager','-o','cat','--grep=K230_CARD_(BENCH|SHELL (motion-|input-origin))','-n','30000']) clean=export.normalized_journal(raw) (out/'telemetry.log').write_text(clean) metadata['end_monotonic_ns']=time.monotonic_ns();metadata['telemetry_lines']=len(clean.splitlines()) (out/'metadata.json').write_text(json.dumps(metadata,indent=2)+'\n') print(json.dumps({'status':'captured','mode':mode,'gestures':len(metadata['gestures']),'lines':metadata['telemetry_lines'],'directory':str(out)}),flush=True) finally: if armed: try:ipc('card_shell benchmark-stop') except Exception:pass try:frame([(3,0x39,-1),(1,0x14a,0)]) except Exception:pass fcntl.ioctl(fd,0x5502);os.close(fd) for n in ('one','two'): try:ipc('[app_id="k230.motion.'+n+'"] kill') except Exception:pass try:ipc('card_shell home') except Exception:pass