thermferm/thermferm.c

changeset 364
2f9bbbcd2407
parent 363
468ec0d96cce
child 367
b9130db48c63
--- a/thermferm/thermferm.c	Sun May 17 19:34:55 2015 +0200
+++ b/thermferm/thermferm.c	Sun May 17 23:23:25 2015 +0200
@@ -1399,39 +1399,43 @@
 		    /*
 		     * PID controller compute
 		     */
+		    UpdatePID(unit->PID_heat);
+		    UpdatePID(unit->PID_cool);
+
+		    /*
+		     * Logging
+		     */
 		    if (unit->heater_address) {
-			UpdatePID(unit->PID_heat);
-
 			if (debug)
 			    fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
 				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
-			if (((unit->PID_heat->OutP >= 1) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
+			if (((unit->PID_heat->OutP >= 2) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
 			    syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
 				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
 			}
 		    }
 		    if (unit->cooler_address) {
-		    	UpdatePID(unit->PID_cool);
-
 		    	if (debug)
 			    fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
 				unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
-		    	if (((unit->PID_cool->OutP >= 1) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
+		    	if (((unit->PID_cool->OutP >= 2) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
 			    syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
 				unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
 		    	}
 		    }
 
+		    /*
+		     * Deadlock
+		     */
 		    if (unit->PID_cool->OutP && unit->PID_heat->OutP) {
 			syslog(LOG_NOTICE, "Heat and Cool lockdown");
 			unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
 		    }
 
 		    if (unit->heater_address && ! unit->cooler_state) {
-			if (unit->PID_heat->OutP >= 1) {
+			if (unit->PID_heat->OutP >= 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 {
 				int	power = round(unit->PID_heat->OutP);
 				if (unit->heater_state != power) {
@@ -1442,7 +1446,6 @@
 			} 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, "Unit `%s' heater On => Off", unit->name);
@@ -1457,10 +1460,9 @@
 		    }
 
 		    if (unit->cooler_address && ! unit->heater_state) {
-			if (unit->PID_cool->OutP >= 1) {
+			if (unit->PID_cool->OutP >= 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 {
 				int	power = round(unit->PID_cool->OutP); 
 				if (unit->cooler_state != power) {
@@ -1471,7 +1473,6 @@
 			} 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, "Unit `%s' cooler On => Off", unit->name);

mercurial