wii_anal_ec.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include "wii_anal.h"
  4. #include "wii_anal_lcd.h"
  5. #include "wii_anal_keys.h"
  6. //+============================================================================ ========================================
  7. // Handle Wii Extension Controller events
  8. //
  9. bool evWiiEC(const eventMsg_t* const msg, state_t* const state) {
  10. bool redraw = false;
  11. #if LOG_LEVEL >= 4
  12. {
  13. const char* s = NULL;
  14. switch(msg->wiiEc.type) {
  15. case WIIEC_NONE:
  16. s = "Error";
  17. break;
  18. case WIIEC_CONN:
  19. s = "Connect";
  20. break;
  21. case WIIEC_DISCONN:
  22. s = "Disconnect";
  23. break;
  24. case WIIEC_PRESS:
  25. s = "Press";
  26. break;
  27. case WIIEC_RELEASE:
  28. s = "Release";
  29. break;
  30. case WIIEC_ANALOG:
  31. s = "Analog";
  32. break;
  33. case WIIEC_ACCEL:
  34. s = "Accel";
  35. break;
  36. default:
  37. s = "Bug";
  38. break;
  39. }
  40. INFO(
  41. "WIIP : %s '%c' = %ld",
  42. s,
  43. (isprint((int)msg->wiiEc.in) ? msg->wiiEc.in : '_'),
  44. msg->wiiEc.val);
  45. if((msg->wiiEc.type == WIIEC_CONN) || (msg->wiiEc.type == WIIEC_DISCONN))
  46. INFO("...%ld=\"%s\"", msg->wiiEc.val, ecId[msg->wiiEc.val].name);
  47. }
  48. #endif
  49. switch(msg->wiiEc.type) {
  50. case WIIEC_CONN:
  51. patBacklight(state);
  52. state->hold = 0;
  53. state->calib = CAL_TRACK;
  54. sceneSet(state, ecId[msg->wiiEc.val].scene);
  55. redraw = true;
  56. #if 1 // Workaround for Classic Controller Pro, which shows 00's for Factory Calibration Data!?
  57. if(state->ec.pidx == PID_CLASSIC_PRO) {
  58. // Simulate a Long-OK keypress, to start Software Calibration mode
  59. eventMsg_t msg = {// .id = EVID_KEY,
  60. .input.type = InputTypeLong,
  61. .input.key = InputKeyOk};
  62. key_calib(&msg, state);
  63. }
  64. #endif
  65. break;
  66. case WIIEC_DISCONN:
  67. patBacklight(state);
  68. sceneSet(state, SCENE_WAIT);
  69. redraw = true;
  70. break;
  71. case WIIEC_PRESS:
  72. if(state->scene == SCENE_NUNCHUCK_ACC) switch(msg->wiiEc.in) {
  73. case 'z': // un-pause
  74. state->pause = !state->pause;
  75. break;
  76. case 'c': // toggle auto-pause
  77. state->pause = false;
  78. state->apause = !state->apause;
  79. break;
  80. default:
  81. break;
  82. }
  83. #if 1 //! factory calibration method not known for classic triggers - this will set the digital switch point
  84. if((state->ec.pidx == PID_CLASSIC) || (state->ec.pidx == PID_CLASSIC_PRO)) {
  85. if(msg->wiiEc.in == 'l') state->ec.calS.classic[2].trgZL = msg->wiiEc.val;
  86. if(msg->wiiEc.in == 'r') state->ec.calS.classic[2].trgZR = msg->wiiEc.val;
  87. }
  88. #endif
  89. __attribute__((fallthrough));
  90. case WIIEC_RELEASE:
  91. patBacklight(state);
  92. redraw = true;
  93. break;
  94. case WIIEC_ANALOG:
  95. case WIIEC_ACCEL:
  96. ecCalibrate(&state->ec, state->calib);
  97. redraw = true;
  98. break;
  99. default:
  100. break;
  101. }
  102. return redraw;
  103. }