output:add put next free output id into hidden input. if none available, return 255

This commit is contained in:
Marcus 2024-10-26 06:04:10 +02:00
parent f7f5fe073b
commit b0f3d05576
2 changed files with 23 additions and 12 deletions

View file

@ -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<const char *>(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;
}

View file

@ -159,7 +159,7 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER%
<p>Add a new output to CanGrow.</p>
<form method='post' action='/system/output/add'>
<input type='hidden' name='gpioId' value='%OUTPUT_ID%' />
<u>Type</u>:<br>
<select id='type_sel' name='type' onchange="showSelect('type_sel', 'type_', 'hidden');" required>
<option disabled value='' selected hidden>---</option>
@ -180,7 +180,7 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER%
</select><br>
<u>Name</u>:<br>
<input type='text' name='name' maxlength='16' value='' ><br>
<input type='text' name='name' maxlength='16' value='' required><br>
<u>Enable</u>:<br>
<select name='enable' required>
@ -191,20 +191,13 @@ const char* Page_system_output_add_HTML PROGMEM = R"(%HEADER%
<div class='hidden' id='type_1'>
<u>GPIO</u>:<br>
<select name='gpio' required>
<select name='gpio'>
<option disabled value='' selected hidden>---</option>
%GPIO_INDEX%
<option value='0'>GPIO 0 !BFL!</option>
<option value='1'>GPIO 12</option>
<option value='2'>GPIO 13</option>
<option value='2'>GPIO 14</option>
<option value='2'>GPIO 15 !BFH!</option>
<option value='2'>GPIO 16 !NOPWM!</option>
</select><br>
<u>GPIO PWM</u>:<br>
<select name='gpio_pwm' required>
<select name='gpio_pwm' >
<option disabled value='' selected hidden>---</option>
<option value='1'>Enable</option>
<option value='2'>Disable</option>