wii_ec_macros.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef WII_EC_MACROS_H_
  2. #define WII_EC_MACROS_H_
  3. //----------------------------------------------------------------------------- ----------------------------------------
  4. // CHECK MACROS
  5. //
  6. // I don't generally like this style of coding - it just (generally) makes things nightmarish to debug
  7. // However, on this occasion I think it's a good choice (to make adding controllers LESS bug-prone)
  8. //
  9. //if (furi_message_queue_get_count(queue) > 18) WARN("queue high %d", furi_message_queue_get_count(queue));
  10. #define MSGQ(lbl) \
  11. do { \
  12. msg.wiiEc.in = lbl; \
  13. furi_message_queue_put(queue, &msg, 0); \
  14. } while(0)
  15. // A 'standard' "button" is an independent SPST switch
  16. // Eg. Nunchuck 'Z' button
  17. // The "value" will always be 0
  18. #define BUTTON(btn, lbl) \
  19. do { \
  20. if(new->btn != old->btn) { \
  21. msg.wiiEc.type = (new->btn) ? WIIEC_PRESS : WIIEC_RELEASE; \
  22. msg.wiiEc.val = 0; \
  23. MSGQ(lbl); \
  24. } \
  25. } while(0)
  26. // An "analogue button" is an SPST coupled with an ananlogue 'switch'
  27. // Eg. The "bottom out" switches on the triggers of the classic controller
  28. // The "value" will be the value of the associated analogue controller
  29. #define ANABTN(btn, ana, lbl) \
  30. do { \
  31. if(new->btn != old->btn) { \
  32. msg.wiiEc.type = (new->btn) ? WIIEC_PRESS : WIIEC_RELEASE; \
  33. msg.wiiEc.val = new->ana; \
  34. MSGQ(lbl); \
  35. } \
  36. } while(0)
  37. #define ANALOG(ana, lbl) \
  38. do { \
  39. if(new->ana != old->ana) { \
  40. msg.wiiEc.type = WIIEC_ANALOG; \
  41. msg.wiiEc.val = new->ana; \
  42. MSGQ(lbl); \
  43. } \
  44. } while(0)
  45. #define ACCEL(acc, lbl) \
  46. do { \
  47. if(new->acc != old->acc) { \
  48. msg.wiiEc.type = WIIEC_ACCEL; \
  49. msg.wiiEc.val = new->acc; \
  50. MSGQ(lbl); \
  51. } \
  52. } while(0)
  53. //----------------------------------------------------------------------------- ----------------------------------------
  54. // CALIBRATION MACROS
  55. //
  56. // Again ...I totally agree with anyone who says "MACRO coding" is (gernally) a poor choice of programming style
  57. // But something about this code is making it soooo appealing
  58. //
  59. // ... v=variable, n=number
  60. //
  61. #define FACTORY_LO(v, n) \
  62. do { \
  63. (dst[1].v) = n; \
  64. } while(0)
  65. #define FACTORY_MID(v, n) \
  66. do { \
  67. (dst[2].v) = n; \
  68. } while(0)
  69. #define FACTORY_HI(v, n) \
  70. do { \
  71. (dst[3].v) = n; \
  72. } while(0)
  73. #define TRACK_LO(v) \
  74. do { \
  75. if((src->v) < (dst[0].v)) (dst[0].v) = (src->v); \
  76. } while(0)
  77. #define TRACK_HI(v) \
  78. do { \
  79. if((src->v) > (dst[4].v)) (dst[4].v) = (src->v); \
  80. } while(0)
  81. #define TRACK_LO_HI(v) \
  82. do { \
  83. TRACK_LO(v); \
  84. TRACK_HI(v); \
  85. } while(0)
  86. #define RESET_LO(v, b) \
  87. do { \
  88. (dst[0].v) = (dst[1].v) = ((1 << (b)) - 1); \
  89. } while(0)
  90. #define RESET_HI(v) \
  91. do { \
  92. (dst[4].v) = (dst[3].v) = 0; \
  93. } while(0)
  94. #define RESET_MID(v) \
  95. do { \
  96. (dst[2].v) = (src->v); \
  97. } while(0)
  98. #define RESET_LO_HI(v, b) \
  99. do { \
  100. RESET_LO(v, b); \
  101. RESET_HI(v); \
  102. } while(0)
  103. #define RESET_LO_MID_HI(v, b) \
  104. do { \
  105. RESET_LO(v, b); \
  106. RESET_MID(v); \
  107. RESET_HI(v); \
  108. } while(0)
  109. #define RANGE_LO(v) \
  110. do { \
  111. if((src->v) < (dst[1].v)) (dst[1].v) = (src->v); \
  112. } while(0)
  113. #define RANGE_HI(v) \
  114. do { \
  115. if((src->v) > (dst[3].v)) (dst[3].v) = (src->v); \
  116. } while(0)
  117. #define RANGE_LO_HI(v) \
  118. do { \
  119. RANGE_LO(v); \
  120. RANGE_HI(v); \
  121. } while(0)
  122. #define CENTRE(v) \
  123. do { \
  124. (dst[2].v) = (src->v); \
  125. } while(0)
  126. #endif //WII_EC_MACROS_H_