21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 |
23 |
24 $(document).ready(function () { |
24 $(document).ready(function () { |
25 |
25 |
26 var bname = ''; |
26 var record = {}; |
27 var bcode = ''; |
27 var newBase = false; |
|
28 var newProduct = false; |
|
29 var newSwitch = false; |
|
30 var newProfile = false; |
28 var yl = 12; // Normal yeast temp range |
31 var yl = 12; // Normal yeast temp range |
29 var yh = 24; |
32 var yh = 24; |
30 var bstage = ''; |
|
31 var bmode = ''; |
|
32 |
33 |
33 var gaugeoptions = { |
34 var gaugeoptions = { |
34 min: 0, max: 40, width: 375, height: 375, |
35 min: 0, max: 40, width: 375, height: 375, |
35 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
36 ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
36 { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
37 { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
55 value: 0, |
56 value: 0, |
56 colorScheme: 'scheme05', |
57 colorScheme: 'scheme05', |
57 animationDuration: 1200, |
58 animationDuration: 1200, |
58 caption: { value: 'Chiller', position: 'bottom', offset: [0, 10] } |
59 caption: { value: 'Chiller', position: 'bottom', offset: [0, 10] } |
59 }; |
60 }; |
|
61 $("#gaugeContainer_air").jqxGauge( gaugeoptions ); |
|
62 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: 00.000' }} ); |
|
63 $("#gaugeContainer_beer").jqxGauge( gaugeoptions ); |
|
64 $("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer: 00.000' }} ); |
|
65 $("#gaugeContainer_chiller").jqxGauge( gaugeSmalloptions ); |
|
66 |
60 var switchoptions = { |
67 var switchoptions = { |
61 height: 68, |
68 height: 68, |
62 width: 35, |
69 width: 35, |
63 theme: theme, |
70 theme: theme, |
64 thumbSize:'50%', |
71 thumbSize:'50%', |
65 orientation: 'vertical' |
72 orientation: 'vertical' |
66 }; |
73 }; |
67 |
|
68 srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ]; |
|
69 srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ]; |
|
70 $("#gaugeContainer_air").jqxGauge( gaugeoptions ); |
|
71 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air', position: 'bottom', offset: [0, 10] }} ); |
|
72 $("#gaugeContainer_beer").jqxGauge( gaugeoptions ); |
|
73 $("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer', position: 'bottom', offset: [0, 10] }} ); |
|
74 $("#gaugeContainer_chiller").jqxGauge( gaugeSmalloptions ); |
|
75 $("#fermenter_toggle1").jqxSwitchButton( switchoptions ); |
74 $("#fermenter_toggle1").jqxSwitchButton( switchoptions ); |
76 $("#fermenter_toggle2").jqxSwitchButton( switchoptions ); |
75 $("#fermenter_toggle2").jqxSwitchButton( switchoptions ); |
77 $("#fermenter_toggle3").jqxSwitchButton( switchoptions ); |
76 $("#fermenter_toggle3").jqxSwitchButton( switchoptions ); |
78 |
77 |
|
78 srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ]; |
|
79 srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ]; |
79 $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 23, dropDownHeight: 156 }); |
80 $("#info_mode").jqxDropDownList({ theme: theme, source: srcMode, width: 100, height: 23, dropDownHeight: 156 }); |
80 $("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 23, dropDownHeight: 125 }); |
81 $("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 23, dropDownHeight: 125 }); |
81 |
82 |
82 function sendBase(stage, mode) { |
83 var targetoptions = { |
83 |
84 inputMode: 'simple', |
84 console.log("sendBase("+stage+", "+mode+")"); |
85 spinMode: 'simple', |
85 var data = 'node=rpi01&alias=unit0&payload={"stage":"' + stage; |
86 theme: theme, |
86 data += '","mode":"' + mode + '","setpoint":{"low":17.8,"high":18.2}}'; |
87 width: 70, |
|
88 height: 23, |
|
89 min:0, max: 40, |
|
90 decimalDigits: 1, |
|
91 spinButtons: true, |
|
92 spinButtonsStep: 0.1 |
|
93 }; |
|
94 $("#target_lo").jqxNumberInput( targetoptions ); |
|
95 $("#target_hi").jqxNumberInput( targetoptions ); |
|
96 |
|
97 function sendBase(stage, mode, tlo, thi) { |
|
98 |
|
99 console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")"); |
|
100 var data = 'node=rpi01&alias=unit0&payload={"stage":"'+stage; |
|
101 data += '","mode":"'+mode+'","setpoint":{"low":'+tlo+',"high":'+thi+'}}'; |
87 $.ajax({ |
102 $.ajax({ |
88 url: "cmd_fermenter.php", |
103 url: "cmd_fermenter.php", |
89 data: data, |
104 data: data, |
90 type: "POST", |
105 type: "POST", |
91 success: function(data) { |
106 success: function(data) { |
141 url: url |
156 url: url |
142 }; |
157 }; |
143 |
158 |
144 var dataAdapter = new $.jqx.dataAdapter(source, { |
159 var dataAdapter = new $.jqx.dataAdapter(source, { |
145 loadComplete: function (records) { |
160 loadComplete: function (records) { |
146 var record = dataAdapter.records[0]; |
161 record = dataAdapter.records[0]; |
147 var oline = (record.online) ? "On-line" : "Off-line"; |
162 var oline = (record.online) ? "On-line" : "Off-line"; |
148 $("#info_uuid").html(record.uuid); |
163 $("#info_uuid").html(record.uuid); |
149 $("#info_system").html(record.node + "/" + record.alias + " " + oline); |
164 $("#info_system").html(record.node + "/" + record.alias + " " + oline); |
150 $("#info_beer").html(record.beercode + " - " + record.beername); |
165 $("#info_beer").html(record.beercode + " - " + record.beername); |
151 bcode = record.beercode; |
|
152 bname = record.beername; |
|
153 bstage = record.stage; |
|
154 bmode = record.mode; |
|
155 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
166 $("#info_mode").jqxDropDownList('selectItem', record.mode); |
156 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
167 $("#info_stage").jqxDropDownList('selectItem', record.stage); |
|
168 $("#target_lo").val(record.setpoint_low); |
|
169 $("#target_hi").val(record.setpoint_high); |
|
170 if (record.online && ((record.mode == "FRIDGE") || (record.mode == "BEER"))) { |
|
171 $("#target_lo").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
|
172 $("#target_hi").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true }); |
|
173 } else { |
|
174 $("#target_lo").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
|
175 $("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false }); |
|
176 } |
157 |
177 |
158 if (record.online && (record.mode != "OFF")) { |
178 if (record.online && (record.mode != "OFF")) { |
159 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
179 $("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power'); |
160 } else { |
180 } else { |
161 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
181 $("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power'); |
163 if (record.online && (record.alarm != "0")) { |
183 if (record.online && (record.alarm != "0")) { |
164 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
184 $("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
165 } else { |
185 } else { |
166 $("#fermenter_alarmled").html('<div class="LEDred_off"></div>Alarm'); |
186 $("#fermenter_alarmled").html('<div class="LEDred_off"></div>Alarm'); |
167 } |
187 } |
168 |
|
169 $("#target_lo").html(record.setpoint_low.toFixed(1)); |
|
170 $("#target_hi").html(record.setpoint_high.toFixed(1)); |
|
171 $("#load_air").html(record.air_temperature.toFixed(3)); |
|
172 $("#load_beer").html(record.beer_temperature.toFixed(3)); |
|
173 |
188 |
174 if (record.online && (record.heater_state != "0")) { |
189 if (record.online && (record.heater_state != "0")) { |
175 $("#fermenter_led1").html('<div class="LEDgreen_on"></div>Heat'); |
190 $("#fermenter_led1").html('<div class="LEDgreen_on"></div>Heat'); |
176 } else { |
191 } else { |
177 $("#fermenter_led1").html('<div class="LEDgreen_off"></div>Heat'); |
192 $("#fermenter_led1").html('<div class="LEDgreen_off"></div>Heat'); |
197 $("#fermenter_toggle1").val( (record.heater_state != "0") ); |
212 $("#fermenter_toggle1").val( (record.heater_state != "0") ); |
198 $("#fermenter_toggle2").val( (record.cooler_state != "0") ); |
213 $("#fermenter_toggle2").val( (record.cooler_state != "0") ); |
199 $("#fermenter_toggle3").val( (record.fan_state != "0") ); |
214 $("#fermenter_toggle3").val( (record.fan_state != "0") ); |
200 } |
215 } |
201 |
216 |
|
217 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: '+record.air_temperature.toFixed(3) }}); |
202 $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); |
218 $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature }); |
203 if (record.online && (record.air_state == "OK")) { |
219 if (record.online && (record.air_state == "OK")) { |
204 $("#gaugeContainer_air").jqxGauge({ disabled: false }); |
220 $("#gaugeContainer_air").jqxGauge({ disabled: false }); |
205 } else { |
221 } else { |
206 $("#gaugeContainer_air").jqxGauge({ disabled: true }); |
222 $("#gaugeContainer_air").jqxGauge({ disabled: true }); |
207 } |
223 } |
|
224 $("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer: '+record.beer_temperature.toFixed(3) }}); |
208 $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature }); |
225 $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature }); |
209 if (record.online && (record.beer_state == "OK")) { |
226 if (record.online && (record.beer_state == "OK")) { |
210 $("#gaugeContainer_beer").jqxGauge({ disabled: false }); |
227 $("#gaugeContainer_beer").jqxGauge({ disabled: false }); |
211 } else { |
228 } else { |
212 $("#gaugeContainer_beer").jqxGauge({ disabled: true }); |
229 $("#gaugeContainer_beer").jqxGauge({ disabled: true }); |
220 } |
237 } |
221 }); |
238 }); |
222 |
239 |
223 // Get the data immediatly and then at regular intervals to refresh. |
240 // Get the data immediatly and then at regular intervals to refresh. |
224 dataAdapter.dataBind(); |
241 dataAdapter.dataBind(); |
225 setInterval(function(){ |
242 setInterval(function() { |
|
243 if (newBase) { |
|
244 sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high); |
|
245 newBase = false; |
|
246 } |
226 dataAdapter.dataBind(); |
247 dataAdapter.dataBind(); |
227 }, 10000); |
248 }, 10000); |
228 |
249 |
229 $('#info_mode').on('change', function (event) { |
250 $('#info_mode').on('change', function (event) { |
230 sendBase(bstage, args.item.value); |
251 record.mode = args.item.value; |
|
252 newBase = true; |
231 }); |
253 }); |
232 $('#info_stage').on('change', function (event) { |
254 $('#info_stage').on('change', function (event) { |
233 sendBase(args.item.value, bmode); |
255 record.stage = args.item.value; |
|
256 newBase = true; |
|
257 }); |
|
258 $('#target_lo').on('change', function (event) { |
|
259 record.setpoint_low = parseFloat(event.args.value); |
|
260 // Keep the high target above the low. |
|
261 if (record.setpoint_low > (record.setpoint_high - 0.2)) { |
|
262 record.setpoint_high = record.setpoint_low + 0.2; |
|
263 $("#target_hi").val(record.setpoint_high); |
|
264 } |
|
265 newBase = true; |
|
266 }); |
|
267 $('#target_hi').on('change', function (event) { |
|
268 record.setpoint_high = parseFloat(event.args.value); |
|
269 // Keep the low target below the high. |
|
270 if (record.setpoint_high < (record.setpoint_low + 0.2)) { |
|
271 record.setpoint_low = record.setpoint_high - 0.2; |
|
272 $("#target_lo").val(record.setpoint_low); |
|
273 } |
|
274 newBase = true; |
234 }); |
275 }); |
235 |
276 |
236 |
277 |
237 // The chart button. |
278 // The chart button. |
238 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); |
279 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme }); |
239 $("#FLog").click(function () { |
280 $("#FLog").click(function () { |
240 var url="log_fermentation.php?code=" + bcode + "&name=" + bname; |
281 var url="log_fermentation.php?code=" + record.beercode + "&name=" + record.beername; |
241 window.open(url); |
282 window.open(url); |
242 }); |
283 }); |
243 }); |
284 }); |