thermferm/thermferm.c

changeset 289
d810df0df36a
parent 288
8b99ab77262b
child 293
881b1ae75468
equal deleted inserted replaced
288:8b99ab77262b 289:d810df0df36a
603 if ((key == KEY_DOWN) || (key == KEY_UP)) 603 if ((key == KEY_DOWN) || (key == KEY_UP))
604 go_menu(MENU_PROFILE_SELECT); 604 go_menu(MENU_PROFILE_SELECT);
605 if (key == KEY_ENTER) { 605 if (key == KEY_ENTER) {
606 current_unit->prof_state = PROFILE_RUN; 606 current_unit->prof_state = PROFILE_RUN;
607 current_unit->prof_started = time(NULL); 607 current_unit->prof_started = time(NULL);
608 current_unit->prof_paused = 0; 608 current_unit->prof_paused = current_unit->prof_primary_done = 0;
609 current_unit->prof_peak_abs = current_unit->prof_peak_rel = 0.0;
609 syslog(LOG_NOTICE, "Profile started from the panel"); 610 syslog(LOG_NOTICE, "Profile started from the panel");
610 go_menu(MENU_MODE_PROFILE); 611 go_menu(MENU_MODE_PROFILE);
611 } 612 }
612 break; 613 break;
613 614
1103 * unit->profile - uuid of the selected profile. 1104 * unit->profile - uuid of the selected profile.
1104 * unit->prof_started - start time or 0 if not yet running. 1105 * unit->prof_started - start time or 0 if not yet running.
1105 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE 1106 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
1106 * unit->prof_target - Calculated target temperature. 1107 * unit->prof_target - Calculated target temperature.
1107 * unit->prof_paused - Internal pause counter. 1108 * unit->prof_paused - Internal pause counter.
1109 * unit->prof_peak_abs - Peak temperature of the beer.
1110 * unit->prof_peak_rel - Peak temperature between beer and fridge.
1111 * unit->prof_primary_done - time when primary fermentation was over the peak.
1108 */ 1112 */
1109 for (profile = Config.profiles; profile; profile = profile->next) { 1113 for (profile = Config.profiles; profile; profile = profile->next) {
1110 if (strcmp(unit->profile, profile->uuid) == 0) { 1114 if (strcmp(unit->profile, profile->uuid) == 0) {
1111 1115
1112 switch (unit->prof_state) { 1116 switch (unit->prof_state) {
1130 run_seconds = (int)(now - unit->prof_started - unit->prof_paused); 1134 run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
1131 run_minutes = run_seconds / 60; 1135 run_minutes = run_seconds / 60;
1132 run_hours = run_minutes / 60; 1136 run_hours = run_minutes / 60;
1133 if (debug) 1137 if (debug)
1134 fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds); 1138 fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
1139
1140 /*
1141 * Primary fermentation tests
1142 */
1143 if ((unit->beer_temperature / 1000.0) > unit->prof_peak_abs)
1144 unit->prof_peak_abs = unit->beer_temperature / 1000.0;
1145 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) > unit->prof_peak_rel)
1146 unit->prof_peak_rel = (unit->beer_temperature - unit->air_temperature) / 1000.0;
1147 if (unit->prof_primary_done == 0) {
1148 if (unit->cooler_address) {
1149 /*
1150 * There is a cooler. If the difference between the beer and air temperature
1151 * drops we assume the primary fermentation is done.
1152 */
1153 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) {
1154 unit->prof_primary_done = time(NULL);
1155 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", profile->name);
1156 }
1157 } else {
1158 /*
1159 * This method works if the unit has no cooling or if the profile allowd the
1160 * beer temperature to rise freely.
1161 */
1162 if ((unit->beer_temperature / 1000.0) < (unit->prof_peak_abs - 0.5)) {
1163 unit->prof_primary_done = time(NULL);
1164 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", profile->name);
1165 }
1166 }
1167 }
1135 1168
1136 /* 1169 /*
1137 * See how long this profile will take 1170 * See how long this profile will take
1138 */ 1171 */
1139 tot_minutes = 0; 1172 tot_minutes = 0;

mercurial