lizard_map.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // lizard_map.h -- configurable input→keyboard/mouse/consumer binding table for lizard (desktop)
  2. // mode.
  3. //
  4. // g_lizardMap replaces the hardcoded button→key map in mode_lizard.cpp with a runtime-configurable
  5. // list of LizardBinding entries. Each binding maps a trigger condition (button bitmask + optional
  6. // hold-modifier bitmask) to a single output action. rfLizard() walks the table every input frame.
  7. //
  8. // Designed for forward compatibility: the output union can gain a GAMEPAD variant to remap emulated-
  9. // controller buttons without changing the trigger model, storage format, or WebUSB protocol.
  10. #pragma once
  11. #include <stdint.h>
  12. // ---- output type (LizardBinding::outType) ----
  13. // 0 = disabled; skip this entry.
  14. #define LZ_OUT_NONE 0u
  15. // Keyboard chord: outData[0]=modifier bits, outData[1..6]=HID keycodes (up to 6, zero=unused).
  16. #define LZ_OUT_KBD_CHORD 1u
  17. // Mouse button: outData[0]=button bitmask (bit0=left, bit1=right, bit2=middle).
  18. #define LZ_OUT_MOUSE_BTN 2u
  19. // Mouse axis: outData[0]=source (LZ_MSRC_*), outData[1]=gyro activation (LZ_GYRO_*).
  20. #define LZ_OUT_MOUSE_AXIS 3u
  21. // Scroll wheel from an analog source: outData[0]=source (LZ_MSRC_*).
  22. #define LZ_OUT_SCROLL 4u
  23. // Consumer control (edge-triggered, MODE_LIZARD only): outData[0]=report bitmask (bit0=vol+, bit1=vol-).
  24. #define LZ_OUT_CONSUMER 5u
  25. // ---- analog source (outData[0] for MOUSE_AXIS and SCROLL) ----
  26. #define LZ_MSRC_RPAD 0u // right trackpad (MOUSE_AXIS; touch-gated by TB_RPADT)
  27. #define LZ_MSRC_LSTICK 1u // left analog stick (MOUSE_AXIS)
  28. #define LZ_MSRC_GYRO \
  29. 2u // gyroscope (MOUSE_AXIS; activation-gated, see LZ_GYRO_*)
  30. #define LZ_MSRC_LPAD 0u // left trackpad (SCROLL; touch-gated by TB_LPADT)
  31. // ---- gyro activation condition (outData[1] when src=LZ_MSRC_GYRO) ----
  32. #define LZ_GYRO_ALWAYS 0u // gyro always drives mouse
  33. #define LZ_GYRO_RPAD 1u // only when right trackpad is touched
  34. #define LZ_GYRO_LSTICK 2u // only when left stick is deflected past threshold
  35. // only when all bits in LizardBinding::holdMask are held
  36. #define LZ_GYRO_BTN 3u
  37. // ---- virtual stick-deflection trigger bits (usable in trigMask / holdMask) ----
  38. // These reuse bits 28..31 of the button word, which the SC2 *does* use in its 0x45 report (bit 28 =
  39. // right grip touch, bit 29 = left grip touch; PROTOCOL.md §8). To avoid grip-touch firing these,
  40. // lizardButtons() masks the controller's top 4 bits off before OR-ing in the deflection flags below,
  41. // so in MODE_LIZARD these bits mean ONLY stick deflection (grips are not a bindable lizard input).
  42. #define LZ_BTN_LSTICK_RT 0x10000000u // lx > 12000
  43. #define LZ_BTN_LSTICK_LF 0x20000000u // lx < -12000
  44. #define LZ_BTN_LSTICK_DN 0x40000000u // ly < -12000
  45. #define LZ_BTN_LSTICK_UP 0x80000000u // ly > 12000
  46. // ---- binding (16 bytes, naturally 4-byte aligned) ----
  47. // trigMask: (buttons & trigMask) != 0 activates the binding.
  48. // holdMask: ALL bits must also be set at the same time (AND-guard).
  49. // MOUSE_AXIS and SCROLL bindings ignore trigMask/holdMask; the analog source drives them.
  50. struct LizardBinding {
  51. uint8_t outType; // LZ_OUT_*
  52. uint8_t outData[7]; // type-specific payload (see constants above)
  53. uint32_t trigMask; // physical/virtual button bits: any-of (OR)
  54. uint32_t holdMask; // physical/virtual button bits: all-of (AND guard)
  55. };
  56. #define LZ_MAX_BINDINGS 32u
  57. struct LizardMap {
  58. uint8_t count;
  59. LizardBinding bindings[LZ_MAX_BINDINGS];
  60. };
  61. extern LizardMap g_lizardMap;
  62. // fill g_lizardMap with defaults (does NOT save to flash)
  63. void defaultLizardMap();
  64. void loadLizardMap();
  65. void saveLizardMap();