haptics.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // haptics.h -- host -> controller haptic relay + the watchdogs that stop a stuck buzz.
  2. //
  3. // Steam (and legacy XInput rumble) send OUTPUT reports the real dongle forwards to the controller as a SET
  4. // sub-TLV inside the E3 poll. We do the same: handleSet()/the console queue a relay into g_relayBuf, and
  5. // rfConnFlushRelay() emits it inside the poll cadence (rf_link.cpp), never at raw loop rate.
  6. //
  7. // The controller's haptic LATCHES until told to stop. If the host's stop is lost over RF (or the link drops
  8. // mid-buzz) the actuator whines forever -- so we actively send 0x82-zero stop bursts on reconnect/silence and
  9. // gate relays on link + slot + lizard state. The g_hapLog ring captures recent OUTPUT reports for the 'H' dump.
  10. #pragma once
  11. #include <stdint.h>
  12. // after this much host silence, consider the current 0x82 haptic stream inactive
  13. #define HAPTIC_QUIET_MS 300u
  14. // drop stale host 0x82 after RF reconnect (Steam floods on attach)
  15. #define HAPTIC_RECONNECT_BLOCK_MS 1500u
  16. // 0x82-zero relays per stop event (sent at poll cadence -- not loop rate)
  17. #define HAPTIC_STOP_BURST 4u
  18. // ---- relay queue (written by puck_hid.cpp, mode_xinput.cpp, serial_console.cpp; drained by rf_link.cpp) ----
  19. extern volatile bool g_relayPend;
  20. extern uint8_t g_relayBuf[24];
  21. extern volatile uint8_t g_relayN;
  22. extern uint8_t g_relayOp; // relay frame opcode (E3 poll)
  23. extern uint8_t g_relaySub; // relay sub-TLV type byte = SET
  24. extern volatile uint8_t g_testHaptic;// 't<n>' injects n test haptics for the buzz hunt
  25. extern volatile uint8_t g_hapticStop;// pending haptic-STOP frames to relay (kill a latched whine)
  26. extern unsigned long g_hapticBlockUntil;
  27. void hapLogAdd(uint8_t slot, uint8_t rid, const uint8_t* b, uint16_t n);
  28. void hapticDumpLog(); // 'H' console dump of the recent OUTPUT-report history
  29. bool hapticLinkUp();
  30. bool haptic82Blocked();
  31. bool hapticRelaySlotOk(int slot);
  32. void haptic82HostReport(const uint8_t* p, uint16_t n);
  33. // queue + flush the pending host/test/stop relay inside the poll cadence (called from rf_link)
  34. void rfConnQueueHapticRelay();
  35. void rfConnFlushRelay(uint8_t ch);
  36. void hapticInit(); // boot reset: clear relay/active flags, arm the reconnect block + initial stop burst
  37. void hapticTask(); // per-loop upkeep: reconnect-block edge handling + steam 0x82 quiet timeout