thermferm/thermferm.c

changeset 289
d810df0df36a
parent 288
8b99ab77262b
child 293
881b1ae75468
--- a/thermferm/thermferm.c	Wed Oct 22 12:42:20 2014 +0200
+++ b/thermferm/thermferm.c	Sat Oct 25 21:08:47 2014 +0200
@@ -605,7 +605,8 @@
 			if (key == KEY_ENTER) {
 			    current_unit->prof_state = PROFILE_RUN;
 			    current_unit->prof_started = time(NULL);
-			    current_unit->prof_paused = 0;
+			    current_unit->prof_paused = current_unit->prof_primary_done = 0;
+			    current_unit->prof_peak_abs = current_unit->prof_peak_rel = 0.0;
 			    syslog(LOG_NOTICE, "Profile started from the panel");
 			    go_menu(MENU_MODE_PROFILE);
 			}
@@ -1105,6 +1106,9 @@
 		     * unit->prof_state		- PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
 		     * unit->prof_target	- Calculated target temperature.
 		     * unit->prof_paused	- Internal pause counter.
+		     * unit->prof_peak_abs	- Peak temperature of the beer.
+		     * unit->prof_peak_rel	- Peak temperature between beer and fridge.
+		     * unit->prof_primary_done	- time when primary fermentation was over the peak.
 		     */
 		    for (profile = Config.profiles; profile; profile = profile->next) {
 			if (strcmp(unit->profile, profile->uuid) == 0) {
@@ -1134,6 +1138,35 @@
 						    fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
 
 						/*
+						 * Primary fermentation tests
+						 */
+						if ((unit->beer_temperature / 1000.0) > unit->prof_peak_abs)
+						    unit->prof_peak_abs = unit->beer_temperature / 1000.0;
+						if (((unit->beer_temperature - unit->air_temperature) / 1000.0) > unit->prof_peak_rel)
+						    unit->prof_peak_rel = (unit->beer_temperature - unit->air_temperature) / 1000.0;
+						if (unit->prof_primary_done == 0) {
+						    if (unit->cooler_address) {
+							/*
+							 * There is a cooler. If the difference between the beer and air temperature
+							 * drops we assume the primary fermentation is done.
+							 */
+							if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) {
+							    unit->prof_primary_done = time(NULL);
+							    syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", profile->name);
+							}
+						    } else {
+						    	/*
+						    	 * This method works if the unit has no cooling or if the profile allowd the
+						    	 * beer temperature to rise freely.
+						    	 */
+						    	if ((unit->beer_temperature / 1000.0) <  (unit->prof_peak_abs - 0.5)) {
+							    unit->prof_primary_done = time(NULL);
+							    syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", profile->name);
+						    	}
+						    }
+						}
+
+						/*
 						 * See how long this profile will take
 						 */
 						tot_minutes = 0;

mercurial