thermferm/thermferm.c

changeset 221
91a5e7281c35
parent 219
ae720212accc
child 223
14700edd2a67
--- a/thermferm/thermferm.c	Mon Aug 11 19:17:32 2014 +0200
+++ b/thermferm/thermferm.c	Tue Aug 12 12:42:15 2014 +0200
@@ -343,7 +343,7 @@
 #else
     long		t = 0;
 #endif
-    int			current_step, time_in_step, time_until_now;
+    int			current_step, valid_step, time_until_now;
     float		previous_target;
 
     if (lockprog((char *)"thermferm")) {
@@ -576,50 +576,52 @@
 						run_minutes = run_seconds / 60;
 						run_hours = run_minutes / 60;
 						if (debug)
-						    fprintf(stdout, "run_hours=%d minutes=%d seconds=%d ", run_hours, run_minutes, run_seconds);
-
-						for (step = profile->steps; step; step = step->next) {
+						    fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
 
-						    if (step->steptime == 0) {
-							unit->prof_state = PROFILE_DONE;
-							syslog(LOG_NOTICE, "Profile is done");
-							break;
-						    }
-
+						valid_step = FALSE;
+						for (step = profile->steps; step; step = step->next) {
 						    /*
 						     * step->steptime
 						     * step->resttime
 						     * step->target
 						     */
-						    time_in_step = step->steptime + step->resttime;
 						    current_step++;
-						    if ((run_hours >= time_until_now) && (run_hours < (time_until_now + time_in_step))) {
+						    if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) {
 							/*
 							 * This is our current step
 							 */
+							valid_step = TRUE;
 							if (debug)
-							    fprintf(stdout, "step=%d step_pos=%d step_length=%d steptime=%d resttime=%d target=%.1f ", 
-									    current_step, run_hours - time_until_now, time_in_step, step->steptime, step->resttime, step->target);
+							    fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f ", 
+									    current_step, run_hours - time_until_now,
+									    step->steptime, step->resttime, step->target);
 							if ((run_hours - time_until_now) < step->steptime) {
 							    unit->prof_target = previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target));
 							    if (debug)
 								fprintf(stdout, "tempshift=%.1f  minutes=%d duration=%d temp_move=%.3f ", 
 										step->target - previous_target, run_minutes - (time_until_now * 60), 
-										step->steptime * 60, 
-								   previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target))
-								 );
+										step->steptime * 60, unit->prof_target);
 							} else {
 							    unit->prof_target = step->target;
 							    fprintf(stdout, "resting target=%.1f ", step->target);
 							}
 							break;
 						    }
-						    time_until_now += time_in_step;
+						    time_until_now += step->steptime + step->resttime;
 						    previous_target = step->target;
 						}
 						if (debug)
-						    fprintf(stdout, "\n");
+						    fprintf(stdout, " %s\n", valid_step ? "TRUE":"FALSE");
+
+						/*
+						 * No more steps to do
+						 */
+						if (valid_step == FALSE) {
+						    unit->prof_state = PROFILE_DONE;
+						    syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
+						}
 						break;
+
 				case PROFILE_DONE:
 						/*
 						 * Keep this state, set target temperature to the last step.

mercurial