thermferm/thermferm.c

changeset 401
0226d0f37bb7
parent 398
efdfef1677d1
child 402
6b9f0c3c7f63
--- a/thermferm/thermferm.c	Thu Sep 17 15:52:46 2015 +0200
+++ b/thermferm/thermferm.c	Thu Sep 17 17:01:15 2015 +0200
@@ -1227,7 +1227,7 @@
 							 * This is our current step
 							 */
 							valid_step = TRUE;
-							unit->prof_fridge_mode = step->fridge_mode;
+//							unit->prof_fridge_mode = step->fridge_mode;
 							if (debug)
 							    fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ", 
 									    current_step, run_hours - time_until_now,
@@ -1235,7 +1235,16 @@
 							if ((run_hours - time_until_now) < step->steptime) {
 							    unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo));
 							    unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi));
-							    // FIXME: shift fridge_mode
+							    if (step->fridge_mode > previous_fridge_mode) {
+							    	unit->prof_fridge_mode = (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
+							    } else if (step->fridge_mode < previous_fridge_mode) {
+								unit->prof_fridge_mode = 100 - (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
+							    } else {
+								unit->prof_fridge_mode = step->fridge_mode;
+							    }
+							    if (debug)
+								fprintf(stdout, "%d/%d/%d ", previous_fridge_mode, step->fridge_mode, unit->prof_fridge_mode);
+
 							    if (debug)
 								fprintf(stdout, "tempshift=%.1f..%.1f  minutes=%d duration=%d temp_move=%.3f..%.3f ", 
 										step->target_lo - previous_target_lo,
@@ -1390,20 +1399,28 @@
 		     */
 		    unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
 		    if (unit->mode == UNITMODE_FRIDGE) {
-			unit->PID_cool->SetP = unit->PID_heat->SetP = unit->fridge_set;
+			unit->PID_cool->SetP = unit->fridge_set;
+			unit->PID_heat->SetP = unit->fridge_set;
 			unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0;
 			unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO;
 		    } else if (unit->mode == UNITMODE_BEER) {
-			unit->PID_cool->SetP = unit->PID_heat->SetP = unit->beer_set;
+			unit->PID_cool->SetP = unit->beer_set;
+			unit->PID_heat->SetP = unit->beer_set;
 			unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
 			unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
 		    } else if (unit->mode == UNITMODE_PROFILE) {
+			double  usetemp;
 			unit->PID_cool->SetP = unit->prof_target_hi;
 			unit->PID_heat->SetP = unit->prof_target_lo;
-			if (unit->prof_fridge_mode)
-			    unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0;
-			else
-			    unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
+			/*
+			 * Get percentage to use from each thermometer. unit->prof_fridge_mode = 0..100
+			 */
+			usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) +
+			          ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0;
+			if (debug)
+			    fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode,
+					    unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp);
+			unit->PID_cool->Input = unit->PID_heat->Input = usetemp;
 			unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
 		    }
 

mercurial