Thu, 17 Jul 2014 21:19:22 +0200
Created control panel layout
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 | ||
69 | foreach($arr as $l) { | |
70 | $vals = explode(",", $l); | |
71 | if (strcmp($vals[0], "NAME") == 0) { | |
72 | /* | |
73 | * The name is allways first, so when we have it | |
74 | * emit the formatting. | |
75 | */ | |
76 | $outstr .= ' <div id="fermentor_head">'.PHP_EOL; | |
77 | $outstr .= ' ' . $vals[1] .PHP_EOL; | |
78 | $outstr .= ' </div>'.PHP_EOL; | |
79 | $outstr .= ' <div id="fermentor_pict">'.PHP_EOL; | |
80 | $outstr .= ' <img src="images/Fermenter_60l.gif">'.PHP_EOL; | |
81 | $outstr .= ' </div>'.PHP_EOL; | |
82 | } | |
83 | if (strcmp($vals[0], "MODE") == 0) { | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
84 | $mode = $vals[1]; |
100 | 85 | } |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
86 | if (strcmp($vals[0], "AIR_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
87 | $air_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
88 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
89 | if (strcmp($vals[0], "AIR_TEMPERATURE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
90 | if ($air_state == 0) |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
91 | $air_temperature = $vals[1]; |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
92 | else |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
93 | $air_temperature = "N/A"; |
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 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
98 | if (strcmp($vals[0], "BEER_TEMPERATURE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
99 | if ($beer_state == 0) |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
100 | $beer_temperature = $vals[1]; |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
101 | else |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
102 | $beer_temperature = "N/A"; |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
103 | } |
100 | 104 | } |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
105 | $outstr .= ' <div id="fermentor_panel">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
106 | $outstr .= ' <div id="fermentor_selector">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
107 | $outstr .= ' Mode '.$mode.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
108 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
109 | $outstr .= ' <div id="fermentor_powerled">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
110 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
111 | $outstr .= ' <div id="fermentor_display1">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
112 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
113 | $outstr .= ' <div id="fermentor_display2">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
114 | $outstr .= ' Air<br>'.$air_temperature.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
115 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
116 | $outstr .= ' <div id="fermentor_display3">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
117 | $outstr .= ' Beer<br>'.$beer_temperature.PHP_EOL; |
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_led1">'.PHP_EOL; |
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_led2">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
122 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
123 | $outstr .= ' <div id="fermentor_led3">'.PHP_EOL; |
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_toggle1">'.PHP_EOL; |
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_toggle2">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
128 | $outstr .= ' </div>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
129 | $outstr .= ' <div id="fermentor_toggle3">'.PHP_EOL; |
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>'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
132 | $outstr .= ' <div id="fermentor_control">'.PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
133 | // $outstr .= ' mode ' . $mode . '<br>' .PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
134 | // $outstr .= ' air temperature ' . $air_temperature . '<br>' .PHP_EOL; |
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
135 | // $outstr .= ' beer temperature ' . $beer_temperature . '<br>' .PHP_EOL; |
100 | 136 | $outstr .= ' </div>'.PHP_EOL; |
112 | 137 | $outstr .= ' <div id="fermentor_edit">'.PHP_EOL; |
138 | $outstr .= ' <button id="fermentor_setup" class="ui-state-default">Edit fermentor</button>'.PHP_EOL; | |
139 | $outstr .= ' </div>'.PHP_EOL; | |
140 | $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; | |
100 | 141 | } |
142 | ||
143 | return $outstr; | |
144 | } | |
145 | ||
146 | ||
147 | ||
148 | function liveview() | |
149 | { | |
150 | $outstr = PHP_EOL; | |
151 | ||
152 | $sock = open_socket(); | |
153 | if ($sock !== false) { | |
154 | socket_write($sock, "LIST", 4096); | |
155 | ||
156 | /* | |
157 | * Multiple reads until the remote closed the connection | |
158 | */ | |
159 | $answer = ""; | |
160 | while (1) { | |
161 | $line = socket_read($sock, 4096); | |
162 | if ($line === '') | |
163 | break; | |
164 | $answer .= $line; | |
165 | } | |
166 | socket_close($sock); | |
167 | $arr = explode("\r\n", $answer); | |
168 | ||
169 | if (startsWith($arr[0], "212")) { | |
170 | $i = 1; | |
171 | while (1) { | |
172 | if (strcmp($arr[$i], ".") == 0) | |
173 | break; | |
174 | $parts = explode(",", $arr[$i]); | |
113
cf3f906ffe0d
Created control panel layout
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
175 | $outstr .= showunit($parts[1], $i); |
100 | 176 | $i++; |
177 | } | |
178 | } | |
179 | } | |
180 | ||
181 | return $outstr; | |
182 | } | |
183 | ||
184 | ||
185 | ||
186 | ?> |