put stuff into seperate functions

This commit is contained in:
Marcus 2024-10-28 22:30:20 +01:00
parent 735cff463e
commit 790b9bb9c9
2 changed files with 101 additions and 49 deletions

View file

@ -106,3 +106,64 @@ String AddHeaderFooter(const String& var, byte activeNav = 0) {
return String();
}
}
/*
* Html_SelectOpt_GPIOindex
*
* returns <option> list as string with available gpios
*/
String Html_SelectOpt_GPIOindex(byte selectId = 255) {
String gpioIndex_html;
// iterate through through all available GPIOs in index
for(byte i = 0; i < GPIOindex_length; i++) {
bool gpioUsed = Check_GPIOindex_Used(i);
gpioIndex_html += "<option value='";
gpioIndex_html += i;
gpioIndex_html += "'";
// set disabled option for gpio which are already in use or incompatible
if( (((gpioUsed == true) && (i != selectId)) || (GPIOindex[i].note == INPUT_ONLY)) ) {
gpioIndex_html += " disabled";
}
if(i == selectId) {
gpioIndex_html += " selected";
}
gpioIndex_html += ">GPIO ";
gpioIndex_html += GPIOindex[i].gpio;
//add gpio note if there is some
//if(GPIOindex[i].note > 0) {
gpioIndex_html += " ";
gpioIndex_html += GPIO_Index_note_descr[GPIOindex[i].note];
// disable output incompatible gpio
if(GPIOindex[i].note == INPUT_ONLY) {
gpioIndex_html += " (N/A)";
// add USED if gpio is already in use
} else if((gpioUsed == true) && (i != selectId)) {
gpioIndex_html += " (used)";
}
gpioIndex_html += "</option>";
}
return gpioIndex_html;
}
String Html_SelectOpt_bool(byte selectVal = 255, String trueStr = "Yes", String falseStr = "No") {
String html;
html += "<option value='1'";
html += (selectVal == true) ? " selected" : "";
html += ">";
html += trueStr;
html += "</option>";
html += "<option value='0'";
html += (selectVal == false) ? " selected" : "";
html += ">";
html += trueStr;
html += "</option>";
return html;
}

View file

@ -399,6 +399,42 @@ void WebPage_system_output(AsyncWebServerRequest *request) {
/*
* Subpage output add
*/
/* returns select <option> list of available output types */
String Html_SelOpt_type_WebPage_system_output_add(byte selectId = 0) {
String outputType_html;
// go through all available Output Devices, skip 0 because it means unconfigured
for(byte i = 1; i < Output_Type_total; i++) {
outputType_html += "<option value='";
outputType_html += i;
outputType_html += "'";
if(i == selectId) {
outputType_html += " selected";
}
outputType_html += ">";
outputType_html += Output_Type_descr[i];
outputType_html += "</option>";
}
return outputType_html;
}
String Html_SelOpt_device_WebPage_system_output_add(byte selectId = 0) {
String outputDevice_html;
// go through all available Output Devices, skip 0 because it means unconfigured
for(byte i = 1; i < Output_Device_total; i++) {
outputDevice_html += "<option value='";
outputDevice_html += i;
outputDevice_html += "'";
if(i == selectId) {
outputDevice_html += " selected";
}
outputDevice_html += ">";
outputDevice_html += Output_Device_descr[i];
outputDevice_html += "</option>";
}
return outputDevice_html;
}
String Proc_WebPage_system_output_add(const String& var) {
#ifndef DEBUG
Serial.print("DB [Webserver:system:output:add(Proc)] var: ");
@ -414,61 +450,16 @@ String Proc_WebPage_system_output_add(const String& var) {
/* OUTPUT_TYPE */
} else if(var == "OUTPUT_TYPE") {
String outputType_html;
// go through all available Output Devices, skip 0 because it means unconfigured
for(byte i = 1; i < Output_Type_total; i++) {
outputType_html += "<option value='";
outputType_html += i;
outputType_html += "'>";
outputType_html += Output_Type_descr[i];
outputType_html += "</option>";
}
return outputType_html;
return Html_SelOpt_type_WebPage_system_output_add();
/* OUTPUT_DEVICE */
} else if(var == "OUTPUT_DEVICE") {
String outputDevice_html;
// go through all available Output Devices, skip 0 because it means unconfigured
for(byte i = 1; i < Output_Device_total; i++) {
outputDevice_html += "<option value='";
outputDevice_html += i;
outputDevice_html += "'>";
outputDevice_html += Output_Device_descr[i];
outputDevice_html += "</option>";
}
return outputDevice_html;
return Html_SelOpt_device_WebPage_system_output_add();
/* GPIO_INDEX */
} else if(var == "GPIO_INDEX") {
String gpioIndex_html;
// iterate through through all available GPIOs in index
for(byte i = 0; i < GPIOindex_length; i++) {
bool gpioUsed = Check_GPIOindex_Used(i);
gpioIndex_html += "<option value='";
gpioIndex_html += i;
gpioIndex_html += "'";
// set disabled option for gpio which are already in use or incompatible
if((gpioUsed == true) || (GPIOindex[i].note == INPUT_ONLY)) {
gpioIndex_html += " disabled";
}
gpioIndex_html += ">GPIO ";
gpioIndex_html += GPIOindex[i].gpio;
//add gpio note if there is some
//if(GPIOindex[i].note > 0) {
gpioIndex_html += " ";
gpioIndex_html += GPIO_Index_note_descr[GPIOindex[i].note];
// disable output incompatible gpio
if(GPIOindex[i].note == INPUT_ONLY) {
gpioIndex_html += " (N/A)";
// add USED if gpio is already in use
} else if(gpioUsed == true) {
gpioIndex_html += " (used)";
}
gpioIndex_html += "</option>";
}
return gpioIndex_html;
return Html_SelectOpt_GPIOindex();
} else {
return String();
}