serial_console.cpp 20 KB

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