From a34fa2fae865d13730fed30022eae9020479cba8 Mon Sep 17 00:00:00 2001 From: "core.editor" Date: Mon, 3 Jun 2024 20:57:32 +0200 Subject: [PATCH] fix against too fast sending acycling display command Anycubic 1.0 display ignores acyclic telegrams as J23 or J18 if they are sent too fast after last cyclic telegram. This results for the user in sporadic not occuring mask "Lack of filament..." or no continue button at filament sensor or M600 G-Code command. The last issue is catatrophic for the print job because interrupted at this point. This commit fix the problem by integrating a minimum time delay which was seen at original anycubic i3 mega S fw. --- .../extui/knutwurst/anycubic_touchscreen.cpp | 88 +++++++++++++++---- .../extui/knutwurst/anycubic_touchscreen.h | 3 + 2 files changed, 73 insertions(+), 18 deletions(-) diff --git a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp index 18aa432c..19a709f8 100755 --- a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp @@ -78,7 +78,8 @@ static void sendLine_P(PGM_P str) { AnycubicMediaPrintState AnycubicTouchscreenClass::mediaPrintingState = AMPRINTSTATE_NOT_PRINTING; AnycubicMediaPauseState AnycubicTouchscreenClass::mediaPauseState = AMPAUSESTATE_NOT_PAUSED; - +uint32_t AnycubicTouchscreenClass::time_last_cyclic_tft_command = 0; +uint8_t AnycubicTouchscreenClass::delayed_tft_command = 0; #if ENABLED(POWER_OUTAGE_TEST) int PowerInt = 6; @@ -261,10 +262,13 @@ void AnycubicTouchscreenClass::ResumePrint() { // trigger the user message box DoFilamentRunoutCheck(); - - // re-enable the continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: Resume Print with filament sensor still " - "tripped... J18"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // re-enable the continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: Resume Print with filament sensor still " + "tripped... J18"); + } + else + delayed_tft_command = 18; return; } #endif @@ -1011,8 +1015,12 @@ void AnycubicTouchscreenClass::DoFilamentRunoutCheck() { // play tone to indicate filament is out injectCommands(F("\nM300 P200 S1567\nM300 P200 S1174\nM300 P200 " "S1567\nM300 P200 S1174\nM300 P2000 S1567")); - // tell the user that the filament has run out and wait - SENDLINE_DBG_PGM("J23", "TFT Serial Debug: Blocking filament prompt... J23"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // tell the user that the filament has run out and wait + SENDLINE_DBG_PGM("J23", "TFT Serial Debug: Blocking filament prompt... J23"); + } + else + delayed_tft_command = 23; } else { SENDLINE_DBG_PGM("J15", "TFT Serial Debug: Non blocking filament runout... J15"); } @@ -1040,29 +1048,49 @@ void AnycubicTouchscreenClass::UserConfirmRequired(const char* const msg) { if (strcmp_P(msg, PSTR("Nozzle Parked")) == 0) { mediaPrintingState = AMPRINTSTATE_PAUSED; mediaPauseState = AMPAUSESTATE_PARKED; - // enable continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD print paused done... J18"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // enable continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD print paused done... J18"); + } + else + delayed_tft_command = 18; } else if (strcmp_P(msg, PSTR("Load Filament")) == 0) { mediaPrintingState = AMPRINTSTATE_PAUSED; mediaPauseState = AMPAUSESTATE_FILAMENT_OUT; - // enable continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is out... J18"); - SENDLINE_DBG_PGM("J23", "TFT Serial Debug: UserConfirm Blocking filament prompt... J23"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // enable continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is out... J18"); + SENDLINE_DBG_PGM("J23", "TFT Serial Debug: UserConfirm Blocking filament prompt... J23"); + } + else + delayed_tft_command = 118; } else if (strcmp_P(msg, PSTR("Filament Purging...")) == 0) { mediaPrintingState = AMPRINTSTATE_PAUSED; mediaPauseState = AMPAUSESTATE_FILAMENT_PURGING; - // enable continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is purging... J18"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // enable continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm Filament is purging... J18"); + } + else + delayed_tft_command = 18; } else if (strcmp_P(msg, PSTR("HeaterTimeout")) == 0) { mediaPrintingState = AMPRINTSTATE_PAUSED; mediaPauseState = AMPAUSESTATE_HEATER_TIMEOUT; - // enable continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Heater timeout... J18"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // enable continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Heater timeout... J18"); + } + else + delayed_tft_command = 18; } else if (strcmp_P(msg, PSTR("Reheat finished.")) == 0) { mediaPrintingState = AMPRINTSTATE_PAUSED; mediaPauseState = AMPAUSESTATE_REHEAT_FINISHED; - // enable continue button - SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Reheat done... J18"); + if ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) { + // enable continue button + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: UserConfirm SD Reheat done... J18"); + } + else + delayed_tft_command = 18; } #endif } @@ -1288,6 +1316,7 @@ void AnycubicTouchscreenClass::GetCommandFromTFT() { } else { SEND_PGM_VAL("A20V ", feedrate_percentage); SENDLINE_PGM(""); + time_last_cyclic_tft_command = millis(); } } break; @@ -2062,6 +2091,29 @@ void AnycubicTouchscreenClass::GetCommandFromTFT() { TFTbuflen = (TFTbuflen - 1); TFTbufindr = (TFTbufindr + 1) % TFTBUFSIZE; } + + // In case of too short time after last cyclic tft command it has to be + // wait to avoid missing action after acyclic command by the tft. + if ( (delayed_tft_command > 0) && ( millis() - time_last_cyclic_tft_command >= WAIT_MS_UNTIL_ACYCLIC_SEND ) ) { + switch (delayed_tft_command) { + case 23: { + SENDLINE_DBG_PGM("J23", "TFT Serial Debug: delayed J23"); + delayed_tft_command = 0; + break; + } + case 18: { + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: delayed J18"); + delayed_tft_command = 0; + break; + } + case 118: { + SENDLINE_DBG_PGM("J23", "TFT Serial Debug: delayed J23"); + SENDLINE_DBG_PGM("J18", "TFT Serial Debug: delayed J18"); + delayed_tft_command = 0; + break; + } + } + } } void AnycubicTouchscreenClass::OnPrintTimerStarted() { diff --git a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h index 09100e7d..c0c746e9 100755 --- a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h @@ -138,6 +138,7 @@ enum AnycubicMediaPauseState { #define SM_BLTZ_EXIT_L "" #define SM_HS_DISABLE_L "" #define SM_HS_ENABLE_L "" + #define WAIT_MS_UNTIL_ACYCLIC_SEND 500 #endif // !KNUTWURST_DGUS2_TFT #if ENABLED(KNUTWURST_DGUS2_TFT) @@ -228,6 +229,8 @@ class AnycubicTouchscreenClass { static AnycubicMediaPrintState mediaPrintingState; static AnycubicMediaPauseState mediaPauseState; + static uint32_t time_last_cyclic_tft_command; + static uint8_t delayed_tft_command; #if defined(POWER_OUTAGE_TEST) struct OutageDataStruct {