www/js/mon_co2meter.js

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

mercurial