Fri, 18 Jul 2014 22:24:03 +0200
Added jquery script. Added radio buttons for unit mode
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 | { |
31 | $outstr = ''; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
32 | $air_state = $beer_state = 1; |
100 | 33 | |
34 | $sock = open_socket(); | |
35 | if ($sock == false) { | |
36 | return ''; | |
37 | } | |
38 | ||
39 | socket_write($sock, "UNIT " . $unit, 4096); | |
40 | $answer = ""; | |
41 | while (1) { | |
42 | $line = socket_read($sock, 4096); | |
43 | if ($line === '') | |
44 | break; | |
45 | $answer .= $line; | |
46 | } | |
47 | socket_close($sock); | |
48 | ||
49 | $sock = open_socket(); | |
50 | if ($sock == false) { | |
51 | return ''; | |
52 | } | |
53 | ||
54 | socket_write($sock, "LIST UNIT", 4096); | |
55 | $answer = ""; | |
56 | while (1) { | |
57 | $line = socket_read($sock, 4096); | |
58 | if ($line === '') | |
59 | break; | |
60 | $answer .= $line; | |
61 | } | |
62 | socket_close($sock); | |
63 | $arr = explode("\r\n", $answer); | |
64 | ||
65 | if (startsWith($arr[0], "213")) { | |
66 | ||
67 | $outstr .= ' <div id="fermentor">'.PHP_EOL; | |
68 | ||
115 | 69 | $set_temperature = "N/A"; |
70 | $air_temperature = "N/A"; | |
71 | $beer_temperature = "N/A"; | |
72 | ||
100 | 73 | foreach($arr as $l) { |
74 | $vals = explode(",", $l); | |
75 | if (strcmp($vals[0], "NAME") == 0) { | |
76 | /* | |
77 | * The name is allways first, so when we have it | |
78 | * emit the formatting. | |
79 | */ | |
80 | $outstr .= ' <div id="fermentor_head">'.PHP_EOL; | |
81 | $outstr .= ' ' . $vals[1] .PHP_EOL; | |
82 | $outstr .= ' </div>'.PHP_EOL; | |
83 | $outstr .= ' <div id="fermentor_pict">'.PHP_EOL; | |
84 | $outstr .= ' <img src="images/Fermenter_60l.gif">'.PHP_EOL; | |
85 | $outstr .= ' </div>'.PHP_EOL; | |
86 | } | |
87 | if (strcmp($vals[0], "MODE") == 0) { | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
88 | $mode = $vals[1]; |
100 | 89 | } |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
90 | if (strcmp($vals[0], "AIR_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
91 | $air_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
92 | } |
115 | 93 | if ((strcmp($vals[0], "AIR_TEMPERATURE") == 0) && ($air_state == 0)) { |
94 | $air_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
95 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
96 | if (strcmp($vals[0], "BEER_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
97 | $beer_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
98 | } |
115 | 99 | if ((strcmp($vals[0], "BEER_TEMPERATURE") == 0) && ($beer_state == 0)) { |
100 | $beer_temperature = $vals[1]; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
101 | } |
100 | 102 | } |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
103 | $outstr .= ' <div id="fermentor_panel">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
104 | $outstr .= ' <div id="fermentor_selector">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
105 | $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
|
106 | $outstr .= ' <form>'.PHP_EOL; |
065a242ed7ec
Added jquery script. Added radio buttons for unit mode
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
107 | 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
|
108 | $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
|
109 | 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
|
110 | $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
|
111 | 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
|
112 | $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
|
113 | 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
|
114 | $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
|
115 | 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
|
116 | $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
|
117 | $outstr .= ' </form>'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
118 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
119 | $outstr .= ' <div id="fermentor_powerled">'.PHP_EOL; |
115 | 120 | $outstr .= ' PwrLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
121 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
122 | $outstr .= ' <div id="fermentor_display1">'.PHP_EOL; |
115 | 123 | $outstr .= ' '.$set_temperature.'<br>Set'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
124 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
125 | $outstr .= ' <div id="fermentor_display2">'.PHP_EOL; |
115 | 126 | $outstr .= ' '.$air_temperature.'<br>Air'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
127 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
128 | $outstr .= ' <div id="fermentor_display3">'.PHP_EOL; |
115 | 129 | $outstr .= ' '.$beer_temperature.'<br>Beer'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
130 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
131 | $outstr .= ' <div id="fermentor_led1">'.PHP_EOL; |
115 | 132 | $outstr .= ' CoolLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
133 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
134 | $outstr .= ' <div id="fermentor_led2">'.PHP_EOL; |
115 | 135 | $outstr .= ' HeatLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
136 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
137 | $outstr .= ' <div id="fermentor_led3">'.PHP_EOL; |
115 | 138 | $outstr .= ' FanLED'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
139 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
140 | $outstr .= ' <div id="fermentor_toggle1">'.PHP_EOL; |
115 | 141 | $outstr .= ' CoolSW'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
142 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
143 | $outstr .= ' <div id="fermentor_toggle2">'.PHP_EOL; |
115 | 144 | $outstr .= ' HeatSW'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
145 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
146 | $outstr .= ' <div id="fermentor_toggle3">'.PHP_EOL; |
115 | 147 | $outstr .= ' FanSW'.PHP_EOL; |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
148 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
149 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
150 | $outstr .= ' <div id="fermentor_control">'.PHP_EOL; |
100 | 151 | $outstr .= ' </div>'.PHP_EOL; |
112 | 152 | $outstr .= ' <div id="fermentor_edit">'.PHP_EOL; |
153 | $outstr .= ' <button id="fermentor_setup" class="ui-state-default">Edit fermentor</button>'.PHP_EOL; | |
115 | 154 | $outstr .= ' <button id="fermentor_history" class="ui-state-default">History</button>'.PHP_EOL; |
112 | 155 | $outstr .= ' </div>'.PHP_EOL; |
156 | $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; | |
100 | 157 | } |
158 | ||
159 | return $outstr; | |
160 | } | |
161 | ||
162 | ||
163 | ||
164 | function liveview() | |
165 | { | |
166 | $outstr = PHP_EOL; | |
167 | ||
168 | $sock = open_socket(); | |
169 | if ($sock !== false) { | |
170 | socket_write($sock, "LIST", 4096); | |
171 | ||
172 | /* | |
173 | * Multiple reads until the remote closed the connection | |
174 | */ | |
175 | $answer = ""; | |
176 | while (1) { | |
177 | $line = socket_read($sock, 4096); | |
178 | if ($line === '') | |
179 | break; | |
180 | $answer .= $line; | |
181 | } | |
182 | socket_close($sock); | |
183 | $arr = explode("\r\n", $answer); | |
184 | ||
185 | if (startsWith($arr[0], "212")) { | |
186 | $i = 1; | |
187 | while (1) { | |
188 | if (strcmp($arr[$i], ".") == 0) | |
189 | break; | |
190 | $parts = explode(",", $arr[$i]); | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
191 | $outstr .= showunit($parts[1], $i); |
100 | 192 | $i++; |
193 | } | |
194 | } | |
195 | } | |
196 | ||
197 | return $outstr; | |
198 | } | |
199 | ||
200 | ||
201 | ||
202 | ?> |