Skip to content

Commit

Permalink
Turbo Available / update pin fix (#805)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
arntsonl authored Jan 18, 2024
1 parent 17f6031 commit 091d4d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/addons/turbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(options.shotCount, TURBO_SHOT_MIN, TURBO_SHOT_MAX);
Expand Down
19 changes: 18 additions & 1 deletion src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

0 comments on commit 091d4d9

Please sign in to comment.