Skip to content

Commit

Permalink
remove the JS Slider addon, move it to core (OpenStickCommunity#1152)
Browse files Browse the repository at this point in the history
this removes a bunch of code to support the addon, naturally, but the
idea is the same, just in core. of note, the default mode when no slider
pins are active has been folded into the core gamepad setting, so a tiny
migration copies the user's default mode into the gamepad setting in
order to not violate expectations. the user can still change this
setting there via webconfig or hotkeys.

this also updates the DDI addon to get the active mode (rather than the
settings mode) so that it doesn't do weird cleaning and/or override
things, and updates the display code to show the active mode

Co-authored-by: Luke A <arntsonl@gmail.com>
  • Loading branch information
bsstephan and arntsonl authored Sep 27, 2024
1 parent 7491db6 commit 2ec5fa1
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 226 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ src/addons/keyboard_host.cpp
src/addons/keyboard_host_listener.cpp
src/addons/i2canalog1219.cpp
src/addons/i2c_gpio_pcf8575.cpp
src/addons/jslider.cpp
src/addons/display.cpp
src/addons/neopicoleds.cpp
src/addons/playernum.cpp
Expand Down
3 changes: 1 addition & 2 deletions configs/KB2040/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
#define KEY_BUTTON_A2 HID_KEY_F2 // A2 | ~ | Capture | ~ | 14 | ~ |
#define KEY_BUTTON_FN -1 // Hotkey Function |

#define JSLIDER_ENABLED 1
#define GPIO_PIN_06 GpioAction::SUSTAIN_DP_MODE_LS
#define GPIO_PIN_07 GpioAction::SUSTAIN_DP_MODE_RS

#define BOARD_LEDS_PIN 17

#define LED_BRIGHTNESS_MAXIMUM 50

#endif
#endif
3 changes: 1 addition & 2 deletions configs/OpenCore0/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
#define TURBO_ENABLED 1
#define GPIO_PIN_27 GpioAction::BUTTON_PRESS_TURBO

#define JSLIDER_ENABLED 1
#define GPIO_PIN_25 GpioAction::SUSTAIN_DP_MODE_LS
#define GPIO_PIN_24 GpioAction::SUSTAIN_DP_MODE_RS

Expand Down Expand Up @@ -130,4 +129,4 @@
#define FOCUS_MODE_BUTTON_LOCK_ENABLED 1


#endif
#endif
3 changes: 1 addition & 2 deletions configs/OpenCore0WASD/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
#define TURBO_ENABLED 1
#define GPIO_PIN_27 GpioAction::BUTTON_PRESS_TURBO

#define JSLIDER_ENABLED 1
#define GPIO_PIN_26 GpioAction::SUSTAIN_DP_MODE_LS
#define GPIO_PIN_25 GpioAction::SUSTAIN_DP_MODE_RS

Expand Down Expand Up @@ -128,4 +127,4 @@
#define FOCUS_MODE_BUTTON_LOCK_ENABLED 1


#endif
#endif
1 change: 0 additions & 1 deletion headers/addons/dualdirectional.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class DualDirectionalInput : public GPAddon {
DpadDirection lastGPLR; // Gamepad Last Left-Right
DpadDirection lastDualUD; // Dual Last Up-Down
DpadDirection lastDualLR; // Gamepad Last Left-Right
DpadMode dpadMode;
GamepadButtonMapping *mapDpadUp;
GamepadButtonMapping *mapDpadDown;
GamepadButtonMapping *mapDpadLeft;
Expand Down
44 changes: 0 additions & 44 deletions headers/addons/jslider.h

This file was deleted.

5 changes: 5 additions & 0 deletions headers/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Gamepad {
inline bool __attribute__((always_inline)) pressedE12() { return pressedButton(GAMEPAD_MASK_E12); }

const GamepadOptions& getOptions() const { return options; }
const DpadMode getActiveDpadMode() { return activeDpadMode; }

void setInputMode(InputMode inputMode) { options.inputMode = inputMode; }
void setSOCDMode(SOCDMode socdMode) { options.socdMode = socdMode; }
Expand Down Expand Up @@ -172,6 +173,9 @@ class Gamepad {
GamepadButtonMapping *mapButtonE11;
GamepadButtonMapping *mapButtonE12;
GamepadButtonMapping *mapButtonFn;
GamepadButtonMapping *mapButtonDP;
GamepadButtonMapping *mapButtonLS;
GamepadButtonMapping *mapButtonRS;

// gamepad specific proxy of debounced buttons --- 1 = active (inverse of the raw GPIO)
// see GP2040::debounceGpioGetAll for details
Expand All @@ -197,6 +201,7 @@ class Gamepad {
void processHotkeyAction(GamepadHotkey action);

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

GamepadHotkey lastAction = HOTKEY_NONE;
Expand Down
4 changes: 2 additions & 2 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ message SliderOptions
optional int32 deprecatedPinSliderTwo = 3 [deprecated = true];
optional DpadMode deprecatedModeOne = 4 [deprecated = true];
optional DpadMode deprecatedModeTwo = 5 [deprecated = true];
optional DpadMode modeDefault = 6;
optional DpadMode deprecatedModeDefault = 6;
}

message SOCDSliderOptions
Expand Down Expand Up @@ -794,7 +794,7 @@ message AddonOptions
optional OnBoardLedOptions onBoardLedOptions = 2;
optional AnalogOptions analogOptions = 3;
optional TurboOptions turboOptions = 4;
optional SliderOptions sliderOptions = 5;
optional SliderOptions deprecatedSliderOptions = 5;
optional ReverseOptions reverseOptions = 6;
optional AnalogADS1219Options analogADS1219Options = 7;
optional DualDirectionalOptions dualDirectionalOptions = 8;
Expand Down
9 changes: 4 additions & 5 deletions src/addons/dualdirectional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ bool DualDirectionalInput::available() {

void DualDirectionalInput::setup() {
const DualDirectionalOptions& options = Storage::getInstance().getAddonOptions().dualDirectionalOptions;
dpadMode = options.dpadMode;

mapDpadUp = new GamepadButtonMapping(GAMEPAD_MASK_UP);
mapDpadDown = new GamepadButtonMapping(GAMEPAD_MASK_DOWN);
Expand Down Expand Up @@ -127,14 +126,14 @@ void DualDirectionalInput::process()
Gamepad * gamepad = Storage::getInstance().GetGamepad();
uint8_t dualOut = dualState;
const SOCDMode socdMode = getSOCDMode(gamepad->getOptions());
uint8_t gamepadDpad = gpadToBinary(gamepad->getOptions().dpadMode, gamepad->state);
uint8_t gamepadDpad = gpadToBinary(gamepad->getActiveDpadMode(), gamepad->state);

// in mixed mode, we need to combine/re-clean the gamepad and DDI outputs to create a coherent behavior
// reminder that combination mode none with the DDI output set to the same thing as the gamepad
// output is, in practice, the same behavior as mixed mode, so it also is addressed here
if (options.combineMode == DualDirectionalCombinationMode::MIXED_MODE ||
(options.combineMode == DualDirectionalCombinationMode::NONE_MODE &&
gamepad->getOptions().dpadMode == options.dpadMode)) {
gamepad->getActiveDpadMode() == options.dpadMode)) {
if ( socdMode == SOCD_MODE_UP_PRIORITY || socdMode == SOCD_MODE_NEUTRAL ) {
// neutral/up priority SOCD cleaning are pretty simple, they just need to be re-neutralized
dualOut = SOCDCombine(socdMode, gamepadDpad);
Expand All @@ -145,14 +144,14 @@ void DualDirectionalInput::process()
// this is bypass SOCD, just OR them together
dualOut |= gamepadDpad;
}
OverrideGamepad(gamepad, gamepad->getOptions().dpadMode, dualOut);
OverrideGamepad(gamepad, gamepad->getActiveDpadMode(), dualOut);
} else if (options.combineMode != DualDirectionalCombinationMode::NONE_MODE) {
// this is either of the override modes, which we will treat the same way --- they replace
// the gamepad entirely in certain conditions: DDI Override if it has any data,
// Gamepad Override if gamepad doesn't have any data
if ((options.combineMode == DualDirectionalCombinationMode::DUAL_MODE && dualOut != 0) ||
(options.combineMode == DualDirectionalCombinationMode::GAMEPAD_MODE && gamepadDpad == 0)) {
OverrideGamepad(gamepad, gamepad->getOptions().dpadMode, dualOut);
OverrideGamepad(gamepad, gamepad->getActiveDpadMode(), dualOut);
}
} else {
// the DDI and gamepad outputs don't need to be mixed, so just apply DDI output to the gamepad
Expand Down
60 changes: 0 additions & 60 deletions src/addons/jslider.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions src/config_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ namespace ConfigLegacy
uint8_t ExtraButtonAddonEnabled;
uint8_t I2CAnalog1219InputEnabled;
//bool I2CDisplayAddonEnabled; // I2C is special case
uint8_t JSliderInputEnabled;
//bool NeoPicoLEDAddonEnabled; // NeoPico is special case
//bool PlayerLEDAddonEnabled; // PlayerLED is special case
uint8_t PlayerNumAddonEnabled;
Expand Down Expand Up @@ -1009,12 +1008,6 @@ bool ConfigUtils::fromLegacyStorage(Config& config)
SET_PROPERTY(analogADS1219Options, deprecatedI2cAddress, legacyAddonOptions.i2cAnalog1219Address);
SET_PROPERTY(analogADS1219Options, deprecatedI2cSpeed, legacyAddonOptions.i2cAnalog1219Speed);

SliderOptions& sliderOptions = config.addonOptions.sliderOptions;
config.addonOptions.has_sliderOptions = true;
SET_PROPERTY(sliderOptions, enabled, legacyAddonOptions.JSliderInputEnabled);
SET_PROPERTY(sliderOptions, deprecatedPinSliderOne, bytePinToIntPin(legacyAddonOptions.pinSliderLS));
SET_PROPERTY(sliderOptions, deprecatedPinSliderTwo, bytePinToIntPin(legacyAddonOptions.pinSliderRS));

PlayerNumberOptions& playerNumberOptions = config.addonOptions.playerNumberOptions;
config.addonOptions.has_playerNumberOptions = true;
SET_PROPERTY(playerNumberOptions, enabled, legacyAddonOptions.PlayerNumAddonEnabled);
Expand Down
67 changes: 57 additions & 10 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "addons/focus_mode.h"
#include "addons/i2canalog1219.h"
#include "addons/display.h"
#include "addons/jslider.h"
#include "addons/keyboard_host.h"
#include "addons/neopicoleds.h"
#include "addons/playernum.h"
Expand Down Expand Up @@ -566,14 +565,6 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
INIT_UNSET_PROPERTY(config.addonOptions.turboOptions, shmupBtnMask4, SHMUP_BUTTON4);
INIT_UNSET_PROPERTY(config.addonOptions.turboOptions, shmupMixMode, SHMUP_MIX_MODE);

// addonOptions.sliderOptions
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, enabled, !!JSLIDER_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, deprecatedPinSliderOne, (Pin_t)-1);
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, deprecatedPinSliderTwo, (Pin_t)-1);
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, deprecatedModeOne, SLIDER_MODE_ONE);
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, deprecatedModeTwo, SLIDER_MODE_TWO);
INIT_UNSET_PROPERTY(config.addonOptions.sliderOptions, modeDefault, SLIDER_MODE_ZERO);

// addonOptions.reverseOptions
INIT_UNSET_PROPERTY(config.addonOptions.reverseOptions, enabled, !!REVERSE_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.reverseOptions, buttonPin, (Pin_t)-1);
Expand Down Expand Up @@ -809,7 +800,7 @@ void gpioMappingsMigrationCore(Config& config)
PinMappings& deprecatedPinMappings = config.deprecatedPinMappings;
ExtraButtonOptions& extraButtonOptions = config.addonOptions.deprecatedExtraButtonOptions;
DualDirectionalOptions& ddiOptions = config.addonOptions.dualDirectionalOptions;
SliderOptions& jsSliderOptions = config.addonOptions.sliderOptions;
SliderOptions& jsSliderOptions = config.addonOptions.deprecatedSliderOptions;
SOCDSliderOptions& socdSliderOptions = config.addonOptions.socdSliderOptions;
PeripheralOptions& peripheralOptions = config.peripheralOptions;
TiltOptions& tiltOptions = config.addonOptions.tiltOptions;
Expand Down Expand Up @@ -1247,6 +1238,60 @@ void gpioMappingsMigrationCore(Config& config)
config.migrations.gpioMappingsMigrated = true;
}

// if the user previously had the JS slider addon enabled, copy its default to the
// core gamepad setting, since the functionality is within the core now
void migrateJSliderToCore(Config& config)
{
if (config.addonOptions.deprecatedSliderOptions.enabled) {
config.gamepadOptions.dpadMode = config.addonOptions.deprecatedSliderOptions.deprecatedModeDefault;
config.addonOptions.deprecatedSliderOptions.enabled = false;
}
}

// populate the alternative gpio mapping sets, aka profiles, with
// the old values or whatever is in the core mappings
// NOTE: this also handles initializations for a blank config! if/when the deprecated
// pin mappings go away, the remainder of this code should go in there (there was no point
// in duplicating it right now)
void gpioMappingsMigrationProfiles(Config& config)
{
AlternativePinMappings* deprecatedAlts = config.profileOptions.deprecatedAlternativePinMappings;

const auto assignProfilePinIfUsed = [&](uint8_t profileNum, Pin_t profilePin, GpioAction action) -> void {
if (isValidPin(profilePin)) {
config.profileOptions.gpioMappingsSets[profileNum].pins[profilePin].action = action;
}
};

for (uint8_t profileNum = 0; profileNum <= 2; profileNum++) {
for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) {
config.profileOptions.gpioMappingsSets[profileNum].pins[pin].action = config.gpioMappings.pins[pin].action;
}
// only check protobuf if profiles are defined
if (profileNum < config.profileOptions.deprecatedAlternativePinMappings_count) {
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonB1, GpioAction::BUTTON_PRESS_B1);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonB2, GpioAction::BUTTON_PRESS_B2);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonB3, GpioAction::BUTTON_PRESS_B3);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonB4, GpioAction::BUTTON_PRESS_B4);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonL1, GpioAction::BUTTON_PRESS_L1);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonR1, GpioAction::BUTTON_PRESS_R1);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonL2, GpioAction::BUTTON_PRESS_L2);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinButtonR2, GpioAction::BUTTON_PRESS_R2);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinDpadUp, GpioAction::BUTTON_PRESS_UP);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinDpadDown, GpioAction::BUTTON_PRESS_DOWN);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinDpadLeft, GpioAction::BUTTON_PRESS_LEFT);
assignProfilePinIfUsed(profileNum, deprecatedAlts[profileNum].pinDpadRight, GpioAction::BUTTON_PRESS_RIGHT);
}

// reminder that this must be set or else nanopb won't retain anything
config.profileOptions.gpioMappingsSets[profileNum].pins_count = NUM_BANK0_GPIOS;
}
// reminder that this must be set or else nanopb won't retain anything
config.profileOptions.gpioMappingsSets_count = 3;

config.migrations.buttonProfilesMigrated = true;
}

void migrateTurboPinToGpio(Config& config) {
// Features converted here must set their previous deprecated pin/set value as well (pin = -1)
TurboOptions & turboOptions = config.addonOptions.turboOptions;
Expand Down Expand Up @@ -1516,6 +1561,8 @@ void ConfigUtils::load(Config& config)
migrateAuthenticationMethods(config);
// Macro pins to gpio
migrateMacroPinsToGpio(config);
// Migrate old JS slider add-on to core
migrateJSliderToCore(config);

// Update boardVersion, in case we migrated from an older version
strncpy(config.boardVersion, GP2040VERSION, sizeof(config.boardVersion));
Expand Down
8 changes: 0 additions & 8 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,10 +1503,6 @@ std::string setAddonOptions()
AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options;
docToValue(analogADS1219Options.enabled, doc, "I2CAnalog1219InputEnabled");

SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions;
docToValue(sliderOptions.modeDefault, doc, "sliderModeZero");
docToValue(sliderOptions.enabled, doc, "JSliderInputEnabled");

PlayerNumberOptions& playerNumberOptions = Storage::getInstance().getAddonOptions().playerNumberOptions;
docToValue(playerNumberOptions.number, doc, "playerNumber");
docToValue(playerNumberOptions.enabled, doc, "PlayerNumAddonEnabled");
Expand Down Expand Up @@ -1928,10 +1924,6 @@ std::string getAddonOptions()
const AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options;
writeDoc(doc, "I2CAnalog1219InputEnabled", analogADS1219Options.enabled);

const SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions;
writeDoc(doc, "sliderModeZero", sliderOptions.modeDefault);
writeDoc(doc, "JSliderInputEnabled", sliderOptions.enabled);

const PlayerNumberOptions& playerNumberOptions = Storage::getInstance().getAddonOptions().playerNumberOptions;
writeDoc(doc, "playerNumber", playerNumberOptions.number);
writeDoc(doc, "PlayerNumAddonEnabled", playerNumberOptions.enabled);
Expand Down
Loading

0 comments on commit 2ec5fa1

Please sign in to comment.