From ca6959c8e8a8801a1d17f24d51bd373f56366d9b Mon Sep 17 00:00:00 2001 From: ShikyC Date: Thu, 4 Jan 2024 17:57:12 -0800 Subject: [PATCH] Preliminary analog input fix --- src/bnusio.cpp | 85 +++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 3ec49d9..4606a22 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -90,8 +90,8 @@ bnusio_GetFirmwareVersion () { return 126; } -u16 drumMin = 10000; -u16 drumMax = 20000; +u16 drumMin = 15000; +u16 drumMax = 30000; u16 drumWaitPeriod = 4; u16 lastHitValue = drumMin; @@ -107,50 +107,54 @@ SDLAxis analogBindings[] = {SDL_AXIS_LEFT_DOWN, SDL_AXIS_LEFT_RIGHT, SDL_AXIS_RI u16 bnusio_GetAnalogIn (u8 which) { + u16 analogValue; if (useTaikoController) { - return (int)(65535 * ControllerAxisIsDown (analogBindings[which])); - } else { - auto button = analogButtons[which]; - if (which == 0) { - if (buttonWaitPeriodP1 > 0) buttonWaitPeriodP1--; - if (buttonWaitPeriodP2 > 0) buttonWaitPeriodP2--; + analogValue = (u16)(32768 * ControllerAxisIsDown (analogBindings[which])); + if (analogValue > 100) { + return analogValue; } - bool isP1 = which / 4 == 0; - if ((isP1 && !buttonQueueP1.empty ()) || (!isP1 && !buttonQueueP2.empty ())) { - if ((isP1 && buttonQueueP1.front () == which && buttonWaitPeriodP1 == 0) || (!isP1 && buttonQueueP2.front () == which && buttonWaitPeriodP2 == 0)) { - if (isP1) { - buttonQueueP1.pop (); - buttonWaitPeriodP1 = drumWaitPeriod; - } else { - buttonQueueP2.pop (); - buttonWaitPeriodP2 = drumWaitPeriod; - } + return 0; + } + auto button = analogButtons[which]; + if (which == 0) { + if (buttonWaitPeriodP1 > 0) buttonWaitPeriodP1--; + if (buttonWaitPeriodP2 > 0) buttonWaitPeriodP2--; + } + bool isP1 = which / 4 == 0; + if ((isP1 && !buttonQueueP1.empty ()) || (!isP1 && !buttonQueueP2.empty ())) { + if ((isP1 && buttonQueueP1.front () == which && buttonWaitPeriodP1 == 0) || (!isP1 && buttonQueueP2.front () == which && buttonWaitPeriodP2 == 0)) { + if (isP1) { + buttonQueueP1.pop (); + buttonWaitPeriodP1 = drumWaitPeriod; + } else { + buttonQueueP2.pop (); + buttonWaitPeriodP2 = drumWaitPeriod; + } - lastHitValue++; - if (lastHitValue >= drumMax) lastHitValue = drumMin; - return lastHitValue; - } - if (IsButtonTapped (*button)) { - if (isP1) buttonQueueP1.push (which); - else buttonQueueP2.push (which); - } - return 0; - } else if (IsButtonTapped (*button)) { - if (isP1 && buttonWaitPeriodP1 > 0) { - buttonQueueP1.push (which); - return 0; - } else if (!isP1 && buttonWaitPeriodP2 > 0) { - buttonQueueP2.push (which); - return 0; - } - if (isP1) buttonWaitPeriodP1 = drumWaitPeriod; - else buttonWaitPeriodP2 = drumWaitPeriod; lastHitValue++; if (lastHitValue >= drumMax) lastHitValue = drumMin; return lastHitValue; - } else { + } + if (IsButtonTapped (*button)) { + if (isP1) buttonQueueP1.push (which); + else buttonQueueP2.push (which); + } + return 0; + } else if (IsButtonTapped (*button)) { + if (isP1 && buttonWaitPeriodP1 > 0) { + buttonQueueP1.push (which); + return 0; + } else if (!isP1 && buttonWaitPeriodP2 > 0) { + buttonQueueP2.push (which); return 0; } + if (isP1) buttonWaitPeriodP1 = drumWaitPeriod; + else buttonWaitPeriodP2 = drumWaitPeriod; + lastHitValue++; + if (lastHitValue >= drumMax) lastHitValue = drumMin; + return lastHitValue; + } else { + return 0; } } @@ -321,7 +325,10 @@ Init () { auto drum = openConfigSection (config, "drum"); if (drum) drumWaitPeriod = readConfigInt (drum, "wait_period", drumWaitPeriod); auto taikoController = openConfigSection (config, "controller"); - if (taikoController) useTaikoController = readConfigBool (taikoController, "analog", useTaikoController); + if (taikoController) { + printf("Using analog input mode. All other input has been disabled.\n"); + useTaikoController = readConfigBool (taikoController, "analog", useTaikoController); + } toml_free (config); }