diff --git a/BrewManiacEx/data/bm.js b/BrewManiacEx/data/bm.js index 1f7b319..d7f71fb 100644 --- a/BrewManiacEx/data/bm.js +++ b/BrewManiacEx/data/bm.js @@ -1 +1 @@ -function setCookie(a,b,c){var d=new Date();d.setTime(d.getTime()+(c*24*60*60*1000));var e="expires="+d.toUTCString();document.cookie=a+"="+b+"; "+e}function getCookie(a){var b=a+"=";var d=document.cookie.split(';');for(var i=0;i9)?c:"0"+c)+':'+((b>9)?b:"0"+b))};BrewChart.prototype.incTime=function(){this.config.data.labels.push(this.ftime(this.ctime));this.ctime+=this.interval};BrewChart.prototype.addData=function(i,a){if(!this.celius&&!isNaN(a))a=C2F(a);this.config.data.datasets[i].data.push(a)};BrewChart.prototype.chart=function(){var t=this;var a=document.getElementById(t.cid).getContext("2d");var b={label:t.spLabel,data:[],fill:false,borderColor:BrewChart.spcolor,backgroundColor:BrewChart.spcolor,pointBorderColor:BrewChart.spcolor,pointBackgroundColor:BrewChart.spcolor,borderDash:[8,4],pointBorderWidth:1,pointRadius:1,pointStyle:'dash',lineTension:0,cubicInterpolationMode:'linear'};t.config.data.datasets.push(b);for(i=0;i0&&a[a.length-1].value==b){if(a[a.length-1].dt=='e'){a.pop()}}var c=$.extend(true,{},BrewChart.stageAnno);if(s<=10){c.label.text=STR.stageName[s]}else if(s==100){c.label.text=STR.ManualMode}else if(s==103){c.label.text=STR.PIDAutoTune}else{return}c.value=b;this.config.options.annotation.annotations.push(c)};BrewChart.prototype.addEvent=function(s){if(s==1||s==10){var a=this.config.options.annotation.annotations;var b=this.ftime(this.ctime);if(a.length>0&&a[a.length-1].value==b){return}var c=$.extend(true,{},BrewChart.eventAnno);c.label.text=STR.event[s];c.value=b;this.config.options.annotation.annotations.push(c)}};BrewChart.prototype.addResume=function(s){this.incTime();for(i=0;i5)return false;return{sensor:s,f:a[1]&0x10}};BrewChart.prototype.process=function(a){var t=this;for(var i=0;i12000){t.addData(t.lidx+1,NaN)}else{t.addData(t.lidx+1,f/100)}if(++t.lidx>=t.numLine)t.lidx=0}}t.myLine.update()};var EEPROM={"s_kp":{max:100,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_ki":{max:155,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_kd":{max:100,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_sample_time":{max:3500,min:1500,inc:250,decode:function(v){return v*250},encode:function(v){return Math.round(v/250)}},"s_window":{max:7500,min:4000,inc:250,decode:function(v){return v*250},encode:function(v){return Math.round(v/250)}},"s_pwm":{max:100,min:0,inc:1},"s_cal":{max:5,min:-5,inc:0.1,decode:function(v){return(v-50)/10},encode:function(v){return v*10+50}},"s_pidstart":{max:3.5,min:1.0,inc:0.1,decode:function(v){return(v)/10},encode:function(v){return v*10}},"s_unit":{max:1,min:0,inc:1,labels:["°C","°F"],},"s_nodelay":{max:1,min:0,inc:1,labels:["No","Yes"]},"s_boil":{max:120,min:80,inc:1},"s_pumpcycle":{max:15,min:5,inc:1},"s_pumprest":{max:5,min:0,inc:1},"s_pumppremash":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpmash":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpmashout":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpboil":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpstop":{max:120,min:80,inc:1},"s_pipe":{max:1,min:0,inc:1,labels:["Passive","Active"]},"s_skipadd":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_skipremove":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_skipiodine":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_iodine":{max:120,min:0,inc:1},"s_whirlpool":{max:2,min:0,labels:["Off","Cold","Hot"]},"s_spenable":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_sptempctrl":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_spsensor":{max:5,min:0,inc:1},"s_sptemp":{max:80,min:75,inc:1},"s_spdiff":{max:2.0,min:0.5,inc:0.1,decode:function(v){return(v)/10},encode:function(v){return v*10}}};var BMSetting={values:{},editing:{},enabled:false,celius:true,singlesensor:true,disableSetting:function(a){$("#settings-p input").spinner({disabled:a})},disableButton:function(a){$("#settings-p button").button({disabled:a})},setEnabled:function(e){this.enabled=e;if(e){$("#esetting").button({disabled:false})}else{$("#esetting").button({disabled:true})}},display:function(){var t=this;var c=t.celius;$.each(this.values,function(k,v){var p=EEPROM[k];if(p){var a;if(typeof p["labels"]=="undefined"){if(typeof p["decode"]=="undefined")a=v;else a=p.decode(v)}else{a=p["labels"][v]}if(!c){if(k=="s_cal"||k=="s_spdiff")a=a*1.8;else if(k=="s_boil"||k=="s_pumpstop"||k=="s_sptemp")a=C2F(a)}$('#'+k).text(a)}else{if(k=="sensors")t.sensorAddr(v);else if(k=="primary")t.primarySensor(v);else if(k=="auxiliary")t.auxiliarySensor(v)}})},auxiliarySensor:function(l){for(var i=0;ithis.numsensor){for(var i=a;i<=n;i++){var e=b.clone();e.find("td.sensor_id").text(i);e.find("td.sensor_addr").attr("id","SA_"+i);e.insertAfter(b);b=e;var f=c.clone();var g="s_cal_"+i;f.find("td.TCAL_T").text(d+" #"+i);f.find("span.TCAL_V").attr("id",g);f.insertAfter(c);EEPROM[g]=EEPROM["s_cal"];c=f}}else{for(var i=n+1;i<=this.numsensor;i++){var h=$("#SA_"+i).closest("tr.sensor_row");h.remove();var j=$("#s_cal_"+i).closest("tr");j.remove()}}this.numsensor=n},setting:function(s){this.values=s;this.display();if($("#esetting").button("option","icons").primary!="ui-icon-pencil"){$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide()}},unitCelius:function(c){if(this.celius!=c){$(".tmp_unit").text((c)?"°C":"°F");this.celius=c}},valuechange:function(s){var n=$(s).attr("name");var v=$(s).spinner("value");var a=$(s).spinner("option","min");var b=$(s).spinner("option","max");if(vb)v=b;$(s).spinner("value",v);if(!this.celius){if(n=="s_cal"||n=="s_spdiff")v=v/1.8;else if(n=="s_boil"||n=="s_pumpstop"||n=="s_sptemp")v=F2C(v)}if(typeof EEPROM[n]["encode"]=="undefined")this.editing[n]=v;else this.editing[n]=EEPROM[n].encode(v)},switchchange:function(n,c){this.editing[n]=c},selectionchange:function(n,v){this.editing[n]=v},editsettings:function(){var f=this.values;var b=this;$.each(EEPROM,function(k,p){var s=$('#'+k).empty();var c=(typeof p["decode"]=="undefined")?f[k]:p.decode(f[k]);if(typeof p["labels"]=="undefined"){var d=p["min"];var e=p["max"];if(!b.celius){if(k=="s_cal"||k=="s_spdiff"){c=c*1.8;d=d*1.8;e=e*1.8}else{if(k=="s_boil"||k=="s_pumpstop"||k=="s_sptemp"){c=C2F(c);d=C2F(d);e=C2F(e)}}}$("").appendTo(s);s.find("input").spinner({min:d,max:e,step:p["inc"],change:function(){b.valuechange(this)}}).attr("name",k)}else if((p["labels"]).length==2){$("").appendTo(s);s.find("input[type=checkbox]").switchButton({on_label:p["labels"][1],off_label:p["labels"][0],name:k,on_callback:function(){b.switchchange(k,(this.options["checked"])?1:0)},off_callback:function(){b.switchchange(k,(this.options["checked"])?1:0)}})}else{var h="";$.each(p["labels"],function(i,a){var b=(c==i)?"checked":"";h=h+""+p["labels"][i]+"
"});$(h).appendTo(s);s.find("input").on("click",function(){b.selectionchange(k,s.find("input:checked").val())})}});if(this.singlesensor)this.editing={};else this.editing={scals:this.values["scals"]}},finishSaving:function(s){if(s){var b=this;$.each(b.editing,function(k,v){b.values[k]=v});b.display();$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide()}else{this.disableSetting(false)}this.disableButton(false)},init:function(a){var b=this;$("#esetting").button({disabled:false,text:false,icons:{primary:"ui-icon-pencil"}}).click(function(){if($("#esetting").button("option","icons").primary=="ui-icon-pencil"){$("#esetting").button("option","icons",{primary:"ui-icon-arrowreturnthick-1-w"});$("#savesetting").show();b.editsettings()}else{$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide();b.display()}});$("#savesetting").button({text:false,icons:{primary:"ui-icon-disk"}}).click(function(){if(!b.enabled){alert("BrewManiac is not in idle state");return}if(Object.keys(b.editing).length==0){$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide();b.display();return}b.disableSetting(true);b.disableButton(true);a.savesetting(b.editing)}).hide()}};var BMRecipe={auto:{},eauto:{},enabled:false,celius:true,disableInput:function(a){$("#automation-p input").spinner({disabled:a})},disableButton:function(a){$("#automation-p button").button({disabled:a})},setEnabled:function(e){this.enabled=e;if(e)$("#editauto").button({disabled:false});else $("#editauto").button({disabled:true})},updateRecipe:function(d){this.auto=d;this.display();if($("#editauto").button("option","icons").primary!="ui-icon-pencil"){this.stopEditRecipe()}},unitCelius:function(a){this.celius=a;if($("#editauto").button("option","icons").primary!="ui-icon-pencil"){this.stopEditRecipe()}if(typeof this.auto.rest_tp!=="undefined")this.display()},newrest:function(i){return $(''+STR.Mash+' '+i+' °'+((this.celius)?'C':'F')+' min')},dis_rest:function(d){var a=$("#s7_tp").closest("tr");$("#s0_tp").closest("tr").nextUntil(a).remove();for(var i=1;i<7;i++){var v=d.rest_tm[i];if(v==0){break}else{var b=this.newrest(i);a.before(b);$('#s'+i+'_tm').text(v);$('#s'+i+'_tp').text(this.TC(d.rest_tp[i]))}}},TC:function(t){return(this.celius)?Math.round(t*10)/10:C2F(t)},display:function(){var d=this.auto;$('#s0_tp').text(this.TC(d.rest_tp[0]));$('#s7_tm').text(d.rest_tm[7]);$('#s7_tp').text(this.TC(d.rest_tp[7]));this.dis_rest(this.auto);$("#boiltime").text(d.boil);$("#auto_table tr:gt("+$("#boiltime").closest("tr").index()+")").remove();var t=$("#auto_table");$.each(d.hops,function(i,h){$("Hop#"+(i+1)+""+h+" min").appendTo(t)})},minRT:[20,25,25,25,25,25,25,75],maxRT:[75,76,76,76,76,76,76,80],minRT_F:[68,77,77,77,77,77,77,167],maxRT_F:[167,169,169,169,169,169,176,176],rtmChange:function(s){var i=$(s).attr("name").substring(2);var v=$(s).spinner("value");if(v>140)v=140;var a=(i>5)?1:0;if(vb)v=b;$(s).spinner("value",v);this.eauto.rest_tp[i]=(this.celius)?v:F2C(v)},btChange:function(s){var v=$(s).spinner("value");if(v>140)v=140;if(v<1)v=1;$(s).spinner("value",v);this.eauto.boil=v;this.listhop()},hchange:function(s){var i=$(s).attr("name").substring(1);this.eauto.hops.splice(i,1);var v=$(s).spinner("value");if(v<1)v=1;if(v>this.eauto.boil)v=this.eauto.boil;this.eauto.hops.push(v);this.eauto.hops.sort(function(a,b){return b-a});this.listhop()},dhop:function(s){var i=$(s).attr("name").substring(2);this.eauto.hops.splice(i,1);this.listhop()},ahop:function(){var v=this.eauto.hops[this.eauto.hops.length-1]-1;if(v<1)v=1;this.eauto.hops.push(v);this.listhop()},listhop:function(){$("#auto_table tr:gt("+$("#boiltime").closest("tr").index()+")").remove();var t=$("#auto_table");var b=this;$.each(b.eauto.hops,function(i,h){var e=$("Hop#"+(i+1)+"min ").appendTo(t);e.find("input").spinner({min:1,max:b.eauto.boil,change:function(){b.hchange(this)}});e.find("button").css("color","red").attr("name","dh"+i).button({text:false,icons:{primary:"ui-icon-trash"}}).click(function(){b.dhop(this)})})},drest:function(s){var b=this;var a=b.eauto.rest_tm;var c=b.eauto.rest_tp;var i=parseInt($(s).attr("name").substring(2));for(var r=i;r<6;r++){var n=r+1;a[r]=a[n];c[r]=c[n]}a[6]=0;c[6]=0;b.dis_rest(this.eauto);for(var i=0;i<7;i++){b.resteditable(i)}},arest:function(){var i;for(i=1;i<7;i++){if(this.eauto.rest_tm[i]==0){this.eauto.rest_tm[i]=10;this.eauto.rest_tp[i]=this.eauto.rest_tp[i-1]+1;var a=this.newrest(i);$("#s7_tp").closest("tr").before(a);this.resteditable(i);break}}},resteditable:function(i){var b=this;if(i!=0){var a=$('#s'+i+'_tm').empty();$("").appendTo(a);var c=1;a.find("input").spinner({min:c,max:140,change:function(){b.rtmChange(this)}}).attr("name",'tm'+i);if(i<7){$('').appendTo(a.closest("td")).css("color","red").attr("name","mr"+i).button({text:false,icons:{primary:"ui-icon-trash"}}).click(function(){b.drest(this)})}}var d=$('#s'+i+'_tp').empty();var v=(this.celius)?b.eauto.rest_tp[i]:C2F(b.eauto.rest_tp[i]);var c=(this.celius)?b.minRT[i]:b.minRT_F[i];var e=(this.celius)?b.maxRT[i]:b.maxRT_F[i];if(ve)v=e;b.eauto.rest_tp[i]=v;$("").appendTo(d);d.find("input").spinner({min:c,max:e,step:0.25,change:function(){b.rtpChange(this)}}).attr("name",'tp'+i)},edit:function(){$("#addhop").show();$("#addrest").show();$("#saveauto").show();var b=this;b.eauto=$.extend(true,{},this.auto);var a=$("").appendTo($('#boiltime').empty()).spinner({min:1,max:140,change:function(){b.btChange(this)}});b.listhop();for(var i=0;i<8;i++){if(i>0&&i<7&&b.eauto.rest_tm[i]==0){i=6;continue}this.resteditable(i)}},stopEditRecipe:function(){$("#editauto").button("option","icons",{primary:"ui-icon-pencil"});$("#saveauto").hide();$("#addhop").hide();$("#addrest").hide()},validate:function(){if(this.eauto.rest_tm[7]==0)return false;var a=this.eauto.boil;if(this.eauto.hops.length>0){var b=this.eauto.hops[0];if(b>a)return false;for(var i=1;i=b)return false;b=v}}return true},finishSaveRecipe:function(a){if(a){this.auto=BM.auto;this.display();this.stopEditRecipe()}else{this.disableInput(false)}this.disableButton(false)},init:function(a){var b=this;$("#editauto").button({disabled:false,text:false,icons:{primary:"ui-icon-pencil"}}).click(function(){if($("#editauto").button("option","icons").primary=="ui-icon-pencil"){b.edit();$("#editauto").button("option","icons",{primary:"ui-icon-arrowreturnthick-1-w"})}else{b.display();b.stopEditRecipe()}});$("#saveauto").button({disabled:false,text:false,icons:{primary:"ui-icon-disk"}}).click(function(){if(!b.enabled){alert("BrewManiac is not in idle state");return}if(b.validate()){b.disableButton(true);b.disableInput(true);a.saveRecipe(b.eauto)}else{alert("Invalid value!")}}).hide();$("#addhop").button({disabled:false,text:false,icons:{primary:"ui-icon-plusthick"}}).click(function(){b.ahop()}).hide();$("#addrest").button({disabled:false,text:false,icons:{primary:"ui-icon-plusthick"}}).click(function(){b.arest()}).hide()}};var BMScreen={ctemp:0,stemp:35,pwm:0,pwmOn:false,screen:"U",bm:null,celius:true,singlesensor:true,numsensor:0,htimer:null,h_animated:0,HC_active:"#FE1E1E",HC_inactive:"#5B0000",HC_pause:"#DE912F",PC_active:"#70FC57",PC_inactive:"#01290C",PC_pause:"#22C6AB",spargesensor:-1,autolist:function(){var a=this.bm.autoAllStages();var t=$("#auto-t").empty();var b=(this.celius)?"°C":"°F";b=""+b+"";var c={addmalt:STR.AddMalt,removemalt:STR.RemoveMalt,boilend:STR.BoilEnd,cooling:STR.Cooling};for(i=0;i"+STR.stageName[s.stage]+""+d+b+""+((s.stage)?(s.time+STR.min):"-")+">").appendTo(t)}else if(s.type=="event"){$(""+c[s.name]+"-->").appendTo(t)}else if(s.type=="boil"){$(""+STR.Boil+"-"+s.time+STR.min+">").appendTo(t)}else if(s.type=="hop"){$(""+STR.HopN+(s.index+1)+"-"+s.time+STR.min+">").appendTo(t)}}},inStage:function(i){$("#auto-t tr:eq("+i+")").removeClass("run").addClass("running");$("#auto-t tr:lt("+i+")").removeClass("running").addClass("run");$("#auto-t tr:gt("+i+")").removeClass("running").removeClass("run")},unitCelius:function(a){this.celius=a;if(this.singlesensor){this.currenttemp(this.ctemp)}else{this.alltemps(this.ctemps)}if(this.isRunning(this.screen))this.settingtemp(this.stemp)},isRunning:function(s){return(s=="A"||s=="M")},setScreen:function(s,a){var t=this;if(s=="S")$("#title").text(STR.Setup);else if(s=="I"){$("#title").text(STR.Idle);if(!t.singlesensor)t.setPrimarySensor(t.primary[0])}else if(s=="M"){$("#title").text(STR.ManualMode);if(!t.singlesensor)t.setPrimarySensor(t.primary[1])}else if(s=="A"){if(a==11)$("#title").text(STR.DelayStart);else $("#title").text(STR.Automation);if(!t.singlesensor){if(a==0)t.setPrimarySensor(t.primary[2]);else if(a>=1&&a<=7)t.setPrimarySensor(t.primary[3]);else if(a==8)t.setPrimarySensor(t.primary[4]);else if(a>8)t.setPrimarySensor(t.primary[5])}}else if(s=="U")$("#title").text(STR.Unknown);else if(s=="T")$("#title").text(STR.PIDAutoTune);if(s!="A"&&s!="M"&&s!="T"){t.clear_settingtemp();t.deacTime();BChart.stop()}else{t.settingtemp(t.stemp);t.displaytime(0);if(BChart.running){BChart.pull()}else{BChart.start();BChart.setCelius(this.celius)}}if(s=="A"){if(t.screen!="A"){t.autolist();$("#auto-p").css('display','inline-block')}}else{$("#auto-p").css('display','none')}t.screen=s},setLed:function(a,b){$(a).css("background",b)},heatStatus:function(s){if(s==0)this.setLed("#heatled",this.HC_inactive);else if(s==1)this.setLed("#heatled",this.HC_active);else this.setLed("#heatled",this.HC_pause)},pumpStatus:function(s){if(s==0)this.setLed("#pumpled",this.PC_inactive);else if(s==1)this.setLed("#pumpled",this.PC_active);else this.setLed("#pumpled",this.PC_pause)},currenttemp:function(t){this.ctemp=t;if(t>300||t<-1){$("#currenttemp").text('--')}else{var v=(this.celius)?t:C2F(t);$("#currenttemp").text(v.toFixed(2))}},setPrimarySensor:function(n){var a=n+1;for(var i=1;i<=this.numsensor;i++){if(i==a)$("#t_id_"+i).text("*#"+i+":");else{if(i!=(this.spargesensor+1))$("#t_id_"+i).text("#"+i+":")}}},multisensor:function(n,a,b){var t=this;t.primary=a;t.aux=b;if(n==0)return;t.singlesensor=false;if(t.numsensor!=n){if(t.numsensor300||t<-1){$("#currentTemp_"+(i+1)).text('--')}else{var v=(this.celius)?t:C2F(t);$("#currentTemp_"+(i+1)).text(v.toFixed(2))}}},clear_settingtemp:function(){$("#setpoint").css("color","#000033");$("#setpoint").text("0.00")},settingtemp:function(t){this.stemp=t;$("#setpoint").css("color","");var v=(this.celius)?t:C2F(t);$("#setpoint").text(v.toFixed(2))},showPwm:function(s){if(s)$("#pwm").css("color","");else{$("#pwm").css("color","#550000");$("#pwm").text("00")}},pwmValue:function(v){this.pwm=v;$("#pwm").text(v)},setPwmOn:function(o){this.pwmOn=o;this.showPwm(o)},displaytime:function(t){if(isNaN(t))return;var m=Math.floor(t/60);var s=t-m*60;var h=Math.floor(m/60);m=m-h*60;$("#timer").css("color","");$("#timer").text(""+((h>9)?h:("0"+h))+":"+((m>9)?m:("0"+m))+":"+((s>9)?s:("0"+s)))},deacTime:function(){$("#timer").css("color","#000033");$("#timer").text("00:00:00")},clearTime:function(){$("#timer").text("00:00:00")},openDiaTimer:null,initDialog:function(){$("div.dialog").hide();var b=this;$("div.dialog").dialog({autoOpen:false,modal:true,show:{effect:"bounce",duration:1000},hide:{effect:"fade",duration:1000},close:function(){Beep.pause()},buttons:{Ok:function(){$(this).dialog("close");if(b.openDiaTimer)clearTimeout(b.openDiaTimer)}}})},popDialog:function(a,c){$(a).dialog("open");var b=this;if((typeof c=="undefined")||c)b.openDiaTimer=setTimeout(function(){$(a).dialog("close");b.openDiaTimer=null},5000)},soundTimeout:null,sound:function(t){var b=this;if(b.soundTimeout)clearTimeout(b.soundTimeout);Beep.pause();Beep.loop=true;Beep.play();if(t>0)b.soundTimeout=setTimeout(function(){b.soundTimeout=null;Beep.pause()},t*1000)},setInfo:function(t,a){a=(typeof a==="undefined")?1:a;$("#info").text(t);if(a)setTimeout(function(){$("#info").text("")},5000)},brewevent:function(e){if(BChart.running)BChart.pull();if(e<=10){this.sound(2);this.setInfo(STR.event[e]);if(e==5)$("#title").text(STR.Pause);else if(e==6)$("#title").text(STR.Automation)}else if(e==11){this.setInfo(STR.PumpRest,0)}else if(e==12){this.setInfo("",0)}else if(e==99){this.sound(5);this.setInfo(STR.event[11])}},error:function(c){if(c=="disc"){this.sound(0);this.popDialog("#d_ConnectionError",false)}else if(c=="s_disc"){this.sound(0);this.popDialog("#d_SerialError",false)}this.setScreen("U")},toggleButton:function(){if($("#showbtn").button("option","icons").primary=="ui-icon-circle-triangle-s"){$("#showbtn").button("option","icons",{primary:"ui-icon-circle-triangle-n"})}else{$("#showbtn").button("option","icons",{primary:"ui-icon-circle-triangle-s"})}$("#bpannel").toggle("slide",{direction:"up"},500)},btnPressed:false,btnClick:function(k,l){var b=this;if(b.btnPressed)return;b.btnPressed=true;this.bm.sendButton(k,l,function(){b.btnPressed=false})},home:function(){this.btnClick("home",false)},hideButton:function(){var H=$("#btncover").height();var a=true;$("#btncover").on("click",function(){if(a){$("#btncover").animate({height:10},500)}else{$("#btncover").animate({height:H},500)}a=!a})},init:function(b){this.bm=b;this.showPwm(false);this.clear_settingtemp();this.initDialog();var b=this;var d=getCookie("warning");if(d!=1){$("#d_warning").dialog({resizable:false,dialogClass:"no-close",modal:true,buttons:{"Agree":function(){$(this).dialog("close")}}});$('#nshow').change(function(){setCookie("warning",($(this).is(':checked'))?1:0,365)})}else $("#d_warning").hide();this.hideButton();function sb(a){var c=$("#btn-"+a).css("background");$("#btn-"+a).bind("touchstart mousedown",function(e){e.preventDefault();this.dt=Date.now();$(this).css("background","#FF1111");return false}).bind("touchend mouseup",function(e){e.preventDefault();if(typeof this.dt!="undefined"){$(this).css("background",c);if(Date.now()-this.dt>1000)b.btnClick(a,true);else b.btnClick(a,false);return false}}).bind("mouseleave",function(e){if(typeof this.dt!="undefined"){$(this).css("background",c);this.dt=null}}).click(function(){return false})}sb("up");sb("down");sb("start");sb("enter");$("#btn-hint").hide()},btnIndex:-1,buttons:function(a){if(a==this.btnIndex)return;this.btnIndex=a;var b=(typeof ButtonLabels[a]=="undefined")?{u:"",d:"",s:"",e:"",i:""}:ButtonLabels[a];$("#btn-up").text(b.u);$("#btn-down").text(b.d);$("#btn-start").text(b.s);$("#btn-enter").text(b.e);$("#info").text(b.i)}};var BM={setting_url:"settings.php",automation_url:"automation.php",saveauto_url:"saveauto.php",ssavesetting_url:"savesettings.php",button_url:"button.php",status_url:"status.php",runningTime:0,timer:null,settings:{},s_settingS:{},auto:{},s_auto:{},celius:true,state:-1,hopN:0,updatingSetting:false,updatingRecipe:false,stageMap:[],conbroken:true,wdt:null,bc:{up:1,down:2,start:4,enter:8,home:3},sendButton:function(k,l,d){var e=this.bc[k]+((l)?16:0);$.ajax({url:this.button_url+"?code="+e,type:"GET",success:function(){d()},error:function(a,b,c){console.log(c)},})},getsetting:function(){var o=this;$.ajax({url:this.setting_url+"?time="+((new Date()).getTime()/1000),type:"GET",dataType:"json",success:function(a){if(a.code==0){o.proc_settings(a.data)}},error:function(a,b,c){console.log(c)},})},savesetting:function(d){this.s_settings=d;var b=this;this.updatingSetting=true;$.ajax({url:this.ssavesetting_url,type:"POST",data:{data:JSON.stringify(d)},success:function(){if(b.updatingSetting)b.startRecoveryTimer()},error:function(a,c,d){alert("error save setting, server response:"+d);b.finishSettingSave(false)}})},unitChangeHdlr:[],addUnitChangeHdlr:function(f){this.unitChangeHdlr.push(f)},unitSetting:function(u){var t=this;var c=(u==0);if(c!=t.celius){t.celius=c;BMSetting.unitCelius(c);BMRecipe.unitCelius(c);BMScreen.unitCelius(c);$.each(t.unitChangeHdlr,function(i,f){f(c)})}},proc_settings:function(s){this.settings=s;if("s_unit"in s){this.unitSetting(s["s_unit"])}if("sensors"in s){BMScreen.multisensor(s["sensors"].length,s["primary"],s["auxiliary"]);BMSetting.multisensor(s["sensors"].length)}if(("s_spenable"in s)&&s["s_spenable"]!=0)BMScreen.swh(true,s.s_sptempctrl,s.s_spsensor);else BMScreen.swh(false);BMSetting.setting(s)},getauto:function(){var b=this;$.ajax({url:this.automation_url,type:"GET",dataType:"json",success:function(a){if(a.code==0){b.procRecipe(a.data)}},error:function(a,b,c){console.log(c)},})},procRecipe:function(d){this.auto=d;BMRecipe.updateRecipe(d)},saveRecipe:function(d){this.s_auto=d;var b=this;b.updatingRecipe=true;$.ajax({url:b.saveauto_url,type:"POST",data:{data:JSON.stringify(d)},success:function(){if(b.updatingRecipe)b.startRecoveryTimer()},error:function(a,c,d){b.finishSaveRecipe(false);alert("Error saving automation, server response:"+d)}})},bmstate:function(s){if(this.state==s)return;if(this.state==-1){if(typeof this.auto.boil=="undefined"){this.getsetting();this.getauto()}}if(s==101){if(!(this.updatingSetting||this.updatingRecipe)){BMRecipe.setEnabled(true);BMSetting.setEnabled(true)}}else{BMRecipe.setEnabled(false);BMSetting.setEnabled(false)}if(s>=0&&s<=11){BMScreen.setScreen("A",s);if(s==11)BMScreen.settingtemp(BM.auto.rest_tp[0]);else this.autostage(s)}else{if(s==100){BMScreen.setScreen("M")}else if(s==101){BMScreen.setScreen("I");this.stopRunningTime();BMScreen.clearTime()}else if(s==102){BMScreen.setScreen("S");this.stopRunningTime();BMScreen.clearTime()}else if(s==103){BMScreen.setScreen("T");BMScreen.clearTime()}else if(s<0){BMScreen.setScreen("U");this.stopRunningTime();BMScreen.clearTime()}}this.state=s},stopRunningTime:function(){if(this.timer)clearInterval(this.timer);this.timer=null},refTime:0,countDir:0,calTime:function(){var t=this.runningTime+this.countDir*Math.round((Date.now()-this.refTime)/1000);return(t<0)?0:t},startRunningTime:function(t){b=this;b.runningTime=t;if(isNaN(t))return;b.refTime=Date.now();b.timer=setInterval(function(){BMScreen.displaytime(b.calTime())},1000)},checkRunningTime:function(t){var a=this.calTime();if((a-t)>5||(a-t)<-5){this.stopRunningTime();this.startRunningTime(t)}},finishSaveRecipe:function(a){this.stopRecoveryTimer();this.updatingRecipe=false;BMRecipe.finishSaveRecipe(a)},finishSettingSave:function(a){this.stopRecoveryTimer();this.updatingSetting=false;BMSetting.finishSaving(a)},recoveryTimout:null,stopRecoveryTimer:function(){if(this.recoveryTimout){clearTimeout(this.recoveryTimout);this.recoveryTimout=null}},startRecoveryTimer:function(){var b=this;b.recoveryTimout=setTimeout(function(){b.recoveryTimout=null;alert("Update failed, check connections");if(b.updatingRecipe)b.finishSaveRecipe(false);if(b.updatingSetting)b.finishSettingSave(false)},10000)},init:function(){BMScreen.init(this);BMSetting.init(this);BMRecipe.init(this);this.getsetting();this.getauto();this.setupEvent()},timerControl:function(r,t,c,p){var b=this;b.countDir=(c==0)?-1:1;if(!p){if(b.timer==null){b.startRunningTime(t)}else{b.checkRunningTime(t)}}else{if(b.timer)b.stopRunningTime();if(r&&b.state<=8&&b.state>0){BMScreen.displaytime(t)}else if(b.state<8&&b.state>0){BMScreen.displaytime(b.auto.rest_tm[b.state]*60)}else if(b.state==8){BMScreen.displaytime(BM.auto.boil*60)}else{BMScreen.clearTime()}}},updateData:function(v){if(v=="recipe"){if(this.updatingRecipe){this.auto=this.s_auto;this.finishSaveRecipe(true)}else{this.getauto()}}else if(v=="setting"){var b=this;if(b.updatingSetting){$.each(b.s_settings,function(k,v){b.settings[k]=v;if(k=="s_unit")b.unitSetting(v)});b.finishSettingSave(true)}else{b.getsetting()}}},errorCode:function(a){this.bmstate(-1);BMScreen.error("s_disc")},watchdog:function(){var b=this;b.wdt=setTimeout(function(){location.reload()},20000)},kick_wdt:function(){if(this.wdt)clearTimeout(this.wdt);this.watchdog()},p_msg:function(e){var b=this;var a=JSON.parse(e);var c={pump:function(v){BMScreen.pumpStatus(v)},heat:function(v){BMScreen.heatStatus(v)},spgw:function(v){BMScreen.spargeStatus(v)},temp:function(v){BMScreen.currenttemp(v)},temps:function(v){BMScreen.alltemps(v)},stemp:function(v){BMScreen.settingtemp(v)},event:function(v){b.brewevent(v)},pwm:function(v){BMScreen.pwmValue(v)},pwmon:function(v){BMScreen.setPwmOn(v==1)},update:function(v){b.updateData(v)},code:function(v){b.errorCode(v)},btn:function(v){BMScreen.buttons(v)}};$.each(a,function(k,v){if(typeof(c[k])!="undefined"){c[k](v)}});if(typeof(a["tr"])!="undefined"&&typeof(a["timer"])!="undefined"&&typeof(a["state"])!="undefined"){b.timerControl(a["tr"],a["timer"],a["counting"],a["paused"]);b.bmstate(a["state"]);b.autoProgressBytime(a["tr"],a["state"],a["timer"])}},setupEvent:function(){var b=this;if(typeof EventSource==="undefined"){alert("Incompatible Browser!");return}var a=new EventSource(BM.status_url);a.onerror=function(){b.ssebroken=true;setTimeout(function(){if(b.ssebroken)BMScreen.error("disc")},5000)};a.onmessage=function(e){b.kick_wdt();b.ssebroken=false;b.p_msg(e.data)}},brewevent:function(e){var b=this;if(e==5&&b.timer)b.stopRunningTime();if(e==1){if(b.state>0&&b.state<8)b.startRunningTime(b.auto.rest_tm[b.state]*60);else if(b.state==8)b.startRunningTime(b.auto.boil*60)}b.autoProgressByevent(e);BMScreen.brewevent(e)},log:function(s){var d=new Date();$(""+d.toLocaleTimeString()+""+s+"").appendTo("#log-t")},autoAllStages:function(){var a=[];var b=0;for(i=0;i<8;i++){if(this.auto.rest_tm[i]>0||i==0){a.push({type:"mash",stage:i,temp:BM.auto.rest_tp[i],time:BM.auto.rest_tm[i]});this.stageMap[i]=b++}if(i==0){a.push({type:"event",name:"addmalt"});b++}}a.push({type:"event",name:"removemalt"});b++;a.push({type:"boil",time:BM.auto.boil});this.stageMap[8]=b++;$.each(BM.auto.hops,function(i,h){a.push({type:"hop",index:i,time:h});b++});a.push({type:"event",name:"boilend"});b++;a.push({type:"event",name:"cooling"});this.stageMap[9]=b++;this.hopN=0;return a},autostage:function(s){BMScreen.inStage(this.stageMap[s]);if(s<8){BMScreen.settingtemp(BM.auto.rest_tp[s]);if(s==0)BMScreen.clearTime();else BMScreen.displaytime(BM.auto.rest_tm[s]*60)}else if(s==8){BMScreen.settingtemp(BM.settings.s_boil);BMScreen.displaytime(BM.auto.boil*60)}else if(s==9){BMScreen.settingtemp(20)}},autoProgressByevent:function(e){if(e==2){BMScreen.inStage(1)}else if(e==3){BMScreen.inStage(BM.stageMap[7]+1)}else if(e==10){BMScreen.inStage(BM.stageMap[9])}},autoProgressBytime:function(a,b,c){if(!a||b!=8)return;if(c==0)c=this.auto.boil*60;var i=this.hopN;for(;ithis.auto.hops[i]*60){break}}if(i!=this.hopN){this.hopN=i;BMScreen.inStage(BM.stageMap[8]+i+1)}}};var NetworkConfig={url:"netcfg.php",host:"bm",secured:false,update:function(){var n=this;var u={};var h=$.trim($("#hostname").val());if(h!==n.host)u["host"]=h;var c=$("#protected").is(":checked");if(c!=n.secured)u["secured"]=c?1:0;var d=$.trim($("#newusername").val());if(d!=="")u["nuser"]=d;var e=$.trim($("#newpasswd").val());if(e!=="")u["npass"]=e;u["user"]=$.trim($("#username").val());u["pass"]=$("#password").val();console.log("update:"+JSON.stringify(u));$.ajax({url:n.url,type:"POST",data:{data:JSON.stringify(u)},success:function(){$("#saveok").show()},error:function(a,b,c){$("#savefail").show();console.log("Error saving automation, server response:"+c)}})},getcfg:function(){var n=this;$.ajax({url:n.url,type:"GET",dataType:"json",success:function(a){n.host=a.host;n.secured=(a.secured!=0);n.inputs()},error:function(a,b,c){n.inputs();console.log(c)}})},discnet:function(){var n=this;var u={};u["user"]=$.trim($("#username").val());u["pass"]=$("#password").val();u["disconnect"]=true;console.log("disconnect wifi:"+JSON.stringify(u));$.ajax({url:n.url,type:"POST",data:{data:JSON.stringify(u)},success:function(){alert("Network disconnect")},error:function(a,b,c){alert("error");console.log("Error saving automation, server response:"+c)}})},chkpass:function(){if($("#newpasswd").val()===$("#newpasswd2").val()){$("#passmatch").hide();$("#savecfg").button("option","disabled",false)}else{$("#passmatch").show();$("#savecfg").button("option","disabled",true)}},verify:function(){if($.trim($("#username").val())!==""&&$.trim($("#password").val())!==""){$("#savecfg").button("option","disabled",false);$("#wifidisc").show()}else{$("#savecfg").button("option","disabled",true);$("#wifidisc").hide()}$("#saveok").hide();$("#savefail").hide()},vchange:function(){$("#saveok").hide();$("#savefail").hide();$("#savecfg").show()},inputs:function(){var n=this;$("#passmatch").hide();$("#hostname").val(n.host).change(function(){n.vchange()});$("#protected").attr("checked",n.secured).change(function(){n.vchange()});$("#newusername").change(function(){n.vchange()});$("#newpasswd").change(function(){n.vchange();n.chkpass()});$("#newpasswd2").change(function(){n.chkpass()});$("#username").change(function(){n.verify()});$("#password").change(function(){n.verify()});$("#savecfg").button({disabled:true}).click(function(){n.update()}).hide();$("#wifidisc").button().click(function(){n.discnet()}).hide();$("#saveok").hide();$("#savefail").hide()},init:function(){this.getcfg()},};var BChart={offset:0,url:'chart.php',reqdata:function(){var t=this;var b='offset='+t.offset;var c=new XMLHttpRequest();c.open('GET',t.url+'?'+b);c.responseType='arraybuffer';c.onload=function(e){var a=new Uint8Array(this.response);if(a.length==0){console.log("zero content");if(t.timer)clearInterval(t.timer);t.timer=null;setTimeout(function(){t.reqdata()},3000);return}t.chart.process(a);t.offset+=a.length;if(t.timer==null)t.settimer()};c.send()},settimer:function(){var t=this;t.timer=setInterval(function(){t.reqdata()},t.chart.interval*1000)},init:function(a){this.chart=new BrewChart(a)},timer:null,pull:function(){},setCelius:function(a){this.chart.setCelius(a)},setYLabel:function(a){this.chart.ylabel(a)},start:function(){if(this.running)return;this.running=true;this.offset=0;this.chart.clear();this.reqdata();$("#tchart").show()},stop:function(){if(!this.running)return;this.running=false;if(this.timer){clearInterval(this.timer);this.timer=null}$("#tchart").hide()}};var Logs={url:"logs.php",dl:"dl",init:function(){var t=this;this.row=$("#loglist").find("tr:nth-of-type(2)");this.row.remove();$("#listfile").button().button("option","icons",{primary:"ui-icon-arrowrefresh-1-e"}).click(function(){t.getlist()});$("#vchart").hide();t.chart=new BrewChart("vchart-canvas")},view:function(b,c){$("#vchart").show();$("#viewlogname").text(b+"@"+c.toLocaleString());var t=this;t.chart.clear();t.chart.setCelius(BM.celius);var d=new XMLHttpRequest();d.open('GET',t.url+"?"+t.dl+"="+b);d.responseType='arraybuffer';d.onload=function(e){var a=new Uint8Array(this.response);if(a.length==0){console.log("zero content");return}t.chart.realtime=true;t.chart.process(a)};d.oerror=function(e){console.log("error")};d.send()},process:function(e){var f=$("#loglist").find("tbody");var g=this.row;var t=this;$.each(e,function(i,a){var b=('000'+a.f).slice(-4);var c=new Date(a.t*1000);var d=g.clone();d.find(".logid").text(b);d.find(".logdate").text(c.toLocaleString());d.find(".dlbutton").button().button("option","icons",{primary:"ui-icon-disk"}).click(function(){window.open(t.url+"?"+t.dl+"="+b)});d.find(".viewbutton").button().button("option","icons",{primary:"ui-icon-circle-zoomout"}).click(function(){t.view(b,c)});f.append(d)})},getlist:function(){var t=this;$.ajax({url:t.url,type:"GET",dataType:"json",success:function(a){$("#loglist tr:gt(0)").remove();t.process(a)},error:function(a,b,c){console.log("Error:"+c)}})}};var BrewMath={plato2sg:function(a){return 1+a/(258.6-((a/258.2)*227.1))},sgTempCorrected:function(a,F,b){return a*((1.00130346-0.000134722124*F+0.00000204052596*F*F-0.00000000232820948*F*F*F)/(1.00130346-0.000134722124*b+0.00000204052596*b*b-0.00000000232820948*b*b*b))},brix2sg:function(a,b){b=(typeof b==="undefined")?1.0:b;var c=a/b;return(c/(258.6-((c/258.2)*227.1)))+1}};var BrewUtils={ciWeightUnit:"WEIGHT_U",ciVolumeUnit:"VOLUME_U",ciTempUnit:"TEMPERATURE_U",ciTC:"HydroCorrected",ciWC:"RefractoWortCorrect",u_vol:'L',u_weight:'M',u_temp:'C',did:null,VolFactor:{L:{L:1,G:0.264172052,Q:1.05668821},G:{L:3.78541178,G:1,Q:4},Q:{L:0.946352946,G:0.25,Q:1}},volume_unit:function(u){var a=(u=='L')?'L':((u=='G')?'gal':'qt');$(this.did).find(".vol_u").text(a);var b=this.VolFactor[this.u_vol][u];this.u_vol=u;setCookie(this.ciVolumeUnit,u,365);$(this.did).find(".volinput").each(function(){var v=$(this).val();if(v){v=(v*b);$(this).val(v.toFixed(2))}})},weight_unit:function(u){var a=(u=='M')?'kg':'lb';$(this.did).find(".weight_u").text(a);var b=(this.u_weight==u)?1:((u=='M')?0.45359237:2.20462262);this.u_weight=u;setCookie(this.ciWeightUnit,u,365);if(b==1)return;$(this.did).find(".weightinput").each(function(){var v=$(this).val();if(v){v=(v*b);$(this).val(v.toFixed(2))}})},temp_unit:function(u){if(this.u_temp==u)return;var a=(u=='C')?'°C':'°F';$(".tmp_u").text(a);this.u_temp=u;setCookie(this.ciTempUnit,u,365);function C2F(c){return c*1.8+32}function F2C(f){return(f-32)/1.8}var b=(u=='C')?F2C:C2F;$(this.did).find(".tempinput").each(function(){var v=$(this).val();if(v){v=b(v);$(this).val(v.toFixed(1))}})},init:function(f){var t=this;t.did=f;var v=getCookie(t.ciVolumeUnit);v=(v)?v:t.u_vol;$(f).find("[name=volume_unit]").val([v]);t.volume_unit(v);var w=getCookie(t.ciWeightUnit);w=(w)?w:t.u_weight;$(f).find("[name=weight_unit]").val([w]);t.weight_unit(w);var T=getCookie(t.ciTempUnit);T=(T)?T:t.u_temp;$(f).find("[name=temp_unit]").val([T]);t.temp_unit(T);var h=getCookie(t.ciWC);if(h)$(f).find(".REFRACTO .wortcorrection").val(h);var i=getCookie(t.ciTC);if(i){var j=i.split(',');var k=j[0];if(j[1]!=t.u_temp){k=(j[1]=='C')?(k*1.8+32):((k-32)/1.8)}$(f).find(".HYDROMETER .correctedTemp").val(k)}$(f).find('input[type="radio"]').change(function(){var a=$(this).attr('name');var b=$(this).val();if($(this).prop('checked')){t[a](b)}});$(f).find('.fwsg').change(function(){var a=$(f).find(".FWSG .grain").val();var b=$(f).find(".FWSG .water").val();if(a&&b){a=(t.u_weight=='M')?a:(a*0.45359237);b=t.VolFactor[t.u_vol].L*b;var c=(a*0.8)/(a*0.8+b);var d=BrewMath.plato2sg(c*100).toFixed(3);$(f).find(".FWSG .result").text(d)}});$(f).find('.hydroinput').change(function(){var a=$(f).find(".HYDROMETER .sgfraction").val();var b=$(f).find(".HYDROMETER .sgtemp").val();var c=$(f).find(".HYDROMETER .correctedTemp").val();if(c)setCookie(t.ciTC,c+","+t.u_temp,365);if(a&&b&&c){var F=(t.u_temp=='C')?(b*1.8+32):b;var d=(t.u_temp=='C')?(c*1.8+32):c;var e=BrewMath.sgTempCorrected(a,F,d);$(f).find(".HYDROMETER .result").text(e.toFixed(3));window.latestSG=e}});$(f).find('.brixinput').change(function(){var a=$(f).find(".REFRACTO .brixreading").val();var b=$(f).find(".REFRACTO .wortcorrection").val();if(b)setCookie(t.ciWC,b,365);if(a){b=(b)?b:1;var c=BrewMath.brix2sg(a,b);$(f).find(".REFRACTO .result").text(c.toFixed(3));window.latestSG=c}});$(f).find('.boiloffinput').change(function(){var a=$(f).find('.BOILOFF .sg').val();var b=$(f).find('.BOILOFF .vol').val();var c=$(f).find('.BOILOFF .newsg').val();var d=$(f).find('.BOILOFF .newvol').val();if(a&&b&&c){var v=(a-1)*b/(c-1);$(f).find(".BOILOFF .resultvol").text(v.toFixed(2))}if(a&&b&&d){var g=(a-1)*b/d+1;$(f).find(".BOILOFF .resultsg").text(g.toFixed(3))}})}};function XDTV(a,b,c){var d=a.getElementsByTagName(b)return(d.length>0)?d[0].textContent:c}function BeerStyle(a){this.dom=a;this.name=XDTV(a,"NAME","");this.categoryNumber=XDTV(a,"CATEGORY_NUMBER","");this.styleLetter=XDTV(a,"STYLE_LETTER","");var b=this.categoryNumber+this.styleLetter;this.comName=(b=="")?this.name:(b+"-"+this.name)}function BeerRecipe(e){this.dom=e;this.asXml=function(a){a=(typeof a=="undefined")?false:a;var s=new XMLSerializer();var b=s.serializeToString(e);if(a)b="\n\n"+b+"\n";return b};this.boilTime=parseInt(XDTV(e,"BOIL_TIME",0));this.style=(e.getElementsByTagName("STYLE").length>0)?(new BeerStyle(e.getElementsByTagName("STYLE")[0])):0;this.name=XDTV(e,"NAME","Unknown");this.batchSize=parseFloat(XDTV(e,"BATCH_SIZE",0));this.spargeTemp=parseFloat(XDTV(e,"SPARGE_TEMP",0));this.eff=parseFloat(XDTV(e,"EFFICIENCY",0));this.og=parseFloat(XDTV(e,"OG",0));this.fg=parseFloat(XDTV(e,"FG",0));this.abv=parseFloat(XDTV(e,"ABV",0));this.ibu=parseFloat(XDTV(e,"IBU",0));this.notes=XDTV(e,"NOTES",0);this.est_color=parseFloat(XDTV(e,"EST_COLOR",0));this.est_og=parseFloat(XDTV(e,"EST_OG",0));this.est_fg=parseFloat(XDTV(e,"EST_FG",0));this.est_abv=parseFloat(XDTV(e,"EST_ABV",0));this.est_ibu=parseFloat(XDTV(e,"EST_IBU",0));this.getValue=function(a){if(this[a])return this[a];if(this["est_"+a])return this["est_"+a];return false};this.ferm_stage=parseInt(XDTV(e,"FERMENTATION_STAGES",0));var g=["PRIMARY","SECONDARY","TERTIARY"];this.fstages=[];for(var i=0;i40)i=40;return a[i]},show:function(a){this.bmAuto={rest_tm:[],rest_tp:[],boil:0,hops:[]};this.recipe=a;this.showFermentables(a.fermentables);this.showHopMisc(a.hops,a.miscs);this.showMash(this.processMash(a.mashes));this.showFermetationStage(a.fstages);this.showYeasts(a.yeasts);$(this.div).find(".boil-time").text(a.boilTime+this.u_min);$(this.div).find(".recipe-name").text(a.name);var b=this.opt.metric?a.batchSize.toFixed(2):this.toGallon(a.batchSize).toFixed(2);$(this.div).find(".batch-size").text(b+(this.opt.metric?this.u_l:this.u_gal));if(a.style)$(this.div).find(".recipe-style").text(a.style.comName);var c=a.getValue("og");if(c)$(this.div).find(".recipe-og").text(c.toFixed(3));var d=a.getValue("fg");if(d)$(this.div).find(".recipe-fg").text(d.toFixed(3));var e=a.getValue("abv");if(e)$(this.div).find(".recipe-abv").text(e.toFixed(1));var f=a.getValue("ibu");if(f)$(this.div).find(".recipe-ibu").text(f.toFixed(1));if(a.eff)$(this.div).find(".recipe-eff").text(a.eff);if(a.est_color)$(this.div).find(".recipe-color").text(a.est_color);if(a.notes)$(this.div).find(".recipe-note").text(a.notes);$(this.div).find(".color-block").css("background-color",this.srmColor(a.est_color));this.bmAuto.boil=a.boilTime},setCelius:function(a){this.celius=a;if(typeof this.recipe!="undefined"){$(this.div).find("tr.mash-row").remove();this.showMash(this.processMash(recipe.mashes))}},showFermentables:function(d){var t=this;var e=$(t.div).find("tr.ferm-header");$.each(d,function(k,v){var a=$(t.fermrow).clone(true);a.find("td.ferm-name").text(v.name);var b=t.opt.metric?v.amount:t.toLb(v.amount);a.find("td.ferm-weight").text(b.toFixed(2)+(t.opt.metric?t.u_kg:t.u_lb));a.find("td.ferm-yield").text(t.ppg?Math.round(46.177*v.yield/100):(v.yield+"%"));a.find("td.ferm-color").text(v.color+t.u_Lovibond);if(v.afterBoil||typeof v.note!="undefined"){var c=v.afterBoil?"After Boil.":"";if(typeof v.note!="undefined")c=c+" "+v.note;a.find("td.ferm-af").text(c)}e.after(a);e=a})},showHopMisc:function(f,g){var t=this;var j=[];var k=[];function pickboil(i,h){if(h.use.toLowerCase()=="boil")j.push(h);else k.push(h)}$.each(f,pickboil);$.each(g,pickboil);j.sort(function(a,b){return b.time-a.time});var l=[];var m=[];var n;$.each(j,function(i,v){if(m.length==0){n=v;m.push(v)}else if(n.time==v.time){m.push(v)}else{l.push(m);m=[v];n=v}});if(m.length)l.push(m);var o=$(t.div).find("tr.hop-header");var p=1;$.each(l,function(i,d){var e=true;$.each(d,function(i,h){var a=$(t.hoprow).clone(true);var b=false;if(e){e=false;a.find("td.hop-time").attr("rowspan",d.length).text(d[0].time+t.u_min);a.find("td.hop-order").attr("rowspan",d.length);if(d[0].time>0)b=true}else{a.find("td.hop-time").remove();a.find("td.hop-order").remove()}if(b){t.bmAuto.hops.push(d[0].time);a.find("td.hop-order").append("Hop#"+p+"");p++}a.find("td.hop-name").text(h.name);var c=t.opt.metric?(h.amount*1000):t.toOz(h.amount);a.find("td.hop-weight").text(c.toFixed(2)+(t.opt.metric?t.u_g:t.u_oz));if(typeof h["alpha"]!="undefined")a.find("td.hop-alpha").text(h.alpha+"%");else a.find("td.hop-note").text(h.type);o.after(a);o=a})});$.each(k,function(i,h){var a=$(t.hoprow).clone(true);a.find("td.hop-name").text(h.name);var b=t.opt.metric?(h.amount*1000):t.toOz(h.amount);a.find("td.hop-weight").text(b.toFixed(2)+(t.opt.metric?t.u_g:t.u_oz));if(typeof h["alpha"]!="undefined")a.find("td.hop-alpha").text(h.alpha+"%");a.find("td.hop-note").text(h.use);o.after(a);o=a})},getStrikeTemp:function(a){if(this.opt.doughIn=='c'&&typeof this.recipe.mashes[0].amount!="undefined"&&!isNaN(this.recipe.mashes[0].amount)&&this.recipe.mashes[0].amount>0){var b=this.recipe.mashGrain();return 0.41727029593*b/this.recipe.mashes[0].amount*(a-this.opt.grainTemp)+a+this.opt.equipAdjust}else if(this.opt.doughIn=='s'&&typeof this.opt.doughInTemp!="undefined"){return this.opt.doughInTemp}return a},processMash:function(a){if(a.length==0)return[];var b=this.getStrikeTemp(a[0].temp);var c={aname:"Mash In",name:"",temp:b};var d=[c];var e;if(a[a.length-1].temp>=75){e=true;a[a.length-1].aname="Mash Out"}else e=false;var f=1;$.each(a,function(k,v){if(!e||k<(a.length-1))v.aname="Mash Step "+f;f++;d.push(v)});if(!e)d.push({aname:"Mash Out",temp:this.opt.MashOutTemp,time:this.opt.MashOutTime});if(d.length>8){var g=d.pop();d.slice(0,6);d.push(g)}return d},showYeasts:function(d){var t=this;var e=$(t.div).find("tr.yeast-header");$.each(d,function(k,v){var a=$(t.yeastrow).clone(true);a.find(".yeast-name").text(v.name);a.find(".yeast-pid").text(v.lab+" "+v.pid);a.find(".yeast-att").text(v.attenuation);var b=t.celius?v.mintemp:t.toFahrenheit(v.mintemp);var c=t.celius?v.maxtemp:t.toFahrenheit(v.maxtemp);a.find(".yeast-temp").html(b.toFixed(1)+" ~ "+c.toFixed(1)+(t.celius?t.u_c:t.u_f));e.after(a);e=a})},showFermetationStage:function(c){var t=this;var d=$(t.div).find("tr.fermstage-header");var e=["Primary","Secondary","Additional"];$.each(c,function(k,v){var a=$(t.stagerow).clone(true);a.find(".ferm-stage").text(e[k]);var b=t.celius?v.temp:t.toFahrenheit(v.temp);a.find(".ferm-temp").html(b.toFixed(1)+(t.celius?t.u_c:t.u_f));a.find(".ferm-time").text(v.time.toFixed(1));d.after(a);d=a})},showMash:function(d){var t=this;var e=$(t.div).find("tr.mash-header");$.each(d,function(k,v){var a=$(t.mashrow).clone(true);a.find("td.mash-autorest").append(""+v.aname+"");a.find("td.mash-name").text(v.name);var b=t.celius?v.temp:t.toFahrenheit(v.temp);a.find("td.mash-temp").html(b.toFixed(1)+(t.celius?t.u_c:t.u_f));t.bmAuto.rest_tp.push(v.temp);if(!isNaN(v.time)){a.find("td.mash-time").text(v.time+t.u_min);t.bmAuto.rest_tm.push(v.time)}else{t.bmAuto.rest_tm.push(1)}if(typeof v.type!="undefined")a.find("td.mash-type").text(v.type);if(v.amount>0){var c=t.opt.metric?v.amount:t.toQt(v.amount);a.find("td.mash-water").text(c.toFixed(2)+(t.opt.metric?t.u_l:t.u_qt))}e.after(a);e=a});if(t.bmAuto.rest_tm.length<8){var f=t.bmAuto.rest_tm.pop();var g=t.bmAuto.rest_tp.pop();var h=7-t.bmAuto.rest_tm.length;for(;h>0;h--){t.bmAuto.rest_tm.push(0);t.bmAuto.rest_tp.push(0)}t.bmAuto.rest_tm.push(f);t.bmAuto.rest_tp.push(g)}}};var Recipes={prefUrl:"userpref.cfg",lsUrl:"list.php",recipeUrlBase:"R/",ulUrl:"upfile.php",rmUrl:"rm.php",celius:true,userPreference:{"metric":true,"MashOutTemp":77.2,"MashOutTime":10,"doughIn":"c","grainTemp":20,"doughInTemp":55,"equipAdjust":0},importing:-1,list:[],loaded:false,load:function(){if(Recipes.loaded)return;Recipes.loaded=true;Recipes.getInfo()},cache:[],upload:function(b,c,d,e,f){var g=new FormData();var h=new Blob([c],{type:d});g.append("file",h,b);var i=new XMLHttpRequest();i.open("POST",Recipes.ulUrl);i.send(g);i.onload=function(a){if(i.status==200){if(e)e()}else{if(f)f(i,i.status);else console.log("failed:"+i.status)}}},view:function(c){this.viewing=c.substring("recipe-list-".length);var d=this.recipeUrlBase+this.viewing;if(typeof Recipes.cache[d]!="undefined"){var e=new BeerXML(Recipes.cache[d]);Recipes.showRecipe(e.recipe(0))}else{$.ajax({method:"GET",url:d,}).done(function(a){Recipes.cache[d]=a;var b=new BeerXML(a);Recipes.showRecipe(b.recipe(0))})}},showRecipe:function(r){if(r){if(r.brewable()){$("#xml-save").button("option","disabled",false);$("#xml-brew").button("option","disabled",false)}else{$("#xml-save").button("option","disabled",true);$("#xml-brew").button("option","disabled",true)}RecipeDisplay.clear();RecipeDisplay.show(r);$("#recipe-table").show()}else{jAlert("Invalid BeerXML!");$("#recipe-table").hide();$("#xml-save").button("option","disabled",true);$("#xml-brew").button("option","disabled",true)}},validFileName:function(){var f=$("#xml-savename").val().trim();if(f.search(/[^\w\d-_]/)>=0)return false;return f},xmlName:function(n){var a=n.replace(/\s/g,'').replace(/[\[\]\/\\\?%\*:|\"<>!\.]/g,'_');var b=a;var c=1;while($.inArray(a,Recipes.list)>=0){a=b+"_"+c;c++}$("#xml-savename").val(a)},xmlSelect:function(e){var a=$(e.target).find("option:selected")[0].value;Recipes.importing=a;var r=Recipes.beerxml.recipe(a);Recipes.xmlName(r.name);Recipes.showRecipe(r)},openfile:function(f){if(f){var r=new FileReader();r.onload=function(e){window.file=f;Recipes.beerxml=new BeerXML(e.target.result);$('#xml-recipe-select').empty();var a=Recipes.beerxml.recipeNames();$.each(a,function(i,n){$('#xml-recipe-select').append($(""))});Recipes.importing=0;if(a.length>0)Recipes.xmlName(a[0]);Recipes.showRecipe(Recipes.beerxml.recipe(0))};r.readAsText(f)}else{$('#xml-recipe-select').empty();Recipes.importing=-1}},prefSup:false,prefChanged:function(){if(this.prefSup)return;$("#recipe-option-update").show();RecipeDisplay.option(Recipes.userPreference)},updateUserPref:function(){$("#recipe-option-update").button("option","disabled",true);var c=JSON.stringify(Recipes.userPreference);Recipes.upload(Recipes.prefUrl,c,"text/plain",function(){$("#recipe-option-update").button("option","disabled",false).hide()},function(a,b){jAlert("Failed to update:"+b);$("#recipe-option-update").button("option","disabled",false)})},brewXml:function(){var a=RecipeDisplay.getAuto();console.log(a);BM.saveRecipe(a)},saveXml:function(){if(Recipes.importing<0||typeof Recipes.beerxml=="undefined")return;var f=Recipes.validFileName();if(!f){jAlert("Invalid name!");return}function doSave(){var a=Recipes.beerxml.recipe(Recipes.importing);var b=Recipes.recipeUrlBase+f;Recipes.upload(b,a.asXml(true),"text/xml",function(){Recipes.addRecipe(f,a.asXml(true))},function(x,s){jAlert("Error saving recipe:"+s)})}if($.inArray(f,Recipes.list)>=0){jConfirm({title:"Replace existing recipe?",msg:"The existing recipe will be replaced.",ok:"Replace",onok:function(){doSave()}})}else doSave()},delRecipe:function(){var t=this;var r=t.viewing;function rmList(){var a=$.inArray(r,Recipes.list);if(a<0){console.log("error condition")}Recipes.list.splice(a,1);$("#recipe-list-"+r).remove()}$.ajax({url:t.rmUrl,type:"POST",data:{file:t.recipeUrlBase+r},success:function(){rmList()},error:function(a,b,c){jAlert("Error delete recipe:"+c)}})},dispPreference:function(){this.prefSup=true;var a=(Recipes.userPreference.metric)?"m":"u";$("input[name=genunit][value="+a+"]").prop('checked',true);$("input[name=mashin_temp][value="+Recipes.userPreference.doughIn+"]").prop('checked',true);Recipes.mashinInput(Recipes.userPreference.doughIn);var b=(this.celius)?Recipes.userPreference.grainTemp:C2F(Recipes.userPreference.grainTemp);$("#grain-temp").spinner("value",b);var c=(this.celius)?Recipes.userPreference.equipAdjust:(1.8*Recipes.userPreference.equipAdjust);$("#equip-adj").spinner("value",c);var d=(this.celius)?Recipes.userPreference.doughInTemp:C2F(Recipes.userPreference.doughInTemp);$("#mashin-stemp").spinner("value",d);var e=(this.celius)?Recipes.userPreference.MashOutTemp:C2F(Recipes.userPreference.MashOutTemp);$("#mo-temp").spinner("value",e);$("#mo-time").spinner("value",Recipes.userPreference.MashOutTime);this.prefSup=false},mashinInput:function(v){function inputdis(g,e,s){$("#grain-temp").spinner("option","disabled",g);$("#equip-adj").spinner("option","disabled",e);$("#mashin-stemp").spinner("option","disabled",s)}if(v=='c')inputdis(false,false,true);else if(v=='s')inputdis(true,true,false);else inputdis(true,true,true)},initPreference:function(){$("input[type=radio][name=genunit]").change(function(){if(this.value=='m'){Recipes.userPreference.metric=true}else{Recipes.userPreference.metric=false}Recipes.prefChanged()});$("#grain-temp").spinner({step:0.1,change:function(){var v=$("#grain-temp").spinner("value");Recipes.userPreference.grainTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("#equip-adj").spinner({step:0.1,change:function(){var v=$("#equip-adj").spinner("value");Recipes.userPreference.equipAdjust=Recipes.celius?v:v/1.8;Recipes.prefChanged()}});$("#mashin-stemp").spinner({step:0.1,change:function(){var v=$("#mashin-stemp").spinner("value");Recipes.userPreference.doughInTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("input[type=radio][name=mashin_temp]").change(function(){Recipes.userPreference.doughIn=this.value;Recipes.mashinInput(this.value);Recipes.prefChanged()});$("#mo-temp").spinner({step:0.1,change:function(){var v=$("#mo-temp").spinner("value");Recipes.userPreference.MashOutTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("#mo-time").spinner({change:function(){Recipes.userPreference.MashOutTime=$("#mo-time").spinner("value");Recipes.prefChanged()}});$("#recipe-option-update").button().click(function(){Recipes.updateUserPref()}).hide()},unitChanged:function(a){Recipes.celius=a;RecipeDisplay.setCelius(a);Recipes.dispPreference()},addRecipe:function(f,a){if($.inArray(f,Recipes.list)<0){Recipes.list.push(f);$("#recipe-list").append("
  • "+f+"
  • ")}Recipes.cache[Recipes.recipeUrlBase+f]=a},updateList:function(){$.each(Recipes.list,function(k,v){$("#recipe-list").append("
  • "+v+"
  • ")})},getList:function(){$.ajax({method:"POST",data:{dir:Recipes.recipeUrlBase},url:Recipes.lsUrl,}).done(function(a){Recipes.list=a;Recipes.updateList()})},getInfo:function(){$.ajax({method:"GET",url:Recipes.prefUrl,}).done(function(a){Recipes.userPreference=JSON.parse(a);RecipeDisplay.option(Recipes.userPreference)}).always(function(){Recipes.dispPreference();Recipes.getList()})},init:function(){$("#recipe-options-panel").hide();$("#recipe-import-panel").hide();$("#recipe-view-panel").hide();$("#recipe-table").hide();Recipes.initPreference();BM.addUnitChangeHdlr(function(c){Recipes.unitChanged(c)});window.menuselected.recipes=function(){Recipes.load()};$("#recipe-list").selectable({element:null,selected:function(a,b){element=$(b.selected)},stop:function(a,b){element.siblings().removeClass("selected");if(element[0].id=="recipe-options"){$("#recipe-options-panel").show();$("#recipe-import-panel").hide();$("#recipe-view-panel").hide();$("#recipe-table").hide()}else if(element[0].id=="recipe-import"){$("#recipe-options-panel").hide();$("#recipe-import-panel").show();$("#recipe-view-panel").hide();if(Recipes.importing>=0&&typeof Recipes.beerxml!="undefined")Recipes.showRecipe(Recipes.beerxml.recipe(Recipes.importing));else $("#recipe-table").hide()}else{$("#recipe-options-panel").hide();$("#recipe-import-panel").hide();$("#recipe-view-panel").show();Recipes.view(element[0].id)}}});RecipeDisplay.init("#xml-recipe",Recipes.userPreference);$('#xml-recipe-select').change(function(e){Recipes.xmlSelect(e)});$("#fileinput").change(function(a){var f=a.target.files[0];Recipes.openfile(f)});$("#xml-save").button({"disabled":true}).click(function(){Recipes.saveXml()});$("#xml-brew").button({"disabled":true}).click(function(){Recipes.brewXml()});$("#recipe-del").button().click(function(){Recipes.delRecipe()});$("#recipe-brew").button().click(function(){Recipes.brewXml()})}}; \ No newline at end of file +function setCookie(a,b,c){var d=new Date();d.setTime(d.getTime()+(c*24*60*60*1000));var e="expires="+d.toUTCString();document.cookie=a+"="+b+"; "+e}function getCookie(a){var b=a+"=";var d=document.cookie.split(';');for(var i=0;i9)?c:"0"+c)+':'+((b>9)?b:"0"+b))};BrewChart.prototype.incTime=function(){this.config.data.labels.push(this.ftime(this.ctime));this.ctime+=this.interval};BrewChart.prototype.addData=function(i,a){if(!this.celius&&!isNaN(a))a=C2F(a);this.config.data.datasets[i].data.push(a)};BrewChart.prototype.chart=function(){var t=this;var a=document.getElementById(t.cid).getContext("2d");var b={label:t.spLabel,data:[],fill:false,borderColor:BrewChart.spcolor,backgroundColor:BrewChart.spcolor,pointBorderColor:BrewChart.spcolor,pointBackgroundColor:BrewChart.spcolor,borderDash:[8,4],pointBorderWidth:1,pointRadius:1,pointStyle:'dash',lineTension:0,cubicInterpolationMode:'linear'};t.config.data.datasets.push(b);for(i=0;i0&&a[a.length-1].value==b){if(a[a.length-1].dt=='e'){a.pop()}}var c=$.extend(true,{},BrewChart.stageAnno);if(s<=10){c.label.text=STR.stageName[s]}else if(s==100){c.label.text=STR.ManualMode}else if(s==103){c.label.text=STR.PIDAutoTune}else{return}c.value=b;this.config.options.annotation.annotations.push(c)};BrewChart.prototype.addEvent=function(s){if(s==1||s==10){var a=this.config.options.annotation.annotations;var b=this.ftime(this.ctime);if(a.length>0&&a[a.length-1].value==b){return}var c=$.extend(true,{},BrewChart.eventAnno);c.label.text=STR.event[s];c.value=b;this.config.options.annotation.annotations.push(c)}};BrewChart.prototype.addResume=function(s){this.incTime();for(i=0;i5)return false;return{sensor:s,f:a[1]&0x10}};BrewChart.prototype.process=function(a){var t=this;for(var i=0;i12000){t.addData(t.lidx+1,NaN)}else{t.addData(t.lidx+1,f/100)}if(++t.lidx>=t.numLine)t.lidx=0}}t.myLine.update()};var EEPROM={"s_kp":{max:100,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_ki":{max:155,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_kd":{max:100,min:-100,inc:1,decode:function(v){return v-100},encode:function(v){return v+100}},"s_sample_time":{max:3500,min:1500,inc:250,decode:function(v){return v*250},encode:function(v){return Math.round(v/250)}},"s_window":{max:7500,min:4000,inc:250,decode:function(v){return v*250},encode:function(v){return Math.round(v/250)}},"s_pwm":{max:100,min:0,inc:1},"s_cal":{max:5,min:-5,inc:0.1,decode:function(v){return(v-50)/10},encode:function(v){return v*10+50}},"s_pidstart":{max:3.5,min:1.0,inc:0.1,decode:function(v){return(v)/10},encode:function(v){return v*10}},"s_unit":{max:1,min:0,inc:1,labels:["°C","°F"],},"s_nodelay":{max:1,min:0,inc:1,labels:["No","Yes"]},"s_boil":{max:120,min:80,inc:1},"s_pumpcycle":{max:15,min:5,inc:1},"s_pumprest":{max:5,min:0,inc:1},"s_pumppremash":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpmash":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpmashout":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpboil":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_pumpstop":{max:120,min:80,inc:1},"s_pipe":{max:1,min:0,inc:1,labels:["Passive","Active"]},"s_skipadd":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_skipremove":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_skipiodine":{max:1,min:0,inc:1,labels:["NO","YES"]},"s_iodine":{max:120,min:0,inc:1},"s_whirlpool":{max:2,min:0,labels:["Off","Cold","Hot"]},"s_spenable":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_sptempctrl":{max:1,min:0,inc:1,labels:["Off","ON"]},"s_spsensor":{max:5,min:0,inc:1},"s_sptemp":{max:80,min:75,inc:1},"s_spdiff":{max:2.0,min:0.5,inc:0.1,decode:function(v){return(v)/10},encode:function(v){return v*10}}};var BMSetting={values:{},editing:{},enabled:false,celius:true,singlesensor:true,disableSetting:function(a){$("#settings-p input").spinner({disabled:a})},disableButton:function(a){$("#settings-p button").button({disabled:a})},setEnabled:function(e){this.enabled=e;if(e){$("#esetting").button({disabled:false})}else{$("#esetting").button({disabled:true})}},display:function(){var t=this;var c=t.celius;$.each(this.values,function(k,v){var p=EEPROM[k];if(p){var a;if(typeof p["labels"]=="undefined"){if(typeof p["decode"]=="undefined")a=v;else a=p.decode(v)}else{a=p["labels"][v]}if(!c){if(k=="s_cal"||k=="s_spdiff")a=a*1.8;else if(k=="s_boil"||k=="s_pumpstop"||k=="s_sptemp")a=C2F(a)}$('#'+k).text(a)}else{if(k=="sensors")t.sensorAddr(v);else if(k=="primary")t.primarySensor(v);else if(k=="auxiliary")t.auxiliarySensor(v)}})},auxiliarySensor:function(l){for(var i=0;ithis.numsensor){for(var i=a;i<=n;i++){var e=b.clone();e.find("td.sensor_id").text(i);e.find("td.sensor_addr").attr("id","SA_"+i);e.insertAfter(b);b=e;var f=c.clone();var g="s_cal_"+i;f.find("td.TCAL_T").text(d+" #"+i);f.find("span.TCAL_V").attr("id",g);f.insertAfter(c);EEPROM[g]=EEPROM["s_cal"];c=f}}else{for(var i=n+1;i<=this.numsensor;i++){var h=$("#SA_"+i).closest("tr.sensor_row");h.remove();var j=$("#s_cal_"+i).closest("tr");j.remove()}}this.numsensor=n},setting:function(s){this.values=s;this.display();if($("#esetting").button("option","icons").primary!="ui-icon-pencil"){$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide()}},unitCelius:function(c){if(this.celius!=c){$(".tmp_unit").text((c)?"°C":"°F");this.celius=c}},valuechange:function(s){var n=$(s).attr("name");var v=$(s).spinner("value");var a=$(s).spinner("option","min");var b=$(s).spinner("option","max");if(vb)v=b;$(s).spinner("value",v);if(!this.celius){if(n=="s_cal"||n=="s_spdiff")v=v/1.8;else if(n=="s_boil"||n=="s_pumpstop"||n=="s_sptemp")v=F2C(v)}if(typeof EEPROM[n]["encode"]=="undefined")this.editing[n]=v;else this.editing[n]=EEPROM[n].encode(v)},switchchange:function(n,c){this.editing[n]=c},selectionchange:function(n,v){this.editing[n]=v},editsettings:function(){var f=this.values;var b=this;$.each(EEPROM,function(k,p){var s=$('#'+k).empty();var c=(typeof p["decode"]=="undefined")?f[k]:p.decode(f[k]);if(typeof p["labels"]=="undefined"){var d=p["min"];var e=p["max"];if(!b.celius){if(k=="s_cal"||k=="s_spdiff"){c=c*1.8;d=d*1.8;e=e*1.8}else{if(k=="s_boil"||k=="s_pumpstop"||k=="s_sptemp"){c=C2F(c);d=C2F(d);e=C2F(e)}}}$("").appendTo(s);s.find("input").spinner({min:d,max:e,step:p["inc"],change:function(){b.valuechange(this)}}).attr("name",k)}else if((p["labels"]).length==2){$("").appendTo(s);s.find("input[type=checkbox]").switchButton({on_label:p["labels"][1],off_label:p["labels"][0],name:k,on_callback:function(){b.switchchange(k,(this.options["checked"])?1:0)},off_callback:function(){b.switchchange(k,(this.options["checked"])?1:0)}})}else{var h="";$.each(p["labels"],function(i,a){var b=(c==i)?"checked":"";h=h+""+p["labels"][i]+"
    "});$(h).appendTo(s);s.find("input").on("click",function(){b.selectionchange(k,s.find("input:checked").val())})}});if(this.singlesensor)this.editing={};else this.editing={scals:this.values["scals"]}},finishSaving:function(s){if(s){var b=this;$.each(b.editing,function(k,v){b.values[k]=v});b.display();$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide()}else{this.disableSetting(false)}this.disableButton(false)},init:function(a){var b=this;$("#esetting").button({disabled:false,text:false,icons:{primary:"ui-icon-pencil"}}).click(function(){if($("#esetting").button("option","icons").primary=="ui-icon-pencil"){$("#esetting").button("option","icons",{primary:"ui-icon-arrowreturnthick-1-w"});$("#savesetting").show();b.editsettings()}else{$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide();b.display()}});$("#savesetting").button({text:false,icons:{primary:"ui-icon-disk"}}).click(function(){if(!b.enabled){alert("BrewManiac is not in idle state");return}if(Object.keys(b.editing).length==0){$("#esetting").button("option","icons",{primary:"ui-icon-pencil"});$("#savesetting").hide();b.display();return}b.disableSetting(true);b.disableButton(true);a.savesetting(b.editing)}).hide()}};var BMRecipe={auto:{},eauto:{},enabled:false,celius:true,disableInput:function(a){$("#automation-p input").spinner({disabled:a})},disableButton:function(a){$("#automation-p button").button({disabled:a})},setEnabled:function(e){this.enabled=e;if(e)$("#editauto").button({disabled:false});else $("#editauto").button({disabled:true})},updateRecipe:function(d){this.auto=d;this.display();if($("#editauto").button("option","icons").primary!="ui-icon-pencil"){this.stopEditRecipe()}},unitCelius:function(a){this.celius=a;if($("#editauto").button("option","icons").primary!="ui-icon-pencil"){this.stopEditRecipe()}if(typeof this.auto.rest_tp!=="undefined")this.display()},newrest:function(i){return $(''+STR.Mash+' '+i+' °'+((this.celius)?'C':'F')+' min')},dis_rest:function(d){var a=$("#s7_tp").closest("tr");$("#s0_tp").closest("tr").nextUntil(a).remove();for(var i=1;i<7;i++){var v=d.rest_tm[i];if(v==0){break}else{var b=this.newrest(i);a.before(b);$('#s'+i+'_tm').text(v);$('#s'+i+'_tp').text(this.TC(d.rest_tp[i]))}}},TC:function(t){return(this.celius)?Math.round(t*10)/10:C2F(t)},display:function(){var d=this.auto;$('#s0_tp').text(this.TC(d.rest_tp[0]));$('#s7_tm').text(d.rest_tm[7]);$('#s7_tp').text(this.TC(d.rest_tp[7]));this.dis_rest(this.auto);$("#boiltime").text(d.boil);$("#auto_table tr:gt("+$("#boiltime").closest("tr").index()+")").remove();var t=$("#auto_table");$.each(d.hops,function(i,h){$("Hop#"+(i+1)+""+h+" min").appendTo(t)})},minRT:[20,25,25,25,25,25,25,75],maxRT:[75,76,76,76,76,76,76,80],minRT_F:[68,77,77,77,77,77,77,167],maxRT_F:[167,169,169,169,169,169,176,176],rtmChange:function(s){var i=$(s).attr("name").substring(2);var v=$(s).spinner("value");if(v>140)v=140;var a=(i>5)?1:0;if(vb)v=b;$(s).spinner("value",v);this.eauto.rest_tp[i]=(this.celius)?v:F2C(v)},btChange:function(s){var v=$(s).spinner("value");if(v>140)v=140;if(v<1)v=1;$(s).spinner("value",v);this.eauto.boil=v;this.listhop()},hchange:function(s){var i=$(s).attr("name").substring(1);this.eauto.hops.splice(i,1);var v=$(s).spinner("value");if(v<1)v=1;if(v>this.eauto.boil)v=this.eauto.boil;this.eauto.hops.push(v);this.eauto.hops.sort(function(a,b){return b-a});this.listhop()},dhop:function(s){var i=$(s).attr("name").substring(2);this.eauto.hops.splice(i,1);this.listhop()},ahop:function(){var v=this.eauto.hops[this.eauto.hops.length-1]-1;if(v<1)v=1;this.eauto.hops.push(v);this.listhop()},listhop:function(){$("#auto_table tr:gt("+$("#boiltime").closest("tr").index()+")").remove();var t=$("#auto_table");var b=this;$.each(b.eauto.hops,function(i,h){var e=$("Hop#"+(i+1)+"min ").appendTo(t);e.find("input").spinner({min:1,max:b.eauto.boil,change:function(){b.hchange(this)}});e.find("button").css("color","red").attr("name","dh"+i).button({text:false,icons:{primary:"ui-icon-trash"}}).click(function(){b.dhop(this)})})},drest:function(s){var b=this;var a=b.eauto.rest_tm;var c=b.eauto.rest_tp;var i=parseInt($(s).attr("name").substring(2));for(var r=i;r<6;r++){var n=r+1;a[r]=a[n];c[r]=c[n]}a[6]=0;c[6]=0;b.dis_rest(this.eauto);for(var i=0;i<7;i++){b.resteditable(i)}},arest:function(){var i;for(i=1;i<7;i++){if(this.eauto.rest_tm[i]==0){this.eauto.rest_tm[i]=10;this.eauto.rest_tp[i]=this.eauto.rest_tp[i-1]+1;var a=this.newrest(i);$("#s7_tp").closest("tr").before(a);this.resteditable(i);break}}},resteditable:function(i){var b=this;if(i!=0){var a=$('#s'+i+'_tm').empty();$("").appendTo(a);var c=1;a.find("input").spinner({min:c,max:140,change:function(){b.rtmChange(this)}}).attr("name",'tm'+i);if(i<7){$('').appendTo(a.closest("td")).css("color","red").attr("name","mr"+i).button({text:false,icons:{primary:"ui-icon-trash"}}).click(function(){b.drest(this)})}}var d=$('#s'+i+'_tp').empty();var v=(this.celius)?b.eauto.rest_tp[i]:C2F(b.eauto.rest_tp[i]);var c=(this.celius)?b.minRT[i]:b.minRT_F[i];var e=(this.celius)?b.maxRT[i]:b.maxRT_F[i];if(ve)v=e;b.eauto.rest_tp[i]=v;$("").appendTo(d);d.find("input").spinner({min:c,max:e,step:0.25,change:function(){b.rtpChange(this)}}).attr("name",'tp'+i)},edit:function(){$("#addhop").show();$("#addrest").show();$("#saveauto").show();var b=this;b.eauto=$.extend(true,{},this.auto);var a=$("").appendTo($('#boiltime').empty()).spinner({min:1,max:140,change:function(){b.btChange(this)}});b.listhop();for(var i=0;i<8;i++){if(i>0&&i<7&&b.eauto.rest_tm[i]==0){i=6;continue}this.resteditable(i)}},stopEditRecipe:function(){$("#editauto").button("option","icons",{primary:"ui-icon-pencil"});$("#saveauto").hide();$("#addhop").hide();$("#addrest").hide()},validate:function(){if(this.eauto.rest_tm[7]==0)return false;var a=this.eauto.boil;if(this.eauto.hops.length>0){var b=this.eauto.hops[0];if(b>a)return false;for(var i=1;i=b)return false;b=v}}return true},finishSaveRecipe:function(a){if(a){this.auto=BM.auto;this.display();this.stopEditRecipe()}else{this.disableInput(false)}this.disableButton(false)},init:function(a){var b=this;$("#editauto").button({disabled:false,text:false,icons:{primary:"ui-icon-pencil"}}).click(function(){if($("#editauto").button("option","icons").primary=="ui-icon-pencil"){b.edit();$("#editauto").button("option","icons",{primary:"ui-icon-arrowreturnthick-1-w"})}else{b.display();b.stopEditRecipe()}});$("#saveauto").button({disabled:false,text:false,icons:{primary:"ui-icon-disk"}}).click(function(){if(!b.enabled){alert("BrewManiac is not in idle state");return}if(b.validate()){b.disableButton(true);b.disableInput(true);a.saveRecipe(b.eauto)}else{alert("Invalid value!")}}).hide();$("#addhop").button({disabled:false,text:false,icons:{primary:"ui-icon-plusthick"}}).click(function(){b.ahop()}).hide();$("#addrest").button({disabled:false,text:false,icons:{primary:"ui-icon-plusthick"}}).click(function(){b.arest()}).hide()}};var BMScreen={ctemp:0,stemp:35,pwm:0,pwmOn:false,screen:"U",bm:null,celius:true,singlesensor:true,numsensor:0,htimer:null,h_animated:0,HC_active:"#FE1E1E",HC_inactive:"#5B0000",HC_pause:"#DE912F",PC_active:"#70FC57",PC_inactive:"#01290C",PC_pause:"#22C6AB",spargesensor:-1,autolist:function(){var a=this.bm.autoAllStages();var t=$("#auto-t").empty();var b=(this.celius)?"°C":"°F";b=""+b+"";var c={addmalt:STR.AddMalt,removemalt:STR.RemoveMalt,boilend:STR.BoilEnd,cooling:STR.Cooling};for(i=0;i"+STR.stageName[s.stage]+""+d+b+""+((s.stage)?(s.time+STR.min):"-")+">").appendTo(t)}else if(s.type=="event"){$(""+c[s.name]+"-->").appendTo(t)}else if(s.type=="boil"){$(""+STR.Boil+"-"+s.time+STR.min+">").appendTo(t)}else if(s.type=="hop"){$(""+STR.HopN+(s.index+1)+"-"+s.time+STR.min+">").appendTo(t)}}},inStage:function(i){$("#auto-t tr:eq("+i+")").removeClass("run").addClass("running");$("#auto-t tr:lt("+i+")").removeClass("running").addClass("run");$("#auto-t tr:gt("+i+")").removeClass("running").removeClass("run")},unitCelius:function(a){this.celius=a;if(this.singlesensor){this.currenttemp(this.ctemp)}else{this.alltemps(this.ctemps)}if(this.isRunning(this.screen))this.settingtemp(this.stemp)},isRunning:function(s){return(s=="A"||s=="M")},setScreen:function(s,a){var t=this;if(s=="S")$("#title").text(STR.Setup);else if(s=="I"){$("#title").text(STR.Idle);if(!t.singlesensor)t.setPrimarySensor(t.primary[0])}else if(s=="M"){$("#title").text(STR.ManualMode);if(!t.singlesensor)t.setPrimarySensor(t.primary[1])}else if(s=="A"){if(a==11)$("#title").text(STR.DelayStart);else $("#title").text(STR.Automation);if(!t.singlesensor){if(a==0)t.setPrimarySensor(t.primary[2]);else if(a>=1&&a<=7)t.setPrimarySensor(t.primary[3]);else if(a==8)t.setPrimarySensor(t.primary[4]);else if(a>8)t.setPrimarySensor(t.primary[5])}}else if(s=="U")$("#title").text(STR.Unknown);else if(s=="T")$("#title").text(STR.PIDAutoTune);if(s!="A"&&s!="M"&&s!="T"){t.clear_settingtemp();t.deacTime();BChart.stop()}else{t.settingtemp(t.stemp);t.displaytime(0);if(BChart.running){BChart.pull()}else{BChart.start();BChart.setCelius(this.celius)}}if(s=="A"){if(t.screen!="A"){t.autolist();$("#auto-p").css('display','inline-block')}}else{$("#auto-p").css('display','none')}t.screen=s},setLed:function(a,b){$(a).css("background",b)},heatStatus:function(s){if(s==0)this.setLed("#heatled",this.HC_inactive);else if(s==1)this.setLed("#heatled",this.HC_active);else this.setLed("#heatled",this.HC_pause)},pumpStatus:function(s){if(s==0)this.setLed("#pumpled",this.PC_inactive);else if(s==1)this.setLed("#pumpled",this.PC_active);else this.setLed("#pumpled",this.PC_pause)},currenttemp:function(t){this.ctemp=t;if(t>300||t<-1){$("#currenttemp").text('--')}else{var v=(this.celius)?t:C2F(t);$("#currenttemp").text(v.toFixed(2))}},setPrimarySensor:function(n){var a=n+1;for(var i=1;i<=this.numsensor;i++){if(i==a)$("#t_id_"+i).text("*#"+i+":");else{if(i!=(this.spargesensor+1))$("#t_id_"+i).text("#"+i+":")}}},multisensor:function(n,a,b){var t=this;t.primary=a;t.aux=b;if(n==0)return;t.singlesensor=false;if(t.numsensor!=n){if(t.numsensor300||t<-1){$("#currentTemp_"+(i+1)).text('--')}else{var v=(this.celius)?t:C2F(t);$("#currentTemp_"+(i+1)).text(v.toFixed(2))}}},clear_settingtemp:function(){$("#setpoint").css("color","#000033");$("#setpoint").text("0.00")},settingtemp:function(t){this.stemp=t;$("#setpoint").css("color","");var v=(this.celius)?t:C2F(t);$("#setpoint").text(v.toFixed(2))},showPwm:function(s){if(s)$("#pwm").css("color","");else{$("#pwm").css("color","#550000");$("#pwm").text("00")}},pwmValue:function(v){this.pwm=v;$("#pwm").text(v)},setPwmOn:function(o){this.pwmOn=o;this.showPwm(o)},displaytime:function(t){if(isNaN(t))return;var m=Math.floor(t/60);var s=t-m*60;var h=Math.floor(m/60);m=m-h*60;$("#timer").css("color","");$("#timer").text(""+((h>9)?h:("0"+h))+":"+((m>9)?m:("0"+m))+":"+((s>9)?s:("0"+s)))},deacTime:function(){$("#timer").css("color","#000033");$("#timer").text("00:00:00")},clearTime:function(){$("#timer").text("00:00:00")},openDiaTimer:null,initDialog:function(){$("div.dialog").hide();var b=this;$("div.dialog").dialog({autoOpen:false,modal:true,show:{effect:"bounce",duration:1000},hide:{effect:"fade",duration:1000},close:function(){Beep.pause()},buttons:{Ok:function(){$(this).dialog("close");if(b.openDiaTimer)clearTimeout(b.openDiaTimer)}}})},popDialog:function(a,c){$(a).dialog("open");var b=this;if((typeof c=="undefined")||c)b.openDiaTimer=setTimeout(function(){$(a).dialog("close");b.openDiaTimer=null},5000)},soundTimeout:null,sound:function(t){var b=this;if(b.soundTimeout)clearTimeout(b.soundTimeout);Beep.pause();Beep.loop=true;Beep.play();if(t>0)b.soundTimeout=setTimeout(function(){b.soundTimeout=null;Beep.pause()},t*1000)},setInfo:function(t,a){a=(typeof a==="undefined")?1:a;$("#info").text(t);if(a)setTimeout(function(){$("#info").text("")},5000)},brewevent:function(e){if(BChart.running)BChart.pull();if(e<=10){this.sound(2);this.setInfo(STR.event[e]);if(e==5)$("#title").text(STR.Pause);else if(e==6)$("#title").text(STR.Automation)}else if(e==11){this.setInfo(STR.PumpRest,0)}else if(e==12){this.setInfo("",0)}else if(e==99){this.sound(5);this.setInfo(STR.event[11])}},error:function(c){if(c=="disc"){this.sound(0);this.popDialog("#d_ConnectionError",false)}else if(c=="s_disc"){this.sound(0);this.popDialog("#d_SerialError",false)}this.setScreen("U")},toggleButton:function(){if($("#showbtn").button("option","icons").primary=="ui-icon-circle-triangle-s"){$("#showbtn").button("option","icons",{primary:"ui-icon-circle-triangle-n"})}else{$("#showbtn").button("option","icons",{primary:"ui-icon-circle-triangle-s"})}$("#bpannel").toggle("slide",{direction:"up"},500)},btnPressed:false,btnClick:function(k,l){var b=this;if(b.btnPressed)return;b.btnPressed=true;this.bm.sendButton(k,l,function(){b.btnPressed=false})},home:function(){this.btnClick("home",false)},hideButton:function(){var H=$("#btncover").height();var a=true;$("#btncover").on("click",function(){if(a){$("#btncover").animate({height:10},500)}else{$("#btncover").animate({height:H},500)}a=!a})},init:function(b){this.bm=b;this.showPwm(false);this.clear_settingtemp();this.initDialog();var b=this;var d=getCookie("warning");if(d!=1){$("#d_warning").dialog({resizable:false,dialogClass:"no-close",modal:true,buttons:{"Agree":function(){$(this).dialog("close")}}});$('#nshow').change(function(){setCookie("warning",($(this).is(':checked'))?1:0,365)})}else $("#d_warning").hide();this.hideButton();function sb(a){var c=$("#btn-"+a).css("background");$("#btn-"+a).bind("touchstart mousedown",function(e){e.preventDefault();this.dt=Date.now();$(this).css("background","#FF1111");return false}).bind("touchend mouseup",function(e){e.preventDefault();if(typeof this.dt!="undefined"){$(this).css("background",c);if(Date.now()-this.dt>1000)b.btnClick(a,true);else b.btnClick(a,false);return false}}).bind("mouseleave",function(e){if(typeof this.dt!="undefined"){$(this).css("background",c);this.dt=null}}).click(function(){return false})}sb("up");sb("down");sb("start");sb("enter");$("#btn-hint").hide()},btnIndex:-1,buttons:function(a){if(a==this.btnIndex)return;this.btnIndex=a;var b=(typeof ButtonLabels[a]=="undefined")?{u:"",d:"",s:"",e:"",i:""}:ButtonLabels[a];$("#btn-up").text(b.u);$("#btn-down").text(b.d);$("#btn-start").text(b.s);$("#btn-enter").text(b.e);$("#info").text(b.i)}};var BM={setting_url:"settings.php",automation_url:"automation.php",saveauto_url:"saveauto.php",ssavesetting_url:"savesettings.php",button_url:"button.php",status_url:"status.php",runningTime:0,timer:null,settings:{},s_settingS:{},auto:{},s_auto:{},celius:true,state:-1,hopN:0,updatingSetting:false,updatingRecipe:false,stageMap:[],conbroken:true,wdt:null,eventHdlr:{},addHandler:function(a,f){if(typeof this.eventHdlr[a]=="undefined")this.eventHdlr[a]=[];this.eventHdlr[a].push(f)},bc:{up:1,down:2,start:4,enter:8,home:3},sendButton:function(k,l,d){var e=this.bc[k]+((l)?16:0);$.ajax({url:this.button_url+"?code="+e,type:"GET",success:function(){d()},error:function(a,b,c){console.log(c)},})},getsetting:function(){var o=this;$.ajax({url:this.setting_url+"?time="+((new Date()).getTime()/1000),type:"GET",dataType:"json",success:function(a){if(a.code==0){o.proc_settings(a.data)}},error:function(a,b,c){console.log(c)},})},savesetting:function(d){this.s_settings=d;var b=this;this.updatingSetting=true;$.ajax({url:this.ssavesetting_url,type:"POST",data:{data:JSON.stringify(d)},success:function(){if(b.updatingSetting)b.startRecoveryTimer()},error:function(a,c,d){alert("error save setting, server response:"+d);b.finishSettingSave(false)}})},unitSetting:function(u){var t=this;var c=(u==0);if(c!=t.celius){t.celius=c;BMSetting.unitCelius(c);BMRecipe.unitCelius(c);BMScreen.unitCelius(c);if(typeof t.eventHdlr["tempunit"]!="undefined")$.each(t.eventHdlr["tempunit"],function(i,f){f(c)})}},proc_settings:function(s){this.settings=s;if("s_unit"in s){this.unitSetting(s["s_unit"])}if("sensors"in s){BMScreen.multisensor(s["sensors"].length,s["primary"],s["auxiliary"]);BMSetting.multisensor(s["sensors"].length)}if(("s_spenable"in s)&&s["s_spenable"]!=0)BMScreen.swh(true,s.s_sptempctrl,s.s_spsensor);else BMScreen.swh(false);BMSetting.setting(s)},getauto:function(){var b=this;$.ajax({url:this.automation_url,type:"GET",dataType:"json",success:function(a){if(a.code==0){b.procRecipe(a.data)}},error:function(a,b,c){console.log(c)},})},procRecipe:function(d){this.auto=d;BMRecipe.updateRecipe(d)},saveRecipe:function(d){this.s_auto=d;var b=this;b.updatingRecipe=true;$.ajax({url:b.saveauto_url,type:"POST",data:{data:JSON.stringify(d)},success:function(){if(b.updatingRecipe)b.startRecoveryTimer()},error:function(a,c,d){b.finishSaveRecipe(false);alert("Error saving automation, server response:"+d)}})},stateChangeHdlr:[],addStateChangeHdlr:function(f){this.stateChangeHdlr.push(f)},bmstate:function(s){var t=this;if(t.state==s)return;if(t.state==-1){if(typeof this.auto.boil=="undefined"){t.getsetting();t.getauto()}}if(s==101){if(!(t.updatingSetting||t.updatingRecipe)){BMRecipe.setEnabled(true);BMSetting.setEnabled(true)}}else{BMRecipe.setEnabled(false);BMSetting.setEnabled(false)}if(s>=0&&s<=11){BMScreen.setScreen("A",s);if(s==11)BMScreen.settingtemp(BM.auto.rest_tp[0]);else t.autostage(s)}else{if(s==100){BMScreen.setScreen("M")}else if(s==101){BMScreen.setScreen("I");t.stopRunningTime();BMScreen.clearTime()}else if(s==102){BMScreen.setScreen("S");t.stopRunningTime();BMScreen.clearTime()}else if(s==103){BMScreen.setScreen("T");BMScreen.clearTime()}else if(s<0){BMScreen.setScreen("U");t.stopRunningTime();BMScreen.clearTime()}}t.state=s;if(typeof t.eventHdlr["state"]!="undefined")$.each(t.eventHdlr["state"],function(i,f){f(s,s==101)})},stopRunningTime:function(){if(this.timer)clearInterval(this.timer);this.timer=null},refTime:0,countDir:0,calTime:function(){var t=this.runningTime+this.countDir*Math.round((Date.now()-this.refTime)/1000);return(t<0)?0:t},startRunningTime:function(t){b=this;b.runningTime=t;if(isNaN(t))return;b.refTime=Date.now();b.timer=setInterval(function(){BMScreen.displaytime(b.calTime())},1000)},checkRunningTime:function(t){var a=this.calTime();if((a-t)>5||(a-t)<-5){this.stopRunningTime();this.startRunningTime(t)}},finishSaveRecipe:function(a){this.stopRecoveryTimer();this.updatingRecipe=false;BMRecipe.finishSaveRecipe(a)},finishSettingSave:function(a){this.stopRecoveryTimer();this.updatingSetting=false;BMSetting.finishSaving(a)},recoveryTimout:null,stopRecoveryTimer:function(){if(this.recoveryTimout){clearTimeout(this.recoveryTimout);this.recoveryTimout=null}},startRecoveryTimer:function(){var b=this;b.recoveryTimout=setTimeout(function(){b.recoveryTimout=null;alert("Update failed, check connections");if(b.updatingRecipe)b.finishSaveRecipe(false);if(b.updatingSetting)b.finishSettingSave(false)},10000)},init:function(){BMScreen.init(this);BMSetting.init(this);BMRecipe.init(this);this.getsetting();this.getauto();this.setupEvent()},timerControl:function(r,t,c,p){var b=this;b.countDir=(c==0)?-1:1;if(!p){if(b.timer==null){b.startRunningTime(t)}else{b.checkRunningTime(t)}}else{if(b.timer)b.stopRunningTime();if(r&&b.state<=8&&b.state>0){BMScreen.displaytime(t)}else if(b.state<8&&b.state>0){BMScreen.displaytime(b.auto.rest_tm[b.state]*60)}else if(b.state==8){BMScreen.displaytime(BM.auto.boil*60)}else{BMScreen.clearTime()}}},updateData:function(v){if(v=="recipe"){if(this.updatingRecipe){this.auto=this.s_auto;this.finishSaveRecipe(true)}else{this.getauto()}}else if(v=="setting"){var b=this;if(b.updatingSetting){$.each(b.s_settings,function(k,v){b.settings[k]=v;if(k=="s_unit")b.unitSetting(v)});b.finishSettingSave(true)}else{b.getsetting()}}},errorCode:function(a){this.bmstate(-1);BMScreen.error("s_disc")},watchdog:function(){var b=this;b.wdt=setTimeout(function(){location.reload()},20000)},kick_wdt:function(){if(this.wdt)clearTimeout(this.wdt);this.watchdog()},p_msg:function(e){var b=this;var a=JSON.parse(e);var c={pump:function(v){BMScreen.pumpStatus(v)},heat:function(v){BMScreen.heatStatus(v)},spgw:function(v){BMScreen.spargeStatus(v)},temp:function(v){BMScreen.currenttemp(v)},temps:function(v){BMScreen.alltemps(v)},stemp:function(v){BMScreen.settingtemp(v)},event:function(v){b.brewevent(v)},pwm:function(v){BMScreen.pwmValue(v)},pwmon:function(v){BMScreen.setPwmOn(v==1)},update:function(v){b.updateData(v)},code:function(v){b.errorCode(v)},btn:function(v){BMScreen.buttons(v)}};$.each(a,function(k,v){if(typeof(c[k])!="undefined"){c[k](v)}});if(typeof(a["tr"])!="undefined"&&typeof(a["timer"])!="undefined"&&typeof(a["state"])!="undefined"){b.timerControl(a["tr"],a["timer"],a["counting"],a["paused"]);b.bmstate(a["state"]);b.autoProgressBytime(a["tr"],a["state"],a["timer"])}},setupEvent:function(){var b=this;if(typeof EventSource==="undefined"){alert("Incompatible Browser!");return}var a=new EventSource(BM.status_url);a.onerror=function(){b.ssebroken=true;setTimeout(function(){if(b.ssebroken)BMScreen.error("disc")},5000)};a.onmessage=function(e){b.kick_wdt();b.ssebroken=false;b.p_msg(e.data)}},brewevent:function(e){var b=this;if(e==5&&b.timer)b.stopRunningTime();if(e==1){if(b.state>0&&b.state<8)b.startRunningTime(b.auto.rest_tm[b.state]*60);else if(b.state==8)b.startRunningTime(b.auto.boil*60)}b.autoProgressByevent(e);BMScreen.brewevent(e)},log:function(s){var d=new Date();$(""+d.toLocaleTimeString()+""+s+"").appendTo("#log-t")},autoAllStages:function(){var a=[];var b=0;for(i=0;i<8;i++){if(this.auto.rest_tm[i]>0||i==0){a.push({type:"mash",stage:i,temp:BM.auto.rest_tp[i],time:BM.auto.rest_tm[i]});this.stageMap[i]=b++}if(i==0){a.push({type:"event",name:"addmalt"});b++}}a.push({type:"event",name:"removemalt"});b++;a.push({type:"boil",time:BM.auto.boil});this.stageMap[8]=b++;$.each(BM.auto.hops,function(i,h){a.push({type:"hop",index:i,time:h});b++});a.push({type:"event",name:"boilend"});b++;a.push({type:"event",name:"cooling"});this.stageMap[9]=b++;this.hopN=0;return a},autostage:function(s){BMScreen.inStage(this.stageMap[s]);if(s<8){BMScreen.settingtemp(BM.auto.rest_tp[s]);if(s==0)BMScreen.clearTime();else BMScreen.displaytime(BM.auto.rest_tm[s]*60)}else if(s==8){BMScreen.settingtemp(BM.settings.s_boil);BMScreen.displaytime(BM.auto.boil*60)}else if(s==9){BMScreen.settingtemp(20)}},autoProgressByevent:function(e){if(e==2){BMScreen.inStage(1)}else if(e==3){BMScreen.inStage(BM.stageMap[7]+1)}else if(e==10){BMScreen.inStage(BM.stageMap[9])}},autoProgressBytime:function(a,b,c){if(!a||b!=8)return;if(c==0)c=this.auto.boil*60;var i=this.hopN;for(;ithis.auto.hops[i]*60){break}}if(i!=this.hopN){this.hopN=i;BMScreen.inStage(BM.stageMap[8]+i+1)}}};var NetworkConfig={url:"netcfg.php",host:"bm",secured:false,update:function(){var n=this;var u={};var h=$.trim($("#hostname").val());if(h!==n.host)u["host"]=h;var c=$("#protected").is(":checked");if(c!=n.secured)u["secured"]=c?1:0;var d=$.trim($("#newusername").val());if(d!=="")u["nuser"]=d;var e=$.trim($("#newpasswd").val());if(e!=="")u["npass"]=e;u["user"]=$.trim($("#username").val());u["pass"]=$("#password").val();console.log("update:"+JSON.stringify(u));$.ajax({url:n.url,type:"POST",data:{data:JSON.stringify(u)},success:function(){$("#saveok").show()},error:function(a,b,c){$("#savefail").show();console.log("Error saving automation, server response:"+c)}})},getcfg:function(){var n=this;$.ajax({url:n.url,type:"GET",dataType:"json",success:function(a){n.host=a.host;n.secured=(a.secured!=0);n.inputs()},error:function(a,b,c){n.inputs();console.log(c)}})},discnet:function(){var n=this;var u={};u["user"]=$.trim($("#username").val());u["pass"]=$("#password").val();u["disconnect"]=true;console.log("disconnect wifi:"+JSON.stringify(u));$.ajax({url:n.url,type:"POST",data:{data:JSON.stringify(u)},success:function(){alert("Network disconnect")},error:function(a,b,c){alert("error");console.log("Error saving automation, server response:"+c)}})},chkpass:function(){if($("#newpasswd").val()===$("#newpasswd2").val()){$("#passmatch").hide();$("#savecfg").button("option","disabled",false)}else{$("#passmatch").show();$("#savecfg").button("option","disabled",true)}},verify:function(){if($.trim($("#username").val())!==""&&$.trim($("#password").val())!==""){$("#savecfg").button("option","disabled",false);$("#wifidisc").show()}else{$("#savecfg").button("option","disabled",true);$("#wifidisc").hide()}$("#saveok").hide();$("#savefail").hide()},vchange:function(){$("#saveok").hide();$("#savefail").hide();$("#savecfg").show()},inputs:function(){var n=this;$("#passmatch").hide();$("#hostname").val(n.host).change(function(){n.vchange()});$("#protected").attr("checked",n.secured).change(function(){n.vchange()});$("#newusername").change(function(){n.vchange()});$("#newpasswd").change(function(){n.vchange();n.chkpass()});$("#newpasswd2").change(function(){n.chkpass()});$("#username").change(function(){n.verify()});$("#password").change(function(){n.verify()});$("#savecfg").button({disabled:true}).click(function(){n.update()}).hide();$("#wifidisc").button().click(function(){n.discnet()}).hide();$("#saveok").hide();$("#savefail").hide()},init:function(){this.getcfg()},};var BChart={offset:0,url:'chart.php',reqdata:function(){var t=this;var b='offset='+t.offset;var c=new XMLHttpRequest();c.open('GET',t.url+'?'+b);c.responseType='arraybuffer';c.onload=function(e){var a=new Uint8Array(this.response);if(a.length==0){console.log("zero content");if(t.timer)clearInterval(t.timer);t.timer=null;setTimeout(function(){t.reqdata()},3000);return}t.chart.process(a);t.offset+=a.length;if(t.timer==null)t.settimer()};c.send()},settimer:function(){var t=this;t.timer=setInterval(function(){t.reqdata()},t.chart.interval*1000)},init:function(a){this.chart=new BrewChart(a)},timer:null,pull:function(){},setCelius:function(a){this.chart.setCelius(a)},setYLabel:function(a){this.chart.ylabel(a)},start:function(){if(this.running)return;this.running=true;this.offset=0;this.chart.clear();this.reqdata();$("#tchart").show()},stop:function(){if(!this.running)return;this.running=false;if(this.timer){clearInterval(this.timer);this.timer=null}$("#tchart").hide()}};var Logs={url:"logs.php",dl:"dl",init:function(){var t=this;this.row=$("#loglist").find("tr:nth-of-type(2)");this.row.remove();$("#listfile").button().button("option","icons",{primary:"ui-icon-arrowrefresh-1-e"}).click(function(){t.getlist()});$("#vchart").hide();t.chart=new BrewChart("vchart-canvas")},view:function(b,c){$("#vchart").show();$("#viewlogname").text(b+"@"+c.toLocaleString());var t=this;t.chart.clear();t.chart.setCelius(BM.celius);var d=new XMLHttpRequest();d.open('GET',t.url+"?"+t.dl+"="+b);d.responseType='arraybuffer';d.onload=function(e){var a=new Uint8Array(this.response);if(a.length==0){console.log("zero content");return}t.chart.realtime=true;t.chart.process(a)};d.oerror=function(e){console.log("error")};d.send()},process:function(e){var f=$("#loglist").find("tbody");var g=this.row;var t=this;$.each(e,function(i,a){var b=('000'+a.f).slice(-4);var c=new Date(a.t*1000);var d=g.clone();d.find(".logid").text(b);d.find(".logdate").text(c.toLocaleString());d.find(".dlbutton").button().button("option","icons",{primary:"ui-icon-disk"}).click(function(){window.open(t.url+"?"+t.dl+"="+b)});d.find(".viewbutton").button().button("option","icons",{primary:"ui-icon-circle-zoomout"}).click(function(){t.view(b,c)});f.append(d)})},getlist:function(){var t=this;$.ajax({url:t.url,type:"GET",dataType:"json",success:function(a){$("#loglist tr:gt(0)").remove();t.process(a)},error:function(a,b,c){console.log("Error:"+c)}})}};var BrewMath={plato2sg:function(a){return 1+a/(258.6-((a/258.2)*227.1))},sgTempCorrected:function(a,F,b){return a*((1.00130346-0.000134722124*F+0.00000204052596*F*F-0.00000000232820948*F*F*F)/(1.00130346-0.000134722124*b+0.00000204052596*b*b-0.00000000232820948*b*b*b))},brix2sg:function(a,b){b=(typeof b==="undefined")?1.0:b;var c=a/b;return(c/(258.6-((c/258.2)*227.1)))+1}};var BrewUtils={ciWeightUnit:"WEIGHT_U",ciVolumeUnit:"VOLUME_U",ciTempUnit:"TEMPERATURE_U",ciTC:"HydroCorrected",ciWC:"RefractoWortCorrect",u_vol:'L',u_weight:'M',u_temp:'C',did:null,VolFactor:{L:{L:1,G:0.264172052,Q:1.05668821},G:{L:3.78541178,G:1,Q:4},Q:{L:0.946352946,G:0.25,Q:1}},volume_unit:function(u){var a=(u=='L')?'L':((u=='G')?'gal':'qt');$(this.did).find(".vol_u").text(a);var b=this.VolFactor[this.u_vol][u];this.u_vol=u;setCookie(this.ciVolumeUnit,u,365);$(this.did).find(".volinput").each(function(){var v=$(this).val();if(v){v=(v*b);$(this).val(v.toFixed(2))}})},weight_unit:function(u){var a=(u=='M')?'kg':'lb';$(this.did).find(".weight_u").text(a);var b=(this.u_weight==u)?1:((u=='M')?0.45359237:2.20462262);this.u_weight=u;setCookie(this.ciWeightUnit,u,365);if(b==1)return;$(this.did).find(".weightinput").each(function(){var v=$(this).val();if(v){v=(v*b);$(this).val(v.toFixed(2))}})},temp_unit:function(u){if(this.u_temp==u)return;var a=(u=='C')?'°C':'°F';$(".tmp_u").text(a);this.u_temp=u;setCookie(this.ciTempUnit,u,365);function C2F(c){return c*1.8+32}function F2C(f){return(f-32)/1.8}var b=(u=='C')?F2C:C2F;$(this.did).find(".tempinput").each(function(){var v=$(this).val();if(v){v=b(v);$(this).val(v.toFixed(1))}})},init:function(f){var t=this;t.did=f;var v=getCookie(t.ciVolumeUnit);v=(v)?v:t.u_vol;$(f).find("[name=volume_unit]").val([v]);t.volume_unit(v);var w=getCookie(t.ciWeightUnit);w=(w)?w:t.u_weight;$(f).find("[name=weight_unit]").val([w]);t.weight_unit(w);var T=getCookie(t.ciTempUnit);T=(T)?T:t.u_temp;$(f).find("[name=temp_unit]").val([T]);t.temp_unit(T);var h=getCookie(t.ciWC);if(h)$(f).find(".REFRACTO .wortcorrection").val(h);var i=getCookie(t.ciTC);if(i){var j=i.split(',');var k=j[0];if(j[1]!=t.u_temp){k=(j[1]=='C')?(k*1.8+32):((k-32)/1.8)}$(f).find(".HYDROMETER .correctedTemp").val(k)}$(f).find('input[type="radio"]').change(function(){var a=$(this).attr('name');var b=$(this).val();if($(this).prop('checked')){t[a](b)}});$(f).find('.fwsg').change(function(){var a=$(f).find(".FWSG .grain").val();var b=$(f).find(".FWSG .water").val();if(a&&b){a=(t.u_weight=='M')?a:(a*0.45359237);b=t.VolFactor[t.u_vol].L*b;var c=(a*0.8)/(a*0.8+b);var d=BrewMath.plato2sg(c*100).toFixed(3);$(f).find(".FWSG .result").text(d)}});$(f).find('.hydroinput').change(function(){var a=$(f).find(".HYDROMETER .sgfraction").val();var b=$(f).find(".HYDROMETER .sgtemp").val();var c=$(f).find(".HYDROMETER .correctedTemp").val();if(c)setCookie(t.ciTC,c+","+t.u_temp,365);if(a&&b&&c){var F=(t.u_temp=='C')?(b*1.8+32):b;var d=(t.u_temp=='C')?(c*1.8+32):c;var e=BrewMath.sgTempCorrected(a,F,d);$(f).find(".HYDROMETER .result").text(e.toFixed(3));window.latestSG=e}});$(f).find('.brixinput').change(function(){var a=$(f).find(".REFRACTO .brixreading").val();var b=$(f).find(".REFRACTO .wortcorrection").val();if(b)setCookie(t.ciWC,b,365);if(a){b=(b)?b:1;var c=BrewMath.brix2sg(a,b);$(f).find(".REFRACTO .result").text(c.toFixed(3));window.latestSG=c}});$(f).find('.boiloffinput').change(function(){var a=$(f).find('.BOILOFF .sg').val();var b=$(f).find('.BOILOFF .vol').val();var c=$(f).find('.BOILOFF .newsg').val();var d=$(f).find('.BOILOFF .newvol').val();if(a&&b&&c){var v=(a-1)*b/(c-1);$(f).find(".BOILOFF .resultvol").text(v.toFixed(2))}if(a&&b&&d){var g=(a-1)*b/d+1;$(f).find(".BOILOFF .resultsg").text(g.toFixed(3))}})}};function XDTV(a,b,c){var d=a.getElementsByTagName(b)return(d.length>0)?d[0].textContent:c}function BeerStyle(a){this.dom=a;this.name=XDTV(a,"NAME","");this.categoryNumber=XDTV(a,"CATEGORY_NUMBER","");this.styleLetter=XDTV(a,"STYLE_LETTER","");var b=this.categoryNumber+this.styleLetter;this.comName=(b=="")?this.name:(b+"-"+this.name)}function BeerRecipe(e){this.dom=e;this.asXml=function(a){a=(typeof a=="undefined")?false:a;var s=new XMLSerializer();var b=s.serializeToString(e);if(a)b="\n\n"+b+"\n";return b};this.boilTime=parseInt(XDTV(e,"BOIL_TIME",0));this.style=(e.getElementsByTagName("STYLE").length>0)?(new BeerStyle(e.getElementsByTagName("STYLE")[0])):0;this.name=XDTV(e,"NAME","Unknown");this.batchSize=parseFloat(XDTV(e,"BATCH_SIZE",0));this.spargeTemp=parseFloat(XDTV(e,"SPARGE_TEMP",0));this.eff=parseFloat(XDTV(e,"EFFICIENCY",0));this.og=parseFloat(XDTV(e,"OG",0));this.fg=parseFloat(XDTV(e,"FG",0));this.abv=parseFloat(XDTV(e,"ABV",0));this.ibu=parseFloat(XDTV(e,"IBU",0));this.notes=XDTV(e,"NOTES",0);this.est_color=parseFloat(XDTV(e,"EST_COLOR",0));this.est_og=parseFloat(XDTV(e,"EST_OG",0));this.est_fg=parseFloat(XDTV(e,"EST_FG",0));this.est_abv=parseFloat(XDTV(e,"EST_ABV",0));this.est_ibu=parseFloat(XDTV(e,"EST_IBU",0));this.getValue=function(a){if(this[a])return this[a];if(this["est_"+a])return this["est_"+a];return false};this.ferm_stage=parseInt(XDTV(e,"FERMENTATION_STAGES",0));var g=["PRIMARY","SECONDARY","TERTIARY"];this.fstages=[];for(var i=0;i40)i=40;return a[i]},show:function(a){this.bmAuto={rest_tm:[],rest_tp:[],boil:0,hops:[]};this.recipe=a;this.showFermentables(a.fermentables);this.showHopMisc(a.hops,a.miscs);this.showMash(this.processMash(a.mashes));this.showFermetationStage(a.fstages);this.showYeasts(a.yeasts);$(this.div).find(".boil-time").text(a.boilTime+this.u_min);$(this.div).find(".recipe-name").text(a.name);var b=this.opt.metric?a.batchSize.toFixed(2):this.toGallon(a.batchSize).toFixed(2);$(this.div).find(".batch-size").text(b+(this.opt.metric?this.u_l:this.u_gal));if(a.style)$(this.div).find(".recipe-style").text(a.style.comName);var c=a.getValue("og");if(c)$(this.div).find(".recipe-og").text(c.toFixed(3));var d=a.getValue("fg");if(d)$(this.div).find(".recipe-fg").text(d.toFixed(3));var e=a.getValue("abv");if(e)$(this.div).find(".recipe-abv").text(e.toFixed(1));var f=a.getValue("ibu");if(f)$(this.div).find(".recipe-ibu").text(f.toFixed(1));if(a.eff)$(this.div).find(".recipe-eff").text(a.eff);if(a.est_color)$(this.div).find(".recipe-color").text(a.est_color);if(a.notes)$(this.div).find(".recipe-note").text(a.notes);$(this.div).find(".color-block").css("background-color",this.srmColor(a.est_color));this.bmAuto.boil=a.boilTime},setCelius:function(a){this.celius=a;if(typeof this.recipe!="undefined"){$(this.div).find("tr.mash-row").remove();this.showMash(this.processMash(recipe.mashes))}},showFermentables:function(d){var t=this;var e=$(t.div).find("tr.ferm-header");$.each(d,function(k,v){var a=$(t.fermrow).clone(true);a.find("td.ferm-name").text(v.name);var b=t.opt.metric?v.amount:t.toLb(v.amount);a.find("td.ferm-weight").text(b.toFixed(2)+(t.opt.metric?t.u_kg:t.u_lb));a.find("td.ferm-yield").text(t.ppg?Math.round(46.177*v.yield/100):(v.yield+"%"));a.find("td.ferm-color").text(v.color+t.u_Lovibond);if(v.afterBoil||typeof v.note!="undefined"){var c=v.afterBoil?"After Boil.":"";if(typeof v.note!="undefined")c=c+" "+v.note;a.find("td.ferm-af").text(c)}e.after(a);e=a})},showHopMisc:function(f,g){var t=this;var j=[];var k=[];function pickboil(i,h){if(h.use.toLowerCase()=="boil")j.push(h);else k.push(h)}$.each(f,pickboil);$.each(g,pickboil);j.sort(function(a,b){return b.time-a.time});var l=[];var m=[];var n;$.each(j,function(i,v){if(m.length==0){n=v;m.push(v)}else if(n.time==v.time){m.push(v)}else{l.push(m);m=[v];n=v}});if(m.length)l.push(m);var o=$(t.div).find("tr.hop-header");var p=1;$.each(l,function(i,d){var e=true;$.each(d,function(i,h){var a=$(t.hoprow).clone(true);var b=false;if(e){e=false;a.find("td.hop-time").attr("rowspan",d.length).text(d[0].time+t.u_min);a.find("td.hop-order").attr("rowspan",d.length);if(d[0].time>0)b=true}else{a.find("td.hop-time").remove();a.find("td.hop-order").remove()}if(b){t.bmAuto.hops.push(d[0].time);a.find("td.hop-order").append("Hop#"+p+"");p++}a.find("td.hop-name").text(h.name);var c=t.opt.metric?(h.amount*1000):t.toOz(h.amount);a.find("td.hop-weight").text(c.toFixed(2)+(t.opt.metric?t.u_g:t.u_oz));if(typeof h["alpha"]!="undefined")a.find("td.hop-alpha").text(h.alpha+"%");else a.find("td.hop-note").text(h.type);o.after(a);o=a})});$.each(k,function(i,h){var a=$(t.hoprow).clone(true);a.find("td.hop-name").text(h.name);var b=t.opt.metric?(h.amount*1000):t.toOz(h.amount);a.find("td.hop-weight").text(b.toFixed(2)+(t.opt.metric?t.u_g:t.u_oz));if(typeof h["alpha"]!="undefined")a.find("td.hop-alpha").text(h.alpha+"%");a.find("td.hop-note").text(h.use);o.after(a);o=a})},getStrikeTemp:function(a){if(this.opt.doughIn=='c'&&typeof this.recipe.mashes[0].amount!="undefined"&&!isNaN(this.recipe.mashes[0].amount)&&this.recipe.mashes[0].amount>0){var b=this.recipe.mashGrain();return 0.41727029593*b/this.recipe.mashes[0].amount*(a-this.opt.grainTemp)+a+this.opt.equipAdjust}else if(this.opt.doughIn=='s'&&typeof this.opt.doughInTemp!="undefined"){return this.opt.doughInTemp}return a},processMash:function(a){if(a.length==0)return[];var b=this.getStrikeTemp(a[0].temp);var c={aname:"Mash In",name:"",temp:b};var d=[c];var e;if(a[a.length-1].temp>=75){e=true;a[a.length-1].aname="Mash Out"}else e=false;var f=1;$.each(a,function(k,v){if(!e||k<(a.length-1))v.aname="Mash Step "+f;f++;d.push(v)});if(!e)d.push({aname:"Mash Out",temp:this.opt.MashOutTemp,time:this.opt.MashOutTime});if(d.length>8){var g=d.pop();d.slice(0,6);d.push(g)}return d},showYeasts:function(d){var t=this;var e=$(t.div).find("tr.yeast-header");$.each(d,function(k,v){var a=$(t.yeastrow).clone(true);a.find(".yeast-name").text(v.name);a.find(".yeast-pid").text(v.lab+" "+v.pid);a.find(".yeast-att").text(v.attenuation);var b=t.celius?v.mintemp:t.toFahrenheit(v.mintemp);var c=t.celius?v.maxtemp:t.toFahrenheit(v.maxtemp);a.find(".yeast-temp").html(b.toFixed(1)+" ~ "+c.toFixed(1)+(t.celius?t.u_c:t.u_f));e.after(a);e=a})},showFermetationStage:function(c){var t=this;var d=$(t.div).find("tr.fermstage-header");var e=["Primary","Secondary","Additional"];$.each(c,function(k,v){var a=$(t.stagerow).clone(true);a.find(".ferm-stage").text(e[k]);var b=t.celius?v.temp:t.toFahrenheit(v.temp);a.find(".ferm-temp").html(b.toFixed(1)+(t.celius?t.u_c:t.u_f));a.find(".ferm-time").text(v.time.toFixed(1));d.after(a);d=a})},showMash:function(d){var t=this;var e=$(t.div).find("tr.mash-header");$.each(d,function(k,v){var a=$(t.mashrow).clone(true);a.find("td.mash-autorest").append(""+v.aname+"");a.find("td.mash-name").text(v.name);var b=t.celius?v.temp:t.toFahrenheit(v.temp);a.find("td.mash-temp").html(b.toFixed(1)+(t.celius?t.u_c:t.u_f));t.bmAuto.rest_tp.push(v.temp);if(!isNaN(v.time)){a.find("td.mash-time").text(v.time+t.u_min);t.bmAuto.rest_tm.push(v.time)}else{t.bmAuto.rest_tm.push(1)}if(typeof v.type!="undefined")a.find("td.mash-type").text(v.type);if(v.amount>0){var c=t.opt.metric?v.amount:t.toQt(v.amount);a.find("td.mash-water").text(c.toFixed(2)+(t.opt.metric?t.u_l:t.u_qt))}e.after(a);e=a});if(t.bmAuto.rest_tm.length<8){var f=t.bmAuto.rest_tm.pop();var g=t.bmAuto.rest_tp.pop();var h=7-t.bmAuto.rest_tm.length;for(;h>0;h--){t.bmAuto.rest_tm.push(0);t.bmAuto.rest_tp.push(0)}t.bmAuto.rest_tm.push(f);t.bmAuto.rest_tp.push(g)}}};var Recipes={prefUrl:"userpref.cfg",lsUrl:"list.php",recipeUrlBase:"R/",ulUrl:"upfile.php",rmUrl:"rm.php",celius:true,userPreference:{"metric":true,"MashOutTemp":77.2,"MashOutTime":10,"doughIn":"c","grainTemp":20,"doughInTemp":55,"equipAdjust":0},importing:-1,list:[],loaded:false,bmidle:true,load:function(){if(Recipes.loaded)return;Recipes.loaded=true;Recipes.getInfo()},cache:[],upload:function(b,c,d,e,f){var g=new FormData();var h=new Blob([c],{type:d});g.append("file",h,b);var i=new XMLHttpRequest();i.open("POST",Recipes.ulUrl);i.send(g);i.onload=function(a){if(i.status==200){if(e)e()}else{if(f)f(i,i.status);else console.log("failed:"+i.status)}}},view:function(c){this.viewing=c.substring("recipe-list-".length);var d=this.recipeUrlBase+this.viewing;if(typeof Recipes.cache[d]!="undefined"){var e=new BeerXML(Recipes.cache[d]);Recipes.showRecipe(e.recipe(0),true)}else{$.ajax({method:"GET",url:d,}).done(function(a){Recipes.cache[d]=a;var b=new BeerXML(a);Recipes.showRecipe(b.recipe(0),true)})}},bmstate:function(a){this.bmidle=a;if(!this.viewing||!this.viewing.brewable())return;if(Recipes.pane=="import")$("#xml-brew").button("option","disabled",a?false:true);else $("#recipe-brew").button("option","disabled",a?false:true)},viewing:null,showRecipe:function(r,a){a=(typeof a=="undefined")?false:a;this.viewing=r;if(r){if(a){if(r.brewable()){$("#recipe-brew").button("option","disabled",Recipes.bmidle?false:true)}else{$("#recipe-brew").button("option","disabled",true)}}else{if(r.brewable()){$("#xml-save").button("option","disabled",false);$("#xml-brew").button("option","disabled",Recipes.bmidle?false:true)}else{$("#xml-save").button("option","disabled",true);$("#xml-brew").button("option","disabled",true)}}RecipeDisplay.clear();RecipeDisplay.show(r);$("#recipe-table").show()}else{jAlert("Invalid BeerXML!");$("#recipe-table").hide();$("#xml-save").button("option","disabled",true);$("#xml-brew").button("option","disabled",true)}},validFileName:function(){var f=$("#xml-savename").val().trim();if(f.search(/[^\w\d-_]/)>=0)return false;return f},xmlName:function(n){var a=n.replace(/\s/g,'').replace(/[\[\]\/\\\?%\*:|\"<>!\.]/g,'_');var b=a;var c=1;while($.inArray(a,Recipes.list)>=0){a=b+"_"+c;c++}$("#xml-savename").val(a)},xmlSelect:function(e){var a=$(e.target).find("option:selected")[0].value;Recipes.importing=a;var r=Recipes.beerxml.recipe(a);Recipes.xmlName(r.name);Recipes.showRecipe(r)},openfile:function(f){if(f){var r=new FileReader();r.onload=function(e){window.file=f;Recipes.beerxml=new BeerXML(e.target.result);$('#xml-recipe-select').empty();var a=Recipes.beerxml.recipeNames();$.each(a,function(i,n){$('#xml-recipe-select').append($(""))});Recipes.importing=0;if(a.length>0)Recipes.xmlName(a[0]);Recipes.showRecipe(Recipes.beerxml.recipe(0))};r.readAsText(f)}else{$('#xml-recipe-select').empty();Recipes.importing=-1}},prefSup:false,prefChanged:function(){if(this.prefSup)return;$("#recipe-option-update").show();RecipeDisplay.option(Recipes.userPreference)},updateUserPref:function(){$("#recipe-option-update").button("option","disabled",true);var c=JSON.stringify(Recipes.userPreference);Recipes.upload(Recipes.prefUrl,c,"text/plain",function(){$("#recipe-option-update").button("option","disabled",false).hide()},function(a,b){jAlert("Failed to update:"+b);$("#recipe-option-update").button("option","disabled",false)})},brewXml:function(){var a=RecipeDisplay.getAuto();console.log(a);BM.saveRecipe(a)},saveXml:function(){if(Recipes.importing<0||typeof Recipes.beerxml=="undefined")return;var f=Recipes.validFileName();if(!f){jAlert("Invalid name!");return}function doSave(){var a=Recipes.beerxml.recipe(Recipes.importing);var b=Recipes.recipeUrlBase+f;Recipes.upload(b,a.asXml(true),"text/xml",function(){Recipes.addRecipe(f,a.asXml(true))},function(x,s){jAlert("Error saving recipe:"+s)})}if($.inArray(f,Recipes.list)>=0){jConfirm({title:"Replace existing recipe?",msg:"The existing recipe will be replaced.",ok:"Replace",onok:function(){doSave()}})}else doSave()},delRecipe:function(){var t=this;var r=t.viewing;function rmList(){var a=$.inArray(r,Recipes.list);if(a<0){console.log("error condition")}Recipes.list.splice(a,1);$("#recipe-list-"+r).remove()}$.ajax({url:t.rmUrl,type:"POST",data:{file:t.recipeUrlBase+r},success:function(){rmList()},error:function(a,b,c){jAlert("Error delete recipe:"+c)}})},dispPreference:function(){this.prefSup=true;var a=(Recipes.userPreference.metric)?"m":"u";$("input[name=genunit][value="+a+"]").prop('checked',true);$("input[name=mashin_temp][value="+Recipes.userPreference.doughIn+"]").prop('checked',true);Recipes.mashinInput(Recipes.userPreference.doughIn);var b=(this.celius)?Recipes.userPreference.grainTemp:C2F(Recipes.userPreference.grainTemp);$("#grain-temp").spinner("value",b);var c=(this.celius)?Recipes.userPreference.equipAdjust:(1.8*Recipes.userPreference.equipAdjust);$("#equip-adj").spinner("value",c);var d=(this.celius)?Recipes.userPreference.doughInTemp:C2F(Recipes.userPreference.doughInTemp);$("#mashin-stemp").spinner("value",d);var e=(this.celius)?Recipes.userPreference.MashOutTemp:C2F(Recipes.userPreference.MashOutTemp);$("#mo-temp").spinner("value",e);$("#mo-time").spinner("value",Recipes.userPreference.MashOutTime);this.prefSup=false},mashinInput:function(v){function inputdis(g,e,s){$("#grain-temp").spinner("option","disabled",g);$("#equip-adj").spinner("option","disabled",e);$("#mashin-stemp").spinner("option","disabled",s)}if(v=='c')inputdis(false,false,true);else if(v=='s')inputdis(true,true,false);else inputdis(true,true,true)},initPreference:function(){$("input[type=radio][name=genunit]").change(function(){if(this.value=='m'){Recipes.userPreference.metric=true}else{Recipes.userPreference.metric=false}Recipes.prefChanged()});$("#grain-temp").spinner({step:0.1,change:function(){var v=$("#grain-temp").spinner("value");Recipes.userPreference.grainTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("#equip-adj").spinner({step:0.1,change:function(){var v=$("#equip-adj").spinner("value");Recipes.userPreference.equipAdjust=Recipes.celius?v:v/1.8;Recipes.prefChanged()}});$("#mashin-stemp").spinner({step:0.1,change:function(){var v=$("#mashin-stemp").spinner("value");Recipes.userPreference.doughInTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("input[type=radio][name=mashin_temp]").change(function(){Recipes.userPreference.doughIn=this.value;Recipes.mashinInput(this.value);Recipes.prefChanged()});$("#mo-temp").spinner({step:0.1,change:function(){var v=$("#mo-temp").spinner("value");Recipes.userPreference.MashOutTemp=Recipes.celius?v:F2C(v);Recipes.prefChanged()}});$("#mo-time").spinner({change:function(){Recipes.userPreference.MashOutTime=$("#mo-time").spinner("value");Recipes.prefChanged()}});$("#recipe-option-update").button().click(function(){Recipes.updateUserPref()}).hide()},unitChanged:function(a){Recipes.celius=a;RecipeDisplay.setCelius(a);Recipes.dispPreference()},addRecipe:function(f,a){if($.inArray(f,Recipes.list)<0){Recipes.list.push(f);$("#recipe-list").append("
  • "+f+"
  • ")}Recipes.cache[Recipes.recipeUrlBase+f]=a},updateList:function(){$.each(Recipes.list,function(k,v){$("#recipe-list").append("
  • "+v+"
  • ")})},getList:function(){$.ajax({method:"POST",data:{dir:Recipes.recipeUrlBase},url:Recipes.lsUrl,}).done(function(a){Recipes.list=a;Recipes.updateList()})},getInfo:function(){$.ajax({method:"GET",url:Recipes.prefUrl,}).done(function(a){Recipes.userPreference=JSON.parse(a);RecipeDisplay.option(Recipes.userPreference)}).always(function(){Recipes.dispPreference();Recipes.getList()})},init:function(){$("#recipe-options-panel").hide();$("#recipe-import-panel").hide();$("#recipe-view-panel").hide();$("#recipe-table").hide();Recipes.initPreference();BM.addHandler("tempunit",function(c){Recipes.unitChanged(c)});BM.addHandler("state",function(s,i){Recipes.bmstate(i)});window.menuselected.recipes=function(){Recipes.load()};Recipes.pane="";$("#recipe-list").selectable({element:null,selected:function(a,b){element=$(b.selected)},stop:function(a,b){element.siblings().removeClass("selected");if(element[0].id=="recipe-options"){$("#recipe-options-panel").show();$("#recipe-import-panel").hide();$("#recipe-view-panel").hide();$("#recipe-table").hide();Recipes.pane="options"}else if(element[0].id=="recipe-import"){$("#recipe-options-panel").hide();$("#recipe-import-panel").show();$("#recipe-view-panel").hide();if(Recipes.importing>=0&&typeof Recipes.beerxml!="undefined")Recipes.showRecipe(Recipes.beerxml.recipe(Recipes.importing));else $("#recipe-table").hide();Recipes.pane="import"}else{$("#recipe-options-panel").hide();$("#recipe-import-panel").hide();$("#recipe-view-panel").show();Recipes.view(element[0].id);Recipes.pane="view"}}});RecipeDisplay.init("#xml-recipe",Recipes.userPreference);$('#xml-recipe-select').change(function(e){Recipes.xmlSelect(e)});$("#fileinput").change(function(a){var f=a.target.files[0];Recipes.openfile(f)});$("#xml-save").button({"disabled":true}).click(function(){Recipes.saveXml()});$("#xml-brew").button({"disabled":true}).click(function(){Recipes.brewXml()});$("#recipe-del").button().click(function(){Recipes.delRecipe()});$("#recipe-brew").button().click(function(){Recipes.brewXml()})}}; \ No newline at end of file