From d61073efccffaadf9d6bccaebc0014110bc6e12a Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Sun, 24 Nov 2024 19:03:56 -0800 Subject: [PATCH] Standalone Directional Input actions and Addon buttons as GpioAction (#1216) * Initial commit of standalone directional inputs in addition to mode-specific and DDI. * Moved directions experiment to feature branch. Updated Tilt addon to remove pin allocation in favor of GpioAction usage. * Removed Reverse button pin allocation in favor of GpioAction * Deprecated Reverse button pin proto definition. * Remove unused Reverse pin variable * Added SUSTAIN_FOCUS_MODE definition for toggling Focus Mode state * Removed Focus Mode pin allocation in favor of GpioAction * Removed deprecated pins from webconfig Addon views * Migrate previous addon pin settings to pin mappings and GpioActions * Revert deprecated pin names for focus, tilt, and reverse to previous names * Update tilt, focus, and reverse migrations to use fromProtoBuf * Remove stray equals sign --- headers/addons/focus_mode.h | 2 +- headers/addons/reverse.h | 3 +- headers/addons/tilt.h | 21 ++-- headers/gamepad.h | 12 ++ proto/config.proto | 26 ++--- proto/enums.proto | 18 +++ src/addons/focus_mode.cpp | 24 ++-- src/addons/reverse.cpp | 20 +++- src/addons/tilt.cpp | 170 ++++++++++++++------------- src/config_utils.cpp | 57 +++++---- src/configs/webconfig.cpp | 24 ---- src/gamepad.cpp | 188 +++++++++++++++++++++--------- www/src/Addons/FocusMode.tsx | 17 --- www/src/Addons/Reverse.tsx | 18 --- www/src/Addons/Tilt.tsx | 188 ------------------------------ www/src/Data/Pins.ts | 16 +++ www/src/Locales/en/PinMapping.jsx | 16 +++ 17 files changed, 374 insertions(+), 446 deletions(-) diff --git a/headers/addons/focus_mode.h b/headers/addons/focus_mode.h index 321fc47e2..254a64a61 100644 --- a/headers/addons/focus_mode.h +++ b/headers/addons/focus_mode.h @@ -44,7 +44,7 @@ class FocusModeAddon : public GPAddon { virtual std::string name() { return FocusModeName; } private: uint32_t buttonLockMask; - uint8_t focusModePin; + GamepadButtonMapping *mapFocusMode; }; #endif // _FocusMode_H_ \ No newline at end of file diff --git a/headers/addons/reverse.h b/headers/addons/reverse.h index ede8c5f95..1cbf3a7e0 100644 --- a/headers/addons/reverse.h +++ b/headers/addons/reverse.h @@ -55,6 +55,7 @@ class ReverseInput : public GPAddon { GamepadButtonMapping *mapDpadDown; GamepadButtonMapping *mapDpadLeft; GamepadButtonMapping *mapDpadRight; + GamepadButtonMapping *mapInputReverse; bool invertXAxis; bool invertYAxis; @@ -64,8 +65,6 @@ class ReverseInput : public GPAddon { uint8_t actionDown; uint8_t actionLeft; uint8_t actionRight; - - uint8_t pinButtonReverse; }; #endif // _Reverse_H_ \ No newline at end of file diff --git a/headers/addons/tilt.h b/headers/addons/tilt.h index 79a2ce45c..5cb4dc749 100644 --- a/headers/addons/tilt.h +++ b/headers/addons/tilt.h @@ -100,6 +100,7 @@ class TiltInput : public GPAddon { uint8_t SOCDCombine(SOCDMode, uint8_t); uint8_t SOCDGamepadClean(uint8_t); void OverrideGamepad(Gamepad*, uint8_t, uint8_t); + uint16_t getAnalogValue(bool isMin, bool isMax); uint8_t tiltLeftState; // Tilt State uint8_t tiltRightState; // Tilt Right Analog State DpadDirection lastGPUD; // Gamepad Last Up-Down @@ -109,25 +110,25 @@ class TiltInput : public GPAddon { DpadDirection rightLastTiltUD; // Tilt Last Up-Down DpadDirection rightLastTiltLR; // Gamepad Last Left-Right uint32_t dpadTime[4]; - uint8_t pinTilt1; uint8_t tilt1FactorLeftX; uint8_t tilt1FactorLeftY; uint8_t tilt1FactorRightX; uint8_t tilt1FactorRightY; - uint8_t pinTilt2; uint8_t tilt2FactorLeftX; uint8_t tilt2FactorLeftY; uint8_t tilt2FactorRightX; uint8_t tilt2FactorRightY; - uint8_t pinTiltLeftAnalogDown; - uint8_t pinTiltLeftAnalogUp; - uint8_t pinTiltLeftAnalogLeft; - uint8_t pinTiltLeftAnalogRight; - uint8_t pinTiltRightAnalogDown; - uint8_t pinTiltRightAnalogUp; - uint8_t pinTiltRightAnalogLeft; - uint8_t pinTiltRightAnalogRight; SOCDMode tiltSOCDMode; + GamepadButtonMapping *mapAnalogLSXNeg; + GamepadButtonMapping *mapAnalogLSXPos; + GamepadButtonMapping *mapAnalogLSYNeg; + GamepadButtonMapping *mapAnalogLSYPos; + GamepadButtonMapping *mapAnalogRSXNeg; + GamepadButtonMapping *mapAnalogRSXPos; + GamepadButtonMapping *mapAnalogRSYNeg; + GamepadButtonMapping *mapAnalogRSYPos; + GamepadButtonMapping *mapAnalogModLow; + GamepadButtonMapping *mapAnalogModHigh; }; #endif // _Tilt_H diff --git a/headers/gamepad.h b/headers/gamepad.h index b69cac78c..657316a63 100644 --- a/headers/gamepad.h +++ b/headers/gamepad.h @@ -176,6 +176,18 @@ class Gamepad { GamepadButtonMapping *mapButtonDP; GamepadButtonMapping *mapButtonLS; GamepadButtonMapping *mapButtonRS; + GamepadButtonMapping *mapDigitalUp; + GamepadButtonMapping *mapDigitalDown; + GamepadButtonMapping *mapDigitalLeft; + GamepadButtonMapping *mapDigitalRight; + GamepadButtonMapping *mapAnalogLSXNeg; + GamepadButtonMapping *mapAnalogLSXPos; + GamepadButtonMapping *mapAnalogLSYNeg; + GamepadButtonMapping *mapAnalogLSYPos; + GamepadButtonMapping *mapAnalogRSXNeg; + GamepadButtonMapping *mapAnalogRSXPos; + GamepadButtonMapping *mapAnalogRSYNeg; + GamepadButtonMapping *mapAnalogRSYPos; // gamepad specific proxy of debounced buttons --- 1 = active (inverse of the raw GPIO) // see GP2040::debounceGpioGetAll for details diff --git a/proto/config.proto b/proto/config.proto index 44593ec4d..054c17ffe 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -426,7 +426,7 @@ message ReverseOptions { optional bool enabled = 1; - optional int32 buttonPin = 2; + optional int32 buttonPin = 2 [deprecated = true]; optional int32 ledPin = 3; optional uint32 actionUp = 4; @@ -475,17 +475,17 @@ message TiltOptions { optional bool enabled = 1; - optional int32 tilt1Pin = 2; - optional int32 tilt2Pin = 3; - optional int32 deprecatedTiltFunctionPin = 4 [deprecated = true]; - optional int32 tiltLeftAnalogUpPin = 5; - optional int32 tiltLeftAnalogDownPin = 6; - optional int32 tiltLeftAnalogLeftPin = 7; - optional int32 tiltLeftAnalogRightPin = 8; - optional int32 tiltRightAnalogUpPin = 9; - optional int32 tiltRightAnalogDownPin = 10; - optional int32 tiltRightAnalogLeftPin = 11; - optional int32 tiltRightAnalogRightPin = 12; + optional int32 tilt1Pin = 2 [deprecated = true]; + optional int32 tilt2Pin = 3 [deprecated = true]; + optional int32 tiltFunctionPin = 4 [deprecated = true]; + optional int32 tiltLeftAnalogUpPin = 5 [deprecated = true]; + optional int32 tiltLeftAnalogDownPin = 6 [deprecated = true]; + optional int32 tiltLeftAnalogLeftPin = 7 [deprecated = true]; + optional int32 tiltLeftAnalogRightPin = 8 [deprecated = true]; + optional int32 tiltRightAnalogUpPin = 9 [deprecated = true]; + optional int32 tiltRightAnalogDownPin = 10 [deprecated = true]; + optional int32 tiltRightAnalogLeftPin = 11 [deprecated = true]; + optional int32 tiltRightAnalogRightPin = 12 [deprecated = true]; optional SOCDMode tiltSOCDMode = 13; @@ -691,7 +691,7 @@ message KeyboardHostOptions message FocusModeOptions { optional bool enabled = 1; - optional int32 pin = 2; + optional int32 pin = 2 [deprecated = true]; optional int32 buttonLockMask = 3; optional bool oledLockEnabled = 4; optional bool rgbLockEnabled = 5; diff --git a/proto/enums.proto b/proto/enums.proto index 7fa979950..1473951e5 100644 --- a/proto/enums.proto +++ b/proto/enums.proto @@ -243,6 +243,24 @@ enum GpioAction BUTTON_PRESS_E10 = 52; BUTTON_PRESS_E11 = 53; BUTTON_PRESS_E12 = 54; + + DIGITAL_DIRECTION_UP = 55; + DIGITAL_DIRECTION_DOWN = 56; + DIGITAL_DIRECTION_LEFT = 57; + DIGITAL_DIRECTION_RIGHT = 58; + ANALOG_DIRECTION_LS_X_NEG = 59; + ANALOG_DIRECTION_LS_X_POS = 60; + ANALOG_DIRECTION_LS_Y_NEG = 61; + ANALOG_DIRECTION_LS_Y_POS = 62; + ANALOG_DIRECTION_RS_X_NEG = 63; + ANALOG_DIRECTION_RS_X_POS = 64; + ANALOG_DIRECTION_RS_Y_NEG = 65; + ANALOG_DIRECTION_RS_Y_POS = 66; + ANALOG_DIRECTION_MOD_LOW = 67; + ANALOG_DIRECTION_MOD_HIGH = 68; + + BUTTON_PRESS_INPUT_REVERSE = 69; + SUSTAIN_FOCUS_MODE = 70; } enum GpioDirection diff --git a/src/addons/focus_mode.cpp b/src/addons/focus_mode.cpp index 74014b55c..094f77426 100644 --- a/src/addons/focus_mode.cpp +++ b/src/addons/focus_mode.cpp @@ -4,23 +4,31 @@ bool FocusModeAddon::available() { const FocusModeOptions& options = Storage::getInstance().getAddonOptions().focusModeOptions; - return options.enabled && - options.buttonLockMask != 0 && - isValidPin(options.pin); + return options.enabled && options.buttonLockMask != 0; } void FocusModeAddon::setup() { const FocusModeOptions& options = Storage::getInstance().getAddonOptions().focusModeOptions; buttonLockMask = options.buttonLockMask; - focusModePin = options.pin; - gpio_init(focusModePin); // Initialize pin - gpio_set_dir(focusModePin, GPIO_IN); // Set as INPUT - gpio_pull_up(focusModePin); // Set as PULLUP + + // Setup Focus Mode + mapFocusMode = new GamepadButtonMapping(0); + + GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings(); + for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) + { + switch (pinMappings[pin].action) { + case GpioAction::SUSTAIN_FOCUS_MODE: mapFocusMode->pinMask |= 1 << pin; break; + default: break; + } + } + } void FocusModeAddon::process() { Gamepad * gamepad = Storage::getInstance().GetGamepad(); - if (!gpio_get(focusModePin)) { + Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio; + if (values & mapFocusMode->pinMask) { if (buttonLockMask & GAMEPAD_MASK_DU) { gamepad->state.dpad &= ~GAMEPAD_MASK_UP; } diff --git a/src/addons/reverse.cpp b/src/addons/reverse.cpp index b46e98198..cbb35d17a 100644 --- a/src/addons/reverse.cpp +++ b/src/addons/reverse.cpp @@ -6,16 +6,22 @@ bool ReverseInput::available() { const ReverseOptions& options = Storage::getInstance().getAddonOptions().reverseOptions; - pinButtonReverse = options.buttonPin; - return options.enabled && isValidPin(options.buttonPin); + return options.enabled; } void ReverseInput::setup() { // Setup Reverse Input Button - gpio_init(pinButtonReverse); // Initialize pin - gpio_set_dir(pinButtonReverse, GPIO_IN); // Set as INPUT - gpio_pull_up(pinButtonReverse); // Set as PULLUP + mapInputReverse = new GamepadButtonMapping(0); + + GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings(); + for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) + { + switch (pinMappings[pin].action) { + case GpioAction::BUTTON_PRESS_INPUT_REVERSE: mapInputReverse->pinMask |= 1 << pin; break; + default: break; + } + } // Setup Reverse LED if available const ReverseOptions& options = Storage::getInstance().getAddonOptions().reverseOptions; @@ -45,7 +51,9 @@ void ReverseInput::setup() } void ReverseInput::update() { - state = !gpio_get(pinButtonReverse); + Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio; + + state = (values & mapInputReverse->pinMask); } uint8_t ReverseInput::input(uint32_t valueMask, uint16_t buttonMask, uint16_t buttonMaskReverse, uint8_t action, bool invertAxis) { diff --git a/src/addons/tilt.cpp b/src/addons/tilt.cpp index ce577e628..8b56e9e06 100644 --- a/src/addons/tilt.cpp +++ b/src/addons/tilt.cpp @@ -6,51 +6,48 @@ bool TiltInput::available() { const TiltOptions& options = Storage::getInstance().getAddonOptions().tiltOptions; - return options.enabled && ((options.tilt1Pin != -1) || (options.tilt2Pin != -1)); + return options.enabled; } void TiltInput::setup() { const TiltOptions& options = Storage::getInstance().getAddonOptions().tiltOptions; tiltSOCDMode = options.tiltSOCDMode; - pinTilt1 = options.tilt1Pin; tilt1FactorLeftX = options.factorTilt1LeftX; tilt1FactorLeftY = options.factorTilt1LeftY; tilt1FactorRightX = options.factorTilt1RightX; tilt1FactorRightY = options.factorTilt1RightY; - pinTilt2 = options.tilt2Pin; tilt2FactorLeftX = options.factorTilt2LeftX; tilt2FactorLeftY = options.factorTilt2LeftY; tilt2FactorRightX = options.factorTilt2RightX; tilt2FactorRightY = options.factorTilt2RightY; - pinTiltLeftAnalogDown = options.tiltLeftAnalogDownPin; - pinTiltLeftAnalogUp = options.tiltLeftAnalogUpPin; - pinTiltLeftAnalogLeft = options.tiltLeftAnalogLeftPin; - pinTiltLeftAnalogRight = options.tiltLeftAnalogRightPin; - pinTiltRightAnalogDown = options.tiltRightAnalogDownPin; - pinTiltRightAnalogUp = options.tiltRightAnalogUpPin; - pinTiltRightAnalogLeft = options.tiltRightAnalogLeftPin; - pinTiltRightAnalogRight = options.tiltRightAnalogRightPin; - - - // Setup Tilt Key - uint8_t pinTilt[10] = { - pinTilt1, - pinTilt2, - pinTiltLeftAnalogDown, - pinTiltLeftAnalogUp, - pinTiltLeftAnalogLeft, - pinTiltLeftAnalogRight, - pinTiltRightAnalogDown, - pinTiltRightAnalogUp, - pinTiltRightAnalogLeft, - pinTiltRightAnalogRight }; - - for (int i = 0; i < 10; i++) { - if (pinTilt[i] != (uint8_t)-1) { - gpio_init(pinTilt[i]); // Initialize pin - gpio_set_dir(pinTilt[i], GPIO_IN); // Set as INPUT - gpio_pull_up(pinTilt[i]); // Set as PULLUP + + mapAnalogLSXNeg = new GamepadButtonMapping(0); + mapAnalogLSXPos = new GamepadButtonMapping(0); + mapAnalogLSYNeg = new GamepadButtonMapping(0); + mapAnalogLSYPos = new GamepadButtonMapping(0); + mapAnalogRSXNeg = new GamepadButtonMapping(GAMEPAD_MASK_LEFT); + mapAnalogRSXPos = new GamepadButtonMapping(GAMEPAD_MASK_RIGHT); + mapAnalogRSYNeg = new GamepadButtonMapping(GAMEPAD_MASK_UP); + mapAnalogRSYPos = new GamepadButtonMapping(GAMEPAD_MASK_DOWN); + mapAnalogModLow = new GamepadButtonMapping(ANALOG_DIRECTION_MOD_LOW); + mapAnalogModHigh = new GamepadButtonMapping(ANALOG_DIRECTION_MOD_HIGH); + + GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings(); + for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) + { + switch (pinMappings[pin].action) { + case GpioAction::ANALOG_DIRECTION_LS_X_NEG: mapAnalogLSXNeg->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_X_POS: mapAnalogLSXPos->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_Y_NEG: mapAnalogLSYNeg->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_Y_POS: mapAnalogLSYPos->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_RS_X_NEG: mapAnalogRSXNeg->pinMask |= 1 << pin; break; + 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::ANALOG_DIRECTION_MOD_LOW: mapAnalogModLow->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_MOD_HIGH: mapAnalogModHigh->pinMask |= 1 << pin; break; + default: break; } } @@ -75,35 +72,20 @@ void TiltInput::setup() { void TiltInput::preprocess() { Gamepad* gamepad = Storage::getInstance().GetGamepad(); + Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio; // Need to invert since we're using pullups - tiltLeftState = 0; - if (pinTiltLeftAnalogUp != (uint8_t)-1) { - tiltLeftState |= (!gpio_get(pinTiltLeftAnalogUp) ? gamepad->mapDpadUp->buttonMask : 0); - } - if (pinTiltLeftAnalogDown != (uint8_t)-1) { - tiltLeftState |= (!gpio_get(pinTiltLeftAnalogDown) ? gamepad->mapDpadDown->buttonMask : 0); - } - if (pinTiltLeftAnalogLeft != (uint8_t)-1) { - tiltLeftState |= (!gpio_get(pinTiltLeftAnalogLeft) ? gamepad->mapDpadLeft->buttonMask : 0); - } - if (pinTiltLeftAnalogRight != (uint8_t)-1) { - tiltLeftState |= (!gpio_get(pinTiltLeftAnalogRight) ? gamepad->mapDpadRight->buttonMask : 0); - } + tiltLeftState = 0 + | ((values & mapAnalogLSXNeg->pinMask) ? mapAnalogLSXNeg->buttonMask : 0) + | ((values & mapAnalogLSXPos->pinMask) ? mapAnalogLSXPos->buttonMask : 0) + | ((values & mapAnalogLSYNeg->pinMask) ? mapAnalogLSYNeg->buttonMask : 0) + | ((values & mapAnalogLSYPos->pinMask) ? mapAnalogLSYPos->buttonMask : 0); - tiltRightState = 0; - if (pinTiltRightAnalogUp != (uint8_t)-1) { - tiltRightState |= (!gpio_get(pinTiltRightAnalogUp) ? gamepad->mapDpadUp->buttonMask : 0); - } - if (pinTiltRightAnalogDown != (uint8_t)-1) { - tiltRightState |= (!gpio_get(pinTiltRightAnalogDown) ? gamepad->mapDpadDown->buttonMask : 0); - } - if (pinTiltRightAnalogLeft != (uint8_t)-1) { - tiltRightState |= (!gpio_get(pinTiltRightAnalogLeft) ? gamepad->mapDpadLeft->buttonMask : 0); - } - if (pinTiltRightAnalogRight != (uint8_t)-1) { - tiltRightState |= (!gpio_get(pinTiltRightAnalogRight) ? gamepad->mapDpadRight->buttonMask : 0); - } + tiltRightState = 0 + | ((values & mapAnalogRSXNeg->pinMask) ? mapAnalogRSXNeg->buttonMask : 0) + | ((values & mapAnalogRSXPos->pinMask) ? mapAnalogRSXPos->buttonMask : 0) + | ((values & mapAnalogRSYNeg->pinMask) ? mapAnalogRSYNeg->buttonMask : 0) + | ((values & mapAnalogRSYPos->pinMask) ? mapAnalogRSYPos->buttonMask : 0); // Convert gamepad from process() output to uint8 value uint8_t gamepadState = gamepad->state.dpad; @@ -121,15 +103,11 @@ void TiltInput::process() OverrideGamepad(gamepad, tiltLeftState, tiltRightState); } -//The character's movement changes depending on the degree to which the stick is tilted. -//I added the functionality to allow the all - button controller to perform the operations that can be performed by the sticks. -//Two buttons, tilt1 and tilt2, have been implemented. -//While pressing these buttons, pressing the left or right analog stick will cause the character to walk or walk more slowly. -//Since this is an auxiliary function for appeals and such, -//pressing Tilt1 and Tilt2 at the same time will cause the light analog stick to correspond to each of the DPad methods. void TiltInput::OverrideGamepad(Gamepad* gamepad, uint8_t dpad1, uint8_t dpad2) { - bool pinTilt1Pressed = (pinTilt1 != (uint8_t)-1) ? !gpio_get(pinTilt1) : false; - bool pinTilt2Pressed = (pinTilt2 != (uint8_t)-1) ? !gpio_get(pinTilt2) : false; + Mask_t values = gamepad->debouncedGpio; + + bool pinTilt1Pressed = (values & mapAnalogModLow->pinMask); + bool pinTilt2Pressed = (values & mapAnalogModHigh->pinMask); // Scales input from 0-100% of maximum input double scaledTilt1FactorLeftX = 1.0 - (tilt1FactorLeftX / 100.0); @@ -146,33 +124,67 @@ void TiltInput::OverrideGamepad(Gamepad* gamepad, uint8_t dpad1, uint8_t dpad2) midValue = DriverManager::getInstance().getDriver()->GetJoystickMidValue(); } + uint16_t leftXValue = midValue; + uint16_t leftYValue = midValue; + uint16_t rightXValue = midValue; + uint16_t rightYValue = midValue; + if (pinTilt1Pressed && pinTilt2Pressed) { - // inputs act as dpad - gamepad->state.dpad |= dpad1|dpad2; + if (dpad2 > 0) { + // right inputs act as dpad + gamepad->state.dpad |= dpad2; + } else { + // prioritize tilt 1 + leftXValue = getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask))) * scaledTilt1FactorLeftX; + leftYValue = getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask))) * scaledTilt1FactorLeftY; + + rightXValue = getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask))) * scaledTilt1FactorRightX; + rightYValue = getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask))) * scaledTilt1FactorRightY; + } } else { // analog input mode if (pinTilt1Pressed) { - gamepad->state.lx = dpadToAnalogX(dpad1) + (midValue - dpadToAnalogX(dpad1)) * scaledTilt1FactorLeftX; - gamepad->state.ly = dpadToAnalogY(dpad1) + (midValue - dpadToAnalogY(dpad1)) * scaledTilt1FactorLeftY; + leftXValue = getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask))) * scaledTilt1FactorLeftX; + leftYValue = getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask))) * scaledTilt1FactorLeftY; - gamepad->state.rx = dpadToAnalogX(dpad2) + (midValue - dpadToAnalogX(dpad2)) * scaledTilt1FactorRightX; - gamepad->state.ry = dpadToAnalogY(dpad2) + (midValue - dpadToAnalogY(dpad2)) * scaledTilt1FactorRightY; + rightXValue = getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask))) * scaledTilt1FactorRightX; + rightYValue = getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask))) * scaledTilt1FactorRightY; } else if (pinTilt2Pressed) { - gamepad->state.lx = dpadToAnalogX(dpad1) + (midValue - dpadToAnalogX(dpad1)) * scaledTilt2FactorLeftX; - gamepad->state.ly = dpadToAnalogY(dpad1) + (midValue - dpadToAnalogY(dpad1)) * scaledTilt2FactorLeftY; + leftXValue = getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask))) * scaledTilt2FactorLeftX; + leftYValue = getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask))) * scaledTilt2FactorLeftY; - gamepad->state.rx = dpadToAnalogX(dpad2) + (midValue - dpadToAnalogX(dpad2)) * scaledTilt2FactorRightX; - gamepad->state.ry = dpadToAnalogY(dpad2) + (midValue - dpadToAnalogY(dpad2)) * scaledTilt2FactorRightY; + rightXValue = getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask))) * scaledTilt2FactorRightX; + rightYValue = getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask)) + (midValue - getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask))) * scaledTilt2FactorRightY; } else { - gamepad->state.lx = dpadToAnalogX(dpad1); - gamepad->state.ly = dpadToAnalogY(dpad1); + leftXValue = getAnalogValue((values & mapAnalogLSXNeg->pinMask), (values & mapAnalogLSXPos->pinMask)); + leftYValue = getAnalogValue((values & mapAnalogLSYNeg->pinMask), (values & mapAnalogLSYPos->pinMask)); - gamepad->state.rx = dpadToAnalogX(dpad2); - gamepad->state.ry = dpadToAnalogY(dpad2); + rightXValue = getAnalogValue((values & mapAnalogRSXNeg->pinMask), (values & mapAnalogRSXPos->pinMask)); + rightYValue = getAnalogValue((values & mapAnalogRSYNeg->pinMask), (values & mapAnalogRSYPos->pinMask)); } } + + gamepad->state.lx = leftXValue; + gamepad->state.ly = leftYValue; + + gamepad->state.rx = rightXValue; + gamepad->state.ry = rightYValue; } +uint16_t TiltInput::getAnalogValue(bool isMin, bool isMax) { + uint16_t midValue = GAMEPAD_JOYSTICK_MID; + if ( DriverManager::getInstance().getDriver() != nullptr ) { + midValue = DriverManager::getInstance().getDriver()->GetJoystickMidValue(); + } + + if (isMin && !isMax) { + return GAMEPAD_JOYSTICK_MIN; + } else if (!isMin && isMax) { + return GAMEPAD_JOYSTICK_MAX; + } else { + return midValue; + } +} void TiltInput::SOCDTiltClean(SOCDMode socdMode) { // Left Stick SOCD Cleaning diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 05bc0e0f8..e064344d7 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -609,24 +609,24 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.tiltOptions INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, enabled, !!TILT_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt1Pin, PIN_TILT_1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt1Pin, (Pin_t)-1); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1LeftX, TILT1_FACTOR_LEFT_X); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1LeftY, TILT1_FACTOR_LEFT_Y); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1RightX, TILT1_FACTOR_RIGHT_X); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt1RightY, TILT1_FACTOR_RIGHT_Y); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt2Pin, PIN_TILT_2); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tilt2Pin, (Pin_t)-1); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2LeftX, TILT2_FACTOR_LEFT_X); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2LeftY, TILT2_FACTOR_LEFT_Y); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2RightX, TILT2_FACTOR_RIGHT_X); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, factorTilt2RightY, TILT2_FACTOR_RIGHT_Y); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogDownPin, PIN_TILT_LEFT_ANALOG_DOWN); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogUpPin, PIN_TILT_LEFT_ANALOG_UP); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogLeftPin, PIN_TILT_LEFT_ANALOG_LEFT); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogRightPin, PIN_TILT_LEFT_ANALOG_RIGHT); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogDownPin, PIN_TILT_RIGHT_ANALOG_DOWN); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogUpPin, PIN_TILT_RIGHT_ANALOG_UP); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogLeftPin, PIN_TILT_RIGHT_ANALOG_LEFT); - INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogRightPin, PIN_TILT_RIGHT_ANALOG_RIGHT); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogDownPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogUpPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogLeftPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltLeftAnalogRightPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogDownPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogUpPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogLeftPin, (Pin_t)-1); + INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltRightAnalogRightPin, (Pin_t)-1); INIT_UNSET_PROPERTY(config.addonOptions.tiltOptions, tiltSOCDMode, TILT_SOCD_MODE); // addonOptions.buzzerOptions @@ -760,7 +760,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.focusModeOptions INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, enabled, !!FOCUS_MODE_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, pin, FOCUS_MODE_PIN); + INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, pin, -1); INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, buttonLockMask, FOCUS_MODE_BUTTON_MASK); INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, buttonLockEnabled, !!FOCUS_MODE_BUTTON_LOCK_ENABLED); INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, macroLockEnabled, !!FOCUS_MODE_MACRO_LOCK_ENABLED); @@ -803,10 +803,12 @@ void gpioMappingsMigrationCore(Config& config) SliderOptions& jsSliderOptions = config.addonOptions.deprecatedSliderOptions; SOCDSliderOptions& socdSliderOptions = config.addonOptions.socdSliderOptions; PeripheralOptions& peripheralOptions = config.peripheralOptions; - TiltOptions& tiltOptions = config.addonOptions.tiltOptions; KeyboardHostOptions& keyboardHostOptions = config.addonOptions.keyboardHostOptions; PSPassthroughOptions& psPassthroughOptions = config.addonOptions.psPassthroughOptions; TurboOptions& turboOptions = config.addonOptions.turboOptions; + TiltOptions& tiltOptions = config.addonOptions.tiltOptions; + FocusModeOptions& focusModeOptions = config.addonOptions.focusModeOptions; + ReverseOptions& reverseOptions = config.addonOptions.reverseOptions; const auto gamepadMaskToGpioAction = [&](Mask_t gpMask) -> GpioAction { @@ -1002,6 +1004,14 @@ void gpioMappingsMigrationCore(Config& config) socdSliderOptions.deprecatedPinTwo = -1; } + if (focusModeOptions.enabled) { + fromProtoBuf(focusModeOptions.has_pin, &focusModeOptions.pin, GpioAction::SUSTAIN_FOCUS_MODE); + } + + if (reverseOptions.enabled) { + fromProtoBuf(reverseOptions.has_buttonPin, &reverseOptions.buttonPin, GpioAction::BUTTON_PRESS_INPUT_REVERSE); + } + // verify that tilt factors are not set to -1 if (tiltOptions.enabled) { if (tiltOptions.factorTilt1LeftX == -1) tiltOptions.factorTilt1LeftX = TILT1_FACTOR_LEFT_X; @@ -1012,6 +1022,17 @@ void gpioMappingsMigrationCore(Config& config) if (tiltOptions.factorTilt2LeftY == -1) tiltOptions.factorTilt2LeftY = TILT2_FACTOR_LEFT_Y; if (tiltOptions.factorTilt2RightX == -1) tiltOptions.factorTilt2RightX = TILT2_FACTOR_RIGHT_X; if (tiltOptions.factorTilt2RightY == -1) tiltOptions.factorTilt2RightY = TILT2_FACTOR_RIGHT_Y; + + fromProtoBuf(tiltOptions.has_tilt1Pin, &tiltOptions.tilt1Pin, GpioAction::ANALOG_DIRECTION_MOD_LOW); + fromProtoBuf(tiltOptions.has_tilt2Pin, &tiltOptions.tilt2Pin, GpioAction::ANALOG_DIRECTION_MOD_HIGH); + fromProtoBuf(tiltOptions.has_tiltLeftAnalogUpPin, &tiltOptions.tiltLeftAnalogUpPin, GpioAction::ANALOG_DIRECTION_LS_Y_NEG); + fromProtoBuf(tiltOptions.has_tiltLeftAnalogDownPin, &tiltOptions.tiltLeftAnalogDownPin, GpioAction::ANALOG_DIRECTION_LS_Y_POS); + fromProtoBuf(tiltOptions.has_tiltLeftAnalogLeftPin, &tiltOptions.tiltLeftAnalogLeftPin, GpioAction::ANALOG_DIRECTION_LS_X_NEG); + fromProtoBuf(tiltOptions.has_tiltLeftAnalogRightPin, &tiltOptions.tiltLeftAnalogRightPin, GpioAction::ANALOG_DIRECTION_LS_X_POS); + fromProtoBuf(tiltOptions.has_tiltRightAnalogUpPin, &tiltOptions.tiltRightAnalogUpPin, GpioAction::ANALOG_DIRECTION_RS_Y_NEG); + fromProtoBuf(tiltOptions.has_tiltRightAnalogDownPin, &tiltOptions.tiltRightAnalogDownPin, GpioAction::ANALOG_DIRECTION_RS_Y_POS); + fromProtoBuf(tiltOptions.has_tiltRightAnalogLeftPin, &tiltOptions.tiltRightAnalogLeftPin, GpioAction::ANALOG_DIRECTION_RS_X_NEG); + fromProtoBuf(tiltOptions.has_tiltRightAnalogRightPin, &tiltOptions.tiltRightAnalogRightPin, GpioAction::ANALOG_DIRECTION_RS_X_POS); } // Assign all potential board config pins @@ -1206,25 +1227,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(config.addonOptions.analogOptions.analogAdc2PinY); markAddonPinIfUsed(config.addonOptions.buzzerOptions.pin); markAddonPinIfUsed(config.addonOptions.buzzerOptions.enablePin); - markAddonPinIfUsed(config.addonOptions.focusModeOptions.pin); markAddonPinIfUsed(config.addonOptions.turboOptions.ledPin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupDialPin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn1Pin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn2Pin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn3Pin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn4Pin); - markAddonPinIfUsed(config.addonOptions.reverseOptions.buttonPin); markAddonPinIfUsed(config.addonOptions.reverseOptions.ledPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tilt1Pin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tilt2Pin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltLeftAnalogUpPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltLeftAnalogDownPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltLeftAnalogLeftPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltLeftAnalogRightPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltRightAnalogUpPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltRightAnalogDownPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltRightAnalogLeftPin); - markAddonPinIfUsed(config.addonOptions.tiltOptions.tiltRightAnalogRightPin); markAddonPinIfUsed(config.addonOptions.snesOptions.clockPin); markAddonPinIfUsed(config.addonOptions.snesOptions.latchPin); markAddonPinIfUsed(config.addonOptions.snesOptions.dataPin); diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index ab78f607c..631e22611 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -1481,29 +1481,18 @@ std::string setAddonOptions() docToValue(dualDirectionalOptions.enabled, doc, "DualDirectionalInputEnabled"); TiltOptions& tiltOptions = Storage::getInstance().getAddonOptions().tiltOptions; - docToPin(tiltOptions.tilt1Pin, doc, "tilt1Pin"); docToValue(tiltOptions.factorTilt1LeftX, doc, "factorTilt1LeftX"); docToValue(tiltOptions.factorTilt1LeftY, doc, "factorTilt1LeftY"); docToValue(tiltOptions.factorTilt1RightX, doc, "factorTilt1RightX"); docToValue(tiltOptions.factorTilt1RightY, doc, "factorTilt1RightY"); - docToPin(tiltOptions.tilt2Pin, doc, "tilt2Pin"); docToValue(tiltOptions.factorTilt2LeftX, doc, "factorTilt2LeftX"); docToValue(tiltOptions.factorTilt2LeftY, doc, "factorTilt2LeftY"); docToValue(tiltOptions.factorTilt2RightX, doc, "factorTilt2RightX"); docToValue(tiltOptions.factorTilt2RightY, doc, "factorTilt2RightY"); - docToPin(tiltOptions.tiltLeftAnalogUpPin, doc, "tiltLeftAnalogUpPin"); - docToPin(tiltOptions.tiltLeftAnalogDownPin, doc, "tiltLeftAnalogDownPin"); - docToPin(tiltOptions.tiltLeftAnalogLeftPin, doc, "tiltLeftAnalogLeftPin"); - docToPin(tiltOptions.tiltLeftAnalogRightPin, doc, "tiltLeftAnalogRightPin"); - docToPin(tiltOptions.tiltRightAnalogUpPin, doc, "tiltRightAnalogUpPin"); - docToPin(tiltOptions.tiltRightAnalogDownPin, doc, "tiltRightAnalogDownPin"); - docToPin(tiltOptions.tiltRightAnalogLeftPin, doc, "tiltRightAnalogLeftPin"); - docToPin(tiltOptions.tiltRightAnalogRightPin, doc, "tiltRightAnalogRightPin"); docToValue(tiltOptions.tiltSOCDMode, doc, "tiltSOCDMode"); docToValue(tiltOptions.enabled, doc, "TiltInputEnabled"); FocusModeOptions& focusModeOptions = Storage::getInstance().getAddonOptions().focusModeOptions; - docToPin(focusModeOptions.pin, doc, "focusModePin"); docToValue(focusModeOptions.buttonLockMask, doc, "focusModeButtonLockMask"); docToValue(focusModeOptions.buttonLockEnabled, doc, "focusModeButtonLockEnabled"); docToValue(focusModeOptions.macroLockEnabled, doc, "focusModeMacroLockEnabled"); @@ -1518,7 +1507,6 @@ std::string setAddonOptions() ReverseOptions& reverseOptions = Storage::getInstance().getAddonOptions().reverseOptions; docToValue(reverseOptions.enabled, doc, "ReverseInputEnabled"); - docToPin(reverseOptions.buttonPin, doc, "reversePin"); docToPin(reverseOptions.ledPin, doc, "reversePinLED"); docToValue(reverseOptions.actionUp, doc, "reverseActionUp"); docToValue(reverseOptions.actionDown, doc, "reverseActionDown"); @@ -1909,24 +1897,14 @@ std::string getAddonOptions() writeDoc(doc, "DualDirectionalInputEnabled", dualDirectionalOptions.enabled); const TiltOptions& tiltOptions = Storage::getInstance().getAddonOptions().tiltOptions; - writeDoc(doc, "tilt1Pin", cleanPin(tiltOptions.tilt1Pin)); writeDoc(doc, "factorTilt1LeftX", tiltOptions.factorTilt1LeftX); writeDoc(doc, "factorTilt1LeftY", tiltOptions.factorTilt1LeftY); writeDoc(doc, "factorTilt1RightX", tiltOptions.factorTilt1RightX); writeDoc(doc, "factorTilt1RightY", tiltOptions.factorTilt1RightY); - writeDoc(doc, "tilt2Pin", cleanPin(tiltOptions.tilt2Pin)); writeDoc(doc, "factorTilt2LeftX", tiltOptions.factorTilt2LeftX); writeDoc(doc, "factorTilt2LeftY", tiltOptions.factorTilt2LeftY); writeDoc(doc, "factorTilt2RightX", tiltOptions.factorTilt2RightX); writeDoc(doc, "factorTilt2RightY", tiltOptions.factorTilt2RightY); - writeDoc(doc, "tiltLeftAnalogUpPin", cleanPin(tiltOptions.tiltLeftAnalogUpPin)); - writeDoc(doc, "tiltLeftAnalogDownPin", cleanPin(tiltOptions.tiltLeftAnalogDownPin)); - writeDoc(doc, "tiltLeftAnalogLeftPin", cleanPin(tiltOptions.tiltLeftAnalogLeftPin)); - writeDoc(doc, "tiltLeftAnalogRightPin", cleanPin(tiltOptions.tiltLeftAnalogRightPin)); - writeDoc(doc, "tiltRightAnalogUpPin", cleanPin(tiltOptions.tiltRightAnalogUpPin)); - writeDoc(doc, "tiltRightAnalogDownPin", cleanPin(tiltOptions.tiltRightAnalogDownPin)); - writeDoc(doc, "tiltRightAnalogLeftPin", cleanPin(tiltOptions.tiltRightAnalogLeftPin)); - writeDoc(doc, "tiltRightAnalogRightPin", cleanPin(tiltOptions.tiltRightAnalogRightPin)); writeDoc(doc, "tiltSOCDMode", tiltOptions.tiltSOCDMode); writeDoc(doc, "TiltInputEnabled", tiltOptions.enabled); @@ -1938,7 +1916,6 @@ std::string getAddonOptions() writeDoc(doc, "PlayerNumAddonEnabled", playerNumberOptions.enabled); const ReverseOptions& reverseOptions = Storage::getInstance().getAddonOptions().reverseOptions; - writeDoc(doc, "reversePin", cleanPin(reverseOptions.buttonPin)); writeDoc(doc, "reversePinLED", cleanPin(reverseOptions.ledPin)); writeDoc(doc, "reverseActionUp", reverseOptions.actionUp); writeDoc(doc, "reverseActionDown", reverseOptions.actionDown); @@ -2024,7 +2001,6 @@ std::string getAddonOptions() writeDoc(doc, "analog1256EnableTriggers", ads1256Options.enableTriggers); const FocusModeOptions& focusModeOptions = Storage::getInstance().getAddonOptions().focusModeOptions; - writeDoc(doc, "focusModePin", cleanPin(focusModeOptions.pin)); writeDoc(doc, "focusModeButtonLockMask", focusModeOptions.buttonLockMask); writeDoc(doc, "focusModeButtonLockEnabled", focusModeOptions.buttonLockEnabled); writeDoc(doc, "focusModeMacroLockEnabled", focusModeOptions.macroLockEnabled); diff --git a/src/gamepad.cpp b/src/gamepad.cpp index c98b8b586..df699f5b6 100644 --- a/src/gamepad.cpp +++ b/src/gamepad.cpp @@ -35,42 +35,54 @@ void Gamepad::setup() // Configure pin mapping GpioMappingInfo* pinMappings = Storage::getInstance().getProfilePinMappings(); - mapDpadUp = new GamepadButtonMapping(GAMEPAD_MASK_UP); - mapDpadDown = new GamepadButtonMapping(GAMEPAD_MASK_DOWN); - mapDpadLeft = new GamepadButtonMapping(GAMEPAD_MASK_LEFT); - mapDpadRight = new GamepadButtonMapping(GAMEPAD_MASK_RIGHT); - mapButtonB1 = new GamepadButtonMapping(GAMEPAD_MASK_B1); - mapButtonB2 = new GamepadButtonMapping(GAMEPAD_MASK_B2); - mapButtonB3 = new GamepadButtonMapping(GAMEPAD_MASK_B3); - mapButtonB4 = new GamepadButtonMapping(GAMEPAD_MASK_B4); - mapButtonL1 = new GamepadButtonMapping(GAMEPAD_MASK_L1); - mapButtonR1 = new GamepadButtonMapping(GAMEPAD_MASK_R1); - mapButtonL2 = new GamepadButtonMapping(GAMEPAD_MASK_L2); - mapButtonR2 = new GamepadButtonMapping(GAMEPAD_MASK_R2); - mapButtonS1 = new GamepadButtonMapping(GAMEPAD_MASK_S1); - mapButtonS2 = new GamepadButtonMapping(GAMEPAD_MASK_S2); - mapButtonL3 = new GamepadButtonMapping(GAMEPAD_MASK_L3); - mapButtonR3 = new GamepadButtonMapping(GAMEPAD_MASK_R3); - mapButtonA1 = new GamepadButtonMapping(GAMEPAD_MASK_A1); - mapButtonA2 = new GamepadButtonMapping(GAMEPAD_MASK_A2); - mapButtonA3 = new GamepadButtonMapping(GAMEPAD_MASK_A3); - mapButtonA4 = new GamepadButtonMapping(GAMEPAD_MASK_A4); - mapButtonE1 = new GamepadButtonMapping(GAMEPAD_MASK_E1); - mapButtonE2 = new GamepadButtonMapping(GAMEPAD_MASK_E2); - mapButtonE3 = new GamepadButtonMapping(GAMEPAD_MASK_E3); - mapButtonE4 = new GamepadButtonMapping(GAMEPAD_MASK_E4); - mapButtonE5 = new GamepadButtonMapping(GAMEPAD_MASK_E5); - mapButtonE6 = new GamepadButtonMapping(GAMEPAD_MASK_E6); - mapButtonE7 = new GamepadButtonMapping(GAMEPAD_MASK_E7); - mapButtonE8 = new GamepadButtonMapping(GAMEPAD_MASK_E8); - mapButtonE9 = new GamepadButtonMapping(GAMEPAD_MASK_E9); - mapButtonE10 = new GamepadButtonMapping(GAMEPAD_MASK_E10); - mapButtonE11 = new GamepadButtonMapping(GAMEPAD_MASK_E11); - mapButtonE12 = new GamepadButtonMapping(GAMEPAD_MASK_E12); - mapButtonFn = new GamepadButtonMapping(AUX_MASK_FUNCTION); - mapButtonDP = new GamepadButtonMapping(SUSTAIN_DP_MODE_DP); - mapButtonLS = new GamepadButtonMapping(SUSTAIN_DP_MODE_LS); - mapButtonRS = new GamepadButtonMapping(SUSTAIN_DP_MODE_RS); + mapDpadUp = new GamepadButtonMapping(GAMEPAD_MASK_UP); + mapDpadDown = new GamepadButtonMapping(GAMEPAD_MASK_DOWN); + mapDpadLeft = new GamepadButtonMapping(GAMEPAD_MASK_LEFT); + mapDpadRight = new GamepadButtonMapping(GAMEPAD_MASK_RIGHT); + mapButtonB1 = new GamepadButtonMapping(GAMEPAD_MASK_B1); + mapButtonB2 = new GamepadButtonMapping(GAMEPAD_MASK_B2); + mapButtonB3 = new GamepadButtonMapping(GAMEPAD_MASK_B3); + mapButtonB4 = new GamepadButtonMapping(GAMEPAD_MASK_B4); + mapButtonL1 = new GamepadButtonMapping(GAMEPAD_MASK_L1); + mapButtonR1 = new GamepadButtonMapping(GAMEPAD_MASK_R1); + mapButtonL2 = new GamepadButtonMapping(GAMEPAD_MASK_L2); + mapButtonR2 = new GamepadButtonMapping(GAMEPAD_MASK_R2); + mapButtonS1 = new GamepadButtonMapping(GAMEPAD_MASK_S1); + mapButtonS2 = new GamepadButtonMapping(GAMEPAD_MASK_S2); + mapButtonL3 = new GamepadButtonMapping(GAMEPAD_MASK_L3); + mapButtonR3 = new GamepadButtonMapping(GAMEPAD_MASK_R3); + mapButtonA1 = new GamepadButtonMapping(GAMEPAD_MASK_A1); + mapButtonA2 = new GamepadButtonMapping(GAMEPAD_MASK_A2); + mapButtonA3 = new GamepadButtonMapping(GAMEPAD_MASK_A3); + mapButtonA4 = new GamepadButtonMapping(GAMEPAD_MASK_A4); + mapButtonE1 = new GamepadButtonMapping(GAMEPAD_MASK_E1); + mapButtonE2 = new GamepadButtonMapping(GAMEPAD_MASK_E2); + mapButtonE3 = new GamepadButtonMapping(GAMEPAD_MASK_E3); + mapButtonE4 = new GamepadButtonMapping(GAMEPAD_MASK_E4); + mapButtonE5 = new GamepadButtonMapping(GAMEPAD_MASK_E5); + mapButtonE6 = new GamepadButtonMapping(GAMEPAD_MASK_E6); + mapButtonE7 = new GamepadButtonMapping(GAMEPAD_MASK_E7); + mapButtonE8 = new GamepadButtonMapping(GAMEPAD_MASK_E8); + mapButtonE9 = new GamepadButtonMapping(GAMEPAD_MASK_E9); + mapButtonE10 = new GamepadButtonMapping(GAMEPAD_MASK_E10); + mapButtonE11 = new GamepadButtonMapping(GAMEPAD_MASK_E11); + mapButtonE12 = new GamepadButtonMapping(GAMEPAD_MASK_E12); + mapButtonFn = new GamepadButtonMapping(AUX_MASK_FUNCTION); + mapButtonDP = new GamepadButtonMapping(SUSTAIN_DP_MODE_DP); + mapButtonLS = new GamepadButtonMapping(SUSTAIN_DP_MODE_LS); + mapButtonRS = new GamepadButtonMapping(SUSTAIN_DP_MODE_RS); + mapDigitalUp = new GamepadButtonMapping(GAMEPAD_MASK_UP); + mapDigitalDown = new GamepadButtonMapping(GAMEPAD_MASK_DOWN); + mapDigitalLeft = new GamepadButtonMapping(GAMEPAD_MASK_LEFT); + mapDigitalRight = new GamepadButtonMapping(GAMEPAD_MASK_RIGHT); + mapAnalogLSXNeg = new GamepadButtonMapping(ANALOG_DIRECTION_LS_X_NEG); + mapAnalogLSXPos = new GamepadButtonMapping(ANALOG_DIRECTION_LS_X_POS); + mapAnalogLSYNeg = new GamepadButtonMapping(ANALOG_DIRECTION_LS_Y_NEG); + mapAnalogLSYPos = new GamepadButtonMapping(ANALOG_DIRECTION_LS_Y_POS); + mapAnalogRSXNeg = new GamepadButtonMapping(ANALOG_DIRECTION_RS_X_NEG); + mapAnalogRSXPos = new GamepadButtonMapping(ANALOG_DIRECTION_RS_X_POS); + mapAnalogRSYNeg = new GamepadButtonMapping(ANALOG_DIRECTION_RS_Y_NEG); + mapAnalogRSYPos = new GamepadButtonMapping(ANALOG_DIRECTION_RS_Y_POS); const auto assignCustomMappingToMaps = [&](GpioMappingInfo mapInfo, Pin_t pin) -> void { if (mapDpadUp->buttonMask & mapInfo.customDpadMask) mapDpadUp->pinMask |= 1 << pin; @@ -91,6 +103,10 @@ void Gamepad::setup() if (mapButtonR3->buttonMask & mapInfo.customButtonMask) mapButtonR3->pinMask |= 1 << pin; if (mapButtonA1->buttonMask & mapInfo.customButtonMask) mapButtonA1->pinMask |= 1 << pin; if (mapButtonA2->buttonMask & mapInfo.customButtonMask) mapButtonA2->pinMask |= 1 << pin; + if (mapDigitalUp->buttonMask & mapInfo.customDpadMask) mapDigitalUp->pinMask |= 1 << pin; + if (mapDigitalDown->buttonMask & mapInfo.customDpadMask) mapDigitalDown->pinMask |= 1 << pin; + if (mapDigitalLeft->buttonMask & mapInfo.customDpadMask) mapDigitalLeft->pinMask |= 1 << pin; + if (mapDigitalRight->buttonMask & mapInfo.customDpadMask) mapDigitalRight->pinMask |= 1 << pin; }; for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) @@ -133,6 +149,18 @@ void Gamepad::setup() case GpioAction::SUSTAIN_DP_MODE_LS: mapButtonLS->pinMask |= 1 << pin; break; case GpioAction::SUSTAIN_DP_MODE_RS: mapButtonRS->pinMask |= 1 << pin; break; case GpioAction::CUSTOM_BUTTON_COMBO: assignCustomMappingToMaps(pinMappings[pin], pin); break; + case GpioAction::DIGITAL_DIRECTION_UP: mapDigitalUp->pinMask |= 1 << pin; break; + case GpioAction::DIGITAL_DIRECTION_DOWN: mapDigitalDown->pinMask |= 1 << pin; break; + case GpioAction::DIGITAL_DIRECTION_LEFT: mapDigitalLeft->pinMask |= 1 << pin; break; + case GpioAction::DIGITAL_DIRECTION_RIGHT: mapDigitalRight->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_X_NEG: mapAnalogLSXNeg->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_X_POS: mapAnalogLSXPos->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_Y_NEG: mapAnalogLSYNeg->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_LS_Y_POS: mapAnalogLSYPos->pinMask |= 1 << pin; break; + case GpioAction::ANALOG_DIRECTION_RS_X_NEG: mapAnalogRSXNeg->pinMask |= 1 << pin; break; + 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; default: break; } } @@ -180,6 +208,18 @@ void Gamepad::reinit() delete mapButtonDP; delete mapButtonLS; delete mapButtonRS; + delete mapDigitalUp; + delete mapDigitalDown; + delete mapDigitalLeft; + delete mapDigitalRight; + delete mapAnalogLSXNeg; + delete mapAnalogLSXPos; + delete mapAnalogLSYNeg; + delete mapAnalogLSYPos; + delete mapAnalogRSXNeg; + delete mapAnalogRSXPos; + delete mapAnalogRSYNeg; + delete mapAnalogRSYPos; // reinitialize pin mappings this->setup(); @@ -221,7 +261,11 @@ void Gamepad::process() state.dpad = filterToFourWayMode(state.dpad); } + uint8_t dpadCheck = state.dpad; + uint8_t dpadOnlyMask = 0; + uint8_t dpadModeMask = 0; state.dpad = runSOCDCleaner(resolveSOCDMode(options), state.dpad); + dpadOnlyMask = ((dpadCheck & 0xF0) >> 4); switch (activeDpadMode) { @@ -232,9 +276,10 @@ void Gamepad::process() } state.lx = dpadToAnalogX(state.dpad); state.ly = dpadToAnalogY(state.dpad); - state.dpad = 0; + state.dpad &= ~dpadOnlyMask; + state.dpad = dpadOnlyMask; break; - + case DpadMode::DPAD_MODE_RIGHT_ANALOG: if (!hasLeftAnalogStick) { state.lx = joystickMid; @@ -242,18 +287,19 @@ void Gamepad::process() } state.rx = dpadToAnalogX(state.dpad); state.ry = dpadToAnalogY(state.dpad); - state.dpad = 0; + state.dpad &= ~dpadOnlyMask; + state.dpad = dpadOnlyMask; break; - + default: - if (!hasLeftAnalogStick) { - state.lx = joystickMid; - state.ly = joystickMid; - } - if (!hasRightAnalogStick) { - state.rx = joystickMid; - state.ry = joystickMid; - } + //if (!hasLeftAnalogStick) { + // state.lx = joystickMid; + // state.ly = joystickMid; + //} + //if (!hasRightAnalogStick) { + // state.rx = joystickMid; + // state.ry = joystickMid; + //} break; } } @@ -272,10 +318,14 @@ void Gamepad::read() | (values & mapButtonFn->pinMask) ? mapButtonFn->buttonMask : 0; state.dpad = 0 - | ((values & mapDpadUp->pinMask) ? mapDpadUp->buttonMask : 0) - | ((values & mapDpadDown->pinMask) ? mapDpadDown->buttonMask : 0) - | ((values & mapDpadLeft->pinMask) ? mapDpadLeft->buttonMask : 0) - | ((values & mapDpadRight->pinMask) ? mapDpadRight->buttonMask : 0) + | ((values & mapDpadUp->pinMask) ? mapDpadUp->buttonMask : 0) + | ((values & mapDpadDown->pinMask) ? mapDpadDown->buttonMask : 0) + | ((values & mapDpadLeft->pinMask) ? mapDpadLeft->buttonMask : 0) + | ((values & mapDpadRight->pinMask) ? mapDpadRight->buttonMask : 0) + | ((values & mapDigitalUp->pinMask) ? (mapDigitalUp->buttonMask) | (mapDigitalUp->buttonMask << 4) : 0) + | ((values & mapDigitalDown->pinMask) ? (mapDigitalDown->buttonMask) | (mapDigitalDown->buttonMask << 4) : 0) + | ((values & mapDigitalLeft->pinMask) ? (mapDigitalLeft->buttonMask) | (mapDigitalLeft->buttonMask << 4) : 0) + | ((values & mapDigitalRight->pinMask) ? (mapDigitalRight->buttonMask) | (mapDigitalRight->buttonMask << 4) : 0) ; state.buttons = 0 @@ -315,10 +365,36 @@ void Gamepad::read() else if (values & mapButtonRS->pinMask) activeDpadMode = DpadMode::DPAD_MODE_RIGHT_ANALOG; else activeDpadMode = options.dpadMode; - state.lx = joystickMid; - state.ly = joystickMid; - state.rx = joystickMid; - state.ry = joystickMid; + if (values & mapAnalogLSXNeg->pinMask) { + state.lx = GAMEPAD_JOYSTICK_MIN; + } else if (values & mapAnalogLSXPos->pinMask) { + state.lx = GAMEPAD_JOYSTICK_MAX; + } else { + state.lx = joystickMid; + } + if (values & mapAnalogLSYNeg->pinMask) { + state.ly = GAMEPAD_JOYSTICK_MIN; + } else if (values & mapAnalogLSYPos->pinMask) { + state.ly = GAMEPAD_JOYSTICK_MAX; + } else { + state.ly = joystickMid; + } + + if (values & mapAnalogRSXNeg->pinMask) { + state.rx = GAMEPAD_JOYSTICK_MIN; + } else if (values & mapAnalogRSXPos->pinMask) { + state.rx = GAMEPAD_JOYSTICK_MAX; + } else { + state.rx = joystickMid; + } + if (values & mapAnalogRSYNeg->pinMask) { + state.ry = GAMEPAD_JOYSTICK_MIN; + } else if (values & mapAnalogRSYPos->pinMask) { + state.ry = GAMEPAD_JOYSTICK_MAX; + } else { + state.ry = joystickMid; + } + state.lt = 0; state.rt = 0; } diff --git a/www/src/Addons/FocusMode.tsx b/www/src/Addons/FocusMode.tsx index 606ee89e4..8dd5a78a5 100644 --- a/www/src/Addons/FocusMode.tsx +++ b/www/src/Addons/FocusMode.tsx @@ -14,10 +14,6 @@ export const focusModeScheme = { .number() .required() .label('Focus Mode Add-On Enabled'), - focusModePin: yup - .number() - .label('Focus Mode Pin') - .validatePinWhenValue('FocusModeAddonEnabled'), focusModeButtonLockEnabled: yup .number() .label('Focus Mode Button Lock Enabled') @@ -49,19 +45,6 @@ const FocusMode = ({