wii_anal_ec.c 2.3 KB

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