1140 * unit->prof_primary_done - time when primary fermentation was over the peak. |
1140 * unit->prof_primary_done - time when primary fermentation was over the peak. |
1141 */ |
1141 */ |
1142 for (profile = Config.profiles; profile; profile = profile->next) { |
1142 for (profile = Config.profiles; profile; profile = profile->next) { |
1143 if (strcmp(unit->profile, profile->uuid) == 0) { |
1143 if (strcmp(unit->profile, profile->uuid) == 0) { |
1144 |
1144 |
|
1145 /* |
|
1146 * Safe defaults |
|
1147 */ |
|
1148 unit->prof_target_lo = profile->inittemp_lo; |
|
1149 unit->prof_target_hi = profile->inittemp_hi; |
|
1150 unit->prof_fridge_mode = 0; |
|
1151 |
1145 switch (unit->prof_state) { |
1152 switch (unit->prof_state) { |
1146 case PROFILE_OFF: |
1153 case PROFILE_OFF: |
1147 unit->prof_target_lo = profile->inittemp_lo; |
1154 // unit->prof_target_lo = profile->inittemp_lo; |
1148 unit->prof_target_hi = profile->inittemp_hi; |
1155 // unit->prof_target_hi = profile->inittemp_hi; |
1149 unit->prof_fridge_mode = 0; |
1156 // unit->prof_fridge_mode = 0; |
1150 unit->prof_percent = 0; |
1157 unit->prof_percent = 0; |
1151 break; |
1158 break; |
1152 case PROFILE_PAUSE: |
1159 case PROFILE_PAUSE: |
1153 /* |
1160 /* |
1154 * Keep current temperature, measure pause time. For |
1161 * Keep current temperature, measure pause time. For |
1160 * Calculate current profile step and desired temperature. |
1167 * Calculate current profile step and desired temperature. |
1161 * When all steps are done, set state to PROFILE_DONE. |
1168 * When all steps are done, set state to PROFILE_DONE. |
1162 */ |
1169 */ |
1163 previous_target_lo = profile->inittemp_lo; |
1170 previous_target_lo = profile->inittemp_lo; |
1164 previous_target_hi = profile->inittemp_hi; |
1171 previous_target_hi = profile->inittemp_hi; |
|
1172 previous_fridge_mode = profile->fridge_mode; |
1165 time_until_now = current_step = 0; |
1173 time_until_now = current_step = 0; |
1166 run_seconds = (int)(now - unit->prof_started - unit->prof_paused); |
1174 run_seconds = (int)(now - unit->prof_started - unit->prof_paused); |
1167 run_minutes = run_seconds / 60; |
1175 run_minutes = run_seconds / 60; |
1168 run_hours = run_minutes / 60; |
1176 run_hours = run_minutes / 60; |
1169 if (debug) |
1177 if (debug) |
1225 current_step, run_hours - time_until_now, |
1233 current_step, run_hours - time_until_now, |
1226 step->steptime, step->resttime, step->target_lo, step->target_hi); |
1234 step->steptime, step->resttime, step->target_lo, step->target_hi); |
1227 if ((run_hours - time_until_now) < step->steptime) { |
1235 if ((run_hours - time_until_now) < step->steptime) { |
1228 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); |
1236 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); |
1229 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); |
1237 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); |
|
1238 // FIXME: shift fridge_mode |
1230 if (debug) |
1239 if (debug) |
1231 fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", |
1240 fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", |
1232 step->target_lo - previous_target_lo, |
1241 step->target_lo - previous_target_lo, |
1233 step->target_hi - previous_target_hi, |
1242 step->target_hi - previous_target_hi, |
1234 run_minutes - (time_until_now * 60), |
1243 run_minutes - (time_until_now * 60), |
1235 step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi); |
1244 step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi); |
1236 } else { |
1245 } else { |
1237 unit->prof_target_lo = step->target_lo; |
1246 unit->prof_target_lo = step->target_lo; |
1238 unit->prof_target_hi = step->target_hi; |
1247 unit->prof_target_hi = step->target_hi; |
|
1248 unit->prof_fridge_mode = step->fridge_mode; |
1239 if (debug) |
1249 if (debug) |
1240 fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi); |
1250 fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi); |
1241 } |
1251 } |
1242 break; |
1252 break; |
1243 } |
1253 } |
1244 time_until_now += step->steptime + step->resttime; |
1254 time_until_now += step->steptime + step->resttime; |
1245 previous_target_lo = step->target_lo; |
1255 previous_target_lo = step->target_lo; |
1246 previous_target_hi = step->target_hi; |
1256 previous_target_hi = step->target_hi; |
|
1257 previous_fridge_mode = step->fridge_mode; |
1247 } |
1258 } |
1248 if (debug) |
1259 if (debug) |
1249 fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds); |
1260 fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds); |
1250 |
1261 |
1251 if (valid_step == TRUE) { |
1262 if (valid_step == TRUE) { |
1270 /* |
1281 /* |
1271 * Keep this state, set target temperature to the last step. |
1282 * Keep this state, set target temperature to the last step. |
1272 */ |
1283 */ |
1273 previous_target_lo = profile->inittemp_lo; |
1284 previous_target_lo = profile->inittemp_lo; |
1274 previous_target_hi = profile->inittemp_hi; |
1285 previous_target_hi = profile->inittemp_hi; |
1275 unit->prof_fridge_mode = profile->fridge_mode; |
1286 previous_fridge_mode = profile->fridge_mode; |
1276 for (step = profile->steps; step; step = step->next) { |
1287 for (step = profile->steps; step; step = step->next) { |
1277 if (step->steptime == 0) |
1288 if ((step->steptime + step->resttime) == 0) |
1278 break; |
1289 break; |
1279 previous_target_lo = step->target_lo; |
1290 previous_target_lo = step->target_lo; |
1280 previous_target_hi = step->target_hi; |
1291 previous_target_hi = step->target_hi; |
1281 unit->prof_fridge_mode = step->fridge_mode; |
1292 previous_fridge_mode = step->fridge_mode; |
1282 |
1293 |
1283 } |
1294 } |
1284 unit->prof_target_lo = previous_target_lo; |
1295 unit->prof_target_lo = previous_target_lo; |
1285 unit->prof_target_hi = previous_target_hi; |
1296 unit->prof_target_hi = previous_target_hi; |
1286 unit->prof_fridge_mode = step->fridge_mode; |
1297 unit->prof_fridge_mode = previous_fridge_mode; |
1287 unit->prof_percent = 100; |
1298 unit->prof_percent = 100; |
1288 break; |
1299 break; |
1289 } /* switch */ |
1300 } /* switch */ |
1290 } |
1301 } |
1291 } |
1302 } |