Mon, 21 Jul 2014 17:16:08 +0200
Added maintenance window with only two buttons yet
100 | 1 | <?php |
2 | /***************************************************************************** | |
3 | * Copyright (C) 2014 | |
4 | * | |
5 | * Michiel Broek <mbroek at mbse dot eu> | |
6 | * | |
7 | * This file is part of ThermFerm | |
8 | * | |
9 | * This is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2, or (at your option) any | |
12 | * later version. | |
13 | * | |
14 | * ThermFerm is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
21 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
22 | *****************************************************************************/ | |
23 | ||
24 | ||
25 | require_once('utilities.php'); | |
26 | ||
27 | ||
28 | ||
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
29 | function showunit($unit, $unr) |
100 | 30 | { |
117 | 31 | global $my_style; |
32 | ||
100 | 33 | $outstr = ''; |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
34 | $air_state = $beer_state = 1; |
100 | 35 | |
36 | $sock = open_socket(); | |
37 | if ($sock == false) { | |
38 | return ''; | |
39 | } | |
40 | ||
41 | socket_write($sock, "UNIT " . $unit, 4096); | |
42 | $answer = ""; | |
43 | while (1) { | |
44 | $line = socket_read($sock, 4096); | |
45 | if ($line === '') | |
46 | break; | |
47 | $answer .= $line; | |
48 | } | |
49 | socket_close($sock); | |
50 | ||
51 | $sock = open_socket(); | |
52 | if ($sock == false) { | |
53 | return ''; | |
54 | } | |
55 | ||
56 | socket_write($sock, "LIST UNIT", 4096); | |
57 | $answer = ""; | |
58 | while (1) { | |
59 | $line = socket_read($sock, 4096); | |
60 | if ($line === '') | |
61 | break; | |
62 | $answer .= $line; | |
63 | } | |
64 | socket_close($sock); | |
65 | $arr = explode("\r\n", $answer); | |
66 | ||
67 | if (startsWith($arr[0], "213")) { | |
68 | ||
117 | 69 | $outstr .= ' <script type="text/javascript">'.PHP_EOL; |
70 | $outstr .= ' $(document).ready(function () {'.PHP_EOL; | |
71 | $outstr .= ' $("#fermentor_setup_'.$unr.'").jqxButton({ width: \'150\', height: \'25\', theme: \''.$my_style.'\'});'.PHP_EOL; | |
72 | $outstr .= ' $("#fermentor_history_'.$unr.'").jqxButton({ width: \'150\', height: \'25\', theme: \''.$my_style.'\'});'.PHP_EOL; | |
73 | $outstr .= ' });'.PHP_EOL; | |
74 | $outstr .= ' </script>'.PHP_EOL; | |
100 | 75 | $outstr .= ' <div id="fermentor">'.PHP_EOL; |
118
7c8f35a43cec
Added maintenance window with only two buttons yet
Michiel Broek <mbroek@mbse.eu>
parents:
117
diff
changeset
|
76 | $outstr .= ' <div id="fermentor_pict">'.PHP_EOL; |
7c8f35a43cec
Added maintenance window with only two buttons yet
Michiel Broek <mbroek@mbse.eu>
parents:
117
diff
changeset
|
77 | $outstr .= ' <img src="images/Fermenter_60l.gif">'.PHP_EOL; |
7c8f35a43cec
Added maintenance window with only two buttons yet
Michiel Broek <mbroek@mbse.eu>
parents:
117
diff
changeset
|
78 | $outstr .= ' </div>'.PHP_EOL; |
100 | 79 | |
115 | 80 | $set_temperature = "N/A"; |
81 | $air_temperature = "N/A"; | |
82 | $beer_temperature = "N/A"; | |
83 | ||
100 | 84 | foreach($arr as $l) { |
85 | $vals = explode(",", $l); | |
86 | if (strcmp($vals[0], "MODE") == 0) { | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
87 | $mode = $vals[1]; |
100 | 88 | } |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
89 | if (strcmp($vals[0], "AIR_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
90 | $air_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
91 | } |
115 | 92 | if ((strcmp($vals[0], "AIR_TEMPERATURE") == 0) && ($air_state == 0)) { |
93 | $air_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
94 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
95 | if (strcmp($vals[0], "BEER_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
96 | $beer_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
97 | } |
115 | 98 | if ((strcmp($vals[0], "BEER_TEMPERATURE") == 0) && ($beer_state == 0)) { |
99 | $beer_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
100 | } |
100 | 101 | } |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
102 | $outstr .= ' <div id="fermentor_panel">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
103 | $outstr .= ' <div id="fermentor_selector">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
104 | $outstr .= ' Mode '.$mode.PHP_EOL; |
116
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
105 | $outstr .= ' <form>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
106 | strcmp($mode, "OFF") ? $se = "" : $se = " checked"; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
107 | $outstr .= ' <input type="radio" name="mode'.$unr.'" value="OFF"'.$se.'>Off<br>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
108 | strcmp($mode, "NONE") ? $se = "" : $se = " checked"; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
109 | $outstr .= ' <input type="radio" name="mode'.$unr.'" value="NONE"'.$se.'>None<br>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
110 | strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked"; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
111 | $outstr .= ' <input type="radio" name="mode'.$unr.'" value="FRIDGE"'.$se.' disabled>Fridge<br>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
112 | strcmp($mode, "BEER") ? $se = "" : $se = " checked"; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
113 | $outstr .= ' <input type="radio" name="mode'.$unr.'" value="BEER"'.$se.' disabled>Beer<br>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
114 | strcmp($mode, "PROFILE") ? $se = "" : $se = " checked"; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
115 | $outstr .= ' <input type="radio" name="mode'.$unr.'" value="PROFILE"'.$se.' disabled>Profile'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
116 | $outstr .= ' </form>'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
117 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
118 | $outstr .= ' <div id="fermentor_powerled">'.PHP_EOL; |
115 | 119 | $outstr .= ' PwrLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
120 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
121 | $outstr .= ' <div id="fermentor_display1">'.PHP_EOL; |
115 | 122 | $outstr .= ' '.$set_temperature.'<br>Set'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
123 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
124 | $outstr .= ' <div id="fermentor_display2">'.PHP_EOL; |
115 | 125 | $outstr .= ' '.$air_temperature.'<br>Air'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
126 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
127 | $outstr .= ' <div id="fermentor_display3">'.PHP_EOL; |
115 | 128 | $outstr .= ' '.$beer_temperature.'<br>Beer'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
129 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
130 | $outstr .= ' <div id="fermentor_led1">'.PHP_EOL; |
115 | 131 | $outstr .= ' CoolLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
132 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
133 | $outstr .= ' <div id="fermentor_led2">'.PHP_EOL; |
115 | 134 | $outstr .= ' HeatLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
135 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
136 | $outstr .= ' <div id="fermentor_led3">'.PHP_EOL; |
115 | 137 | $outstr .= ' FanLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
138 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
139 | $outstr .= ' <div id="fermentor_toggle1">'.PHP_EOL; |
117 | 140 | $outstr .= ' <form>'.PHP_EOL; |
141 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
142 | $ch = " checked"; | |
143 | $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
144 | $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
145 | $outstr .= ' Cooler'.PHP_EOL; | |
146 | $outstr .= ' </form>'.PHP_EOL; | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
147 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
148 | $outstr .= ' <div id="fermentor_toggle2">'.PHP_EOL; |
117 | 149 | $outstr .= ' <form>'.PHP_EOL; |
150 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
151 | $outstr .= ' <input type="radio" name="heater'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
152 | $outstr .= ' <input type="radio" name="heater'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
153 | $outstr .= ' Heater'.PHP_EOL; | |
154 | $outstr .= ' </form>'.PHP_EOL; | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
155 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
156 | $outstr .= ' <div id="fermentor_toggle3">'.PHP_EOL; |
117 | 157 | $outstr .= ' <form>'.PHP_EOL; |
158 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
159 | $outstr .= ' <input type="radio" name="fan'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
160 | $outstr .= ' <input type="radio" name="fan'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
161 | $outstr .= ' Fan'.PHP_EOL; | |
162 | $outstr .= ' </form>'.PHP_EOL; | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
163 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
164 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
165 | $outstr .= ' <div id="fermentor_control">'.PHP_EOL; |
100 | 166 | $outstr .= ' </div>'.PHP_EOL; |
112 | 167 | $outstr .= ' <div id="fermentor_edit">'.PHP_EOL; |
117 | 168 | $outstr .= ' <button id="fermentor_setup_'.$unr.'">Edit fermentor</button>'.PHP_EOL; |
169 | $outstr .= ' <button id="fermentor_history_'.$unr.'">History</button>'.PHP_EOL; | |
112 | 170 | $outstr .= ' </div>'.PHP_EOL; |
171 | $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; | |
100 | 172 | } |
173 | ||
174 | return $outstr; | |
175 | } | |
176 | ||
177 | ||
178 | ||
179 | function liveview() | |
180 | { | |
181 | $outstr = PHP_EOL; | |
182 | ||
183 | $sock = open_socket(); | |
184 | if ($sock !== false) { | |
185 | socket_write($sock, "LIST", 4096); | |
186 | ||
187 | /* | |
188 | * Multiple reads until the remote closed the connection | |
189 | */ | |
190 | $answer = ""; | |
191 | while (1) { | |
192 | $line = socket_read($sock, 4096); | |
193 | if ($line === '') | |
194 | break; | |
195 | $answer .= $line; | |
196 | } | |
197 | socket_close($sock); | |
198 | $arr = explode("\r\n", $answer); | |
199 | ||
117 | 200 | $outstr .= ' <div id="jqxTabs">'.PHP_EOL; |
201 | $outstr .= ' <ul>'.PHP_EOL; | |
100 | 202 | if (startsWith($arr[0], "212")) { |
203 | $i = 1; | |
204 | while (1) { | |
205 | if (strcmp($arr[$i], ".") == 0) | |
206 | break; | |
207 | $parts = explode(",", $arr[$i]); | |
117 | 208 | $outstr .= ' <li style="margin-left: 30px;">'.$parts[2].'</li>'.PHP_EOL; |
209 | $i++; | |
210 | } | |
211 | } | |
212 | $outstr .= ' </ul>'.PHP_EOL; | |
213 | ||
214 | if (startsWith($arr[0], "212")) { | |
215 | $i = 1; | |
216 | while (1) { | |
217 | if (strcmp($arr[$i], ".") == 0) | |
218 | break; | |
219 | $parts = explode(",", $arr[$i]); | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
220 | $outstr .= showunit($parts[1], $i); |
100 | 221 | $i++; |
222 | } | |
223 | } | |
117 | 224 | $outstr .= ' </div> <!-- jqxTabs -->'.PHP_EOL; |
100 | 225 | } |
226 | ||
227 | return $outstr; | |
228 | } | |
229 | ||
230 | ||
231 | ||
232 | ?> |