wii_anal_ec.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. input.type = InputTypeLong,
  42. input.key = InputKeyOk
  43. };
  44. key_calib(&msg, state);
  45. }
  46. #endif
  47. break;
  48. case WIIEC_DISCONN:
  49. patBacklight(state);
  50. sceneSet(state, SCENE_WAIT);
  51. redraw = true;
  52. break;
  53. case WIIEC_PRESS:
  54. if (state->scene == SCENE_NUNCHUCK_ACC) switch (msg->wiiEc.in) {
  55. case 'z': // un-pause
  56. state->pause = !state->pause;
  57. break;
  58. case 'c': // toggle auto-pause
  59. state->pause = false;
  60. state->apause = !state->apause;
  61. break;
  62. default: break ;
  63. }
  64. #if 1 //! factory calibration method not known for classic triggers - this will set the digital switch point
  65. if ((state->ec.pidx == PID_CLASSIC) || (state->ec.pidx == PID_CLASSIC_PRO)) {
  66. if (msg->wiiEc.in == 'l') state->ec.calS.classic[2].trgZL = msg->wiiEc.val ;
  67. if (msg->wiiEc.in == 'r') state->ec.calS.classic[2].trgZR = msg->wiiEc.val ;
  68. }
  69. #endif
  70. __attribute__ ((fallthrough));
  71. case WIIEC_RELEASE:
  72. patBacklight(state);
  73. redraw = true;
  74. break;
  75. case WIIEC_ANALOG:
  76. case WIIEC_ACCEL:
  77. ecCalibrate(&state->ec, state->calib);
  78. redraw = true;
  79. break;
  80. default:
  81. break;
  82. }
  83. return redraw;
  84. }