# HG changeset patch # User Michiel Broek # Date 1408549355 -7200 # Node ID abdba3f9d9e2c90cc45d3755037db512ee67c481 # Parent 8c52b09bdeccf6eef03cbb36f339b2120a981b13 Automatic ajax updates of radio buttons diff -r 8c52b09bdecc -r abdba3f9d9e2 www-thermferm/getstate.php --- a/www-thermferm/getstate.php Wed Aug 20 14:01:15 2014 +0200 +++ b/www-thermferm/getstate.php Wed Aug 20 17:42:35 2014 +0200 @@ -36,9 +36,11 @@ $beer_temperature = "NA"; $beer_state = "NA"; $target_temperature = "NA"; -$led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = 0; +$led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = ""; $fridge_set = "NA"; $beer_set = "NA"; +$heater = $cooler = $fan = "no"; + if (startsWith($arr[0], "213")) { $j = 1; @@ -57,12 +59,24 @@ $beer_temperature = $f[1]; if ($f[0] == "MODE") $mode = $f[1]; - if ($f[0] == "COOLER_STATE") + if (($f[0] == "COOLER_ADDRESS") && (strcmp($f[1], "(null)"))) + $cooler = "yes"; + if ($f[0] == "COOLER_STATE") { + $cooler_state = $f[1]; $led1 = $f[1] ? '
' : '
'; - if ($f[0] == "HEATER_STATE") + } + if (($f[0] == "HEATER_ADDRESS") && (strcmp($f[1], "(null)"))) + $heater = "yes"; + if ($f[0] == "HEATER_STATE") { + $heater_state = $f[1]; $led2 = $f[1] ? '
' : '
'; - if ($f[0] == "FAN_STATE") + } + if (($f[0] == "FAN_ADDRESS") && (strcmp($f[1], "(null)"))) + $fan = "yes"; + if ($f[0] == "FAN_STATE") { + $fan_state = $f[1]; $led3 = $f[1] ? '
' : '
'; + } if (($f[0] == "BEER_SET") && ($mode == "BEER")) $target_temperature = $f[1]; if (($f[0] == "FRIDGE_SET") && ($mode == "FRIDGE")) @@ -74,11 +88,50 @@ } +/* + * Create the value for the mode select radio buttons + */ +strcmp($mode, "OFF") ? $se = "" : $se = " checked"; +$modestr = ' Off
'.PHP_EOL; +strcmp($mode, "NONE") ? $se = "" : $se = " checked"; +$modestr .= ' None
'.PHP_EOL; +(strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = " disabled"; +strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked"; +$modestr .= ' Fridge
'.PHP_EOL; +strcmp($mode, "BEER") ? $se = "" : $se = " checked"; +$modestr .= ' Beer
'.PHP_EOL; +strcmp($mode, "PROFILE") ? $se = "" : $se = " checked"; +$modestr .= ' Profile'.PHP_EOL; + + +/* + * Create the values for the on/off switches + */ +(($mode == "NONE") && ($cooler == "yes")) ? $dis = "" : $dis = " disabled"; +($cooler_state == "0") ? $ch = " checked" : $ch = ""; +$sw1 = ' Off
'.PHP_EOL; +($cooler_state == "100") ? $ch = " checked" : $ch = ""; +$sw1 .= ' On'.PHP_EOL; + +(($mode == "NONE") && ($heater == "yes")) ? $dis = "" : $dis = " disabled"; +($heater_state == "0") ? $ch = " checked" : $ch = ""; +$sw2 = ' Off
'.PHP_EOL; +($heater_state == "100") ? $ch = " checked" : $ch = ""; +$sw2 .= ' On'.PHP_EOL; + +(($mode == "NONE") && ($fan== "yes")) ? $dis = "" : $dis = " disabled"; +($fan_state == "0") ? $ch = " checked" : $ch = ""; +$sw3 = ' Off
'.PHP_EOL; +($fan_state == "100") ? $ch = " checked" : $ch = ""; +$sw3 .= ' On'.PHP_EOL; + + + $reply = array ( 'air_temperature' => $air_temperature, 'beer_temperature' => $beer_temperature, 'target_temperature' => $target_temperature, - 'mode' => $mode, + 'mode' => $modestr, 'led1' => $led1, 'led2' => $led2, 'led3' => $led3, diff -r 8c52b09bdecc -r abdba3f9d9e2 www-thermferm/liveview.php --- a/www-thermferm/liveview.php Wed Aug 20 14:01:15 2014 +0200 +++ b/www-thermferm/liveview.php Wed Aug 20 17:42:35 2014 +0200 @@ -170,9 +170,13 @@ $outstr .= ' $("#load_air_'.$unr.'").html(data.air_temperature);'.PHP_EOL; $outstr .= ' $("#load_beer_'.$unr.'").html(data.beer_temperature);'.PHP_EOL; $outstr .= ' $("#load_target_'.$unr.'").html(data.target_temperature);'.PHP_EOL; + $outstr .= ' $("#load_select_'.$unr.'").html(data.mode);'.PHP_EOL; $outstr .= ' $("#load_led1_'.$unr.'").html(data.led1);'.PHP_EOL; $outstr .= ' $("#load_led2_'.$unr.'").html(data.led2);'.PHP_EOL; $outstr .= ' $("#load_led3_'.$unr.'").html(data.led3);'.PHP_EOL; + $outstr .= ' $("#load_sw1_'.$unr.'").html(data.sw1);'.PHP_EOL; + $outstr .= ' $("#load_sw2_'.$unr.'").html(data.sw2);'.PHP_EOL; + $outstr .= ' $("#load_sw3_'.$unr.'").html(data.sw3);'.PHP_EOL; $outstr .= ' });'.PHP_EOL; $outstr .= ' }, 10000);'.PHP_EOL; $outstr .= ' });'.PHP_EOL; @@ -183,6 +187,7 @@ $outstr .= '
'.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; strcmp($mode, "OFF") ? $se = "" : $se = " checked"; $outstr .= ' Off
'.PHP_EOL; strcmp($mode, "NONE") ? $se = "" : $se = " checked"; @@ -194,6 +199,7 @@ $outstr .= ' Beer
'.PHP_EOL; strcmp($mode, "PROFILE") ? $se = "" : $se = " checked"; $outstr .= ' Profile'.PHP_EOL; + $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= '
'.PHP_EOL; @@ -321,9 +327,11 @@ $outstr .= '
'.PHP_EOL; (($mode == "NONE") && ($cooler == "yes")) ? $dis = "" : $dis = " disabled"; ($cooler_state == "0") ? $ch = " checked" : $ch = ""; - $outstr .= ' Off
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' Off
'.PHP_EOL; ($cooler_state == "100") ? $ch = " checked" : $ch = ""; - $outstr .= ' On'.PHP_EOL; + $outstr .= ' On'.PHP_EOL; + $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= '
'.PHP_EOL; @@ -332,9 +340,11 @@ $outstr .= '
'.PHP_EOL; (($mode == "NONE") && ($heater == "yes")) ? $dis = "" : $dis = " disabled"; ($heater_state == "0") ? $ch = " checked" : $ch = ""; - $outstr .= ' Off
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' Off
'.PHP_EOL; ($heater_state == "100") ? $ch = " checked" : $ch = ""; - $outstr .= ' On'.PHP_EOL; + $outstr .= ' On'.PHP_EOL; + $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; @@ -343,9 +353,11 @@ $outstr .= '
'.PHP_EOL; (($mode == "NONE") && ($fan== "yes")) ? $dis = "" : $dis = " disabled"; ($fan_state == "0") ? $ch = " checked" : $ch = ""; - $outstr .= ' Off
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' Off
'.PHP_EOL; ($fan_state == "100") ? $ch = " checked" : $ch = ""; - $outstr .= ' On'.PHP_EOL; + $outstr .= ' On'.PHP_EOL; + $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL;