Sun, 20 Jul 2014 23:09:50 +0200
Initial setup of wqwidgets
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; |
76 | ||
115 | 77 | $set_temperature = "N/A"; |
78 | $air_temperature = "N/A"; | |
79 | $beer_temperature = "N/A"; | |
80 | ||
100 | 81 | foreach($arr as $l) { |
82 | $vals = explode(",", $l); | |
83 | if (strcmp($vals[0], "NAME") == 0) { | |
84 | /* | |
85 | * The name is allways first, so when we have it | |
86 | * emit the formatting. | |
87 | */ | |
88 | $outstr .= ' <div id="fermentor_head">'.PHP_EOL; | |
89 | $outstr .= ' ' . $vals[1] .PHP_EOL; | |
90 | $outstr .= ' </div>'.PHP_EOL; | |
91 | $outstr .= ' <div id="fermentor_pict">'.PHP_EOL; | |
92 | $outstr .= ' <img src="images/Fermenter_60l.gif">'.PHP_EOL; | |
93 | $outstr .= ' </div>'.PHP_EOL; | |
94 | } | |
95 | if (strcmp($vals[0], "MODE") == 0) { | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
96 | $mode = $vals[1]; |
100 | 97 | } |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
98 | if (strcmp($vals[0], "AIR_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
99 | $air_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
100 | } |
115 | 101 | if ((strcmp($vals[0], "AIR_TEMPERATURE") == 0) && ($air_state == 0)) { |
102 | $air_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
103 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
104 | if (strcmp($vals[0], "BEER_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
105 | $beer_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
106 | } |
115 | 107 | if ((strcmp($vals[0], "BEER_TEMPERATURE") == 0) && ($beer_state == 0)) { |
108 | $beer_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
109 | } |
100 | 110 | } |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
111 | $outstr .= ' <div id="fermentor_panel">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
112 | $outstr .= ' <div id="fermentor_selector">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
113 | $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
|
114 | $outstr .= ' <form>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
115 | 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
|
116 | $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
|
117 | 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
|
118 | $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
|
119 | 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
|
120 | $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
|
121 | 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
|
122 | $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
|
123 | 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
|
124 | $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
|
125 | $outstr .= ' </form>'.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_powerled">'.PHP_EOL; |
115 | 128 | $outstr .= ' PwrLED'.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_display1">'.PHP_EOL; |
115 | 131 | $outstr .= ' '.$set_temperature.'<br>Set'.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_display2">'.PHP_EOL; |
115 | 134 | $outstr .= ' '.$air_temperature.'<br>Air'.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_display3">'.PHP_EOL; |
115 | 137 | $outstr .= ' '.$beer_temperature.'<br>Beer'.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_led1">'.PHP_EOL; |
115 | 140 | $outstr .= ' CoolLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
141 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
142 | $outstr .= ' <div id="fermentor_led2">'.PHP_EOL; |
115 | 143 | $outstr .= ' HeatLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
144 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
145 | $outstr .= ' <div id="fermentor_led3">'.PHP_EOL; |
115 | 146 | $outstr .= ' FanLED'.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_toggle1">'.PHP_EOL; |
117 | 149 | $outstr .= ' <form>'.PHP_EOL; |
150 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
151 | $ch = " checked"; | |
152 | $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
153 | $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
154 | $outstr .= ' Cooler'.PHP_EOL; | |
155 | $outstr .= ' </form>'.PHP_EOL; | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
156 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
157 | $outstr .= ' <div id="fermentor_toggle2">'.PHP_EOL; |
117 | 158 | $outstr .= ' <form>'.PHP_EOL; |
159 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
160 | $outstr .= ' <input type="radio" name="heater'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
161 | $outstr .= ' <input type="radio" name="heater'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
162 | $outstr .= ' Heater'.PHP_EOL; | |
163 | $outstr .= ' </form>'.PHP_EOL; | |
113
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_toggle3">'.PHP_EOL; |
117 | 166 | $outstr .= ' <form>'.PHP_EOL; |
167 | strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; | |
168 | $outstr .= ' <input type="radio" name="fan'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; | |
169 | $outstr .= ' <input type="radio" name="fan'.$unr.'" value="ON"'.$se.'>On<br>'.PHP_EOL; | |
170 | $outstr .= ' Fan'.PHP_EOL; | |
171 | $outstr .= ' </form>'.PHP_EOL; | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
172 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
173 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
174 | $outstr .= ' <div id="fermentor_control">'.PHP_EOL; |
100 | 175 | $outstr .= ' </div>'.PHP_EOL; |
112 | 176 | $outstr .= ' <div id="fermentor_edit">'.PHP_EOL; |
117 | 177 | $outstr .= ' <button id="fermentor_setup_'.$unr.'">Edit fermentor</button>'.PHP_EOL; |
178 | $outstr .= ' <button id="fermentor_history_'.$unr.'">History</button>'.PHP_EOL; | |
112 | 179 | $outstr .= ' </div>'.PHP_EOL; |
180 | $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; | |
100 | 181 | } |
182 | ||
183 | return $outstr; | |
184 | } | |
185 | ||
186 | ||
187 | ||
188 | function liveview() | |
189 | { | |
190 | $outstr = PHP_EOL; | |
191 | ||
192 | $sock = open_socket(); | |
193 | if ($sock !== false) { | |
194 | socket_write($sock, "LIST", 4096); | |
195 | ||
196 | /* | |
197 | * Multiple reads until the remote closed the connection | |
198 | */ | |
199 | $answer = ""; | |
200 | while (1) { | |
201 | $line = socket_read($sock, 4096); | |
202 | if ($line === '') | |
203 | break; | |
204 | $answer .= $line; | |
205 | } | |
206 | socket_close($sock); | |
207 | $arr = explode("\r\n", $answer); | |
208 | ||
117 | 209 | $outstr .= ' <div id="jqxTabs">'.PHP_EOL; |
210 | $outstr .= ' <ul>'.PHP_EOL; | |
100 | 211 | if (startsWith($arr[0], "212")) { |
212 | $i = 1; | |
213 | while (1) { | |
214 | if (strcmp($arr[$i], ".") == 0) | |
215 | break; | |
216 | $parts = explode(",", $arr[$i]); | |
117 | 217 | $outstr .= ' <li style="margin-left: 30px;">'.$parts[2].'</li>'.PHP_EOL; |
218 | $i++; | |
219 | } | |
220 | } | |
221 | $outstr .= ' </ul>'.PHP_EOL; | |
222 | ||
223 | if (startsWith($arr[0], "212")) { | |
224 | $i = 1; | |
225 | while (1) { | |
226 | if (strcmp($arr[$i], ".") == 0) | |
227 | break; | |
228 | $parts = explode(",", $arr[$i]); | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
229 | $outstr .= showunit($parts[1], $i); |
100 | 230 | $i++; |
231 | } | |
232 | } | |
117 | 233 | $outstr .= ' </div> <!-- jqxTabs -->'.PHP_EOL; |
100 | 234 | } |
235 | ||
236 | return $outstr; | |
237 | } | |
238 | ||
239 | ||
240 | ||
241 | ?> |