Added Fan delay logic.

Wed, 01 Apr 2015 17:28:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 01 Apr 2015 17:28:26 +0200
changeset 349
1f89da6511a9
parent 348
ffc4b8aa824f
child 350
7283561977b1

Added Fan delay logic.

thermferm/thermferm.c file | annotate | diff | comparison | revisions
www-thermferm/getstate.php file | annotate | diff | comparison | revisions
www-thermferm/units.php file | annotate | diff | comparison | revisions
--- a/thermferm/thermferm.c	Wed Apr 01 15:56:04 2015 +0200
+++ b/thermferm/thermferm.c	Wed Apr 01 17:28:26 2015 +0200
@@ -1436,16 +1436,28 @@
 		    if ((unit->heater_address || unit->cooler_address) && unit->fan_address) {
 			/*
 			 * If there is a heater or cooler and we have a fan, turn fan on if
-			 * cooling or heating.
+			 * cooling or heating. The Fan has a start/stop delay.
 			 */
 			if ((unit->heater_address && unit->heater_state) || (unit->cooler_address && unit->cooler_state)) {
-			    if (! unit->fan_state)
-				syslog(LOG_NOTICE, "Fan Off => On");
-			    unit->fan_state = 100;
+			    if (unit->fan_wait < unit->fan_delay) {
+				unit->fan_wait++;
+				syslog(LOG_NOTICE, "fan_wait + %d/%d", unit->fan_wait, unit->fan_delay);
+			    } else {
+				if (! unit->fan_state) {
+				    syslog(LOG_NOTICE, "Fan Off => On");
+			    	    unit->fan_state = 100;
+				}
+			    }
 			} else {
-			    if (unit->fan_state)
-				syslog(LOG_NOTICE, "Fan On => Off");
-			    unit->fan_state = 0;
+			    if (unit->fan_wait > 0) {
+				unit->fan_wait--;
+				syslog(LOG_NOTICE, "fan_wait - %d/%d", unit->fan_wait, unit->fan_delay);
+			    } else {
+			    	if (unit->fan_state) {
+				    syslog(LOG_NOTICE, "Fan On => Off");
+			    	    unit->fan_state = 0;
+				}
+			    }
 			}
 			device_out(unit->fan_address, unit->fan_state);
 		    }
@@ -1454,8 +1466,8 @@
 		    P_err = 0.0;
 		    unit->PID_iState = 0.0;
 		    unit->PID_dState = 0.0;
-		}
-	    }
+		} /* fridge beer or profile mode */
+	    } /* for units */
 
 #ifdef HAVE_WIRINGPI_H
 	    piLock(LOCK_MENU);
--- a/www-thermferm/getstate.php	Wed Apr 01 15:56:04 2015 +0200
+++ b/www-thermferm/getstate.php	Wed Apr 01 17:28:26 2015 +0200
@@ -39,7 +39,7 @@
 $led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = "";
 $fridge_set = "NA";
 $beer_set = "NA";
-$heater = $cooler = $fan = "no";
+$heater = $cooler = $fan = $psu = $door = "no";
 $prof_state = "OFF";
 
 
@@ -78,6 +78,10 @@
 		$fan_state = $f[1];
 		$led3 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
 	}
+	if (($f[0] == "PSU_ADDRESS") && (strcmp($f[1], "(null)")))
+		$psu = "yes";
+	if (($f[0] == "DOOR_ADDRESS") && (strcmp($f[1], "(null)")))
+		$door = "yes";
 	if (($f[0] == "BEER_SET") && ($mode == "BEER"))
 		$target_temperature = $f[1];
 	if (($f[0] == "FRIDGE_SET") && ($mode == "FRIDGE"))
--- a/www-thermferm/units.php	Wed Apr 01 15:56:04 2015 +0200
+++ b/www-thermferm/units.php	Wed Apr 01 17:28:26 2015 +0200
@@ -99,6 +99,7 @@
 	$cmd[] = "COOLER_ADDRESS,".$_POST['CoolerAddress'];
 	$cmd[] = "COOLER_DELAY,".$_POST['CoolerDelay'];
 	$cmd[] = "FAN_ADDRESS,".$_POST['FanAddress'];
+	$cmd[] = "FAN_DELAY,".$_POST['FanDelay'];
 	$cmd[] = "LIGHT_ADDRESS,".$_POST['LightAddress'];
 	$cmd[] = "LIGHT_DELAY,".$_POST['LightDelay'];
 	$cmd[] = "DOOR_ADDRESS,".$_POST['DoorAddress'];
@@ -128,6 +129,7 @@
     unset($_POST['LightAddress']);
     unset($_POST['LightDelay']);
     unset($_POST['FanAddress']);
+    unset($_POST['FanDelay']);
     unset($_POST['DoorAddress']);
     unset($_POST['PSUAddress']);
     unset($_POST['TempSetMin']);
@@ -162,6 +164,7 @@
  *         9 = IdleRangeL out of range
  *        10 = IdleRangeH out of range
  *        11 = LightDelay out of range
+ *	  12 = FanDelay out of range
  *        99 = Cancel key
  */
 function test_thedata() {
@@ -172,7 +175,7 @@
 	isset($_POST['BeerAddress']) && isset($_POST['HeaterAddress']) && isset($_POST['CoolerAddress']) && isset($_POST['LightAddress']) &&
 	isset($_POST['HeaterDelay']) && isset($_POST['CoolerDelay']) && isset($_POST['LightDelay']) && isset($_POST['PSUAddress']) &&
 	isset($_POST['FanAddress']) && isset($_POST['DoorAddress']) && isset($_POST['TempSetMin']) && isset($_POST['TempSetMax']) &&
-	isset($_POST['PID_Kp']) && isset($_POST['PID_Kd']) && isset($_POST['PID_Ki']) &&
+	isset($_POST['PID_Kp']) && isset($_POST['PID_Kd']) && isset($_POST['PID_Ki']) && isset($_POST['FanDelay']) &&
 	isset($_POST['IdleRangeL']) && isset($_POST['IdleRangeH']) && isset($_POST['key']) && isset($_POST['command'])) {
 
 	if ($_POST['key'] == 'Cancel')
@@ -218,6 +221,9 @@
 	if (($_POST['LightDelay'] < 0) || ($_POST['LightDelay'] > 720))
 	    return 11;
 
+	if (($_POST['FanDelay'] < 0) || ($_POST['FanDelay'] > 720))
+	    return 12;
+
     } else {
 	return 1;
     }
@@ -266,6 +272,8 @@
 		break;
 	case 11: $error = 'Light Delay must be bewteen 0 and 720 seconds';
 		break;
+	case 12: $error = 'Fan Delay must be bewteen 0 and 720 seconds';
+		break;
 	case 99:        
 		load('units.php');
 		break;
@@ -448,6 +456,12 @@
 		$outstr .= '        </select></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+	    if ($f[0] == "FAN_DELAY") {
+		$outstr .= '       <tr class="editor">'.PHP_EOL;
+		$outstr .= '        <td class="editname">Fan Switch Delay</td>'.PHP_EOL;
+		$outstr .= '        <td class="editfield"><input type="text" name="FanDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
+		$outstr .= '       </tr>'.PHP_EOL;
+	    }
 	    if ($f[0] == "LIGHT_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Lights Address</td>'.PHP_EOL;

mercurial