From 40d017556404494708c58b3852650cbef4005159 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 26 Oct 2024 22:10:39 +0200 Subject: [PATCH] main stuff for adding new output is done. for i2c i have not idea atm what i need. --- Arduino/CanGrow/CanGrow.ino | 3 +- Arduino/CanGrow/include/CanGrow.h | 66 +++++++++-- Arduino/CanGrow/include/CanGrow_LittleFS.h | 12 +- .../include/Webserver/File_cangrow_CSS.h | 1 + .../CanGrow/include/Webserver/Page_system.h | 105 ++++++++++++++---- .../include/Webserver/Page_system_HTML.h | 23 ++-- 6 files changed, 158 insertions(+), 52 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 798c6bd..3999e49 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -133,7 +133,8 @@ void setup() { Webserver_Init(); Serial.printf(":: [SETUP] Usable Pins: %d\n", GPIOindex_length); for(byte i = 0; i < GPIOindex_length; i++) { - Serial.printf(":: [SETUP] Pin Index: %d, GPIO: %d, Notes: %d\n", i, GPIOindex[i].gpio, GPIOindex[i].note); + Serial.printf(":: [SETUP] Pin Index: %d, GPIO: %d, Notes: ", i, GPIOindex[i].gpio); + Serial.println(GPIO_Index_note_descr[GPIOindex[i].note]); } } diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index ea9e333..12f56db 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -77,7 +77,7 @@ char INPUT_ONLY_descr[] = "IN_ONLY"; char NO_PWM_descr[] = "NO_PWM"; char HIGH_BOOT_descr[] = "B_HIGH"; -const char * GPIO_Index_note[] = { +const char * GPIO_Index_note_descr[] = { NULL, // 0 - no note BOOTFAILS_LOW_descr, // 1 BOOTFAILS_HIGH_descr, // 2 @@ -87,11 +87,61 @@ const char * GPIO_Index_note[] = { HIGH_BOOT_descr, // 6 }; - +/* + * Output Type + */ + +// 0 is unconfigured +const byte Output_Type_total = 4; + const byte OUTPUT_TYPE_GPIO = 1; const byte OUTPUT_TYPE_I2C = 2; const byte OUTPUT_TYPE_WEB = 3; +char OUTPUT_TYPE_GPIO_descr[] = "GPIO"; +char OUTPUT_TYPE_I2C_descr[] = "I2C"; +char OUTPUT_TYPE_WEB_descr[] = "Webcall"; + +const char * Output_Type_descr[] = { + NULL, // 0 - no description because 0 means unconfigured + OUTPUT_TYPE_GPIO_descr, + OUTPUT_TYPE_I2C_descr, + OUTPUT_TYPE_WEB_descr, +}; + +/* + * Output Device + */ +// 0 is unconfigured +const byte Output_Device_total = 7; + +const byte OUTPUT_DEVICE_LIGHT = 1; +const byte OUTPUT_DEVICE_FAN = 2; +const byte OUTPUT_DEVICE_PUMP = 3; +const byte OUTPUT_DEVICE_HUMIDIFIER = 4; +const byte OUTPUT_DEVICE_DEHUMIDIFIER = 5; +const byte OUTPUT_DEVICE_HEATING = 6; + +char OUTPUT_DEVICE_LIGHT_descr[] = "Light"; +char OUTPUT_DEVICE_FAN_descr[] = "Fan"; +char OUTPUT_DEVICE_PUMP_descr[] = "Pump"; +char OUTPUT_DEVICE_HUMIDIFIER_descr[] = "Humidifier"; +char OUTPUT_DEVICE_DEHUMIDIFIER_descr[] = "Dehumidifier"; +char OUTPUT_DEVICE_HEATING_descr[] = "Heating"; + + +const char * Output_Device_descr[] = { + NULL, // 0 - no description because 0 means unconfigured + OUTPUT_DEVICE_LIGHT_descr, + OUTPUT_DEVICE_FAN_descr, + OUTPUT_DEVICE_PUMP_descr, + OUTPUT_DEVICE_HUMIDIFIER_descr, + OUTPUT_DEVICE_DEHUMIDIFIER_descr, + OUTPUT_DEVICE_HEATING_descr, +}; + + + struct GPIO_Index { const byte gpio; const byte note; @@ -146,9 +196,9 @@ struct Config_System_Output { * - gpio_invert: invert gpio output * - gpio_pwm: enable pwm for output * - i2c: - * - web_host: ip to smart plug (tasmota e.g.) - * - web_req_on: GET request path to turn ON - * - web_req_off: GET request path to turn ON + * - webcall_host: ip to smart plug (tasmota e.g.) + * - webcall_path_on: GET request path to turn ON + * - webcall_path_off: GET request path to turn OFF * */ @@ -160,9 +210,9 @@ struct Config_System_Output { bool gpio_invert[Max_Outputs]; bool gpio_pwm[Max_Outputs]; char i2c[Max_Outputs][8]; - char web_host[Max_Outputs][32]; - char web_req_on[Max_Outputs][32]; - char web_req_off[Max_Outputs][32]; + char webcall_host[Max_Outputs][32]; + char webcall_path_on[Max_Outputs][32]; + char webcall_path_off[Max_Outputs][32]; }; /* main System struct */ diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h index 4f54291..e8cbdd3 100644 --- a/Arduino/CanGrow/include/CanGrow_LittleFS.h +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -221,9 +221,9 @@ bool LoadConfig() { // i2c strlcpy(config.system.output.i2c[i], objSystemOutput["i2c"][i], sizeof(config.system.output.i2c[i])); // web - strlcpy(config.system.output.web_host[i], objSystemOutput["web_host"][i], sizeof(config.system.output.web_host[i])); - strlcpy(config.system.output.web_req_on[i], objSystemOutput["web_req_on"][i], sizeof(config.system.output.web_req_on[i])); - strlcpy(config.system.output.web_req_off[i], objSystemOutput["web_req_off"][i], sizeof(config.system.output.web_req_off[i])); + strlcpy(config.system.output.webcall_host[i], objSystemOutput["webcall_host"][i], sizeof(config.system.output.webcall_host[i])); + strlcpy(config.system.output.webcall_path_on[i], objSystemOutput["webcall_path_on"][i], sizeof(config.system.output.webcall_path_on[i])); + strlcpy(config.system.output.webcall_path_off[i], objSystemOutput["webcall_path_off"][i], sizeof(config.system.output.webcall_path_off[i])); } } @@ -301,9 +301,9 @@ bool SaveConfig(bool writeToSerial = false) { // i2c objSystemOutput["i2c"][i] = config.system.output.i2c[i]; // web - objSystemOutput["web_host"][i] = config.system.output.web_host[i]; - objSystemOutput["web_req_on"][i] = config.system.output.web_req_on[i]; - objSystemOutput["web_req_off"][i] = config.system.output.web_req_off[i]; + objSystemOutput["webcall_host"][i] = config.system.output.webcall_host[i]; + objSystemOutput["webcall_path_on"][i] = config.system.output.webcall_path_on[i]; + objSystemOutput["webcall_path_off"][i] = config.system.output.webcall_path_off[i]; } } diff --git a/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h b/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h index fd374f5..367cef8 100644 --- a/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h +++ b/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h @@ -64,6 +64,7 @@ h3 { td { text-align: left; vertical-align: middle; + border-bottom: 1px solid #262B27; } a:link, a:visited { diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index 06751e3..5b6fff3 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -312,9 +312,9 @@ String Proc_WebPage_system_output(const String& var) { output_tr_td += ""; output_tr_td += config.system.output.name[i]; output_tr_td += ""; - output_tr_td += config.system.output.type[i]; + output_tr_td += Output_Type_descr[config.system.output.type[i]]; output_tr_td += ""; - output_tr_td += config.system.output.device[i]; + output_tr_td += Output_Device_descr[config.system.output.device[i]]; output_tr_td += ""; output_tr_td += config.system.output.enabled[i]; output_tr_td += " 0) { gpioIndex_html += " "; - gpioIndex_html += GPIO_Index_note[GPIOindex[i].note]; + gpioIndex_html += GPIO_Index_note_descr[GPIOindex[i].note]; // disable output incompatible gpio if(GPIOindex[i].note == INPUT_ONLY) { @@ -472,25 +499,59 @@ void WebPage_system_output_add(AsyncWebServerRequest *request) { config.system.output.enabled[outputId] = p_enabled->value().toInt(); } - // only fill gpio values if type is GPIO - if(outputType == 1) { - if(request->hasParam("gpio", true)) { - const AsyncWebParameter* p_gpio = request->getParam("gpio", true); - Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio->name().c_str(), p_gpio->value().c_str()); - config.system.output.gpio[outputId] = p_gpio->value().toInt(); - } - - if(request->hasParam("gpio_pwm", true)) { - const AsyncWebParameter* p_gpio_pwm = request->getParam("gpio_pwm", true); - Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio_pwm->name().c_str(), p_gpio_pwm->value().c_str()); - config.system.output.gpio_pwm[outputId] = p_gpio_pwm->value().toInt(); - } - - if(request->hasParam("gpio_invert", true)) { - const AsyncWebParameter* p_gpio_invert = request->getParam("gpio_invert", true); - Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio_invert->name().c_str(), p_gpio_invert->value().c_str()); - config.system.output.gpio_invert[outputId] = p_gpio_invert->value().toInt(); - } + // only fill the type related config vars + switch(outputType) { + // GPIO + case 1: + if(request->hasParam("gpio", true)) { + const AsyncWebParameter* p_gpio = request->getParam("gpio", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio->name().c_str(), p_gpio->value().c_str()); + config.system.output.gpio[outputId] = p_gpio->value().toInt(); + } + + if(request->hasParam("gpio_pwm", true)) { + const AsyncWebParameter* p_gpio_pwm = request->getParam("gpio_pwm", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio_pwm->name().c_str(), p_gpio_pwm->value().c_str()); + config.system.output.gpio_pwm[outputId] = p_gpio_pwm->value().toInt(); + } + + if(request->hasParam("gpio_invert", true)) { + const AsyncWebParameter* p_gpio_invert = request->getParam("gpio_invert", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio_invert->name().c_str(), p_gpio_invert->value().c_str()); + config.system.output.gpio_invert[outputId] = p_gpio_invert->value().toInt(); + } + break; + + // I2C + case 2: + if(request->hasParam("i2c", true)) { + const AsyncWebParameter* p_i2c = request->getParam("i2c", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_i2c->name().c_str(), p_i2c->value().c_str()); + strlcpy(config.system.output.i2c[outputId], p_i2c->value().c_str(), sizeof(config.system.output.i2c[outputId])); + } + break; + // Webcall + case 3: + if(request->hasParam("webcall_host", true)) { + const AsyncWebParameter* p_webcall_host = request->getParam("webcall_host", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_webcall_host->name().c_str(), p_webcall_host->value().c_str()); + strlcpy(config.system.output.webcall_host[outputId], p_webcall_host->value().c_str(), sizeof(config.system.output.webcall_host[outputId])); + } + + if(request->hasParam("webcall_path_on", true)) { + const AsyncWebParameter* p_webcall_path_on = request->getParam("webcall_path_on", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_webcall_path_on->name().c_str(), p_webcall_path_on->value().c_str()); + strlcpy(config.system.output.webcall_path_on[outputId], p_webcall_path_on->value().c_str(), sizeof(config.system.output.webcall_path_on[outputId])); + } + + if(request->hasParam("webcall_path_off", true)) { + const AsyncWebParameter* p_webcall_path_off = request->getParam("webcall_path_off", true); + Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_webcall_path_off->name().c_str(), p_webcall_path_off->value().c_str()); + strlcpy(config.system.output.webcall_path_off[outputId], p_webcall_path_off->value().c_str(), sizeof(config.system.output.webcall_path_off[outputId])); + } + + break; + default: break; } diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h index 46e2198..74a1b86 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h @@ -165,20 +165,13 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER% Type:

Device:

Name:
@@ -220,14 +213,14 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER%