From 6a9c989766ce28084aff0fcd049f4368174441fb Mon Sep 17 00:00:00 2001 From: Noctr <88264186+Noctr@users.noreply.github.com> Date: Sun, 1 Aug 2021 23:38:13 +0700 Subject: [PATCH 1/6] Update controls.js --- data/js/controls.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/data/js/controls.js b/data/js/controls.js index 5191b0e..76d5f4e 100644 --- a/data/js/controls.js +++ b/data/js/controls.js @@ -263,6 +263,7 @@ function start() { } else { parent = $("#row"); } + if (data.visible) { parent.append( "
" + "
" ); + } break; case UI_TEXT_INPUT: @@ -535,6 +546,7 @@ function start() { } else { parent = $("#row"); } + if (data.visible) { parent.append( "
" + "
" ); + } break; case UI_TAB: + if (data.visible) { $("#tabsnav").append( "
  • " + data.value + "
  • " ); @@ -574,6 +588,7 @@ function start() { } e.preventDefault(); }); + } break; case UI_SELECT: @@ -583,6 +598,7 @@ function start() { } else { parent = $("#row"); } + if (data.visible) { parent.append( "
    " + "
    " ); + } break; case UI_OPTION: @@ -651,6 +668,7 @@ function start() { } else { parent = $("#row"); } + if (data.visible) { parent.append( "
    " + "
    " ); + } break; case UI_ACCEL: @@ -719,6 +740,7 @@ function start() { parent = $("#row"); } hasAccel = true; + if (data.visible) { parent.append( "
    "+ data.value+ ""+ -"
    ");break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+ data.value+ -"
    ");$("#btn"+data.id).on({touchstart:function(e){e.preventDefault();buttonclick(data.id,true);},touchend:function(e){e.preventDefault();buttonclick(data.id,false);},});break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    ");switcher(data.id,data.value);} +break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    OK":"")+ ""+ -"
    ");$("#pf"+data.id).on({touchstart:function(e){e.preventDefault();padclick(UP,data.id,true);},touchend:function(e){e.preventDefault();padclick(UP,data.id,false);},});$("#pl"+data.id).on({touchstart:function(e){e.preventDefault();padclick(LEFT,data.id,true);},touchend:function(e){e.preventDefault();padclick(LEFT,data.id,false);},});$("#pr"+data.id).on({touchstart:function(e){e.preventDefault();padclick(RIGHT,data.id,true);},touchend:function(e){e.preventDefault();padclick(RIGHT,data.id,false);},});$("#pb"+data.id).on({touchstart:function(e){e.preventDefault();padclick(DOWN,data.id,true);},touchend:function(e){e.preventDefault();padclick(DOWN,data.id,false);},});$("#pc"+data.id).on({touchstart:function(e){e.preventDefault();padclick(CENTER,data.id,true);},touchend:function(e){e.preventDefault();padclick(CENTER,data.id,false);},});break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    ");rangeSlider(!sliderContinuous);} +break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    "+ -"
    ");break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+ -"
    ");break;case UI_TAB:$("#tabsnav").append("
  • "+data.value+"
  • ");$("#tabscontent").append("
    ");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");} -e.preventDefault();});break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+data.value+"");$("#tabscontent").append("
    ");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");} +e.preventDefault();});} +break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    "+ -"
    ");break;case UI_OPTION:if(data.parentControl){var parent=$("#select"+data.parentControl);parent.append("
    ");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;} +"
    ");requestOrientationPermission();} +break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;} if(data.type>=UPDATE_OFFSET&&data.type Date: Sun, 1 Aug 2021 23:50:26 +0700 Subject: [PATCH 3/6] Update dataControlsJS.h --- src/dataControlsJS.h | 62 ++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/dataControlsJS.h b/src/dataControlsJS.h index fd24c89..fdcc993 100644 --- a/src/dataControlsJS.h +++ b/src/dataControlsJS.h @@ -10,7 +10,7 @@ function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restar function start(){document.addEventListener("visibilitychange",handleVisibilityChange,false);if(window.location.port!=""||window.location.port!=80||window.location.port!=443){websock=new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws");}else{websock=new WebSocket("ws://"+window.location.hostname+"/ws");} websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){console.log(evt);var data=JSON.parse(evt.data);var e=document.body;var center="";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;} data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+ data.value+ ""+ -"
    ");break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+ data.value+ -"
    ");$("#btn"+data.id).on({touchstart:function(e){e.preventDefault();buttonclick(data.id,true);},touchend:function(e){e.preventDefault();buttonclick(data.id,false);},});break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    ");switcher(data.id,data.value);} +break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    OK":"")+ ""+ -"
    ");$("#pf"+data.id).on({touchstart:function(e){e.preventDefault();padclick(UP,data.id,true);},touchend:function(e){e.preventDefault();padclick(UP,data.id,false);},});$("#pl"+data.id).on({touchstart:function(e){e.preventDefault();padclick(LEFT,data.id,true);},touchend:function(e){e.preventDefault();padclick(LEFT,data.id,false);},});$("#pr"+data.id).on({touchstart:function(e){e.preventDefault();padclick(RIGHT,data.id,true);},touchend:function(e){e.preventDefault();padclick(RIGHT,data.id,false);},});$("#pb"+data.id).on({touchstart:function(e){e.preventDefault();padclick(DOWN,data.id,true);},touchend:function(e){e.preventDefault();padclick(DOWN,data.id,false);},});$("#pc"+data.id).on({touchstart:function(e){e.preventDefault();padclick(CENTER,data.id,true);},touchend:function(e){e.preventDefault();padclick(CENTER,data.id,false);},});break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    ");rangeSlider(!sliderContinuous);} +break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    "+ -"
    ");break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+ -"
    ");break;case UI_TAB:$("#tabsnav").append("
  • "+data.value+"
  • ");$("#tabscontent").append("
    ");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");} -e.preventDefault();});break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} -parent.append("
    "+data.value+"");$("#tabscontent").append("
    ");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");} +e.preventDefault();});} +break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");} +if(data.visible){parent.append("
    "+ -"
    ");break;case UI_OPTION:if(data.parentControl){var parent=$("#select"+data.parentControl);parent.append("
    ");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;} +"
    ");requestOrientationPermission();} +break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;} if(data.type>=UPDATE_OFFSET&&data.type Date: Sun, 1 Aug 2021 23:54:50 +0700 Subject: [PATCH 4/6] Update ESPUI.h --- src/ESPUI.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ESPUI.h b/src/ESPUI.h index d31ca8a..fc571bd 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -134,18 +134,21 @@ public: void (*callback)(Control*, int); String value; ControlColor color; + bool visible; uint16_t parentControl; Control* next; + static constexpr uint16_t noParent = 0xffff; Control(ControlType type, const char* label, void (*callback)(Control*, int), const String& value, - ControlColor color, uint16_t parentControl = Control::noParent) + ControlColor color, bool visible = true, uint16_t parentControl = Control::noParent) : type(type), label(label), callback(callback), value(value), color(color), + visible(visible), parentControl(parentControl), next(nullptr) { @@ -159,6 +162,7 @@ public: callback(control.callback), value(control.value), color(control.color), + visible(control.visible), parentControl(control.parentControl), next(control.next) { } @@ -295,3 +299,4 @@ private: extern ESPUIClass ESPUI; #endif + From de0c74ab4b9c67d127e1ac943018245a8bbc7d7b Mon Sep 17 00:00:00 2001 From: Noctr <88264186+Noctr@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:33:53 +0700 Subject: [PATCH 5/6] Update ESPUI.h --- src/ESPUI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ESPUI.h b/src/ESPUI.h index fc571bd..b3fa205 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -134,7 +134,7 @@ public: void (*callback)(Control*, int); String value; ControlColor color; - bool visible; + bool visible; uint16_t parentControl; Control* next; From 95d13ec5a9ad8e37e523cdd44e9009b6807b3799 Mon Sep 17 00:00:00 2001 From: Noctr <88264186+Noctr@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:40:10 +0700 Subject: [PATCH 6/6] Update ESPUI.h --- src/ESPUI.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ESPUI.h b/src/ESPUI.h index b3fa205..3f63171 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -138,7 +138,6 @@ public: uint16_t parentControl; Control* next; - static constexpr uint16_t noParent = 0xffff; Control(ControlType type, const char* label, void (*callback)(Control*, int), const String& value, @@ -299,4 +298,3 @@ private: extern ESPUIClass ESPUI; #endif -