const UI_INITIAL_GUI=200;const UI_RELOAD=201;const UPDATE_OFFSET=100;const UI_EXTEND_GUI=210;const ALERT_I=240;const ALERT_W=241;const ALERT_E=242;const ALERT_S=243;const UI_TITEL=0;const UI_PAD=1;const UPDATE_PAD=101;const UI_CPAD=2;const UPDATE_CPAD=102;const UI_BUTTON=3;const UPDATE_BUTTON=103;const UI_LABEL=4;const UPDATE_LABEL=104;const UI_SWITCHER=5;const UPDATE_SWITCHER=105;const UI_SLIDER=6;const UPDATE_SLIDER=106;const UI_NUMBER=7;const UPDATE_NUMBER=107;const UI_TEXT_INPUT=8;const UPDATE_TEXT_INPUT=108;const UI_GRAPH=9;const ADD_GRAPH_POINT=10;const CLEAR_GRAPH=109;const UI_TAB=11;const UPDATE_TAB=111;const UI_SELECT=12;const UPDATE_SELECT=112;const UI_OPTION=13;const UPDATE_OPTION=113;const UI_MIN=14;const UPDATE_MIN=114;const UI_MAX=15;const UPDATE_MAX=115;const UI_STEP=16;const UPDATE_STEP=116;const UI_GAUGE=17;const UPDATE_GAUGE=117;const UI_ACCEL=18;const UPDATE_ACCEL=118;const UI_SEPARATOR=19;const UPDATE_SEPARATOR=119;const UI_TIME=20;const UPDATE_TIME=120;const UI_FRAGMENT=21;const UP=0;const DOWN=1;const LEFT=2;const RIGHT=3;const CENTER=4;const C_TURQUOISE=0;const C_EMERALD=1;const C_PETERRIVER=2;const C_WETASPHALT=3;const C_SUNFLOWER=4;const C_CARROT=5;const C_ALIZARIN=6;const C_DARK=7;const C_NONE=255;var controlAssemblyArray=new Object();var FragmentAssemblyTimer=0;var graphData=new Array();var hasAccel=false;var sliderContinuous=false;class Alert{static fire(icon,message,position="tl",type="",options={},onConfirm=function(){},onCancel=function(){}){const el=document.createElement("div");el.className="Alert";const divIcon=document.createElement("div");divIcon.className="AlertIcon";const divMessage=document.createElement("div");divMessage.className="AlertMessage";el.appendChild(divIcon);el.appendChild(divMessage);if(icon=="succ"){divIcon.innerHTML='✓';}else if(icon=="err"){divIcon.innerHTML='⨷';el.style.backgroundColor="rgba(180, 0, 0, 0.75)"
message="ERROR
"+message;}else if(icon=="info"){divIcon.innerHTML='⚠';}else if(icon=="warn"){divIcon.innerHTML="𝕎";el.style.backgroundColor="rgba(100, 0, 0, 0.75);"}
divMessage.innerHTML="
"+message+"
";if(type=="dialog"){el.style.flexDirection="column";divIcon.style.position="relative";divIcon.style.left="0px";divIcon.style.marginTop="15px";const divControls=document.createElement("div");divControls.className="AlertControls";const btnConfirm=document.createElement("button");btnConfirm.className="BtnConfirm";btnConfirm.innerHTML="Confirm";const btnCancel=document.createElement("button");btnCancel.className="BtnCancel";btnCancel.innerHTML="Cancel";el.appendChild(divControls);divControls.appendChild(btnConfirm);divControls.appendChild(btnCancel);btnConfirm.onclick=function(){onConfirm();removeAlert(el);};btnCancel.onclick=function(){onCancel();removeAlert(el);};if(Object.keys(options).length>0){if(options.confirmButtonText){btnConfirm.innerHTML=options.confirmButtonText;} if(options.cancelButtonText){btnCancel.innerHTML=options.cancelButtonText;} if(options.confirmButtonColor){btnConfirm.style.backgroundColor=options.confirmButtonColor;} if(options.cancelButtonColor){btnCancel.style.backgroundColor=options.cancelButtonColor;}}} el.style.left=0;switch(position){case"tl":el.style.top=0;break;case"tm":el.style.right=0;el.style.marginLeft="auto";el.style.marginRight="auto";break;case"bl":el.style.bottom=0;break;case"bm":el.style.right=0;el.style.bottom=0;el.style.marginLeft="auto";el.style.marginRight="auto";break;case"center":el.style.right=0;el.style.marginLeft="auto";el.style.marginRight="auto";el.style.marginTop="20%";break;} if(Object.keys(options).length>0){if(options.backgroundColor){el.style.backgroundColor=options.backgroundColor;} if(options.fontColor){divMessage.style.color=options.fontColor;} if(options.iconColor){divIcon.style.color=options.iconColor;} if(options.borderRadius){el.style.borderRadius=options.borderRadius;} if(options.border){el.style.border=options.border;}} document.body.appendChild(el);if(type==""){setTimeout(()=>{el.parentNode.removeChild(el);},8000);} function remAlert(element){element.parentNode.removeChild(element);}}} function colorClass(colorId){colorId=Number(colorId);switch(colorId){case C_TURQUOISE:return"turquoise";case C_EMERALD:return"emerald";case C_PETERRIVER:return"peterriver";case C_WETASPHALT:return"wetasphalt";case C_SUNFLOWER:return"sunflower";case C_CARROT:return"carrot";case C_ALIZARIN:return"alizarin";case C_DARK:case C_NONE:return"dark";default:return"";}} var websock;var websockConnected=false;var WebSocketTimer=null;function requestOrientationPermission(){} function saveGraphData(){localStorage.setItem("espuigraphs",JSON.stringify(graphData));} function restoreGraphData(id){var savedData=localStorage.getItem("espuigraphs",graphData);if(savedData!=null){savedData=JSON.parse(savedData);let idData=savedData[id];return Array.isArray(idData)?idData:[];} return[];} function restart(){$(document).add("*").off();$("#row").html("");conStatusError();start();} function FragmentAssemblyTimerStop(){if(FragmentAssemblyTimer) FragmentAssemblyTimer.forEach(element=>{clearInterval(element);});FragmentAssemblyTimer=0;} function conStatusError(){FragmentAssemblyTimerStop();controlAssemblyArray=new Object();if(true===websockConnected){websockConnected=false;websock.close();$("#conStatus").removeClass("color-green");$("#conStatus").addClass("color-red");$("#conStatus").html("Error / No Connection ↻");$("#conStatus").off();$("#conStatus").on({click:restart,});}} function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restart();}} function start(){let location=window.location.hostname;let port=window.location.port;document.addEventListener("visibilitychange",handleVisibilityChange,false);if(port!=""||port!=80||port!=443){websock=new WebSocket("ws://"+location+":"+port+"/ws");}else{websock=new WebSocket("ws://"+location+"/ws");} if(null===WebSocketTimer){WebSocketTimer=setInterval(function(){if(websock.readyState===3){console.info("Web Socket Is Closed");restart();}},5000);} websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;controlAssemblyArray=new Object();};websock.onclose=function(evt){console.log("websock close");conStatusError();FragmentAssemblyTimerStop();controlAssemblyArray=new Object();};websock.onerror=function(evt){console.log("websock Error");restart();FragmentAssemblyTimerStop();controlAssemblyArray=new Object();};var handleEvent=function(evt){try{var data=JSON.parse(evt.data);} catch(Event){console.error(Event);websock.send("uiok:"+0);return;} var e=document.body;var center="";console.info("data.type: '"+data.type+"'");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);});if(data.totalcontrols>(data.controls.length-1)){websock.send("uiok:"+(data.controls.length-1));} break;case UI_EXTEND_GUI:data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});if(data.totalcontrols>data.startindex+(data.controls.length-1)){websock.send("uiok:"+(data.startindex+(data.controls.length-1)));} break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case ALERT_I:Alert.fire("info",data.value);break;case ALERT_W:Alert.fire("warn",data.value);break;case ALERT_E:Alert.fire("err",data.value);break;case ALERT_S:Alert.fire("succ",data.value);break;case UI_LABEL:case UI_NUMBER:case UI_TEXT_INPUT:case UI_SELECT:case UI_GAUGE:case UI_SEPARATOR:if(data.visible)addToHTML(data);break;case UI_BUTTON:if(data.visible){addToHTML(data);$("#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:if(data.visible){addToHTML(data);switcher(data.id,data.value);} break;case UI_CPAD:case UI_PAD:if(data.visible){addToHTML(data);$("#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:if(data.visible){addToHTML(data);rangeSlider(!sliderContinuous);} break;case UI_TAB:if(data.visible){$("#tabsnav").append("