thermferm/thermferm.c

changeset 221
91a5e7281c35
parent 219
ae720212accc
child 223
14700edd2a67
equal deleted inserted replaced
220:382938c5fce2 221:91a5e7281c35
341 struct tm *tm; 341 struct tm *tm;
342 int row, key; 342 int row, key;
343 #else 343 #else
344 long t = 0; 344 long t = 0;
345 #endif 345 #endif
346 int current_step, time_in_step, time_until_now; 346 int current_step, valid_step, time_until_now;
347 float previous_target; 347 float previous_target;
348 348
349 if (lockprog((char *)"thermferm")) { 349 if (lockprog((char *)"thermferm")) {
350 syslog(LOG_NOTICE, "Can't lock"); 350 syslog(LOG_NOTICE, "Can't lock");
351 return 1; 351 return 1;
574 current_step = 0; 574 current_step = 0;
575 run_seconds = (int)(now - unit->prof_started - unit->prof_paused); 575 run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
576 run_minutes = run_seconds / 60; 576 run_minutes = run_seconds / 60;
577 run_hours = run_minutes / 60; 577 run_hours = run_minutes / 60;
578 if (debug) 578 if (debug)
579 fprintf(stdout, "run_hours=%d minutes=%d seconds=%d ", run_hours, run_minutes, run_seconds); 579 fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
580 580
581 valid_step = FALSE;
581 for (step = profile->steps; step; step = step->next) { 582 for (step = profile->steps; step; step = step->next) {
582
583 if (step->steptime == 0) {
584 unit->prof_state = PROFILE_DONE;
585 syslog(LOG_NOTICE, "Profile is done");
586 break;
587 }
588
589 /* 583 /*
590 * step->steptime 584 * step->steptime
591 * step->resttime 585 * step->resttime
592 * step->target 586 * step->target
593 */ 587 */
594 time_in_step = step->steptime + step->resttime;
595 current_step++; 588 current_step++;
596 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + time_in_step))) { 589 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) {
597 /* 590 /*
598 * This is our current step 591 * This is our current step
599 */ 592 */
593 valid_step = TRUE;
600 if (debug) 594 if (debug)
601 fprintf(stdout, "step=%d step_pos=%d step_length=%d steptime=%d resttime=%d target=%.1f ", 595 fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f ",
602 current_step, run_hours - time_until_now, time_in_step, step->steptime, step->resttime, step->target); 596 current_step, run_hours - time_until_now,
597 step->steptime, step->resttime, step->target);
603 if ((run_hours - time_until_now) < step->steptime) { 598 if ((run_hours - time_until_now) < step->steptime) {
604 unit->prof_target = previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target)); 599 unit->prof_target = previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target));
605 if (debug) 600 if (debug)
606 fprintf(stdout, "tempshift=%.1f minutes=%d duration=%d temp_move=%.3f ", 601 fprintf(stdout, "tempshift=%.1f minutes=%d duration=%d temp_move=%.3f ",
607 step->target - previous_target, run_minutes - (time_until_now * 60), 602 step->target - previous_target, run_minutes - (time_until_now * 60),
608 step->steptime * 60, 603 step->steptime * 60, unit->prof_target);
609 previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target))
610 );
611 } else { 604 } else {
612 unit->prof_target = step->target; 605 unit->prof_target = step->target;
613 fprintf(stdout, "resting target=%.1f ", step->target); 606 fprintf(stdout, "resting target=%.1f ", step->target);
614 } 607 }
615 break; 608 break;
616 } 609 }
617 time_until_now += time_in_step; 610 time_until_now += step->steptime + step->resttime;
618 previous_target = step->target; 611 previous_target = step->target;
619 } 612 }
620 if (debug) 613 if (debug)
621 fprintf(stdout, "\n"); 614 fprintf(stdout, " %s\n", valid_step ? "TRUE":"FALSE");
615
616 /*
617 * No more steps to do
618 */
619 if (valid_step == FALSE) {
620 unit->prof_state = PROFILE_DONE;
621 syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
622 }
622 break; 623 break;
624
623 case PROFILE_DONE: 625 case PROFILE_DONE:
624 /* 626 /*
625 * Keep this state, set target temperature to the last step. 627 * Keep this state, set target temperature to the last step.
626 */ 628 */
627 previous_target = profile->inittemp; 629 previous_target = profile->inittemp;

mercurial