# HG changeset patch # User Michiel Broek # Date 1407840135 -7200 # Node ID 91a5e7281c3583c1cdc22276ace4df796d7b7416 # Parent 382938c5fce21bf134cbd2f7314ebd32412d9a75 Fixed end of profile steps, didn't go to the PROFILE_DONE state. diff -r 382938c5fce2 -r 91a5e7281c35 thermferm/thermferm.c --- 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.