main/automation.c

changeset 87
47253f294a9f
parent 82
7d17e2cb31a8
child 89
fa44bd094e01
equal deleted inserted replaced
86:8d0287a1a9e1 87:47253f294a9f
49 extern SemaphoreHandle_t xSemaphoreDriver; ///< Relays driver lock semaphore 49 extern SemaphoreHandle_t xSemaphoreDriver; ///< Relays driver lock semaphore
50 extern double Output; ///< Cakculated outpout power 50 extern double Output; ///< Cakculated outpout power
51 extern time_t now; ///< Current time 51 extern time_t now; ///< Current time
52 extern struct tm timeinfo; ///< Current time structure 52 extern struct tm timeinfo; ///< Current time structure
53 53
54
54 #ifdef CONFIG_TEMP_SENSORS_SIMULATOR 55 #ifdef CONFIG_TEMP_SENSORS_SIMULATOR
55 extern float Fake_MLT; 56 extern float Fake_MLT;
56 extern float Fake_HLT; 57 extern float Fake_HLT;
57 #endif 58 #endif
58 59
116 #endif 117 #endif
117 if (recipe.Mashsteps > 1) 118 if (recipe.Mashsteps > 1)
118 LastMashStep = recipe.Mashsteps - 2; 119 LastMashStep = recipe.Mashsteps - 2;
119 else 120 else
120 LastMashStep = 0; 121 LastMashStep = 0;
121 log_msg(TAG, "Last mash step %d", LastMashStep); 122 ESP_LOGD(TAG, "Last mash step %d", LastMashStep);
122 123
123 // Check for a crashed session. 124 // Check for a crashed session.
124 if (runtime.AutoModeStarted) { 125 if (runtime.AutoModeStarted) {
125 TopMessage((char *)"Brouwen hervatten?"); 126 TopMessage((char *)"Brouwen hervatten?");
126 Buttons_Add( 40, 100, 80, 40, (char *)"Ja", 0); 127 Buttons_Add( 40, 100, 80, 40, (char *)"Ja", 0);
180 runtime.HopAddition = 0; 181 runtime.HopAddition = 0;
181 runtime.Logfile[0] = '\0'; 182 runtime.Logfile[0] = '\0';
182 runtime.PumpCooling = false; 183 runtime.PumpCooling = false;
183 runtime.MashStep = 0; 184 runtime.MashStep = 0;
184 runtime.MaltAdded = false; 185 runtime.MaltAdded = false;
186 runtime.MLT_usage = 0;
187 runtime.HLT_usage = 0;
185 write_runtime(); 188 write_runtime();
186 power_MLT = power_HLT = counts = 0; 189 power_MLT = power_HLT = counts = 0;
187 log_clean(); 190 log_clean();
188 vTaskDelay(250 / portTICK_PERIOD_MS); // Allow some time 191 vTaskDelay(250 / portTICK_PERIOD_MS); // Allow some time
189 break; 192 break;
378 driver_state->hlt_mode = HLT_MODE_NONE; 381 driver_state->hlt_mode = HLT_MODE_NONE;
379 driver_state->hlt_sp = 0.0; 382 driver_state->hlt_sp = 0.0;
380 driver_state->pump_run = 0; 383 driver_state->pump_run = 0;
381 xSemaphoreGive(xSemaphoreDriver); 384 xSemaphoreGive(xSemaphoreDriver);
382 } 385 }
386 double mwu = (runtime.MLT_usage / 1000.0 / 60.0 / 60.0) * equipment.MLT_watt / 1000.0;
387 double hwu = (runtime.HLT_usage / 1000.0 / 60.0 / 60.0) * equipment.HLT_watt / 1000.0;
388 log_msg(TAG, "MLT usage %.3f KWU, HLT usage %.3f KWU, total %.3f KWU", mwu, hwu, mwu + hwu);
383 _fg = TFT_YELLOW; 389 _fg = TFT_YELLOW;
384 TFT_setFont(DEJAVU24_FONT, NULL); 390 TFT_setFont(DEJAVU24_FONT, NULL);
385 if (Main_Screen == MAIN_AUTO_DONE) { 391 if (Main_Screen == MAIN_AUTO_DONE) {
386 TFT_print((char *)"Brouwen is gereed.", CENTER, CENTER); 392 TFT_print((char *)"Brouwen is gereed.", CENTER, CENTER);
387 log_msg(TAG, "Brew is done"); 393 log_msg(TAG, "Brew is done");
574 } 580 }
575 runtime.UseHLT = _UseHLT; 581 runtime.UseHLT = _UseHLT;
576 } else { 582 } else {
577 runtime.UseHLT = _UseHLT = false; 583 runtime.UseHLT = _UseHLT = false;
578 } 584 }
579 log_msg(TAG, "Use HLT %s", (_UseHLT)?"true":"false"); 585 ESP_LOGD(TAG, "Use HLT %s", (_UseHLT)?"true":"false");
580 updateRuntime = true; 586 updateRuntime = true;
581 if (_UseHLT) { 587 if (_UseHLT) {
582 /* 588 /*
583 * Calculate HLT setpoint for pre-heat. Substract the 589 * Calculate HLT setpoint for pre-heat. Substract the
584 * available Mash rest times, asume 0.5 degrees/minute 590 * available Mash rest times, asume 0.5 degrees/minute
611 HLT_info(71,150, true, false); 617 HLT_info(71,150, true, false);
612 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { 618 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
613 if (driver_state->hlt_pv >= driver_state->hlt_sp) { 619 if (driver_state->hlt_pv >= driver_state->hlt_sp) {
614 Main_Screen = MAIN_AUTO_MASH; 620 Main_Screen = MAIN_AUTO_MASH;
615 driver_state->hlt_sp = recipe.SpargeTemp; // Set final setpoint 621 driver_state->hlt_sp = recipe.SpargeTemp; // Set final setpoint
616 log_msg(TAG, "HLT preheat done"); 622 ESP_LOGD(TAG, "HLT preheat done");
617 } 623 }
618 xSemaphoreGive(xSemaphoreDriver); 624 xSemaphoreGive(xSemaphoreDriver);
619 } 625 }
620 break; 626 break;
621 627
799 if ((recipe.MashStep[runtime.MashStep].Step_temp != recipe.MashStep[runtime.MashStep].End_temp) && 805 if ((recipe.MashStep[runtime.MashStep].Step_temp != recipe.MashStep[runtime.MashStep].End_temp) &&
800 (recipe.MashStep[runtime.MashStep].Type != MASHTYPE_DECOCTION) && (oldTimeLeft != TimeLeft)) { 806 (recipe.MashStep[runtime.MashStep].Type != MASHTYPE_DECOCTION) && (oldTimeLeft != TimeLeft)) {
801 float part = ((stageTime * 60.0) - TimeLeft) / (stageTime * 60.0); 807 float part = ((stageTime * 60.0) - TimeLeft) / (stageTime * 60.0);
802 newTemp = ((int)(((part * (recipe.MashStep[runtime.MashStep].End_temp - recipe.MashStep[runtime.MashStep].Step_temp)) + 808 newTemp = ((int)(((part * (recipe.MashStep[runtime.MashStep].End_temp - recipe.MashStep[runtime.MashStep].Step_temp)) +
803 recipe.MashStep[runtime.MashStep].Step_temp) * 16)) / 16.0; 809 recipe.MashStep[runtime.MashStep].Step_temp) * 16)) / 16.0;
804 //newTemp = ((int)(newTemp * 16)) / 16.0;
805 if (newTemp != stageTemp) { 810 if (newTemp != stageTemp) {
806 stageTemp = newTemp; 811 stageTemp = newTemp;
807 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { 812 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
808 driver_state->mlt_sp = stageTemp; 813 driver_state->mlt_sp = stageTemp;
809 xSemaphoreGive(xSemaphoreDriver); 814 xSemaphoreGive(xSemaphoreDriver);
810 } 815 }
811 ESP_LOGI(TAG, "Curent %7.4f new %7.4f part %7.4f", stageTemp, newTemp, part); 816 //ESP_LOGI(TAG, "Current %7.4f new %7.4f part %7.4f", stageTemp, newTemp, part);
812 } 817 }
813 } 818 }
814 oldTimeLeft = TimeLeft; 819 oldTimeLeft = TimeLeft;
815 820
816 if (TimeLeft == 0) { 821 if (TimeLeft == 0) {
817 runtime.StageTimeLeft = 0; 822 runtime.StageTimeLeft = 0;
818 updateRuntime = true; 823 updateRuntime = true;
824 TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
825 snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen);
826 ws_server_send_text_clients((char *)"/ws", msg, strlen(msg));
827
819 if (runtime.MashStep == 0 && ! runtime.MaltAdded && config.AskAdd) { 828 if (runtime.MashStep == 0 && ! runtime.MaltAdded && config.AskAdd) {
820 /* 829 /*
821 * Add Mash prompt. 830 * Add Mash prompt.
822 */ 831 */
823 stageTemp = recipe.MashStep[runtime.MashStep].Step_temp; // Set normal step temperature 832 stageTemp = recipe.MashStep[runtime.MashStep].Step_temp; // Set normal step temperature
824 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { 833 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
825 driver_state->mlt_sp = stageTemp; 834 driver_state->mlt_sp = stageTemp;
826 xSemaphoreGive(xSemaphoreDriver); 835 xSemaphoreGive(xSemaphoreDriver);
827 } 836 }
828 log_annotation(ANNOTATION_EVENT, (char *)"Mout storten"); 837 log_annotation(ANNOTATION_EVENT, (char *)"Mout storten");
829 TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
830 Buttons_Clear(); 838 Buttons_Clear();
831 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); 839 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0);
832 Buttons[0].dark = true; 840 Buttons[0].dark = true;
833 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); 841 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1);
834 Buttons_Show(); 842 Buttons_Show();
846 if ((runtime.MashStep == LastMashStep) && config.AskIodine) { 854 if ((runtime.MashStep == LastMashStep) && config.AskIodine) {
847 /* 855 /*
848 * Iodone test prompt. 856 * Iodone test prompt.
849 */ 857 */
850 log_annotation(ANNOTATION_EVENT, (char *)"Jodium test"); 858 log_annotation(ANNOTATION_EVENT, (char *)"Jodium test");
851 TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
852 Buttons_Clear(); 859 Buttons_Clear();
853 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); 860 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0);
854 Buttons[0].dark = true; 861 Buttons[0].dark = true;
855 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); 862 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1);
856 Buttons_Show(); 863 Buttons_Show();
870 if ((runtime.MashStep == (recipe.Mashsteps - 1)) && config.AskRemove) { 877 if ((runtime.MashStep == (recipe.Mashsteps - 1)) && config.AskRemove) {
871 /* 878 /*
872 * Mash remove prompt. 879 * Mash remove prompt.
873 */ 880 */
874 log_annotation(ANNOTATION_EVENT, (char *)"Mout verwijderen"); 881 log_annotation(ANNOTATION_EVENT, (char *)"Mout verwijderen");
875 TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
876 Buttons_Clear(); 882 Buttons_Clear();
877 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); 883 Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0);
878 Buttons[0].dark = true; 884 Buttons[0].dark = true;
879 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); 885 Buttons_Add(255,120, 60, 40, (char *)"Ok", 1);
880 Buttons_Show(); 886 Buttons_Show();
1345 */ 1351 */
1346 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { 1352 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
1347 driver_state->pump_run = (driver_state->mlt_pv < equipment.PumpMaxTemp) ? 1 : 0; 1353 driver_state->pump_run = (driver_state->mlt_pv < equipment.PumpMaxTemp) ? 1 : 0;
1348 xSemaphoreGive(xSemaphoreDriver); 1354 xSemaphoreGive(xSemaphoreDriver);
1349 } 1355 }
1350 log_annotation(ANNOTATION_STAGE, (char *)"Whirlpool"); 1356 log_annotation(ANNOTATION_EVENT, (char *)"Whirlpool");
1351 1357
1352 TimerSet(TimeWhirlPool * 60); 1358 TimerSet(TimeWhirlPool * 60);
1353 runtime.StageTimeLeft = TimeWhirlPool; 1359 runtime.StageTimeLeft = TimeWhirlPool;
1354 updateRuntime = true; 1360 updateRuntime = true;
1355 MLT_info(71, 26, false); 1361 MLT_info(71, 26, false);

mercurial