Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initialization of new profiles' blocked pins and counts #1154

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ std::string setProfileOptions()
DynamicJsonDocument doc = get_post_data();

ProfileOptions& profileOptions = Storage::getInstance().getProfileOptions();
GpioMappings& coreMappings = Storage::getInstance().getGpioMappings();
JsonObject options = doc.as<JsonObject>();
JsonArray alts = options["alternativePinMappings"];
int altsIndex = 0;
Expand All @@ -551,15 +552,23 @@ std::string setProfileOptions()
for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) {
snprintf(pinName, 6, "pin%0*d", 2, pin);
// setting a pin shouldn't change a new existing addon/reserved pin
// but if the profile definition is new, we should still capture the addon/reserved state
if (profileOptions.gpioMappingsSets[altsIndex].pins[pin].action != GpioAction::ASSIGNED_TO_ADDON &&
profileOptions.gpioMappingsSets[altsIndex].pins[pin].action != GpioAction::RESERVED &&
(GpioAction)alt[pinName]["action"] != GpioAction::RESERVED &&
(GpioAction)alt[pinName]["action"] != GpioAction::ASSIGNED_TO_ADDON) {
profileOptions.gpioMappingsSets[altsIndex].pins[pin].action = (GpioAction)alt[pinName]["action"];
profileOptions.gpioMappingsSets[altsIndex].pins[pin].customButtonMask = (uint32_t)alt[pinName]["customButtonMask"];
profileOptions.gpioMappingsSets[altsIndex].pins[pin].customDpadMask = (uint32_t)alt[pinName]["customDpadMask"];
} else if ((coreMappings.pins[pin].action == GpioAction::RESERVED &&
(GpioAction)alt[pinName]["action"] == GpioAction::RESERVED) ||
(coreMappings.pins[pin].action == GpioAction::ASSIGNED_TO_ADDON &&
(GpioAction)alt[pinName]["action"] == GpioAction::ASSIGNED_TO_ADDON)) {
profileOptions.gpioMappingsSets[altsIndex].pins[pin].action = (GpioAction)alt[pinName]["action"];
}
}
profileOptions.gpioMappingsSets[altsIndex].pins_count = NUM_BANK0_GPIOS;

size_t profileLabelSize = sizeof(profileOptions.gpioMappingsSets[altsIndex].profileLabel);
strncpy(profileOptions.gpioMappingsSets[altsIndex].profileLabel, alt["profileLabel"], profileLabelSize - 1);
profileOptions.gpioMappingsSets[altsIndex].profileLabel[profileLabelSize - 1] = '\0';
Expand Down