1511 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) { |
1511 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) { |
1512 /* |
1512 /* |
1513 * This is our current step |
1513 * This is our current step |
1514 */ |
1514 */ |
1515 valid_step = TRUE; |
1515 valid_step = TRUE; |
1516 // if (debug) |
|
1517 // fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ", |
|
1518 // current_step, run_hours - time_until_now, |
|
1519 // step->steptime, step->resttime, step->target_lo, step->target_hi); |
|
1520 if ((run_hours - time_until_now) < step->steptime) { |
1516 if ((run_hours - time_until_now) < step->steptime) { |
1521 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); |
1517 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); |
1522 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); |
1518 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); |
1523 if (step->fridge_mode > previous_fridge_mode) { |
1519 if (step->fridge_mode > previous_fridge_mode) { |
1524 unit->prof_fridge_mode = (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60)); |
1520 unit->prof_fridge_mode = (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60)); |
1528 unit->prof_fridge_mode = step->fridge_mode; |
1524 unit->prof_fridge_mode = step->fridge_mode; |
1529 } |
1525 } |
1530 if (debug) |
1526 if (debug) |
1531 fprintf(stdout, "prof_fridge_mode=%d run_minutes=%d steptime=%d time_until_now=%d\n", |
1527 fprintf(stdout, "prof_fridge_mode=%d run_minutes=%d steptime=%d time_until_now=%d\n", |
1532 unit->prof_fridge_mode, run_minutes, step->steptime, time_until_now); |
1528 unit->prof_fridge_mode, run_minutes, step->steptime, time_until_now); |
1533 // if (debug) |
|
1534 // fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", |
|
1535 // step->target_lo - previous_target_lo, |
|
1536 // step->target_hi - previous_target_hi, |
|
1537 // run_minutes - (time_until_now * 60), |
|
1538 // step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi); |
|
1539 } else { |
1529 } else { |
1540 unit->prof_target_lo = step->target_lo; |
1530 unit->prof_target_lo = step->target_lo; |
1541 unit->prof_target_hi = step->target_hi; |
1531 unit->prof_target_hi = step->target_hi; |
1542 unit->prof_fridge_mode = step->fridge_mode; |
1532 unit->prof_fridge_mode = step->fridge_mode; |
1543 // if (debug) |
|
1544 // fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi); |
|
1545 } |
1533 } |
1546 break; |
1534 break; |
1547 } |
1535 } |
1548 time_until_now += step->steptime + step->resttime; |
1536 time_until_now += step->steptime + step->resttime; |
1549 previous_target_lo = step->target_lo; |
1537 previous_target_lo = step->target_lo; |
1550 previous_target_hi = step->target_hi; |
1538 previous_target_hi = step->target_hi; |
1551 previous_fridge_mode = step->fridge_mode; |
1539 previous_fridge_mode = step->fridge_mode; |
1552 } |
1540 } |
1553 // if (debug) |
|
1554 // fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds); |
|
1555 |
1541 |
1556 if (valid_step == TRUE) { |
1542 if (valid_step == TRUE) { |
1557 unit->prof_percent = (100 * run_minutes) / tot_minutes; |
1543 unit->prof_percent = (100 * run_minutes) / tot_minutes; |
1558 if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) { |
1544 if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) { |
1559 syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, fridge/beer %d%% %.3f..%.3f degrees", |
1545 syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, fridge/beer %d%% %.3f..%.3f degrees", |
1675 /* |
1661 /* |
1676 * Get percentage to use from each thermometer. unit->prof_fridge_mode = 0..100 |
1662 * Get percentage to use from each thermometer. unit->prof_fridge_mode = 0..100 |
1677 */ |
1663 */ |
1678 usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) + |
1664 usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) + |
1679 ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0; |
1665 ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0; |
1680 if (debug) |
|
1681 fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode, |
|
1682 unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp); |
|
1683 unit->PID_cool->Input = unit->PID_heat->Input = usetemp; |
1666 unit->PID_cool->Input = unit->PID_heat->Input = usetemp; |
1684 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; |
1667 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; |
1685 } |
1668 } |
1686 |
1669 |
1687 /* |
1670 /* |