Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.

Sun, 31 Aug 2014 18:25:32 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 31 Aug 2014 18:25:32 +0200
changeset 273
b863e0147296
parent 272
f436d826de4b
child 274
111b0e9663dc

Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Sun Aug 31 17:51:04 2014 +0200
+++ b/thermferm/server.c	Sun Aug 31 18:25:32 2014 +0200
@@ -1547,7 +1547,7 @@
 				    unit->heater_state = ival;
 
 			    } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) {
-				if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
+				if (sscanf(val, "%d", &ival) == 1)
 				    unit->heater_delay = ival;
 
 			    } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) {
@@ -1566,7 +1566,7 @@
 				    unit->cooler_state = ival;
 
 			    } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) {
-				if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
+				if (sscanf(val, "%d", &ival) == 1)
 				    unit->cooler_delay = ival;
 
 			    } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) {
@@ -1585,7 +1585,7 @@
 				    unit->fan_state = ival;
 			    
 			    } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) {
-				if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
+				if (sscanf(val, "%d", &ival) == 1)
 				    unit->fan_delay = ival;
 
 			    } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) {
--- a/thermferm/thermferm.c	Sun Aug 31 17:51:04 2014 +0200
+++ b/thermferm/thermferm.c	Sun Aug 31 18:25:32 2014 +0200
@@ -1287,40 +1287,47 @@
 					sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
 			}
 			if (unit->heater_address) {
-			    if (unit->heater_wait < unit->heater_delay) {
-				unit->heater_wait++;
-				syslog(LOG_NOTICE, "heater_wait %d/%d", unit->heater_wait, unit->heater_delay);
-			    } else {
-			        if (Out >= 2) {
+			    if (Out >= 2) {
+				if (unit->heater_wait < unit->heater_delay) {
+				    unit->heater_wait++;
+				    syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay);
+				} else {
 				    if (! unit->heater_state && ! unit->cooler_state) {
-				    	syslog(LOG_NOTICE, "Heater Off => On");
-					unit->heater_wait = 0;
-				    	unit->heater_state = 100;
+					syslog(LOG_NOTICE, "Heater Off => On");
+					unit->heater_state = 100;
 				    }
-			    	} else {
+				}
+			    } else {
+				if (unit->heater_wait > 0) {
+				    unit->heater_wait--;
+				    syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay);
+				} else {
 				    if (unit->heater_state) {
-				    	syslog(LOG_NOTICE, "Heater On => Off");
-					unit->heater_wait = 0;
-				    	unit->heater_state = 0;
+					syslog(LOG_NOTICE, "Heater On => Off");
+					unit->heater_state = 0;
 				    }
-			    	}
+				}
 			    }
 			    device_out(unit->heater_address, unit->heater_state);
 			}
 			if (unit->cooler_address) {
-			    if (unit->cooler_wait < unit->cooler_delay) {
-				unit->cooler_wait++;
-			    } else {
-			    	if (Out <= -2) {
+			    if (Out <= -2) {
+			    	if (unit->cooler_wait < unit->cooler_delay) {
+				    unit->cooler_wait++;
+				    syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay);
+			    	} else {
 				    if (! unit->cooler_state && ! unit->heater_state) {
 				    	syslog(LOG_NOTICE, "Cooler Off => On");
-					unit->cooler_wait = 0;
 					unit->cooler_state = 100;
 				    }
+				}
+			    } else {
+				if (unit->cooler_wait > 0) {
+				    unit->cooler_wait--;
+				    syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay);
 			    	} else {
 				    if (unit->cooler_state) {
 				    	syslog(LOG_NOTICE, "Cooler On => Off");
-					unit->cooler_wait = 0;
 					unit->cooler_state = 0;
 				    }
 				}

mercurial