www/js/mon_fermenter.js

changeset 180
a5aa3502310c
child 182
58618d93c0fb
equal deleted inserted replaced
179:8adaeecd9dc8 180:a5aa3502310c
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 bname = '';
27 var bcode = '';
28
29 var gaugeoptions = {
30 min: -5, max: 35, width: 275, height: 275,
31 ranges: [{ startValue: -5, endValue: 0, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
32 { startValue: 0, endValue: 16, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
33 { startValue: 16, endValue: 24, style: { fill: '#FCA76A', stroke: '#FCA76A' }, endWidth: 10, startWidth: 10 },
34 { startValue: 24, endValue: 35, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
35 ticksMinor: { interval: 1, size: '5%' },
36 ticksMajor: { interval: 5, size: '9%' },
37 labels: { interval: 5 },
38 style: { fill: '#eeeeee', stroke: '#666666' },
39 value: 0,
40 colorScheme: 'scheme05',
41 animationDuration: 1200
42 };
43 var gaugeSmalloptions = {
44 min: -20, max: 25, width: 150, height: 150,
45 ranges: [{ startValue: -20, endValue: 0, startWidth: 5, endWidth: 5, style: { fill: '#3399FF', stroke: '#3399FF' }},
46 { startValue: 0, endValue: 25, startWidth: 5, endWidth: 5, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }}],
47 ticksMinor: { interval: 1, size: '5%' },
48 ticksMajor: { interval: 5, size: '9%' },
49 labels: { interval: 5 },
50 style: { fill: '#eeeeee', stroke: '#666666' },
51 value: 0,
52 colorScheme: 'scheme05',
53 animationDuration: 1200,
54 caption: { value: 'Chiller', position: 'bottom', offset: [0, 10] }
55 };
56
57 $("#gaugeContainer_air").jqxGauge( gaugeoptions );
58 $("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air', position: 'bottom', offset: [0, 10] }} );
59 $("#gaugeContainer_beer").jqxGauge( gaugeoptions );
60 $("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer', position: 'bottom', offset: [0, 10] }} );
61 $("#gaugeContainer_chiller").jqxGauge( gaugeSmalloptions );
62
63 var url = "getfermenter.php?uuid='" + my_uuid + "'";
64 var source = {
65 datatype: "json",
66 datafields: [
67 { name: 'record', type: 'int' },
68 { name: 'uuid', type: 'string' },
69 { name: 'alias', type: 'string' },
70 { name: 'node', type: 'string' },
71 { name: 'online', type: 'bool' },
72 { name: 'beercode', type: 'string' },
73 { name: 'beername', type: 'string' },
74 { name: 'air_state', type: 'string' },
75 { name: 'air_temperature', type: 'float' },
76 { name: 'beer_state', type: 'string' },
77 { name: 'beer_temperature', type: 'float' },
78 { name: 'chiller_state', type: 'string' },
79 { name: 'chiller_temperature', type: 'float' },
80 { name: 'heater_state', type: 'int' },
81 { name: 'heater_usage', type: 'int' },
82 { name: 'cooler_state', type: 'int' },
83 { name: 'cooler_usage', type: 'int' },
84 { name: 'fan_state', type: 'int' },
85 { name: 'fan_usage', type: 'int' },
86 { name: 'light_state', type: 'int' },
87 { name: 'light_usage', type: 'int' },
88 { name: 'door_state', type: 'int' },
89 { name: 'psu_state', type: 'int' },
90 { name: 'mode', type: 'string' },
91 { name: 'alarm', type: 'int' },
92 { name: 'setpoint_high', type: 'float' },
93 { name: 'setpoint_low', type: 'float' },
94 { name: 'profile_uuid', type: 'string' },
95 { name: 'profile_name', type: 'string' },
96 { name: 'profile_state', type: 'string' },
97 { name: 'profile_precent', type: 'int' },
98 { name: 'profile_inittemp_high', type: 'float' },
99 { name: 'profile_inittemp_low', type: 'float' },
100 { name: 'profile_steps', type: 'string' },
101 { name: 'stage', type: 'string' }
102 ],
103 id: 'record',
104 url: url
105 };
106
107 var dataAdapter = new $.jqx.dataAdapter(source, {
108 loadComplete: function (records) {
109 var record = dataAdapter.records[0];
110 var oline = (record.online) ? "On-line" : "Off-line";
111 var html = "<div id='fermenter_table'>";
112 html += "<table style='width: 100%; padding: 10px;'>";
113 html += "<tr><th colspan=2>Klimaatkast overzicht</th></tr>";
114 html += "<tr><td>Uuid</td><td>" + record.uuid + "</td></tr>";
115 html += "<tr><td>Systeem</td><td>" + record.node + "/" + record.alias + " " + oline + "</td></tr>";
116 html += "<tr><td>Bier</td><td>" + record.beercode + " - " + record.beername + "</td></tr>";
117 html += "<tr><td>Werking</td><td>" + record.mode + "</td></tr>";
118 html += "<tr><td>Fase</td><td>" + record.stage + "</td></tr>"
119 html += "</<table>";
120 html += "</div>";
121 $("#ContentPanel").html(html);
122 bcode = record.beercode;
123 bname = record.beername;
124
125 $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature });
126 if (record.online && (record.air_state == "OK")) {
127 $("#gaugeContainer_air").jqxGauge({ disabled: false });
128 } else {
129 $("#gaugeContainer_air").jqxGauge({ disabled: true });
130 }
131 $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature });
132 if (record.online && (record.beer_state == "OK")) {
133 $("#gaugeContainer_beer").jqxGauge({ disabled: false });
134 } else {
135 $("#gaugeContainer_beer").jqxGauge({ disabled: true });
136 }
137 $("#gaugeContainer_chiller").jqxGauge({ value: record.chiller_temperature });
138 if (record.online && (record.chiller_state == "OK")) {
139 $("#gaugeContainer_chiller").jqxGauge({ disabled: false });
140 } else {
141 $("#gaugeContainer_chiller").jqxGauge({ disabled: true });
142 }
143
144 html = "<div>SpH <span class='temperature NUM'>" + record.setpoint_high.toFixed(1) + "</span></div>";
145 html += "<div>SpL <span class='temperature NUM'>" + record.setpoint_low.toFixed(1) + "</span></div>";
146 html += "<div>Air <span class='temperature NUM'>" + record.air_temperature.toFixed(3) + "</span></div>";
147 html += "<div>Beer <span class='temperature NUM'>" + record.beer_temperature.toFixed(3) + "</span></div>";
148 $("#fermenter_tempdigits").html(html);
149 }
150 });
151
152 // Get the data immediatly and then at regular intervals to refresh.
153 dataAdapter.dataBind();
154 setInterval(function(){
155 dataAdapter.dataBind();
156 }, 10000);
157
158 // The chart button.
159 $("#FLog").jqxButton({ template: "info", width: '150px', theme: theme });
160 $("#FLog").click(function () {
161 var url="log_fermentation.php?code=" + bcode + "&name=" + bname;
162 window.open(url);
163 });
164 });

mercurial