Changed internal storage of temperatures to float. Added 2 prompts. Added editors for float and integer values. Added most of brewunit edit functions.

Fri, 04 Dec 2015 22:57:23 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 04 Dec 2015 22:57:23 +0100
changeset 445
3ec477cda546
parent 444
eafb140a1ddd
child 446
78e9d5234d15

Changed internal storage of temperatures to float. Added 2 prompts. Added editors for float and integer values. Added most of brewunit edit functions.

brewco/README file | annotate | diff | comparison | revisions
brewco/brewco.h file | annotate | diff | comparison | revisions
brewco/futil.c file | annotate | diff | comparison | revisions
brewco/prompt.c file | annotate | diff | comparison | revisions
brewco/rdconfig.c file | annotate | diff | comparison | revisions
brewco/setup.c file | annotate | diff | comparison | revisions
--- a/brewco/README	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/README	Fri Dec 04 22:57:23 2015 +0100
@@ -1,4 +1,7 @@
 
+Intern temperatuur in Celcius, float 3 cijfers achter comma. 
+Als het systeem in Farenheid mode staat is alleen de
+presentatie in Farenheid.
 
 Er moeten meerdere installaties in.
 Iedere installatie heeft een MLT/brew kettle.
--- a/brewco/brewco.h	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/brewco.h	Fri Dec 04 22:57:23 2015 +0100
@@ -131,7 +131,7 @@
     int			pump_onmash;		/* 0/1				*/
     int			pump_mashout;		/* 0/1				*/
     int			pump_onboil;		/* 0/1 pump during boiling	*/
-    int			pump_stop;		/* 80..105 C			*/
+    float		pump_stop;		/* 80..105 C			*/
     int			skip_add;		/* 0/1 skip Add phase		*/
     int			skip_remove;		/* 0/1 skip Remove phase	*/
     int			skip_iodine;		/* 0/1 skip Iodine test		*/
@@ -197,7 +197,7 @@
     int			min;			/* Minimum temperature		*/
     int			max;			/* Maximum temperature		*/
     int			canskip;		/* 0/1 can we skip this step	*/
-    int			setpoint;		/* Temperature setpoint		*/
+    float		setpoint;		/* Temperature setpoint		*/
     int			skip;			/* Skip this step		*/
     int			duration;		/* Step duration		*/
 } mash_step;
--- a/brewco/futil.c	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/futil.c	Fri Dec 04 22:57:23 2015 +0100
@@ -75,3 +75,25 @@
 }
 
 
+/* From ArdBir */
+float Arrotonda025(float Num){
+    // Appoggio la parte intera
+    int Appoggio= (int)Num;
+
+    // Arrotondo il valore con peso 0.25
+    return Appoggio+(int)((Num-Appoggio)*1000/225)*0.25;
+}
+
+float ConvertiCtoF(float Num){        
+    Num = Num/16;              // Recupero il valore
+    Num = (Num*1.8)+32;          // Converto in °F
+    Num = Arrotonda025(Num);
+    return Num*16;              // Preparo il valore per la registrazione
+}
+float ConvertiFtoC(float Num){
+    Num = Num/16;              // Recupero il valore
+    Num = (Num-32)/1.8;            // Converto in °C
+    Num = Arrotonda025(Num);
+    return Num*16;              // Preparo il valore per la registrazione
+}
+
--- a/brewco/prompt.c	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/prompt.c	Fri Dec 04 22:57:23 2015 +0100
@@ -86,6 +86,10 @@
 			break;
 	case 132:	snprintf(message, Config.lcd_cols + 1, "   Toggle Yes/No    ");
 			break;
+	case 133:	snprintf(message, Config.lcd_cols + 1, " Change temperature ");
+			break;
+	case 134:	snprintf(message, Config.lcd_cols + 1, "    Change time     ");
+			break;
 	case 200:	snprintf(message, Config.lcd_cols + 1, text);
 			break;
 	case 202:	snprintf(message, Config.lcd_cols + 1, "   Manage Recipes   ");
--- a/brewco/rdconfig.c	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/rdconfig.c	Fri Dec 04 22:57:23 2015 +0100
@@ -376,7 +376,7 @@
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;
 	    }
-	    if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_STOP", "%d", unit->pump_stop)) < 0)) {
+	    if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_STOP", "%.3f", unit->pump_stop)) < 0)) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;
 	    }
@@ -774,7 +774,7 @@
 {
     xmlChar     *key;
     int         i, ival;
-    float       val;
+    float       fval;
     units_list  *unit, *tmp;
 
     unit = (units_list *)malloc(sizeof(units_list));
@@ -792,7 +792,7 @@
     unit->pump_onmash = 1;
     unit->pump_mashout = 0;
     unit->pump_onboil = 0;
-    unit->pump_stop = 90;
+    unit->pump_stop = 90.0;
     unit->skip_add = 0;
     unit->skip_remove = 0;
     unit->skip_iodine = 0;
@@ -988,8 +988,8 @@
 	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_STOP"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		unit->pump_stop = ival;
+	    if (sscanf((const char *)key, "%f", &fval) == 1)
+		unit->pump_stop = fval;
 	    xmlFree(key);
 	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"SKIP_ADD"))) {
@@ -1029,62 +1029,62 @@
 
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_IMAX"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->iMax = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->iMax = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_IGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->iGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->iGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_PGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->pGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->pGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_DGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->dGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->dGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_INPUT"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->Input = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->Input = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_ERR"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->Err = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->Err = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_ERRLAST"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->ErrLast = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->ErrLast = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_ISTATE"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->iState = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->iState = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_SETP"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->SetP = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->SetP = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_OUTP"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_hlt->OutP = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_hlt->OutP = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_MODE"))) {
@@ -1100,62 +1100,62 @@
 
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_IMAX"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->iMax = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->iMax = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_IGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->iGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->iGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_PGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->pGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->pGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_DGAIN"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->dGain = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->dGain = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_INPUT"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->Input = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->Input = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_ERR"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->Err = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->Err = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_ERRLAST"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->ErrLast = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->ErrLast = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_ISTATE"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->iState = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->iState = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_SETP"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->SetP = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->SetP = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_OUTP"))) {
             key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-            if (sscanf((const char *)key, "%f", &val) == 1)
-                unit->PID_mlt->OutP = val;
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                unit->PID_mlt->OutP = fval;
             xmlFree(key);
         }
         if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_MLT_MODE"))) {
--- a/brewco/setup.c	Fri Dec 04 14:21:25 2015 +0100
+++ b/brewco/setup.c	Fri Dec 04 22:57:23 2015 +0100
@@ -36,9 +36,90 @@
 
 
 
-int toggleYesNo(int value, char *text)
+void editFloat(float *value, float low, float high, char *text)
 {
-    int		key, new = value;
+    int		key;
+    float	new = *value;
+    char	pmpt[81];
+
+    prompt(0, NULL);
+    prompt(133, NULL);
+
+    for (;;) {
+	snprintf(pmpt, Config.lcd_cols + 1, "%s: %5.1f\001", text, new);
+	prompt(200, pmpt);
+	if (new == low)
+	    prompt(404, NULL);
+	else if (new == high)
+	    prompt(402, NULL);
+	else
+	    prompt(403, NULL);
+
+	key = keywait();
+	if ((key == KEY_RETURN) || my_shutdown)
+	    return;
+	if (key == KEY_UP) {
+	    new = new + 0.5;
+	    if (new > high)
+		new = high;
+	}
+	if (key == KEY_DOWN) {
+	    new = new - 0.5;
+	    if (new < low)
+		new = low;
+	}
+	if (key == KEY_ENTER) {
+	    *value = new;
+	    return;
+	}
+    }
+}
+
+
+
+void editInteger(int *value, int low, int high, char *text)
+{
+    int         key, new = *value;
+    char        pmpt[81];
+
+    prompt(0, NULL);
+    prompt(134, NULL);
+
+    for (;;) {
+        snprintf(pmpt, Config.lcd_cols + 1, "%s: %2d mins", text, new);
+        prompt(200, pmpt);
+        if (new == low)
+            prompt(404, NULL);
+        else if (new == high)
+            prompt(402, NULL);
+        else
+            prompt(403, NULL);
+
+        key = keywait();
+        if ((key == KEY_RETURN) || my_shutdown)
+            return;
+        if (key == KEY_UP) {
+            new++;
+            if (new > high)
+                new = high;
+        }
+        if (key == KEY_DOWN) {
+            new--;
+            if (new < low)
+                new = low;
+        }
+        if (key == KEY_ENTER) {
+            *value = new;
+            return;
+        }
+    }
+}
+
+
+
+void toggleYesNo(int *value, char *text)
+{
+    int		key, new = *value;
     char	pmpt[81];
 
     prompt(0, NULL);
@@ -56,13 +137,15 @@
 
 	key = keywait();
 	if ((key == KEY_RETURN) || my_shutdown)
-	    return value;
+	    return;
 	if ((key == KEY_UP) && new)
 	    new = 0;
 	else if ((key == KEY_DOWN) && (new == 0))
 	    new = 1;
-	if (key == KEY_ENTER)
-	    return new;
+	if (key == KEY_ENTER) {
+	    *value = new;
+	    return;
+	}
     }
 }
 
@@ -132,7 +215,7 @@
 	    case 13:	snprintf(pmpt, Config.lcd_cols + 1, " Pump on-boil: %s", unit->pump_onboil ? (char *)"Yes":(char *)"No");
 			prompt(200, pmpt);
 			break;
-	    case 14:	snprintf(pmpt, Config.lcd_cols + 1, "  Pump stop: %3d\337C", unit->pump_stop);
+	    case 14:	snprintf(pmpt, Config.lcd_cols + 1, " Pump stop: %5.1f\001", unit->pump_stop);
 			prompt(200, pmpt);
 			break;
 	    case 15:	snprintf(pmpt, Config.lcd_cols + 1, "    Skip Add: %s", unit->skip_add ? (char *)"Yes":(char *)"No");
@@ -169,8 +252,32 @@
 
 	if (key == KEY_ENTER) {
 	    switch(index) {
-		case 7:	unit->hlt_heater_mltfirst = toggleYesNo(unit->hlt_heater_mltfirst , (char *)"MLT heat b4 HLT");
-			break;
+
+		case 7:		toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT");
+				break;
+		case 8:		editInteger(&unit->pump_cycle, 5, 15, (char *)"Pump cycle");
+				break;
+		case 9:		editInteger(&unit->pump_rest, 1, 5, (char *)"Pump rest ");
+				break;
+		case 10:	toggleYesNo(&unit->pump_premash, (char *)" Pump pre-mash");
+				break;
+		case 11:	toggleYesNo(&unit->pump_onmash, (char *)" Pump on-mash");
+				break;
+		case 12:	toggleYesNo(&unit->pump_mashout, (char *)" Pump mashout");
+				break;
+		case 13:	toggleYesNo(&unit->pump_onboil, (char *)" Pump on-boil");
+				break;
+		case 14:	editFloat(&unit->pump_stop, 80.0, 110.0, (char *)" Pump stop");
+				break;
+		case 15:	toggleYesNo(&unit->skip_add, (char *)"Skip add water");
+				break;
+		case 16:	toggleYesNo(&unit->skip_remove, (char *)"Skip remove Mash");
+				break;
+		case 17:	toggleYesNo(&unit->skip_iodine, (char *)"Skip iodine test");
+				break;
+		case 19:	toggleYesNo(&unit->whirlpool, (char *)"Do a whirlpool");
+				break;
+
 	    }
 	}
     // name

mercurial