From b0f3d055760ec09b2cee5b23140a927505ea52a4 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 26 Oct 2024 06:04:10 +0200 Subject: [PATCH] output:add put next free output id into hidden input. if none available, return 255 --- .../CanGrow/include/Webserver/Page_system.h | 20 ++++++++++++++++++- .../include/Webserver/Page_system_HTML.h | 15 ++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index 92172a5..731f604 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -359,6 +359,22 @@ String Proc_WebPage_system_output_add(const String& var) { return AddHeaderFooter(var, 2); } else if(Test_WebPage_system_SUBNAV(var)) { return Proc_WebPage_system_SUBNAV(var, 1); + } else if(var == "OUTPUT_ID") { + // we check which id is free. A free ID as type == 0 + byte freeOutputId; + + for(byte i=0; i < Max_Outputs; i++) { + if(config.system.output.type[i] > 0) { + // here i define that 255 stands for "not available" + freeOutputId = 255; + } else { + freeOutputId = i; + break; + } + } + Serial.printf("DB [Webserver:system:output:add(Proc)] next free output id: %d\n", freeOutputId); + return String(freeOutputId); + } else if(var == "GPIO_INDEX") { String gpioIndex_html; for(byte i = 0; i < GPIOindex_length; i++) { @@ -384,7 +400,7 @@ String Proc_WebPage_system_output_add(const String& var) { } return gpioIndex_html; - } else{ + } else { return String(); } } @@ -410,7 +426,9 @@ auto Chunk_system_output_add_HTML(uint8_t *buffer, size_t maxlen, size_t index) // https://forum.arduino.cc/t/strlen-and-progmem/629376/3 size_t len_html = strlen_P(reinterpret_cast(Page_system_output_add_HTML)); size_t len = min(maxlen, len_html - index); + #ifdef DEBUG Serial.printf(":: [Webserver:system:output:add(Chunked)] Sending len %u bytes , maxlen %u, index %u, sizeof %u\n", len, maxlen, index, len_html); + #endif memcpy(buffer, Page_system_output_add_HTML + index, len); return len; } diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h index 75d18bd..33e76bf 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h @@ -159,7 +159,7 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER%

Add a new output to CanGrow.

- + Type:

Name:
-
+
Enable:
+
GPIO PWM:
-