thermferm/thermferm.c

changeset 194
9eaaba49450f
parent 189
cc2b04d4db99
child 195
b34a1b2421fb
--- a/thermferm/thermferm.c	Thu Aug 07 21:19:30 2014 +0200
+++ b/thermferm/thermferm.c	Thu Aug 07 22:06:18 2014 +0200
@@ -248,7 +248,10 @@
     char                buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40];
     time_t		now, last = (time_t)0;
     units_list		*unit;
+    profiles_list	*profile;
+    prof_step		*step;
     int			rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation;
+    int			run_seconds, run_minutes, run_hours;
     float		err = 0.0, sp, pv, P_err, D_err, Out;
 #ifdef HAVE_WIRINGPI_H
     struct tm		*tm;
@@ -421,11 +424,47 @@
 		     * unit->prof_started	- start time or 0 if not yet running.
 		     * unit->prof_state		- PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
 		     * unit->prof_target	- Calculated target temperature.
+		     * unit->prof_paused	- Internal pause counter.
 		     */
-		    // off.  Target is ??
-		    // pause Target is keep target.
-		    // run.  Target must be calculated using steps.
-		    // done. Target is last target.
+		    for (profile = Config.profiles; profile; profile = profile->next) {
+			if (strcmp(unit->profile, profile->uuid) == 0) {
+			    /*
+			     * Set initial temperature for this profile.
+			     */
+			    switch (unit->prof_state) {
+				case PROFILE_OFF:
+						/*
+						 * Setup initial temperature.
+						 */
+			    			unit->prof_target = profile->inittemp;
+						break;
+				case PROFILE_PAUSE:
+						/*
+						 * Keep current temperature, measure pause time.
+						 */
+						break;
+				case PROFILE_RUN:
+						/*
+						 * Calculate current profile step en desired temperature.
+						 * When all done, set state to PROFILE_DONE.
+						 */
+						run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
+						run_minutes = run_seconds / 60;
+						run_hours = run_minutes / 60;
+						if (debug)
+						    fprintf(stdout, "run_hours=%d minutes=%d seconds=%d\n", run_hours, run_minutes, run_seconds);
+
+						for (step = profile->steps; step; step = step->next) {
+						}
+						break;
+				case PROFILE_DONE:
+						/*
+						 * Keep this state.
+						 */
+						break;
+			    } /* switch */
+			}
+		    }
 		}
 
 		/*

mercurial