Added mash temperature adjust steps if different begin and end temperatures.

Sun, 07 Jun 2020 15:09:23 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 07 Jun 2020 15:09:23 +0200
changeset 81
72c715ac0444
parent 80
9d2c0a85ee6e
child 82
7d17e2cb31a8

Added mash temperature adjust steps if different begin and end temperatures.

main/automation.c file | annotate | diff | comparison | revisions
--- a/main/automation.c	Sat Jun 06 22:51:44 2020 +0200
+++ b/main/automation.c	Sun Jun 07 15:09:23 2020 +0200
@@ -25,9 +25,11 @@
 uint32_t			power_HLT = 0;			///< HLT power
 uint32_t			counts = 0;			///< Counter for power average
 float                           stageTemp = 0.0;		///< Current stage temperature
+float				newTemp = 0.0;			///< New stage temperature
 uint16_t                        stageTime = 0;			///< Current stage timer
 uint16_t                        TimeWhirlPool = 0;		///< Whirlpool timer
-uint32_t                        TimeLeft = 0;			///< Tie left in this stage
+uint32_t                        TimeLeft = 0;			///< Time left in this stage
+uint32_t			oldTimeLeft = 0;		///< The previous time left
 uint32_t                        TimeSpent = 0;			///< Tota time spent
 uint32_t                        SecsCount = 0;			///< Seconds counter
 uint32_t                        pumpTime = 0;			///< Pump running time
@@ -651,9 +653,9 @@
                     MashState = Sub_Screen = MASH_WAITTEMP;
 		    snprintf(msg, 255, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen);
                     ws_server_send_text_clients((char *)"/ws", msg, strlen(msg));
-                    log_msg(TAG, "Mash step %d type: %s time: %d sp: %6.4f  sv: %6.4f",
+                    log_msg(TAG, "Mash step %d type: %s time: %d sp: %6.4f-%6.4f sv: %6.4f",
 				    runtime.MashStep, mashTypes[recipe.MashStep[runtime.MashStep].Type],
-                                    stageTime, stageTemp, temp_MLT);
+                                    stageTime, stageTemp, recipe.MashStep[runtime.MashStep].End_temp, temp_MLT);
 
 		    if (runtime.MashStep) {
 			// Do not annotate before the log is open.
@@ -719,6 +721,7 @@
                     if ((temp_MLT >= stageTemp) && (Steady > 10)) {
                         SoundPlay(SOUND_TempReached);
                         TempReached = true;
+			newTemp = stageTemp;
                         MashState = Sub_Screen = MASH_REST;
 			snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen);
                 	ws_server_send_text_clients((char *)"/ws", msg, strlen(msg));
@@ -732,6 +735,7 @@
                         }
 			Resume = false;
 			runtime.StageTimeLeft = TimeLeft / 60;
+			oldTimeLeft = TimeLeft;
 			updateRuntime = true;
                         log_msg(TAG, "Mash step %d temperature reached, rest %d minutes", runtime.MashStep, TimeLeft / 60);
                         Buttons_Clear();
@@ -792,6 +796,23 @@
                         }
                     }
 
+		    if ((recipe.MashStep[runtime.MashStep].Step_temp != recipe.MashStep[runtime.MashStep].End_temp) &&
+			(recipe.MashStep[runtime.MashStep].Type != MASHTYPE_DECOCTION) && (oldTimeLeft != TimeLeft)) {
+			float part = ((stageTime * 60.0) - TimeLeft) / (stageTime * 60.0);
+			newTemp = ((int)(((part * (recipe.MashStep[runtime.MashStep].End_temp - recipe.MashStep[runtime.MashStep].Step_temp)) +
+				  recipe.MashStep[runtime.MashStep].Step_temp) * 16)) / 16.0;
+			//newTemp = ((int)(newTemp * 16)) / 16.0;
+			if (newTemp != stageTemp) {
+			    stageTemp = newTemp;
+			    if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
+                        	driver_state->mlt_sp = stageTemp;
+                        	xSemaphoreGive(xSemaphoreDriver);
+                    	    }
+			ESP_LOGI(TAG, "Curent %7.4f new %7.4f part %7.4f", stageTemp, newTemp, part);
+			}
+		    }
+		    oldTimeLeft = TimeLeft;
+
                     if (TimeLeft == 0) {
 			runtime.StageTimeLeft = 0;
 			updateRuntime = true;

mercurial