serial_console.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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 0x81 CLEAR_DIGITAL_MAPPINGS (the connect amp-clicker)
  81. g_drop81 = !g_drop81;
  82. Serial.printf(
  83. "# drop relayed 0x81 (Steam mode) %s\n",
  84. g_drop81 ? "ON" : "off");
  85. } else if (!strcmp(line, "FC")) {
  86. // feature-command capture: log Steam's USB SET/GET commands to serial + suppress I45
  87. g_cmdCapture = !g_cmdCapture;
  88. Serial.printf(
  89. "# feature-cmd capture %s (I45 %s)\n",
  90. g_cmdCapture ? "ON" : "off",
  91. g_cmdCapture ? "suppressed" : "on");
  92. } else if (!strcmp(line, "L87")) {
  93. // EXPERIMENT: land all relayed 0x87 config verbatim (real-puck relay) vs the discard-whitelist.
  94. // Exact-match string (single letters are all taken; 'l' alone = rfListenStart).
  95. g_landAll87 = !g_landAll87;
  96. saveCfg();
  97. Serial.printf(
  98. "# land-all-0x87 (verbatim 0x87 relay) %s\n",
  99. g_landAll87 ? "ON" : "off");
  100. } else if (!strcmp(line, "FR")) {
  101. // re-dump the flight recorder trail captured before the last watchdog hang (also printed
  102. // automatically at boot, but CDC may not be attached yet then -- this reprints on demand).
  103. faultDiagDumpFlight();
  104. } else if (!strcmp(line, "VIT")) {
  105. // toggle the live per-second CDC vitals line (loop rate / usbd stack / heap / relay trend)
  106. g_vitals = !g_vitals;
  107. Serial.printf("# live vitals line %s\n",
  108. g_vitals ? "ON" : "off");
  109. } else if (line[0] == 'l')
  110. rfListenStart();
  111. else if (line[0] == 'B') {
  112. g_rfBeacon = !g_rfBeacon;
  113. g_rfListen = false;
  114. Serial.printf("# beacon %s ch%u\n",
  115. g_rfBeacon ? "ON" : "off",
  116. g_rfCh);
  117. } else if (line[0] == 'L') {
  118. g_plen = strtol(line + 1, 0, 16);
  119. Serial.printf("# plen=%02X\n", g_plen);
  120. } else if (line[0] == '1') {
  121. g_s1incl = !g_s1incl;
  122. Serial.printf("# s1incl=%u\n", g_s1incl);
  123. } else if (line[0] == 'R') {
  124. g_rfCh = atoi(line + 1);
  125. g_rfRaw = true;
  126. g_rfListen = false;
  127. g_rfBeacon = false;
  128. rfRawStart(g_rfCh);
  129. Serial.printf("# raw cap ch%u\n", g_rfCh);
  130. } else if (line[0] == 'Z') {
  131. g_rfRaw = true;
  132. g_rfSweep = true;
  133. g_rfListen = false;
  134. g_rfBeacon = false;
  135. g_rfCh = 2;
  136. rfRawStart(g_rfCh);
  137. Serial.println("# raw SWEEP");
  138. } else if (line[0] == 'H') {
  139. g_rfHost = !g_rfHost;
  140. g_rfBeacon = false;
  141. g_rfListen = false;
  142. g_rfRaw = false;
  143. g_rfSweep = false;
  144. g_rfCh = 2;
  145. Serial.printf(
  146. "# HOSTFRAME beacon %s base %02X%02X%02X%02X (slot0 uuids %02X%02X%02X%02X/%02X%02X%02X%02X)\n",
  147. g_rfHost ? "ON" : "off", g_rfBase[0],
  148. g_rfBase[1], g_rfBase[2], g_rfBase[3],
  149. g_slot[0].rec[0], g_slot[0].rec[1],
  150. g_slot[0].rec[2], g_slot[0].rec[3],
  151. g_slot[0].rec[4], g_slot[0].rec[5],
  152. g_slot[0].rec[6], g_slot[0].rec[7]);
  153. } else if (line[0] == 'C') {
  154. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  155. g_rfHost = false;
  156. rfRespondStart();
  157. } else if (line[0] == 's') {
  158. g_rfListen = false;
  159. g_rfBeacon = false;
  160. g_rfRaw = false;
  161. g_rfSweep = false;
  162. g_rfHost = false;
  163. g_rfRespond = false;
  164. NRF_RADIO->TASKS_DISABLE = 1;
  165. Serial.println("# RF off");
  166. } else if (line[0] == 'u') {
  167. // id9=0 hold (MODE_STEAM only) A/B toggle (persisted; see haptics.h LIZKEEP_MS)
  168. g_lizKeep = !g_lizKeep;
  169. saveCfg();
  170. Serial.printf(
  171. "# id9=0 hold (Steam mode, /%ums) %s\n",
  172. (unsigned)LIZKEEP_MS,
  173. g_lizKeep ? "ON" : "off");
  174. }
  175. // 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)
  176. else if (line[0] == 'x') {
  177. uint8_t m = strtoul(line + 1, 0, 10);
  178. if (modeValid(m)) {
  179. if (USBDevice.suspended()) {
  180. Serial.println(
  181. "# mode change blocked: host suspended");
  182. } else {
  183. Serial.printf(
  184. "# switch mode %u (reboot)\n",
  185. m);
  186. delay(20);
  187. // clean detach + reboot (releases held input on the outgoing device)
  188. modeSwitchReboot(m);
  189. }
  190. }
  191. } else if (line[0] == 'c') {
  192. g_rfCh = atoi(line + 1);
  193. Serial.printf("# ch=%u\n", g_rfCh);
  194. if (g_rfListen)
  195. rfListenStart();
  196. } else if (line[0] == 'p') {
  197. g_rfPrefix = strtol(line + 1, 0, 16);
  198. Serial.printf("# prefix=%02X\n", g_rfPrefix);
  199. if (g_rfListen)
  200. rfListenStart();
  201. } else if (line[0] == 'i') {
  202. g_crcinit = strtoul(line + 1, 0, 16);
  203. Serial.printf("# crcinit=%06lX\n",
  204. (unsigned long)g_crcinit);
  205. } else if (line[0] == 'w') {
  206. g_whiteiv = atoi(line + 1);
  207. Serial.printf("# whiteiv=%u\n", g_whiteiv);
  208. } else if (line[0] == '0') {
  209. g_pcnf0 = strtoul(line + 1, 0, 16);
  210. Serial.printf("# pcnf0=%08lX\n",
  211. (unsigned long)g_pcnf0);
  212. } else if (line[0] == '2') {
  213. g_pcnf1 = strtoul(line + 1, 0, 16);
  214. Serial.printf("# pcnf1=%08lX\n",
  215. (unsigned long)g_pcnf1);
  216. } else if (line[0] == 'M') {
  217. g_mode = strtoul(line + 1, 0, 16);
  218. Serial.printf(
  219. "# mode=%u (3=Ble1M,4=Ble2M,0/2=Nrf)\n",
  220. g_mode);
  221. } else if (line[0] == 'I') {
  222. g_crcinit = strtoul(line + 1, 0, 16);
  223. Serial.printf("# crcinit=%08lX\n",
  224. (unsigned long)g_crcinit);
  225. } else if (line[0] == 'P') {
  226. g_crcpoly = strtoul(line + 1, 0, 16);
  227. Serial.printf("# crcpoly=%lX\n",
  228. (unsigned long)g_crcpoly);
  229. } else if (line[0] == 'N') {
  230. g_crccnf = strtoul(line + 1, 0, 16);
  231. Serial.printf("# crccnf=%X\n", g_crccnf);
  232. } else if (line[0] == 'Y') {
  233. g_rfCap = true;
  234. g_rfCapOne = true;
  235. g_rfReplay = g_rfHost = g_rfAuto = false;
  236. g_rfCh = 2;
  237. rfCapStart(2);
  238. Serial.println(
  239. "# capture ONE frame for replay...");
  240. } else if (line[0] == 'y') {
  241. g_rfReplay = !g_rfReplay;
  242. g_rfCap = g_rfHost = g_rfAuto = false;
  243. Serial.printf("# REPLAY %s (%uB)\n",
  244. g_rfReplay ? "ON" : "off",
  245. g_replayLen);
  246. } else if (line[0] == 'T') {
  247. g_statlen = strtoul(line + 1, 0, 16);
  248. g_pcnf1 = 0;
  249. Serial.printf("# statlen=%02X\n", g_statlen);
  250. } else if (line[0] == 'k') {
  251. g_connOn = !g_connOn;
  252. if (g_connOn) {
  253. g_connSt = 0;
  254. g_connStep = 0;
  255. g_connPoll = 0;
  256. g_connF1 = 0;
  257. }
  258. Serial.printf(
  259. "# CONN mode %s: %s%s poll on ch%u (param=%02X). F1 seen=%lu\n",
  260. g_connOn ? "ON" : "off",
  261. g_e7announce ? "E7-awake[00 00] -> " :
  262. "",
  263. g_pollGet ? "E3+GET-report-0x45" :
  264. "bare E3",
  265. g_rfCh, g_getParam,
  266. (unsigned long)g_connF1);
  267. } else if (line[0] == 'q') {
  268. g_getParam = g_getParam ? 0x00 : 0x2D;
  269. Serial.printf("# GET-0x45 param=%02X\n",
  270. g_getParam);
  271. } else if (line[0] == 'v') {
  272. g_connVerbose = !g_connVerbose;
  273. Serial.printf(
  274. "# conn verbose %s (F1 seen=%lu)\n",
  275. g_connVerbose ? "ON" : "off",
  276. (unsigned long)g_connF1);
  277. } else if (line[0] == 'C') {
  278. g_sessCh = strtoul(line + 1, 0, 10);
  279. Serial.printf(
  280. "# session channel=%u (re-pair/reconnect to apply)\n",
  281. g_sessCh);
  282. } else if (line[0] == 'E') {
  283. g_mDiv = strtoul(line + 1, 0, 10);
  284. if (g_mDiv < 4)
  285. g_mDiv = 4;
  286. saveCfg();
  287. Serial.printf(
  288. "# xbox-mouse sensitivity divisor=%d (lower=faster)\n",
  289. g_mDiv);
  290. } else if (line[0] == 'F') {
  291. g_mFric = strtoul(line + 1, 0, 10);
  292. if (g_mFric > 99)
  293. g_mFric = 99;
  294. saveCfg();
  295. Serial.printf(
  296. "# xbox-mouse friction=%d%% (higher=more glide/momentum)\n",
  297. g_mFric);
  298. } else if (line[0] == 'W') {
  299. // A/B swap edits the ACTIVE emulated type (Xbox/Switch/DS4/DS5); puck modes have none.
  300. if (g_etype < ET_COUNT) {
  301. g_type[g_etype].abSwap =
  302. !g_type[g_etype].abSwap;
  303. applyActiveType();
  304. saveCfg();
  305. Serial.printf(
  306. "# A/B + X/Y swap %s (Nintendo layout) [type %u]\n",
  307. g_abSwap ? "ON" : "off",
  308. g_etype);
  309. } else
  310. Serial.println(
  311. "# A/B swap N/A in this mode (Steam/Lizard are not emulated types)");
  312. } else if (line[0] == 'K') {
  313. int i = line[1] - '0';
  314. uint8_t code = strtoul(line + 2, 0, 10);
  315. // back paddles edit the ACTIVE emulated type. code 18 = Capture/Screenshot (Switch only).
  316. if (i >= 0 && i < 4 && g_etype < ET_COUNT) {
  317. g_type[g_etype].back[i] = code;
  318. applyActiveType();
  319. saveCfg();
  320. Serial.printf(
  321. "# 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",
  322. i,
  323. (const char *[]){ "L4", "R4",
  324. "L5",
  325. "R5" }[i],
  326. code, g_etype);
  327. } else if (g_etype >= ET_COUNT)
  328. Serial.println(
  329. "# back map N/A in this mode (Steam/Lizard are not emulated types)");
  330. else
  331. Serial.println(
  332. "# usage: K<0-3> <code> (0=L4 1=R4 2=L5 3=R5)");
  333. } else if (line[0] == 'Q') {
  334. uint8_t code = strtoul(line + 1, 0, 10);
  335. if (g_etype < ET_COUNT) {
  336. g_type[g_etype].qamMap = code;
  337. applyActiveType();
  338. saveCfg();
  339. Serial.printf(
  340. "# 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",
  341. code, g_etype);
  342. } else
  343. Serial.println(
  344. "# QAM map N/A in this mode (Steam/Lizard are not emulated types)");
  345. } else if (line[0] == 'J') {
  346. char *sp = 0;
  347. uint8_t id = strtoul(line + 1, &sp, 0);
  348. // inject SET-SETTINGS to controller: report 0x87 [id][val u16 LE]
  349. uint16_t val = sp ? strtoul(sp, 0, 0) : 0;
  350. uint8_t pl[3] = { id, (uint8_t)(val & 0xFF),
  351. (uint8_t)(val >> 8) };
  352. // console-injected writes go to all connected controllers (no specific slot in scope)
  353. relayEnqueue(0x87, pl, 3, 0xFF);
  354. Serial.printf(
  355. "# queued SET-SETTINGS id=0x%02X val=%u (relay 0x87) — watch new=/s\n",
  356. id, val);
  357. } else if (line[0] == 'G') {
  358. g_sniff = !g_sniff;
  359. g_sniffPh = 0;
  360. g_rfHost = g_connOn = g_rfCap = g_rfAuto =
  361. g_rfReplay = false;
  362. if (g_sniff)
  363. rfSniffStart();
  364. Serial.printf(
  365. "# SESSION SNIFF %s (phase0: catch host frame on ibex/ch2; phase1 PARK ch=%s)\n",
  366. g_sniff ? "ON" : "off",
  367. g_sniffPark ? "override" : "primary");
  368. } else if (line[0] == 'g') {
  369. g_sniffPark = strtoul(line + 1, 0, 10);
  370. if (g_sniffPh == 1)
  371. rfSniffStart();
  372. Serial.printf(
  373. "# sniff park channel=%u (0=learned primary)\n",
  374. g_sniffPark);
  375. } else if (line[0] == 'V') {
  376. g_e7b = strtoul(line + 1, 0, 10);
  377. Serial.printf(
  378. "# E7 protocol-version B-byte=%u (0=awake/slow, 1=try v1-fast; watch new=/s; revert if input stops)\n",
  379. g_e7b);
  380. } else if (line[0] == 'O') {
  381. g_relayOp = strtoul(line + 1, 0, 16);
  382. Serial.printf("# relay opcode=%02X\n",
  383. g_relayOp);
  384. } else if (line[0] == 'o') {
  385. g_relaySub = strtoul(line + 1, 0, 16);
  386. Serial.printf("# relay sub-type=%02X\n",
  387. g_relaySub);
  388. } else if (line[0] == 'h') {
  389. uint8_t nc = strtoul(line + 1, 0, 10);
  390. Serial.printf(
  391. "# HOP %u->%u (advertise on current ch, then poll new). Watch F1=/s\n",
  392. g_sessCh, nc);
  393. rfHopTo(nc);
  394. } else if (line[0] == 'z') {
  395. g_qos = !g_qos;
  396. g_hopIdx = 0;
  397. g_qosBad = 0;
  398. g_qosCheckMs = millis();
  399. Serial.printf(
  400. "# QoS adaptive channel hopping %s (candidates 18,46,76,22,68)\n",
  401. g_qos ? "ON" : "off");
  402. } else if (line[0] == 'U') {
  403. // Per-slot debug dump: which controllers are connected, their RSSI, haptic-block
  404. // state, and session address. Quick at-a-glance view for multi-controller testing.
  405. Serial.printf("# session ch%u, curSlot=%d\n",
  406. g_sessCh, g_curSlot);
  407. for (int s = 0; s < NSLOT; s++) {
  408. bool live = g_slot[s].used &&
  409. g_connReplyMs[s] != 0;
  410. unsigned long age =
  411. live ? (unsigned long)(millis() -
  412. g_connReplyMs
  413. [s]) :
  414. 0;
  415. int rssi =
  416. g_linkRssi[s] ?
  417. (int)g_linkRssi[s] -
  418. RSSI_DBM_OFFSET :
  419. 0;
  420. unsigned long now_ms = millis();
  421. unsigned long blk =
  422. (g_hapticBlockUntil[s] &&
  423. (int32_t)(g_hapticBlockUntil[s] -
  424. now_ms) > 0) ?
  425. (g_hapticBlockUntil[s] -
  426. now_ms) :
  427. 0;
  428. Serial.printf(
  429. "# 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",
  430. s,
  431. g_slot[s].used ?
  432. (live ? "LIVE" :
  433. "BONDED") :
  434. "empty",
  435. g_sessBase[s][0],
  436. g_sessBase[s][1],
  437. g_sessBase[s][2],
  438. g_sessBase[s][3],
  439. g_sessPrefix[s], rssi, age,
  440. g_battery[s], blk,
  441. g_slot[s].rec[0],
  442. g_slot[s].rec[1],
  443. g_slot[s].rec[2],
  444. g_slot[s].rec[3],
  445. g_slot[s].rec[4],
  446. g_slot[s].rec[5],
  447. g_slot[s].rec[6],
  448. g_slot[s].rec[7]);
  449. }
  450. } else if (line[0] == 'r') {
  451. // poll RX-window is FIXED (not configurable) -- report only.
  452. Serial.printf(
  453. "# poll RX-window=%lu us (FIXED; poll rate caps ~%lu/s)\n",
  454. (unsigned long)g_rxWin,
  455. (unsigned long)(1000000 / g_rxWin));
  456. } else if (line[0] == 'e') {
  457. g_e3mode = strtoul(line + 1, 0, 10);
  458. Serial.printf(
  459. "# E3 poll PID mode=%u (0=fixed07, 1=cyclePID+noack1, 2=cyclePID+noack0) - watch new=/s\n",
  460. g_e3mode);
  461. } else if (line[0] == 'd') {
  462. g_pollGet = !g_pollGet;
  463. Serial.printf(
  464. "# poll = %s (real puck sends BARE E3) - watch F1=/s new=/s\n",
  465. g_pollGet ?
  466. "E3 + GET-report-0x45 TLV (legacy)" :
  467. "bare E3");
  468. } else if (line[0] == 'n') {
  469. g_e7announce = !g_e7announce;
  470. Serial.printf(
  471. "# E7 awake-announce %s (real puck never sends E7) - watch F1=/s\n",
  472. g_e7announce ? "ON (legacy)" : "off");
  473. } else if (line[0] == 'm') {
  474. g_e1keepalive = !g_e1keepalive;
  475. Serial.printf(
  476. "# session-channel E1 keepalive %s (real puck sends none; needed for shared addr) - watch F1=/s\n",
  477. g_e1keepalive ? "ON" : "off");
  478. } else if (line[0] == 't') {
  479. // inject n test haptics (output 0x82 [01 01 F7]) over the relay
  480. uint8_t n = line[1] ? strtoul(line + 1, 0, 10) :
  481. 40;
  482. g_testHaptic = n;
  483. Serial.printf(
  484. "# test-haptic burst x%u queued (relay 0x82 01 01 F7 via op=%02X sub=%02X)\n",
  485. n, g_relayOp, g_relaySub);
  486. }
  487. // dump the captured OUTPUT-report history (oldest->newest)
  488. else if (line[0] == 'H') {
  489. hapticDumpLog();
  490. } else if (line[0] == 'j') {
  491. g_connType = strtoul(line + 1, 0, 16);
  492. Serial.printf("# connType=%02X\n", g_connType);
  493. } else if (line[0] == 'Q') {
  494. g_connLen = strtoul(line + 1, 0, 16);
  495. Serial.printf("# connLen=%02X\n", g_connLen);
  496. } else if (line[0] == 'A') {
  497. g_balen = strtoul(line + 1, 0, 16);
  498. g_pcnf1 = 0;
  499. Serial.printf("# balen=%u\n", g_balen);
  500. } else if (line[0] == 'a') {
  501. uint32_t v = strtoul(line + 1, 0, 16);
  502. g_rfBase[0] = v >> 24;
  503. g_rfBase[1] = v >> 16;
  504. g_rfBase[2] = v >> 8;
  505. g_rfBase[3] = v;
  506. Serial.printf("# base=%08lX\n",
  507. (unsigned long)v);
  508. if (g_rfListen)
  509. rfListenStart();
  510. } else if (line[0] == 'b') {
  511. for (int i = 0; i < NSLOT; i++)
  512. if (g_slot[i].used) {
  513. Serial.printf("slot%d ", i);
  514. for (int j = 0; j < 24; j++)
  515. Serial.printf(
  516. "%02X",
  517. g_slot[i].rec[j]);
  518. Serial.println();
  519. }
  520. } else if (line[0] == 'D') {
  521. armDebugCdcNextBoot();
  522. Serial.println(
  523. "# debug-CDC armed: reset to KEEP the serial console one more boot (auto-reverts after; the wake mouse is dropped that boot)");
  524. } else if (line[0] == 'X') {
  525. g_rfCap = !g_rfCap;
  526. g_rfHost = g_rfAuto = g_rfBeacon = g_rfListen =
  527. g_rfRaw = g_rfSweep = g_rfRespond =
  528. false;
  529. g_rfCh = 2;
  530. g_capV = 0;
  531. if (g_rfCap)
  532. rfCapStart(g_rfCh);
  533. Serial.printf(
  534. "# CAPTURE(listen) %s ch%u on \"ibex\", cycling 1M/2M x BALEN3/4 (use cN to set ch)\n",
  535. g_rfCap ? "ON" : "off", g_rfCh);
  536. } else if (line[0] == 'S') {
  537. g_rfAuto = !g_rfAuto;
  538. g_rfHost = g_rfAuto;
  539. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  540. false;
  541. g_rfCh = 2;
  542. g_cfgIdx = 0;
  543. if (g_rfAuto)
  544. applyCfg(0);
  545. Serial.printf("# AUTOSWEEP %s\n",
  546. g_rfAuto ? "ON" : "off");
  547. }
  548. li = 0;
  549. } else if (li < sizeof line - 1)
  550. line[li++] = c;
  551. }
  552. }