66 placeHolder: "Kies bier:", |
67 placeHolder: "Kies bier:", |
67 theme: theme, |
68 theme: theme, |
68 source: productlist, |
69 source: productlist, |
69 displayMember: "code", |
70 displayMember: "code", |
70 width: 150, |
71 width: 150, |
71 height: 23, |
72 height: 24, |
72 dropDownWidth: 500, |
73 dropDownWidth: 500, |
73 autoDropDownHeight: true, |
74 autoDropDownHeight: true, |
74 renderer: function (index, label, value) { |
75 renderer: function (index, label, value) { |
75 var datarecord = productlist.records[index]; |
76 var datarecord = productlist.records[index]; |
76 return datarecord.code + " - " + datarecord.name; |
77 return datarecord.code + " - " + datarecord.name; |
77 } |
78 } |
|
79 }); |
|
80 |
|
81 var profileSource = { |
|
82 datatype: "json", |
|
83 cache: false, |
|
84 datafields: [ |
|
85 { name: 'record', type: 'int' }, |
|
86 { name: 'uuid', type: 'string' }, |
|
87 { name: 'name', type: 'string' }, |
|
88 { name: 'inittemp_lo', type: 'float' }, |
|
89 { name: 'inittemp_hi', type: 'float' }, |
|
90 { name: 'fridgemode', type: 'int' }, |
|
91 { name: 'totalsteps', type: 'int' }, |
|
92 { name: 'duration', type: 'int' }, |
|
93 { name: 'steps', type: 'array' } |
|
94 ], |
|
95 id: 'record', |
|
96 url: "includes/db_profile_fermentation.php" |
|
97 }; |
|
98 var profilelist = new $.jqx.dataAdapter(profileSource, { |
|
99 beforeLoadComplete: function (records) { |
|
100 var data = new Array(); |
|
101 var empty = {}; |
|
102 // Create a dummy beer on top to store in idle fermenters. |
|
103 empty['record'] = -1; |
|
104 empty['uuid'] = ''; |
|
105 empty['name'] = 'Wis profiel'; |
|
106 empty['inittemp_lo'] = 20; |
|
107 empty['inittemp_hi'] = 20; |
|
108 empty['fridgemode'] = 0; |
|
109 empty['totalsteps'] = 0; |
|
110 empty['duration'] = 0; |
|
111 empty['steps'] = '[]'; |
|
112 data.push(empty); |
|
113 for (var i = 0; i < records.length; i++) { |
|
114 var row = records[i]; |
|
115 data.push(row); |
|
116 } |
|
117 return data; |
|
118 }, |
|
119 loadError: function(jqXHR, status, error) { |
|
120 $('#err').text(status + ' ' + error); |
|
121 }, |
|
122 }); |
|
123 $("#select_profile").jqxDropDownList({ |
|
124 placeHolder: "Kies profiel:", |
|
125 theme: theme, |
|
126 source: profilelist, |
|
127 displayMember: "name", |
|
128 width: 150, |
|
129 height: 24, |
|
130 dropDownWidth: 500, |
|
131 autoDropDownHeight: true, |
78 }); |
132 }); |
79 |
133 |
80 var gaugeoptions = { |
134 var gaugeoptions = { |
81 min: 0, max: 40, width: 375, height: 375, |
135 min: 0, max: 40, width: 375, height: 375, |
82 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
136 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
121 $("#fermenter_toggle2").jqxSwitchButton( switchoptions ); |
175 $("#fermenter_toggle2").jqxSwitchButton( switchoptions ); |
122 $("#fermenter_toggle3").jqxSwitchButton( switchoptions ); |
176 $("#fermenter_toggle3").jqxSwitchButton( switchoptions ); |
123 |
177 |
124 srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ]; |
178 srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ]; |
125 srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ]; |
179 srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ]; |
126 $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 23, dropDownHeight: 156 }); |
180 $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 156 }); |
127 $("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 23, dropDownHeight: 125 }); |
181 $("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 24, dropDownHeight: 125 }); |
128 |
182 |
129 var targetoptions = { |
183 var targetoptions = { |
130 inputMode: 'simple', |
184 inputMode: 'simple', |
131 spinMode: 'simple', |
185 spinMode: 'simple', |
132 theme: theme, |
186 theme: theme, |
133 width: 70, |
187 width: 70, |
134 height: 23, |
|
135 min:0, max: 40, |
188 min:0, max: 40, |
136 decimalDigits: 1, |
189 decimalDigits: 1, |
137 spinButtons: true, |
190 spinButtons: true, |
138 spinButtonsStep: 0.1 |
191 spinButtonsStep: 0.1 |
139 }; |
192 }; |
140 $("#target_lo").jqxNumberInput( targetoptions ); |
193 $("#target_lo").jqxNumberInput( targetoptions ); |
141 $("#target_hi").jqxNumberInput( targetoptions ); |
194 $("#target_hi").jqxNumberInput( targetoptions ); |
|
195 |
|
196 $("#Profile1").jqxButton({ template: "info", width: '150px', height: 24, theme: theme }); |
|
197 $("#Profile2").jqxButton({ template: "info", width: '150px', height: 24, theme: theme }); |
|
198 $("#Profile1").hide(); // Hide these until they are needed. |
|
199 $("#Profile2").hide(); |
142 |
200 |
143 function sendBase(stage, mode, tlo, thi) { |
201 function sendBase(stage, mode, tlo, thi) { |
144 |
202 |
145 console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); |
203 console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); |
146 var data = 'node='+record.node+'&alias='+record.alias+'&payload={"stage":"'+stage; |
204 var data = 'node='+record.node+'&alias='+record.alias+'&payload={"stage":"'+stage; |
179 function sendProduct(code, name) { |
237 function sendProduct(code, name) { |
180 |
238 |
181 console.log("sendProduct("+code+", "+name+")"); |
239 console.log("sendProduct("+code+", "+name+")"); |
182 var data = 'node='+record.node+'&alias='+record.alias+'&payload='; |
240 var data = 'node='+record.node+'&alias='+record.alias+'&payload='; |
183 data += '{"product":{"code":"'+code+'","name":"'+name+'"}}'; |
241 data += '{"product":{"code":"'+code+'","name":"'+name+'"}}'; |
|
242 $.ajax({ |
|
243 url: "cmd_fermenter.php", |
|
244 data: data, |
|
245 type: "POST", |
|
246 success: function(data) { |
|
247 //do something after something is received from php |
|
248 }, |
|
249 error: function(jqXHR, textStatus, errorThrown) { |
|
250 console.log("sendBase() error"); |
|
251 } |
|
252 }); |
|
253 } |
|
254 |
|
255 function sendProfile(payload) { |
|
256 |
|
257 console.log("sendProfile("+payload+")"); |
|
258 var data = 'node='+record.node+'&alias='+record.alias+'&payload='+payload; |
184 $.ajax({ |
259 $.ajax({ |
185 url: "cmd_fermenter.php", |
260 url: "cmd_fermenter.php", |
186 data: data, |
261 data: data, |
187 type: "POST", |
262 type: "POST", |
188 success: function(data) { |
263 success: function(data) { |
215 { name: 'heater_usage', type: 'int' }, |
290 { name: 'heater_usage', type: 'int' }, |
216 { name: 'cooler_state', type: 'int' }, |
291 { name: 'cooler_state', type: 'int' }, |
217 { name: 'cooler_usage', type: 'int' }, |
292 { name: 'cooler_usage', type: 'int' }, |
218 { name: 'fan_state', type: 'int' }, |
293 { name: 'fan_state', type: 'int' }, |
219 { name: 'fan_usage', type: 'int' }, |
294 { name: 'fan_usage', type: 'int' }, |
|
295 { name: 'light_address', type: 'string' }, |
220 { name: 'light_state', type: 'int' }, |
296 { name: 'light_state', type: 'int' }, |
221 { name: 'light_usage', type: 'int' }, |
297 { name: 'light_usage', type: 'int' }, |
|
298 { name: 'door_address', type: 'string' }, |
222 { name: 'door_state', type: 'int' }, |
299 { name: 'door_state', type: 'int' }, |
|
300 { name: 'psu_address', type: 'string' }, |
223 { name: 'psu_state', type: 'int' }, |
301 { name: 'psu_state', type: 'int' }, |
224 { name: 'mode', type: 'string' }, |
302 { name: 'mode', type: 'string' }, |
225 { name: 'alarm', type: 'int' }, |
303 { name: 'alarm', type: 'int' }, |
226 { name: 'setpoint_high', type: 'float' }, |
304 { name: 'setpoint_high', type: 'float' }, |
227 { name: 'setpoint_low', type: 'float' }, |
305 { name: 'setpoint_low', type: 'float' }, |
228 { name: 'profile_uuid', type: 'string' }, |
306 { name: 'profile_uuid', type: 'string' }, |
229 { name: 'profile_name', type: 'string' }, |
307 { name: 'profile_name', type: 'string' }, |
230 { name: 'profile_state', type: 'string' }, |
308 { name: 'profile_state', type: 'string' }, |
231 { name: 'profile_precent', type: 'int' }, |
309 { name: 'profile_percent', type: 'int' }, |
232 { name: 'profile_inittemp_high', type: 'float' }, |
310 { name: 'profile_inittemp_high', type: 'float' }, |
233 { name: 'profile_inittemp_low', type: 'float' }, |
311 { name: 'profile_inittemp_low', type: 'float' }, |
234 { name: 'profile_steps', type: 'string' }, |
312 { name: 'profile_steps', type: 'string' }, |
235 { name: 'stage', type: 'string' } |
313 { name: 'stage', type: 'string' } |
236 ], |
314 ], |
241 var dataAdapter = new $.jqx.dataAdapter(source, { |
319 var dataAdapter = new $.jqx.dataAdapter(source, { |
242 loadComplete: function (records) { |
320 loadComplete: function (records) { |
243 record = dataAdapter.records[0]; |
321 record = dataAdapter.records[0]; |
244 var oline = (record.online) ? "On-line" : "Off-line"; |
322 var oline = (record.online) ? "On-line" : "Off-line"; |
245 $("#info_uuid").html(record.uuid); |
323 $("#info_uuid").html(record.uuid); |
246 $("#info_system").html(record.node + "/" + record.alias + " " + oline); |
324 $("#info_system").html(record.node + "/" + record.alias); |
|
325 $("#info_online").html(oline); |
247 $("#info_beer").html(record.beercode + " - " + record.beername); |
326 $("#info_beer").html(record.beercode + " - " + record.beername); |
248 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
327 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
249 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
328 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
250 $("#info_profile").html(record.profile_name); |
329 $("#info_profile").html(record.profile_name); |
251 blank['name'] = record.alias; |
330 blank['name'] = record.alias; |
262 } else { |
341 } else { |
263 $("#target_lo").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
342 $("#target_lo").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
264 $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
343 $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
265 } |
344 } |
266 |
345 |
267 if (record.online && (record.door_state != "0")) { |
346 if (record.online && record.door_address && (record.door_state == "0")) { |
268 $("#fermenter_doorled").html('<div class="LEDyellow_on"></div>Door'); |
347 $("#fermenter_doorled").html('<div class="LEDyellow_on"></div>Door'); |
269 } else { |
348 } else { |
270 $("#fermenter_doorled").html('<div class="LEDyellow_off"></div>Door'); |
349 $("#fermenter_doorled").html('<div class="LEDyellow_off"></div>Door'); |
271 } |
350 } |
272 if (record.online && (record.light_state != "0")) { |
351 if (record.online && record.light_address && (record.light_state != "0")) { |
273 $("#fermenter_lightled").html('<div class="LEDyellow_on"></div>Light'); |
352 $("#fermenter_lightled").html('<div class="LEDyellow_on"></div>Light'); |
274 } else { |
353 } else { |
275 $("#fermenter_lightled").html('<div class="LEDyellow_off"></div>Light'); |
354 $("#fermenter_lightled").html('<div class="LEDyellow_off"></div>Light'); |
276 } |
355 } |
277 |
356 |
278 if (record.online && (record.mode != "OFF")) { |
357 if (record.online && (record.mode != "OFF")) { |
279 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
358 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
280 $("#select_beer").jqxDropDownList({ disabled: true }); |
359 $("#select_beer").jqxDropDownList({ disabled: true }); |
281 $("#select_beer").jqxDropDownList('clearSelection'); |
360 $("#select_beer").jqxDropDownList('clearSelection'); |
|
361 $("#select_beer").hide(); |
282 } else { |
362 } else { |
283 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
363 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
|
364 $("#select_beer").show(); |
284 $("#select_beer").jqxDropDownList({ disabled: false }); |
365 $("#select_beer").jqxDropDownList({ disabled: false }); |
285 } |
366 } |
286 if (record.online && (record.alarm != "0")) { |
367 if (record.online && (record.alarm != "0")) { |
287 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
368 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
288 } else { |
369 } else { |
313 $("#fermenter_toggle2").jqxSwitchButton( 'disable' ); |
394 $("#fermenter_toggle2").jqxSwitchButton( 'disable' ); |
314 $("#fermenter_toggle3").jqxSwitchButton( 'disable' ); |
395 $("#fermenter_toggle3").jqxSwitchButton( 'disable' ); |
315 $("#fermenter_toggle1").val( (record.heater_state != "0") ); |
396 $("#fermenter_toggle1").val( (record.heater_state != "0") ); |
316 $("#fermenter_toggle2").val( (record.cooler_state != "0") ); |
397 $("#fermenter_toggle2").val( (record.cooler_state != "0") ); |
317 $("#fermenter_toggle3").val( (record.fan_state != "0") ); |
398 $("#fermenter_toggle3").val( (record.fan_state != "0") ); |
|
399 } |
|
400 |
|
401 if (record.online && (record.mode == "PROFILE")) { |
|
402 if (record.profile_state == "OFF") { |
|
403 $("#select_profile").show(); |
|
404 $("#select_profile").jqxDropDownList({ disabled: false }); |
|
405 $("#info_mode").jqxDropDownList({ disabled: false }); |
|
406 $('#Profile1').jqxButton({ template: "success", value: "Starten" }); |
|
407 $("#Profile1").show(); |
|
408 $("#Profile2").hide(); |
|
409 $("#status_profile").html(''); |
|
410 } else if (record.profile_state == "RUN") { |
|
411 $("#select_profile").jqxDropDownList({ disabled: true }); |
|
412 $("#select_profile").hide(); |
|
413 $("#info_mode").jqxDropDownList({ disabled: true }); |
|
414 $('#Profile1').jqxButton({ template: "danger", value: "Afbreken" }); |
|
415 $('#Profile2').jqxButton({ template: "primary", value: "Pauze" }); |
|
416 $("#Profile1").show(); |
|
417 $("#Profile2").show(); |
|
418 $("#status_profile").html('Profiel actief, '+record.profile_percent+'% gereed'); |
|
419 } else if (record.profile_state == "PAUSE") { |
|
420 $("#select_profile").jqxDropDownList({ disabled: true }); |
|
421 $("#select_profile").hide(); |
|
422 $("#info_mode").jqxDropDownList({ disabled: true }); |
|
423 $('#Profile1').jqxButton({ template: "danger", value: "Afbreken" }); |
|
424 $('#Profile2').jqxButton({ template: "success", value: "Doorgaan" }); |
|
425 $("#Profile1").show(); |
|
426 $("#Profile2").show(); |
|
427 $("#status_profile").html('Profiel pauze, '+record.profile_percent+'% gereed'); |
|
428 } else if (record.profile_state == "DONE") { |
|
429 $("#select_profile").jqxDropDownList({ disabled: true }); |
|
430 $("#select_profile").hide(); |
|
431 $("#info_mode").jqxDropDownList({ disabled: true }); |
|
432 $('#Profile1').jqxButton({ template: "primary", value: "Profiel Ok" }); |
|
433 $("#Profile1").show(); |
|
434 $("#Profile2").hide(); |
|
435 $("#status_profile").html('Profiel is gereed'); |
|
436 } |
|
437 } else { |
|
438 $("#select_profile").show(); |
|
439 $("#select_profile").jqxDropDownList({ disabled: false }); |
|
440 $("#info_mode").jqxDropDownList({ disabled: false }); |
|
441 $("#Profile1").hide(); |
|
442 $("#Profile2").hide(); |
|
443 $("#status_profile").html(''); |
318 } |
444 } |
319 |
445 |
320 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: '+record.air_temperature.toFixed(3) }}); |
446 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: '+record.air_temperature.toFixed(3) }}); |
321 $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); |
447 $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); |
322 if (record.online && (record.air_state == "OK")) { |
448 if (record.online && (record.air_state == "OK")) { |
384 record.code = datarecord.code; |
521 record.code = datarecord.code; |
385 record.name = datarecord.name; |
522 record.name = datarecord.name; |
386 newProduct = true; |
523 newProduct = true; |
387 } |
524 } |
388 }); |
525 }); |
|
526 $("#select_profile").on('select', function (event) { |
|
527 if (event.args) { |
|
528 var index = event.args.index; |
|
529 var datarecord = profilelist.records[index]; |
|
530 if (datarecord.record == -1) { |
|
531 ppayload = '{"profile":null}'; |
|
532 } else { |
|
533 ppayload = '{"profile":{"uuid":"'+datarecord.uuid+'","name":"'+datarecord.name+'",'; |
|
534 ppayload += '"inittemp":{"low":'+datarecord.inittemp_lo+',"high":'+datarecord.inittemp_hi+'},'; |
|
535 ppayload += '"fridgemode":'+datarecord.fridgemode+',"steps":['; |
|
536 for (var i = 0; i < datarecord.steps.length; i++) { |
|
537 var row = datarecord.steps[i]; |
|
538 if (i > 0) |
|
539 ppayload += ','; |
|
540 ppayload += '{"steptime":'+row['steptime']+',"resttime":'+row['resttime']; |
|
541 ppayload += ',"target_lo":'+row['target_lo']+',"target_hi":'+row['target_hi']; |
|
542 ppayload += ',"fridgemode":'+row['fridgemode']+',"name":"'+row['name']+'"}'; |
|
543 } |
|
544 ppayload += ']}}'; |
|
545 } |
|
546 newProfile = true; |
|
547 } |
|
548 }); |
389 |
549 |
390 $('#target_lo').on('change', function (event) { |
550 $('#target_lo').on('change', function (event) { |
391 record.setpoint_low = parseFloat(event.args.value); |
551 record.setpoint_low = parseFloat(event.args.value); |
392 // Keep the high target above the low. |
552 // Keep the high target above the low. |
393 if (record.setpoint_low > record.setpoint_high) { |
553 if (record.setpoint_low > record.setpoint_high) { |
444 if (record.mode == "NONE") { |
604 if (record.mode == "NONE") { |
445 record.fan_state = 100; |
605 record.fan_state = 100; |
446 newSwitch = true; |
606 newSwitch = true; |
447 } |
607 } |
448 }); |
608 }); |
449 |
609 $("#Profile1").click(function () { |
|
610 if (record.mode == "PROFILE") { |
|
611 if (record.profile_state == "OFF") { |
|
612 ppayload = '{"profile":{"command":"start"}}'; |
|
613 newProfile = true; |
|
614 } else if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) { |
|
615 ppayload = '{"profile":{"command":"abort"}}'; |
|
616 newProfile = true; |
|
617 } else if (record.profile_state == "DONE") { |
|
618 ppayload = '{"profile":{"command":"done"}}'; |
|
619 newProfile = true; |
|
620 } |
|
621 } |
|
622 }); |
|
623 $("#Profile2").click(function () { |
|
624 if (record.mode == "PROFILE") { |
|
625 if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) { |
|
626 ppayload = '{"profile":{"command":"pause"}}'; |
|
627 newProfile = true; |
|
628 } |
|
629 } |
|
630 }); |
450 |
631 |
451 // The chart button. |
632 // The chart button. |
452 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); |
633 $("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme }); |
453 $("#FLog").click(function () { |
634 $("#FLog").click(function () { |
454 var url="log_fermentation.php?code=" + record.beercode + "&name=" + record.beername; |
635 var url="log_fermentation.php?code=" + record.beercode + "&name=" + record.beername; |
455 window.open(url); |
636 window.open(url); |
456 }); |
637 }); |
457 }); |
638 }); |