diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 6d910ddf0..3a4ba19d6 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2431,10 +2431,28 @@ int http_fn_cfg_pins(http_request_t* request) { if (i) { poststr(request, ","); } - hprintf255(request, "\"%s\"", htmlPinRoleNames[i]); + // print array with ["name_of_role",] + hprintf255(request, "[\"%s\",%i]", htmlPinRoleNames[i],PIN_IOR_NofChan(i)); } poststr(request, "];"); + poststr(request, "function hide_show() {" + "switch (r[this.selectedIndex][1]){" + "case 0:" + " e=getElement('r'+this.name); e.disabled=true;e.style.display='none';" + " e=getElement('e'+this.name); e.disabled=true;e.style.display='none';" + " break;" + "case 1:" + " e=getElement('r'+this.name); e.disabled=false;e.style.display='inline';" + " e=getElement('e'+this.name); e.disabled=true;e.style.display='none';" + " break;" + "case 2:" + " e=getElement('r'+this.name); e.disabled=false;e.style.display='inline';" + " e=getElement('e'+this.name); e.disabled=false;e.style.display='inline';" + " break;" + "};" + "}"); + poststr(request, "function f(alias, id, c, b, ch1, ch2) {" "let f = document.getElementById(\"x\");" "let d = document.createElement(\"div\");" @@ -2446,31 +2464,33 @@ int http_fn_cfg_pins(http_request_t* request) { "s.name = id;" "d.appendChild(s);" " for (var i = 0; i < r.length; i++) {" - " if(b && r[i].startsWith(\"PWM\")) continue; " + " if(b && r[i][0].startsWith(\"PWM\")) continue; " "var o = document.createElement(\"option\");" - " o.text = r[i];" + " o.text = r[i][0];" " 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);" + "s.add(o);s.onchange = hide_show;" "}" + "var y = document.createElement(\"input\");" + "y.className = \"hele\";" + "y.type = \"text\";" + "y.name = \"r\"+id;" + "y.id = \"r\"+id;" + "y.disabled = ch1==null;" + "y.style.display = ch1==null ? 'none' :'inline' ;" + "y.value = ch1==null ? 0 : ch1;" + "d.appendChild(y);" + "y = document.createElement(\"input\");" + "y.className = \"hele\";" + "y.type = \"text\";" + "y.name = \"e\"+id;" + "y.id = \"e\"+id;" + "y.disabled = ch2==null ;" + "y.style.display = ch2==null ? 'none' :'inline' ;" + "y.value = ch2==null ? 0 : ch2;" + "d.appendChild(y);" " }"); for (i = 0; i < PLATFORM_GPIO_MAX; i++) { @@ -2504,26 +2524,19 @@ int http_fn_cfg_pins(http_request_t* request) { } hprintf255(request, "\",%i,%i, %i,", i, si, !bCanThisPINbePWM); // Primary linked channel -// 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 - && !(si >= IOR_IRRecv && si <= IOR_DHT11) - && !(si >= IOR_SM2135_DAT && si <= IOR_BP1658CJ_CLK)) - || IS_PIN_DHT_ROLE(si)) + int NofC = PIN_IOR_NofChan(si); + if (NofC >= 1) { hprintf255(request, "%i,", ch); - //hprintf255(request, "", i, ch); } + // Some roles do not need any channels 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)) + if (NofC > 1) { hprintf255(request, "%i,", ch2); - //hprintf255(request, "", i, ch2); } else { hprintf255(request, "null,", ch); diff --git a/src/new_pins.c b/src/new_pins.c index e388facec..32c4b3a2f 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -326,6 +326,25 @@ int PIN_GetPinChannel2ForPinIndex(int index) { } return g_cfg.pins.channels2[index]; } +// return number of channels used for a role +// taken from code in http_fnc.c +int PIN_IOR_NofChan(int test){ + // For button, is relay index to toggle on double click + if (test == IOR_Button || test == IOR_Button_n || IS_PIN_DHT_ROLE(test) || IS_PIN_TEMP_HUM_SENSOR_ROLE(test) || IS_PIN_AIR_SENSOR_ROLE(test)){ + return 2; + } + // Some roles don't need any channels + if (test == IOR_SGP_CLK || test == IOR_SHT3X_CLK || test == IOR_CHT8305_CLK || test == IOR_Button_ToggleAll || test == IOR_Button_ToggleAll_n + || test == IOR_BL0937_CF || test == IOR_BL0937_CF1 || test == IOR_BL0937_SEL + || test == IOR_LED_WIFI || test == IOR_LED_WIFI_n || test == IOR_LED_WIFI_n + || (test >= IOR_IRRecv && test <= IOR_DHT11) + || (test >= IOR_SM2135_DAT && test <= IOR_BP1658CJ_CLK)) { + return 0; + } + // all others have 1 channel + return 1; +} + void RAW_SetPinValue(int index, int iVal) { if (index < 0 || index >= PLATFORM_GPIO_MAX) { addLogAdv(LOG_ERROR, LOG_FEATURE_CFG, "RAW_SetPinValue: Pin index %i out of range <0,%i).", index, PLATFORM_GPIO_MAX); diff --git a/src/new_pins.h b/src/new_pins.h index 0701375f4..5d3b43701 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1333,6 +1333,9 @@ int ChannelType_GetDecimalPlaces(int type); int PIN_ParsePinRoleName(const char* name); const char* PIN_RoleToString(int role); +// return number of channels used for a role +// taken from code in http_fnc.c +int PIN_IOR_NofChan(int test); extern const char* g_channelTypeNames[];