fix buggy output stuff, which behaved weird when using relais true

This commit is contained in:
DeltaLima 2024-12-05 02:38:44 +01:00
parent 26a0c6603d
commit 3c14910747
4 changed files with 28 additions and 25 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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";

View file

@ -501,6 +501,11 @@ void WEBgrowSettings() {
body += "LED brightness: <input type='range' id='PinLEDPWM' name='PinLEDPWM' min='0' max='255' value='";
body += PinLEDPWM;
body += "'/> %<br>\n";
} else {
body += "LED on/off: <select id='PinLEDPWM' name='PinLEDPWM' required>\n";
body += "<option value='1'" + returnStrSelected(PinLEDPWM, 1) + ">On</option>\n";
body += "<option value='0'" + returnStrSelected(PinLEDPWM, 0) + ">Off</option>\n";
body += "</select><br>\n";
}
if(UseFANrelais == false) {
@ -509,8 +514,8 @@ void WEBgrowSettings() {
body += "'/> %<br>\n";
} else {
body += "FAN on/off: <select id='PinFANPWM' name='PinFANPWM' required>\n";
body += "<option value='1'" + returnStrSelected(PinFANPWM, 1) + ">Yes</option>\n";
body += "<option value='0'" + returnStrSelected(PinFANPWM, 0) + ">No</option>\n";
body += "<option value='1'" + returnStrSelected(PinFANPWM, 1) + ">On</option>\n";
body += "<option value='0'" + returnStrSelected(PinFANPWM, 0) + ">Off</option>\n";
body += "</select><br>\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();
}
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);