From e3ee48b52ebf898aa2fc5a2ffbcf507670ff2c82 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 15ef0e1f..3eac1c56 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -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"]); @@ -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 { @@ -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);