index.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>OpenPuck Config</title>
  7. <style>
  8. :root{ --bg:#11131a; --card:#1b1f2b; --fg:#e7ecf3; --mut:#8a93a6; --acc:#5bd6a0; --acc2:#5b9bd6; --bad:#d65b6e; }
  9. *{box-sizing:border-box}
  10. body{margin:0;font:14px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--fg);padding:24px}
  11. h1{font-size:20px;margin:0 0 4px}
  12. .sub{color:var(--mut);margin:0 0 20px}
  13. .wrap{max-width:680px;margin:0 auto}
  14. .card{background:var(--card);border:1px solid #272d3d;border-radius:12px;padding:18px 20px;margin-bottom:16px}
  15. .card h2{font-size:13px;text-transform:uppercase;letter-spacing:.06em;color:var(--mut);margin:0 0 14px}
  16. .row{display:flex;align-items:center;gap:14px;margin:12px 0}
  17. .row label{flex:0 0 150px;color:var(--fg)}
  18. .row .val{flex:0 0 64px;text-align:right;color:var(--acc);font-variant-numeric:tabular-nums}
  19. input[type=range]{flex:1;accent-color:var(--acc)}
  20. select{background:#0e1017;color:var(--fg);border:1px solid #313a4f;border-radius:8px;padding:6px 8px;flex:1}
  21. button{background:#222a3a;color:var(--fg);border:1px solid #36405a;border-radius:8px;padding:9px 14px;cursor:pointer;font:inherit}
  22. button:hover{border-color:var(--acc2)}
  23. button.primary{background:var(--acc2);border-color:var(--acc2);color:#06121f;font-weight:600}
  24. button.active{background:var(--acc);border-color:var(--acc);color:#062018;font-weight:600}
  25. button:disabled{opacity:.4;cursor:default}
  26. .pill{display:inline-block;padding:2px 9px;border-radius:99px;font-size:12px;font-weight:600}
  27. .pill.up{background:#143626;color:var(--acc)} .pill.dn{background:#3a1822;color:var(--bad)}
  28. .statgrid{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}
  29. .stat{background:#0e1017;border:1px solid #232a3a;border-radius:8px;padding:10px}
  30. .stat .k{color:var(--mut);font-size:11px;text-transform:uppercase;letter-spacing:.05em}
  31. .stat .v{font-size:18px;margin-top:2px}
  32. .modes{display:flex;gap:10px}
  33. .note{color:var(--mut);font-size:12px;margin-top:10px}
  34. #log{font:12px ui-monospace,Menlo,monospace;color:var(--mut);white-space:pre-wrap;margin-top:8px;max-height:120px;overflow:auto}
  35. .hide{display:none}
  36. /* ---- controller slot tabs ---- */
  37. .slot-tabs{display:flex;gap:6px;margin:0 0 14px;flex-wrap:wrap}
  38. .slot-tab{display:flex;align-items:center;gap:7px;padding:5px 14px;border-radius:8px;font-size:12px;font-weight:600;background:#0e1017;border:1px solid #232a3a;color:var(--mut);cursor:pointer;transition:border-color .15s,color .15s,background .15s}
  39. .slot-tab:hover{border-color:var(--acc2);color:var(--fg)}
  40. .slot-tab.active{background:#111c2e;border-color:var(--acc2);color:var(--fg)}
  41. .slot-tab .dot{width:7px;height:7px;border-radius:50%;background:var(--bad);flex-shrink:0;transition:background .3s}
  42. .slot-tab .dot.up{background:var(--acc);animation:pulse-link 2.2s ease-in-out infinite}
  43. @keyframes pulse-link{
  44. 0%,100%{box-shadow:0 0 0 0 rgba(91,214,160,.5)}
  45. 55%{box-shadow:0 0 0 5px rgba(91,214,160,0)}
  46. }
  47. @media(prefers-reduced-motion:reduce){.slot-tab .dot.up{animation:none}}
  48. .per-slot-grid{margin-bottom:12px}
  49. </style>
  50. </head>
  51. <body>
  52. <div class="wrap">
  53. <h1>OpenPuck Config</h1>
  54. <p class="sub">nRF52840 Steam Controller 2 puck reimplementation — WebUSB. Chrome/Edge only.</p>
  55. <div class="card" id="connectCard">
  56. <div class="row" style="margin:0">
  57. <button id="connectBtn" class="primary">Connect to copycat</button>
  58. <span id="connState" class="pill dn">disconnected</span>
  59. </div>
  60. <p class="note">If nothing appears in the device picker, the copycat may be busy (quit any app holding it) or needs a replug.</p>
  61. </div>
  62. <div id="panel" class="hide">
  63. <div class="card">
  64. <h2>USB mode</h2>
  65. <div class="modes" style="flex-wrap:wrap">
  66. <button data-mode="0" class="modebtn">Steam (puck)</button>
  67. <button data-mode="1" class="modebtn">Xbox 360</button>
  68. <button data-mode="2" class="modebtn">Switch (HORIPAD)</button>
  69. <button data-mode="3" class="modebtn">Lizard (always)</button>
  70. <button data-mode="4" class="modebtn">Switch Pro + gyro</button>
  71. <button data-mode="5" class="modebtn">PS5 DualSense</button>
  72. <button data-mode="6" class="modebtn">HID gyro (DS4)</button>
  73. <button data-mode="9" class="modebtn">PS3 (DualShock 3)</button>
  74. </div>
  75. <p class="note">Switching reboots the copycat and re-enumerates USB (~2 s). WebUSB works in every mode, including Steam/Lizard with Steam running (Chrome claims the vendor interface; Steam keeps the HID slots). Switch HORIPAD + WebUSB is PC-only.</p>
  76. <div class="row"><label>Persist last mode</label>
  77. <button id="persistMode">off</button>
  78. <span class="note" style="flex:1">Off (default): every restart / fresh reconnect boots into Steam mode. On: remembers the last mode you selected.</span>
  79. </div>
  80. </div>
  81. <div class="card">
  82. <h2>Back4 + face button chords</h2>
  83. <p class="note" style="margin-top:0">Hold all four back paddles (L4+R4+L5+R5) plus a face button to switch mode without the WebUI. <strong>A is always Steam.</strong> B / X / Y are configurable below (defaults: B=Lizard, X=Xbox, Y=Switch HORIPAD).</p>
  84. <div class="row"><label>B + back4 →</label><select class="chord" data-i="0"></select></div>
  85. <div class="row"><label>X + back4 →</label><select class="chord" data-i="1"></select></div>
  86. <div class="row"><label>Y + back4 →</label><select class="chord" data-i="2"></select></div>
  87. </div>
  88. <div class="card">
  89. <h2>Link status</h2>
  90. <!-- Per-controller tabs: visible only when 2+ controllers are bonded -->
  91. <div class="slot-tabs" id="slotTabs" style="display:none"></div>
  92. <!-- Per-slot: RF link / Battery / Signal -->
  93. <div class="statgrid per-slot-grid">
  94. <div class="stat"><div class="k">RF link</div><div class="v" id="stLink">—</div></div>
  95. <div class="stat"><div class="k">Battery</div><div class="v" id="stBatt">—</div></div>
  96. <div class="stat"><div class="k">Signal</div><div class="v" id="stRssi">—</div></div>
  97. </div>
  98. <!-- Global stats -->
  99. <div class="statgrid">
  100. <div class="stat"><div class="k">Delivered</div><div class="v" id="stRate">—</div></div>
  101. <div class="stat"><div class="k">New reports</div><div class="v" id="stNew">—</div></div>
  102. <div class="stat"><div class="k">Polls/s</div><div class="v" id="stPolls">—</div></div>
  103. <div class="stat"><div class="k">RF fails/s (crc·noRx·heal)</div><div class="v" id="stRfFail">—</div></div>
  104. <div class="stat logonly"><div class="k">Loop period</div><div class="v" id="stLoop">—</div></div>
  105. <div class="stat logonly"><div class="k">Slowest stage</div><div class="v" id="stWorst">—</div></div>
  106. <div class="stat logonly"><div class="k">Poll period act/want</div><div class="v" id="stPollPer">—</div></div>
  107. <div class="stat"><div class="k">Build (git)</div><div class="v" id="stBuild">—</div></div>
  108. <div class="stat"><div class="k">Last reset</div><div class="v" id="stReset">—</div></div>
  109. </div>
  110. <p class="note" style="margin-top:6px"><strong>Reset detail:</strong> <span id="resetHist" style="font-family:ui-monospace,Menlo,monospace">—</span><br>
  111. <em>watchdog (hang)</em>/<em>CPU lockup</em>/<em>HARDFAULT</em> = a fault worth reporting (issue #72); <em>reboot</em> = an intentional reset (mode change / config); <em>power-on</em> &amp; <em>pin/replug</em> = normal plug-in.</p>
  112. <p class="note" style="margin-top:8px"><strong>IMU (raw):</strong> <span id="stImu" style="font-family:ui-monospace,Menlo,monospace">—</span><br>
  113. Raw SC2 accel (before scaling). This controller is a ±2 g sensor (~16384 = 1 g); the Switch report divides it by 4 to present the genuine ±8 g (4096 = 1 g) scale so the console's gravity-correction engages and the gyro stops drifting.</p>
  114. <p class="note logonly">Polls/s ≈ 250 expected; it's capped by Loop period (≈4000 µs needed). "Slowest stage" is the loop section eating the most time per iteration.</p>
  115. <div class="row" style="margin:14px 0 0;border-top:1px solid #272d3d;padding-top:14px">
  116. <strong style="flex-basis:100%">Connection tuning <span class="note">(persists across reboot)</span></strong>
  117. </div>
  118. <div class="row" style="margin:8px 0 0"><label style="min-width:150px">Block haptics on connect</label>
  119. <button id="hapBlockOn">off</button>
  120. <span class="note" style="flex:1">Drops all Steam haptics for a short window right after a controller (re)connects, so its haptic engine settles before the first real haptic.</span>
  121. </div>
  122. <div class="row" style="margin:8px 0 0"><label style="min-width:150px">Block duration</label>
  123. <input type="range" id="hapBlockS" min="0" max="30" step="1"><span class="val" id="hapBlockSV"></span>
  124. <span class="note" style="flex:1">How long to drop haptics after connect (seconds). Default 10 s.</span>
  125. </div>
  126. <div class="row" style="margin:14px 0 0;border-top:1px solid #272d3d;padding-top:14px"><button id="hapClear">Clear stuck buzz</button>
  127. <span class="note" style="flex:1">If the controller's haptics get stuck/buzzing, this re-inits them (same as pressing Steam).</span>
  128. </div>
  129. <div class="row" style="margin:10px 0 0"><button id="ctlrOff">Turn off controller</button>
  130. <span class="note" style="flex:1">Fires the controller power-off (0x9F "off!", x3) — the same path Steam's "turn off controller" and host-suspend use. Watch the link status to see it disconnect.</span>
  131. </div>
  132. <div class="row" style="margin:10px 0 0;border-top:1px solid #272d3d;padding-top:14px">
  133. <button id="dfuSerial">Reboot to Serial DFU</button>
  134. <span class="note" style="flex:1">Reboots the puck into serial DFU mode (adafruit-nrfutil). The device drops off USB — flash with <code>adafruit-nrfutil dfu serial …</code> then replug.</span>
  135. </div>
  136. <div class="row" style="margin:10px 0 0">
  137. <button id="dfuUf2">Reboot to UF2 Bootloader</button>
  138. <span class="note" style="flex:1">Reboots the puck into the UF2 mass-storage bootloader. It mounts as a USB drive — drag the <code>.uf2</code> file onto it to flash, then it reboots automatically.</span>
  139. </div>
  140. <div class="row" style="margin:18px 0 0;border-top:1px solid #4a2030;padding-top:14px">
  141. <button id="factoryErase" style="background:#3a1420;border-color:#7a2233;color:#ff9bb0;font-weight:600">⚠ Factory erase</button>
  142. <span class="note" style="flex:1"><strong style="color:#ff9bb0">Danger:</strong> wipes <em>all</em> persistent storage on the copycat — the paired controller bond <em>and</em> every saved setting (mode, chords, back-paddle map, sensitivity). The copycat reboots to factory defaults and you must <strong>re-pair the controller</strong>. This cannot be undone.</span>
  143. </div>
  144. </div>
  145. <div class="card" id="mouseCard">
  146. <h2>Trackpad mouse (lizard + Xbox)</h2>
  147. <div class="row"><label>Sensitivity</label><input type="range" id="mDiv" min="4" max="200" step="1"><span class="val" id="mDivV"></span></div>
  148. <div class="row"><label>Glide / friction</label><input type="range" id="mFric" min="0" max="99" step="1"><span class="val" id="mFricV"></span></div>
  149. <p class="note">Right-pad cursor in Steam-mode lizard (Steam closed) and in Xbox mode. Sensitivity is a divisor — lower = faster pointer. Glide = how long the cursor coasts after a flick.</p>
  150. </div>
  151. <div class="card">
  152. <h2>Rumble</h2>
  153. <div class="row"><label>Strength</label><input type="range" id="rumble" min="0" max="255" step="5"><span class="val" id="rumbleV"></span></div>
  154. <p class="note">Scales rumble amplitude across all modes (100% = native, 200% = double, 0% = off).</p>
  155. </div>
  156. <div class="card">
  157. <h2>Switch Pro motion</h2>
  158. <div class="row"><label>Report rate</label><select id="swRate"></select></div>
  159. <p class="note" style="margin:0 0 6px">Full rate (~250 Hz, default) is lowest-latency. 120 Hz is low-latency and drift-free. 66 Hz is a genuine-cadence compatibility fallback — drop to it only if your console rejects the faster rates.</p>
  160. <div class="row"><label>Gyro scale</label><select id="swGyro"></select></div>
  161. <p class="note">Gyro sensitivity multiplier for Switch Pro mode (1.0× = unchanged).</p>
  162. </div>
  163. <div class="card">
  164. <h2>Button mapping</h2>
  165. <p class="note" style="margin-top:0">Separate mappings per emulated controller type — each only offers targets that exist on that controller. The type matching the current mode is highlighted. Steam &amp; Lizard are native puck modes (Steam does its own remapping) and aren't configured here.</p>
  166. <div id="typeCfgs"></div>
  167. </div>
  168. <div class="card logonly">
  169. <h2>Capture — host → controller commands</h2>
  170. <p class="note" style="margin-top:0">The firmware logs everything from boot into a big RAM ring: Steam's writes (<code>ifN</code>), the frames we transmit to the controller (<code>TX→ctlr</code>), and RF <code>LINK UP/DOWN</code> edges. For the reconnect buzz: trigger it (it appears moments after the puck boots / the controller reconnects), then connect here and click <b>Dump from boot</b> — the trigger is still in the ring. (Only present in a logging build, <code>-DOPK_LOG=1</code>.)</p>
  171. <div class="row" style="margin:0;flex-wrap:wrap">
  172. <button id="capStart" class="primary">Dump from boot</button>
  173. <button id="capStop" disabled>Stop</button>
  174. <button id="capDl">Download .txt</button>
  175. </div>
  176. <p class="note">Dump streams the whole ring (oldest→newest) and then keeps live-updating until you press Stop. <code>cmd</code> is the command/report byte, then the raw bytes.</p>
  177. <pre id="capOut" style="font:12px ui-monospace,Menlo,monospace;color:var(--fg);background:#0e1017;border:1px solid #232a3a;border-radius:8px;padding:10px;margin-top:10px;max-height:260px;overflow:auto;white-space:pre-wrap"></pre>
  178. </div>
  179. <div id="log"></div>
  180. </div>
  181. </div>
  182. <script>
  183. const MODE_NAMES = ["Steam (puck)","Xbox 360","Switch (HORIPAD)","Lizard (always)","Switch Pro + gyro","PS5 DualSense","HID gyro (DS4)","PS5 (game/clean)","DS4 (game/clean)","PS3 (DualShock 3)"];
  184. const CHORD_FIELD = [17, 18, 19];
  185. let dev=null, epIn=0, epOut=0, ifNum=0, polling=false, capturing=false;
  186. const $ = s=>document.querySelector(s);
  187. function log(m){ const l=$("#log"); l.textContent=(new Date().toLocaleTimeString()+" "+m+"\n"+l.textContent).slice(0,2000); }
  188. // Per-emulated-type config (must match firmware ET_* order: Xbox=0, Switch=1, DS4=2, DS5=3). Each type lists
  189. // only the remap targets that exist on that controller. Field id sent to firmware = 40 + et*8 + k
  190. // (k: 0..3 back paddles, 4 QAM, 5 A/B-swap, 6 trackpad-haptics, 7 LED brightness). Blob v10 reads them back at p[73 + et*8 + ...].
  191. const DPAD = {12:"D-pad Up",13:"D-pad Down",14:"D-pad Left",15:"D-pad Right"};
  192. const TYPE_DEFS = [
  193. {key:"XBOX", name:"Xbox", labels:{1:"A",2:"B",3:"X",4:"Y",5:"LB",6:"RB",7:"L3",8:"R3",9:"Back",10:"Start",11:"Guide",19:"LT",20:"RT",...DPAD}},
  194. {key:"SWITCH", name:"Switch", labels:{1:"A",2:"B",3:"X",4:"Y",5:"L",6:"R",7:"L-Stick",8:"R-Stick",9:"Minus",10:"Plus",11:"Home",19:"ZL",20:"ZR",...DPAD,18:"Capture / Screenshot"}},
  195. {key:"DS4", name:"DS4", labels:{1:"Cross",2:"Circle",3:"Square",4:"Triangle",5:"L1",6:"R1",7:"L3",8:"R3",9:"Create",10:"Options",11:"PS",19:"L2",20:"R2",...DPAD,16:"Touchpad Click"}},
  196. {key:"DS5", name:"DS5", labels:{1:"Cross",2:"Circle",3:"Square",4:"Triangle",5:"L1",6:"R1",7:"L3",8:"R3",9:"Create",10:"Options",11:"PS",19:"L2",20:"R2",...DPAD,16:"Touchpad Click",17:"Mute"}},
  197. ];
  198. // Which emulated type a USB mode belongs to (mirror of firmware etypeForMode); -1 = puck mode (no type).
  199. function etypeForMode(m){ switch(m){case 1:return 0; case 2:case 4:return 1; case 6:case 8:case 9:return 2; case 5:case 7:return 3; default:return -1;} }
  200. const BACK_LABELS = ["L4 (back upper-left)","R4 (back upper-right)","L5 (back lower-left)","R5 (back lower-right)"];
  201. const typeEls = []; // one entry per TYPE_DEFS: {sec, tab, activeDot, back[], qam, abSwap, pad, led, ledV}
  202. function mkSelect(def, includeNone){
  203. const sel=document.createElement("select");
  204. if(includeNone){ const o=document.createElement("option"); o.value=0; o.textContent="— none —"; sel.appendChild(o); }
  205. else { const o=document.createElement("option"); o.value=0; o.textContent="Default (per-mode)"; sel.appendChild(o); }
  206. for(const c of Object.keys(def.labels).map(Number).sort((a,b)=>a-b)){
  207. const o=document.createElement("option"); o.value=c; o.textContent=def.labels[c]; sel.appendChild(o); }
  208. return sel;
  209. }
  210. let curTab=0, tabInited=false;
  211. function setTab(et){
  212. curTab=et;
  213. typeEls.forEach((rec,i)=>{
  214. rec.sec.style.display = (i===et) ? "" : "none";
  215. rec.tab.classList.toggle("active", i===et);
  216. });
  217. }
  218. (function buildTypeCfgs(){
  219. const host=document.getElementById("typeCfgs");
  220. const bar=document.createElement("div"); bar.style.cssText="display:flex;gap:6px;flex-wrap:wrap;margin-bottom:12px";
  221. host.appendChild(bar);
  222. TYPE_DEFS.forEach((def,et)=>{
  223. // tab button
  224. const tab=document.createElement("button"); tab.className="slot-tab"; tab.style.cursor="pointer";
  225. tab.innerHTML='<span>'+def.name+'</span><span class="active-dot" style="display:none;font-size:11px;color:var(--acc)"> ●</span>';
  226. tab.onclick=()=>setTab(et); bar.appendChild(tab);
  227. // panel
  228. const sec=document.createElement("div"); sec.style.cssText="background:#0e1017;border:1px solid #232a3a;border-radius:8px;padding:12px 14px;display:none";
  229. const rec={sec,tab,activeDot:tab.querySelector(".active-dot"),back:[],qam:null,abSwap:null,pad:null,led:null,ledV:null};
  230. // A/B swap + trackpad haptics toggles
  231. const tog=document.createElement("div"); tog.className="row";
  232. tog.innerHTML='<label>A/B + X/Y swap</label>';
  233. const ab=document.createElement("button"); ab.textContent="off"; tog.appendChild(ab);
  234. const padLbl=document.createElement("label"); padLbl.textContent="Trackpad haptics"; padLbl.style.marginLeft="14px"; tog.appendChild(padLbl);
  235. const pad=document.createElement("button"); pad.textContent="on"; tog.appendChild(pad);
  236. sec.appendChild(tog);
  237. rec.abSwap=ab; rec.pad=pad;
  238. ab.onclick=()=>{ const on=ab.classList.contains("active"); setField(40+et*8+5, on?0:1); };
  239. pad.onclick=()=>{ const on=pad.classList.contains("active"); setField(40+et*8+6, on?0:1); };
  240. // back paddles
  241. for(let i=0;i<4;i++){
  242. const row=document.createElement("div"); row.className="row";
  243. const lab=document.createElement("label"); lab.textContent=BACK_LABELS[i]; row.appendChild(lab);
  244. const sel=mkSelect(def,true); row.appendChild(sel); sec.appendChild(row);
  245. sel.addEventListener("change",()=>setField(40+et*8+i, +sel.value));
  246. rec.back.push(sel);
  247. }
  248. // QAM
  249. { const row=document.createElement("div"); row.className="row";
  250. const lab=document.createElement("label"); lab.textContent="QAM (3 dots)"; row.appendChild(lab);
  251. const sel=mkSelect(def,false); row.appendChild(sel); sec.appendChild(row);
  252. sel.addEventListener("change",()=>setField(40+et*8+4, +sel.value));
  253. rec.qam=sel; }
  254. // LED brightness
  255. { const row=document.createElement("div"); row.className="row";
  256. const lab=document.createElement("label"); lab.textContent="LED brightness"; row.appendChild(lab);
  257. const sl=document.createElement("input"); sl.type="range"; sl.min=0; sl.max=100; sl.step=5; row.appendChild(sl);
  258. const vspan=document.createElement("span"); vspan.className="val"; row.appendChild(vspan);
  259. function fmtLed(v){ return (+v===0)?"Auto":v+"%"; }
  260. sl.addEventListener("input",()=>{ vspan.textContent=fmtLed(sl.value); });
  261. sl.addEventListener("change",()=>setField(40+et*8+7, +sl.value));
  262. sec.appendChild(row);
  263. rec.led=sl; rec.ledV=vspan; }
  264. host.appendChild(sec); typeEls.push(rec);
  265. });
  266. setTab(0);
  267. })();
  268. for(const sel of document.querySelectorAll("select.chord")){
  269. MODE_NAMES.forEach((n,i)=>{ if(i===7||i===8) return;
  270. const o=document.createElement("option"); o.value=i; o.textContent=n; sel.appendChild(o); });
  271. }
  272. { const sel=document.getElementById("swRate");
  273. for(const [lbl,v] of [["Full rate (~250 Hz, default)",2],["120 Hz",1],["66 Hz (compatibility)",0]]){
  274. const o=document.createElement("option"); o.value=v; o.textContent=lbl; sel.appendChild(o); }
  275. }
  276. { const sel=document.getElementById("swGyro");
  277. for(const [lbl,v] of [["0.5×",5],["1.0×",10],["1.5×",15],["2.0×",20],["2.5×",25],["3.0×",30]]){
  278. const o=document.createElement("option"); o.value=v; o.textContent=lbl; sel.appendChild(o); }
  279. }
  280. // ---- per-slot tab state ----
  281. let g_activeSlot = 0;
  282. let g_slotData = []; // [{up, battery, rssi}] indexed by slot 0..3, only set for bonded slots
  283. function updateSlotDisplay(slotIdx) {
  284. const d = g_slotData[slotIdx];
  285. if (!d) { $("#stLink").innerHTML="—"; $("#stBatt").textContent="—"; $("#stRssi").textContent="—"; return; }
  286. $("#stLink").innerHTML = d.up ? '<span class="pill up">up</span>' : '<span class="pill dn">down</span>';
  287. $("#stBatt").textContent = (d.up && d.battery) ? d.battery+"%" : "—";
  288. $("#stRssi").textContent = (d.up && d.rssi) ? ("-"+d.rssi+" dBm") : "—";
  289. }
  290. function renderSlotTabs(bondedCount) {
  291. const bar = $("#slotTabs");
  292. if (bondedCount <= 1) { bar.style.display="none"; updateSlotDisplay(g_activeSlot); return; }
  293. bar.style.display="flex";
  294. bar.innerHTML="";
  295. for (let s=0; s<4; s++) {
  296. const d = g_slotData[s];
  297. if (!d) continue;
  298. const btn = document.createElement("button");
  299. btn.className = "slot-tab" + (s===g_activeSlot ? " active" : "");
  300. const dot = document.createElement("span");
  301. dot.className = "dot" + (d.up ? " up" : "");
  302. btn.appendChild(dot);
  303. btn.appendChild(document.createTextNode("Controller "+(s+1)));
  304. btn.onclick = () => { g_activeSlot=s; renderSlotTabs(bondedCount); };
  305. bar.appendChild(btn);
  306. }
  307. updateSlotDisplay(g_activeSlot);
  308. }
  309. async function connect(){
  310. try{
  311. dev = await navigator.usb.requestDevice({filters:[{vendorId:0x28DE},{vendorId:0x045E},{vendorId:0x057E},{vendorId:0x0F0D},{vendorId:0x054C}]});
  312. await dev.open();
  313. if(dev.configuration===null) await dev.selectConfiguration(1);
  314. let found=null;
  315. for(const itf of dev.configuration.interfaces){
  316. const a=itf.alternate;
  317. if(a.interfaceClass!==0xFF) continue;
  318. if(a.interfaceSubClass===0x5D) continue;
  319. let bin=0,bout=0;
  320. for(const e of a.endpoints){ if(e.type==="bulk"){ if(e.direction==="in")bin=e.endpointNumber; else bout=e.endpointNumber; } }
  321. if(bin&&bout){ found={ifNum:itf.interfaceNumber, epIn:bin, epOut:bout}; break; }
  322. }
  323. if(!found){ log("no WebUSB bulk vendor interface — reflash firmware with WebUSB enabled, or another app may be holding the device"); return; }
  324. ifNum=found.ifNum; epIn=found.epIn; epOut=found.epOut;
  325. await dev.claimInterface(ifNum);
  326. await dev.controlTransferOut({requestType:"class", recipient:"interface", request:0x22, value:0x01, index:ifNum});
  327. $("#connState").textContent="connected"; $("#connState").className="pill up";
  328. $("#connectBtn").textContent="Reconnect";
  329. $("#panel").classList.remove("hide");
  330. log(`connected — VID ${dev.vendorId.toString(16)} iface ${ifNum} epIn ${epIn} epOut ${epOut}`);
  331. navigator.usb.addEventListener("disconnect", e=>{ if(e.device===dev){ onGone(); }});
  332. startPolling();
  333. }catch(e){ log("connect failed: "+e.message); }
  334. }
  335. function onGone(){
  336. polling=false; dev=null; tabInited=false; // re-default the config tab to the mode on next connect
  337. $("#connState").textContent="disconnected"; $("#connState").className="pill dn";
  338. $("#panel").classList.add("hide");
  339. log("device disconnected (likely a mode-switch reboot — reconnect)");
  340. }
  341. async function send(bytes){
  342. if(!dev) return;
  343. try{ await dev.transferOut(epOut, new Uint8Array(bytes)); }
  344. catch(e){ log("write err: "+e.message); }
  345. }
  346. async function readBlob(){
  347. try{
  348. // v8 blob is 75 bytes (two USB-FS packets); read 128 to capture both in one call.
  349. const r = await dev.transferIn(epIn, 128);
  350. if(r.status!=="ok"||r.data.byteLength<2) return null;
  351. const d=new Uint8Array(r.data.buffer);
  352. let i=0; while(i<d.length && d[i]!==0xA5) i++;
  353. if(i+2>d.length) return null;
  354. const len=d[i+1]; const p=d.slice(i+2, i+2+len);
  355. return p.length>=12 ? p : null;
  356. }catch(e){ if(dev) log("read err: "+e.message); return null; }
  357. }
  358. function applyBlob(p){
  359. const mode=p[1], mDiv=p[2], mFric=p[3]; // p[4..11] mirror the active type (per-type block below is authoritative)
  360. const slot=p[10], up=p[11], f1=(p[12]|(p[13]<<8));
  361. const newps=(p.length>16?(p[15]|(p[16]<<8)):0), persistMode=(p.length>22?p[22]:0);
  362. const chord=(p.length>25)?[p[23],p[24],p[25]]:[3,1,4];
  363. const polls=(p.length>27?(p[26]|(p[27]<<8)):0);
  364. const loopUs=(p.length>29?(p[28]|(p[29]<<8)):0);
  365. const worstIdx=(p.length>30?p[30]:0), worstUs=(p.length>32?(p[31]|(p[32]<<8)):0);
  366. const WORST=["webusb","ctrl.task","serial","rfdiag","rflink","haptic","led"];
  367. const pollUs=(p.length>34?(p[33]|(p[34]<<8)):0);
  368. const pollIntended=(p.length>14?p[14]*100:0);
  369. const logEnabled=(p.length>35?p[35]:0);
  370. for(const el of document.querySelectorAll(".logonly")) el.style.display = logEnabled ? "" : "none";
  371. for(const b of document.querySelectorAll(".modebtn")) b.classList.toggle("active", +b.dataset.mode===mode);
  372. $("#mouseCard").style.opacity = (mode===1||mode===3)?1:0.5;
  373. const battery=(p.length>36?p[36]:0);
  374. const rumbleScale=(p.length>51?p[51]:200);
  375. const swProRate=(p.length>52?p[52]:2);
  376. const swGyro10=(p.length>53?p[53]:10);
  377. const rssi=(p.length>37?p[37]:0);
  378. // per-slot link status (protocol v8, p.length >= 73)
  379. const hasSlotsData = p.length >= 73;
  380. if (hasSlotsData) {
  381. const bondedN = p[60];
  382. g_slotData = [];
  383. for (let s=0; s<4; s++) {
  384. const base = 61 + s*3;
  385. if (p.length >= base+3) {
  386. // only include bonded slots (a slot with up=0 could be bonded but offline)
  387. // check if the slot appears at all in the bonded map by checking if bondedN covers it;
  388. // the firmware only sets non-zero battery/rssi for actually-bonded slots
  389. const slotUp = !!p[base];
  390. const slotBatt = p[base+1];
  391. const slotRssi = p[base+2];
  392. // slot is "bonded" if firmware included it in bondedN coverage
  393. // we populate slotData for all 4 and renderSlotTabs skips gaps
  394. g_slotData[s] = {up: slotUp, battery: slotBatt, rssi: slotRssi};
  395. }
  396. }
  397. // keep only bonded slots by cross-referencing bondedN
  398. // firmware sends bondedSlotCount but not a slot bitmask; use battery>0 || rssi>0 || up as presence hint
  399. // simpler: just count how many of the 4 slots have any non-zero data OR are marked up
  400. // Actually the firmware always writes all 4 slots; we filter by the bond system's "used" flag via presence.
  401. // For clean display: we'll show tabs only for slots that have ever had a reply OR are bonded (battery/rssi set).
  402. // The firmware sets g_battery[s]=0 and g_linkRssi[s]=0 for unused slots, so 0/0/0 = not bonded.
  403. // But a bonded offline slot also has 0/0/0 initially. We rely on bondedN for count and show the first bondedN slots
  404. // that have g_slot[s].used — but we can't easily know which slots are used from the blob.
  405. // Best heuristic: show all 4 slots if bondedN==4, otherwise use slot indices where battery or rssi != 0 OR up==1,
  406. // OR fall back to showing slots 0..bondedN-1 if none have data yet (device just booted).
  407. let bondedSlots = [];
  408. for (let s=0; s<4; s++) {
  409. if (g_slotData[s] && (g_slotData[s].up || g_slotData[s].battery || g_slotData[s].rssi)) bondedSlots.push(s);
  410. }
  411. // fallback: if no data yet (all offline, just booted), show slots 0..bondedN-1
  412. if (bondedSlots.length === 0 && bondedN > 0) {
  413. for (let s=0; s<bondedN; s++) bondedSlots.push(s);
  414. }
  415. // remove slotData for non-bonded slots so tabs don't appear for them
  416. const bondedSet = new Set(bondedSlots);
  417. for (let s=0; s<4; s++) { if (!bondedSet.has(s)) g_slotData[s] = null; }
  418. // clamp active slot to a valid bonded slot
  419. if (!g_slotData[g_activeSlot]) g_activeSlot = bondedSlots[0] || 0;
  420. renderSlotTabs(bondedN);
  421. } else {
  422. // old firmware: single-slot display
  423. $("#slotTabs").style.display="none";
  424. $("#stLink").innerHTML = up? '<span class="pill up">up</span>' : '<span class="pill dn">down</span>';
  425. $("#stBatt").textContent = (up && battery)? battery+"%" : "—";
  426. $("#stRssi").textContent = (up && rssi)? ("-"+rssi+" dBm") : "—";
  427. }
  428. // global stats
  429. $("#stRate").textContent = up? f1+" /s" : "—";
  430. $("#stNew").textContent = up? newps+" /s" : "—";
  431. // Poll TX + RF-fail counts: shown ALWAYS (even when the link reads down) so a wedge is diagnosable --
  432. // polls>0 here while Delivered is "—" means the puck is still polling but getting no usable replies.
  433. $("#stPolls").textContent = polls+" /s";
  434. { const crc=(p.length>113?p[113]:0), norx=(p.length>114?p[114]:0), heal=(p.length>115?p[115]:0);
  435. $("#stRfFail").textContent = crc+" · "+norx+" · "+heal; }
  436. $("#stLoop").textContent = loopUs? loopUs+" µs" : "—";
  437. $("#stWorst").textContent = loopUs? (WORST[worstIdx]||worstIdx)+" "+worstUs+"µs" : "—";
  438. $("#stPollPer").textContent = up? (pollUs+" / "+pollIntended+" µs") : "—";
  439. // last-boot reset cause (protocol v11): a single classified code (firmware classifies it from RESETREAS +
  440. // a GPREGRET2 marker) plus the raw RESETREAS. Codes match RR_* in fault_diag.h. Earlier firmware (<v11)
  441. // didn't send this -> guard on length and leave the tile blank.
  442. const RR_NAMES = ["unknown","power-on","pin/replug","watchdog (hang)","CPU lockup",
  443. "HARDFAULT","reboot","soft reset","wake-from-off"];
  444. const RR_FAULT = new Set([3,4,5]); // watchdog / lockup / hardfault = a real crash worth reporting (#72)
  445. if (p.length > 109) {
  446. const code = p[105];
  447. const raw = ((p[106]|(p[107]<<8)|(p[108]<<16)|(p[109]<<24))>>>0);
  448. const name = RR_NAMES[code] || ("code "+code);
  449. $("#stReset").innerHTML = RR_FAULT.has(code) ? ('<span class="pill dn">'+name+'</span>') : name;
  450. const el = $("#resetHist");
  451. if (el) el.textContent = "RESETREAS=0x"+raw.toString(16).padStart(8,"0");
  452. }
  453. // Connection tuning: haptic-block enable (p[111]), block seconds (p[112]). (poll RX window p[110] is now
  454. // fixed in firmware and no longer shown.)
  455. const hapBlockOn = (p.length>111?p[111]:0);
  456. $("#hapBlockOn").textContent = hapBlockOn?"on":"off"; $("#hapBlockOn").classList.toggle("active",!!hapBlockOn);
  457. if (p.length>112) setSlider("hapBlockS", p[112]);
  458. const gitDirty=(p.length>38?p[38]:0); let gitHash="";
  459. for(let i=39;i<51 && i<p.length && p[i];i++) gitHash+=String.fromCharCode(p[i]);
  460. $("#stBuild").innerHTML = gitHash
  461. ? (gitHash + (gitDirty ? ' <span class="pill dn">dirty</span>' : ' <span class="pill up">clean</span>'))
  462. : "—";
  463. setSlider("mDiv",mDiv); setSlider("mFric",mFric); setSlider("rumble",rumbleScale);
  464. $("#persistMode").textContent = persistMode? "on":"off"; $("#persistMode").classList.toggle("active",!!persistMode);
  465. // per-type button config (blob v10): 4 types x 8 bytes. readBlob() strips the 2-byte [0xA5][len] header, so
  466. // the firmware's buffer index 75 lands at JS index 73 here.
  467. if(p.length>=73+TYPE_DEFS.length*8){
  468. const activeEt=etypeForMode(mode);
  469. typeEls.forEach((rec,et)=>{
  470. const q=73+et*8;
  471. const back=[p[q],p[q+1],p[q+2],p[q+3]], qam=p[q+4], ab=p[q+5], pad=p[q+6], led=p[q+7];
  472. rec.back.forEach((sel,i)=>{ if(document.activeElement!==sel) sel.value=back[i]; });
  473. if(document.activeElement!==rec.qam) rec.qam.value=qam;
  474. rec.abSwap.textContent=ab?"on":"off"; rec.abSwap.classList.toggle("active",!!ab);
  475. rec.pad.textContent=pad?"on":"off"; rec.pad.classList.toggle("active",!!pad);
  476. if(document.activeElement!==rec.led){ rec.led.value=led; rec.ledV.textContent=(led===0)?"Auto":led+"%"; }
  477. // dot marks the type matching the current puck mode
  478. rec.activeDot.style.display = (et===activeEt) ? "" : "none";
  479. });
  480. // open the tab for the current mode's type on first load (then leave the user's choice alone)
  481. if(!tabInited){ tabInited=true; setTab(activeEt>=0?activeEt:0); }
  482. }
  483. if(p.length>=60){ const s16=(o)=>{ let v=p[o]|(p[o+1]<<8); return v>32767?v-65536:v; };
  484. const ax=s16(54),ay=s16(56),az=s16(58);
  485. const amag=Math.round(Math.sqrt(ax*ax+ay*ay+az*az));
  486. $("#stImu").textContent = `a=(${ax}, ${ay}, ${az}) |a|=${amag}`;
  487. }
  488. { const sel=$("#swRate"); if(document.activeElement!==sel) sel.value=swProRate; }
  489. { const sel=$("#swGyro"); if(document.activeElement!==sel) sel.value=swGyro10; }
  490. for(const sel of document.querySelectorAll("select.chord")){ if(document.activeElement!==sel) sel.value=chord[+sel.dataset.i]; }
  491. }
  492. function fmtSlider(id,v){ return id==="rumble" ? v+"%" : id==="hapBlockS" ? v+" s" : ""+v; }
  493. function setSlider(id,v){ const el=$("#"+id); if(document.activeElement!==el){ el.value=v; } $("#"+id+"V").textContent=fmtSlider(id,el.value); }
  494. let inflight=false;
  495. async function refresh(){
  496. if(!dev||inflight||capturing) return; inflight=true;
  497. await send([0x01]); const p=await readBlob(); if(p) applyBlob(p);
  498. inflight=false;
  499. }
  500. async function setField(field,value){
  501. await send([0x02, field, value&0xff]); const p=await readBlob(); if(p) applyBlob(p);
  502. }
  503. function fmtCapEntry(e,maxMs){
  504. const hex=e.bytes.map(x=>x.toString(16).padStart(2,"0")).join(" ");
  505. const t = `-${String(maxMs-e.ms).padStart(6," ")}ms `;
  506. if(e.slot===0xFD){ const k=e.bytes[0]; return `${t}════════ ${k===2?"RECONNECT (block+reinit armed)":k===1?"RF LINK UP":"RF LINK DOWN"} ════════`; }
  507. if(e.slot===0xFC){ return `${t}GET←host rid=${e.rid.toString(16).padStart(2,"0")} n=${e.nb}: ${hex}`; } // host feature GET (battery poll lives here)
  508. if(e.slot===0xFB){ return `${t}→host rid=${e.rid.toString(16).padStart(2,"0")} n=${e.nb}: ${hex}`; } // pushed device→host status (0x43 battery / 0x7B / 0x79)
  509. const who = (e.slot===0xFE) ? "TX→ctlr " : `if${e.slot} `;
  510. return `${t}${who} cmd=${e.rid.toString(16).padStart(2,"0")} n=${e.nb}: ${hex}`;
  511. }
  512. function downloadCap(){
  513. const t=window._lastCap||$("#capOut").textContent||"";
  514. const a=document.createElement("a");
  515. a.href=URL.createObjectURL(new Blob([t],{type:"text/plain"}));
  516. a.download="puck-capture.txt"; a.click();
  517. }
  518. let liveTimer=null, draining=false, capLines=[];
  519. function renderCap(){
  520. if(!capLines.length){ $("#capOut").textContent="(nothing captured yet)"; window._lastCap=""; return; }
  521. const maxMs=capLines[capLines.length-1].ms;
  522. const t=capLines.map(e=>fmtCapEntry(e,maxMs)).join("\n");
  523. $("#capOut").textContent=t; window._lastCap=t;
  524. }
  525. async function drainTick(){
  526. if(!dev||draining) return; draining=true;
  527. let acc=new Uint8Array(0);
  528. try{
  529. await send([0x06]);
  530. let done=false, guard=0;
  531. while(!done && guard++<400){
  532. const r=await dev.transferIn(epIn,64);
  533. if(r.status!=="ok") break;
  534. const d=new Uint8Array(r.data.buffer);
  535. const m=new Uint8Array(acc.length+d.length); m.set(acc); m.set(d,acc.length); acc=m;
  536. let i=0;
  537. while(i<acc.length){
  538. if(acc[i]!==0xA6){ i++; continue; }
  539. if(i+2>acc.length) break;
  540. const L=acc[i+1]; if(i+2+L>acc.length) break;
  541. const f=acc.slice(i+2,i+2+L); i+=2+L;
  542. if(f[0]===0){ done=true; break; }
  543. if(f[0]===1 && L>=8){
  544. const ms=((f[1])|(f[2]<<8)|(f[3]<<16)|(f[4]<<24))>>>0;
  545. capLines.push({ms, slot:f[5], rid:f[6], nb:f[7], bytes:[...f.slice(8,8+f[7])]});
  546. }
  547. }
  548. acc=acc.slice(i);
  549. }
  550. }catch(e){ log("drain err: "+e.message); }
  551. draining=false;
  552. if(liveTimer){ const el=$("#capOut"); const atBottom=el.scrollTop+el.clientHeight>=el.scrollHeight-4; renderCap(); if(atBottom) el.scrollTop=el.scrollHeight; }
  553. }
  554. async function startCapture(){
  555. if(!dev||capturing) return;
  556. capturing=true; capLines=[];
  557. $("#capOut").textContent="(dumping ring from boot, then live — press Stop when done)";
  558. $("#capStart").disabled=true; $("#capStop").disabled=false;
  559. await send([0x05,1]);
  560. liveTimer=setInterval(drainTick,100);
  561. }
  562. async function stopCapture(){
  563. if(liveTimer){ clearInterval(liveTimer); liveTimer=null; }
  564. await drainTick();
  565. try{ await send([0x05,0]); }catch(e){}
  566. capturing=false;
  567. $("#capStart").disabled=false; $("#capStop").disabled=true;
  568. renderCap(); log(`capture stopped — ${capLines.length} entries`);
  569. }
  570. async function startPolling(){
  571. polling=true; await refresh();
  572. while(polling && dev){ await new Promise(r=>setTimeout(r,600)); await refresh(); }
  573. }
  574. // UI wiring
  575. $("#connectBtn").onclick=connect;
  576. $("#capDl").onclick=downloadCap;
  577. $("#capStart").onclick=startCapture;
  578. $("#capStop").onclick=stopCapture;
  579. $("#hapClear").onclick=async()=>{ if(dev){ await send([0x07]); log("haptic re-init sent (clear stuck buzz)"); } };
  580. $("#ctlrOff").onclick=async()=>{ if(dev){ await send([0x08]); log("controller power-off attempt sent — watch link status"); } };
  581. $("#dfuSerial").onclick=async()=>{
  582. if(!dev){ log("not connected"); return; }
  583. if(!confirm("Reboot into serial DFU?\n\nThe puck will disconnect immediately. Flash with adafruit-nrfutil, then replug.")) return;
  584. await send([0x0B]); log("serial DFU reboot sent — device disconnecting");
  585. };
  586. $("#dfuUf2").onclick=async()=>{
  587. if(!dev){ log("not connected"); return; }
  588. if(!confirm("Reboot into UF2 bootloader?\n\nThe puck will disconnect and mount as a USB drive. Drag the .uf2 file onto it to flash.")) return;
  589. await send([0x0C]); log("UF2 bootloader reboot sent — device disconnecting");
  590. };
  591. $("#factoryErase").onclick=async()=>{
  592. if(!dev){ log("not connected"); return; }
  593. if(!confirm("Factory erase?\n\nThis wipes ALL persistent storage on the copycat:\n • the paired-controller bond (you'll have to re-pair)\n • every saved setting (mode, chords, back paddles, sensitivity)\n\nThe copycat reboots to factory defaults. This CANNOT be undone.")) return;
  594. if(!confirm("Are you absolutely sure?\n\nThere is no recovery. The controller bond and all settings will be gone.")) return;
  595. const typed=prompt('Final confirmation — type ERASE (all caps) to wipe everything:');
  596. if(typed!=="ERASE"){ log("factory erase cancelled (confirmation text did not match)"); return; }
  597. await send([0x0A,0x45,0x52,0x53]);
  598. log("FACTORY ERASE sent — copycat is reformatting and rebooting to defaults. Re-pair the controller, then reconnect.");
  599. };
  600. $("#persistMode").onclick=()=>{ const on=$("#persistMode").classList.contains("active"); setField(16, on?0:1); };
  601. // Connection tuning: post-connect haptic block on (field 27) + seconds (field 28). (poll RX window is fixed.)
  602. $("#hapBlockOn").onclick=()=>{ const on=$("#hapBlockOn").classList.contains("active"); setField(27, on?0:1); };
  603. for(const id of ["mDiv","mFric","rumble","hapBlockS"]){
  604. const field={mDiv:1,mFric:2,rumble:22,hapBlockS:28}[id];
  605. $("#"+id).addEventListener("input", ()=>{ $("#"+id+"V").textContent=fmtSlider(id,$("#"+id).value); });
  606. $("#"+id).addEventListener("change", ()=>setField(field, +$("#"+id).value));
  607. }
  608. // per-type back/QAM/A-B-swap/haptics handlers are wired in buildTypeCfgs()
  609. $("#swRate").addEventListener("change", ()=>setField(23, +$("#swRate").value));
  610. $("#swGyro").addEventListener("change", ()=>setField(24, +$("#swGyro").value));
  611. for(const sel of document.querySelectorAll("select.chord")){
  612. sel.addEventListener("change", ()=>setField(CHORD_FIELD[+sel.dataset.i], +sel.value));
  613. }
  614. for(const b of document.querySelectorAll(".modebtn")){
  615. b.onclick=()=>{ const m=+b.dataset.mode;
  616. const clean=(m===7||m===8||m===9);
  617. const msg="Switch to "+MODE_NAMES[m]+"? The copycat will reboot."+(clean?"\n\nNOTE: the game/clean PlayStation modes (and PS3) drop WebUSB + host-wake, so THIS PANEL WILL DISCONNECT and can't reach the device while it's in this mode. To get back, chord on the controller: hold back-paddle 4 + A to return to Steam mode.":"");
  618. if(confirm(msg)){ send([0x03, m]); log("mode switch requested — device will reboot"); } };
  619. }
  620. if(!("usb" in navigator)) $("#connectBtn").outerHTML='<b style="color:var(--bad)">WebUSB not supported — use Chrome or Edge.</b>';
  621. </script>
  622. </body>
  623. </html>