// Javascript for printing OpenSprinkler schedule page // Firmware v1.8 // All content is published under: // Creative Commons Attribution ShareAlike 3.0 License // Sep 2012, Rayshobby.net // colors to draw different programs var prog_color=["rgba(0,0,200,0.5)","rgba(0,200,0,0.5)","rgba(200,0,0,0.5)","rgba(0,200,200,0.5)"]; var days_str=["Sun","Mon","Tue","Wed","Thur","Fri","Sat"]; var xstart=80,ystart=80,stwidth=40,stheight=180; var winwidth=stwidth*sd['nbrd']*8+xstart, winheight=26*stheight+ystart; var sid,sn,t; var simt=Date.UTC(yy,mm-1,dd,0,0,0,0); var simdate=new Date(simt); var simday = (simt/1000/3600/24)>>0; function w(s) {document.writeln(s);} function check_match(prog,simminutes,simdate,simday) { // simdate is Java date object, simday is the #days since 1970 01-01 var wd,dn,drem; if(prog[0]==0) return 0; if ((prog[1]&0x80)&&(prog[2]>1)) { // inverval checking dn=prog[2];drem=prog[1]&0x7f; if((simday%dn)!=((devday+drem)%dn)) return 0; // remainder checking } else { wd=(simdate.getUTCDay()+6)%7; // getDay assumes sunday is 0, converts to Monday 0 if((prog[1]&(1<prog[4]) return 0; // start and end time checking if(prog[5]==0) return 0; if(((simminutes-prog[3])/prog[5]>>0)*prog[5] == (simminutes-prog[3])) { // interval checking return 1; } return 0; // no match found } function getx(sid) {return xstart+sid*stwidth-stwidth/2;} // x coordinate given a station function gety(t) {return ystart+t*stheight/60;} // y coordinate given a time function getrunstr(start,end){ // run time string var h,m,s,str; h=start/3600>>0;m=(start/60>>0)%60;s=start%60; str=""+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); h=end/3600>>0;m=(end/60>>0)%60;s=end%60; str+="->"+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); return str; } function plot_bar(sid,start,pid,end) { // plot program bar w("
P"+pid+"
"); } function plot_master(start,end) { // plot master station w("
"); //if(sd['mas']==0||start==end) return; //ctx.fillStyle="rgba(64,64,64,0.5)"; //ctx.fillRect(getx(mas-1),gety(start/60),stwidth,(end-start)/60*stheight/60); } function plot_currtime() { w("
"); } function run_sched(simseconds,st_array,pid_array,et_array) { // run and plot schedule stored in array data var sid,endtime=simseconds; for(sid=0;sid0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) plot_master(st_array[sid]+sd['mton'], et_array[sid]+sd['mtoff']); endtime=et_array[sid]; } else { // concurrent plot_bar(sid,simseconds,pid_array[sid],et_array[sid]); // check if this station activates master if((sd['mas']>0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) endtime=(endtime>et_array[sid])?endtime:et_array[sid]; } } } if(sd['seq']==0&&sd['mas']>0) plot_master(simseconds,endtime); return endtime; } function draw_title() { w("
Program Preview of "); w(days_str[simdate.getUTCDay()]+" "+(simdate.getUTCMonth()+1)+"/"+(simdate.getUTCDate())+" "+(simdate.getUTCFullYear())); w("
(Hover over each colored bar to see tooltip)"); w("
"); } function draw_grid() { // draw table and grid for(sid=0;sid<=sd['nbrd']*8;sid++) { sn=sid+1; if(sidS"+(sn/10>>0)+(sn%10)+""); w("
"); } // horizontal grid, time for(t=0;t<=24;t++) { w("
"); w("
"); w("
"+(t/10>>0)+(t%10)+":00
"); } plot_currtime(); } function draw_program() { // plot program data by a full simulation var simminutes=0,busy=0,match_found=0,bid,s,sid,pid,match=[0,0]; var st_array=new Array(sd['nbrd']*8),pid_array=new Array(sd['nbrd']*8); var et_array=new Array(sd['nbrd']*8); for(sid=0;sid>3;s=sid%8; if(sd['mas']==(sid+1)) continue; // skip master station if(prog[7+bid]&(1<>0;pid_array[sid]=pid+1; match_found=1; }//if }//for_sid }//if_match }//for_pid if(match_found) { var acctime=simminutes*60; if(sd['seq']) { // sequential for(sid=0;sid>0; if(sd['seq']&&simminutes!=endminutes) simminutes=endminutes; else simminutes++; for(sid=0;sid>0)*60)); // scroll to the hour line cloest to the current time } draw_title(); draw_grid(); draw_program();