29 var newSwitch = false; |
29 var newSwitch = false; |
30 var newProfile = false; |
30 var newProfile = false; |
31 var yl = 12; // Normal yeast temp range |
31 var yl = 12; // Normal yeast temp range |
32 var yh = 24; |
32 var yh = 24; |
33 |
33 |
|
34 var productSource = { |
|
35 datatype: "json", |
|
36 cache: false, |
|
37 datafields: [ |
|
38 { name: 'code', type: 'string' }, |
|
39 { name: 'name', type: 'string' }, |
|
40 { name: 'stage', type: 'string' }, |
|
41 ], |
|
42 id: 'code', |
|
43 url: "includes/db_product.php?select=ferment" |
|
44 }; |
|
45 var productlist = new $.jqx.dataAdapter(productSource); |
|
46 $("#select_beer").jqxDropDownList({ |
|
47 placeHolder: "Kies bier:", |
|
48 theme: theme, |
|
49 source: productlist, |
|
50 displayMember: "code", |
|
51 width: 150, |
|
52 height: 23, |
|
53 dropDownWidth: 500, |
|
54 autoDropDownHeight: true, |
|
55 renderer: function (index, label, value) { |
|
56 var datarecord = productlist.records[index]; |
|
57 return datarecord.code + " - " + datarecord.name; |
|
58 } |
|
59 }); |
|
60 |
34 var gaugeoptions = { |
61 var gaugeoptions = { |
35 min: 0, max: 40, width: 375, height: 375, |
62 min: 0, max: 40, width: 375, height: 375, |
36 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
63 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
37 { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
64 { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
38 { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
65 { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
95 $("#target_hi").jqxNumberInput( targetoptions ); |
122 $("#target_hi").jqxNumberInput( targetoptions ); |
96 |
123 |
97 function sendBase(stage, mode, tlo, thi) { |
124 function sendBase(stage, mode, tlo, thi) { |
98 |
125 |
99 console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); |
126 console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); |
100 var data = 'node=rpi01&alias=unit0&payload={"stage":"'+stage; |
127 var data = 'node='+record.node+'&alias='+record.alias+'&payload={"stage":"'+stage; |
101 data += '","mode":"'+mode+'","setpoint":{"low":'+tlo+',"high":'+thi+'}}'; |
128 data += '","mode":"'+mode+'","setpoint":{"low":'+tlo+',"high":'+thi+'}}'; |
102 $.ajax({ |
129 $.ajax({ |
103 url: "cmd_fermenter.php", |
130 url: "cmd_fermenter.php", |
104 data: data, |
131 data: data, |
105 type: "POST", |
132 type: "POST", |
106 success: function(data) { |
133 success: function(data) { |
107 //do something after something is recieved from php |
134 //do something after something is received from php |
|
135 }, |
|
136 error: function(jqXHR, textStatus, errorThrown) { |
|
137 console.log("sendBase() error"); |
|
138 } |
|
139 }); |
|
140 } |
|
141 |
|
142 function sendSwitch(sw1, sw2, sw3, sw4) { |
|
143 |
|
144 console.log("sendSwitch("+sw1+", "+sw2+", "+sw3+", "+sw4+")"); |
|
145 var data = 'node='+record.node+'&alias='+record.alias+'&payload='; |
|
146 data += '{"heater":{"state":'+sw1+'},"cooler":{"state":'+sw2+'},"fan":{"state":'+sw3+'},"light":{"state":'+sw4+'}}'; |
|
147 $.ajax({ |
|
148 url: "cmd_fermenter.php", |
|
149 data: data, |
|
150 type: "POST", |
|
151 success: function(data) { |
|
152 //do something after something is received from php |
|
153 }, |
|
154 error: function(jqXHR, textStatus, errorThrown) { |
|
155 console.log("sendBase() error"); |
|
156 } |
|
157 }); |
|
158 } |
|
159 |
|
160 function sendProduct(code, name) { |
|
161 |
|
162 console.log("sendProduct("+code+", "+name+")"); |
|
163 var data = 'node='+record.node+'&alias='+record.alias+'&payload='; |
|
164 data += '{"product":{"code":"'+code+'","name":"'+name+'"}}'; |
|
165 $.ajax({ |
|
166 url: "cmd_fermenter.php", |
|
167 data: data, |
|
168 type: "POST", |
|
169 success: function(data) { |
|
170 //do something after something is received from php |
108 }, |
171 }, |
109 error: function(jqXHR, textStatus, errorThrown) { |
172 error: function(jqXHR, textStatus, errorThrown) { |
110 console.log("sendBase() error"); |
173 console.log("sendBase() error"); |
111 } |
174 } |
112 }); |
175 }); |
163 $("#info_uuid").html(record.uuid); |
226 $("#info_uuid").html(record.uuid); |
164 $("#info_system").html(record.node + "/" + record.alias + " " + oline); |
227 $("#info_system").html(record.node + "/" + record.alias + " " + oline); |
165 $("#info_beer").html(record.beercode + " - " + record.beername); |
228 $("#info_beer").html(record.beercode + " - " + record.beername); |
166 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
229 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
167 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
230 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
|
231 $("#info_profile").html(record.profile_name); |
|
232 if (record.profile_name == "") |
|
233 $("#info_mode").jqxDropDownList('disableItem', "PROFILE"); |
|
234 else |
|
235 $("#info_mode").jqxDropDownList('enableItem', "PROFILE"); |
168 $("#target_lo").val(record.setpoint_low); |
236 $("#target_lo").val(record.setpoint_low); |
169 $("#target_hi").val(record.setpoint_high); |
237 $("#target_hi").val(record.setpoint_high); |
170 if (record.online && ((record.mode == "FRIDGE") || (record.mode == "BEER"))) { |
238 if (record.online && ((record.mode == "FRIDGE") || (record.mode == "BEER"))) { |
171 $("#target_lo").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
239 $("#target_lo").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
172 $("#target_hi").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
240 $("#target_hi").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
175 $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
243 $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
176 } |
244 } |
177 |
245 |
178 if (record.online && (record.mode != "OFF")) { |
246 if (record.online && (record.mode != "OFF")) { |
179 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
247 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
|
248 $("#select_beer").jqxDropDownList({ disabled: true }); |
|
249 $("#select_beer").jqxDropDownList('clearSelection'); |
180 } else { |
250 } else { |
181 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
251 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
|
252 $("#select_beer").jqxDropDownList({ disabled: false }); |
182 } |
253 } |
183 if (record.online && (record.alarm != "0")) { |
254 if (record.online && (record.alarm != "0")) { |
184 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
255 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
185 } else { |
256 } else { |
186 $("#fermenter_alarmled").html('<div class="LEDred_off"></div>Alarm'); |
257 $("#fermenter_alarmled").html('<div class="LEDred_off"></div>Alarm'); |
238 }); |
309 }); |
239 |
310 |
240 // Get the data immediatly and then at regular intervals to refresh. |
311 // Get the data immediatly and then at regular intervals to refresh. |
241 dataAdapter.dataBind(); |
312 dataAdapter.dataBind(); |
242 setInterval(function() { |
313 setInterval(function() { |
|
314 var skip = false; |
243 if (newBase) { |
315 if (newBase) { |
244 sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high); |
316 sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high); |
245 newBase = false; |
317 newBase = false; |
246 } |
318 skip = true; |
247 dataAdapter.dataBind(); |
319 } |
|
320 if (newSwitch) { |
|
321 sendSwitch(record.heater_state, record.cooler_state, record.fan_state, record.light_state); |
|
322 newSwitch = false; |
|
323 skip = true; |
|
324 } |
|
325 if (newProduct) { |
|
326 sendProduct(record.code, record.name); |
|
327 newProduct = false; |
|
328 skip = true; |
|
329 } |
|
330 |
|
331 if (! skip) { |
|
332 // Only if we didn't send a command so that a command can be processed. |
|
333 dataAdapter.dataBind(); |
|
334 } |
248 }, 10000); |
335 }, 10000); |
249 |
336 |
250 $('#info_mode').on('change', function (event) { |
337 $('#info_mode').on('change', function (event) { |
251 record.mode = args.item.value; |
338 record.mode = args.item.value; |
|
339 $("#fermenter_toggle1").val(0); |
|
340 $("#fermenter_toggle2").val(0); |
|
341 $("#fermenter_toggle3").val(0); |
252 newBase = true; |
342 newBase = true; |
253 }); |
343 }); |
254 $('#info_stage').on('change', function (event) { |
344 $('#info_stage').on('select', function (event) { |
255 record.stage = args.item.value; |
345 record.stage = args.item.value; |
256 newBase = true; |
346 newBase = true; |
257 }); |
347 }); |
|
348 $("#select_beer").on('select', function (event) { |
|
349 if (event.args) { |
|
350 var index = event.args.index; |
|
351 var datarecord = productlist.records[index]; |
|
352 record.code = datarecord.code; |
|
353 record.name = datarecord.name; |
|
354 newProduct = true; |
|
355 } |
|
356 }); |
|
357 |
258 $('#target_lo').on('change', function (event) { |
358 $('#target_lo').on('change', function (event) { |
259 record.setpoint_low = parseFloat(event.args.value); |
359 record.setpoint_low = parseFloat(event.args.value); |
260 // Keep the high target above the low. |
360 // Keep the high target above the low. |
261 if (record.setpoint_low > (record.setpoint_high - 0.2)) { |
361 if (record.setpoint_low > record.setpoint_high) { |
262 record.setpoint_high = record.setpoint_low + 0.2; |
362 record.setpoint_high = record.setpoint_low; |
263 $("#target_hi").val(record.setpoint_high); |
363 $("#target_hi").val(record.setpoint_high); |
264 } |
364 } |
265 newBase = true; |
365 newBase = true; |
266 }); |
366 }); |
267 $('#target_hi').on('change', function (event) { |
367 $('#target_hi').on('change', function (event) { |
268 record.setpoint_high = parseFloat(event.args.value); |
368 record.setpoint_high = parseFloat(event.args.value); |
269 // Keep the low target below the high. |
369 // Keep the low target below the high. |
270 if (record.setpoint_high < (record.setpoint_low + 0.2)) { |
370 if (record.setpoint_high < record.setpoint_low) { |
271 record.setpoint_low = record.setpoint_high - 0.2; |
371 record.setpoint_low = record.setpoint_high; |
272 $("#target_lo").val(record.setpoint_low); |
372 $("#target_lo").val(record.setpoint_low); |
273 } |
373 } |
274 newBase = true; |
374 newBase = true; |
|
375 }); |
|
376 |
|
377 $("#fermenter_toggle1").on('checked', function (event) { |
|
378 if (record.mode == "NONE") { |
|
379 record.heater_state = 0; |
|
380 newSwitch = true; |
|
381 } |
|
382 }); |
|
383 $("#fermenter_toggle1").on('unchecked', function (event) { |
|
384 if (record.mode == "NONE") { |
|
385 record.heater_state = 100; |
|
386 record.cooler_state = 0; |
|
387 $("#fermenter_toggle2").val(0); |
|
388 newSwitch = true; |
|
389 } |
|
390 }); |
|
391 $("#fermenter_toggle2").on('checked', function (event) { |
|
392 if (record.mode == "NONE") { |
|
393 record.cooler_state = 0; |
|
394 newSwitch = true; |
|
395 } |
|
396 }); |
|
397 $("#fermenter_toggle2").on('unchecked', function (event) { |
|
398 if (record.mode == "NONE") { |
|
399 record.cooler_state = 100; |
|
400 record.heater_state = 0; |
|
401 $("#fermenter_toggle1").val(0); |
|
402 newSwitch = true; |
|
403 } |
|
404 }); |
|
405 $("#fermenter_toggle3").on('checked', function (event) { |
|
406 if (record.mode == "NONE") { |
|
407 record.fan_state = 0; |
|
408 newSwitch = true; |
|
409 } |
|
410 }); |
|
411 $("#fermenter_toggle3").on('unchecked', function (event) { |
|
412 if (record.mode == "NONE") { |
|
413 record.fan_state = 100; |
|
414 newSwitch = true; |
|
415 } |
275 }); |
416 }); |
276 |
417 |
277 |
418 |
278 // The chart button. |
419 // The chart button. |
279 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); |
420 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); |