From 3c14910747e7f885c299f003b3c746dc29b19838 Mon Sep 17 00:00:00 2001 From: DeltaLima Date: Thu, 5 Dec 2024 02:38:44 +0100 Subject: [PATCH] fix buggy output stuff, which behaved weird when using relais true --- Arduino/CanGrow/CanGrow.ino | 9 ++++--- Arduino/CanGrow/CanGrow_SysFunctions.h | 6 +++-- Arduino/CanGrow/CanGrow_Version.h | 2 +- Arduino/CanGrow/CanGrow_WebFunctions.h | 36 ++++++++++++-------------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index f85a266..e286e24 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -71,13 +71,16 @@ void setup() { // set all OUTPUT to low - digitalWrite(PinFAN, HIGH); digitalWrite(PINwaterlevel, LOW); + + // For CanGrow 0.6 PCB this has to be HIGH, as its MOSFET driver + // is inverted. + digitalWrite(PinFAN, HIGH); digitalWrite(PinLED, HIGH); digitalWrite(PinPUMP, HIGH); // except PINsoilmoisture // PINsoilmoisture is always HIGH and gets LOW in moment of waterlevel measurement - digitalWrite(PINsoilmoisture, LOW); + digitalWrite(PINsoilmoisture, HIGH); // set PWM frequency to 13.37KHz analogWriteFreq(13370); @@ -100,7 +103,7 @@ void setup() { Serial.println(":: initialise I2C ::"); // initialise Wire for I2C Wire.begin(); - // ClockStretchLimit seems to have negative effects + // just for testing //Wire.setClockStretchLimit(2500); Serial.println(":: initialise display ::"); // initialise I2C display diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h index 29d2fb9..127afbd 100644 --- a/Arduino/CanGrow/CanGrow_SysFunctions.h +++ b/Arduino/CanGrow/CanGrow_SysFunctions.h @@ -449,10 +449,12 @@ void setOutput(byte Output, byte OutputState) { // TODO read config for inverted outputs if( (UseRelais == true) || (OutputPin == PinPUMP) ) { + // convert OutputState to bool when using relais, so we can invert it easy + bool OutputState_bool = OutputState; if(OutputInvert == true) { - OutputState_tmp = 1 - OutputState; + OutputState_tmp = 1 - OutputState_bool; } else { - OutputState_tmp = OutputState; + OutputState_tmp = OutputState_bool; } digitalWrite(OutputPin, OutputState_tmp); } else { diff --git a/Arduino/CanGrow/CanGrow_Version.h b/Arduino/CanGrow/CanGrow_Version.h index 66e88dc..ee9c0c1 100644 --- a/Arduino/CanGrow/CanGrow_Version.h +++ b/Arduino/CanGrow/CanGrow_Version.h @@ -1,5 +1,5 @@ /* CanGrow_Version.h gets generated from cangrow.sh */ const char* CanGrowVer = "0.1-dev"; -const char* CanGrowBuild = "461b816-20241205020134"; +const char* CanGrowBuild = "26a0c66-20241205023254"; diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h index 79f8450..c22584b 100644 --- a/Arduino/CanGrow/CanGrow_WebFunctions.h +++ b/Arduino/CanGrow/CanGrow_WebFunctions.h @@ -501,6 +501,11 @@ void WEBgrowSettings() { body += "LED brightness: %
\n"; + } else { + body += "LED on/off:
\n"; } if(UseFANrelais == false) { @@ -509,8 +514,8 @@ void WEBgrowSettings() { body += "'/> %
\n"; } else { body += "FAN on/off:
\n"; } @@ -748,14 +753,7 @@ void WEBhelp() { void POSTgrowSettings() { - if(UseLEDrelais == true) { - // if a relais is used to turn on grow light, we force PWM to max val - PinLEDPWM = 255; - } else { - // otherwise just do PWM - PinLEDPWM = webserver.arg("PinLEDPWM").toInt(); - } - + PinLEDPWM = webserver.arg("PinLEDPWM").toInt(); PinFANPWM = webserver.arg("PinFANPWM").toInt(); String GrowName_tmp = webserver.arg("GrowName"); GrowName_tmp.toCharArray(GrowName, 32); @@ -888,20 +886,20 @@ void POSTsystemSettings() { Serial.println(":: POSTsystemSettings ::"); // when user uses an relais for LED control, we force here PinLEDPWM to 255 - // to ensure nothing bad happens - if(UseLEDrelais == true) { + // to ensure nothing bad happens and its turned on + if(UseLEDrelais == false) { PinLEDPWM = 255; EEPROM.put(213, PinLEDPWM); EEPROM.commit(); - Serial.println("UseLEDrelais is 1, forcing PinLEDPWM to max to prevent relais damage"); + Serial.println("UseLEDrelais is 0, forcing PinLEDPWM to max to prevent relais damage and ensure its turned on"); } - //~ if(UseFANrelais == true) { - //~ PinFANPWM = 255; - //~ EEPROM.put(215, PinFANPWM); - //~ EEPROM.commit(); - //~ Serial.println("UseFANrelais is 1, forcing PinFANPWM to max to prevent relais damage"); - //~ } + if(UseFANrelais == false) { + PinFANPWM = 255; + EEPROM.put(215, PinFANPWM); + EEPROM.commit(); + Serial.println("UseFANrelais is 0, forcing PinFANPWM to max to prevent relais damage and ensure its turned on"); + } Serial.print("configured: "); Serial.println(configured);