serial_console.cpp 20 KB

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