Beginning of the main program loop

Fri, 11 Dec 2015 15:52:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 11 Dec 2015 15:52:37 +0100
changeset 454
78242696c15a
parent 453
76418c89b480
child 455
f84501d8dd87

Beginning of the main program loop

brewco/brewco.c file | annotate | diff | comparison | revisions
brewco/pid.c file | annotate | diff | comparison | revisions
--- a/brewco/brewco.c	Thu Dec 10 21:34:28 2015 +0100
+++ b/brewco/brewco.c	Fri Dec 11 15:52:37 2015 +0100
@@ -226,13 +226,15 @@
 int server(void)
 {
     int 		rc = 0, run = 1, key;
-    int			do_init = TRUE;
+    int			do_init = TRUE, seconds = 0, minutes = 0;
     units_list		*unit;
     brew_session	*brew = NULL;
 #ifndef HAVE_WIRINGPI_H
     long		t = 0;
 #endif
-    double		hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint;
+    struct tm		*tm;
+    time_t		now, last = (time_t)0;
+    static double	hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint;
 
     prompt(101, NULL);
 
@@ -396,11 +398,42 @@
 	    PID_setOutputLimits(unit->PID_mlt, 0, 5000);
 	    PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime);
 
+	    prompt(0, NULL);
+	    prompt(101, NULL);
+	    prompt(401, NULL);
+	    manual = MANUAL_NONE;
+
 	    do_init = FALSE;
 	}
 
 	/* run_pause code here */
 
+	/*
+	 * Update PID's, even if they are off. Both PID's will do
+	 * the scheduling by themselves.
+	 */
+	rc = PID_compute(unit->PID_hlt);
+//	if (seconds < 3)
+//	fprintf(stdout, "hlt rc=%d");
+	rc = PID_compute(unit->PID_mlt);
+//	if (seconds < 3)
+//		        fprintf(stdout, "   mlt rc=%d\n");
+
+	now = time(NULL);
+	if (now != last) {
+	    /*
+	     * Each second
+	     */
+	    last = now;
+	    seconds++;
+fprintf(stdout, "1 second %ld millis\n", millis());
+	    if (debug && ((seconds % 10) == 1)) {
+		fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf  HLT: In=%.2lf Out=%.2lf Set=%.2lf\n",
+				mltInput, mltOutput, mltSetpoint, hltInput, hltOutput, hltSetpoint);
+	    }
+
+	}
+
 	if (brew) {
 	    /*
 	     * Automate mode
@@ -411,23 +444,31 @@
 	     * Manual mode
 	     */
 	    manual_menu(unit);
+	    if (manual == MANUAL_NONE) {
+		/*
+		 * Rewrite the display
+		 */
+		prompt(0, NULL);
+		prompt(101, NULL);
+		prompt(401, NULL);
+	    }
 	} else {
 	    /*
 	     * Not running.
 	     */
-	    prompt(0, NULL);
-	    prompt(101, NULL);
-	    prompt(401, NULL);
 	    tempstatus(120.3, 165.34);
-	    key = keywait();
-	    if (key == KEY_ENTER)
+	    key = keycheck();
+	    if (key == KEY_ENTER) {
 		setup();
-	    else if (key == KEY_DOWN) {
+		prompt(0, NULL);
+		prompt(101, NULL);
+		prompt(401, NULL);
+	    } else if (key == KEY_DOWN) {
 		manual = MANUAL_SELHLT;
 	    }
 	}
 
-	usleep(10000);	/* 10 mSec */
+	usleep(5000);	/* 5 mSec */
 
     } while (run);
 
--- a/brewco/pid.c	Thu Dec 10 21:34:28 2015 +0100
+++ b/brewco/pid.c	Fri Dec 11 15:52:37 2015 +0100
@@ -246,6 +246,7 @@
 	    output = pid->outMax;
 	else if (output < pid->outMin)
 	    output = pid->outMin;
+	*pid->myOutput = output;
 
 	/*
 	 * Remember some variables for the next time

mercurial