wii_ec_macros.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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) do { \
  11. msg.wiiEc.in = lbl; \
  12. furi_message_queue_put(queue, &msg, 0); \
  13. }while(0)
  14. // A 'standard' "button" is an independent SPST switch
  15. // Eg. Nunchuck 'Z' button
  16. // The "value" will always be 0
  17. #define BUTTON(btn,lbl) do { \
  18. if (new->btn != old->btn) { \
  19. msg.wiiEc.type = (new->btn) ? WIIEC_PRESS : WIIEC_RELEASE; \
  20. msg.wiiEc.val = 0; \
  21. MSGQ(lbl); \
  22. } \
  23. }while(0)
  24. // An "analogue button" is an SPST coupled with an ananlogue 'switch'
  25. // Eg. The "bottom out" switches on the triggers of the classic controller
  26. // The "value" will be the value of the associated analogue controller
  27. #define ANABTN(btn,ana,lbl) do { \
  28. if (new->btn != old->btn) { \
  29. msg.wiiEc.type = (new->btn) ? WIIEC_PRESS : WIIEC_RELEASE; \
  30. msg.wiiEc.val = new->ana; \
  31. MSGQ(lbl); \
  32. } \
  33. }while(0)
  34. #define ANALOG(ana,lbl) do { \
  35. if (new->ana != old->ana) { \
  36. msg.wiiEc.type = WIIEC_ANALOG; \
  37. msg.wiiEc.val = new->ana; \
  38. MSGQ(lbl); \
  39. } \
  40. }while(0)
  41. #define ACCEL(acc,lbl) do { \
  42. if (new->acc != old->acc) { \
  43. msg.wiiEc.type = WIIEC_ACCEL; \
  44. msg.wiiEc.val = new->acc; \
  45. MSGQ(lbl); \
  46. } \
  47. }while(0)
  48. //----------------------------------------------------------------------------- ----------------------------------------
  49. // CALIBRATION MACROS
  50. //
  51. // Again ...I totally agree with anyone who says "MACRO coding" is (gernally) a poor choice of programming style
  52. // But something about this code is making it soooo appealing
  53. //
  54. // ... v=variable, n=number
  55. //
  56. #define FACTORY_LO(v,n) do{ (dst[1]. v) = n; }while(0)
  57. #define FACTORY_MID(v,n) do{ (dst[2]. v) = n; }while(0)
  58. #define FACTORY_HI(v,n) do{ (dst[3]. v) = n; }while(0)
  59. #define TRACK_LO(v) do{ if ((src-> v) < (dst[0]. v)) (dst[0]. v) = (src-> v); }while(0)
  60. #define TRACK_HI(v) do{ if ((src-> v) > (dst[4]. v)) (dst[4]. v) = (src-> v); }while(0)
  61. #define TRACK_LO_HI(v) do{ TRACK_LO(v); TRACK_HI(v); }while(0)
  62. #define RESET_LO(v,b) do{ (dst[0]. v) = (dst[1]. v) = ((1<<(b))-1); }while(0)
  63. #define RESET_HI(v) do{ (dst[4]. v) = (dst[3]. v) = 0; }while(0)
  64. #define RESET_MID(v) do{ (dst[2]. v) = (src-> v); }while(0)
  65. #define RESET_LO_HI(v,b) do{ RESET_LO(v,b); RESET_HI(v); }while(0)
  66. #define RESET_LO_MID_HI(v,b) do{ RESET_LO(v,b); RESET_MID(v); RESET_HI(v); }while(0)
  67. #define RANGE_LO(v) do{ if ((src-> v) < (dst[1]. v)) (dst[1]. v) = (src-> v); }while(0)
  68. #define RANGE_HI(v) do{ if ((src-> v) > (dst[3]. v)) (dst[3]. v) = (src-> v); }while(0)
  69. #define RANGE_LO_HI(v) do{ RANGE_LO(v); RANGE_HI(v); }while(0)
  70. #define CENTRE(v) do{ (dst[2]. v) = (src-> v); } while(0)
  71. #endif //WII_EC_MACROS_H_