// -------------------------------- // ! MyPower.CZ Microlog ! X ! // !------------------------------- // ! web interface base script ! // ! (C) 2019 MyPower.CZ ! // !------------------------------- // ! Licence: ! // ! free for noncommercial use. ! // -------------------------------- // ! ! OK ! ! // -------------------------------- __micrologversion=2.04; _last_xdata=false; _last_xdataauto=false; _mpwShowRefreshOptions_laststate=0; _mpwqTimer_enabled=true; _mpwqTimer_code=""; _mpwqTimer_counter=0; _mpwqTimer_unlockablecode=""; _lastPinSetupStr=""; _lastPinSetupObject=false; _lastDisplaySetupObject=false; _areaobjs=new Array(); _areatimer=false; _areaxid=0; _xtmsx=0; // ------------------------------------------- function mpwJSgetcontent() { xret='<'+'style>'; xret+='.textAreaEditContent{ margin-top:0; margin-bottom:0; margin-right:0; margin-left:30px; background:rgba(0,0,0,0.2); color:#FFFFFF;'+ 'width:400px; height:300px; display:block; border:0px none; font-size:11px; font-family:monospace; line-height:14px; } '+ '.textAreaWithLines { display:block; cursor:default; margin:0; border:0px none; '+ ' border-right:1px dotted #808080; background:rgba(255,255,255,0.03); color:#808080; '+ 'font-size:11px; font-family:monospace; line-height:14px; } '; xret+='.mpwmenu div { cursor:pointer; border-bottom:1px dotted #808080; padding:5px;font-size:11px; }'; xret+='.mpwmenu div:hover { background-color:rgba(0,0,0,0.1); }'; xret+='.mpwmenu div { color: #FFC000; }'; xret+='.mpwtext { border:1px solid #404040; font-size:11px; padding:2px; background:#101010; color:#FFFFFF; }'; xret+='.mpwbutton { border:1px solid #404040; font-size:11px; padding:2px; background:#303030; color:#FFC000; cursor:pointer; } '; xret+='body { min-width:900px; }'; xret+='<'+'/style>'; xret+='
'; xret+=''; xret+='
'; xret+='
Hardware info
'; xret+='
Analogové vstupy
'; xret+='
Sampler
'; xret+='
Display
'; if (__micrologversion>=2.02) xret+='
Digitální výstupy
'; if (__micrologversion>=2.03) xret+='
Záloha eprom
'; xret+='
'; xret+='
'; xret+='< Klikněte na požadovanou funkci v levém sloupci.
'; return xret; } // ------------------------------------------- function mpwJSsenddata(xdata) { mpwJSsenddata_xhttp(xdata,xhttp,""); } // ------------------------------------------- function mpwJSsenddata_iframe(xdata,xframeid) { mpwJSsenddata_xhttp(xdata,"iframe",xframeid); } // ------------------------------------------- __xhttplastobj=null; function mpwJSsenddata_xhttp(xdata,xhttpobj,xframeid) { var intoiframe=(xhttpobj=="iframe"); if (!intoiframe) { if (xhttpobj!=xhttpauto) _last_xdata=xdata; else _last_xdataauto=xdata; } xurl="./cfg?"; var xf=true; if (typeof xdata == "object") for (p in xdata) if (p!="_eval") { if (!xf) xurl+="&"; else xf=false; xurl+=p+"="+mpwUTFhex(xdata[p]); } //mpwlogadd(xurl); if (intoiframe) { var o=document.getElementById(xframeid); if (!o) alert("No iframe '"+xframeid+"' found."); else o.src=xurl; } else { xhttpobj.open("GET",xurl,true); __xhttplastobj=xhttpobj; mpwSetWebLedState((__xhttplastobj==xhttpauto?"xhttpautoled":"xhttpled"),true); setTimeout("__xhttplastobj.send();",1); } } // ------------------------------------------- function mpwSetRefresh(xstate) { _mpwqTimer_enabled=(xstate==1); mpwShowRefreshOptions(_mpwShowRefreshOptions_laststate); } // ------------------------------------------- function mpwShowLedPanel() { var dname="xtoppaneldiv"; var o=document.getElementById(dname); if (!o) { o=document.createElement("DIV"); o.id=dname; var xled='
'+ ''+ ''+ '
'; o.innerHTML='
'+ ''+ ''+ '
'+xled.split("xunnamedled").join("xhttpled").split("xfill").join("#FF4000")+''+xled.split("xunnamedled").join("xhttpautoled").split("xfill").join("#40FF00")+'
'; document.body.insertBefore(o,document.body.childNodes[0]); } } // ------------------------------------------- function mpwShowRefreshOptions(xstate) { _mpwShowRefreshOptions_laststate=xstate; var dname="xrefreshoptdiv"; var o=document.getElementById(dname); if (!o) { o=document.createElement("DIV"); o.id=dname; o.innerHTML='
automatické obnovování: '+ 'pozastavit'+ 'spustit'+ '
'; document.body.insertBefore(o,document.body.childNodes[0]); } var xoff=document.getElementById("xrefreshoptdivhref_stop"); var xon=document.getElementById("xrefreshoptdivhref_start"); if ((xon) && (xoff)) { xon.style.display=((_mpwqTimer_enabled)?"none":"inline"); xoff.style.display=((_mpwqTimer_enabled)?"inline":"none"); } o.style.display=((xstate==1)?"block":"none"); } // ------------------------------------------- function mpwqTimer() { _mpwqTimer_counter++; if ((_mpwqTimer_counter&1)==1) { if ((_mpwqTimer_code!="") && (_mpwqTimer_enabled)) eval(_mpwqTimer_code); } if (_mpwqTimer_unlockablecode!="") eval(_mpwqTimer_unlockablecode); setTimeout("mpwqTimer()",1000); } // ------------------------------------------- function mpwLoadPage(xid) { var xdata=new Object(); xdata["cmd"]=xid; mpwJSsenddata(xdata); } // ------------------------------------------- function mpwLoadPageAuto(xid) { var xdata=new Object(); xdata["cmd"]=xid; mpwJSsenddata_xhttp(xdata,xhttpauto); } // ------------------------------------------- function mpwJSxmenu(xid) { mpwShowRefreshOptions(0); _mpwqTimer_code=""; _mpwqTimer_unlockablecode=""; if (xid=="sd") { mpwActivateMainMenuItem("sd"); mpwShowSDCard(); } else if (xid=="hw") { _mpwqTimer_code="mpwLoadPageAuto('"+xid+"')"; eval(_mpwqTimer_code); mpwShowRefreshOptions(1); } else if (xid=="ds") { mpwLoadPage(xid); mpwShowRefreshOptions(1); } else if (xid=="as") { mpwLoadPage(xid); _mpwqTimer_code="mpwLoadAnalogPins()"; mpwShowRefreshOptions(1); } else if (xid=="sp") { mpwLoadPage(xid); _mpwqTimer_code="mpwLoadSamplerPins()"; mpwShowRefreshOptions(1); } else if (xid=="dp") { mpwLoadPage(xid); _mpwqTimer_code="mpwLoadDisplayDump()"; mpwShowRefreshOptions(1); } else if (xid=="ep") { mpwActivateMainMenuItem("ep"); mpwShowEpromPage(); } else mpwLoadPage(xid); } // ------------------------------------------- function mpwActivateMainMenuItem(xmenuid) { var e=document.getElementsByTagName("div"); for (var ii=0;ii < e.length;ii++) { var o=e[ii]; if (o.getAttribute("xmenuid")==xmenuid) { o.style.color="#FFFFFF"; o.style.background="rgba(255,255,255,0.1)"; } else if (o.hasAttribute("xmenuid")) { o.style.color=""; o.style.background=""; } } } // ------------------------------------------- function mpwOnDataReceived(xhttp,qres,odata) { mpwSetWebLedState((xhttp==xhttpauto?"xhttpautoled":"xhttpled"),false); var xres=""; if (mpwtrim(odata["_eval"])!="") { // mpwlog(odata["_eval"]); eval(odata["_eval"]); } else if (odata["cmd"]=="hw") { xres=mpwtrim(qres).split("\n"); qpage=xres.shift(); if (qpage=="~HW") mpwShowHWInfo(xres); mpwActivateMainMenuItem("hw"); } else if (odata["cmd"]=="sp") { xres=mpwtrim(qres).split("\n"); qpage=xres.shift(); if (qpage=="~SP") mpwShowSampler(xres); mpwActivateMainMenuItem("sp"); } else if ((odata["cmd"]=="as") || (odata["cmd"]=="was")) { xres=mpwtrim(qres).split("\n"); qpage=xres.shift(); if ((qpage=="~AS") || (qpage=="~WAS")) { _pinsetupcache=qres; mpwShowAnalogPinInfo(xres); _mpwqTimer_unlockablecode="mpwApplyPinPanelSettings()"; } mpwActivateMainMenuItem("as"); } else if ((odata["cmd"]=="dp") || (odata["cmd"]=="wdp")) { xres=mpwtrim(qres).split("\n"); qpage=xres.shift(); if ((qpage=="~DP") || (qpage=="~WDP")) { mpwShowDisplayInfo(xres); _mpwqTimer_unlockablecode="mpwApplyDisplaySettings()"; mpwApplyDisplaySettings(); mpwLoadDisplayDump() } mpwActivateMainMenuItem("dp"); } else if ((odata["cmd"]=="ds") || (odata["cmd"]=="wds")) { __mpwLoadDigitalPins_lockreload=false; xres=mpwtrim(qres).split("\n"); qpage=xres.shift(); if ((qpage=="~DS") || (qpage=="~WDS")) { _doutsetupcache=qres; mpwShowDOutPinInfo(xres); } mpwActivateMainMenuItem("ds"); _mpwqTimer_code="mpwLoadDigitalPins()"; } else mpwSetHTML('
'+qres+"
"); } // ------------------------------------------- function mpwParseHexData(xv) { xret=""; xv=mpwtrim(xv); for (var ii=0;ii < xv.length;ii+=2) xret+=String.fromCharCode(parseInt("0x"+xv.charAt(ii)+xv.charAt(ii+1))); return xret; } // ------------------------------------------- function mpwdStr(xstr) { qstr=xstr; xarray=new Array(); while (qstr!="") { xarray.push(parseInt("0x"+qstr.substr(0,2))); qstr=qstr.substr(2); } var rstr=utfBytesToStr(xarray); var xrstr=""; for (var i=0;i < rstr.length;i++) { var ch=rstr.charAt(i); if (ch=="\\") { i++; ch=rstr.charAt(i); if (ch=="0") ch=String.fromCharCode(0); } xrstr+=ch; } return xrstr; } // ------------------------------------------- function mpwSetHTML(xhtml) { var o=document.getElementById("qmpwc"); if (o) o.innerHTML=xhtml; } // ------------------------------------------- var xhttp=new XMLHttpRequest(); xhttp.onreadystatechange=function() { mpwFlashWebLed("xhttpled"); if (this.readyState==4 && this.status==404) mpwOnNotFound(this); else if (this.readyState==4 && this.status==200) eval("mpwOnDataReceived(this,this.responseText,_last_xdata)"); } // ------------------------------------------- var xhttpauto=new XMLHttpRequest(); xhttpauto.onreadystatechange=function() { mpwFlashWebLed("xhttpautoled"); if (this.readyState==4 && this.status==404) mpwOnNotFound(this); else if (this.readyState==4 && this.status==200) eval("mpwOnDataReceived(this,this.responseText,_last_xdataauto)"); } // ------------------------------------------- function mpwSetWebLedState(xid,xstate) { var o=document.getElementById(xid); if (o) o.style.opacity=((xstate)?(0.9):(0.2)); } // ------------------------------------------- __mpwFlashWebLed_lasttimeout=false; function mpwFlashWebLed(xid) { mpwSetWebLedState(xid,true); if (__mpwFlashWebLed_lasttimeout) clearTimeout(__mpwFlashWebLed_lasttimeout); __mpwFlashWebLed_lasttimeout=setTimeout("mpwSetWebLedState('"+xid+"',false)",200); } setTimeout("mpwJSinit()",100); // ------------------------------------------- function mpwJSinit() { var e=document.getElementsByTagName("div"); for (var ii=0;ii < e.length;ii++) if (e[ii].getAttribute("x")=="n") { e[ii].innerHTML=mpwJSgetcontent(); break; } mpwqTimer(); mpwShowLedPanel(); } function mpwgraph_paint(xdiv,xparams,qtype) { var qparams=mpwgraph_parseParams(xparams); var cparams=qtype.split("."); xtype=cparams.shift(); if (xtype=="small") { var xtop=0; var xleft=0; var xwidth=306; var xheight=64; var s=''; s+=''; s+=''+ ''+ ''+ ''; s+=''; var xtimes=qparams["xtimes"].split(","); var xmintime=0; var xmaxtime=xtimes[xtimes.length-1]; var xdiftime=xmaxtime-xmintime; var xdif10=10000; for (var yy=0;yy<100;yy++) { var xvx=(Math.ceil((xmintime+(xdif10*yy))/10)*10)-xmintime; var xv=(xwidth/xdiftime)*xvx; if (xv>xwidth) break; s+='<'+'polyline points="'+(xleft+xv)+','+xtop+' '+(xleft+xv)+','+(xtop+xheight); s+='" stroke-dasharray="1,1" d="M5 20 l215 0" style="fill:none;stroke:#FFFFFF;stroke-opacity:0.1;stroke-width:1px" />'; s+=''; s+=(Math.round(xvx/10000)*10)+" ms"; s+=''; } var xmin=qparams["xdatamin"]; var xmax=qparams["xdatamax"]; var xdif=xmax-xmin; if (xdif<=0) xdif=1; var xvx=qparams["xdatarms"]-xmin; var xv=xheight-(xheight/xdif*xvx); s+='<'+'polyline points="0,'+xv+' '+(xwidth-1)+','+xv; s+='" style="fill:none;stroke:#8F0000;stroke-width:1" />'; var xvx=qparams["xdataavg"]-xmin; var xv=xheight-(xheight/xdif*xvx); s+='<'+'polyline points="0,'+xv+' '+(xwidth-1)+','+xv; s+='" stroke-dasharray="5,5" d="M5 40 l215 0" style="fill:none;stroke:#008F00;stroke-width:1" />'; s+='<'+'polyline points="'; s+=mpwgraph_polyline(qparams,0,0,xwidth,xheight,xmin,xmax); s+='" style="fill:none;stroke:#00FF00;stroke-width:1" />'; s+=''; } if (xtype=="big") { var qwidth=xdiv.offsetWidth; var qheight=xdiv.offsetHeight-10; var xwidth=qwidth-120; var xheight=qheight-50; var xleft=60; var xtop=25; var qpinconf=false; if (_qpinconfs) qpinconf=_qpinconfs[qparams["xpin"]]; var s=''; s+=''; s+=''+ ''+ ''+ ''+ ''+ ''+ ''; s+=''; s+=''; var xtimes=qparams["xtimes"].split(","); var xmintime=0; var xmaxtime=xtimes[xtimes.length-1]; var xdiftime=xmaxtime-xmintime; var xdif10=10000; var hasminus=(xdif10<0); xdif10=Math.abs(xdif10); adif=Math.abs(xdiftime); pxf=new Array(1,2,5); var xok=false; for (var qi=-3;qi<=10;qi++) { for (var qix=0;qix < pxf.length;qix++) { var xstepd=pxf[qix]; var xstep=xstepd*Math.pow(10,qi); if ((xwidth/adif*xstep)>30) { xdif10=xstep; xok=true; break; } } if (xok) break; } if (hasminus) xdif10=-xdif10; for (var yy=0;yy<100;yy++) { var xvx=(Math.ceil((xmintime+(xdif10*yy))/xdif10)*xdif10)-xmintime; var xv=(xwidth/xdiftime)*xvx; if (xv>xwidth) break; s+='<'+'polyline points="'+(xleft+xv)+','+xtop+' '+(xleft+xv)+','+(xtop+xheight); s+='" stroke-dasharray="1,1" d="M5 20 l215 0" style="fill:none;stroke:#505050;stroke-width:1px" />'; s+=''; s+=(Math.round(xvx/xdif10)*xdif10/1000)+"ms"; s+=''; } var xmin=parseInt(qparams["xdatamin"]); var xmax=parseInt(qparams["xdatamax"]); // var xmin=0; // var xmax=1023; var qpmin=xmin var qpmax=xmax; if (qpinconf) { var qpmin=qpinconf["xmin"]; var qpmax=qpinconf["xmax"]; if ((qpmin-qpmax)==0) { qpmin=0;qpmax=1023; } } var xdif=xmax-xmin; if (xdif<=0) { xmin=xmax-1; xmax++; xdif=xmax-xmin; } var pmin=qpmin+(((qpmax-qpmin)/1023)*xmin); var pmax=qpmin+(((qpmax-qpmin)/1023)*xmax); pdif=pmax-pmin; var pdif10 = pdif/10; var xdif10 = xdif/10; var hasminus=(pdif10<0); pdif10=Math.abs(pdif10); adif=Math.abs(pdif); pxf=new Array(1,2,5); var xok=false; for (var qi=-3;qi<=10;qi++) { for (var qix=0;qix < pxf.length;qix++) { var xstepd=pxf[qix]; var xstep=xstepd*Math.pow(10,qi); if ((xheight/adif*xstep)>20) { pdif10=xstep; xok=true; break; } } if (xok) break; } if (hasminus) pdif10=-pdif10; var hasminus=(xdif10<0); xdif10=Math.abs(xdif10); adif=Math.abs(xdif); pxf=new Array(1,2,5); var xok=false; for (var qi=-3;qi<=10;qi++) { for (var qix=0;qix < pxf.length;qix++) { var xstepd=pxf[qix]; var xstep=xstepd*Math.pow(10,qi); if ((xheight/adif*xstep)>20) { xdif10=xstep; xok=true; break; } } if (xok) break; } if (hasminus) xdif10=-xdif10; for (var yy=-1;yy<=30;yy++) { var qxv=0; var pqxv=0; var xvx=0; xvx=(Math.ceil((xmin+(xdif10*yy))/xdif10)*xdif10)-xmin; qxv=xheight-(xheight/xdif*xvx); if ((qxv >= 0) && (qxv <= xheight)) { var xv=xtop+qxv; s+='<'+'polyline points="'+xleft+','+xv+' '+(xleft+xwidth-1)+','+xv; s+='" stroke-dasharray="3,3" d="M5 20 l215 0" style="fill:none;stroke:#00FF00;stroke-width:1px;stroke-opacity:0.2" />'; if (((qxv-5) > 0) && ((qxv+5) < xheight)) { s+=''; s+=Math.round((xmin+xvx)*100)/100; s+=''; } } var pxvx=0; pxvx=(Math.ceil((pmin+(pdif10*yy))/pdif10)*pdif10)-pmin; pqxv=xheight-(xheight/pdif*pxvx); if ((pqxv >= 0) && (pqxv <= xheight)) { var pxv=xtop+pqxv; s+='<'+'polyline points="'+xleft+','+pxv+' '+(xleft+xwidth-1)+','+pxv; s+='" stroke-dasharray="1,1" d="M5 20 l215 0" style="fill:none;stroke:#FFFFFF;stroke-width:1px;stroke-opacity:0.5" />'; s+=''; s+=mpwtrim(mpwXUnitFormat(Math.round((pmin+pxvx)*100)/100)+" "+qpinconf["xunit"]); s+=''; } if ((qxv < 0) && (pqxv < 0)) break; } var xvx=qparams["xdatarms"]-xmin; var pval=qpmin+(((qpmax-qpmin)/1023)*qparams["xdatarms"]); var qv=xheight-(xheight/xdif*xvx); if ((qv >= 0) && (qv <= xheight)) { var xv=xtop+qv; s+='<'+'polyline points="'+xleft+','+xv+' '+(xleft+xwidth-1)+','+xv; s+='" style="fill:none;stroke:#8F0000;stroke-width:1" />'; s+=''; // s+=Math.round((xmin+xvx)*10)/10; s+=mpwtrim(mpwXUnitFormat(Math.round(pval*100)/100)+" "+qpinconf["xunit"]); s+=''; } var xvx=qparams["xdataavg"]-xmin; var pval=qpmin+(((qpmax-qpmin)/1023)*qparams["xdataavg"]); var qv=xheight-(xheight/xdif*xvx); if ((qv >= 0) && (qv <= xheight)) { var xv=xtop+qv; s+='<'+'polyline points="'+xleft+','+xv+' '+(xleft+xwidth-1)+','+xv; s+='" stroke-dasharray="5,5" d="M5 40 l215 0" style="fill:none;stroke:#008F00;stroke-width:1" />'; s+=''; // s+=Math.round((xmin+xvx)*10)/10; s+=mpwtrim(mpwXUnitFormat(Math.round(pval*100)/100)+" "+qpinconf["xunit"]); s+=''; } var xvx=qparams["xdatamin"]-xmin; var pval=qpmin+(((qpmax-qpmin)/1023)*qparams["xdatamin"]); var qv=xheight-(xheight/xdif*xvx); if ((qv >= 0) && (qv <= xheight)) { var xv=xtop+qv; s+='<'+'polyline points="'+xleft+','+xv+' '+(xleft+xwidth-1)+','+xv; s+='" stroke-dasharray="1,1" d="M5 20 l215 0" style="fill:none;stroke:#FFFF00;stroke-width:1" />'; s+=''; // s+=Math.round((xmin+xvx)*10)/10; s+=mpwtrim(mpwXUnitFormat(Math.round(pval*100)/100)+" "+qpinconf["xunit"]); s+=''; } var xvx=qparams["xdatamax"]-xmin; var pval=qpmin+(((qpmax-qpmin)/1023)*qparams["xdatamax"]); var qv=xheight-(xheight/xdif*xvx); if ((qv >= 0) && (qv <= xheight)) { var xv=xtop+qv; s+='<'+'polyline points="'+xleft+','+xv+' '+(xleft+xwidth-1)+','+xv; s+='" stroke-dasharray="1,1" d="M5 20 l215 0" style="fill:none;stroke:#008F8F;stroke-width:1" />'; s+=''; // s+=Math.round((xmin+xvx)*10)/10; s+=mpwtrim(mpwXUnitFormat(Math.round(pval*100)/100)+" "+qpinconf["xunit"]); s+=''; } s+='<'+'polyline points="'; s+=mpwgraph_polyline(qparams,xleft,xtop,xwidth,xheight,xmin,xmax); s+='" style="fill:none;stroke:#00FF00;stroke-width:1" />'; s+=''; var qxname=""; if (qpinconf) { var qn=mpwtrim(qpinconf["xname"]); if (qn!="") qxname=" - "+qn; } s+=''; s+='A'+qparams["xpin"]+qxname; s+=''; s+=''; } xdiv.innerHTML=s; } function mpwgraph_polyline(qparams,xs,ys,xwidth,xheight,xmin,xmax) { var xout=new Array(); var xtimes=qparams["xtimes"].split(","); var xmintime=0; var xmaxtime=xtimes[xtimes.length-1]; var xdiftime=xmaxtime-xmintime; var xsamples=qparams["xdatasamples"].split(","); var xminsample=xmin; var xmaxsample=xmax; var xdifsample=xmaxsample-xminsample; if (xdifsample<=0) { xminsample=xmaxsample-1; xmaxsample++; xdifsample=xmaxsample-xminsample; } for (var x=0;x < qparams["xdatacount"]; x++) { var xtime=xtimes[x]-xmintime; var xsample=xsamples[x]-xminsample; var px=xs+(xwidth/xdiftime*xtime); var py=ys+(xheight-(xheight/xdifsample*xsample)); xout.push(px+","+py); } return (xout.join(" ")); } function mpwgraph_parseParams(xparams) { var xret=new Object; var qx=xparams.split("\n"); for (var i=0;i < qx.length;i++) { var px=qx[i].split("="); var xk=px.shift(); var xv=px.join("="); xret[xk]=xv; } return xret; } // ------------------------------------------- function mpwUTFhex(xval) { var s=""; var xarray=utfStrToBytes(xval); for(var ii=0;ii < xarray.length;ii++) { var q=xarray[ii].toString(16).toUpperCase(); while ((q.length & 1)==1) q="0"+q; s+=q; } return s; } // ------------------------------------------- function mpwtrim(inputString) { if (inputString==null) inputString=new String(""); if (typeof inputString != "string") inputString=new String(inputString); var retValue = inputString; var ch = retValue.substring(0, 1); while ((ch == " ") || (ch =="\n") || (ch =="\r")) { retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); } ch = retValue.substring(retValue.length - 1, retValue.length); while ((ch == " ") || (ch =="\n") || (ch =="\r")) { retValue = retValue.substring(0, retValue.length - 1); ch = retValue.substring(retValue.length - 1, retValue.length); } return retValue; } // ------------------------------------------- function mpwtrimUTFstring(xstr,maxlen) { var xret=""; xstr=mpwtrim(xstr); for (var ii=0;ii < xstr.length;ii++) { var xch=xstr.charAt(ii); var xc=xret+xch; xha=utfStrToBytes(xc); if (xha.length<=maxlen) xret+=xch; else break; } return xret; } // ------------------------------------------- function mpwXUnitFormat(xval) { var xabsval=Math.abs(xval); if (xabsval<0.001) xabsval=0; else if (xabsval<1) xabsval=(Math.floor(xabsval*1000))/1000; else if (xabsval<1000) xabsval=(Math.floor(xabsval*100))/100; else if (xabsval<10000) xabsval=(Math.floor(xabsval/1000*100))/100+"k"; else if (xabsval<1000000) xabsval=(Math.floor(xabsval/1000*10))/10+"k"; else if (xabsval<10000000) xabsval=(Math.floor(xabsval/1000/1000*100))/100+"M"; else if (xabsval<1000000000) xabsval=(Math.floor(xabsval/1000/1000*10))/10+"M"; else if (xabsval<10000000000) xabsval=(Math.floor(xabsval/1000/1000/1000*100))/100+"G"; else if (xabsval<1000000000000) xabsval=(Math.floor(xabsval/1000/1000/1000*10))/10+"G"; else xabsval=mpwtrim(xabsval); if (xval<0) xabsval="-"+xabsval; return xabsval; } // ------------------------------------------- function CapacityEx(size,multiplier,unitname) { if (!(multiplier>0)) multiplier=1024; if ((!unitname) || (mpwtrim(unitname)=="")) unitname="B"; var mm="0"; tt=new Array("k","M","G","T","P","E"); var ii=0; if (size>0) { var xtt=""; while (size>=multiplier) { size=size/multiplier; xtt=tt[ii];ii++; if (ii>=tt.length) break; } mm=(Math.round(size*100)/100)+" "+xtt+unitname; } return mm; } // ------------------------------------------- function CFormatTime(tt) { var ss=new Object(); var tf=Math.floor(tt); if (tf!=tt) { var tms=Math.round((tt-tf)*100000)/100; if (tms>0) ss["msec"]=tms; } ss["sec"]=Math.floor(tt%60); tt=Math.floor(tt/60); if (tt>0) { ss["min"]=tt%60; tt=Math.floor(tt/60); if (tt>0) { ss["hrs"]=tt%24; tt=Math.floor(tt/24); if (tt>0) ss["days"]=tt; } } var xs=new Array(); for (var p in ss) { xs.unshift(mpwtrim(ss[p]+" "+p)); } return xs.join(" "); } // ------------------------------------------- function set_cookie ( name, value, exp_seconds, path, domain, secure ) { var cookie_string = name + "=" + escape ( value ); if ( exp_seconds ) { var expires = new Date (); ex=expires.valueOf()+exp_seconds*1000; expires = new Date (ex); cookie_string += "; expires=" + expires.toGMTString(); } if ( path ) cookie_string += "; path=" + escape ( path ); if ( domain ) cookie_string += "; domain=" + escape ( domain ); if ( secure ) cookie_string += "; secure"; document.cookie = cookie_string; } // ------------------------------------------- function delete_cookie(cookie_name) { var cookie_date=new Date(); cookie_date.setTime(cookie_date.getTime()-1); document.cookie=cookie_name+="=; expires="+cookie_date.toGMTString(); } function get_cookie ( cookie_name ) { var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' ); if (results) return ( unescape ( results[1] ) ); else return null; } // ------------------------------------------- function mpwlog(xtext) { mpwlogx(xtext,true); } function mpwlogadd(xtext) { mpwlogx(xtext,false); } // ------------------------------------------- function mpwlogx(xtext,xdelete) { var o=document.getElementById("xlog"); if (!o) { o=document.createElement("textarea"); document.body.appendChild(o); o.id="xlog"; o.style.position="fixed"; o.style.left="10px"; o.style.top="10px"; } var qx=""; if (typeof xtext == "object") { var s=""; for (var p in xtext) s+="["+p+"]="+xtext[p]+"\n"; qx=s; } else qx=xtext+"\n"; if (xdelete) o.value=qx; else o.value=o.value+qx; } // ------------------------------------------- function utfStrToBytes(str) { var out = new Array(); var p = 0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); if (c < 128) out[p++] = c; else if (c < 2048) { out[p++] = (c >> 6) | 192; out[p++] = (c & 63) | 128; } else { out[p++] = (c >> 12) | 224; out[p++] = ((c >> 6) & 63) | 128; out[p++] = (c & 63) | 128; } } return out; } // ------------------------------------------- function utfBytesToStr(bytes) { var ix = 0; if( bytes.slice(0,3) == "\xEF\xBB\xBF") ix = 3; var string = ""; for( ; ix < bytes.length; ix++ ) { var byte1 = bytes[ix]; if( byte1 < 0x80 ) { string += String.fromCharCode(byte1); } else if( byte1 >= 0xC2 && byte1 < 0xE0 ) { var byte2 = bytes[++ix]; string += String.fromCharCode(((byte1&0x1F)<<6) + (byte2&0x3F)); } else if( byte1 >= 0xE0 && byte1 < 0xF0 ) { var byte2 = bytes[++ix]; var byte3 = bytes[++ix]; string += String.fromCharCode(((byte1&0xFF)<<12) + ((byte2&0x3F)<<6) + (byte3&0x3F)); } else if( byte1 >= 0xF0 && byte1 < 0xF5) { var byte2 = bytes[++ix]; var byte3 = bytes[++ix]; var byte4 = bytes[++ix]; var codepoint = ((byte1&0x07)<<18) + ((byte2&0x3F)<<12)+ ((byte3&0x3F)<<6) + (byte4&0x3F); codepoint -= 0x10000; string += String.fromCharCode((codepoint>>10) + 0xD800,(codepoint&0x3FF) + 0xDC00); } } return string; } function mpwtaxsetline() { if (_areaobjs.length>0) { var naobjs=new Array(); for (var ii=0;ii < _areaobjs.length;ii++) { var ox=_areaobjs[ii]; var xi = document.getElementById(ox["id"]); if (xi) { el=ox["el"]; ta=ox["ta"]; while (el.scrollHeight <= (ta.scrollHeight+20)) { var xlinenr=Math.round(el.getAttribute("xlinenr")); if (!((xlinenr<=0) || (xlinenr>=0))) xlinenr=0; var str=""; for(var no=0;no<10;no++) str += ((xlinenr+no+1)+'\n'); el.value=el.value+str; el.setAttribute("xlinenr",xlinenr+no); } el.scrollTop = ta.scrollTop; el.style.top = (ta.offsetTop) + "px"; el.style.left = (ta.offsetLeft - 30) + "px"; naobjs.push(ox); } } _areaobjs=naobjs; if ((!_areatimer) && (_areaobjs.length>0)) _areatimer=setTimeout("_areatimer=false;mpwtaxsetline();",100); } } function mpwDisableSelection(element) { if (typeof element.onselectstart != 'undefined') { element.onselectstart = function() { return false; }; } else if (typeof element.style.MozUserSelect != 'undefined') { element.style.MozUserSelect = 'none'; } else { element.onmousedown = function() { return false; }; } } function mpwcreateTextAreaWithLines(id) { _areaxid++; var el = document.createElement('TEXTAREA'); var ta = document.getElementById(id); var string = ''; el.className = 'textAreaWithLines'; el.style.width = "25px"; el.style.minWidth = el.style.width; el.style.maxWidth = el.style.width; el.style.minHeight = ta.offsetHeight+"px";; el.style.maxHeight = ta.offsetHeight+"px";; ta.style.minWidth = ta.offsetWidth+"px"; ta.style.maxWidth = ta.offsetWidth+"px"; ta.style.minHeight = ta.offsetHeight+"px"; ta.style.maxHeight = ta.offsetHeight+"px"; el.style.position = "absolute"; el.style.overflow = 'hidden'; el.style.textAlign = 'right'; el.style.paddingRight = '2px'; el.setAttribute("xlinenr",0); el.setAttribute("readonly","readonly"); el.setAttribute("readonly","readonly"); el.setAttribute("tabIndex", "-1"); el.onfocus = function() { ta.focus();}; var qqid="xlinearea__"+_areaxid; el.id=qqid; el.style.zIndex = 0; mpwDisableSelection(el); ta.style.zIndex = 1; ta.style.position = "relative"; ta.parentNode.insertBefore(el, ta.nextSibling); qx=new Object(); qx["id"]=qqid; qx["el"]=el; qx["ta"]=ta; _areaobjs.push(qx); if (_areaobjs.length==1) mpwtaxsetline(); ta.focus(); } // ------------------------------------------- function mpwStoreDisplaySetup() { var xdata=new Object(); xdata["cmd"]="wdp"; var o=document.getElementById("xmpwdisplaysrc"); if (o) { xdata["src"]=_mpwCheckDisplaySrcParsed; mpwJSsenddata(xdata); } } // ------------------------------------------- function mpwApplyDisplaySettings() { var ol=document.getElementById("xmpwdisplaysrclength"); var ot=document.getElementById("xmpwdisplaysrc"); var or=document.getElementById("xmpwdisplaysrclengthremain"); _mpwCheckDisplaySrcParsed=""; var xm=mpwCheckDisplaySrc(ot.value); if ((or) && (ol) && (ot)) { ol.innerHTML=_mpwCheckDisplaySrcParsed.length; or.innerHTML=_lastDisplaySetupObject["xmax"]-_mpwCheckDisplaySrcParsed.length; } var o=document.getElementById("xmpwdisplaystorebutton"); if (o) o.style.display=( (ot.getAttribute("xorigsrc")!=ot.value) && (xm=="") )?"block":"none"; var o=document.getElementById("xmpwdisplayerr"); if ((o) && (o.innerHTML!=xm)) o.innerHTML=xm; } // ------------------------------------------- _mpwCheckDisplaySrcParsed="" function mpwCheckDisplaySrc(xsrc) { var xp=new Array(); var xret=""; _mpwCheckDisplaySrcParsed=""; var xsrcx=xsrc.split("\n"); for (var ll=0;ll < xsrcx.length; ll++) { var t=xsrcx[ll]; var tx=""; for (var ii=0;ii < t.length; ii++) { var c=t.charCodeAt(ii); var ct=t.charAt(ii); if (c==13) continue; if (!( ((c>=32) && (c<127)) || (c==10) ) ) { var xii=ii-10; if (xii<0) xii=0; if (xret=="") xret="Řádek "+(ll+1)+", neplatný znak: "+t.substring(xii,ii)+ ">"+ct+ "<"+t.substring(ii+1,ii+10)+" (kód: "+c+")."; } tx+=ct; } xp.push(tx); var xmaxpline=50; if (t.length>xmaxpline) if (xret=="") xret="Řádek "+(ll+1)+" je příliš dlouhý. Největší akceptovatelná délka řádku je "+ xmaxpline+" znaků. Délka řádku je "+t.length+", přebývá "+(t.length-xmaxpline)+"."; } _mpwCheckDisplaySrcParsed=xp.join("\n"); var qlen=_mpwCheckDisplaySrcParsed.length; var maxlen=0; if (_lastDisplaySetupObject) maxlen=_lastDisplaySetupObject["xmax"]; if (qlen > maxlen) xret="Zdrojový text nastavení displaye je příliš velký. Maximum je "+maxlen+ " bajtů, aktuální délka: "+qlen+" bajtů. Rozdíl: "+(qlen-maxlen)+" bajtů."; return xret; } // ------------------------------------------- function mpwDisplayClickButton(xbutt) { var xdata=new Object(); xdata["cmd"]="db"; xdata["bid"]=xbutt; xdata["_eval"]="mpwDisplayClickButton_finished(qres)"; mpwJSsenddata(xdata); } // ------------------------------------------- function mpwDisplayClickButton_finished(qres) { if (qres!="OK") alert(qres); else { mpwLoadDisplayDump(); } } // ------------------------------------------- function mpwLoadDisplayDump() { var xdata=new Object(); xdata["_eval"]="mpwLoadDisplayDump_finished(qres)"; _last_xdataauto=xdata; xurl="./cfg?cmd="+mpwUTFhex("dd"); xhttpauto.open("GET",xurl,true); xhttpauto.send(); } // ------------------------------------------- function mpwLoadDisplayDump_finished(qres) { var s=qres.split("\r").join("").split("\n"); if (s.shift()=="~DD") var xlines=new Array(); var xdtype="" var xtype="" for (var ii=0;ii < s.length;ii++) { var ch=":"; var qx=s[ii].split(ch); var qk=qx.shift();qx=qx.join(ch); if (qk=="T") xdtype=qx; else if (qk=="S") { var cq=qx.split(","); var o=document.getElementById("qlcddispstats"); if (o) o.innerHTML="Počet proměnných: "+cq.shift()+"
Ram pro proměnné:"+cq.shift(); } if (xdtype==1602) { if (qk.charAt(0)=="L") { var ql=Math.round(qk.charAt(1)); if (ql>=0) { if (qx.length>16) qx=substr(0,16); while (qx.length<16) qx+=" "; xlines.push(qx); } } } } if ((xdtype==1602) && (xlines.length==2)) { var o=document.getElementById("qlcddisppre"); if (o) o.textContent=xlines.shift()+"\n"+xlines.shift(); } } // ------------------------------------------- function mpwShowDisplayInfo(xres) { var qobj=new Object(); qobj["xtype"]=""; qobj["xsrc"]=""; qobj["xmax"]=0; qobj["xrsum"]=0; qobj["xcsum"]=0; for (var ii=0;ii < xres.length;ii++) { var xq=mpwtrim(xres[ii]).split(":"); var xk=xq.shift(); var xv=xq.pop(); if (xk=="T") qobj["xtype"]=xv; else if (xk=="B") qobj["xmax"]=xv; else if (xk=="R") qobj["xrsum"]=xv; else if (xk=="C") qobj["xcsum"]=xv; else if (xk=="D") qobj["xsrc"]+=mpwParseHexData(xv); } if (qobj["xcsum"]!=qobj["xrsum"]) qobj["xsrc"]=""; if (mpwGetDisplayTypeStr(qobj["xtype"])=="") { var xhtml=''+ ''+ ''+ '
'+ 'Display - nastavení 
Podpora pro display je vypnuta.
'; mpwSetHTML(xhtml); } else { var xinit=false; var o=document.getElementById("xmpwdisplaysrc"); if (!o) { var xhtml=''+ ''+ ''+ '
'+ ' 
'+ '
'+ '
'+ '
'+ '
'+ ''+ '
'+ '
'+
'                '+"\n"+
'                '+
'
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ '
  
  
'+ '
'+ '
'+ '
'+ '
Aktuální délka: , maximum: '+qobj["xmax"]+', zbývá: '+ '.
'+ '
' '
'; mpwSetHTML(xhtml); mpwcreateTextAreaWithLines("xmpwdisplaysrc"); xinit=true; var o=document.getElementById("xmpwdisplaysrc"); } if (o) { if (xinit) o.value=qobj["xsrc"]; o.setAttribute("xorigsrc",qobj["xsrc"]); _lastDisplaySetupObject=qobj; } var o=document.getElementById("xdisplaytypespan"); if (o) o.innerHTML=mpwGetDisplayTypeStr(qobj["xtype"]); } } // ------------------------------------------- function mpwGetDisplayTypeStr(ctx) { var xret=""; if (ctx==1602) xret="LCD Keypad Shield 16x2"; return xret; } // ------------------------------------------- function mpwShowHWInfo(xres) { var xconfmap=new Object(); xconfmap["t"]=new Array( "sys/uptime|Hs/Čas od posledního restartu" ); xconfmap["c"]=new Array( "hw/pincount|Počet analogových pinů", "hw/statusledpin|Pin pro stavovou LED", "mpw/logtime|S/Interval přenosu dat", "mpw/resumetime|S/Interval přenosu po chybě", "mpw/maxerrors|Maximum chyb přenosu", "mpw/errors|Počet chyb přenosu", "serial/enabled|B/Log do seriové konzoly", "disp/enabled|B/Display", "disp/type|Dt/Typ displaye", "sys/seconds|Sx/Čítač sekund (timeS)" ); xconfmap["f"]=new Array( "mpw/fveid|Pw/FVEID" ); xconfmap["h"]=new Array( "mpw/server|Server" ); xconfmap["x"]=new Array( "mpw/enabled|B/Přenos dat" ); xconfmap["r"]=new Array( "sys/ram|Volná ram (bytů)", "sw/arduino|XV/Arduino sw verze", "hw/maxphysram|Fyzická RAM (max. adresa)", "hw/maxaddrram|Adresovatelná RAM (max. adresa)", "hw/maxeprom|Eprom (max. adresa)", "hw/flash|Flash", "hw/spm_pagesize|SPM_PAGESIZE", "hw/e2pagesize|E2PAGESIZE" ); xconfmap["v"]=new Array( "sw/version|MicroLog sw verze" ); xconfmap["m"]=new Array( "net/mac|MAC Adresa" ); xconfmap["n"]=new Array( "net/ip|IP Adresa", "net/mask|Maska", "net/gw|Brána", "net/dns|DNS" ); xconfmap["w"]=new Array( "http/enabled|B/Stav", "http/port|WWW Port" ); xconfmap["de"]=new Array( "disp/port|B/Emulace" ); xconfmap["ds"]=new Array( "dpin/conf|xDPins/Digitální piny", "dpin/status|xLed/Stav pinů", "dpin/logicmask|xMask/Maska výstupní logiky" ); xconfmap["mpw"]=new Array( "time/mpwRealTime|xRTimeStamp/Systémový čas", "time/mpwremoteTime|xTimeStamp/Poslední synchronizace", "time/mpwremoteCheckedAtS|Sx/timeS při synchronizaci", "mpw/mpwlogintimeS|Sx/timeS při navázání spojení", "mpw/mpwDeviceId|DeviceID", "mpw/mpwAccessId|AccessID", "time/xComStatus|xComStatus/Příznaky data a času", "time/mpwWeek|Číslo týdne", "time/mpwDayOfWeek|xmpwDayOfWeek/Den v týdnu", "time/mpwSyncAge|Sx/Poslední synchronizace před" ); var xconfmapnames=new Object(); xconfmapnames["sys"]="Systém"; xconfmapnames["time"]="Čas"; xconfmapnames["net"]="Net"; xconfmapnames["hw"]="Hardware"; xconfmapnames["http"]="HTTP"; xconfmapnames["dpin"]="Digitální výstupy"; xconfmapnames["serial"]="USB Serial"; xconfmapnames["disp"]="Display"; xconfmapnames["mpw"]="MyPower.CZ"; xconfmapnames["sw"]="Firmware"; var xconfobj=new Object(); for (var ii=0;ii < xres.length;ii++) { var qx=xres[ii].split(":"); var xk=mpwtrim(qx.shift()); var xv=qx.join(":"); var qmap=xconfmap[xk]; if (typeof qmap == "object") { var cv=""; if ((xk=="r") || (xk=="c")) cv=xv.split("."); else if ((xk=="n") || (xk=='w') || (xk=='ds') || (xk=='mpw')) cv=xv.split("/"); else cv=new Array(mpwtrim(xv)); for (var ix=0;ix < qmap.length; ix++) { var xqmap=qmap[ix].split("|"); var qmaptext=xqmap.pop(); var qmappath=xqmap.shift(); var qpathx=qmappath.split("/"); var qpath1=qpathx[0]; var qpath2=qpathx[1]; if (!xconfobj[qpath1]) xconfobj[qpath1]=new Object(); var xcfx=new Object(); xcfx["path"]=qmappath; xcfx["text"]=qmaptext; var xc=qmaptext.split("/"); var xn=mpwtrim(xc.pop()); var xt=mpwtrim(xc.shift()); ctx=cv[ix]; xcfx["type"]=xt; xcfx["rawvalue"]=ctx; if (xt=="Dt") { var xcc=mpwGetDisplayTypeStr(ctx); ct=(xcc=="")?'neznámý':xcc; } else if (xt=="Hs") ct=CFormatTime(parseInt("0x"+ctx)/1000); else if (xt=="S") ct=CFormatTime(ctx); else if (xt=="xTimeStamp") ct=mpwFmtHwinfoTimestamp(ctx); else if (xt=="xRTimeStamp") ct=ctx.split("@").join(" "); else if (xt=="xComStatus") ct=mpwFmtHwinfoxComStaus(ctx); else if (xt=="xmpwDayOfWeek") ct=mpwFmtHwDayOfWeek(ctx); else if (xt=="Sx") ct=CFormatTime(ctx)+' ('+ctx+')'; else if (xt=="xDPins") ct='
'+ ctx.split(",").join('
')+'
'; else if (xt=="xLed") ct=mpwHWLedHTML(ctx,xt); else if (xt=="xMask") ct=mpwHWLedHTML(ctx,xt); else if (xt=="B") ct=(ctx==1)?'zapnuto':'vypnuto'; else if (xt=="Pw") { var xwd="block"; var xws="none"; var od=document.getElementById("xhwdivfveid_def"); var os=document.getElementById("xhwdivfveid_show"); if ((od) && (os)) { xwd=od.style.display; xws=os.style.display; } if (mpwtrim(ctx)=="") { ct='
nenastaveno
'; } else { ct='
nastaveno Zobrazit
'; ct+='
'+ctx+' Skrýt
'; } } else if (xt=="XV") ct=(ctx.substring(0,ctx.length-2))+"."+(ctx.substring(ctx.length-2)); else if ((xk=="r") && (ctx<0)) continue; else ct=ctx; xcfx["title"]=xn; xcfx["htmltext"]=ct; var xtr=''+xn+ ''+ct+''; xcfx["htmltr"]=xtr; xconfobj[qpath1][qpath2]=xcfx; } } } var xhtml=""; for (var p in xconfmapnames) //for (var p in xconfobj) { var xconfdir=xconfobj[p]; if (xconfdir) { xhtml+='
'+ '
'+xconfmapnames[p]+'
'+ '
'; for (var px in xconfdir) { var xconfitem=xconfdir[px]; xhtml+=xconfitem["htmltr"]; } xhtml+='
'+ '
'; } } mpwSetHTML(xhtml); } function mpwFmtHwDayOfWeek(ctx) { var xret="-"; if (ctx==1) xret="Pondělí"; else if (ctx==2) xret="Úterý"; else if (ctx==3) xret="Středa"; else if (ctx==4) xret="Čtvrtek"; else if (ctx==5) xret="Pátek"; else if (ctx==6) xret="Sobota"; else if (ctx==7) xret="Neděle"; if (xret=="-") { xret=ctx; } else { xret=ctx+''+" - "+xret+""; } return xret; } function mpwFmtHwinfoxComStaus(ctx) { var xret="-"; var xint=parseInt(ctx); if (xint>=0) { var xdm=xint&0x30; var xdaysinmonth=28; if (xdm==0x00) xdaysinmonth=28; else if (xdm==0x10) xdaysinmonth=29; else if (xdm==0x20) xdaysinmonth=30; else if (xdm==0x30) xdaysinmonth=31; var xdst=((xint&0x08)!=0)?"yes":"no"; var xlastdayinmonth=((xint&0x04)!=0)?"yes":"no"; xret='MonthDays '+xdaysinmonth+' | '+ 'DST '+xdst+' | '+ 'LastDayInMonth '+xlastdayinmonth; } return xret; } function mpwFmtHwinfoTimestamp(ctx) { var xret=""; var mp=ctx.split("."); var xyear=parseInt(mp.shift()); var xmonth=parseInt(mp.shift()); var xday=parseInt(mp.shift()); var xtimeS=parseInt(mp.shift()); var xhh=Math.floor(xtimeS/3600); var xmm=Math.floor((xtimeS%3600)/60); var xss=Math.floor((xtimeS%3600)%60); xret=xday+"."+xmonth+"."+xyear+" "+(xhh<10?"0"+xhh:xhh)+":"+(xmm<10?"0"+xmm:xmm)+":"+(xss<10?"0"+xss:xss)+ " "+''+"("+xtimeS+")"; return xret; } // ----------------------------------------------- function mpwHWLedHTML(ctx,xt) { var xret=""; var isled=(xt=="xLed"); var qint=parseInt("0x"+ctx); if (!(qint>=0)) qint=0; for (var i=0;i<16;i++) { var xled='
'+ ''+ ''+ '
'; xret+=xled; } return xret; } // ----------------------------------------------- function mpwHWinfoShowFVEID() { var od=document.getElementById("xhwdivfveid_def"); var os=document.getElementById("xhwdivfveid_show"); if ((od) && (os)) { os.style.display = (os.style.display!="none")?"none":"block"; od.style.display = (os.style.display!="none")?"none":"block"; } } _pinsetupcache=""; _pinsetupcache_onloadcode=""; // ------------------------------------------- function mpwReloadPinSetupCacheIfNeeded(onDoneEvalCode) { _pinsetupcache_onloadcode=onDoneEvalCode; if (mpwtrim(_pinsetupcache)=="") { var xdata=new Object(); xdata["_eval"]="mpwReloadPinSetupCacheIfNeeded_Done(qres)"; xdata["cmd"]="as"; mpwJSsenddata(xdata); } else mpwReloadPinSetupCacheIfNeeded_Done(_pinsetupcache); } // ------------------------------------------- function mpwReloadPinSetupCacheIfNeeded_Done(qres) { _pinsetupcache=qres; if (_pinsetupcache_onloadcode!="") setTimeout("mpwReloadPinSetupCacheIfNeeded_Event()",10); } // ------------------------------------------- function mpwReloadPinSetupCacheIfNeeded_Event() { eval(_pinsetupcache_onloadcode); _pinsetupcache_onloadcode=""; } // ------------------------------------------- function mpwApplyPinPanelSettings() { if (typeof _lastPinSetupObject != "object") _lastPinSetupObject=new Object(); var e=document.getElementsByTagName("div"); for (var ii=0;ii < e.length; ii++) if (e[ii].getAttribute("xispinpanel")=="yes") { var o=e[ii]; var xpinpanel=o; var xpindex=o.getAttribute("xpindex"); var xenabled=document.getElementById("mpintext_"+xpindex+"_enabled"); var oen=document.getElementById("xpingenabledpanel_"+xpindex); var xtype=document.getElementById("mpintext_"+xpindex+"_type"); var xgroup=document.getElementById("mpintext_"+xpindex+"_group"); var pinsetupobject=_lastPinSetupObject[xpindex]; if (typeof pinsetupobject != "object") pinsetupobject=new Object(); var venabled=0; if ((xenabled) && (oen)) { if (xenabled.checked) { venabled=1; oen.className="mxenabled"; } else oen.className="mxdisabled"; } vtype="s"; if (xtype) vtype=xtype.value; var otype=document.getElementById("mpin_"+xpindex+"_typediv"); if (otype) { xqout=""; if (vtype=='s') xqout='SMP'; if (vtype=='a') xqout='AVG'; if (vtype=='e') xqout='RMS'; if (vtype=='m') xqout='MIN'; if (vtype=='x') xqout='MAX'; otype.innerHTML=xqout; } vgroup=0; if (xgroup) vgroup=xgroup.value; var ogroupc=document.getElementById("mpin_"+xpindex+"_pingroupcolordiv"); if (ogroupc) { ogroupc.style.display=(vgroup==0?'none':'block'); ogroupc.style.backgroundColor=mpwPinGroup2HTMLColor(vgroup); } var oname=document.getElementById("mpin_"+xpindex+"_namediv"); var xname=document.getElementById("mpintext_"+xpindex+"_name"); var vname=""; if ((oname) && (xname)) { var xv=mpwtrim(xname.value); if (xv=="") { oname.style.color="#505050"; oname.innerHTML="nepojmenováno"; } else { oname.style.color="#FFFFFF"; vname=mpwtrimUTFstring(xv,20); oname.textContent=vname; } } var ounit=document.getElementById("mpin_"+xpindex+"_unitdiv"); var xunit=document.getElementById("mpintext_"+xpindex+"_unit"); var omin=document.getElementById("mpin_"+xpindex+"_mindiv"); var xmin=document.getElementById("mpintext_"+xpindex+"_min"); var omax=document.getElementById("mpin_"+xpindex+"_maxdiv"); var xmax=document.getElementById("mpintext_"+xpindex+"_max"); var vmax=0; var vmin=0; var vunit=""; if ((xmax) && (omax) && (omin) && (xmin) && (ounit) && (xunit)) { vmax=parseFloat(mpwtrim(xmax.value)); vmin=parseFloat(mpwtrim(xmin.value)); vunit=mpwtrim(xunit.value); if (! ((vmax<0) || (vmax>=0)) ) vmax=0; if (! ((vmin<0) || (vmin>=0)) ) vmin=0; qmax=Math.floor(10000*Math.abs(vmax))/10000; qmin=Math.floor(10000*Math.abs(vmin))/10000; if (vmax<0) vmax=-qmax; else vmax=qmax; if (vmin<0) vmin=-qmin; else vmin=qmin; var xabsmax=2000000000; if (vmax>xabsmax) vmax=xabsmax; else if (vmax<-xabsmax) vmax=-xabsmax; if (vmin>xabsmax) vmin=xabsmax; else if (vmin<-xabsmax) vmin=-xabsmax; omin.textContent=mpwXUnitFormat(vmin); omax.textContent=mpwXUnitFormat(vmax); vunit=mpwtrimUTFstring(vunit,5); ounit.textContent=vunit; xpinpanel.setAttribute("_qpin_minmax",vmin+"/"+vmax); var ws=xpinpanel.getAttribute("_lastpinval"); if (!((ws>=0) && (ws<=1023))) ws=0; mpwSetPinValue(xpindex,ws); } pinsetupobject["min"]=mpwtrim(vmin); pinsetupobject["max"]=mpwtrim(vmax); pinsetupobject["uni"]=mpwtrim(vunit); pinsetupobject["nam"]=mpwtrim(vname); pinsetupobject["ena"]=mpwtrim(venabled); pinsetupobject["typ"]=mpwtrim(vtype); pinsetupobject["grp"]=mpwtrim(vgroup); _lastPinSetupObject[xpindex]=pinsetupobject; } var o=document.getElementById("mpwpinsetupstorebutton"); if (o) o.style.display=(mpwPinSetupChanged()?"block":"none"); } // ------------------------------------------- function mpwMakePinSetupStr() { var s=new Array(); if (typeof _lastPinSetupObject == "object") for (var px in _lastPinSetupObject) { var qx=new Array(); if (typeof _lastPinSetupObject[px] == "object") for (var p in _lastPinSetupObject[px]) qx.push(p+":"+_lastPinSetupObject[px][p]); s.push("A"+px+"="+qx.join("\t")); } var xret=s.join("\n"); return xret; } // ------------------------------------------- function mpwPinSetupChanged() { return ((mpwMakePinSetupStr()!=_lastPinSetupStr) && (_lastPinSetupStr!="init")); } // ------------------------------------------- function mpwOnPinClick(xpindex) { var e=document.getElementsByTagName("div"); for (var ii=0;ii < e.length;ii++) { if (e[ii].getAttribute("xispinopts")=="yes") e[ii].style.display=(e[ii].getAttribute("xpindex")==xpindex)?"block":"none"; if (e[ii].getAttribute("xispinpanel")=="yes") e[ii].className=(e[ii].getAttribute("xpindex")==xpindex)?"mxpin mxselected":e[ii].className="mxpin mxnormal"; } } // ------------------------------------------- function mpwLoadAnalogPins_finished(qres) { var pst=qres.split(","); for (var ii=0;ii < pst.length;ii++) { pcx=mpwtrim(pst[ii]).split(":"); var pk=pcx.shift(); if (pk.charAt(0)=="A") { var pn=parseInt(pk.substring(1)); if (pn>=0) { var pv=pcx.pop(); mpwSetPinValue(pn,pv); } } } } // ------------------------------------------- function mpwSetPinValue(pn,pv) { var o=document.getElementById("xpingfxdiv_"+pn); if (o) o.style.width=Math.round(100*pv/1023)+"%"; var o=document.getElementById("xpingfxdivval_"+pn); if (o) o.innerHTML=pv; var o=document.getElementById("xpinpanel_"+pn); var oval=document.getElementById("mpin_"+pn+"_valuediv"); if ((o) && (oval)) { var xmin=0; var xmax=0; var xmx=mpwtrim(o.getAttribute("_qpin_minmax")).split("/"); if (xmx.length==2) { xmin=parseFloat(mpwtrim(xmx.shift())); xmax=parseFloat(mpwtrim(xmx.shift())); } var xv=xmin+(((xmax-xmin)/1023)*pv); oval.textContent=mpwXUnitFormat(xv); o.setAttribute("_lastpinval",pv); } } // ------------------------------------------- function mpwLoadAnalogPins() { var xdata=new Object(); xdata["_eval"]="mpwLoadAnalogPins_finished(qres)"; _last_xdataauto=xdata; xurl="./pin"; xhttpauto.open("GET",xurl,true); xhttpauto.send(); } // ------------------------------------------- function mpwPinGroup2HTMLColor(xgroup) { var xret="#000000"; if (xgroup==1) xret="#FF0000"; else if (xgroup==2) xret="#00FF00"; else if (xgroup==3) xret="#0000FF"; return xret; } // ------------------------------------------- function mpwShowAnalogPinInfo(xres) { var haspindiv=document.getElementById("xpinsetupdiv"); _lastPinSetupStr=""; var xhtml=""; if (!haspindiv) { xhtml+='<'+'style>'; xhtml+='.pinbkg {cursor:pointer;} .pinbkg:hover { background:rgba(255,255,255,0.05); } '; xhtml+='.mpwtdxh { font-weight:bold;color:#808080;width:100px;background:rgba(255,255,255,0.01); } '; xhtml+='.mxdisabled { opacity:0.2; } '; xhtml+='.mxenabled { } '; xhtml+='.mxpin { float:left;margin-right:6px;border-bottom:1px solid #808080;'+ 'border-top:1px solid #000000;border-right:1px solid #808080;border-left:1px solid #000000;background:#101010;margin-bottom:6px;} '; xhtml+='.mxnormal { } '; xhtml+='.mxselected { background:rgba(255,200,0,0.05); } '; xhtml+='
'+ '
'; } xpohtmls=new Array(); xpinvalues=new Object(); for (var ii=0;ii < xres.length;ii++) { xqr=mpwParsePinConfLine(xres[ii]); if (xqr) { qpindex=xqr["xpin"]; qpconf=xqr["xpconf"]; if (haspindiv) { var o=document.getElementById("mpintext_"+qpindex+"_name"); if (o) o.value=qpconf["xname"]; var o=document.getElementById("mpintext_"+qpindex+"_enabled"); if (o) o.checked=qpconf["xenabled"]; var o=document.getElementById("mpintext_"+qpindex+"_unit"); if (o) o.value=qpconf["xunit"]; var o=document.getElementById("mpintext_"+qpindex+"_type"); if (o) o.value=qpconf["xtype"]; var o=document.getElementById("mpintext_"+qpindex+"_group"); if (o) o.value=qpconf["xgroup"]; var o=document.getElementById("mpintext_"+qpindex+"_min"); if (o) o.value=qpconf["xmin"]; var o=document.getElementById("mpintext_"+qpindex+"_max"); if (o) o.value=qpconf["xmax"]; } else { xpinvalues[qpindex]=qpconf["xvalue"]; xhtml+='
'+ '
'; xhtml+='
'; xhtml+='
'+ '
'+ '
A'+qpindex+'
'+ '
'+ '
'+ '
'+ '
'+ ' 
'+ '
'+ '
'+ '
'; xhtml+='
'; xhtml+='
'; xhtml+='
'+ '
'; xhtml+='
'; xpinoptshtml=''; xpohtmls.push(xpinoptshtml); } } } if (!haspindiv) { xhtml+='
'; xhtml+='
' xhtml+=''; xhtml+=''; xhtml+=''; xhtml+=''; mpwSetHTML(xhtml); _lastPinSetupStr="init"; mpwApplyPinPanelSettings(); _lastPinSetupStr=mpwMakePinSetupStr(); for (var p in xpinvalues) mpwSetPinValue(p,xpinvalues[p]); } else { _lastPinSetupStr="init"; mpwApplyPinPanelSettings(); _lastPinSetupStr=mpwMakePinSetupStr(); } } // ------------------------------------------- function mpwpinoptx(xparam) { var xq=xparam.split("-"); xcmd=xq.shift(); xpin=parseInt(xq.pop()); if (xcmd=="close") mpwOnPinClick("none"); else if ((xcmd=="reset") && (xpin>=0)) { if (confirm("Opravdu smazat nastavení pinu A"+xpin+"?")) { var o=document.getElementById("mpintext_"+xpin+"_name"); if (o) o.value=""; var o=document.getElementById("mpintext_"+xpin+"_enabled"); if (o) o.checked=false; var o=document.getElementById("mpintext_"+xpin+"_unit"); if (o) o.value=""; var o=document.getElementById("mpintext_"+xpin+"_min"); if (o) o.value=""; var o=document.getElementById("mpintext_"+xpin+"_max"); if (o) o.value=""; var o=document.getElementById("mpintext_"+xpin+"_type"); if (o) o.value=""; var o=document.getElementById("mpintext_"+xpin+"_group"); if (o) o.value=""; mpwApplyPinPanelSettings(); } } } // ------------------------------------------- function mpwReStorePinSetup() { if (confirm("Opravdu zrušit provedené změny a obnovit poslední uložené nastavení?")) mpwLoadPage("as"); } // ------------------------------------------- function mpwStorePinSetup() { var xdata=new Object(); xdata["cmd"]="was"; if (typeof _lastPinSetupObject == "object") { for (var px in _lastPinSetupObject) { var xps=_lastPinSetupObject[px]; if (typeof xps=="object") for (var p in xps) xdata["A"+px+"."+p]=xps[p]; xdata["A"+px+".~w"]=px; } mpwJSsenddata(xdata); } } // ------------------------------------------- function mpwParsePinConfLine(xline) { xret=false; xline=mpwtrim(xline); if (xline!="") { qret=new Object(); var qpx=mpwtrim(xline).split(":"); var qpn=mpwtrim(qpx.shift()); var qpc=mpwtrim(qpx.pop()); if (qpn.charAt(0)=="A") { var qcfx=qpc.split("/"); qpconf=new Object(); qpconf["xenabled"]=false; qpconf["xmax"]=0; qpconf["xmin"]=0; qpconf["xunit"]=""; qpconf["xname"]=""; qpconf["xvalue"]=0; qpconf["xtype"]="s"; qpconf["xgroup"]="0"; if (qcfx.length>2) { // TTT GG E // 0000 0000 var qpx=qcfx.shift(); qpconf["xenabled"]=(parseInt("0x"+qpx)&parseInt('00000001', 2)!=0); var qgroup=((parseInt("0x"+qpx)&parseInt('00001100', 2))) >> 2; qpconf["xgroup"]=qgroup; var qtype=(parseInt("0x"+qpx)&parseInt('01110000', 2)); var rt="s"; if (qtype==0x00) rt="s"; if (qtype==0x10) rt="a"; if (qtype==0x20) rt="e"; if (qtype==0x30) rt="m"; if (qtype==0x40) rt="x"; qpconf["xtype"]=rt; var xxq=(parseFloat(qcfx.shift())); if (!((xxq>=0) || (xxq<=0))) xxq=0; qpconf["xmin"]=xxq; var xxq=(parseFloat(qcfx.shift())); if (!((xxq>=0) || (xxq<=0))) xxq=0; qpconf["xmax"]=xxq; qpconf["xname"]=mpwdStr(qcfx.shift()); qpconf["xunit"]=mpwdStr(qcfx.shift()); var xb=parseInt(qcfx.shift()); if (!(xb>=0)) xb=0; qpconf["xvalue"]=xb; } var qpindex=parseInt(qpn.substring(1)); if (qpindex>=0) { qret["xpin"]=qpindex; qret["xpconf"]=qpconf; xret=qret; } } } return xret; } _samplerdata=new Object(); _mpwSamplerSelectPin=-1; _qpinconfs=new Object(); // ----------------------------------------------- function mpwShowSampler(xres) { mpwSamplerParseXres(xres); var xhtml=''; var oinit=document.getElementById("xsmpHTML_initialized"); if (!oinit) { xhtml+='
'+ '
Klikněte na pin pro úpravu jeho nastavení ...
'+ xpohtmls.join("\n")+'
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
SMPAVGRMSMINMAX
'+ '
'+ ''; } xhtml+=''; xhtml+='
'; xhtml+='
'; xhtml+='< Klikněte na pin pro zobrazení detailů.'; xhtml+='
'; xhtml+='
'; xhtml+='
'; mpwSetHTML(xhtml); } for (var p in _samplerdata["pins"]) { var o=document.getElementById("xsmppanel_"+p+"_smp"); if (o) o.innerHTML=_samplerdata["pins"][p]["V"]; var o=document.getElementById("xsmppanel_"+p+"_avg"); if (o) o.innerHTML=_samplerdata["pins"][p]["A"]; var o=document.getElementById("xsmppanel_"+p+"_rms"); if (o) o.innerHTML=_samplerdata["pins"][p]["S"]; var o=document.getElementById("xsmppanel_"+p+"_min"); if (o) o.innerHTML=_samplerdata["pins"][p]["M"]; var o=document.getElementById("xsmppanel_"+p+"_max"); if (o) o.innerHTML=_samplerdata["pins"][p]["X"]; } for (var i=0;i < _samplerdata["sampler"].length;i++) { var qx=_samplerdata["sampler"][i]; var xtimes=qx["times"].join(","); var xlength=qx["length"]; var xmillis=qx["millis"]; for (var p in qx["pins"]) { var o=document.getElementById("xsmppanel_"+p+"_main"); if (o) { var xdata=qx["pins"][p]["data"]; var xdatarms=xdata["S"]; var xdataavg=xdata["A"]; var xdatamin=xdata["M"]; var xdatamax=xdata["X"]; var xdatacount=xdata["C"]; var xdatasamples=qx["pins"][p]["samples"].join(","); var sx="xtimes="+xtimes+"\n"+ "xpin="+p+"\n"+ "xlength="+xlength+"\n"+ "xmillis="+xmillis+"\n"+ "xdataavg="+xdataavg+"\n"+ "xdatarms="+xdatarms+"\n"+ "xdatamin="+xdatamin+"\n"+ "xdatamax="+xdatamax+"\n"+ "xdatacount="+xdatacount+"\n"+ "xdatasamples="+xdatasamples; o.setAttribute("xmpwPinGraphData",sx); var xdiv=document.getElementById("xsmppanel_"+p+"_graph"); mpwgraph_paint(xdiv,sx,"small"); if (_mpwSamplerSelectPin==p) mpwSamplerPaintBigGraph(p); } } } mpwReloadPinSetupCacheIfNeeded("mpwSamplerRefreshPinConfig()"); } // ----------------------------------------------- function mpwSamplerRefreshPinConfig() { _qpinconfs=new Object(); var qx=_pinsetupcache.split("\n"); var txn=qx.shift(); if ((txn=="~AS") || (txn=="~WAS")) { for (var ii=0;ii < qx.length;ii++) { var xqr=mpwParsePinConfLine(qx[ii]); if (xqr) { var qpindex=xqr["xpin"]; var qpconf=xqr["xpconf"]; _qpinconfs[qpindex]=qpconf; var og=document.getElementById('xsmppanel_'+qpindex+'_graph'); var o=document.getElementById('xsmppanel_'+qpindex+'_main'); if ( (o) && (og) ) { if (qpconf["xenabled"]==0) { o.style.opacity="0.5"; // og.style.display="none"; } else { o.style.opacity="1"; // og.style.display="block"; } } var o=document.getElementById('xsmppanel_'+qpindex+'_pinname'); if (o) o.textContent=qpconf["xname"]; var o=document.getElementById('xsmppanel_'+qpindex+'_groupcolordiv'); if (o) { o.style.display=(qpconf["xgroup"]==0)?"none":"block"; o.style.backgroundColor=mpwPinGroup2HTMLColor(qpconf["xgroup"]); } var o=document.getElementById('xsmppanel_'+qpindex+'_pinvalue'); if (o) { var qsmpdata=_samplerdata["pins"][qpindex]; if (qsmpdata) { var xtype=qpconf["xtype"]; var pv=0; if (xtype=="s") { pv=qsmpdata["V"]; qsxc='SMP' } else if (xtype=="a") { pv=qsmpdata["A"]; qsxc='AVG' } else if (xtype=="e") { pv=qsmpdata["S"]; qsxc='RMS' } else if (xtype=="m") { pv=qsmpdata["N"]; qsxc='MAX' } else if (xtype=="x") { pv=qsmpdata["X"]; qsxc='MIN' } var xmin=qpconf["xmin"]; var xmax=qpconf["xmax"]; var xv=xmin+(((xmax-xmin)/1023)*pv); o.textContent=mpwtrim(mpwXUnitFormat(xv)+" "+qpconf["xunit"]); var qcz=o.innerHTML; o.innerHTML=qsxc+" "+qcz; } } } } } var oinit=document.getElementById("xsmpHTML_body"); if (oinit) if (oinit.style.display=="none") { oinit.style.display="block"; mpwSamplerSelectPin(-1); } } // ----------------------------------------------- function mpwSamplerOnBigGraphClose() { var o=document.getElementById("xmpwbiggraphdiv"); if (o) o.parentNode.removeChild(o); } // ----------------------------------------------- function mpwSamplerOnBigGraphClick() { if (_mpwSamplerSelectPin>=0) { var o=document.getElementById("xmpwbiggraphdiv"); if (!o) { var o=document.createElement("DIV"); o.id="xmpwbiggraphdiv"; document.body.appendChild(o); o.innerHTML='
'; } o.style.display="block"; o.style.position="fixed"; o.style.left="0px"; o.style.top="0px"; o.style.width="100%"; o.style.height="100%"; o.style.background="black"; var xpin=_mpwSamplerSelectPin; var op=document.getElementById("xsmppanel_"+xpin+"_main"); if (op) { var sx=op.getAttribute("xmpwPinGraphData"); var xdiv=document.getElementById("xmpwbiggraphdivmain"); mpwgraph_paint(xdiv,sx,"big"); } } } // ----------------------------------------------- function mpwSamplerPaintBigGraph(xpin) { var o=document.getElementById("xsmppanel_"+xpin+"_main"); if (o) { var sx=o.getAttribute("xmpwPinGraphData"); var xdiv=document.getElementById("xsmppanel_biggraph"); xdiv.onclick=function() { mpwSamplerOnBigGraphClick(); }; xdiv.style.cursor="pointer"; mpwgraph_paint(xdiv,sx,"big"); var xdiv=document.getElementById("xmpwbiggraphdivmain"); if (xdiv) mpwgraph_paint(xdiv,sx,"big"); } } // ----------------------------------------------- function mpwSamplerSelectPin(xpin) { var i=0; if (xpin==-1) xpin=_mpwSamplerSelectPin; _mpwSamplerSelectPin=xpin; while (true) { var o=document.getElementById("xsmppanel_"+i+"_panelindextext"); if (!o) break; o.style.color=(i==xpin)?"#FFC000":""; if (i==xpin) mpwSamplerPaintBigGraph(i); i++; } } // ------------------------------------------- function mpwSamplerOnPinClick(xpin) { mpwSamplerSelectPin(xpin); } // ------------------------------------------- function mpwSamplerParseXres(xres) { _samplerdata=new Object(); _samplerdata["sampler"]=new Array(); _samplerdata["pins"]=new Object(); var samplerun=false; for (var ii=0;ii < xres.length;ii++) { var q=mpwtrim(xres[ii]); if (q!="") { var qx=q.split(":"); var kx=mpwtrim(qx.shift()); if (kx!="") { if (kx.substr(0,1)=="A") _samplerdata["pins"][kx.substr(1)]=mpwSamplerParsePinLine(qx.shift()); else if (kx=="MS") { if (typeof samplerun=="object") _samplerdata["sampler"].push(samplerun); samplerun=new Object(); samplerun["pins"]=new Object(); samplerun["millis"]=parseInt("0x"+qx.shift()); } if (typeof samplerun=="object") { if (kx=="L") samplerun["length"]=parseInt("0x"+qx.shift()); else if (kx=="T") { var qd=mpwtrim(qx.shift()); samplerun["times"]=new Array(); var qms=0; for (var x=0;x<128;x++) { var qt=parseInt("0x0"+mpwtrim(qd.substr(x << 1,2)))+400; qms+=qt; samplerun["times"].push(qms); } } else if (kx.substr(0,1)=="S") samplerun["pins"][kx.substr(1)]=mpwSamplerParseSampleLine(qx.shift(),qx.shift()); } } } } if (typeof samplerun=="object") _samplerdata["sampler"].push(samplerun); } // ------------------------------------------- function mpwSamplerParseSampleLine(xdata,xsamples) { var xret=new Object(); xret["data"]=mpwSamplerParsePinLine(xdata); var xs=xsamples.split("/"); xsHI=mpwtrim(xs.shift()); xsLO=mpwtrim(xs.shift()); var smpHI8=new Array(); var smpLO2=new Array(); for (var x=0;x<128;x++) smpHI8.push(parseInt("0x0"+xsHI.substr(x << 1,2))); for (var x=0;x<32;x++) smpLO2.push(parseInt("0x0"+xsLO.substr(x << 1,2))); var qsmp=new Array(); for (var x=0;x<128;x++) qsmp.push((smpHI8[x] << 2)| ((smpLO2[x>>2]>>((x&0x03) << 1))&0x03) ); xret["samples"]=qsmp; return xret; } // ------------------------------------------- function mpwSamplerParsePinLine(xpline) { var xret=new Object(); var sx=mpwtrim(xpline).split(","); for (var ii=0;ii < sx.length;ii++) { var qx=mpwtrim(sx[ii]).split("="); if (qx.length==2) xret[qx.shift()]=parseInt(qx.shift()); } return xret; } _mpwLoadSamplerPins_TickCounter=0; // ------------------------------------------- function mpwLoadSamplerPins() { if (_mpwLoadSamplerPins_TickCounter>=2) { _mpwLoadSamplerPins_TickCounter=0; mpwJSxmenu('sp'); } else _mpwLoadSamplerPins_TickCounter++; } _doutsetupcache=""; _doutsetupcache_onloadcode=""; _doutsetupobject=new Object(); // ------------------------------------------------------------------------- function mpwShowDOutPinInfo(xres) { var xhtml=""; var oxdiv=document.getElementById("qDPINpanelMainDiv"); if (!oxdiv) { xhtml=""; xhtml+=mpwDOutPinCSS(); xhtml+='
'+ '
'; xhtml+='
'+ ''+ ''+ ''+ ''+ '
ALL OFF
'+ '
' mpwSetHTML(xhtml); oxdiv=document.getElementById("qDPINpanelMainDiv"); } for (var ii=0;ii < xres.length;ii++) { var xl=mpwtrim(xres[ii]); if (xl!="") { var cl=xl.split(":"); var cix=cl.shift() if (cix.substr(0,2)=="DX") { var dpx=cl.shift().split("/"); var xdpinstatus=parseInt("0x"+dpx.shift()); var xdpinlogicmask=parseInt("0x"+dpx.shift()); for (var ix=0;ix < 16; ix++) { _doutsetupobject[ix]["cStatus"]=((xdpinstatus&(1 << ix))==0)?"OFF":"ON"; _doutsetupobject[ix]["cLogic"]=((xdpinlogicmask&(1 << ix))==0)?"std":"neg"; } } else if (cix.substr(0,1)=="D") { var cDPinIndex=parseInt(cix.substr(1)); if ((cDPinIndex>=0) && (cDPinIndex<16)) { var cDPinNumber=parseInt(cl.shift()); var qxx=cl.shift(); var cDPinName=mpwdStr(qxx); var cIsValidPinNumber=( (cDPinNumber>=22) && (cDPinNumber<=49) ); var ox=_doutsetupobject[cDPinIndex]; if (!ox) { ox=new Object(); ox["_SetStatus"]=false; ox["_SetStatus_send"]=false; } ox["cDPinIndex"]=cDPinIndex; ox["cDPinNumber"]=cDPinNumber; ox["cDPinName_changed"]="no"; if ( (mpwtrim(ox["cDPinName"])!="") && (ox["cDPinName"]!=cDPinName) ) ox["cDPinName_changed"]="yes"; ox["cDPinName"]=cDPinName; ox["cIsValidPinNumber"]=cIsValidPinNumber; ox["cStatus"]="OFF"; _doutsetupobject[cDPinIndex]=ox; var xled='
'+ ''+ ''+ '
'; var o=document.getElementById("qDPINpanel_"+cDPinIndex); if (!o) { var xhtml= '
'+ ''+ ''+ ''+ ''+ '
'+ ''+ '
'+ '
'+ ''+ ''+ ''+ ''+ '
'+ '
'+xled+'
'+ '
PIN: '+ '
'+ '
OFF
'+ '
'; var qd=document.createElement("div"); qd.innerHTML=xhtml; oxdiv.appendChild(qd); qd.style.float="left"; } } } } } for (var ii=0;ii<16;ii++) { var dpinobj=_doutsetupobject[ii]; if (dpinobj) { if (dpinobj["_SetStatus_send"]=="yes") { if (_doutsetupobject[ii]["_SetStatus"]==_doutsetupobject[ii]["cStatus"]) { _doutsetupobject[ii]["_SetStatus_send"]=false; _doutsetupobject[ii]["_SetStatus"]=false; } } var o=document.getElementById("qDPINpanel_"+ii+"_name"); if (o) { if ( (o.getAttribute("xinit")!="yes") || ( (dpinobj["cDPinName_changed"]=="yes") && (o.getAttribute("xhasfocus")!="yes") ) ) { o.setAttribute("xinit","yes"); o.value=dpinobj["cDPinName"]; } } var o=document.getElementById("qDPINpanel_"+ii+"_pinindex"); if (o) o.innerHTML="D"+dpinobj["cDPinIndex"]; var o=document.getElementById("qDPINpanel_"+ii+"_pinnumber"); if (o) o.innerHTML="D"+dpinobj["cDPinNumber"]; var otr=document.getElementById("qDPINpanel_"+ii+"_pinnumbertr"); if (o) o.innerHTML="D"+dpinobj["cDPinNumber"]; var o=document.getElementById("qDPINpanel_"+ii+"_switch"); if ((o) && (otr)) mpwUpdateDPinButtonState(ii); var o=document.getElementById("qDPINpanel_"+ii); if (o) { if (dpinobj["cIsValidPinNumber"]) { otr.style.display="block"; o.style.opacity="1"; } else { otr.style.display="block"; o.style.opacity="0.2"; } } } } mpwDOutCheckPinNameChanges(); } // ------------------------------------------------------------------------- function mpwOnDPinClick(xpinindex) { var dpinobj=_doutsetupobject[xpinindex]; var o=document.getElementById("qDPINpanel_"+xpinindex+"_switch"); if ((o) && (dpinobj) && (dpinobj["cIsValidPinNumber"])) { mpwDisableSelection(o); if ((_doutsetupobject[xpinindex]["_SetStatus"]=="ON") || (_doutsetupobject[xpinindex]["_SetStatus"]=="OFF") ) { if ((_doutsetupobject[xpinindex]["_SetStatus_send"]=="yes") || (_doutsetupobject[xpinindex]["_SetStatus_send"]=="no")) { _doutsetupobject[xpinindex]["_SetStatus"]=((_doutsetupobject[xpinindex]["_SetStatus"]=="ON")?"OFF":"ON"); _doutsetupobject[xpinindex]["_SetStatus_send"]="no"; } else _doutsetupobject[xpinindex]["_SetStatus"]=false; } else if (dpinobj["cStatus"]=="OFF") _doutsetupobject[xpinindex]["_SetStatus"]="ON"; else if (dpinobj["cStatus"]=="ON") _doutsetupobject[xpinindex]["_SetStatus"]="OFF"; mpwUpdateDPinButtonState(xpinindex); } mpwStoreDigitalPinChanges(); } // ------------------------------------------------------------------------- function mpwUpdateDPinButtonState(xpinindex) { var dpinobj=_doutsetupobject[xpinindex]; var o=document.getElementById("qDPINpanel_"+xpinindex+"_switch"); if ((o) && (dpinobj) && (dpinobj["cIsValidPinNumber"])) { var issentset=((dpinobj["_SetStatus_send"]=="yes") || (dpinobj["_SetStatus_send"]=="no")); if (_doutsetupobject[xpinindex]["_SetStatus"]=="OFF") { o.className="xcssDPinON2OFF"+(issentset?"sent":""); o.innerHTML=">OFF"; } else if (_doutsetupobject[xpinindex]["_SetStatus"]=="ON") { o.className="xcssDPinOFF2ON"+(issentset?"sent":""); o.innerHTML=">ON"; } else if (dpinobj["cStatus"]=="OFF") { o.className="xcssDPinOFF"; o.innerHTML="OFF"; } else if (dpinobj["cStatus"]=="ON") { o.className="xcssDPinON"; o.innerHTML="ON"; } var oled=document.getElementById("qDPINpanel_"+xpinindex+"_pinLed"); if (oled) { var xst=(dpinobj["cStatus"]=="ON"); if (dpinobj["cLogic"]=="neg") xst=!xst; oled.style.opacity=xst?0.9:0.2; } var olx=document.getElementById("qDPINpanel_"+xpinindex+"_pinlogic"); if (olx) olx.innerHTML=(dpinobj["cLogic"]=="neg")?"NEG":""; // if (xpinindex==0) mpwlog(""); // mpwlogadd(xpinindex+":"+dpinobj["cStatus"]+" "+dpinobj["cLogic"]+" "+dpinobj["_SetStatus_send"]+" "+dpinobj["_SetStatus"]); } } // ------------------------------------------------------------------------- function mpwStoreDPinSetup(xquery) { var xdata=new Object(); xdata["cmd"]="wds"; if (typeof xquery == "object") { __mpwLoadDigitalPins_lockreload=true; for (var px in xquery) xdata[px]=xquery[px]; mpwJSsenddata(xdata); } } // ------------------------------------------------------------------------- function mpwApplyDigitalPinChanges() { var xquery=new Object(); var xchanges=0; for (var ii=0;ii<16;ii++) { var dpinobj=_doutsetupobject[ii]; if (dpinobj) { var xset=dpinobj["_SetStatus"]; if ((xset=="ON") || (xset=="OFF")) { xchanges++; xquery["s"+ii]=(xset=="ON")?"1":"0"; _doutsetupobject[ii]["_SetStatus_send"]="yes"; mpwUpdateDPinButtonState(ii); } } } if (xchanges>0) mpwStoreDPinSetup(xquery); } // ------------------------------------------------------------------------- function mpwDOutPinCSS() { var xcss=''; return xcss; } // ------------------------------------------------------------------------- _mpwStoreDigitalPinChanges_timer=-1; function mpwStoreDigitalPinChanges() { if (_mpwStoreDigitalPinChanges_timer>=0) clearTimeout(_mpwStoreDigitalPinChanges_timer); _mpwStoreDigitalPinChanges_timer=setTimeout("mpwStoreDigitalPinChanges_int()",1000); } // ------------------------------------------------------------------------- function mpwStoreDigitalPinChanges_int() { mpwApplyDigitalPinChanges(); } // ------------------------------------------------------------------------- function mpwDOutAllOff() { for (var ii=0;ii<16;ii++) { var dpinobj=_doutsetupobject[ii]; if (dpinobj) { if ((dpinobj["cStatus"]=="ON") && (dpinobj["_SetStatus"]!="OFF")) mpwOnDPinClick(ii); } } } // ------------------------------------------------------------------------- function mpwDOutCheckPinNameChanges() { var xchanges=0; var xquery=new Object(); for (var ii=0;ii<16;ii++) { var dpinobj=_doutsetupobject[ii]; var oinput=document.getElementById("qDPINpanel_"+ii+"_name"); if ((dpinobj) && (oinput)) { var xname=mpwtrim(oinput.value); if (dpinobj["cDPinName"]!=xname) { xchanges++; xquery[ii]=xname; } } } var o=document.getElementById("qDPINStoreButton"); if (o) o.style.display=(xchanges>0)?"block":"none"; var qx=new Array(xchanges,xquery); return qx; } // ------------------------------------------------------------------------- function mpwStoreDPinNames() { var qx=mpwDOutCheckPinNameChanges(); var xchanges=qx.shift(); var xquery=qx.shift(); if (xchanges>0) { __mpwLoadDigitalPins_lockreload=true; var xdata=new Object(); xdata["cmd"]="wds"; if (typeof xquery == "object") { for (var px in xquery) { var xv=xquery[px]; xv=mpwtrimUTFstring(xv,19); xdata["D"+px+".nam"]=xv; var oinput=document.getElementById("qDPINpanel_"+px+"_name"); if (oinput) oinput.setAttribute("xinit","send"); } mpwJSsenddata(xdata); } } } __mpwLoadDigitalPins_lockreload=false; // ------------------------------------------------------------------------- function mpwLoadDigitalPins() { mpwDOutCheckPinNameChanges(); if (!__mpwLoadDigitalPins_lockreload) { var xdata=new Object(); xdata["_eval"]="mpwLoadDigitalPins_finished(qres)"; xdata["cmd"]="ds"; _last_xdataauto=xdata; mpwJSsenddata_xhttp(xdata,xhttpauto); } } function mpwLoadDigitalPins_finished(qres) { var xres=qres.split("\n"); xres.shift(); mpwShowDOutPinInfo(xres); } function mpwShowEpromPage() { var xhtml='
'+ '
Stáhnout zálohu EPROM
'+ // '
Obnovit ze souboru:

'+ // '

'+ '
'+ ''; mpwSetHTML(xhtml); } function mpwEpromDownload() { var xdata=new Object(); xdata["cmd"]="ep"; mpwJSsenddata_iframe(xdata,"epromworkframe"); } // ------------------------------------------- function mpwShowSDCard() { var xhtml="SD"; mpwSetHTML(xhtml); }