Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 4-way mode when enabled for both core gamepad and DDI #733

Merged
merged 2 commits into from Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions headers/addons/dualdirectional.h
Expand Up @@ -56,6 +56,8 @@ class DualDirectionalInput : public GPAddon {
private:
void debounce();
uint8_t gpadToBinary(DpadMode, GamepadState);
uint8_t updateDpadDDI(uint8_t dpad, DpadDirection direction);
uint8_t filterToFourWayModeDDI(uint8_t dpad);
void SOCDDualClean(SOCDMode);
uint8_t SOCDCombine(SOCDMode, uint8_t);
uint8_t SOCDGamepadClean(uint8_t, bool isLastWin);
Expand Down
50 changes: 49 additions & 1 deletion src/addons/dualdirectional.cpp
Expand Up @@ -71,6 +71,54 @@ void DualDirectionalInput::debounce()
}
}


uint8_t DualDirectionalInput::updateDpadDDI(uint8_t dpad, DpadDirection direction)
{
static bool inList[] = {false, false, false, false, false}; // correspond to DpadDirection: none, up, down, left, right
static list<DpadDirection> dpadList;

if(dpad & getMaskFromDirection(direction))
{
if(!inList[direction])
{
dpadList.push_back(direction);
inList[direction] = true;
}
}
else
{
if(inList[direction])
{
dpadList.remove(direction);
inList[direction] = false;
}
}

if(dpadList.empty()) {
return 0;
}
else {
return getMaskFromDirection(dpadList.back());
}
}

/**
* @brief Filter diagonals out of the dpad, making the device work as a 4-way lever.
*
* The most recent cardinal direction wins.
*
* @param dpad The GameState.dpad value.
* @return uint8_t The new dpad value.
*/
uint8_t DualDirectionalInput::filterToFourWayModeDDI(uint8_t dpad)
{
updateDpadDDI(dpad, DIRECTION_UP);
updateDpadDDI(dpad, DIRECTION_DOWN);
updateDpadDDI(dpad, DIRECTION_LEFT);
return updateDpadDDI(dpad, DIRECTION_RIGHT);
}


void DualDirectionalInput::preprocess()
{
const DualDirectionalOptions& options = Storage::getInstance().getAddonOptions().dualDirectionalOptions;
Expand All @@ -92,7 +140,7 @@ void DualDirectionalInput::preprocess()

// 4-way before SOCD, might have better history without losing any coherent functionality
if (options.fourWayMode) {
dualState = filterToFourWayMode(dualState);
dualState = filterToFourWayModeDDI(dualState);
}

// Combined Mode
Expand Down