Skip to content

Commit

Permalink
recreate turboPinMask when doing reinit() (when profiles are changed) (
Browse files Browse the repository at this point in the history
…#919)

* recreate turboPinMask when doing reinit() (when profiles are changed)

Fixes #918

* clear turboPinMask in case the new profile doesn't have it mapped
  • Loading branch information
bsstephan authored Mar 31, 2024
1 parent 91105bb commit d0678f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions headers/addons/turbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@
class TurboInput : public GPAddon {
public:
virtual bool available();
virtual void setup(); // TURBO Button Setup
virtual void setup(); // TURBO Button Setup
virtual void reinit();
virtual void preprocess() {}
virtual void process(); // TURBO Setting of buttons (Enable/Disable)
virtual void process(); // TURBO Setting of buttons (Enable/Disable)
virtual std::string name() { return TurboName; }
private:
void updateInterval(uint8_t shotCount);
void updateTurboShotCount(uint8_t turboShotCount);
Pin_t turboPin; // Pin for Turbo from Gamepad/BoardConfig
Mask_t turboPinMask; // Pin mask for Turbo pin
bool bDebState; // Debounce TURBO Button State
uint32_t uDebTime; // Debounce TURBO Button Time
Expand Down
22 changes: 17 additions & 5 deletions src/addons/turbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool TurboInput::available() {
{
if ( pinMappings[pin] == GpioAction::BUTTON_PRESS_TURBO ) {
hasTurboAssigned = true;
turboPin = pin;
turboPinMask = 1 << pin;
break;
}
}
Expand Down Expand Up @@ -90,10 +90,6 @@ void TurboInput::setup()
turboButtonsMask = 0;
}

if (isValidPin(turboPin)) {
turboPinMask = 1 << turboPin;
}

lastButtons = 0;
bDebState = false;
uDebTime = now;
Expand All @@ -109,6 +105,22 @@ void TurboInput::setup()
nextTimer = getMicro();
}

/**
* @brief Reset the turbo pin mask.
*/
void TurboInput::reinit()
{
turboPinMask = 0;
GpioAction* pinMappings = Storage::getInstance().getProfilePinMappings();
for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++)
{
if ( pinMappings[pin] == GpioAction::BUTTON_PRESS_TURBO ) {
turboPinMask = 1 << pin;
break;
}
}
}

void TurboInput::process()
{
Gamepad * gamepad = Storage::getInstance().GetGamepad();
Expand Down

0 comments on commit d0678f5

Please sign in to comment.