pins page is now down to 8kb (was 90kb, then 10kb)

This commit is contained in:
Tester23
2024-05-11 15:25:18 +02:00
parent 8cad88ab5e
commit 5dd30c66ad

View File

@ -2423,8 +2423,60 @@ int http_fn_cfg_pins(http_request_t* request) {
hprintf255(request, "Pins update - %i reqs, %i changed!<br><br>", iChangedRequested, iChanged);
}
// strcat(outbuf,"<button type=\"button\">Click Me!</button>");
poststr(request, "<form action=\"cfg_pins\">");
poststr(request, "<form action=\"cfg_pins\" id=\"x\">");
poststr(request, "<script> var r = [");
for (i = 0; i < IOR_Total_Options; i++) {
if (i) {
poststr(request, ",");
}
hprintf255(request, "\"%s\"", htmlPinRoleNames[i]);
}
poststr(request, "];");
poststr(request, "function f(alias, id, c, b, ch1, ch2) {"
"let f = document.getElementById(\"x\");"
"let d = document.createElement(\"div\");"
"d.className = \"hdiv\";"
"d.innerText = alias;"
"f.appendChild(d);"
"let s = document.createElement(\"select\");"
"s.className = \"hele\";"
"s.name = id;"
"d.appendChild(s);"
" for (var i = 0; i < r.length; i++) {"
" if(b && r[i].startsWith(\"PWM\")) continue; "
"var o = document.createElement(\"option\");"
" o.text = r[i];"
" o.value = i;"
" if (i == c) {"
" o.selected = true;"
" }"
"s.add(o);"
"}"
"if(ch1!= null) {"
"let y = document.createElement(\"input\");"
"y.className = \"hele\";"
"y.type = \"text\";"
"y.name = \"r\"+id;"
"y.value = ch1;"
"d.appendChild(y);"
"}"
"if(ch2!= null) {"
"let y = document.createElement(\"input\");"
"y.className = \"hele\";"
"y.type = \"text\";"
"y.name = \"e\"+id;"
"y.value = ch2;"
"d.appendChild(y);"
"}"
" }");
for (i = 0; i < PLATFORM_GPIO_MAX; i++) {
// On BL602, any GPIO can be mapped to one of 5 PWM channels
// But on Beken chips, only certain pins can be PWM
int bCanThisPINbePWM;
int si, ch, ch2;
int j;
const char* alias;
@ -2435,7 +2487,10 @@ int http_fn_cfg_pins(http_request_t* request) {
// if available..
alias = HAL_PIN_GetPinNameAlias(i);
poststr(request, "<div class=\"hdiv\">");
bCanThisPINbePWM = HAL_PIN_CanThisPinBePWM(i);
si = PIN_GetPinRoleForPinIndex(i);
hprintf255(request, "f(\"");
if (alias) {
#if defined(PLATFORM_BEKEN) || defined(WINDOWS)
hprintf255(request, "P%i (%s) ", i, alias);
@ -2447,10 +2502,9 @@ int http_fn_cfg_pins(http_request_t* request) {
else {
hprintf255(request, "P%i ", i);
}
hprintf255(request, "<select class=\"hele\" name=\"%i\" id=\"s%i\">", i, i);
poststr(request, "</select>");
hprintf255(request, "\",%i,%i, %i,", i, si, !bCanThisPINbePWM);
// Primary linked channel
// Some roles do not need any channels
// Some roles do not need any channels
if ((si != IOR_SGP_CLK && si != IOR_SHT3X_CLK && si != IOR_CHT8305_CLK && si != IOR_Button_ToggleAll && si != IOR_Button_ToggleAll_n
&& si != IOR_BL0937_CF && si != IOR_BL0937_CF1 && si != IOR_BL0937_SEL
&& si != IOR_LED_WIFI && si != IOR_LED_WIFI_n && si != IOR_LED_WIFI_n
@ -2458,48 +2512,24 @@ int http_fn_cfg_pins(http_request_t* request) {
&& !(si >= IOR_SM2135_DAT && si <= IOR_BP1658CJ_CLK))
|| IS_PIN_DHT_ROLE(si))
{
hprintf255(request, "<input class=\"hele\" name=\"r%i\" type=\"text\" value=\"%i\"/>", i, ch);
hprintf255(request, "%i,", ch);
//hprintf255(request, "<input class=\"hele\" name=\"r%i\" type=\"text\" value=\"%i\"/>", i, ch);
}
else {
hprintf255(request, "null,", ch);
}
// Secondary linked channel
// For button, is relay index to toggle on double click
if (si == IOR_Button || si == IOR_Button_n || IS_PIN_DHT_ROLE(si) || IS_PIN_TEMP_HUM_SENSOR_ROLE(si) || IS_PIN_AIR_SENSOR_ROLE(si))
{
hprintf255(request, "<input class=\"hele\" name=\"e%i\" type=\"text\" value=\"%i\"/>", i, ch2);
hprintf255(request, "%i,", ch2);
//hprintf255(request, "<input class=\"hele\" name=\"e%i\" type=\"text\" value=\"%i\"/>", i, ch2);
}
poststr(request, "</div>");
}
poststr(request, "<script> var r = [");
for (i = 0; i < IOR_Total_Options; i++) {
if (i) {
poststr(request, ",");
else {
hprintf255(request, "null,", ch);
}
hprintf255(request, "\"%s\"", htmlPinRoleNames[i]);
}
poststr(request, "];");
hprintf255(request, ");");
poststr(request, "function f(n, c, b) {"
"let d = document.getElementById(n);"
" for (var i = 0; i < r.length; i++) {"
" if(b && r[i].startsWith(\"PWM\")) continue; "
"var o = document.createElement(\"option\");"
" o.text = r[i];"
" o.value = i;"
" if (i == c) {"
" o.selected = true;"
" }"
"d.add(o);"
"}"
" }");
for (i = 0; i < PLATFORM_GPIO_MAX; i++) {
int si;
// On BL602, any GPIO can be mapped to one of 5 PWM channels
// But on Beken chips, only certain pins can be PWM
int bCanThisPINbePWM;
bCanThisPINbePWM = HAL_PIN_CanThisPinBePWM(i);
si = PIN_GetPinRoleForPinIndex(i);
hprintf255(request, "f(\"s%i\",%i, %i);", i, si, !bCanThisPINbePWM);
}
poststr(request, " </script>");
poststr(request, "<input type=\"submit\" value=\"Save\"/></form>");