Skip to content

Commit

Permalink
Deallocate relay, button and IR pins prior to reallocation in JSON co…
Browse files Browse the repository at this point in the history
…nfig parser (#3294)
  • Loading branch information
Aircoookie committed Jul 19, 2023
1 parent 286e057 commit e3ee48b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
disablePullUp = !pull;
JsonArray hw_btn_ins = btn_obj[F("ins")];
if (!hw_btn_ins.isNull()) {
for (uint8_t b = 0; b < WLED_MAX_BUTTONS; b++) { // deallocate existing button pins
pinManager.deallocatePin(btnPin[b], PinOwner::Button); // does nothing if trying to deallocate a pin with PinOwner != Button
}
uint8_t s = 0;
for (JsonObject btn : hw_btn_ins) {
CJSON(buttonType[s], btn["type"]);
Expand Down Expand Up @@ -264,6 +267,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {

int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
if (hw_ir_pin > -2) {
pinManager.deallocatePin(irPin, PinOwner::IR);
if (pinManager.allocatePin(hw_ir_pin, false, PinOwner::IR)) {
irPin = hw_ir_pin;
} else {
Expand All @@ -276,6 +280,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
JsonObject relay = hw[F("relay")];
int hw_relay_pin = relay["pin"] | -2;
if (hw_relay_pin > -2) {
pinManager.deallocatePin(rlyPin, PinOwner::Relay);
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
rlyPin = hw_relay_pin;
pinMode(rlyPin, OUTPUT);
Expand Down

0 comments on commit e3ee48b

Please sign in to comment.