From 492581b206e3b4ae37bf79bd98bd677cec949168 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 19 Jul 2023 18:02:57 +0200 Subject: [PATCH] Deallocate relay, button and IR pins prior to reallocation in JSON config parser (#3294) --- wled00/cfg.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 55b4db34..d694c9cc 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -233,6 +233,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"]); @@ -300,6 +303,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 { @@ -312,6 +316,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);