Skip to content

Commit

Permalink
Fix initialization of new profiles' blocked pins and counts (OpenStic…
Browse files Browse the repository at this point in the history
…kCommunity#1154)

* we need to update the pin count in protobuf for it to save properly

* retain assigned to addon/reserved actions on a new profile

old code used to assume that the profiles were copied from profile 1
and/or the pins blocked by addon API calls, such that all profiles'
assigned to addon/reserved pins were already set that way. however, now
creating new profiles, setProfileOptions might have to do that for the
first time
  • Loading branch information
bsstephan authored Sep 28, 2024
1 parent c0447ec commit e943bd1
Showing 1 changed file with 9 additions and 0 deletions.
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

0 comments on commit e943bd1

Please sign in to comment.