wii_anal_ec.c 2.7 KB

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