From 091d4d90bf8e5fa3ee156bc7783d2bc4abedb5c5 Mon Sep 17 00:00:00 2001 From: Luke Arntson Date: Wed, 17 Jan 2024 19:27:42 -0500 Subject: [PATCH] Turbo Available / update pin fix (#805) * Turbo Available / update pin fix * Moved turbo migrations to their own check (0.7.6+ upgrades will require this type of checking) * Silly comment fix --- src/addons/turbo.cpp | 21 +++++++++++---------- src/config_utils.cpp | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/addons/turbo.cpp b/src/addons/turbo.cpp index e2634c180..f59e72b3b 100644 --- a/src/addons/turbo.cpp +++ b/src/addons/turbo.cpp @@ -12,24 +12,25 @@ #define TURBO_SHOT_MAX 30 bool TurboInput::available() { - return Storage::getInstance().getAddonOptions().turboOptions.enabled; -} - -void TurboInput::setup() -{ - const TurboOptions& options = Storage::getInstance().getAddonOptions().turboOptions; - Gamepad * gamepad = Storage::getInstance().GetGamepad(); - uint32_t now = getMillis(); - // Turbo Button initialized by void Gamepad::setup() + bool hasTurboAssigned = false; GpioAction* pinMappings = Storage::getInstance().getProfilePinMappings(); for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) { if ( pinMappings[pin] == GpioAction::BUTTON_PRESS_TURBO ) { - turboPin = pin; + hasTurboAssigned = true; + turboPin = pin; break; } } + return Storage::getInstance().getAddonOptions().turboOptions.enabled && (hasTurboAssigned == true); +} + +void TurboInput::setup() +{ + const TurboOptions& options = Storage::getInstance().getAddonOptions().turboOptions; + Gamepad * gamepad = Storage::getInstance().GetGamepad(); + uint32_t now = getMillis(); // Turbo Dial uint8_t shotCount = std::clamp(options.shotCount, TURBO_SHOT_MIN, TURBO_SHOT_MAX); diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 9779e03f6..019bfc16a 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -700,6 +700,7 @@ void gpioMappingsMigrationCore(Config& config) TiltOptions& tiltOptions = config.addonOptions.tiltOptions; KeyboardHostOptions& keyboardHostOptions = config.addonOptions.keyboardHostOptions; PSPassthroughOptions& psPassthroughOptions = config.addonOptions.psPassthroughOptions; + TurboOptions& turboOptions = config.addonOptions.turboOptions; const auto gamepadMaskToGpioAction = [&](Mask_t gpMask) -> GpioAction { @@ -1099,7 +1100,6 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(config.addonOptions.buzzerOptions.pin); markAddonPinIfUsed(config.addonOptions.focusModeOptions.pin); markAddonPinIfUsed(config.addonOptions.turboOptions.ledPin); - markAddonPinIfUsed(config.addonOptions.turboOptions.deprecatedButtonPin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupDialPin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn1Pin); markAddonPinIfUsed(config.addonOptions.turboOptions.shmupBtn2Pin); @@ -1181,6 +1181,19 @@ void gpioMappingsMigrationProfiles(Config& config) config.migrations.buttonProfilesMigrated = true; } +// Check for additional migrations for features 0.7.6+ +void checkAdditionalMigrations(Config& config) { + // Features converted here must set their previous deprecated pin/set value as well (pin = -1) + TurboOptions & turboOptions = config.addonOptions.turboOptions; + + // Convert turbo pin mapping to GPIO mapping config + if (turboOptions.enabled && isValidPin(turboOptions.deprecatedButtonPin)) { + // previous config had a value we haven't migrated yet, it can/should apply in the new config + config.gpioMappings.pins[turboOptions.deprecatedButtonPin].action = GpioAction::BUTTON_PRESS_TURBO; + turboOptions.deprecatedButtonPin = -1; // set our turbo options to -1 for subsequent calls + } +} + // populate existing configurations' buttonsMask and auxMask to mirror behavior // from the behavior before this code merged. totally new configs get their // board defaults via initUnsetPropertiesWithDefaults @@ -1331,6 +1344,9 @@ void ConfigUtils::load(Config& config) if (!config.migrations.buttonProfilesMigrated) gpioMappingsMigrationProfiles(config); + // Run additional migrations for 0.7.6+ upgrades + checkAdditionalMigrations(config); + // Update boardVersion, in case we migrated from an older version strncpy(config.boardVersion, GP2040VERSION, sizeof(config.boardVersion)); config.boardVersion[sizeof(config.boardVersion) - 1] = '\0'; @@ -1902,6 +1918,7 @@ bool ConfigUtils::fromJSON(Config& config, const char* data, size_t dataLen) // we need to run migrations here too, in case the json document changed pins or things derived from pins gpioMappingsMigrationCore(config); gpioMappingsMigrationProfiles(config); + checkAdditionalMigrations(config); return true; }