bonds.h 1.1 KB

12345678910111213141516171819202122232425262728293031
  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_connSlot / g_connReplyMs are the live RF link state, shared here so the USB feature
  7. // 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. // bonded slot being polled (== the USB-connected slot); -1 = none
  20. extern int g_connSlot;
  21. extern unsigned long
  22. g_connReplyMs; // millis of last RF reply (link-alive timestamp)
  23. extern volatile bool g_dirty; // bonds changed -> flush to flash from loop()
  24. extern bool g_pairing;
  25. bool recEmpty(const uint8_t *r);
  26. void loadBonds();
  27. void saveBonds();