bonds.h 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. // bonds.h -- the puck's bond slots + live link state.
  2. //
  3. // The real puck holds four controller bonds and exposes one HID control interface per slot (interface N owns
  4. // slot N). We mirror that: g_slot[N] holds the bond record [8 uuid][16 serial] plus a staging buffer for that
  5. // interface's pending feature-report reply (filled by puck_hid.cpp's command channel). Bonds persist to
  6. // flash (bonds.bin). g_connReplyMs (per-slot, rf_link sets the active one) is the live RF link state, shared
  7. // here so the USB feature handler can report per-slot connection status without depending on the RF layer.
  8. #pragma once
  9. #include <stdint.h>
  10. #define NSLOT 4
  11. // per-slot state (record = [8 uuid][16 serial]) + per-interface response staging
  12. struct Slot {
  13. uint8_t rec[24];
  14. bool used;
  15. uint8_t resp[63];
  16. uint16_t resp_len;
  17. };
  18. extern Slot g_slot[NSLOT];
  19. // Per-slot link state. g_connReplyMs[i] is the millis() of the last F-type reply on slot i (the
  20. // "controller is alive" timestamp). g_linkRssi (rf_link.h) is also per-slot. Steam reads each slot's
  21. // B4/0x79/0x7B against its own entry here, so the four interfaces present four independent controllers
  22. // (each marked connected on its own).
  23. extern unsigned long g_connReplyMs[NSLOT];
  24. extern volatile bool g_dirty; // bonds changed -> flush to flash from loop()
  25. extern bool g_pairing;
  26. bool recEmpty(const uint8_t *r);
  27. void loadBonds();
  28. void saveBonds();
  29. int bondedSlotCount();