1
0
mirror of synced 2024-11-24 15:10:16 +01:00

Preliminary analog input fix

This commit is contained in:
ShikyC 2024-01-04 17:57:12 -08:00
parent a9b48ab8ef
commit ca6959c8e8

View File

@ -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);
}