www-thermferm/liveview.php

changeset 195
b34a1b2421fb
parent 193
4136193a0c22
child 196
4d7a96c5d1ff
--- a/www-thermferm/liveview.php	Thu Aug 07 22:06:18 2014 +0200
+++ b/www-thermferm/liveview.php	Fri Aug 08 23:07:44 2014 +0200
@@ -54,6 +54,8 @@
 	$set_temperature = "NA";
 	$air_temperature = "NA";
 	$beer_temperature = "NA";
+	$profile = "";
+	$prof_state = "OFF";
 	$power_led = $cooler_led = $heater_led = $fan_led = "off";
 	$heater = $cooler = $fan = "no";
 	$heater_state = $cooler_state = $fan_state = 0;
@@ -95,6 +97,12 @@
 	    if (strcmp($vals[0], "FAN_STATE") == 0) {
 		$fan_state = $vals[1];
 	    }
+	    if (strcmp($vals[0], "PROFILE") == 0) {
+		$profile = $vals[1];
+	    }
+	    if (strcmp($vals[0], "PROF_STATE") == 0) {
+		$prof_state = $vals[1];
+	    }
 	    if (($vals[0] == "BEER_SET") && ($mode == "BEER")) {
 		$set_temperature = $vals[1];
 	    }
@@ -203,9 +211,97 @@
 	$outstr .= '        <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL;
 	$outstr .= '       </form>'.PHP_EOL;
 	$outstr .= '      </div>'.PHP_EOL;
+
 	$outstr .= '      <div id="fermentor_powerled">'.PHP_EOL;
 	$outstr .= '       <img src="images/led_green_'.$power_led.'.png"><br>Pwr'.PHP_EOL;
 	$outstr .= '      </div>'.PHP_EOL;
+
+	$outstr .= '      <div id="fermentor_mode_control">'.PHP_EOL;
+	if ($mode == "FRIDGE") {
+	    $outstr .= '       <form id="set_fridge_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    $outstr .= '        <input type="text" name="Fridge" size="5" value="'.$set_temperature.'"><br>'.PHP_EOL;
+	    $outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	if ($mode == "BEER") {
+	    $outstr .= '       <form id="set_beer_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    $outstr .= '        <input type="text" name="Beer" size="5" value="'.$set_temperature.'">'.PHP_EOL;
+	    $outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	if ($mode == "PROFILE") {
+	    /*
+	     * First, load a list with available profiles.
+	     */
+	    $sock = open_socket();
+	    if ($sock == true) {
+	    	socket_write($sock, "PROFILE LIST", 4096);
+	    	$answer = "";
+	    	while (1) {
+		    $line = socket_read($sock, 4096);
+		    if ($line === '')
+			break;
+		    $answer .= $line;
+	    	}
+	    	socket_close($sock);
+	    	$reply = explode("\r\n", $answer);
+	    }
+
+	    /*
+	     * Show loaded profile.
+	     */
+	    if ($profile == "(null)") {
+		$prof_name = "None";
+	    }else {
+		if (startsWith($reply[0], "212")) {
+		    $i = 1;
+		    while (1) {
+			if (strcmp($reply[$i], ".") == 0)
+			    break;
+			$f = explode(",", $reply[$i]);
+			if ($f[0] == $profile) {
+			    $prof_name = $f[1];
+			    break;
+			}
+			$i++;
+		    }
+		}
+	    }
+	    $outstr .= '       <div style="color: blue; width: 148px; height: 20px; overflow: hidden;">Profile: '.$prof_name.'</div>'.PHP_EOL;
+
+	    $outstr .= '       <form id="set_profile_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    if ($prof_state == "OFF") {
+	    	$outstr .= '        <select name="SetProfile" style="width: 130px;">'.PHP_EOL;
+	    	$outstr .= '         <option value="">None</option>'.PHP_EOL;
+	    	if (startsWith($reply[0], "212")) {
+		    $i = 1;
+		    while (1) {
+			if (strcmp($reply[$i], ".") == 0)
+			    break;
+			$f = explode(",", $reply[$i]);
+			if ($f[2] > 0) {
+			    ($f[0] == $profile) ? $se = " selected" : $se = "";
+			    $outstr .= '         <option value="'.$f[0].'"'.$se.'>'.$f[1].'</option>'.PHP_EOL;
+			}
+			$i++;
+		    }
+	    	}
+		$outstr .= '        </select>'.PHP_EOL;
+		$outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+		if ($profile != "(null)")
+		    $outstr .= '        <input type="submit" value="Start" name="key">'.PHP_EOL;
+
+	    } else if ($prof_state == "RUN") {
+	    } else if ($prof_state == "PAUSE") {
+	    } else if ($prof_state == "DONE") {
+	    }
+	    //$outstr .= '        <input type="text" name="Beer" size="5" value="'.$set_temperature.'">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	$outstr .= '      </div>'.PHP_EOL;
 	$outstr .= '     </div> <!-- fermentor_panel_top -->'.PHP_EOL;
 
 	$outstr .= '     <div id="fermentor_panel_display">'.PHP_EOL;

mercurial