Skip to content

Commit

Permalink
Merge 4/8-way mode toggle into one action
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelsin committed Jan 8, 2025
1 parent cca1a02 commit c4ee926
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
5 changes: 2 additions & 3 deletions headers/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ class Gamepad {
GamepadButtonMapping *mapAnalogRSXPos;
GamepadButtonMapping *mapAnalogRSYNeg;
GamepadButtonMapping *mapAnalogRSYPos;
GamepadButtonMapping *map4WayMode;
GamepadButtonMapping *map8WayMode;
GamepadButtonMapping *map48WayMode;

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

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

GamepadHotkey lastAction = HOTKEY_NONE;
Expand Down
3 changes: 1 addition & 2 deletions proto/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ enum GpioAction
BUTTON_PRESS_INPUT_REVERSE = 69;
SUSTAIN_FOCUS_MODE = 70;

SUSTAIN_4_WAY_MODE = 71;
SUSTAIN_8_WAY_MODE = 72;
SUSTAIN_4_8_WAY_MODE = 71;
}

enum GpioDirection
Expand Down
15 changes: 5 additions & 10 deletions src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +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);
map4WayMode = new GamepadButtonMapping(SUSTAIN_4_WAY_MODE);
map8WayMode = new GamepadButtonMapping(SUSTAIN_8_WAY_MODE);
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 @@ -163,8 +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_WAY_MODE: map4WayMode->pinMask |= 1 << pin; break;
case GpioAction::SUSTAIN_8_WAY_MODE: map8WayMode->pinMask |= 1 << pin; break;
case GpioAction::SUSTAIN_4_8_WAY_MODE: map48WayMode->pinMask |= 1 << pin; break;
default: break;
}
}
Expand Down Expand Up @@ -224,8 +222,7 @@ void Gamepad::reinit()
delete mapAnalogRSXPos;
delete mapAnalogRSYNeg;
delete mapAnalogRSYPos;
delete map4WayMode;
delete map8WayMode;
delete map48WayMode;

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

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

Expand Down Expand Up @@ -371,9 +368,7 @@ void Gamepad::read()
else if (values & mapButtonRS->pinMask) activeDpadMode = DpadMode::DPAD_MODE_RIGHT_ANALOG;
else activeDpadMode = options.dpadMode;

if (values & map4WayMode->pinMask) fourWayMode = true;
else if (values & map8WayMode->pinMask) fourWayMode = false;
else fourWayMode = options.fourWayMode;
map48WayModeToggle = (values & map48WayMode->pinMask);

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

export const PIN_DIRECTIONS = {
Expand Down
3 changes: 1 addition & 2 deletions www/src/Locales/en/PinMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +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_WAY_MODE: '4-Way Mode Enable',
SUSTAIN_8_WAY_MODE: '8-Way Mode Enable',
SUSTAIN_4_8_WAY_MODE: 'Toggle 4-Way Mode',
},
};

0 comments on commit c4ee926

Please sign in to comment.