diff -r 66d4e137b99d -r 00ca08f5a6f8 thermferm/thermferm.c --- a/thermferm/thermferm.c Tue Sep 15 17:29:15 2015 +0200 +++ b/thermferm/thermferm.c Wed Sep 16 22:05:05 2015 +0200 @@ -811,7 +811,7 @@ int server(void) { - char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40]; + char buf[1024], *filename, target_lo[40], target_hi[40], heater[40], cooler[40], fan[40], door[40]; char use_heater[40], use_cooler[40], use_fan[40], room_temp[40]; time_t now, last = (time_t)0; units_list *unit; @@ -826,7 +826,7 @@ long t = 0; #endif int current_step, valid_step, time_until_now; - float previous_target; + float previous_target_lo, previous_target_hi; if (lockprog((char *)"thermferm")) { @@ -1144,7 +1144,9 @@ switch (unit->prof_state) { case PROFILE_OFF: - unit->prof_target = profile->inittemp; + unit->prof_target_lo = profile->inittemp_lo; + unit->prof_target_hi = profile->inittemp_hi; + unit->prof_fridge_mode = 0; unit->prof_percent = 0; break; case PROFILE_PAUSE: @@ -1158,7 +1160,8 @@ * Calculate current profile step and desired temperature. * When all steps are done, set state to PROFILE_DONE. */ - previous_target = profile->inittemp; + previous_target_lo = profile->inittemp_lo; + previous_target_hi = profile->inittemp_hi; time_until_now = current_step = 0; run_seconds = (int)(now - unit->prof_started - unit->prof_paused); run_minutes = run_seconds / 60; @@ -1216,24 +1219,31 @@ * This is our current step */ valid_step = TRUE; + unit->prof_fridge_mode = step->fridge_mode; if (debug) - fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f ", + fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ", current_step, run_hours - time_until_now, - step->steptime, step->resttime, step->target); + step->steptime, step->resttime, step->target_lo, step->target_hi); 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)); + 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)); 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, unit->prof_target); + fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", + step->target_lo - previous_target_lo, + step->target_hi - previous_target_hi, + run_minutes - (time_until_now * 60), + step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi); } else { - unit->prof_target = step->target; - fprintf(stdout, "resting target=%.1f ", step->target); + unit->prof_target_lo = step->target_lo; + unit->prof_target_hi = step->target_hi; + if (debug) + fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi); } break; } time_until_now += step->steptime + step->resttime; - previous_target = step->target; + previous_target_lo = step->target_lo; + previous_target_hi = step->target_hi; } if (debug) fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds); @@ -1241,9 +1251,10 @@ if (valid_step == TRUE) { unit->prof_percent = (100 * run_minutes) / tot_minutes; if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) { - syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %.3f degrees", + syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %s %.3f..%.3f degrees", profile->name, run_hours / 24, run_hours % 24, run_minutes % 60, current_step, - unit->prof_percent, unit->prof_target); + unit->prof_percent, unit->prof_fridge_mode ? (char *)"air":(char *)"beer", + unit->prof_target_lo, unit->prof_target_hi); } } else { /* @@ -1259,13 +1270,20 @@ /* * Keep this state, set target temperature to the last step. */ - previous_target = profile->inittemp; + previous_target_lo = profile->inittemp_lo; + previous_target_hi = profile->inittemp_hi; + unit->prof_fridge_mode = profile->fridge_mode; for (step = profile->steps; step; step = step->next) { if (step->steptime == 0) break; - previous_target = step->target; + previous_target_lo = step->target_lo; + previous_target_hi = step->target_hi; + unit->prof_fridge_mode = step->fridge_mode; + } - unit->prof_target = previous_target; + unit->prof_target_lo = previous_target_lo; + unit->prof_target_hi = previous_target_hi; + unit->prof_fridge_mode = step->fridge_mode; unit->prof_percent = 100; break; } /* switch */ @@ -1369,8 +1387,12 @@ 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) { - unit->PID_cool->SetP = unit->PID_heat->SetP = unit->prof_target; - unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0; + 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; unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; } @@ -1517,7 +1539,8 @@ for (unit = Config.units; unit; unit = unit->next) { if (unit->mode != UNITMODE_OFF) { - snprintf(target, 39, "NA"); + snprintf(target_lo, 39, "NA"); + snprintf(target_hi, 39, "NA"); snprintf(heater, 39, "NA"); snprintf(cooler, 39, "NA"); snprintf(fan, 39, "NA"); @@ -1527,12 +1550,16 @@ snprintf(use_fan, 39, "NA"); snprintf(room_temp, 39, "NA"); - if (unit->mode == UNITMODE_BEER) - snprintf(target, 39, "%.1f", unit->beer_set); - else if (unit->mode == UNITMODE_FRIDGE) - snprintf(target, 39, "%.1f", unit->fridge_set); - else if (unit->mode == UNITMODE_PROFILE) - snprintf(target, 39, "%.1f", unit->prof_target); + if (unit->mode == UNITMODE_BEER) { + snprintf(target_lo, 39, "%.1f", unit->beer_set); + snprintf(target_hi, 39, "%.1f", unit->beer_set); + } else if (unit->mode == UNITMODE_FRIDGE) { + snprintf(target_lo, 39, "%.1f", unit->fridge_set); + snprintf(target_hi, 39, "%.1f", unit->fridge_set); + } else if (unit->mode == UNITMODE_PROFILE) { + snprintf(target_lo, 39, "%.1f", unit->prof_target_lo); + snprintf(target_hi, 39, "%.1f", unit->prof_target_hi); + } if (unit->heater_address) { snprintf(heater, 39, "%d", unit->heater_state); @@ -1553,9 +1580,10 @@ snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0); } - snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s", + snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", UNITMODE[unit->mode], unit->air_temperature / 1000.0, - unit->beer_temperature / 1000.0, target, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp); + unit->beer_temperature / 1000.0, + target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi); filename = xstrcpy(unit->name); filename = xstrcat(filename, (char *)".log"); logger(filename, buf);