From ff0542911b460edb5c0253c750774f5843e48015 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:21:45 +0100 Subject: [PATCH] Double set pin (#287) --- CustomDevices | 2 +- src/MF_Output/MFOutput.cpp | 13 ++++++++++--- src/MF_Output/Output.cpp | 13 +++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CustomDevices b/CustomDevices index d7e3f346..6a2b2831 160000 --- a/CustomDevices +++ b/CustomDevices @@ -1 +1 @@ -Subproject commit d7e3f346f672674cba950f8c0156ff62fa14e288 +Subproject commit 6a2b2831bb450ba14116809c8a98d12d692ef024 diff --git a/src/MF_Output/MFOutput.cpp b/src/MF_Output/MFOutput.cpp index 78b21bfa..cf35fb88 100644 --- a/src/MF_Output/MFOutput.cpp +++ b/src/MF_Output/MFOutput.cpp @@ -14,16 +14,23 @@ MFOutput::MFOutput() void MFOutput::attach(uint8_t pin) { _pin = pin; -#if !defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_ARCH_RP2040) + pinMode(_pin, OUTPUT_12MA); +#else pinMode(_pin, OUTPUT); - set(_value); #endif + set(LOW); } void MFOutput::set(uint8_t value) { _value = value; - analogWrite(_pin, _value); + if (_value == 0xFF) + digitalWrite(_pin, HIGH); + else if (_value == 0x00) + digitalWrite(_pin, LOW); + else + analogWrite(_pin, _value); } void MFOutput::powerSavingMode(bool state) diff --git a/src/MF_Output/Output.cpp b/src/MF_Output/Output.cpp index 084311f0..b8a9d22f 100644 --- a/src/MF_Output/Output.cpp +++ b/src/MF_Output/Output.cpp @@ -29,10 +29,6 @@ namespace Output return; outputs[outputsRegistered] = MFOutput(); outputs[outputsRegistered].attach(pin); -#if defined(ARDUINO_ARCH_RP2040) - pinMode(pin, OUTPUT_12MA); - analogWrite(pin, false); -#endif outputsRegistered++; #ifdef DEBUG2CMDMESSENGER cmdMessenger.sendCmd(kDebug, F("Added output")); @@ -52,9 +48,14 @@ namespace Output // Read led state argument, interpret string as boolean int pin = cmdMessenger.readInt16Arg(); int state = cmdMessenger.readInt16Arg(); + // Set led - analogWrite(pin, state); // why does the UI sends the pin number and not the x.th output number like other devices? - // output[pin].set(state); // once this is changed uncomment this + if (state == 0xFF) + digitalWrite(pin, HIGH); + else if (state == 0x00) + digitalWrite(pin, LOW); + else + analogWrite(pin, state); } void PowerSave(bool state)