Skip to content

Commit

Permalink
Add GpioAction for sustaining 4/8 way mode (#1260)
Browse files Browse the repository at this point in the history
* A take on handling mapping for sustain 4/8 way mode

* Merge 4/8-way mode toggle into one action
  • Loading branch information
Pelsin authored Jan 9, 2025
1 parent 0e6e0b8 commit eaef4ea
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions headers/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Gamepad {
GamepadButtonMapping *mapAnalogRSXPos;
GamepadButtonMapping *mapAnalogRSYNeg;
GamepadButtonMapping *mapAnalogRSYPos;
GamepadButtonMapping *map48WayMode;

// gamepad specific proxy of debounced buttons --- 1 = active (inverse of the raw GPIO)
// see GP2040::debounceGpioGetAll for details
Expand All @@ -213,6 +214,7 @@ class Gamepad {

GamepadOptions & options;
DpadMode activeDpadMode;
bool map48WayModeToggle;
const HotkeyOptions & hotkeyOptions;

GamepadHotkey lastAction = HOTKEY_NONE;
Expand Down
2 changes: 2 additions & 0 deletions proto/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ enum GpioAction

BUTTON_PRESS_INPUT_REVERSE = 69;
SUSTAIN_FOCUS_MODE = 70;

SUSTAIN_4_8_WAY_MODE = 71;
}

enum GpioDirection
Expand Down
11 changes: 8 additions & 3 deletions src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void Gamepad::setup()
mapAnalogRSXPos = new GamepadButtonMapping(ANALOG_DIRECTION_RS_X_POS);
mapAnalogRSYNeg = new GamepadButtonMapping(ANALOG_DIRECTION_RS_Y_NEG);
mapAnalogRSYPos = new GamepadButtonMapping(ANALOG_DIRECTION_RS_Y_POS);
map48WayMode = new GamepadButtonMapping(SUSTAIN_4_8_WAY_MODE);

const auto assignCustomMappingToMaps = [&](GpioMappingInfo mapInfo, Pin_t pin) -> void {
if (mapDpadUp->buttonMask & mapInfo.customDpadMask) mapDpadUp->pinMask |= 1 << pin;
Expand Down Expand Up @@ -161,6 +162,7 @@ void Gamepad::setup()
case GpioAction::ANALOG_DIRECTION_RS_X_POS: mapAnalogRSXPos->pinMask |= 1 << pin; break;
case GpioAction::ANALOG_DIRECTION_RS_Y_NEG: mapAnalogRSYNeg->pinMask |= 1 << pin; break;
case GpioAction::ANALOG_DIRECTION_RS_Y_POS: mapAnalogRSYPos->pinMask |= 1 << pin; break;
case GpioAction::SUSTAIN_4_8_WAY_MODE: map48WayMode->pinMask |= 1 << pin; break;
default: break;
}
}
Expand Down Expand Up @@ -220,6 +222,7 @@ void Gamepad::reinit()
delete mapAnalogRSXPos;
delete mapAnalogRSYNeg;
delete mapAnalogRSYPos;
delete map48WayMode;

// reinitialize pin mappings
this->setup();
Expand Down Expand Up @@ -257,7 +260,7 @@ void Gamepad::process()
}

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

Expand All @@ -279,7 +282,7 @@ void Gamepad::process()
state.dpad &= ~dpadOnlyMask;
state.dpad = dpadOnlyMask;
break;

case DpadMode::DPAD_MODE_RIGHT_ANALOG:
if (!hasLeftAnalogStick) {
state.lx = joystickMid;
Expand All @@ -290,7 +293,7 @@ void Gamepad::process()
state.dpad &= ~dpadOnlyMask;
state.dpad = dpadOnlyMask;
break;

default:
//if (!hasLeftAnalogStick) {
// state.lx = joystickMid;
Expand Down Expand Up @@ -365,6 +368,8 @@ void Gamepad::read()
else if (values & mapButtonRS->pinMask) activeDpadMode = DpadMode::DPAD_MODE_RIGHT_ANALOG;
else activeDpadMode = options.dpadMode;

map48WayModeToggle = (values & map48WayMode->pinMask);

if (values & mapAnalogLSXNeg->pinMask) {
state.lx = GAMEPAD_JOYSTICK_MIN;
} else if (values & mapAnalogLSXPos->pinMask) {
Expand Down
1 change: 1 addition & 0 deletions www/src/Data/Pins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const BUTTON_ACTIONS = {
ANALOG_DIRECTION_MOD_HIGH: 68,
BUTTON_PRESS_INPUT_REVERSE: 69,
SUSTAIN_FOCUS_MODE: 70,
SUSTAIN_4_8_WAY_MODE: 71,
} as const;

export const PIN_DIRECTIONS = {
Expand Down
1 change: 1 addition & 0 deletions www/src/Locales/en/PinMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ export default {
ANALOG_DIRECTION_MOD_HIGH: 'Analog Stick Modifier High',
BUTTON_PRESS_INPUT_REVERSE: 'Reverse Input',
SUSTAIN_FOCUS_MODE: 'Focus Mode Enable',
SUSTAIN_4_8_WAY_MODE: 'Toggle 4-Way Mode',
},
};

0 comments on commit eaef4ea

Please sign in to comment.