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

v0.7.6-RC3 Fix: manage ASSIGNED_TO_ADDON profile pins as well as core pins #726

Merged
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
36 changes: 34 additions & 2 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,23 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
}
else
{
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand All @@ -136,14 +143,21 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key0][key1];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
} else {
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand All @@ -157,14 +171,21 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key0][key1][key2];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
} else {
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand Down Expand Up @@ -1102,16 +1123,27 @@ std::string setPeripheralOptions()

// need to reserve previous/next pin for dp
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
uint8_t adjacent = peripheralOptions.blockUSB0.order ? -1 : 1;

Pin_t oldPinDplus = peripheralOptions.blockUSB0.dp;
docToPin(peripheralOptions.blockUSB0.dp, doc, "peripheral", "usb0", "dp");
if (isValidPin(peripheralOptions.blockUSB0.dp))
if (isValidPin(peripheralOptions.blockUSB0.dp)) {
// if D+ pin is now set, also set the pin that will be used for D-
gpioMappings[peripheralOptions.blockUSB0.dp+adjacent].action = GpioAction::ASSIGNED_TO_ADDON;
else if (isValidPin(oldPinDplus))
profiles.gpioMappingsSets[0].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
} else if (isValidPin(oldPinDplus)) {
// if D+ pin was set and is no longer, also unset the pin that was used for D-
gpioMappings[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
}

Storage::getInstance().save();

Expand Down