|
1 /***************************************************************************** |
|
2 * Copyright (C) 2019 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BMS |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * Brewery Management System istributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 |
|
24 $(document).ready(function () { |
|
25 |
|
26 var record = {}, |
|
27 blank = {}, |
|
28 newProduct = false, |
|
29 schedule = 0, |
|
30 |
|
31 productSource = { |
|
32 datatype: "json", |
|
33 cache: false, |
|
34 datafields: [ |
|
35 { name: 'code', type: 'string' }, |
|
36 { name: 'name', type: 'string' }, |
|
37 { name: 'uuid', type: 'string' } |
|
38 ], |
|
39 id: 'code', |
|
40 url: "includes/db_product.php?select=ferment" |
|
41 }, |
|
42 productlist = new $.jqx.dataAdapter(productSource, { |
|
43 beforeLoadComplete: function (records) { |
|
44 var row, i, data = new Array(); |
|
45 // Create a dummy beer on top to store in idle meters. |
|
46 blank['code'] = "Free"; // Will override this later. |
|
47 blank['name'] = 'Dummy'; |
|
48 blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5'; |
|
49 data.push(blank); |
|
50 for (i = 0; i < records.length; i++) { |
|
51 row = records[i]; |
|
52 data.push(row); |
|
53 } |
|
54 return data; |
|
55 }, |
|
56 loadError: function(jqXHR, status, error) { |
|
57 $('#err').text(status + ' ' + error); |
|
58 }, |
|
59 }), |
|
60 gaugeoptionst = { |
|
61 min: 10, max: 40, width: 375, height: 375, |
|
62 ranges: [{ startValue: 10, endValue: 20, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 }, |
|
63 { startValue: 20, endValue: 28, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
|
64 { startValue: 28, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
|
65 ticksMinor: { interval: 1, size: '5%' }, |
|
66 ticksMajor: { interval: 5, size: '9%' }, |
|
67 labels: { interval: 5 }, |
|
68 style: { fill: '#eeeeee', stroke: '#666666' }, |
|
69 value: 0, |
|
70 colorScheme: 'scheme05' |
|
71 }, |
|
72 gaugeoptionsp = { |
|
73 min: 0, max: 6, width: 375, height: 375, |
|
74 ranges: [{ startValue: 0, endValue: 3, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 }, |
|
75 { startValue: 3, endValue: 6, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }], |
|
76 ticksMinor: { interval: 0.2, size: '5%' }, |
|
77 ticksMajor: { interval: 1, size: '9%' }, |
|
78 labels: { interval: 1 }, |
|
79 style: { fill: '#eeeeee', stroke: '#666666' }, |
|
80 value: 0, |
|
81 colorScheme: 'scheme05' |
|
82 }, |
|
83 url = "getco2meter.php?uuid='" + my_uuid + "'", |
|
84 source = { |
|
85 datatype: "json", |
|
86 datafields: [ |
|
87 { name: 'record', type: 'int' }, |
|
88 { name: 'uuid', type: 'string' }, |
|
89 { name: 'alias', type: 'string' }, |
|
90 { name: 'node', type: 'string' }, |
|
91 { name: 'online', type: 'int' }, |
|
92 { name: 'beercode', type: 'string' }, |
|
93 { name: 'beername', type: 'string' }, |
|
94 { name: 'beeruuid', type: 'string' }, |
|
95 { name: 'mode', type: 'string' }, |
|
96 { name: 'alarm', type: 'int' }, |
|
97 { name: 'temperature_state', type: 'string' }, |
|
98 { name: 'temperature', type: 'float' }, |
|
99 { name: 'pressure_state', type: 'string' }, |
|
100 { name: 'pressure_bar', type: 'float' } |
|
101 ], |
|
102 id: 'record', |
|
103 url: url |
|
104 }, |
|
105 dataAdapter = new $.jqx.dataAdapter(source, { |
|
106 loadComplete: function (records) { |
|
107 record = dataAdapter.records[0]; |
|
108 var oline = (record.online) ? "On-line" : "Off-line"; |
|
109 $("#info_uuid").html(record.uuid); |
|
110 $("#info_system").html(record.node + "/" + record.alias); |
|
111 $("#info_online").html(oline); |
|
112 $("#info_beer").html(record.beercode + " - " + record.beername); |
|
113 $("#info_mode").html(record.mode); |
|
114 blank['name'] = record.alias; |
|
115 blank['code'] = record.alias.toUpperCase(); |
|
116 blank['uuid'] = record.uuid; |
|
117 |
|
118 if (record.online && (record.mode != "OFF")) { |
|
119 $("#co2meter_powerled").html('<div class="LEDblue_on"></div>Power'); |
|
120 $("#select_beer").jqxDropDownList({ disabled: true }); |
|
121 $("#select_beer").jqxDropDownList('clearSelection'); |
|
122 $("#select_beer").hide(); |
|
123 } else { |
|
124 $("#co2meter_powerled").html('<div class="LEDblue_off"></div>Power'); |
|
125 $("#select_beer").show(); |
|
126 $("#select_beer").jqxDropDownList({ disabled: false }); |
|
127 |
|
128 } |
|
129 if (record.online && (record.alarm != "0")) { |
|
130 $("#co2meter_alarmled").html('<div class="LEDred_on"></div>Alarm'); |
|
131 } else { |
|
132 $("#co2meter_alarmled").html('<div class="LEDred_off"></div>Alarm'); |
|
133 } |
|
134 |
|
135 $("#gaugeContainer_temperature").jqxGauge({ caption: { value: 'Temp: '+record.temperature.toFixed(3) }}); |
|
136 $('#gaugeContainer_temperature').jqxGauge({ value: record.temperature }); |
|
137 if (record.temperature_state == "OK") { |
|
138 $("#gaugeContainer_temperature").jqxGauge({ disabled: false }); |
|
139 } else { |
|
140 $("#gaugeContainer_temperature").jqxGauge({ disabled: true }); |
|
141 } |
|
142 $("#gaugeContainer_pressure").jqxGauge({ caption: { value: 'Bar: '+record.pressure_bar.toFixed(2) }}); |
|
143 $('#gaugeContainer_pressure').jqxGauge({ value: record.pressure_bar }); |
|
144 if (record.pressure_state == "OK") { |
|
145 $("#gaugeContainer_pressure").jqxGauge({ disabled: false }); |
|
146 } else { |
|
147 $("#gaugeContainer_pressure").jqxGauge({ disabled: true }); |
|
148 } |
|
149 } |
|
150 }); |
|
151 |
|
152 $("#select_beer").jqxDropDownList({ |
|
153 placeHolder: "Kies bier:", |
|
154 theme: theme, |
|
155 source: productlist, |
|
156 displayMember: "code", |
|
157 width: 150, |
|
158 height: 24, |
|
159 dropDownWidth: 500, |
|
160 autoDropDownHeight: true, |
|
161 renderer: function (index, label, value) { |
|
162 var datarecord = productlist.records[index]; |
|
163 return datarecord.code + " - " + datarecord.name; |
|
164 } |
|
165 }); |
|
166 |
|
167 $("#gaugeContainer_temperature").jqxGauge( gaugeoptionst ); |
|
168 $("#gaugeContainer_temperature").jqxGauge( { caption: { value: 'Temp: 00.000' }} ); |
|
169 $("#gaugeContainer_pressure").jqxGauge( gaugeoptionsp ); |
|
170 $("#gaugeContainer_pressure").jqxGauge( { caption: { value: 'Bar: 00.000' }} ); |
|
171 |
|
172 function sendProduct(code, name, uuid) { |
|
173 |
|
174 console.log("sendProduct("+code+", "+name+", "+uuid+")"); |
|
175 var data = 'uuid='+record.uuid+'&beeruuid='+uuid+'&beercode='+code+'&beername='+name; |
|
176 $.ajax({ |
|
177 url: "cmd_co2meter.php", |
|
178 data: data, |
|
179 type: "POST", |
|
180 success: function(data) {}, |
|
181 error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); } |
|
182 }); |
|
183 } |
|
184 |
|
185 // Get the data immediatly and then at regular intervals to refresh. |
|
186 dataAdapter.dataBind(); |
|
187 setInterval(function() { |
|
188 var skip = false; |
|
189 if (newProduct) { |
|
190 sendProduct(record.beercode, record.beername, record.beeruuid); |
|
191 newProduct = false; |
|
192 skip = true; |
|
193 } |
|
194 if (skip) { |
|
195 schedule = 4; // 2 seconds wait to get the results |
|
196 } else { |
|
197 if (schedule > 0) |
|
198 schedule--; |
|
199 } |
|
200 |
|
201 if (schedule <= 0) { |
|
202 dataAdapter.dataBind(); |
|
203 schedule = 20; |
|
204 } |
|
205 }, 500); |
|
206 |
|
207 $("#select_beer").on('select', function (event) { |
|
208 if (event.args) { |
|
209 var index = event.args.index, |
|
210 datarecord = productlist.records[index]; |
|
211 record.beercode = datarecord.code; |
|
212 record.beername = datarecord.name; |
|
213 record.beeruuid = datarecord.uuid; |
|
214 newProduct = true; |
|
215 } |
|
216 }); |
|
217 |
|
218 // The chart button. |
|
219 $("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme }); |
|
220 $("#FLog").click(function () { |
|
221 window.open('log_co2pressure.php?code=' + record.beercode + '&name=' + record.beername); |
|
222 }); |
|
223 }); |