serial_console.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. #include "serial_console.h"
  2. #include "radio.h"
  3. #include "rf_diag.h"
  4. #include "rf_link.h"
  5. #include "haptics.h"
  6. #include "bonds.h"
  7. #include "config.h"
  8. #include "puck_hid.h" // g_cmdCapture (feature-command capture toggle)
  9. #include "fault_diag.h"
  10. #include "usb_mount.h" // modeSwitchReboot()
  11. #include <Adafruit_TinyUSB.h>
  12. #include <Arduino.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. // CDC commands: l=listen, s=stop, cN=channel, p<hex>=prefix, a<8hex>=base addr, b=bonds, etc.
  16. // Command order matters: else-if chain, FIRST matching letter wins. 'C' and 'H' appear twice; the second
  17. // occurrence is unreachable.
  18. void serialConsolePoll()
  19. {
  20. static char line[24];
  21. static uint8_t li = 0;
  22. while (Serial.available()) {
  23. char c = Serial.read();
  24. if (c == '\n' || c == '\r') {
  25. line[li] = 0;
  26. // FULL factory wipe -- requires the exact word "ERASE-ALL" so it can't be fat-fingered. Reformats the
  27. // internal FS (cfg.bin + bonds.bin gone), reboots into clean defaults; controller must be re-paired.
  28. if (!strcmp(line, "ERASE-ALL")) {
  29. Serial.println(
  30. "# ERASING ALL persistent storage (config + bonds)...");
  31. factoryErase();
  32. Serial.println(
  33. "# done -- rebooting into clean defaults; re-pair the controller");
  34. delay(40);
  35. faultDiagArmIntentionalReset();
  36. NVIC_SystemReset();
  37. } else if (!strcmp(line, "AMP")) {
  38. // A/B: land Steam's amp/haptic 0x87 config (0x18/0x2E/0x34/0x35) so haptics play as ticks
  39. g_landAmp = !g_landAmp;
  40. Serial.printf(
  41. "# land amp/haptic 0x87 config %s\n",
  42. g_landAmp ? "ON" : "off");
  43. } else if (!strcmp(line, "CD")) {
  44. // A/B: content dedup on the Steam input forward (drop reports whose body minus the
  45. // free-running counter is unchanged) -- caps delivered rate at the controller's real
  46. // distinct-report rate instead of the poll rate.
  47. g_fwdContentDedup = !g_fwdContentDedup;
  48. Serial.printf("# content dedup %s\n",
  49. g_fwdContentDedup ? "ON" : "off");
  50. } else if (!strcmp(line, "SS")) {
  51. // on-demand smoothness snapshot: print the last-second cached rates in ONE line, NOW,
  52. // instead of waiting for the guarded 1 Hz "# stat" (which the I45/FC flood starves during
  53. // a drag). new/s = the FRESH-delivered rate (what Steam receives); noRx = RF packet loss.
  54. Serial.printf(
  55. "# SS pollrate=%luHz polls=%u/s F1=%u/s new=%u/s crc=%u noRx=%u slot%d\n",
  56. (unsigned long)(1000000UL / g_pollUs),
  57. g_pollsps, g_f1ps, g_newps, g_crcps,
  58. g_norxps, g_curSlot);
  59. } else if (!strncmp(line, "PR", 2) &&
  60. (line[2] >= '0' && line[2] <= '9')) {
  61. // live poll-rate sweep: "PR<hz>" sets the RF poll cadence (session-only, not persisted).
  62. // Clamped 100..1000 Hz. Watch the delivered report rate / feel to find the sweet spot.
  63. long hz = atol(line + 2);
  64. if (hz < 100)
  65. hz = 100;
  66. else if (hz > 1000)
  67. hz = 1000;
  68. g_pollUs = (uint32_t)(1000000L / hz);
  69. Serial.printf(
  70. "# poll rate -> %ld Hz (%lu us)\n", hz,
  71. (unsigned long)g_pollUs);
  72. } else if (!strcmp(line, "HR")) {
  73. // A/B: disable the puck->controller haptic relay (Steam 0x80-0x86 rumble/pad feedback)
  74. // to isolate whether relaying Steam's trackpad texture haptics degrades drag smoothness.
  75. g_hapticRelay = !g_hapticRelay;
  76. Serial.printf(
  77. "# haptic relay (Steam 0x80-0x86) %s\n",
  78. g_hapticRelay ? "ON" : "off");
  79. } else if (!strcmp(line, "S81")) {
  80. // A/B: drop Steam's relayed FEATURE cmd 0x81 CLEAR_DIGITAL_MAPPINGS (the connect
  81. // amp-clicker). Does NOT touch OUTPUT report 0x81 = HAPTIC_PULSE (always relayed).
  82. g_drop81 = !g_drop81;
  83. Serial.printf(
  84. "# drop relayed feature 0x81 (Steam mode) %s\n",
  85. g_drop81 ? "ON" : "off");
  86. } else if (!strcmp(line, "FC")) {
  87. // feature-command capture: log Steam's USB SET/GET commands to serial + suppress I45
  88. g_cmdCapture = !g_cmdCapture;
  89. Serial.printf(
  90. "# feature-cmd capture %s (I45 %s)\n",
  91. g_cmdCapture ? "ON" : "off",
  92. g_cmdCapture ? "suppressed" : "on");
  93. } else if (!strcmp(line, "L87")) {
  94. // EXPERIMENT: land all relayed 0x87 config verbatim (real-puck relay) vs the discard-whitelist.
  95. // Exact-match string (single letters are all taken; 'l' alone = rfListenStart).
  96. g_landAll87 = !g_landAll87;
  97. saveCfg();
  98. Serial.printf(
  99. "# land-all-0x87 (verbatim 0x87 relay) %s\n",
  100. g_landAll87 ? "ON" : "off");
  101. } else if (!strcmp(line, "FR")) {
  102. // re-dump the flight recorder trail captured before the last watchdog hang (also printed
  103. // automatically at boot, but CDC may not be attached yet then -- this reprints on demand).
  104. faultDiagDumpFlight();
  105. } else if (!strcmp(line, "VIT")) {
  106. // toggle the live per-second CDC vitals line (loop rate / usbd stack / heap / relay trend)
  107. g_vitals = !g_vitals;
  108. Serial.printf("# live vitals line %s\n",
  109. g_vitals ? "ON" : "off");
  110. } else if (line[0] == 'l')
  111. rfListenStart();
  112. else if (line[0] == 'B') {
  113. g_rfBeacon = !g_rfBeacon;
  114. g_rfListen = false;
  115. Serial.printf("# beacon %s ch%u\n",
  116. g_rfBeacon ? "ON" : "off",
  117. g_rfCh);
  118. } else if (line[0] == 'L') {
  119. g_plen = strtol(line + 1, 0, 16);
  120. Serial.printf("# plen=%02X\n", g_plen);
  121. } else if (line[0] == '1') {
  122. g_s1incl = !g_s1incl;
  123. Serial.printf("# s1incl=%u\n", g_s1incl);
  124. } else if (line[0] == 'R') {
  125. g_rfCh = atoi(line + 1);
  126. g_rfRaw = true;
  127. g_rfListen = false;
  128. g_rfBeacon = false;
  129. rfRawStart(g_rfCh);
  130. Serial.printf("# raw cap ch%u\n", g_rfCh);
  131. } else if (line[0] == 'Z') {
  132. g_rfRaw = true;
  133. g_rfSweep = true;
  134. g_rfListen = false;
  135. g_rfBeacon = false;
  136. g_rfCh = 2;
  137. rfRawStart(g_rfCh);
  138. Serial.println("# raw SWEEP");
  139. } else if (line[0] == 'H') {
  140. g_rfHost = !g_rfHost;
  141. g_rfBeacon = false;
  142. g_rfListen = false;
  143. g_rfRaw = false;
  144. g_rfSweep = false;
  145. g_rfCh = 2;
  146. Serial.printf(
  147. "# HOSTFRAME beacon %s base %02X%02X%02X%02X (slot0 uuids %02X%02X%02X%02X/%02X%02X%02X%02X)\n",
  148. g_rfHost ? "ON" : "off", g_rfBase[0],
  149. g_rfBase[1], g_rfBase[2], g_rfBase[3],
  150. g_slot[0].rec[0], g_slot[0].rec[1],
  151. g_slot[0].rec[2], g_slot[0].rec[3],
  152. g_slot[0].rec[4], g_slot[0].rec[5],
  153. g_slot[0].rec[6], g_slot[0].rec[7]);
  154. } else if (line[0] == 'C') {
  155. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  156. g_rfHost = false;
  157. rfRespondStart();
  158. } else if (line[0] == 's') {
  159. g_rfListen = false;
  160. g_rfBeacon = false;
  161. g_rfRaw = false;
  162. g_rfSweep = false;
  163. g_rfHost = false;
  164. g_rfRespond = false;
  165. NRF_RADIO->TASKS_DISABLE = 1;
  166. Serial.println("# RF off");
  167. } else if (line[0] == 'u') {
  168. // id9=0 hold (MODE_STEAM only) A/B toggle (persisted; see haptics.h LIZKEEP_MS)
  169. g_lizKeep = !g_lizKeep;
  170. saveCfg();
  171. Serial.printf(
  172. "# id9=0 hold (Steam mode, /%ums) %s\n",
  173. (unsigned)LIZKEEP_MS,
  174. g_lizKeep ? "ON" : "off");
  175. }
  176. // switch USB mode: 0=steam 1=xbox 2=hori 3=lizard 4=swpro 5=ps5 6=hidgyro 7=ps5-game/clean 8=ds4-game/clean 9=ps3(dualshock3)
  177. else if (line[0] == 'x') {
  178. uint8_t m = strtoul(line + 1, 0, 10);
  179. if (modeValid(m)) {
  180. if (USBDevice.suspended()) {
  181. Serial.println(
  182. "# mode change blocked: host suspended");
  183. } else {
  184. Serial.printf(
  185. "# switch mode %u (reboot)\n",
  186. m);
  187. delay(20);
  188. // clean detach + reboot (releases held input on the outgoing device)
  189. modeSwitchReboot(m);
  190. }
  191. }
  192. } else if (line[0] == 'c') {
  193. g_rfCh = atoi(line + 1);
  194. Serial.printf("# ch=%u\n", g_rfCh);
  195. if (g_rfListen)
  196. rfListenStart();
  197. } else if (line[0] == 'p') {
  198. g_rfPrefix = strtol(line + 1, 0, 16);
  199. Serial.printf("# prefix=%02X\n", g_rfPrefix);
  200. if (g_rfListen)
  201. rfListenStart();
  202. } else if (line[0] == 'i') {
  203. g_crcinit = strtoul(line + 1, 0, 16);
  204. Serial.printf("# crcinit=%06lX\n",
  205. (unsigned long)g_crcinit);
  206. } else if (line[0] == 'w') {
  207. g_whiteiv = atoi(line + 1);
  208. Serial.printf("# whiteiv=%u\n", g_whiteiv);
  209. } else if (line[0] == '0') {
  210. g_pcnf0 = strtoul(line + 1, 0, 16);
  211. Serial.printf("# pcnf0=%08lX\n",
  212. (unsigned long)g_pcnf0);
  213. } else if (line[0] == '2') {
  214. g_pcnf1 = strtoul(line + 1, 0, 16);
  215. Serial.printf("# pcnf1=%08lX\n",
  216. (unsigned long)g_pcnf1);
  217. } else if (line[0] == 'M') {
  218. g_mode = strtoul(line + 1, 0, 16);
  219. Serial.printf(
  220. "# mode=%u (3=Ble1M,4=Ble2M,0/2=Nrf)\n",
  221. g_mode);
  222. } else if (line[0] == 'I') {
  223. g_crcinit = strtoul(line + 1, 0, 16);
  224. Serial.printf("# crcinit=%08lX\n",
  225. (unsigned long)g_crcinit);
  226. } else if (line[0] == 'P') {
  227. g_crcpoly = strtoul(line + 1, 0, 16);
  228. Serial.printf("# crcpoly=%lX\n",
  229. (unsigned long)g_crcpoly);
  230. } else if (line[0] == 'N') {
  231. g_crccnf = strtoul(line + 1, 0, 16);
  232. Serial.printf("# crccnf=%X\n", g_crccnf);
  233. } else if (line[0] == 'Y') {
  234. g_rfCap = true;
  235. g_rfCapOne = true;
  236. g_rfReplay = g_rfHost = g_rfAuto = false;
  237. g_rfCh = 2;
  238. rfCapStart(2);
  239. Serial.println(
  240. "# capture ONE frame for replay...");
  241. } else if (line[0] == 'y') {
  242. g_rfReplay = !g_rfReplay;
  243. g_rfCap = g_rfHost = g_rfAuto = false;
  244. Serial.printf("# REPLAY %s (%uB)\n",
  245. g_rfReplay ? "ON" : "off",
  246. g_replayLen);
  247. } else if (line[0] == 'T') {
  248. g_statlen = strtoul(line + 1, 0, 16);
  249. g_pcnf1 = 0;
  250. Serial.printf("# statlen=%02X\n", g_statlen);
  251. } else if (line[0] == 'k') {
  252. g_connOn = !g_connOn;
  253. if (g_connOn) {
  254. g_connSt = 0;
  255. g_connStep = 0;
  256. g_connPoll = 0;
  257. g_connF1 = 0;
  258. }
  259. Serial.printf(
  260. "# CONN mode %s: %s%s poll on ch%u (param=%02X). F1 seen=%lu\n",
  261. g_connOn ? "ON" : "off",
  262. g_e7announce ? "E7-awake[00 00] -> " :
  263. "",
  264. g_pollGet ? "E3+GET-report-0x45" :
  265. "bare E3",
  266. g_rfCh, g_getParam,
  267. (unsigned long)g_connF1);
  268. } else if (line[0] == 'q') {
  269. g_getParam = g_getParam ? 0x00 : 0x2D;
  270. Serial.printf("# GET-0x45 param=%02X\n",
  271. g_getParam);
  272. } else if (line[0] == 'v') {
  273. g_connVerbose = !g_connVerbose;
  274. Serial.printf(
  275. "# conn verbose %s (F1 seen=%lu)\n",
  276. g_connVerbose ? "ON" : "off",
  277. (unsigned long)g_connF1);
  278. } else if (line[0] == 'C') {
  279. g_sessCh = strtoul(line + 1, 0, 10);
  280. Serial.printf(
  281. "# session channel=%u (re-pair/reconnect to apply)\n",
  282. g_sessCh);
  283. } else if (line[0] == 'E') {
  284. g_mDiv = strtoul(line + 1, 0, 10);
  285. if (g_mDiv < 4)
  286. g_mDiv = 4;
  287. saveCfg();
  288. Serial.printf(
  289. "# xbox-mouse sensitivity divisor=%d (lower=faster)\n",
  290. g_mDiv);
  291. } else if (line[0] == 'F') {
  292. g_mFric = strtoul(line + 1, 0, 10);
  293. if (g_mFric > 99)
  294. g_mFric = 99;
  295. saveCfg();
  296. Serial.printf(
  297. "# xbox-mouse friction=%d%% (higher=more glide/momentum)\n",
  298. g_mFric);
  299. } else if (line[0] == 'W') {
  300. // A/B swap edits the ACTIVE emulated type (Xbox/Switch/DS4/DS5); puck modes have none.
  301. if (g_etype < ET_COUNT) {
  302. g_type[g_etype].abSwap =
  303. !g_type[g_etype].abSwap;
  304. applyActiveType();
  305. saveCfg();
  306. Serial.printf(
  307. "# A/B + X/Y swap %s (Nintendo layout) [type %u]\n",
  308. g_abSwap ? "ON" : "off",
  309. g_etype);
  310. } else
  311. Serial.println(
  312. "# A/B swap N/A in this mode (Steam/Lizard are not emulated types)");
  313. } else if (line[0] == 'K') {
  314. int i = line[1] - '0';
  315. uint8_t code = strtoul(line + 2, 0, 10);
  316. // back paddles edit the ACTIVE emulated type. code 18 = Capture/Screenshot (Switch only).
  317. if (i >= 0 && i < 4 && g_etype < ET_COUNT) {
  318. g_type[g_etype].back[i] = code;
  319. applyActiveType();
  320. saveCfg();
  321. Serial.printf(
  322. "# back[%d] (%s) -> code %u [type %u] [0=none 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n",
  323. i,
  324. (const char *[]){ "L4", "R4",
  325. "L5",
  326. "R5" }[i],
  327. code, g_etype);
  328. } else if (g_etype >= ET_COUNT)
  329. Serial.println(
  330. "# back map N/A in this mode (Steam/Lizard are not emulated types)");
  331. else
  332. Serial.println(
  333. "# usage: K<0-3> <code> (0=L4 1=R4 2=L5 3=R5)");
  334. } else if (line[0] == 'Q') {
  335. uint8_t code = strtoul(line + 1, 0, 10);
  336. if (g_etype < ET_COUNT) {
  337. g_type[g_etype].qamMap = code;
  338. applyActiveType();
  339. saveCfg();
  340. Serial.printf(
  341. "# QAM -> code %u [type %u] [0=default 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n",
  342. code, g_etype);
  343. } else
  344. Serial.println(
  345. "# QAM map N/A in this mode (Steam/Lizard are not emulated types)");
  346. } else if (line[0] == 'J') {
  347. char *sp = 0;
  348. uint8_t id = strtoul(line + 1, &sp, 0);
  349. // inject SET-SETTINGS to controller: report 0x87 [id][val u16 LE]
  350. uint16_t val = sp ? strtoul(sp, 0, 0) : 0;
  351. uint8_t pl[3] = { id, (uint8_t)(val & 0xFF),
  352. (uint8_t)(val >> 8) };
  353. // console-injected writes go to all connected controllers (no specific slot in scope)
  354. relayEnqueue(0x87, pl, 3, 0xFF);
  355. Serial.printf(
  356. "# queued SET-SETTINGS id=0x%02X val=%u (relay 0x87) — watch new=/s\n",
  357. id, val);
  358. } else if (line[0] == 'G') {
  359. g_sniff = !g_sniff;
  360. g_sniffPh = 0;
  361. g_rfHost = g_connOn = g_rfCap = g_rfAuto =
  362. g_rfReplay = false;
  363. if (g_sniff)
  364. rfSniffStart();
  365. Serial.printf(
  366. "# SESSION SNIFF %s (phase0: catch host frame on ibex/ch2; phase1 PARK ch=%s)\n",
  367. g_sniff ? "ON" : "off",
  368. g_sniffPark ? "override" : "primary");
  369. } else if (line[0] == 'g') {
  370. g_sniffPark = strtoul(line + 1, 0, 10);
  371. if (g_sniffPh == 1)
  372. rfSniffStart();
  373. Serial.printf(
  374. "# sniff park channel=%u (0=learned primary)\n",
  375. g_sniffPark);
  376. } else if (line[0] == 'V') {
  377. g_e7b = strtoul(line + 1, 0, 10);
  378. Serial.printf(
  379. "# E7 protocol-version B-byte=%u (0=awake/slow, 1=try v1-fast; watch new=/s; revert if input stops)\n",
  380. g_e7b);
  381. } else if (line[0] == 'O') {
  382. g_relayOp = strtoul(line + 1, 0, 16);
  383. Serial.printf("# relay opcode=%02X\n",
  384. g_relayOp);
  385. } else if (line[0] == 'o') {
  386. g_relaySub = strtoul(line + 1, 0, 16);
  387. Serial.printf("# relay sub-type=%02X\n",
  388. g_relaySub);
  389. } else if (line[0] == 'h') {
  390. uint8_t nc = strtoul(line + 1, 0, 10);
  391. Serial.printf(
  392. "# HOP %u->%u (advertise on current ch, then poll new). Watch F1=/s\n",
  393. g_sessCh, nc);
  394. rfHopTo(nc);
  395. } else if (line[0] == 'z') {
  396. g_qos = !g_qos;
  397. g_hopIdx = 0;
  398. g_qosBad = 0;
  399. g_qosCheckMs = millis();
  400. Serial.printf(
  401. "# QoS adaptive channel hopping %s (candidates 18,46,76,22,68)\n",
  402. g_qos ? "ON" : "off");
  403. } else if (line[0] == 'U') {
  404. // Per-slot debug dump: which controllers are connected, their RSSI, haptic-block
  405. // state, and session address. Quick at-a-glance view for multi-controller testing.
  406. Serial.printf("# session ch%u, curSlot=%d\n",
  407. g_sessCh, g_curSlot);
  408. for (int s = 0; s < NSLOT; s++) {
  409. bool live = g_slot[s].used &&
  410. g_connReplyMs[s] != 0;
  411. unsigned long age =
  412. live ? (unsigned long)(millis() -
  413. g_connReplyMs
  414. [s]) :
  415. 0;
  416. int rssi =
  417. g_linkRssi[s] ?
  418. (int)g_linkRssi[s] -
  419. RSSI_DBM_OFFSET :
  420. 0;
  421. unsigned long now_ms = millis();
  422. unsigned long blk =
  423. (g_hapticBlockUntil[s] &&
  424. (int32_t)(g_hapticBlockUntil[s] -
  425. now_ms) > 0) ?
  426. (g_hapticBlockUntil[s] -
  427. now_ms) :
  428. 0;
  429. Serial.printf(
  430. "# slot %d: %s addr %02X%02X%02X%02X/%02X rssi=%ddBm conn=%lums ago batt=%u%% haptic-block=%lums uuid %02X%02X%02X%02X %02X%02X%02X%02X\n",
  431. s,
  432. g_slot[s].used ?
  433. (live ? "LIVE" :
  434. "BONDED") :
  435. "empty",
  436. g_sessBase[s][0],
  437. g_sessBase[s][1],
  438. g_sessBase[s][2],
  439. g_sessBase[s][3],
  440. g_sessPrefix[s], rssi, age,
  441. g_battery[s], blk,
  442. g_slot[s].rec[0],
  443. g_slot[s].rec[1],
  444. g_slot[s].rec[2],
  445. g_slot[s].rec[3],
  446. g_slot[s].rec[4],
  447. g_slot[s].rec[5],
  448. g_slot[s].rec[6],
  449. g_slot[s].rec[7]);
  450. }
  451. } else if (line[0] == 'r') {
  452. // poll RX-window is FIXED (not configurable) -- report only.
  453. Serial.printf(
  454. "# poll RX-window=%lu us (FIXED; poll rate caps ~%lu/s)\n",
  455. (unsigned long)g_rxWin,
  456. (unsigned long)(1000000 / g_rxWin));
  457. } else if (line[0] == 'e') {
  458. g_e3mode = strtoul(line + 1, 0, 10);
  459. Serial.printf(
  460. "# E3 poll PID mode=%u (0=fixed07, 1=cyclePID+noack1, 2=cyclePID+noack0) - watch new=/s\n",
  461. g_e3mode);
  462. } else if (line[0] == 'd') {
  463. g_pollGet = !g_pollGet;
  464. Serial.printf(
  465. "# poll = %s (real puck sends BARE E3) - watch F1=/s new=/s\n",
  466. g_pollGet ?
  467. "E3 + GET-report-0x45 TLV (legacy)" :
  468. "bare E3");
  469. } else if (line[0] == 'n') {
  470. g_e7announce = !g_e7announce;
  471. Serial.printf(
  472. "# E7 awake-announce %s (real puck never sends E7) - watch F1=/s\n",
  473. g_e7announce ? "ON (legacy)" : "off");
  474. } else if (line[0] == 'm') {
  475. g_e1keepalive = !g_e1keepalive;
  476. Serial.printf(
  477. "# session-channel E1 keepalive %s (real puck sends none; needed for shared addr) - watch F1=/s\n",
  478. g_e1keepalive ? "ON" : "off");
  479. } else if (line[0] == 't') {
  480. // inject n test haptics (output 0x82 [01 01 F7]) over the relay
  481. uint8_t n = line[1] ? strtoul(line + 1, 0, 10) :
  482. 40;
  483. g_testHaptic = n;
  484. Serial.printf(
  485. "# test-haptic burst x%u queued (relay 0x82 01 01 F7 via op=%02X sub=%02X)\n",
  486. n, g_relayOp, g_relaySub);
  487. }
  488. // dump the captured OUTPUT-report history (oldest->newest)
  489. else if (line[0] == 'H') {
  490. hapticDumpLog();
  491. } else if (line[0] == 'j') {
  492. g_connType = strtoul(line + 1, 0, 16);
  493. Serial.printf("# connType=%02X\n", g_connType);
  494. } else if (line[0] == 'Q') {
  495. g_connLen = strtoul(line + 1, 0, 16);
  496. Serial.printf("# connLen=%02X\n", g_connLen);
  497. } else if (line[0] == 'A') {
  498. g_balen = strtoul(line + 1, 0, 16);
  499. g_pcnf1 = 0;
  500. Serial.printf("# balen=%u\n", g_balen);
  501. } else if (line[0] == 'a') {
  502. uint32_t v = strtoul(line + 1, 0, 16);
  503. g_rfBase[0] = v >> 24;
  504. g_rfBase[1] = v >> 16;
  505. g_rfBase[2] = v >> 8;
  506. g_rfBase[3] = v;
  507. Serial.printf("# base=%08lX\n",
  508. (unsigned long)v);
  509. if (g_rfListen)
  510. rfListenStart();
  511. } else if (line[0] == 'b') {
  512. for (int i = 0; i < NSLOT; i++)
  513. if (g_slot[i].used) {
  514. Serial.printf("slot%d ", i);
  515. for (int j = 0; j < 24; j++)
  516. Serial.printf(
  517. "%02X",
  518. g_slot[i].rec[j]);
  519. Serial.println();
  520. }
  521. } else if (line[0] == 'D') {
  522. armDebugCdcNextBoot();
  523. Serial.println(
  524. "# debug-CDC armed: reset to KEEP the serial console one more boot (auto-reverts after; the wake mouse is dropped that boot)");
  525. } else if (line[0] == 'X') {
  526. g_rfCap = !g_rfCap;
  527. g_rfHost = g_rfAuto = g_rfBeacon = g_rfListen =
  528. g_rfRaw = g_rfSweep = g_rfRespond =
  529. false;
  530. g_rfCh = 2;
  531. g_capV = 0;
  532. if (g_rfCap)
  533. rfCapStart(g_rfCh);
  534. Serial.printf(
  535. "# CAPTURE(listen) %s ch%u on \"ibex\", cycling 1M/2M x BALEN3/4 (use cN to set ch)\n",
  536. g_rfCap ? "ON" : "off", g_rfCh);
  537. } else if (line[0] == 'S') {
  538. g_rfAuto = !g_rfAuto;
  539. g_rfHost = g_rfAuto;
  540. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  541. false;
  542. g_rfCh = 2;
  543. g_cfgIdx = 0;
  544. if (g_rfAuto)
  545. applyCfg(0);
  546. Serial.printf("# AUTOSWEEP %s\n",
  547. g_rfAuto ? "ON" : "off");
  548. }
  549. li = 0;
  550. } else if (li < sizeof line - 1)
  551. line[li++] = c;
  552. }
  553. }