From 37d0f49a82cd2e4d91dce4e62671b266924eb2a7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 24 May 2023 01:05:55 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Misc.=20Ext?= =?UTF-8?q?UI=20LCD=20cleanup=20(#25872)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/AVR/HAL.h | 2 +- Marlin/src/HAL/LPC1768/HAL.h | 2 +- Marlin/src/HAL/STM32/HAL.h | 2 +- Marlin/src/HAL/STM32F1/HAL.h | 2 +- Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 2 +- .../extui/anycubic_chiron/FileNavigator.cpp | 30 +- .../lcd/extui/anycubic_chiron/FileNavigator.h | 4 +- .../extui/anycubic_chiron/chiron_extui.cpp | 26 +- .../lcd/extui/anycubic_chiron/chiron_tft.cpp | 310 +-- .../lcd/extui/anycubic_chiron/chiron_tft.h | 48 +- .../extui/anycubic_i3mega/anycubic_extui.cpp | 22 +- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 1154 ++++---- .../anycubic_i3mega/anycubic_i3mega_lcd.h | 69 +- .../extui/anycubic_vyper/FileNavigator.cpp | 22 +- .../lcd/extui/anycubic_vyper/FileNavigator.h | 4 +- .../src/lcd/extui/anycubic_vyper/dgus_tft.cpp | 271 +- .../src/lcd/extui/anycubic_vyper/dgus_tft.h | 38 +- .../lcd/extui/anycubic_vyper/vyper_extui.cpp | 26 +- Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp | 2 +- .../extui/dgus/fysetc/DGUSScreenHandler.cpp | 6 +- .../extui/dgus/hiprecy/DGUSScreenHandler.cpp | 6 +- .../lcd/extui/dgus/mks/DGUSScreenHandler.cpp | 6 +- .../extui/dgus/origin/DGUSScreenHandler.cpp | 6 +- .../lcd/extui/dgus_reloaded/DGUSRxHandler.cpp | 2 +- .../lcd/extui/dgus_reloaded/DGUSRxHandler.h | 2 +- .../extui/dgus_reloaded/DGUSScreenHandler.cpp | 4 +- .../extui/dgus_reloaded/DGUSScreenHandler.h | 4 +- .../dgus_reloaded/definition/DGUS_VPList.cpp | 2 +- .../dgus_reloaded/dgus_reloaded_extui.cpp | 4 +- .../lcd/extui/ia_creality/FileNavigator.cpp | 24 +- .../src/lcd/extui/ia_creality/FileNavigator.h | 11 +- .../extui/ia_creality/ia_creality_extui.cpp | 2333 +++-------------- .../lcd/extui/ia_creality/ia_creality_rts.cpp | 1730 ++++++++++++ ...{ia_creality_extui.h => ia_creality_rts.h} | 26 +- .../extui/mks_ui/tft_lvgl_configuration.cpp | 1 - .../src/lcd/extui/nextion/FileNavigator.cpp | 62 +- Marlin/src/lcd/extui/nextion/FileNavigator.h | 4 +- .../src/lcd/extui/nextion/nextion_extui.cpp | 12 +- Marlin/src/lcd/extui/nextion/nextion_tft.cpp | 46 +- Marlin/src/lcd/extui/nextion/nextion_tft.h | 26 +- .../src/lcd/extui/nextion/nextion_tft_defs.h | 14 +- Marlin/src/lcd/language/language_en.h | 6 +- 42 files changed, 3173 insertions(+), 3200 deletions(-) create mode 100644 Marlin/src/lcd/extui/ia_creality/ia_creality_rts.cpp rename Marlin/src/lcd/extui/ia_creality/{ia_creality_extui.h => ia_creality_rts.h} (92%) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index d458790979f..6d98dff0802 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -140,7 +140,7 @@ typedef Servo hal_servo_t; #endif #define LCD_SERIAL lcdSerial #if HAS_DGUS_LCD - #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free() + #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free() #endif #endif diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 6d5824f7a15..be4d59ada73 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -101,7 +101,7 @@ extern DefaultSerial1 USBSerial; #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB." #endif #if HAS_DGUS_LCD - #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.available() + #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.available() #endif #endif diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 54359c5b098..dc36cc1eca3 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -114,7 +114,7 @@ #error "LCD_SERIAL_PORT must be from 1 to 6, or -1 for Native USB." #endif #if HAS_DGUS_LCD - #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() + #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #endif #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 954281a4be3..8ed525bfb71 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -140,7 +140,7 @@ static_assert(false, "LCD_SERIAL_PORT must be from 1 to " STRINGIFY(NUM_UARTS) ". You can also use -1 if the board supports Native USB.") #endif #if HAS_DGUS_LCD - #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() + #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #endif #endif diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index ceaf147c3ba..53e4466bf81 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -2536,7 +2536,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item Draw_Menu_Item(row, ICON_Back, F("Back")); else Draw_Menu(Motion, MOTION_STEPS); - break; + break; #if HAS_X_AXIS case STEPS_X: if (draw) { diff --git a/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.cpp b/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.cpp index 6e77b2b2fda..ffc485a3dc2 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.cpp +++ b/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.cpp @@ -60,21 +60,21 @@ using namespace ExtUI; namespace Anycubic { FileNavigator filenavigator; -FileList FileNavigator::filelist; // Instance of the Marlin file API +FileList FileNavigator::filelist; // ExtUI file API uint16_t FileNavigator::lastpanelindex; uint16_t FileNavigator::currentindex; // override the panel request uint8_t FileNavigator::folderdepth; -uint16_t FileNavigator::currentfolderindex[MAX_FOLDER_DEPTH]; // track folder pos for iteration -char FileNavigator::currentfoldername[MAX_PATH_LEN + 1]; // Current folder path +uint16_t FileNavigator::currentDirIndex[MAX_FOLDER_DEPTH]; // track folder pos for iteration +char FileNavigator::currentDirPath[MAX_PATH_LEN + 1]; // Current folder path FileNavigator::FileNavigator() { reset(); } void FileNavigator::reset() { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; folderdepth = 0; currentindex = 0; lastpanelindex = 0; - ZERO(currentfolderindex); + ZERO(currentDirIndex); // Start at root folder while (!filelist.isAtRootDir()) filelist.upDir(); @@ -85,9 +85,9 @@ void FileNavigator::refresh() { filelist.refresh(); } void FileNavigator::changeDIR(const char *folder) { if (folderdepth >= MAX_FOLDER_DEPTH) return; // limit the folder depth - currentfolderindex[folderdepth] = currentindex; - strcat(currentfoldername, folder); - strcat(currentfoldername, "/"); + currentDirIndex[folderdepth] = currentindex; + strcat(currentDirPath, folder); + strcat(currentDirPath, "/"); filelist.changeDir(folder); folderdepth++; currentindex = 0; @@ -97,15 +97,15 @@ void FileNavigator::upDIR() { if (!filelist.isAtRootDir()) { filelist.upDir(); folderdepth--; - currentindex = currentfolderindex[folderdepth]; // restore last position in the folder + currentindex = currentDirIndex[folderdepth]; // restore last position in the folder filelist.seek(currentindex); // restore file information } // Remove the child folder from the stored path if (folderdepth == 0) - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; else { - char * const pos = strchr(currentfoldername, '/'); + char * const pos = strchr(currentDirPath, '/'); *(pos + 1) = '\0'; } } @@ -151,7 +151,7 @@ void FileNavigator::skiptofileindex(uint16_t skip) { // The new panel ignores entries that don't end in .GCO or .gcode so add and pad them. if (paneltype <= AC_panel_new) { TFTSer.println("<<.GCO"); - Chiron.SendtoTFTLN(F(".. .gcode")); + chiron.tftSendLn(F(".. .gcode")); } else { TFTSer.println("<<"); @@ -186,7 +186,7 @@ void FileNavigator::skiptofileindex(uint16_t skip) { } else { // Not DIR TFTSer.write('/'); - if (folderdepth > 0) TFTSer.print(currentfoldername); + if (folderdepth > 0) TFTSer.print(currentDirPath); TFTSer.println(filelist.shortFilename()); TFTSer.print(filelist.longFilename()); @@ -233,9 +233,9 @@ void FileNavigator::skiptofileindex(uint16_t skip) { void FileNavigator::sendFile(panel_type_t paneltype) { TFTSer.write('/'); - if (folderdepth > 0) TFTSer.print(currentfoldername); + if (folderdepth > 0) TFTSer.print(currentDirPath); TFTSer.println(filelist.shortFilename()); - if (folderdepth > 0) TFTSer.print(currentfoldername); + if (folderdepth > 0) TFTSer.print(currentDirPath); TFTSer.println(filelist.longFilename()); } diff --git a/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.h b/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.h index 71236c4df95..f4fad966531 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.h +++ b/Marlin/src/lcd/extui/anycubic_chiron/FileNavigator.h @@ -52,8 +52,8 @@ namespace Anycubic { static uint16_t lastpanelindex; static uint16_t currentindex; static uint8_t folderdepth; - static uint16_t currentfolderindex[MAX_FOLDER_DEPTH]; - static char currentfoldername[MAX_PATH_LEN + 1]; + static uint16_t currentDirIndex[MAX_FOLDER_DEPTH]; + static char currentDirPath[MAX_PATH_LEN + 1]; }; extern FileNavigator filenavigator; diff --git a/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp b/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp index 520ca587e33..27ee4689ba1 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp @@ -37,17 +37,17 @@ using namespace Anycubic; namespace ExtUI { - void onStartup() { Chiron.Startup(); } + void onStartup() { chiron.startup(); } - void onIdle() { Chiron.IdleLoop(); } + void onIdle() { chiron.idleLoop(); } void onPrinterKilled(FSTR_P const error, FSTR_P const component) { - Chiron.PrinterKilled(error, component); + chiron.printerKilled(error, component); } - void onMediaInserted() { Chiron.MediaEvent(AC_media_inserted); } - void onMediaError() { Chiron.MediaEvent(AC_media_error); } - void onMediaRemoved() { Chiron.MediaEvent(AC_media_removed); } + void onMediaInserted() { chiron.mediaEvent(AC_media_inserted); } + void onMediaError() { chiron.mediaEvent(AC_media_error); } + void onMediaRemoved() { chiron.mediaEvent(AC_media_removed); } void onPlayTone(const uint16_t frequency, const uint16_t duration) { #if ENABLED(SPEAKER) @@ -55,15 +55,15 @@ namespace ExtUI { #endif } - void onPrintTimerStarted() { Chiron.TimerEvent(AC_timer_started); } - void onPrintTimerPaused() { Chiron.TimerEvent(AC_timer_paused); } - void onPrintTimerStopped() { Chiron.TimerEvent(AC_timer_stopped); } + void onPrintTimerStarted() { chiron.timerEvent(AC_timer_started); } + void onPrintTimerPaused() { chiron.timerEvent(AC_timer_paused); } + void onPrintTimerStopped() { chiron.timerEvent(AC_timer_stopped); } void onPrintDone() {} - void onFilamentRunout(const extruder_t) { Chiron.FilamentRunout(); } + void onFilamentRunout(const extruder_t) { chiron.filamentRunout(); } - void onUserConfirmRequired(const char * const msg) { Chiron.ConfirmationRequest(msg); } - void onStatusChanged(const char * const msg) { Chiron.StatusChange(msg); } + void onUserConfirmRequired(const char * const msg) { chiron.confirmationRequest(msg); } + void onStatusChanged(const char * const msg) { chiron.statusChange(msg); } void onHomingStart() {} void onHomingDone() {} @@ -127,7 +127,7 @@ namespace ExtUI { // Called when power-loss state is detected } // Called on resume from power-loss - void onPowerLossResume() { Chiron.PowerLossRecovery(); } + void onPowerLossResume() { chiron.powerLossRecovery(); } #endif #if HAS_PID_HEATING diff --git a/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.cpp index f3bc64a0249..bcf78746a24 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.cpp @@ -42,9 +42,13 @@ #include "../../../libs/numtostr.h" #include "../../../MarlinCore.h" +#define DEBUG_OUT ACDEBUGLEVEL +#include "../../../core/debug_out.h" + namespace Anycubic { -ChironTFT Chiron; +ChironTFT chiron; + #if AUTO_DETECT_CHIRON_TFT panel_type_t ChironTFT::panel_type = AC_panel_unknown; #endif @@ -60,7 +64,7 @@ uint8_t ChironTFT::command_len; float ChironTFT::live_Zoffset; file_menu_t ChironTFT::file_menu; -void ChironTFT::Startup() { +void ChironTFT::startup() { selectedfile[0] = '\0'; panel_command[0] = '\0'; command_len = 0; @@ -92,73 +96,73 @@ void ChironTFT::Startup() { break; default: SERIAL_ECHOLNF(AC_msg_auto_panel_detection); - DetectPanelType(); + detectPanelType(); break; } // Signal Board has reset - SendtoTFTLN(AC_msg_main_board_has_reset); + tftSendLn(AC_msg_main_board_has_reset); // Enable leveling and Disable end stops during print // as Z home places nozzle above the bed so we need to allow it past the end stops injectCommands(AC_cmnd_enable_leveling); - // Startup tunes are defined in Tunes.h + // startup tunes are defined in Tunes.h PlayTune(TERN(AC_DEFAULT_STARTUP_TUNE, Anycubic_PowerOn, GB_PowerOn)); #if ACDEBUGLEVEL - SERIAL_ECHOLNPGM("AC Debug Level ", ACDEBUGLEVEL); + DEBUG_ECHOLNPGM("AC Debug Level ", ACDEBUGLEVEL); #endif - SendtoTFTLN(AC_msg_ready); + tftSendLn(AC_msg_ready); } -void ChironTFT::DetectPanelType() { +void ChironTFT::detectPanelType() { #if AUTO_DETECT_CHIRON_TFT // Send a query to the TFT - SendtoTFTLN(AC_Test_for_OldPanel); // The panel will respond with 'SXY 480 320' - SendtoTFTLN(AC_Test_for_NewPanel); // the panel will respond with '[0]=0 ' to '[19]=0 ' + tftSendLn(AC_Test_for_OldPanel); // The panel will respond with 'SXY 480 320' + tftSendLn(AC_Test_for_NewPanel); // the panel will respond with '[0]=0 ' to '[19]=0 ' #endif } -void ChironTFT::IdleLoop() { - if (ReadTFTCommand()) { - ProcessPanelRequest(); +void ChironTFT::idleLoop() { + if (readTFTCommand()) { + processPanelRequest(); command_len = 0; } - CheckHeaters(); + checkHeaters(); } -void ChironTFT::PrinterKilled(FSTR_P const error, FSTR_P const component) { - SendtoTFTLN(AC_msg_kill_lcd); +void ChironTFT::printerKilled(FSTR_P const error, FSTR_P const component) { + tftSendLn(AC_msg_kill_lcd); #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("PrinterKilled()\nerror: ", error , "\ncomponent: ", component); + DEBUG_ECHOLNPGM("printerKilled()\nerror: ", error , "\ncomponent: ", component); #endif } -void ChironTFT::MediaEvent(media_event_t event) { +void ChironTFT::mediaEvent(media_event_t event) { #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("ProcessMediaStatus() ", event); + DEBUG_ECHOLNPGM("ProcessMediaStatus() ", event); #endif switch (event) { case AC_media_inserted: - SendtoTFTLN(AC_msg_sd_card_inserted); + tftSendLn(AC_msg_sd_card_inserted); break; case AC_media_removed: - SendtoTFTLN(AC_msg_sd_card_removed); + tftSendLn(AC_msg_sd_card_removed); break; case AC_media_error: last_error = AC_error_noSD; - SendtoTFTLN(AC_msg_no_sd_card); + tftSendLn(AC_msg_no_sd_card); break; } } -void ChironTFT::TimerEvent(timer_event_t event) { +void ChironTFT::timerEvent(timer_event_t event) { #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("TimerEvent() ", event); - SERIAL_ECHOLNPGM("Printer State: ", printer_state); + DEBUG_ECHOLNPGM("timerEvent() ", event); + DEBUG_ECHOLNPGM("Printer State: ", printer_state); #endif switch (event) { @@ -166,44 +170,44 @@ void ChironTFT::TimerEvent(timer_event_t event) { live_Zoffset = 0.0; // reset print offset setSoftEndstopState(false); // disable endstops to print printer_state = AC_printer_printing; - SendtoTFTLN(AC_msg_print_from_sd_card); + tftSendLn(AC_msg_print_from_sd_card); } break; case AC_timer_paused: { printer_state = AC_printer_paused; pause_state = AC_paused_idle; - SendtoTFTLN(AC_msg_paused); + tftSendLn(AC_msg_paused); } break; case AC_timer_stopped: { if (printer_state != AC_printer_idle) { printer_state = AC_printer_stopping; - SendtoTFTLN(AC_msg_print_complete); + tftSendLn(AC_msg_print_complete); } setSoftEndstopState(true); // enable endstops } break; } } -void ChironTFT::FilamentRunout() { +void ChironTFT::filamentRunout() { #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("FilamentRunout() printer_state ", printer_state); + DEBUG_ECHOLNPGM("filamentRunout() printer_state ", printer_state); #endif // 1 Signal filament out last_error = AC_error_filament_runout; - SendtoTFTLN(isPrintingFromMedia() ? AC_msg_filament_out_alert : AC_msg_filament_out_block); + tftSendLn(isPrintingFromMedia() ? AC_msg_filament_out_alert : AC_msg_filament_out_block); PlayTune(FilamentOut); } -void ChironTFT::ConfirmationRequest(const char * const msg) { +void ChironTFT::confirmationRequest(const char * const msg) { // M108 continue #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("ConfirmationRequest() ", msg, " printer_state:", printer_state); + DEBUG_ECHOLNPGM("confirmationRequest() ", msg, " printer_state:", printer_state); #endif switch (printer_state) { case AC_printer_pausing: { if (strcmp_P(msg, MARLIN_msg_print_paused) == 0 || strcmp_P(msg, MARLIN_msg_nozzle_parked) == 0) { - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button printer_state = AC_printer_paused; } } break; @@ -214,18 +218,18 @@ void ChironTFT::ConfirmationRequest(const char * const msg) { // Heater timeout, send acknowledgement if (strcmp_P(msg, MARLIN_msg_heater_timeout) == 0) { pause_state = AC_paused_heater_timed_out; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button PlayTune(HeaterTimeout); } // Reheat finished, send acknowledgement else if (strcmp_P(msg, MARLIN_msg_reheat_done) == 0) { pause_state = AC_paused_idle; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button } // Filament Purging, send acknowledgement enter run mode else if (strcmp_P(msg, MARLIN_msg_filament_purging) == 0) { pause_state = AC_paused_purging_filament; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button } } break; default: @@ -233,10 +237,10 @@ void ChironTFT::ConfirmationRequest(const char * const msg) { } } -void ChironTFT::StatusChange(const char * const msg) { +void ChironTFT::statusChange(const char * const msg) { #if ACDEBUG(AC_MARLIN) - SERIAL_ECHOLNPGM("StatusChange() ", msg); - SERIAL_ECHOLNPGM("printer_state:", printer_state); + DEBUG_ECHOLNPGM("statusChange() ", msg); + DEBUG_ECHOLNPGM("printer_state:", printer_state); #endif bool msg_matched = false; // The only way to get printer status is to parse messages @@ -247,7 +251,7 @@ void ChironTFT::StatusChange(const char * const msg) { // Ignore the custom machine name if (strcmp_P(msg + strlen(MACHINE_NAME), MARLIN_msg_ready) == 0) { injectCommands(F("M500\nG27")); - SendtoTFTLN(AC_msg_probing_complete); + tftSendLn(AC_msg_probing_complete); printer_state = AC_printer_idle; msg_matched = true; } @@ -255,7 +259,7 @@ void ChironTFT::StatusChange(const char * const msg) { if (strcmp_P(msg, MARLIN_msg_probing_failed) == 0) { PlayTune(BeepBeepBeeep); injectCommands(F("G1 Z50 F500")); - SendtoTFTLN(AC_msg_probing_complete); + tftSendLn(AC_msg_probing_complete); printer_state = AC_printer_idle; msg_matched = true; } @@ -263,14 +267,14 @@ void ChironTFT::StatusChange(const char * const msg) { case AC_printer_printing: { if (strcmp_P(msg, MARLIN_msg_reheating) == 0) { - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button msg_matched = true; } } break; case AC_printer_pausing: { if (strcmp_P(msg, MARLIN_msg_print_paused) == 0) { - SendtoTFTLN(AC_msg_paused); + tftSendLn(AC_msg_paused); printer_state = AC_printer_paused; pause_state = AC_paused_idle; msg_matched = true; @@ -279,7 +283,7 @@ void ChironTFT::StatusChange(const char * const msg) { case AC_printer_stopping: { if (strcmp_P(msg, MARLIN_msg_print_aborted) == 0) { - SendtoTFTLN(AC_msg_stop); + tftSendLn(AC_msg_stop); printer_state = AC_printer_idle; msg_matched = true; } @@ -291,11 +295,11 @@ void ChironTFT::StatusChange(const char * const msg) { // If not matched earlier see if this was a heater message if (!msg_matched) { if (strcmp_P(msg, MARLIN_msg_extruder_heating) == 0) { - SendtoTFTLN(AC_msg_nozzle_heating); + tftSendLn(AC_msg_nozzle_heating); hotend_state = AC_heater_temp_set; } else if (strcmp_P(msg, MARLIN_msg_bed_heating) == 0) { - SendtoTFTLN(AC_msg_bed_heating); + tftSendLn(AC_msg_bed_heating); hotbed_state = AC_heater_temp_set; } else if (strcmp_P(msg, MARLIN_msg_EEPROM_version) == 0) { @@ -304,33 +308,33 @@ void ChironTFT::StatusChange(const char * const msg) { } } -void ChironTFT::PowerLossRecovery() { +void ChironTFT::powerLossRecovery() { printer_state = AC_printer_resuming_from_power_outage; // Play tune to notify user we can recover. last_error = AC_error_powerloss; PlayTune(SOS); SERIAL_ECHOLNF(AC_msg_powerloss_recovery); } -void ChironTFT::PrintComplete() { - SendtoTFT(AC_msg_print_complete); +void ChironTFT::printComplete() { + tftSend(AC_msg_print_complete); printer_state = AC_printer_idle; setSoftEndstopState(true); // enable endstops } -void ChironTFT::SendtoTFT(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel +void ChironTFT::tftSend(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel #if ACDEBUG(AC_SOME) - SERIAL_ECHOF(fstr); + DEBUG_ECHOF(fstr); #endif PGM_P str = FTOP(fstr); while (const char c = pgm_read_byte(str++)) TFTSer.write(c); } -void ChironTFT::SendtoTFTLN(FSTR_P const fstr/*=nullptr*/) { +void ChironTFT::tftSendLn(FSTR_P const fstr/*=nullptr*/) { if (fstr) { #if ACDEBUG(AC_SOME) - SERIAL_ECHOPGM("> "); + DEBUG_ECHOPGM("> "); #endif - SendtoTFT(fstr); + tftSend(fstr); #if ACDEBUG(AC_SOME) SERIAL_EOL(); #endif @@ -338,7 +342,7 @@ void ChironTFT::SendtoTFTLN(FSTR_P const fstr/*=nullptr*/) { TFTSer.println(); } -bool ChironTFT::ReadTFTCommand() { +bool ChironTFT::readTFTCommand() { bool command_ready = false; while (TFTSer.available() > 0 && command_len < MAX_CMND_LEN) { panel_command[command_len] = TFTSer.read(); @@ -352,29 +356,29 @@ bool ChironTFT::ReadTFTCommand() { if (command_ready || command_len == MAX_CMND_LEN) { panel_command[command_len] = '\0'; #if ACDEBUG(AC_ALL) - SERIAL_ECHOLNPGM("len(",command_len,") < ", panel_command); + DEBUG_ECHOLNPGM("len(",command_len,") < ", panel_command); #endif command_ready = true; } return command_ready; } -int8_t ChironTFT::FindToken(char c) { +int8_t ChironTFT::findToken(char c) { for (int8_t pos = 0; pos < command_len; pos++) { if (panel_command[pos] == c) { #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Tpos:", pos, " ", c); + DEBUG_ECHOLNPGM("Tpos:", pos, " ", c); #endif return pos; } } #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Not found: ", c); + DEBUG_ECHOLNPGM("Not found: ", c); #endif return -1; } -void ChironTFT::CheckHeaters() { +void ChironTFT::checkHeaters() { uint8_t faultDuration = 0; // if the hotend temp is abnormal, confirm state before signalling panel @@ -382,7 +386,7 @@ void ChironTFT::CheckHeaters() { while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) { faultDuration++; if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_nozzle_temp_abnormal); + tftSendLn(AC_msg_nozzle_temp_abnormal); last_error = AC_error_abnormal_temp_t0; SERIAL_ECHOLNPGM("Extruder temp abnormal! : ", temp); break; @@ -397,7 +401,7 @@ void ChironTFT::CheckHeaters() { while (!WITHIN(temp, BED_MINTEMP, BED_MAXTEMP)) { faultDuration++; if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_nozzle_temp_abnormal); + tftSendLn(AC_msg_nozzle_temp_abnormal); last_error = AC_error_abnormal_temp_bed; SERIAL_ECHOLNPGM("Bed temp abnormal! : ", temp); break; @@ -409,7 +413,7 @@ void ChironTFT::CheckHeaters() { // Update panel with hotend heater status if (hotend_state != AC_heater_temp_reached) { if (WITHIN(getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -(TEMP_WINDOW), TEMP_WINDOW)) { - SendtoTFTLN(AC_msg_nozzle_heating_done); + tftSendLn(AC_msg_nozzle_heating_done); hotend_state = AC_heater_temp_reached; } } @@ -417,23 +421,23 @@ void ChironTFT::CheckHeaters() { // Update panel with bed heater status if (hotbed_state != AC_heater_temp_reached) { if (WITHIN(getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -(TEMP_BED_WINDOW), TEMP_BED_WINDOW)) { - SendtoTFTLN(AC_msg_bed_heating_done); + tftSendLn(AC_msg_bed_heating_done); hotbed_state = AC_heater_temp_reached; } } } -void ChironTFT::SendFileList(int8_t startindex) { +void ChironTFT::sendFileList(int8_t startindex) { // Respond to panel request for 4 files starting at index #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("## SendFileList ## ", startindex); + DEBUG_ECHOLNPGM("## sendFileList ## ", startindex); #endif - SendtoTFTLN(F("FN ")); + tftSendLn(F("FN ")); filenavigator.getFiles(startindex, panel_type, 4); - SendtoTFTLN(F("END")); + tftSendLn(F("END")); } -void ChironTFT::SelectFile() { +void ChironTFT::selectFile() { if (panel_type <= AC_panel_new) { strncpy(selectedfile, panel_command + 4, command_len - 3); selectedfile[command_len - 4] = '\0'; @@ -443,50 +447,50 @@ void ChironTFT::SelectFile() { selectedfile[command_len - 5] = '\0'; } #if ACDEBUG(AC_FILE) - SERIAL_ECHOLNPGM(" Selected File: ",selectedfile); + DEBUG_ECHOLNPGM(" Selected File: ",selectedfile); #endif switch (selectedfile[0]) { case '/': // Valid file selected - SendtoTFTLN(AC_msg_sd_file_open_success); + tftSendLn(AC_msg_sd_file_open_success); break; case '<': // .. (go up folder level) filenavigator.upDIR(); - SendtoTFTLN(AC_msg_sd_file_open_failed); - SendFileList( 0 ); + tftSendLn(AC_msg_sd_file_open_failed); + sendFileList( 0 ); break; default: // enter sub folder // for new panel remove the '.GCO' tag that was added to the end of the path if (panel_type <= AC_panel_new) selectedfile[strlen(selectedfile) - 4] = '\0'; filenavigator.changeDIR(selectedfile); - SendtoTFTLN(AC_msg_sd_file_open_failed); - SendFileList( 0 ); + tftSendLn(AC_msg_sd_file_open_failed); + sendFileList( 0 ); break; } } -void ChironTFT::ProcessPanelRequest() { +void ChironTFT::processPanelRequest() { // Break these up into logical blocks // as its easier to navigate than one huge switch case! - int8_t tpos = FindToken('A'); + int8_t tpos = findToken('A'); // Panel request are 'A0' - 'A36' if (tpos >= 0) { const int8_t req = atoi(&panel_command[tpos + 1]); // Information requests A0 - A8 and A33 - if (req <= 8 || req == 33) PanelInfo(req); + if (req <= 8 || req == 33) panelInfo(req); // Simple Actions A9 - A28 - else if (req <= 28) PanelAction(req); + else if (req <= 28) panelAction(req); // Process Initiation - else if (req <= 36) PanelProcess(req); + else if (req <= 36) panelProcess(req); } else { #if AUTO_DETECT_CHIRON_TFT // This may be a response to a panel type detection query if (panel_type == AC_panel_unknown) { - tpos = FindToken('S'); // old panel will respond to 'SIZE' with 'SXY 480 320' + tpos = findToken('S'); // old panel will respond to 'SIZE' with 'SXY 480 320' if (tpos >= 0) { if (panel_command[tpos + 1] == 'X' && panel_command[tpos + 2] =='Y') { panel_type = AC_panel_standard; @@ -496,7 +500,7 @@ void ChironTFT::ProcessPanelRequest() { else { // new panel will respond to 'J200' with '[0]=0' // it seems only after a power cycle so detection assumes a new panel - tpos = FindToken('['); + tpos = findToken('['); if (tpos >= 0) { if (panel_command[tpos + 1] == '0' && panel_command[tpos + 2] ==']') { panel_type = AC_panel_new; @@ -508,94 +512,94 @@ void ChironTFT::ProcessPanelRequest() { } #endif - SendtoTFTLN(); // Ignore unknown requests + tftSendLn(); // Ignore unknown requests } } -void ChironTFT::PanelInfo(uint8_t req) { +void ChironTFT::panelInfo(uint8_t req) { // information requests A0-A8 and A33 switch (req) { case 0: // A0 Get HOTEND Temp - SendtoTFT(F("A0V ")); + tftSend(F("A0V ")); TFTSer.println(getActualTemp_celsius(E0)); break; case 1: // A1 Get HOTEND Target Temp - SendtoTFT(F("A1V ")); + tftSend(F("A1V ")); TFTSer.println(getTargetTemp_celsius(E0)); break; case 2: // A2 Get BED Temp - SendtoTFT(F("A2V ")); + tftSend(F("A2V ")); TFTSer.println(getActualTemp_celsius(BED)); break; case 3: // A3 Get BED Target Temp - SendtoTFT(F("A3V ")); + tftSend(F("A3V ")); TFTSer.println(getTargetTemp_celsius(BED)); break; case 4: // A4 Get FAN Speed - SendtoTFT(F("A4V ")); + tftSend(F("A4V ")); TFTSer.println(getActualFan_percent(FAN0)); break; case 5: // A5 Get Current Coordinates - SendtoTFT(F("A5V X: ")); + tftSend(F("A5V X: ")); TFTSer.print(getAxisPosition_mm(X)); - SendtoTFT(F(" Y: ")); + tftSend(F(" Y: ")); TFTSer.print(getAxisPosition_mm(Y)); - SendtoTFT(F(" Z: ")); + tftSend(F(" Z: ")); TFTSer.println(getAxisPosition_mm(Z)); break; case 6: // A6 Get printing progress if (isPrintingFromMedia()) { - SendtoTFT(F("A6V ")); + tftSend(F("A6V ")); TFTSer.println(ui8tostr2(getProgress_percent())); } else - SendtoTFTLN(F("A6V ---")); + tftSendLn(F("A6V ---")); break; case 7: { // A7 Get Printing Time uint32_t time = getProgress_seconds_elapsed() / 60; - SendtoTFT(F("A7V ")); + tftSend(F("A7V ")); TFTSer.print(ui8tostr2(time / 60)); - SendtoTFT(F(" H ")); + tftSend(F(" H ")); TFTSer.print(ui8tostr2(time % 60)); - SendtoTFT(F(" M")); + tftSend(F(" M")); #if ACDEBUG(AC_ALL) - SERIAL_ECHOLNPGM("Print time ", ui8tostr2(time / 60), ":", ui8tostr2(time % 60)); + DEBUG_ECHOLNPGM("Print time ", ui8tostr2(time / 60), ":", ui8tostr2(time % 60)); #endif } break; case 8: // A8 Get SD Card list A8 S0 if (!isMediaInserted()) safe_delay(500); if (!isMediaInserted()) // Make sure the card is removed - SendtoTFTLN(AC_msg_no_sd_card); + tftSendLn(AC_msg_no_sd_card); else if (panel_command[3] == 'S') - SendFileList( atoi( &panel_command[4] ) ); + sendFileList( atoi( &panel_command[4] ) ); break; case 33: // A33 Get firmware info - SendtoTFT(F("J33 ")); + tftSend(F("J33 ")); // If there is an error recorded, show that instead of the FW version - if (!GetLastError()) SendtoTFTLN(F(SHORT_BUILD_VERSION)); + if (!getLastError()) tftSendLn(F(SHORT_BUILD_VERSION)); break; } } -void ChironTFT::PanelAction(uint8_t req) { +void ChironTFT::panelAction(uint8_t req) { switch (req) { case 9: // A9 Pause SD print if (isPrintingFromMedia()) { - SendtoTFTLN(AC_msg_pause); + tftSendLn(AC_msg_pause); pausePrint(); printer_state = AC_printer_pausing; } else - SendtoTFTLN(AC_msg_stop); + tftSendLn(AC_msg_stop); break; case 10: // A10 Resume SD Print @@ -613,7 +617,7 @@ void ChironTFT::PanelAction(uint8_t req) { else { if (printer_state == AC_printer_resuming_from_power_outage) injectCommands(F("M1000 C")); // Cancel recovery - SendtoTFTLN(AC_msg_stop); + tftSendLn(AC_msg_stop); printer_state = AC_printer_idle; } break; @@ -623,7 +627,7 @@ void ChironTFT::PanelAction(uint8_t req) { break; case 13: // A13 Select file - SelectFile(); + selectFile(); break; case 14: // A14 Start Printing @@ -632,11 +636,9 @@ void ChironTFT::PanelAction(uint8_t req) { injectCommands(F("M1000 C")); // Cancel recovery printer_state = AC_printer_idle; } - #if ACDebugLevel >= 1 - SERIAL_ECHOLNPGM("Print: ", selectedfile); - #endif + DEBUG_ECHOLNPGM("Print: ", selectedfile); printFile(selectedfile); - SendtoTFTLN(AC_msg_print_from_sd_card); + tftSendLn(AC_msg_print_from_sd_card); break; case 15: // A15 Resuming from outage @@ -671,7 +673,7 @@ void ChironTFT::PanelAction(uint8_t req) { case 19: // A19 Motors off if (!isPrinting()) { stepper.disable_all_steppers(); - SendtoTFTLN(AC_msg_ready); + tftSendLn(AC_msg_ready); } break; @@ -679,7 +681,7 @@ void ChironTFT::PanelAction(uint8_t req) { if (panel_command[4] == 'S') setFeedrate_percent(atoi(&panel_command[5])); else { - SendtoTFT(F("A20V ")); + tftSend(F("A20V ")); TFTSer.println(getFeedrate_percent()); } break; @@ -707,7 +709,7 @@ void ChironTFT::PanelAction(uint8_t req) { char MoveCmnd[30]; sprintf_P(MoveCmnd, PSTR("G91\nG0%s\nG90"), panel_command + 3); #if ACDEBUG(AC_ACTION) - SERIAL_ECHOLNPGM("Move: ", MoveCmnd); + DEBUG_ECHOLNPGM("Move: ", MoveCmnd); #endif setSoftEndstopState(true); // enable endstops injectCommands(MoveCmnd); @@ -720,7 +722,7 @@ void ChironTFT::PanelAction(uint8_t req) { // Temps defined in configuration.h setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED); setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, E0); - SendtoTFTLN(); + tftSendLn(); hotbed_state = AC_heater_temp_set; hotend_state = AC_heater_temp_set; } @@ -731,7 +733,7 @@ void ChironTFT::PanelAction(uint8_t req) { if (!isPrinting()) { setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED); setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, E0); - SendtoTFTLN(); + tftSendLn(); hotbed_state = AC_heater_temp_set; hotend_state = AC_heater_temp_set; } @@ -742,7 +744,7 @@ void ChironTFT::PanelAction(uint8_t req) { if (!isPrinting()) { setTargetTemp_celsius(0, E0); setTargetTemp_celsius(0, BED); - SendtoTFTLN(AC_msg_ready); + tftSendLn(AC_msg_ready); hotbed_state = AC_heater_off; hotend_state = AC_heater_off; } @@ -761,21 +763,21 @@ void ChironTFT::PanelAction(uint8_t req) { case 28: // A28 Filament set A28 O/C // Ignore request if printing if (isPrinting()) break; - SendtoTFTLN(); + tftSendLn(); break; } } -void ChironTFT::PanelProcess(uint8_t req) { +void ChironTFT::panelProcess(uint8_t req) { switch (req) { case 29: { // A29 Read Mesh Point A29 X1 Y1 xy_uint8_t pos; float pos_z; - pos.x = atoi(&panel_command[FindToken('X')+1]); - pos.y = atoi(&panel_command[FindToken('Y')+1]); + pos.x = atoi(&panel_command[findToken('X')+1]); + pos.y = atoi(&panel_command[findToken('Y')+1]); pos_z = getMeshPoint(pos); - SendtoTFT(F("A29V ")); + tftSend(F("A29V ")); TFTSer.println(pos_z * 100); if (!isPrinting()) { setSoftEndstopState(true); // disable endstops @@ -786,7 +788,7 @@ void ChironTFT::PanelProcess(uint8_t req) { if (isPositionKnown()) { #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z); + DEBUG_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z); #endif // Go up before moving setAxisPosition_mm(3.0,Z); @@ -795,7 +797,7 @@ void ChironTFT::PanelProcess(uint8_t req) { setAxisPosition_mm(20 + (93 * pos.y), Y); setAxisPosition_mm(0.0, Z); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Current Z: ", getAxisPosition_mm(Z)); + DEBUG_ECHOLNPGM("Current Z: ", getAxisPosition_mm(Z)); #endif } } @@ -805,24 +807,24 @@ void ChironTFT::PanelProcess(uint8_t req) { } break; case 30: // A30 Auto leveling - if (FindToken('S') >= 0) { // Start probing New panel adds spaces.. + if (findToken('S') >= 0) { // Start probing New panel adds spaces.. // Ignore request if printing if (isPrinting()) - SendtoTFTLN(AC_msg_probing_not_allowed); // forbid auto leveling + tftSendLn(AC_msg_probing_not_allowed); // forbid auto leveling else { - SendtoTFTLN(AC_msg_start_probing); + tftSendLn(AC_msg_start_probing); injectCommands(F("G28\nG29")); printer_state = AC_printer_probing; } } else - SendtoTFTLN(AC_msg_start_probing); // Just enter levelling menu + tftSendLn(AC_msg_start_probing); // Just enter levelling menu break; case 31: // A31 Adjust all Probe Points // The tokens can occur in different places on the new panel so we need to find it. - if (FindToken('C') >= 0) { // Restore and apply original offsets + if (findToken('C') >= 0) { // Restore and apply original offsets if (!isPrinting()) { injectCommands(F("M501\nM420 S1")); selectedmeshpoint.x = selectedmeshpoint.y = 99; @@ -830,7 +832,7 @@ void ChironTFT::PanelProcess(uint8_t req) { } } - else if (FindToken('D') >= 0) { // Save Z Offset tables and restore leveling state + else if (findToken('D') >= 0) { // Save Z Offset tables and restore leveling state if (!isPrinting()) { setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made injectCommands(F("M500")); @@ -839,8 +841,8 @@ void ChironTFT::PanelProcess(uint8_t req) { } } - else if (FindToken('G') >= 0) { // Get current offset - SendtoTFT(F("A31V ")); + else if (findToken('G') >= 0) { // Get current offset + tftSend(F("A31V ")); // When printing use the live z Offset position // we will use babystepping to move the print head if (isPrinting()) @@ -852,7 +854,7 @@ void ChironTFT::PanelProcess(uint8_t req) { } else { - int8_t tokenpos = FindToken('S'); + int8_t tokenpos = findToken('S'); if (tokenpos >= 0) { // Set offset (adjusts all points by value) float Zshift = atof(&panel_command[tokenpos+1]); setSoftEndstopState(false); // disable endstops @@ -860,22 +862,22 @@ void ChironTFT::PanelProcess(uint8_t req) { // From the leveling panel use the all points UI to adjust the print pos. if (isPrinting()) { #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift); + DEBUG_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift); #endif if (isAxisPositionKnown(Z)) { #if ACDEBUG(AC_INFO) const float currZpos = getAxisPosition_mm(Z); - SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); + DEBUG_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); #endif // Use babystepping to adjust the head position int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Steps to move Z: ", steps); + DEBUG_ECHOLNPGM("Steps to move Z: ", steps); #endif babystepAxis_steps(steps, Z); live_Zoffset += Zshift; } - SendtoTFT(F("A31V ")); + tftSend(F("A31V ")); TFTSer.println(live_Zoffset); } else { @@ -884,23 +886,23 @@ void ChironTFT::PanelProcess(uint8_t req) { const float currval = getMeshPoint(pos); setMeshPoint(pos, constrain(currval + Zshift, AC_LOWEST_MESHPOINT_VAL, 2)); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) ); + DEBUG_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) ); #endif } const float currZOffset = getZOffset_mm(); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift); + DEBUG_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift); #endif setZOffset_mm(currZOffset + Zshift); - SendtoTFT(F("A31V ")); + tftSend(F("A31V ")); TFTSer.println(getZOffset_mm()); if (isAxisPositionKnown(Z)) { // Move Z axis const float currZpos = getAxisPosition_mm(Z); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); + DEBUG_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); #endif setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z); } @@ -916,7 +918,7 @@ void ChironTFT::PanelProcess(uint8_t req) { //TFTSer.println(); break; - // A33 firmware info request see PanelInfo() + // A33 firmware info request see panelInfo() case 34: // A34 Adjust single mesh point A34 C/S X1 Y1 V123 if (panel_command[3] == 'C') { // Restore original offsets @@ -932,8 +934,8 @@ void ChironTFT::PanelProcess(uint8_t req) { float currmesh = getMeshPoint(pos); float newval = atof(&panel_command[11])/100; #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Change mesh point x:", pos.x, " y:", pos.y); - SERIAL_ECHOLNPGM("from ", currmesh, " to ", newval); + DEBUG_ECHOLNPGM("Change mesh point x:", pos.x, " y:", pos.y); + DEBUG_ECHOLNPGM("from ", currmesh, " to ", newval); #endif // Update Meshpoint setMeshPoint(pos,newval); @@ -944,7 +946,7 @@ void ChironTFT::PanelProcess(uint8_t req) { setSoftEndstopState(false); float currZpos = getAxisPosition_mm(Z); #if ACDEBUG(AC_INFO) - SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(newval - currmesh, -0.05, 0.05)); + DEBUG_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(newval - currmesh, -0.05, 0.05)); #endif setAxisPosition_mm(currZpos + constrain(newval - currmesh, -0.05, 0.05), Z); } @@ -953,19 +955,19 @@ void ChironTFT::PanelProcess(uint8_t req) { break; case 36: // A36 Auto leveling for new TFT bet that was a typo in the panel code! - SendtoTFTLN(AC_msg_start_probing); + tftSendLn(AC_msg_start_probing); break; } } -bool ChironTFT::GetLastError() { +bool ChironTFT::getLastError() { switch (last_error) { - case AC_error_abnormal_temp_bed: SendtoTFTLN(AC_msg_error_bed_temp); break; - case AC_error_abnormal_temp_t0: SendtoTFTLN(AC_msg_error_hotend_temp); break; - case AC_error_noSD: SendtoTFTLN(AC_msg_error_sd_card); break; - case AC_error_powerloss: SendtoTFTLN(AC_msg_power_loss); break; - case AC_error_EEPROM: SendtoTFTLN(AC_msg_eeprom_version); break; - case AC_error_filament_runout: SendtoTFTLN(AC_msg_filament_out); break; + case AC_error_abnormal_temp_bed: tftSendLn(AC_msg_error_bed_temp); break; + case AC_error_abnormal_temp_t0: tftSendLn(AC_msg_error_hotend_temp); break; + case AC_error_noSD: tftSendLn(AC_msg_error_sd_card); break; + case AC_error_powerloss: tftSendLn(AC_msg_power_loss); break; + case AC_error_EEPROM: tftSendLn(AC_msg_eeprom_version); break; + case AC_error_filament_runout: tftSendLn(AC_msg_filament_out); break; default: return false; } last_error = AC_error_none; diff --git a/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.h b/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.h index e0517ec640e..25b8145b135 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.h +++ b/Marlin/src/lcd/extui/anycubic_chiron/chiron_tft.h @@ -57,32 +57,32 @@ class ChironTFT { static float live_Zoffset; static file_menu_t file_menu; public: - static void Startup(); - static void IdleLoop(); - static void PrinterKilled(FSTR_P, FSTR_P); - static void MediaEvent(media_event_t); - static void TimerEvent(timer_event_t); - static void FilamentRunout(); - static void ConfirmationRequest(const char * const); - static void StatusChange(const char * const); - static void PowerLossRecovery(); - static void PrintComplete(); - static void SendtoTFT(FSTR_P const=nullptr); - static void SendtoTFTLN(FSTR_P const=nullptr); + static void startup(); + static void idleLoop(); + static void printerKilled(FSTR_P, FSTR_P); + static void mediaEvent(media_event_t); + static void timerEvent(timer_event_t); + static void filamentRunout(); + static void confirmationRequest(const char * const); + static void statusChange(const char * const); + static void powerLossRecovery(); + static void printComplete(); + static void tftSend(FSTR_P const=nullptr); + static void tftSendLn(FSTR_P const=nullptr); private: - static void DetectPanelType(); - static bool ReadTFTCommand(); - static int8_t FindToken(char); - static void CheckHeaters(); - static void SendFileList(int8_t); - static void SelectFile(); - static void ProcessPanelRequest(); - static void PanelInfo(uint8_t); - static void PanelAction(uint8_t); - static void PanelProcess(uint8_t); - static bool GetLastError(); + static void detectPanelType(); + static bool readTFTCommand(); + static int8_t findToken(char); + static void checkHeaters(); + static void sendFileList(int8_t); + static void selectFile(); + static void processPanelRequest(); + static void panelInfo(uint8_t); + static void panelAction(uint8_t); + static void panelProcess(uint8_t); + static bool getLastError(); }; -extern ChironTFT Chiron; +extern ChironTFT chiron; } // Anycubic namespace diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp index a2ad678ac62..0df3bde89d5 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp @@ -35,20 +35,20 @@ namespace ExtUI { - void onStartup() { AnycubicTFT.OnSetup(); } - void onIdle() { AnycubicTFT.OnCommandScan(); } - void onPrinterKilled(FSTR_P const error, FSTR_P const component) { AnycubicTFT.OnKillTFT(); } - void onMediaInserted() { AnycubicTFT.OnSDCardStateChange(true); } - void onMediaError() { AnycubicTFT.OnSDCardError(); } - void onMediaRemoved() { AnycubicTFT.OnSDCardStateChange(false); } + void onStartup() { anycubicTFT.onSetup(); } + void onIdle() { anycubicTFT.onCommandScan(); } + void onPrinterKilled(FSTR_P const error, FSTR_P const component) { anycubicTFT.onKillTFT(); } + void onMediaInserted() { anycubicTFT.onSDCardStateChange(true); } + void onMediaError() { anycubicTFT.onSDCardError(); } + void onMediaRemoved() { anycubicTFT.onSDCardStateChange(false); } void onPlayTone(const uint16_t frequency, const uint16_t duration) { TERN_(SPEAKER, ::tone(BEEPER_PIN, frequency, duration)); } - void onPrintTimerStarted() { AnycubicTFT.OnPrintTimerStarted(); } - void onPrintTimerPaused() { AnycubicTFT.OnPrintTimerPaused(); } - void onPrintTimerStopped() { AnycubicTFT.OnPrintTimerStopped(); } - void onFilamentRunout(const extruder_t extruder) { AnycubicTFT.OnFilamentRunout(); } - void onUserConfirmRequired(const char * const msg) { AnycubicTFT.OnUserConfirmRequired(msg); } + void onPrintTimerStarted() { anycubicTFT.onPrintTimerStarted(); } + void onPrintTimerPaused() { anycubicTFT.onPrintTimerPaused(); } + void onPrintTimerStopped() { anycubicTFT.onPrintTimerStopped(); } + void onFilamentRunout(const extruder_t extruder) { anycubicTFT.onFilamentRunout(); } + void onUserConfirmRequired(const char * const msg) { anycubicTFT.onUserConfirmRequired(msg); } void onStatusChanged(const char * const msg) {} void onHomingStart() {} diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp index 36b24861fe3..dca0f2e85da 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -24,6 +24,8 @@ #if ENABLED(ANYCUBIC_LCD_I3MEGA) //#define ANYCUBIC_LCD_DEBUG +#define DEBUG_OUT ANYCUBIC_LCD_DEBUG +#include "../../../core/debug_out.h" #include "anycubic_i3mega_lcd.h" #include "../ui_api.h" @@ -40,13 +42,8 @@ #define SEND_PGM_VAL(x,y) (send_P(PSTR(x)), sendLine(i16tostr3rj(y))) #define SEND(x) send(x) #define SENDLINE(x) sendLine(x) -#if ENABLED(ANYCUBIC_LCD_DEBUG) - #define SENDLINE_DBG_PGM(x,y) do{ sendLine_P(PSTR(x)); SERIAL_ECHOLNPGM(y); }while(0) - #define SENDLINE_DBG_PGM_VAL(x,y,z) do{ sendLine_P(PSTR(x)); SERIAL_ECHOLNPGM(y, z); }while(0) -#else - #define SENDLINE_DBG_PGM(x,y) sendLine_P(PSTR(x)) - #define SENDLINE_DBG_PGM_VAL(x,y,z) sendLine_P(PSTR(x)) -#endif +#define SENDLINE_DBG_PGM(x,y) do{ sendLine_P(PSTR(x)); DEBUG_ECHOLNPGM(y); }while(0) +#define SENDLINE_DBG_PGM_VAL(x,y,z) do{ sendLine_P(PSTR(x)); DEBUG_ECHOLNPGM(y, z); }while(0) // Append ".gcode" to filename, if requested. Used for some DGUS-clone displays with built-in filter. // Filenames are limited to 26 characters, so the actual name for the FILENAME can be 20 characters at most. @@ -54,21 +51,20 @@ #define SPECIAL_MENU_FILENAME(A) A TERN_(ANYCUBIC_LCD_GCODE_EXT, ".gcode") #define SPECIAL_MENU_ALTNAME(A, B) TERN(ANYCUBIC_LCD_GCODE_EXT, A ".gcode", B) -AnycubicTFTClass AnycubicTFT; +AnycubicTFTClass anycubicTFT; -char AnycubicTFTClass::TFTcmdbuffer[TFTBUFSIZE][TFT_MAX_CMD_SIZE]; -int AnycubicTFTClass::TFTbuflen = 0, - AnycubicTFTClass::TFTbufindr = 0, - AnycubicTFTClass::TFTbufindw = 0; +char AnycubicTFTClass::tftCommands[TFTBUFSIZE][TFT_MAX_CMD_SIZE]; +int AnycubicTFTClass::tftBufLen = 0, + AnycubicTFTClass::tftBufIndR = 0, + AnycubicTFTClass::tftBufIndW = 0; char AnycubicTFTClass::serial3_char; -int AnycubicTFTClass::serial3_count = 0; -char* AnycubicTFTClass::TFTstrchr_pointer; -uint8_t AnycubicTFTClass::SpecialMenu = false; +char* AnycubicTFTClass::tftStrchrPtr; +uint8_t AnycubicTFTClass::specialMenu = false; AnycubicMediaPrintState AnycubicTFTClass::mediaPrintingState = AMPRINTSTATE_NOT_PRINTING; AnycubicMediaPauseState AnycubicTFTClass::mediaPauseState = AMPAUSESTATE_NOT_PAUSED; -char AnycubicTFTClass::SelectedDirectory[30]; -char AnycubicTFTClass::SelectedFile[FILENAME_LENGTH]; +char AnycubicTFTClass::selectedDirectory[30]; +char AnycubicTFTClass::selectedFile[FILENAME_LENGTH]; // Serial helpers static void sendNewLine() { LCD_SERIAL.write('\r'); LCD_SERIAL.write('\n'); } @@ -84,7 +80,7 @@ using namespace ExtUI; AnycubicTFTClass::AnycubicTFTClass() {} -void AnycubicTFTClass::OnSetup() { +void AnycubicTFTClass::onSetup() { #ifndef LCD_BAUDRATE #define LCD_BAUDRATE 115200 #endif @@ -94,9 +90,6 @@ void AnycubicTFTClass::OnSetup() { delay_ms(10); // Init the state of the key pins running on the TFT - #if BOTH(HAS_MEDIA, HAS_SD_DETECT) - SET_INPUT_PULLUP(SD_DETECT_PIN); - #endif #if ENABLED(FILAMENT_RUNOUT_SENSOR) SET_INPUT_PULLUP(FIL_RUNOUT1_PIN); #endif @@ -104,30 +97,26 @@ void AnycubicTFTClass::OnSetup() { mediaPrintingState = AMPRINTSTATE_NOT_PRINTING; mediaPauseState = AMPAUSESTATE_NOT_PAUSED; - // DoSDCardStateCheck(); + // doSDCardStateCheck(); SENDLINE_DBG_PGM("J12", "TFT Serial Debug: Ready... J12"); // J12 Ready delay_ms(10); - DoFilamentRunoutCheck(); - SelectedFile[0] = 0; + doFilamentRunoutCheck(); + selectedFile[0] = 0; #if ENABLED(STARTUP_CHIME) injectCommands(F("M300 P250 S554\nM300 P250 S554\nM300 P250 S740\nM300 P250 S554\nM300 P250 S740\nM300 P250 S554\nM300 P500 S831")); #endif - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: Finished startup"); - #endif + DEBUG_ECHOLNPGM("TFT Serial Debug: Finished startup"); } -void AnycubicTFTClass::OnCommandScan() { +void AnycubicTFTClass::onCommandScan() { static millis_t nextStopCheck = 0; // used to slow the stopped print check down to reasonable times const millis_t ms = millis(); if (ELAPSED(ms, nextStopCheck)) { nextStopCheck = ms + 1000UL; - if (mediaPrintingState == AMPRINTSTATE_STOP_REQUESTED && IsNozzleHomed()) { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: Finished stopping print, releasing motors ..."); - #endif + if (mediaPrintingState == AMPRINTSTATE_STOP_REQUESTED && isNozzleHomed()) { + DEBUG_ECHOLNPGM("TFT Serial Debug: Finished stopping print, releasing motors ..."); mediaPrintingState = AMPRINTSTATE_NOT_PRINTING; mediaPauseState = AMPAUSESTATE_NOT_PAUSED; injectCommands(F("M84\nM27")); // disable stepper motors and force report of SD status @@ -137,44 +126,36 @@ void AnycubicTFTClass::OnCommandScan() { } } - if (TFTbuflen < (TFTBUFSIZE - 1)) - GetCommandFromTFT(); + if (tftBufLen < (TFTBUFSIZE) - 1) + getCommandFromTFT(); - if (TFTbuflen) { - TFTbuflen = (TFTbuflen - 1); - TFTbufindr = (TFTbufindr + 1) % TFTBUFSIZE; + if (tftBufLen) { + --tftBufLen; + tftBufIndR = (tftBufIndR + 1) % (TFTBUFSIZE); } } -void AnycubicTFTClass::OnKillTFT() { +void AnycubicTFTClass::onKillTFT() { SENDLINE_DBG_PGM("J11", "TFT Serial Debug: Kill command... J11"); } -void AnycubicTFTClass::OnSDCardStateChange(bool isInserted) { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: OnSDCardStateChange event triggered...", isInserted); - #endif - DoSDCardStateCheck(); +void AnycubicTFTClass::onSDCardStateChange(bool isInserted) { + DEBUG_ECHOLNPGM("TFT Serial Debug: onSDCardStateChange event triggered...", isInserted); + doSDCardStateCheck(); } -void AnycubicTFTClass::OnSDCardError() { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: OnSDCardError event triggered..."); - #endif +void AnycubicTFTClass::onSDCardError() { + DEBUG_ECHOLNPGM("TFT Serial Debug: onSDCardError event triggered..."); SENDLINE_DBG_PGM("J21", "TFT Serial Debug: On SD Card Error ... J21"); } -void AnycubicTFTClass::OnFilamentRunout() { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: FilamentRunout triggered..."); - #endif - DoFilamentRunoutCheck(); +void AnycubicTFTClass::onFilamentRunout() { + DEBUG_ECHOLNPGM("TFT Serial Debug: onFilamentRunout triggered..."); + doFilamentRunoutCheck(); } -void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: OnUserConfirmRequired triggered... ", msg); - #endif +void AnycubicTFTClass::onUserConfirmRequired(const char * const msg) { + DEBUG_ECHOLNPGM("TFT Serial Debug: onUserConfirmRequired triggered... ", msg); #if HAS_MEDIA /** @@ -225,190 +206,188 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) { #endif } -float AnycubicTFTClass::CodeValue() { - return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], nullptr)); +float AnycubicTFTClass::codeValue() { + return (strtod(&tftCommands[tftBufIndR][tftStrchrPtr - tftCommands[tftBufIndR] + 1], nullptr)); } -bool AnycubicTFTClass::CodeSeen(char code) { - TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code); - return !!TFTstrchr_pointer; // Return True if a character was found +bool AnycubicTFTClass::codeSeen(char code) { + tftStrchrPtr = strchr(tftCommands[tftBufIndR], code); + return !!tftStrchrPtr; // Return True if a character was found } -bool AnycubicTFTClass::IsNozzleHomed() { +bool AnycubicTFTClass::isNozzleHomed() { const float xPosition = getAxisPosition_mm((axis_t) X); const float yPosition = getAxisPosition_mm((axis_t) Y); return WITHIN(xPosition, X_MIN_POS - 0.1, X_MIN_POS + 0.1) && WITHIN(yPosition, Y_MIN_POS - 0.1, Y_MIN_POS + 0.1); } -void AnycubicTFTClass::HandleSpecialMenu() { +void AnycubicTFTClass::handleSpecialMenu() { /** * NOTE: that the file selection command actual lowercases the entire selected file/foldername, so charracter comparisons need to be lowercase. */ - if (SelectedDirectory[0] == '<') { - switch (SelectedDirectory[1]) { - case 'e': // "" - SpecialMenu = false; - return; + if (selectedDirectory[0] != '<') { + DEBUG_ECHOLNPGM("TFT Serial Debug: Attempted to handleSpecialMenu on non-special menu... ", selectedDirectory); + return; + } + + switch (selectedDirectory[1]) { + default: break; + + case 'e': specialMenu = false; return; // "" + + #if ENABLED(PROBE_MANUALLY) + + case '0': + switch (selectedDirectory[2]) { + default: break; + + case '1': // "<01ZUp0.1>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Z Up 0.1")); + injectCommands(F("G91\nG1 Z+0.1\nG90")); + break; + + case '2': // "<02ZUp0.02>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Z Up 0.02")); + injectCommands(F("G91\nG1 Z+0.02\nG90")); + break; + + case '3': // "<03ZDn0.02>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Z Down 0.02")); + injectCommands(F("G91\nG1 Z-0.02\nG90")); + break; + + case '4': // "<04ZDn0.1>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Z Down 0.1")); + injectCommands(F("G91\nG1 Z-0.1\nG90")); + break; + + case '5': // "<05PrehtBed>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Preheat Bed")); + injectCommands(F("M140 S65")); + break; + + case '6': // "<06SMeshLvl>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Start Mesh Leveling")); + injectCommands(F("G29S1")); + break; + + case '7': // "<07MeshNPnt>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Next Mesh Point")); + injectCommands(F("G29S2")); + break; + + case '8': // "<08HtEndPID>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Auto Tune Hotend PID")); + // need to dwell for half a second to give the fan a chance to start before the pid tuning starts + injectCommands(F("M106 S204\nG4 P500\nM303 E0 S215 C15 U1")); + break; + + case '9': // "<09HtBedPID>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Auto Tune Hotbed Pid")); + injectCommands(F("M303 E-1 S65 C6 U1")); + break; + } break; - #if ENABLED(PROBE_MANUALLY) - case '0': - switch (SelectedDirectory[2]) { - case '1': // "<01ZUp0.1>" - SERIAL_ECHOLNPGM("Special Menu: Z Up 0.1"); - injectCommands(F("G91\nG1 Z+0.1\nG90")); - break; + case '1': + switch (selectedDirectory[2]) { + default: break; - case '2': // "<02ZUp0.02>" - SERIAL_ECHOLNPGM("Special Menu: Z Up 0.02"); - injectCommands(F("G91\nG1 Z+0.02\nG90")); - break; - - case '3': // "<03ZDn0.02>" - SERIAL_ECHOLNPGM("Special Menu: Z Down 0.02"); - injectCommands(F("G91\nG1 Z-0.02\nG90")); - break; - - case '4': // "<04ZDn0.1>" - SERIAL_ECHOLNPGM("Special Menu: Z Down 0.1"); - injectCommands(F("G91\nG1 Z-0.1\nG90")); - break; - - case '5': // "<05PrehtBed>" - SERIAL_ECHOLNPGM("Special Menu: Preheat Bed"); - injectCommands(F("M140 S65")); - break; - - case '6': // "<06SMeshLvl>" - SERIAL_ECHOLNPGM("Special Menu: Start Mesh Leveling"); - injectCommands(F("G29S1")); - break; - - case '7': // "<07MeshNPnt>" - SERIAL_ECHOLNPGM("Special Menu: Next Mesh Point"); - injectCommands(F("G29S2")); - break; - - case '8': // "<08HtEndPID>" - SERIAL_ECHOLNPGM("Special Menu: Auto Tune Hotend PID"); - // need to dwell for half a second to give the fan a chance to start before the pid tuning starts - injectCommands(F("M106 S204\nG4 P500\nM303 E0 S215 C15 U1")); - break; - - case '9': // "<09HtBedPID>" - SERIAL_ECHOLNPGM("Special Menu: Auto Tune Hotbed Pid"); - injectCommands(F("M303 E-1 S65 C6 U1")); - break; - - default: - break; - } + case '0': // "<10FWDeflts>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Load FW Defaults")); + injectCommands(F("M502\nM300 P105 S1661\nM300 P210 S1108")); break; - case '1': - switch (SelectedDirectory[2]) { - case '0': // "<10FWDeflts>" - SERIAL_ECHOLNPGM("Special Menu: Load FW Defaults"); - injectCommands(F("M502\nM300 P105 S1661\nM300 P210 S1108")); - break; - - case '1': // "<11SvEEPROM>" - SERIAL_ECHOLNPGM("Special Menu: Save EEPROM"); - injectCommands(F("M500\nM300 P105 S1108\nM300 P210 S1661")); - break; - - default: - break; - } + case '1': // "<11SvEEPROM>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Save EEPROM")); + injectCommands(F("M500\nM300 P105 S1108\nM300 P210 S1661")); break; - #else // if ENABLED(PROBE_MANUALLY) - case '0': - switch (SelectedDirectory[2]) { - case '1': // "<01PrehtBed>" - SERIAL_ECHOLNPGM("Special Menu: Preheat Bed"); - injectCommands(F("M140 S65")); - break; + } + break; - case '2': // "<02ABL>" - SERIAL_ECHOLNPGM("Special Menu: Auto Bed Leveling"); - injectCommands(F("G29N")); - break; + #else // !PROBE_MANUALLY - case '3': // "<03HtendPID>" - SERIAL_ECHOLNPGM("Special Menu: Auto Tune Hotend PID"); - // need to dwell for half a second to give the fan a chance to start before the pid tuning starts - injectCommands(F("M106 S204\nG4 P500\nM303 E0 S215 C15 U1")); - break; + case '0': + switch (selectedDirectory[2]) { + default: break; - case '4': // "<04HtbedPID>" - SERIAL_ECHOLNPGM("Special Menu: Auto Tune Hotbed Pid"); - injectCommands(F("M303 E-1 S65 C6 U1")); - break; - - case '5': // "<05FWDeflts>" - SERIAL_ECHOLNPGM("Special Menu: Load FW Defaults"); - injectCommands(F("M502\nM300 P105 S1661\nM300 P210 S1108")); - break; - - case '6': // "<06SvEEPROM>" - SERIAL_ECHOLNPGM("Special Menu: Save EEPROM"); - injectCommands(F("M500\nM300 P105 S1108\nM300 P210 S1661")); - break; - - case '7': // <07SendM108> - SERIAL_ECHOLNPGM("Special Menu: Send User Confirmation"); - injectCommands(F("M108")); - break; - - default: - break; - } + case '1': // "<01PrehtBed>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Preheat Bed")); + injectCommands(F("M140 S65")); break; - #endif // PROBE_MANUALLY - default: + case '2': // "<02ABL>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Auto Bed Leveling")); + injectCommands(F("G29N")); break; - } - #if ENABLED(ANYCUBIC_LCD_DEBUG) - } - else { - SERIAL_ECHOPGM("TFT Serial Debug: Attempted to HandleSpecialMenu on non-special menu... "); - SERIAL_ECHOLN(SelectedDirectory); - #endif + + case '3': // "<03HtendPID>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Auto Tune Hotend PID")); + // need to dwell for half a second to give the fan a chance to start before the pid tuning starts + injectCommands(F("M106 S204\nG4 P500\nM303 E0 S215 C15 U1")); + break; + + case '4': // "<04HtbedPID>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Auto Tune Hotbed Pid")); + injectCommands(F("M303 E-1 S65 C6 U1")); + break; + + case '5': // "<05FWDeflts>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Load FW Defaults")); + injectCommands(F("M502\nM300 P105 S1661\nM300 P210 S1108")); + break; + + case '6': // "<06SvEEPROM>" + SERIAL_ECHOLNPGM("Special Menu: ", F("Save EEPROM")); + injectCommands(F("M500\nM300 P105 S1108\nM300 P210 S1661")); + break; + + case '7': // <07SendM108> + SERIAL_ECHOLNPGM("Special Menu: ", F("Send User Confirmation")); + injectCommands(F("M108")); + break; + } + break; + + #endif // !PROBE_MANUALLY } + } -void AnycubicTFTClass::RenderCurrentFileList() { +void AnycubicTFTClass::renderCurrentFileList() { #if HAS_MEDIA uint16_t selectedNumber = 0; - SelectedDirectory[0] = 0; - SelectedFile[0] = 0; + selectedDirectory[0] = 0; + selectedFile[0] = 0; FileList currentFileList; SENDLINE_PGM("FN "); // Filelist start - if (!isMediaInserted() && !SpecialMenu) { + if (!isMediaInserted() && !specialMenu) { SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to render Current File List... J02"); SENDLINE_PGM("")); } else { - if (CodeSeen('S')) - selectedNumber = CodeValue(); + if (codeSeen('S')) + selectedNumber = codeValue(); - if (SpecialMenu) - RenderSpecialMenu(selectedNumber); + if (specialMenu) + renderSpecialMenu(selectedNumber); else if (selectedNumber <= currentFileList.count()) - RenderCurrentFolder(selectedNumber); + renderCurrentFolder(selectedNumber); } SENDLINE_PGM("END"); // Filelist stop #endif // HAS_MEDIA } -void AnycubicTFTClass::RenderSpecialMenu(uint16_t selectedNumber) { +void AnycubicTFTClass::renderSpecialMenu(uint16_t selectedNumber) { + switch (selectedNumber) { + default: break; + #if ENABLED(PROBE_MANUALLY) case 0: // First Page SENDLINE_PGM("<01ZUP~1.GCO"); @@ -442,7 +421,9 @@ void AnycubicTFTClass::RenderSpecialMenu(uint16_t selectedNumber) { SENDLINE_PGM("")); break; - #else + + #else // !PROBE_MANUALLY + case 0: // First Page SENDLINE_PGM("<01PRE~1.GCO"); SENDLINE_PGM(SPECIAL_MENU_FILENAME("")); @@ -465,25 +446,16 @@ void AnycubicTFTClass::RenderSpecialMenu(uint16_t selectedNumber) { SENDLINE_PGM(SPECIAL_MENU_FILENAME("")); break; - #endif // PROBE_MANUALLY - - default: - break; + #endif // !PROBE_MANUALLY } } -void AnycubicTFTClass::RenderCurrentFolder(uint16_t selectedNumber) { +void AnycubicTFTClass::renderCurrentFolder(uint16_t selectedNumber) { FileList currentFileList; - uint16_t cnt = selectedNumber; - uint16_t max_files; - uint16_t dir_files = currentFileList.count(); + const uint16_t dir_files = currentFileList.count(), + max_files = (dir_files - selectedNumber) < 4 ? dir_files : selectedNumber + 3; - if ((dir_files - selectedNumber) < 4) - max_files = dir_files; - else - max_files = selectedNumber + 3; - - for (cnt = selectedNumber; cnt <= max_files; cnt++) { + for (uint16_t cnt = selectedNumber; cnt <= max_files; cnt++) { if (cnt == 0) { // Special Entry if (currentFileList.isAtRootDir()) { SENDLINE_PGM(" 0 && TFTbuflen < TFTBUFSIZE) { - serial3_char = LCD_SERIAL.read(); - if (serial3_char == '\n' || - serial3_char == '\r' || - serial3_char == ':' || - serial3_count >= (TFT_MAX_CMD_SIZE - 1) - ) { + while (LCD_SERIAL.available() > 0 && tftBufLen < (TFTBUFSIZE)) { + char c = LCD_SERIAL.read(); + if (c != '\n' && c != '\r' && c != ':' && serial_count < (TFT_MAX_CMD_SIZE - 1)) { + tftCommands[tftBufIndW][serial_count++] = c; + continue; + } - if (!serial3_count) return; // if empty line + if (!serial_count) return; // if empty line - TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string + tftCommands[tftBufIndW][serial_count] = 0; // terminate string - if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != nullptr)) { - int16_t a_command; - TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A'); - a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], nullptr)))); + if ((strchr(tftCommands[tftBufIndW], 'A') != nullptr)) { + int16_t a_command; + tftStrchrPtr = strchr(tftCommands[tftBufIndW], 'A'); + a_command = ((int)((strtod(&tftCommands[tftBufIndW][tftStrchrPtr - tftCommands[tftBufIndW] + 1], nullptr)))); - #if ENABLED(ANYCUBIC_LCD_DEBUG) - if ((a_command > 7) && (a_command != 20)) // No debugging of status polls, please! - SERIAL_ECHOLNPGM("TFT Serial Command: ", TFTcmdbuffer[TFTbufindw]); - #endif - - switch (a_command) { - case 0: { // A0 GET HOTEND TEMP - const celsius_float_t hotendActualTemp = getActualTemp_celsius(E0); - SEND_PGM_VAL("A0V ", ROUND(hotendActualTemp)); - } - break; - - case 1: { // A1 GET HOTEND TARGET TEMP - const celsius_float_t hotendTargetTemp = getTargetTemp_celsius(E0); - SEND_PGM_VAL("A1V ", ROUND(hotendTargetTemp)); - } - break; - - case 2: { // A2 GET HOTBED TEMP - const celsius_float_t heatedBedActualTemp = getActualTemp_celsius(BED); - SEND_PGM_VAL("A2V ", ROUND(heatedBedActualTemp)); - } - break; - - case 3: { // A3 GET HOTBED TARGET TEMP - const celsius_float_t heatedBedTargetTemp = getTargetTemp_celsius(BED); - SEND_PGM_VAL("A3V ", ROUND(heatedBedTargetTemp)); - } break; - - case 4: { // A4 GET FAN SPEED - SEND_PGM_VAL("A4V ", int(getActualFan_percent(FAN0))); - } break; - - case 5: { // A5 GET CURRENT COORDINATE - const float xPosition = getAxisPosition_mm(X), - yPosition = getAxisPosition_mm(Y), - zPosition = getAxisPosition_mm(Z); - SEND_PGM("A5V X: "); LCD_SERIAL.print(xPosition); - SEND_PGM( " Y: "); LCD_SERIAL.print(yPosition); - SEND_PGM( " Z: "); LCD_SERIAL.print(zPosition); - SENDLINE_PGM(""); - } break; - - case 6: // A6 GET SD CARD PRINTING STATUS - #if HAS_MEDIA - if (isPrintingFromMedia()) { - SEND_PGM("A6V "); - if (isMediaInserted()) - SENDLINE(ui8tostr3rj(getProgress_percent())); - else - SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to return printing status... J02"); - } - else - SENDLINE_PGM("A6V ---"); - #endif - break; - - case 7: { // A7 GET PRINTING TIME - const uint32_t elapsedSeconds = getProgress_seconds_elapsed(); - SEND_PGM("A7V "); - if (elapsedSeconds != 0) { // print time - const uint32_t elapsedMinutes = elapsedSeconds / 60; - SEND(ui8tostr2(elapsedMinutes / 60)); - SEND_PGM(" H "); - SEND(ui8tostr2(elapsedMinutes % 60)); - SENDLINE_PGM(" M"); - } - else - SENDLINE_PGM(" 999:999"); - } - break; - - case 8: // A8 GET SD LIST - #if HAS_MEDIA - SelectedFile[0] = 0; - RenderCurrentFileList(); - #endif - break; - - case 9: // A9 pause sd print - #if HAS_MEDIA - if (isPrintingFromMedia()) - PausePrint(); - #endif - break; - - case 10: // A10 resume sd print - #if HAS_MEDIA - if (isPrintingFromMediaPaused()) - ResumePrint(); - #endif - break; - - case 11: // A11 STOP SD PRINT - TERN_(HAS_MEDIA, StopPrint()); - break; - - case 12: // A12 kill - kill(F(STR_ERR_KILLED)); - break; - - case 13: // A13 SELECTION FILE - #if HAS_MEDIA - if (isMediaInserted()) { - starpos = (strchr(TFTstrchr_pointer + 4, '*')); - if (TFTstrchr_pointer[4] == '/') { - strcpy(SelectedDirectory, TFTstrchr_pointer + 5); - SelectedFile[0] = 0; - SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected - SENDLINE_PGM(""); - } - else if (TFTstrchr_pointer[4] == '<') { - strcpy(SelectedDirectory, TFTstrchr_pointer + 4); - SpecialMenu = true; - SelectedFile[0] = 0; - SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected - SENDLINE_PGM(""); - } - else { - SelectedDirectory[0] = 0; - - if (starpos) *(starpos - 1) = '\0'; - - strcpy(SelectedFile, TFTstrchr_pointer + 4); - SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected - } - } - #endif - break; - - case 14: // A14 START PRINTING - #if HAS_MEDIA - if (!isPrinting() && strlen(SelectedFile) > 0) - StartPrint(); - #endif - break; - - case 15: // A15 RESUMING FROM OUTAGE - // TODO: JBA implement resume form outage - break; - - case 16: { // A16 set hotend temp - uint16_t tempvalue; - if (CodeSeen('S')) { - tempvalue = constrain(CodeValue(), 0, 275); - setTargetTemp_celsius(tempvalue, (extruder_t)E0); - } - else if (CodeSeen('C') && !isPrinting()) { - if (getAxisPosition_mm(Z) < 10) - injectCommands(F("G1 Z10")); // RASE Z AXIS - tempvalue = constrain(CodeValue(), 0, 275); - setTargetTemp_celsius(tempvalue, (extruder_t)E0); - } - } - break; - - case 17: { // A17 set heated bed temp - uint16_t tempbed; - if (CodeSeen('S')) { - tempbed = constrain(CodeValue(), 0, 100); - setTargetTemp_celsius(tempbed, (heater_t)BED); - } - } - break; - - case 18: { // A18 set fan speed - float fanPercent; - if (CodeSeen('S')) { - fanPercent = CodeValue(); - fanPercent = constrain(fanPercent, 0, 100); - setTargetFan_percent(fanPercent, FAN0); - } - else - fanPercent = 100; - - setTargetFan_percent(fanPercent, FAN0); - SENDLINE_PGM(""); - } - break; - - case 19: // A19 stop stepper drivers - sent on stop extrude command and on turn motors off command - if (!isPrinting()) { - quickstop_stepper(); - stepper.disable_all_steppers(); - } - - SENDLINE_PGM(""); - break; - - case 20: // A20 read printing speed - if (CodeSeen('S')) - feedrate_percentage = constrain(CodeValue(), 40, 999); - else - SEND_PGM_VAL("A20V ", feedrate_percentage); - break; - - case 21: // A21 all home - if (!isPrinting() && !isPrintingFromMediaPaused()) { - if (CodeSeen('X') || CodeSeen('Y') || CodeSeen('Z')) { - if (CodeSeen('X')) - injectCommands(F("G28X")); - if (CodeSeen('Y')) - injectCommands(F("G28Y")); - if (CodeSeen('Z')) - injectCommands(F("G28Z")); - } - else if (CodeSeen('C')) { - injectCommands_P(G28_STR); - } - } - break; - - case 22: // A22 move X/Y/Z or extrude - if (!isPrinting()) { - float coorvalue; - uint16_t movespeed = 0; - char commandStr[30]; - char fullCommandStr[38]; - - commandStr[0] = 0; // empty string - if (CodeSeen('F')) // Set feedrate - movespeed = CodeValue(); - - if (CodeSeen('X')) { // Move in X direction - coorvalue = CodeValue(); - if ((coorvalue <= 0.2) && coorvalue > 0) - sprintf_P(commandStr, PSTR("G1 X0.1F%i"), movespeed); - else if ((coorvalue <= -0.1) && coorvalue > -1) - sprintf_P(commandStr, PSTR("G1 X-0.1F%i"), movespeed); - else - sprintf_P(commandStr, PSTR("G1 X%iF%i"), int(coorvalue), movespeed); - } - else if (CodeSeen('Y')) { // Move in Y direction - coorvalue = CodeValue(); - if ((coorvalue <= 0.2) && coorvalue > 0) - sprintf_P(commandStr, PSTR("G1 Y0.1F%i"), movespeed); - else if ((coorvalue <= -0.1) && coorvalue > -1) - sprintf_P(commandStr, PSTR("G1 Y-0.1F%i"), movespeed); - else - sprintf_P(commandStr, PSTR("G1 Y%iF%i"), int(coorvalue), movespeed); - } - else if (CodeSeen('Z')) { // Move in Z direction - coorvalue = CodeValue(); - if ((coorvalue <= 0.2) && coorvalue > 0) - sprintf_P(commandStr, PSTR("G1 Z0.1F%i"), movespeed); - else if ((coorvalue <= -0.1) && coorvalue > -1) - sprintf_P(commandStr, PSTR("G1 Z-0.1F%i"), movespeed); - else - sprintf_P(commandStr, PSTR("G1 Z%iF%i"), int(coorvalue), movespeed); - } - else if (CodeSeen('E')) { // Extrude - coorvalue = CodeValue(); - if ((coorvalue <= 0.2) && coorvalue > 0) - sprintf_P(commandStr, PSTR("G1 E0.1F%i"), movespeed); - else if ((coorvalue <= -0.1) && coorvalue > -1) - sprintf_P(commandStr, PSTR("G1 E-0.1F%i"), movespeed); - else - sprintf_P(commandStr, PSTR("G1 E%iF500"), int(coorvalue)); - } - - if (strlen(commandStr) > 0) { - sprintf_P(fullCommandStr, PSTR("G91\n%s\nG90"), commandStr); - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOPGM("TFT Serial Debug: A22 Move final request with gcode... "); - SERIAL_ECHOLN(fullCommandStr); - #endif - injectCommands(fullCommandStr); - } - } - SENDLINE_PGM(""); - break; - - case 23: // A23 preheat pla - if (!isPrinting()) { - if (getAxisPosition_mm(Z) < 10) - injectCommands(F("G1 Z10")); // RASE Z AXIS - - setTargetTemp_celsius(PREHEAT_1_TEMP_BED, (heater_t)BED); - setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, (extruder_t)E0); - SENDLINE_PGM("OK"); - } - break; - - case 24:// A24 preheat abs - if (!isPrinting()) { - if (getAxisPosition_mm(Z) < 10) - injectCommands(F("G1 Z10")); // RASE Z AXIS - - setTargetTemp_celsius(PREHEAT_2_TEMP_BED, (heater_t)BED); - setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, (extruder_t)E0); - SENDLINE_PGM("OK"); - } - break; - - case 25: // A25 cool down - if (!isPrinting()) { - setTargetTemp_celsius(0, (heater_t) BED); - setTargetTemp_celsius(0, (extruder_t) E0); - - SENDLINE_DBG_PGM("J12", "TFT Serial Debug: Cooling down... J12"); // J12 cool down - } - break; - - case 26: // A26 refresh SD - #if HAS_MEDIA - if (isMediaInserted()) { - if (strlen(SelectedDirectory) > 0) { - FileList currentFileList; - if ((SelectedDirectory[0] == '.') && (SelectedDirectory[1] == '.')) { - currentFileList.upDir(); - } - else { - if (SelectedDirectory[0] == '<') - HandleSpecialMenu(); - else - currentFileList.changeDir(SelectedDirectory); - } - } - } - else { - SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to refresh SD A26... J02"); - } - - SelectedDirectory[0] = 0; - #endif - break; - - #if ENABLED(SERVO_ENDSTOPS) - case 27: break; // A27 servos angles adjust - #endif - - case 28: // A28 filament test - if (CodeSeen('O')) - NOOP; - else if (CodeSeen('C')) - NOOP; - SENDLINE_PGM(""); - break; - - case 33: // A33 get version info - SEND_PGM("J33 "); - SENDLINE_PGM(DETAILED_BUILD_VERSION); - break; - - default: - break; - } + if (a_command > 7 && a_command != 20) { // No debugging of status polls, please! + DEBUG_ECHOLNPGM("TFT Serial Command: ", tftCommands[tftBufIndW]); } - TFTbufindw = (TFTbufindw + 1) % TFTBUFSIZE; - TFTbuflen += 1; - serial3_count = 0; // clear buffer + switch (a_command) { + case 0: { // A0 GET HOTEND TEMP + const celsius_float_t hotendActualTemp = getActualTemp_celsius(E0); + SEND_PGM_VAL("A0V ", ROUND(hotendActualTemp)); + } + break; + + case 1: { // A1 GET HOTEND TARGET TEMP + const celsius_float_t hotendTargetTemp = getTargetTemp_celsius(E0); + SEND_PGM_VAL("A1V ", ROUND(hotendTargetTemp)); + } + break; + + case 2: { // A2 GET HOTBED TEMP + const celsius_float_t heatedBedActualTemp = getActualTemp_celsius(BED); + SEND_PGM_VAL("A2V ", ROUND(heatedBedActualTemp)); + } + break; + + case 3: { // A3 GET HOTBED TARGET TEMP + const celsius_float_t heatedBedTargetTemp = getTargetTemp_celsius(BED); + SEND_PGM_VAL("A3V ", ROUND(heatedBedTargetTemp)); + } break; + + case 4: { // A4 GET FAN SPEED + SEND_PGM_VAL("A4V ", int(getActualFan_percent(FAN0))); + } break; + + case 5: { // A5 GET CURRENT COORDINATE + const float xPosition = getAxisPosition_mm(X), + yPosition = getAxisPosition_mm(Y), + zPosition = getAxisPosition_mm(Z); + SEND_PGM("A5V X: "); LCD_SERIAL.print(xPosition); + SEND_PGM( " Y: "); LCD_SERIAL.print(yPosition); + SEND_PGM( " Z: "); LCD_SERIAL.print(zPosition); + SENDLINE_PGM(""); + } break; + + case 6: // A6 GET SD CARD PRINTING STATUS + #if HAS_MEDIA + if (isPrintingFromMedia()) { + SEND_PGM("A6V "); + if (isMediaInserted()) + SENDLINE(ui8tostr3rj(getProgress_percent())); + else + SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to return printing status... J02"); + } + else + SENDLINE_PGM("A6V ---"); + #endif + break; + + case 7: { // A7 GET PRINTING TIME + const uint32_t elapsedSeconds = getProgress_seconds_elapsed(); + SEND_PGM("A7V "); + if (elapsedSeconds != 0) { // print time + const uint32_t elapsedMinutes = elapsedSeconds / 60; + SEND(ui8tostr2(elapsedMinutes / 60)); + SEND_PGM(" H "); + SEND(ui8tostr2(elapsedMinutes % 60)); + SENDLINE_PGM(" M"); + } + else + SENDLINE_PGM(" 999:999"); + } + break; + + case 8: // A8 GET SD LIST + #if HAS_MEDIA + selectedFile[0] = 0; + renderCurrentFileList(); + #endif + break; + + case 9: // A9 pause sd print + TERN_(HAS_MEDIA, if (isPrintingFromMedia()) pausePrint()); + break; + + case 10: // A10 resume sd print + #if HAS_MEDIA + if (isPrintingFromMediaPaused()) + resumePrint(); + #endif + break; + + case 11: // A11 STOP SD PRINT + TERN_(HAS_MEDIA, stopPrint()); + break; + + case 12: // A12 kill + kill(F(STR_ERR_KILLED)); + break; + + case 13: // A13 SELECTION FILE + #if HAS_MEDIA + if (isMediaInserted()) { + starpos = (strchr(tftStrchrPtr + 4, '*')); + if (tftStrchrPtr[4] == '/') { + strcpy(selectedDirectory, tftStrchrPtr + 5); + selectedFile[0] = 0; + SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected + SENDLINE_PGM(""); + } + else if (tftStrchrPtr[4] == '<') { + strcpy(selectedDirectory, tftStrchrPtr + 4); + specialMenu = true; + selectedFile[0] = 0; + SENDLINE_DBG_PGM("J21", "TFT Serial Debug: Clear file selection... J21 "); // J21 Not File Selected + SENDLINE_PGM(""); + } + else { + selectedDirectory[0] = 0; + + if (starpos) *(starpos - 1) = '\0'; + + strcpy(selectedFile, tftStrchrPtr + 4); + SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", selectedFile); // J20 File Selected + } + } + #endif + break; + + case 14: // A14 START PRINTING + #if HAS_MEDIA + if (!isPrinting() && strlen(selectedFile) > 0) + startPrint(); + #endif + break; + + case 15: // A15 RESUMING FROM OUTAGE + // TODO: JBA implement resume form outage + break; + + case 16: { // A16 set hotend temp + uint16_t tempvalue; + if (codeSeen('S')) { + tempvalue = constrain(codeValue(), 0, 275); + setTargetTemp_celsius(tempvalue, (extruder_t)E0); + } + else if (codeSeen('C') && !isPrinting()) { + if (getAxisPosition_mm(Z) < 10) + injectCommands(F("G1 Z10")); // RASE Z AXIS + tempvalue = constrain(codeValue(), 0, 275); + setTargetTemp_celsius(tempvalue, (extruder_t)E0); + } + } + break; + + case 17: { // A17 set heated bed temp + uint16_t tempbed; + if (codeSeen('S')) { + tempbed = constrain(codeValue(), 0, 100); + setTargetTemp_celsius(tempbed, (heater_t)BED); + } + } + break; + + case 18: { // A18 set fan speed + float fanPercent; + if (codeSeen('S')) { + fanPercent = codeValue(); + fanPercent = constrain(fanPercent, 0, 100); + setTargetFan_percent(fanPercent, FAN0); + } + else + fanPercent = 100; + + setTargetFan_percent(fanPercent, FAN0); + SENDLINE_PGM(""); + } + break; + + case 19: // A19 stop stepper drivers - sent on stop extrude command and on turn motors off command + if (!isPrinting()) { + quickstop_stepper(); + stepper.disable_all_steppers(); + } + + SENDLINE_PGM(""); + break; + + case 20: // A20 read printing speed + if (codeSeen('S')) + feedrate_percentage = constrain(codeValue(), 40, 999); + else + SEND_PGM_VAL("A20V ", feedrate_percentage); + break; + + case 21: // A21 all home + if (!isPrinting() && !isPrintingFromMediaPaused()) { + if (codeSeen('X') || codeSeen('Y') || codeSeen('Z')) { + if (codeSeen('X')) + injectCommands(F("G28X")); + if (codeSeen('Y')) + injectCommands(F("G28Y")); + if (codeSeen('Z')) + injectCommands(F("G28Z")); + } + else if (codeSeen('C')) { + injectCommands_P(G28_STR); + } + } + break; + + case 22: // A22 move X/Y/Z or extrude + if (!isPrinting()) { + float coorvalue; + uint16_t movespeed = 0; + char commandStr[30]; + char fullCommandStr[38]; + + commandStr[0] = 0; // empty string + if (codeSeen('F')) // Set feedrate + movespeed = codeValue(); + + if (codeSeen('X')) { // Move in X direction + coorvalue = codeValue(); + if ((coorvalue <= 0.2) && coorvalue > 0) + sprintf_P(commandStr, PSTR("G1 X0.1F%i"), movespeed); + else if ((coorvalue <= -0.1) && coorvalue > -1) + sprintf_P(commandStr, PSTR("G1 X-0.1F%i"), movespeed); + else + sprintf_P(commandStr, PSTR("G1 X%iF%i"), int(coorvalue), movespeed); + } + else if (codeSeen('Y')) { // Move in Y direction + coorvalue = codeValue(); + if ((coorvalue <= 0.2) && coorvalue > 0) + sprintf_P(commandStr, PSTR("G1 Y0.1F%i"), movespeed); + else if ((coorvalue <= -0.1) && coorvalue > -1) + sprintf_P(commandStr, PSTR("G1 Y-0.1F%i"), movespeed); + else + sprintf_P(commandStr, PSTR("G1 Y%iF%i"), int(coorvalue), movespeed); + } + else if (codeSeen('Z')) { // Move in Z direction + coorvalue = codeValue(); + if ((coorvalue <= 0.2) && coorvalue > 0) + sprintf_P(commandStr, PSTR("G1 Z0.1F%i"), movespeed); + else if ((coorvalue <= -0.1) && coorvalue > -1) + sprintf_P(commandStr, PSTR("G1 Z-0.1F%i"), movespeed); + else + sprintf_P(commandStr, PSTR("G1 Z%iF%i"), int(coorvalue), movespeed); + } + else if (codeSeen('E')) { // Extrude + coorvalue = codeValue(); + if ((coorvalue <= 0.2) && coorvalue > 0) + sprintf_P(commandStr, PSTR("G1 E0.1F%i"), movespeed); + else if ((coorvalue <= -0.1) && coorvalue > -1) + sprintf_P(commandStr, PSTR("G1 E-0.1F%i"), movespeed); + else + sprintf_P(commandStr, PSTR("G1 E%iF500"), int(coorvalue)); + } + + if (strlen(commandStr) > 0) { + sprintf_P(fullCommandStr, PSTR("G91\n%s\nG90"), commandStr); + DEBUG_ECHOPGM("TFT Serial Debug: A22 Move final request with gcode... "); + DEBUG_ECHOLN(fullCommandStr); + injectCommands(fullCommandStr); + } + } + SENDLINE_PGM(""); + break; + + case 23: // A23 preheat pla + if (!isPrinting()) { + if (getAxisPosition_mm(Z) < 10) + injectCommands(F("G1 Z10")); // RASE Z AXIS + + setTargetTemp_celsius(PREHEAT_1_TEMP_BED, (heater_t)BED); + setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, (extruder_t)E0); + SENDLINE_PGM("OK"); + } + break; + + case 24:// A24 preheat abs + if (!isPrinting()) { + if (getAxisPosition_mm(Z) < 10) + injectCommands(F("G1 Z10")); // RASE Z AXIS + + setTargetTemp_celsius(PREHEAT_2_TEMP_BED, (heater_t)BED); + setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, (extruder_t)E0); + SENDLINE_PGM("OK"); + } + break; + + case 25: // A25 cool down + if (!isPrinting()) { + setTargetTemp_celsius(0, (heater_t) BED); + setTargetTemp_celsius(0, (extruder_t) E0); + + SENDLINE_DBG_PGM("J12", "TFT Serial Debug: Cooling down... J12"); // J12 cool down + } + break; + + case 26: // A26 refresh SD + #if HAS_MEDIA + if (isMediaInserted()) { + if (strlen(selectedDirectory) > 0) { + FileList currentFileList; + if ((selectedDirectory[0] == '.') && (selectedDirectory[1] == '.')) { + currentFileList.upDir(); + } + else { + if (selectedDirectory[0] == '<') + handleSpecialMenu(); + else + currentFileList.changeDir(selectedDirectory); + } + } + } + else { + SENDLINE_DBG_PGM("J02", "TFT Serial Debug: No SD Card mounted to refresh SD A26... J02"); + } + + selectedDirectory[0] = 0; + #endif + break; + + #if ENABLED(SERVO_ENDSTOPS) + case 27: break; // A27 servos angles adjust + #endif + + case 28: // A28 filament test + if (codeSeen('O')) + NOOP; + else if (codeSeen('C')) + NOOP; + SENDLINE_PGM(""); + break; + + case 33: // A33 get version info + SEND_PGM("J33 "); + SENDLINE_PGM(DETAILED_BUILD_VERSION); + break; + + default: + break; + } } - else { - TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char; - } - } + + tftBufIndW = (tftBufIndW + 1) % (TFTBUFSIZE); + tftBufLen++; + serial_count = 0; // clear buffer + + } // while } -void AnycubicTFTClass::DoSDCardStateCheck() { +void AnycubicTFTClass::doSDCardStateCheck() { #if BOTH(HAS_MEDIA, HAS_SD_DETECT) bool isInserted = isMediaInserted(); if (isInserted) @@ -934,7 +895,7 @@ void AnycubicTFTClass::DoSDCardStateCheck() { #endif } -void AnycubicTFTClass::DoFilamentRunoutCheck() { +void AnycubicTFTClass::doFilamentRunoutCheck() { #if ENABLED(FILAMENT_RUNOUT_SENSOR) // NOTE: getFilamentRunoutState() only returns the runout state if the job is printing // we want to actually check the status of the pin here, regardless of printstate @@ -953,23 +914,18 @@ void AnycubicTFTClass::DoFilamentRunoutCheck() { #endif // FILAMENT_RUNOUT_SENSOR } -void AnycubicTFTClass::StartPrint() { +void AnycubicTFTClass::startPrint() { #if HAS_MEDIA - if (!isPrinting() && strlen(SelectedFile) > 0) { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOPGM("TFT Serial Debug: About to print file ... "); - SERIAL_ECHO(isPrinting()); - SERIAL_ECHOPGM(" "); - SERIAL_ECHOLN(SelectedFile); - #endif + if (!isPrinting() && strlen(selectedFile) > 0) { + DEBUG_ECHOLNPGM("TFT Serial Debug: About to print file ... ", isPrinting(), " ", selectedFile); mediaPrintingState = AMPRINTSTATE_PRINTING; mediaPauseState = AMPAUSESTATE_NOT_PAUSED; - printFile(SelectedFile); + printFile(selectedFile); } #endif // SDUPPORT } -void AnycubicTFTClass::PausePrint() { +void AnycubicTFTClass::pausePrint() { #if HAS_MEDIA if (isPrintingFromMedia() && mediaPrintingState != AMPRINTSTATE_STOP_REQUESTED && mediaPauseState == AMPAUSESTATE_NOT_PAUSED) { mediaPrintingState = AMPRINTSTATE_PAUSE_REQUESTED; @@ -983,16 +939,14 @@ void AnycubicTFTClass::PausePrint() { #endif } -void AnycubicTFTClass::ResumePrint() { +void AnycubicTFTClass::resumePrint() { #if HAS_MEDIA #if ENABLED(FILAMENT_RUNOUT_SENSOR) if (READ(FIL_RUNOUT1_PIN)) { - #if ENABLED(ANYCUBIC_LCD_DEBUG) - SERIAL_ECHOLNPGM("TFT Serial Debug: Resume Print with filament sensor still tripped... "); - #endif + DEBUG_ECHOLNPGM("TFT Serial Debug: Resume Print with filament sensor still tripped... "); // trigger the user message box - DoFilamentRunoutCheck(); + doFilamentRunoutCheck(); // re-enable the continue button SENDLINE_DBG_PGM("J18", "TFT Serial Debug: Resume Print with filament sensor still tripped... J18"); @@ -1019,7 +973,7 @@ void AnycubicTFTClass::ResumePrint() { #endif } -void AnycubicTFTClass::StopPrint() { +void AnycubicTFTClass::stopPrint() { #if HAS_MEDIA mediaPrintingState = AMPRINTSTATE_STOP_REQUESTED; mediaPauseState = AMPAUSESTATE_NOT_PAUSED; diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.h b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.h index 8fcadc1553f..7316c5fc04f 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.h +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.h @@ -48,48 +48,45 @@ enum AnycubicMediaPauseState { class AnycubicTFTClass { public: AnycubicTFTClass(); - static void OnSetup(); - static void OnCommandScan(); - static void OnKillTFT(); - static void OnSDCardStateChange(bool); - static void OnSDCardError(); - static void OnFilamentRunout(); - static void OnUserConfirmRequired(const char *); - static void OnPrintTimerStarted(); - static void OnPrintTimerPaused(); - static void OnPrintTimerStopped(); + static void onSetup(); + static void onCommandScan(); + static void onKillTFT(); + static void onSDCardStateChange(bool); + static void onSDCardError(); + static void onFilamentRunout(); + static void onUserConfirmRequired(const char *); + static void onPrintTimerStarted(); + static void onPrintTimerPaused(); + static void onPrintTimerStopped(); private: - static char TFTcmdbuffer[TFTBUFSIZE][TFT_MAX_CMD_SIZE]; - static int TFTbuflen, TFTbufindr, TFTbufindw; - static char serial3_char; - static int serial3_count; - static char *TFTstrchr_pointer; - static uint8_t SpecialMenu; + static char tftCommands[TFTBUFSIZE][TFT_MAX_CMD_SIZE]; + static int tftBufLen, tftBufIndR, tftBufIndW; + static char *tftStrchrPtr; + static uint8_t specialMenu; static AnycubicMediaPrintState mediaPrintingState; static AnycubicMediaPauseState mediaPauseState; - static float CodeValue(); - static bool CodeSeen(char); - static bool IsNozzleHomed(); - static void RenderCurrentFileList(); - static void RenderSpecialMenu(uint16_t); - static void RenderCurrentFolder(uint16_t); - static void GetCommandFromTFT(); - static void CheckSDCardChange(); - static void CheckPauseState(); - static void CheckPrintCompletion(); - static void HandleSpecialMenu(); - static void DoSDCardStateCheck(); - static void DoFilamentRunoutCheck(); - static void StartPrint(); - static void PausePrint(); - static void ResumePrint(); - static void StopPrint(); + static float codeValue(); + static bool codeSeen(char); + static bool isNozzleHomed(); + static void renderCurrentFileList(); + static void renderSpecialMenu(uint16_t); + static void renderCurrentFolder(uint16_t); + static void getCommandFromTFT(); + static void checkSDCardChange(); + static void checkPauseState(); + static void handleSpecialMenu(); + static void doSDCardStateCheck(); + static void doFilamentRunoutCheck(); + static void startPrint(); + static void pausePrint(); + static void resumePrint(); + static void stopPrint(); - static char SelectedDirectory[30]; - static char SelectedFile[FILENAME_LENGTH]; + static char selectedDirectory[30]; + static char selectedFile[FILENAME_LENGTH]; }; -extern AnycubicTFTClass AnycubicTFT; +extern AnycubicTFTClass anycubicTFT; extern const char G28_STR[]; diff --git a/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.cpp b/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.cpp index 03eba4c5b35..da88acc725c 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.cpp @@ -40,8 +40,8 @@ using namespace ExtUI; namespace Anycubic { - FileList FileNavigator::filelist; // Instance of the Marlin file API - char FileNavigator::currentfoldername[MAX_PATH_LEN + 1]; // Current folder path + FileList FileNavigator::filelist; // ExtUI file API + char FileNavigator::currentDirPath[MAX_PATH_LEN + 1]; // Current folder path uint16_t FileNavigator::lastindex; uint8_t FileNavigator::folderdepth; uint16_t FileNavigator::currentindex; // override the panel request @@ -51,7 +51,7 @@ namespace Anycubic { FileNavigator::FileNavigator() { reset(); } void FileNavigator::reset() { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; folderdepth = 0; currentindex = 0; lastindex = 0; @@ -94,7 +94,7 @@ namespace Anycubic { DgusTFT::SendTxtToTFT(filelist.longFilename(), TXT_FILE_0 + file_num*0x30); #if ACDEBUG(AC_FILE) - SERIAL_ECHOLNPGM("seek: ", _seek, " '", filelist.longFilename(), "' '", currentfoldername, "", filelist.shortFilename(), "'\n"); + SERIAL_ECHOLNPGM("seek: ", _seek, " '", filelist.longFilename(), "' '", currentDirPath, "", filelist.shortFilename(), "'\n"); #endif } else { @@ -120,11 +120,11 @@ namespace Anycubic { void FileNavigator::changeDIR(char *folder) { #if ACDEBUG(AC_FILE) - SERIAL_ECHOLNPGM("currentfolder: ", currentfoldername, " New: ", folder); + SERIAL_ECHOLNPGM("currentfolder: ", currentDirPath, " New: ", folder); #endif if (folderdepth >= MAX_FOLDER_DEPTH) return; // limit the folder depth - strcat(currentfoldername, folder); - strcat(currentfoldername, "/"); + strcat(currentDirPath, folder); + strcat(currentDirPath, "/"); filelist.changeDir(folder); refresh(); folderdepth++; @@ -138,22 +138,22 @@ namespace Anycubic { currentindex = 0; // Remove the last child folder from the stored path if (folderdepth == 0) { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; reset(); } else { char *pos = nullptr; for (uint8_t f = 0; f < folderdepth; f++) - pos = strchr(currentfoldername, '/'); + pos = strchr(currentDirPath, '/'); *(pos + 1) = '\0'; } #if ACDEBUG(AC_FILE) - SERIAL_ECHOLNPGM("depth: ", folderdepth, " currentfoldername: ", currentfoldername); + SERIAL_ECHOLNPGM("depth: ", folderdepth, " currentDirPath: ", currentDirPath); #endif } - char* FileNavigator::getCurrentFolderName() { return currentfoldername; } + char* FileNavigator::getCurrentDirPath() { return currentDirPath; } uint16_t FileNavigator::getFileNum() { return filelist.count(); } } diff --git a/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.h b/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.h index dd4b0b0f748..2505ae7c4cd 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.h +++ b/Marlin/src/lcd/extui/anycubic_vyper/FileNavigator.h @@ -43,13 +43,13 @@ namespace Anycubic { static void changeDIR(char *); static void sendFile(); static void refresh(); - static char* getCurrentFolderName(); + static char* getCurrentDirPath(); static uint16_t getFileNum(); private: static uint16_t lastindex; static uint16_t currentindex; static uint8_t folderdepth; - static char currentfoldername[MAX_PATH_LEN + 1]; + static char currentDirPath[MAX_PATH_LEN + 1]; }; extern FileNavigator filenavigator; diff --git a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp index e846d65a1fa..49609ada329 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp @@ -111,10 +111,10 @@ namespace Anycubic { uint8_t pop_up_index_saved; uint32_t key_value_saved; - void DEBUG_PRINT_PAUSED_STATE(FSTR_P const msg, paused_state_t state); - void DEBUG_PRINT_PRINTER_STATE(FSTR_P const msg, printer_state_t state); - void DEBUG_PRINT_TIMER_EVENT(FSTR_P const msg, timer_event_t event); - void DEBUG_PRINT_MEDIA_EVENT(FSTR_P const msg, media_event_t event); + void DEBUG_PRINT_PAUSED_STATE(const paused_state_t state, FSTR_P const msg=nullptr); + void DEBUG_PRINT_PRINTER_STATE(const printer_state_t state, FSTR_P const msg=nullptr); + void DEBUG_PRINT_TIMER_EVENT(const timer_event_t event, FSTR_P const msg=nullptr); + void DEBUG_PRINT_MEDIA_EVENT(const media_event_t event, FSTR_P const msg=nullptr); DgusTFT Dgus; @@ -127,9 +127,9 @@ namespace Anycubic { feedrate_back = -1; } - void DgusTFT::Startup() { + void DgusTFT::startup() { #if ACDEBUG(AC_MARLIN) - DEBUG_ECHOLNPGM("DgusTFT::Startup()"); + DEBUG_ECHOLNPGM("DgusTFT::startup()"); #endif selectedfile[0] = '\0'; panel_command[0] = '\0'; @@ -148,16 +148,16 @@ namespace Anycubic { TFTSer.begin(115200); // Signal Board has reset - SendtoTFTLN(AC_msg_main_board_has_reset); + tftSendLn(AC_msg_main_board_has_reset); // Enable levelling and Disable end stops during print // as Z home places nozzle above the bed so we need to allow it past the end stops injectCommands(AC_cmnd_enable_leveling); #if ACDEBUGLEVEL - DEBUG_ECHOLNPGM("Startup AC Debug Level ", ACDEBUGLEVEL); + DEBUG_ECHOLNPGM("startup AC Debug Level ", ACDEBUGLEVEL); #endif - SendtoTFTLN(AC_msg_ready); + tftSendLn(AC_msg_ready); } void DgusTFT::ParamInit() { @@ -188,15 +188,15 @@ namespace Anycubic { RequestValueFromTFT(0x14); // get page ID } - void DgusTFT::IdleLoop() { - if (ReadTFTCommand()) { - ProcessPanelRequest(); + void DgusTFT::idleLoop() { + if (readTFTCommand()) { + processPanelRequest(); command_len = 0; } #if ACDEBUG(AC_MARLIN) if (key_value) { - DEBUG_ECHOLNPGM("IdleLoop page: ", page_index_now); + DEBUG_ECHOLNPGM("idleLoop page: ", page_index_now); DEBUG_ECHOLNPGM("key: ", key_value); } #endif @@ -266,7 +266,7 @@ namespace Anycubic { pop_up_manager(); key_value = 0; - CheckHeaters(); + checkHeaters(); } uint8_t FSHlength(FSTR_P FSHinput) { @@ -276,7 +276,7 @@ namespace Anycubic { return stringLength; } - void DgusTFT::PrinterKilled(FSTR_P error_p, FSTR_P component_p) { + void DgusTFT::printerKilled(FSTR_P error_p, FSTR_P component_p) { // copy string in FLASH to RAM for strcmp_P @@ -288,9 +288,9 @@ namespace Anycubic { char component[FSHlength(component_p) + 1]; memcpy_P(component, component_p, textLength + 1); // +1 for the null terminator - SendtoTFTLN(AC_msg_kill_lcd); + tftSendLn(AC_msg_kill_lcd); #if ACDEBUG(AC_MARLIN) - DEBUG_ECHOLNPGM("PrinterKilled()\nerror: ", error, "\ncomponent: ", component); + DEBUG_ECHOLNPGM("printerKilled()\nerror: ", error, "\ncomponent: ", component); #endif if (strcmp_P(error, PSTR("Heating Failed")) == 0) { @@ -364,9 +364,9 @@ namespace Anycubic { SendColorToTFT(color, TXT_DESCRIPT_0 + 0x30 * (index - 1)); } - void DgusTFT::MediaEvent(media_event_t event) { + void DgusTFT::mediaEvent(media_event_t event) { #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_MEDIA_EVENT(F("ProcessMediaStatus() "), event); + DEBUG_PRINT_MEDIA_EVENT(event); #endif switch (event) { case AC_media_inserted: @@ -379,12 +379,12 @@ namespace Anycubic { lcd_txtbox_index = 0; } - SendFileList(lcd_txtbox_index); + sendFileList(lcd_txtbox_index); break; case AC_media_removed: - SendtoTFTLN(AC_msg_sd_card_removed); + tftSendLn(AC_msg_sd_card_removed); filenavigator.reset(); @@ -394,33 +394,33 @@ namespace Anycubic { lcd_txtbox_index = 0; } - SendFileList(lcd_txtbox_index); + sendFileList(lcd_txtbox_index); break; case AC_media_error: - SendtoTFTLN(AC_msg_no_sd_card); + tftSendLn(AC_msg_no_sd_card); break; } } - void DgusTFT::TimerEvent(timer_event_t event) { + void DgusTFT::timerEvent(timer_event_t event) { #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_TIMER_EVENT(F("TimerEvent() "), event); - DEBUG_PRINT_PRINTER_STATE(F("Printer State: "), printer_state); + DEBUG_PRINT_TIMER_EVENT(event); + DEBUG_PRINT_PRINTER_STATE(printer_state); #endif switch (event) { case AC_timer_started: setSoftEndstopState(false); // disable endstops to print printer_state = AC_printer_printing; - SendtoTFTLN(AC_msg_print_from_sd_card); + tftSendLn(AC_msg_print_from_sd_card); break; case AC_timer_paused: //printer_state = AC_printer_paused; //pause_state = AC_paused_idle; - SendtoTFTLN(AC_msg_paused); + tftSendLn(AC_msg_paused); break; case AC_timer_stopped: @@ -438,7 +438,7 @@ namespace Anycubic { sprintf(str_buf + strlen(str_buf), "%s M", utostr3(time % 60)); SendTxtToTFT(str_buf, TXT_FINISH_TIME); ChangePageOfTFT(PAGE_PRINT_FINISH); - SendtoTFTLN(AC_msg_print_complete); + tftSendLn(AC_msg_print_complete); pop_up_index = 100; } } @@ -449,12 +449,12 @@ namespace Anycubic { #if ENABLED(FILAMENT_RUNOUT_SENSOR) - void DgusTFT::FilamentRunout() { + void DgusTFT::filamentRunout() { #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_PRINTER_STATE(F("FilamentRunout() printer_state "), printer_state); + DEBUG_PRINT_PRINTER_STATE(printer_state, F("filamentRunout() ")); // 1 Signal filament out - SendtoTFTLN(isPrintingFromMedia() ? AC_msg_filament_out_alert : AC_msg_filament_out_block); + tftSendLn(isPrintingFromMedia() ? AC_msg_filament_out_alert : AC_msg_filament_out_block); //printer_state = AC_printer_filament_out; DEBUG_ECHOLNPGM("getFilamentRunoutState: ", getFilamentRunoutState()); @@ -477,13 +477,13 @@ namespace Anycubic { #endif // FILAMENT_RUNOUT_SENSOR - void DgusTFT::ConfirmationRequest(const char * const msg) { + void DgusTFT::confirmationRequest(const char * const msg) { // M108 continue #if ACDEBUG(AC_MARLIN) DEBUG_ECHOLNPGM("HomingComplete, line: ", __LINE__); - DEBUG_ECHOLNPGM("ConfirmationRequest() ", msg); - DEBUG_PRINT_PRINTER_STATE(F("printer_state: " ), printer_state); - DEBUG_PRINT_PAUSED_STATE(F("pause_state: "), pause_state); + DEBUG_ECHOLNPGM("confirmationRequest() ", msg); + DEBUG_PRINT_PRINTER_STATE(printer_state); + DEBUG_PRINT_PAUSED_STATE(pause_state); #endif switch (printer_state) { @@ -504,7 +504,7 @@ namespace Anycubic { // Heater timout, send acknowledgement if (strcmp_P(msg, MARLIN_msg_heater_timeout) == 0) { pause_state = AC_paused_heater_timed_out; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button PlayTune(HeaterTimeout); } // Reheat finished, send acknowledgement @@ -517,12 +517,12 @@ namespace Anycubic { if (pause_state != AC_paused_filament_lack) pause_state = AC_paused_idle; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button } // Filament Purging, send acknowledgement enter run mode else if (strcmp_P(msg, MARLIN_msg_filament_purging) == 0) { pause_state = AC_paused_purging_filament; - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button } else if (strcmp_P(msg, MARLIN_msg_nozzle_parked) == 0) { #if ACDEBUG(AC_MARLIN) @@ -540,11 +540,11 @@ namespace Anycubic { } } - void DgusTFT::StatusChange(const char * const msg) { + void DgusTFT::statusChange(const char * const msg) { #if ACDEBUG(AC_MARLIN) - DEBUG_ECHOLNPGM("StatusChange() ", msg); - DEBUG_PRINT_PRINTER_STATE(F("printer_state: "), printer_state); - DEBUG_PRINT_PAUSED_STATE(F("pause_state: "), pause_state); + DEBUG_ECHOLNPGM("statusChange() ", msg); + DEBUG_PRINT_PRINTER_STATE(printer_state); + DEBUG_PRINT_PAUSED_STATE(pause_state); #endif bool msg_matched = false; @@ -579,7 +579,7 @@ namespace Anycubic { PlayTune(BeepBeepBeeep); injectCommands(F("G1 Z50 F500")); ChangePageOfTFT(PAGE_CHS_ABNORMAL_LEVELING_SENSOR); - SendtoTFTLN(AC_msg_probing_complete); + tftSendLn(AC_msg_probing_complete); printer_state = AC_printer_idle; msg_matched = true; } @@ -595,7 +595,7 @@ namespace Anycubic { case AC_printer_printing: if (strcmp_P(msg, MARLIN_msg_reheating) == 0) { - SendtoTFTLN(AC_msg_paused); // enable continue button + tftSendLn(AC_msg_paused); // enable continue button ChangePageOfTFT(PAGE_STATUS2); msg_matched = true; } @@ -652,14 +652,14 @@ namespace Anycubic { if (!msg_matched) { #if HAS_HOTEND if (strcmp_P(msg, MARLIN_msg_extruder_heating) == 0) { - SendtoTFTLN(AC_msg_nozzle_heating); + tftSendLn(AC_msg_nozzle_heating); hotend_state = AC_heater_temp_set; return; } #endif #if HAS_HEATED_BED if (strcmp_P(msg, MARLIN_msg_bed_heating) == 0) { - SendtoTFTLN(AC_msg_bed_heating); + tftSendLn(AC_msg_bed_heating); hotbed_state = AC_heater_temp_set; } #endif @@ -675,7 +675,7 @@ namespace Anycubic { LOOP_L_N(i, COUNT(data)) TFTSer.write(data[i]); } - void DgusTFT::PowerLossRecovery() { + void DgusTFT::powerLossRecovery() { printer_state = AC_printer_resuming_from_power_outage; // Play tune to notify user we can recover. } @@ -699,7 +699,7 @@ namespace Anycubic { ChangePageOfTFT(page_index_last); } - void DgusTFT::SendtoTFT(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel + void DgusTFT::tftSend(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel #if ACDEBUG(AC_SOME) DEBUG_ECHOF(fstr); #endif @@ -707,12 +707,12 @@ namespace Anycubic { while (const char c = pgm_read_byte(str++)) TFTSer.write(c); } - void DgusTFT::SendtoTFTLN(FSTR_P const fstr/*=nullptr*/) { + void DgusTFT::tftSendLn(FSTR_P const fstr/*=nullptr*/) { if (fstr) { #if ACDEBUG(AC_SOME) DEBUG_ECHOPGM("> "); #endif - SendtoTFT(fstr); + tftSend(fstr); #if ACDEBUG(AC_SOME) SERIAL_EOL(); #endif @@ -804,7 +804,7 @@ namespace Anycubic { LOOP_L_N(i, 10) TFTSer.write(data[i]); } - bool DgusTFT::ReadTFTCommand() { + bool DgusTFT::readTFTCommand() { static uint8_t length = 0, cnt = 0, tft_receive_steps = 0; uint8_t data; @@ -858,7 +858,7 @@ namespace Anycubic { #if 0 { - //SERIAL_ECHOLNPGM("ReadTFTCommand: ", millis()); + //SERIAL_ECHOLNPGM("readTFTCommand: ", millis()); //return -1; bool command_ready = false; @@ -888,7 +888,7 @@ namespace Anycubic { uint8_t req = atoi(&panel_command[1]); if (req > 7 && req != 20) { DEBUG_ECHOLNPGM("> ", panel_command); - DEBUG_PRINT_PRINTER_STATE(F("printer_state: "), printer_state); + DEBUG_PRINT_PRINTER_STATE(printer_state); } #endif } @@ -902,7 +902,7 @@ namespace Anycubic { return -1; } - void DgusTFT::CheckHeaters() { + void DgusTFT::checkHeaters() { static uint32_t time_last = 0; if (PENDING(millis(), time_last)) return; time_last = millis() + 500; @@ -916,7 +916,7 @@ namespace Anycubic { if (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) { faultE0Duration++; if (faultE0Duration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_nozzle_temp_abnormal); + tftSendLn(AC_msg_nozzle_temp_abnormal); #if ACDEBUG(AC_MARLIN) DEBUG_ECHOLNPGM("Extruder temp abnormal! : ", temp); #endif @@ -931,7 +931,7 @@ namespace Anycubic { if (!WITHIN(temp, BED_MINTEMP, BED_MAXTEMP)) { faultBedDuration++; if (faultBedDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_bed_temp_abnormal); + tftSendLn(AC_msg_bed_temp_abnormal); #if ACDEBUG(AC_MARLIN) DEBUG_ECHOLNPGM("Bed temp abnormal! : ", temp); #endif @@ -944,7 +944,7 @@ namespace Anycubic { // Update panel with hotend heater status if (hotend_state != AC_heater_temp_reached) { if (WITHIN(getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -1, 1)) { - SendtoTFTLN(AC_msg_nozzle_heating_done); + tftSendLn(AC_msg_nozzle_heating_done); hotend_state = AC_heater_temp_reached; } } @@ -952,22 +952,22 @@ namespace Anycubic { // Update panel with bed heater status if (hotbed_state != AC_heater_temp_reached) { if (WITHIN(getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -0.5, 0.5)) { - SendtoTFTLN(AC_msg_bed_heating_done); + tftSendLn(AC_msg_bed_heating_done); hotbed_state = AC_heater_temp_reached; } } #endif } - void DgusTFT::SendFileList(int8_t startindex) { + void DgusTFT::sendFileList(int8_t startindex) { // Respond to panel request for 4 files starting at index #if ACDEBUG(AC_INFO) - DEBUG_ECHOLNPGM("## SendFileList ## ", startindex); + DEBUG_ECHOLNPGM("## sendFileList ## ", startindex); #endif filenavigator.getFiles(startindex); } - void DgusTFT::SelectFile() { + void DgusTFT::selectFile() { strncpy(selectedfile, panel_command + 4, command_len - 4); selectedfile[command_len - 5] = '\0'; #if ACDEBUG(AC_FILE) @@ -975,22 +975,22 @@ namespace Anycubic { #endif switch (selectedfile[0]) { case '/': // Valid file selected - SendtoTFTLN(AC_msg_sd_file_open_success); + tftSendLn(AC_msg_sd_file_open_success); break; case '<': // .. (go up folder level) filenavigator.upDIR(); - SendtoTFTLN(AC_msg_sd_file_open_failed); - SendFileList(0); + tftSendLn(AC_msg_sd_file_open_failed); + sendFileList(0); break; default: // enter sub folder filenavigator.changeDIR(selectedfile); - SendtoTFTLN(AC_msg_sd_file_open_failed); - SendFileList(0); + tftSendLn(AC_msg_sd_file_open_failed); + sendFileList(0); break; } } - void DgusTFT::ProcessPanelRequest() { + void DgusTFT::processPanelRequest() { uint16_t control_index = 0; uint32_t control_value; uint16_t temp; @@ -1080,7 +1080,7 @@ namespace Anycubic { } else if (control_value == 0x010000) { // startup first gif - // Startup tunes are defined in Tunes.h + // startup tunes are defined in Tunes.h PlayTune(Anycubic_PowerOn); // takes 3500 ms } } @@ -1112,15 +1112,15 @@ namespace Anycubic { int8_t req = atoi(&panel_command[1]); // Information requests A0 - A8 and A33 - if (req <= 8 || req == 33) PanelInfo(req); + if (req <= 8 || req == 33) panelInfo(req); // Simple Actions A9 - A28 - else if (req <= 28) PanelAction(req); + else if (req <= 28) panelAction(req); // Process Initiation - else if (req <= 34) PanelProcess(req); + else if (req <= 34) panelProcess(req); - else SendtoTFTLN(); + else tftSendLn(); } #endif @@ -1187,7 +1187,7 @@ namespace Anycubic { lcd_txtbox_index = 0; } ChangePageOfTFT(PAGE_FILE); - SendFileList(0); + sendFileList(0); } break; case 2: { // tool @@ -1249,7 +1249,7 @@ namespace Anycubic { set_descript_color(COLOR_BLUE); lcd_txtbox_index = 0; - SendFileList(lcd_txtbox_page * 5); + sendFileList(lcd_txtbox_page * 5); } break; @@ -1260,7 +1260,7 @@ namespace Anycubic { set_descript_color(COLOR_BLUE); lcd_txtbox_index = 0; - SendFileList(lcd_txtbox_page * 5); + sendFileList(lcd_txtbox_page * 5); } break; @@ -1274,12 +1274,12 @@ namespace Anycubic { set_descript_color(COLOR_BLUE); lcd_txtbox_index = 0; } - SendFileList(lcd_txtbox_index); + sendFileList(lcd_txtbox_index); break; case 5: // resume of outage(last power off) #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_PRINTER_STATE(F("printer_state: "), printer_state); + DEBUG_PRINT_PRINTER_STATE(printer_state); #endif if (lcd_txtbox_index > 0 && lcd_txtbox_index < 6) { // 1~5 @@ -1398,8 +1398,8 @@ namespace Anycubic { case 2: // resume print #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_PRINTER_STATE(F("printer_state: "), printer_state); - DEBUG_PRINT_PAUSED_STATE(F("pause_state :"), pause_state); + DEBUG_PRINT_PRINTER_STATE(printer_state); + DEBUG_PRINT_PAUSED_STATE(pause_state); #endif if ( pause_state == AC_paused_idle || pause_state == AC_paused_filament_lack @@ -2418,8 +2418,8 @@ namespace Anycubic { case 1: // return #if ACDEBUG(AC_MARLIN) - DEBUG_PRINT_PRINTER_STATE(F("printer_state: "), printer_state); - DEBUG_PRINT_PAUSED_STATE(F("pause_state: "), pause_state); + DEBUG_PRINT_PRINTER_STATE(printer_state); + DEBUG_PRINT_PAUSED_STATE(pause_state); #endif if (AC_printer_printing == printer_state) ChangePageOfTFT(PAGE_STATUS2); // show pause @@ -3179,6 +3179,7 @@ namespace Anycubic { break; case 15: // filament lack + case 23: if (page_index_now != PAGE_FILAMENT_LACK) ChangePageOfTFT(PAGE_FILAMENT_LACK); pop_up_index = 100; @@ -3194,12 +3195,6 @@ namespace Anycubic { pop_up_index = 100; break; - case 23: // - if (page_index_now != PAGE_FILAMENT_LACK) - ChangePageOfTFT(PAGE_FILAMENT_LACK); - pop_up_index = 100; - break; - case 24: { // uint32_t time = getProgress_seconds_elapsed() / 60; char str_buf[20]; @@ -3207,7 +3202,7 @@ namespace Anycubic { sprintf(str_buf + strlen(str_buf), "%s M", utostr3(time % 60)); SendTxtToTFT(str_buf, TXT_FINISH_TIME); ChangePageOfTFT(PAGE_PRINT_FINISH); - //SendtoTFTLN(AC_msg_print_complete); // no idea why this causes a compile error + //tftSendLn(AC_msg_print_complete); // no idea why this causes a compile error pop_up_index = 100; } break; @@ -3218,84 +3213,56 @@ namespace Anycubic { } } - void DEBUG_PRINT_PAUSED_STATE(FSTR_P const msg, paused_state_t state) { - DEBUG_ECHOPGM(msg, state); + void DEBUG_PRINT_PAUSED_STATE(const paused_state_t state, FSTR_P const msg/*=nullptr*/) { + if (msg) DEBUG_ECHOF(msg); + DEBUG_ECHOPGM("Paused state: ", state, " "); switch (state) { - case AC_paused_heater_timed_out: - DEBUG_ECHOLNPGM(" AC_paused_heater_timed_out"); - break; - case AC_paused_filament_lack: - DEBUG_ECHOLNPGM(" AC_paused_filament_lack"); - break; - case AC_paused_purging_filament: - DEBUG_ECHOLNPGM(" AC_paused_purging_filament"); - break; - case AC_paused_idle: - DEBUG_ECHOLNPGM(" AC_paused_idle"); - break; + case AC_paused_heater_timed_out: DEBUG_ECHOPGM("AC_paused_heater_timed_out"); break; + case AC_paused_filament_lack: DEBUG_ECHOPGM("AC_paused_filament_lack"); break; + case AC_paused_purging_filament: DEBUG_ECHOPGM("AC_paused_purging_filament"); break; + case AC_paused_idle: DEBUG_ECHOPGM("AC_paused_idle"); break; } + DEBUG_EOL(); } -// routines to make the debug outputs human readable + // Human-readable debugging - void DEBUG_PRINT_PRINTER_STATE(FSTR_P const msg, printer_state_t state) { - DEBUG_ECHOPGM(msg, state); + void DEBUG_PRINT_PRINTER_STATE(const printer_state_t state, FSTR_P const msg/*=nullptr*/) { + if (msg) DEBUG_ECHOF(msg); + DEBUG_ECHOPGM("Printer State: ", state, " "); switch (state) { - case AC_printer_idle: - DEBUG_ECHOLNPGM(" AC_printer_idle"); - break; - case AC_printer_probing: - DEBUG_ECHOLNPGM(" AC_printer_probing"); - break; - case AC_printer_printing: - DEBUG_ECHOLNPGM(" AC_printer_printing"); - break; - case AC_printer_pausing: - DEBUG_ECHOLNPGM(" AC_printer_pausing"); - break; - case AC_printer_paused: - DEBUG_ECHOLNPGM(" AC_printer_paused"); - break; - case AC_printer_stopping: - DEBUG_ECHOLNPGM(" AC_printer_stopping"); - break; - case AC_printer_stopping_from_media_remove: - DEBUG_ECHOLNPGM(" AC_printer_stopping_from_media_remove"); - break; - case AC_printer_resuming_from_power_outage: - DEBUG_ECHOLNPGM(" AC_printer_resuming_from_power_outage"); - break; + case AC_printer_idle: DEBUG_ECHOPGM("AC_printer_idle"); break; + case AC_printer_probing: DEBUG_ECHOPGM("AC_printer_probing"); break; + case AC_printer_printing: DEBUG_ECHOPGM("AC_printer_printing"); break; + case AC_printer_pausing: DEBUG_ECHOPGM("AC_printer_pausing"); break; + case AC_printer_paused: DEBUG_ECHOPGM("AC_printer_paused"); break; + case AC_printer_stopping: DEBUG_ECHOPGM("AC_printer_stopping"); break; + case AC_printer_stopping_from_media_remove: DEBUG_ECHOPGM("AC_printer_stopping_from_media_remove"); break; + case AC_printer_resuming_from_power_outage: DEBUG_ECHOPGM("AC_printer_resuming_from_power_outage"); break; } + DEBUG_EOL(); } - void DEBUG_PRINT_TIMER_EVENT(FSTR_P const msg, timer_event_t event) { - DEBUG_ECHOPGM(msg, event); + void DEBUG_PRINT_TIMER_EVENT(const timer_event_t event, FSTR_P const msg/*=nullptr*/) { + if (msg) DEBUG_ECHOPGM(msg, event); + DEBUG_ECHOPGM("timerEvent() ", event, " "); switch (event) { - case AC_timer_started: - DEBUG_ECHOLNPGM(" AC_timer_started"); - break; - case AC_timer_paused: - DEBUG_ECHOLNPGM(" AC_timer_paused"); - break; - case AC_timer_stopped: - DEBUG_ECHOLNPGM(" AC_timer_stopped"); - break; + case AC_timer_started: DEBUG_ECHOPGM("AC_timer_started"); break; + case AC_timer_paused: DEBUG_ECHOPGM("AC_timer_paused"); break; + case AC_timer_stopped: DEBUG_ECHOPGM("AC_timer_stopped"); break; } + DEBUG_EOL(); } - void DEBUG_PRINT_MEDIA_EVENT(FSTR_P const msg, media_event_t event) { - DEBUG_ECHOPGM(msg, event); + void DEBUG_PRINT_MEDIA_EVENT(const media_event_t event, FSTR_P const msg/*=nullptr*/) { + if (msg) DEBUG_ECHOPGM(msg, event); + DEBUG_ECHOPGM("ProcessMediaStatus() ", event, " "); switch (event) { - case AC_media_inserted: - DEBUG_ECHOLNPGM(" AC_media_inserted"); - break; - case AC_media_removed: - DEBUG_ECHOLNPGM(" AC_media_removed"); - break; - case AC_media_error: - DEBUG_ECHOLNPGM(" AC_media_error"); - break; + case AC_media_inserted: DEBUG_ECHOPGM("AC_media_inserted"); break; + case AC_media_removed: DEBUG_ECHOPGM("AC_media_removed"); break; + case AC_media_error: DEBUG_ECHOPGM("AC_media_error"); break; } + DEBUG_EOL(); } } // namespace diff --git a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.h b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.h index 1903fa11833..747193dd77f 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.h +++ b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.h @@ -356,17 +356,17 @@ namespace Anycubic { static lcd_info_t lcd_info, lcd_info_back; static uint16_t page_index_now; - static void Startup(); + static void startup(); static void ParamInit(); - static void IdleLoop(); - static void PrinterKilled(FSTR_P,FSTR_P); - static void MediaEvent(media_event_t); - static void TimerEvent(timer_event_t); - static void FilamentRunout(); - static void ConfirmationRequest(const char * const); - static void StatusChange(const char * const); + static void idleLoop(); + static void printerKilled(FSTR_P,FSTR_P); + static void mediaEvent(media_event_t); + static void timerEvent(timer_event_t); + static void filamentRunout(); + static void confirmationRequest(const char * const); + static void statusChange(const char * const); static void PowerLoss(); - static void PowerLossRecovery(); + static void powerLossRecovery(); static void HomingStart(); static void HomingComplete(); @@ -450,17 +450,17 @@ namespace Anycubic { static void pop_up_manager(); - static void SendtoTFT(FSTR_P const=nullptr); - static void SendtoTFTLN(FSTR_P const=nullptr); - static bool ReadTFTCommand(); + static void tftSend(FSTR_P const=nullptr); + static void tftSendLn(FSTR_P const=nullptr); + static bool readTFTCommand(); static int8_t Findcmndpos(const char *, const char); - static void CheckHeaters(); - static void SendFileList(int8_t); - static void SelectFile(); - static void ProcessPanelRequest(); - static void PanelInfo(uint8_t); - static void PanelAction(uint8_t); - static void PanelProcess(uint8_t); + static void checkHeaters(); + static void sendFileList(int8_t); + static void selectFile(); + static void processPanelRequest(); + static void panelInfo(uint8_t); + static void panelAction(uint8_t); + static void panelProcess(uint8_t); static void SendValueToTFT(const uint16_t value, const uint16_t address); static void RequestValueFromTFT(const uint16_t address); diff --git a/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp b/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp index 142f438861b..80e1746a2f9 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp @@ -37,17 +37,17 @@ using namespace Anycubic; namespace ExtUI { - void onStartup() { Dgus.Startup(); } + void onStartup() { Dgus.startup(); } - void onIdle() { Dgus.IdleLoop(); } + void onIdle() { Dgus.idleLoop(); } void onPrinterKilled(FSTR_P const error, FSTR_P const component) { - Dgus.PrinterKilled(error, component); + Dgus.printerKilled(error, component); } - void onMediaInserted() { Dgus.MediaEvent(AC_media_inserted); } - void onMediaError() { Dgus.MediaEvent(AC_media_error); } - void onMediaRemoved() { Dgus.MediaEvent(AC_media_removed); } + void onMediaInserted() { Dgus.mediaEvent(AC_media_inserted); } + void onMediaError() { Dgus.mediaEvent(AC_media_error); } + void onMediaRemoved() { Dgus.mediaEvent(AC_media_removed); } void onPlayTone(const uint16_t frequency, const uint16_t duration) { #if ENABLED(SPEAKER) @@ -55,15 +55,15 @@ namespace ExtUI { #endif } - void onPrintTimerStarted() { Dgus.TimerEvent(AC_timer_started); } - void onPrintTimerPaused() { Dgus.TimerEvent(AC_timer_paused); } - void onPrintTimerStopped() { Dgus.TimerEvent(AC_timer_stopped); } + void onPrintTimerStarted() { Dgus.timerEvent(AC_timer_started); } + void onPrintTimerPaused() { Dgus.timerEvent(AC_timer_paused); } + void onPrintTimerStopped() { Dgus.timerEvent(AC_timer_stopped); } void onPrintDone() {} - void onFilamentRunout(const extruder_t) { Dgus.FilamentRunout(); } + void onFilamentRunout(const extruder_t) { Dgus.filamentRunout(); } - void onUserConfirmRequired(const char * const msg) { Dgus.ConfirmationRequest(msg); } - void onStatusChanged(const char * const msg) { Dgus.StatusChange(msg); } + void onUserConfirmRequired(const char * const msg) { Dgus.confirmationRequest(msg); } + void onStatusChanged(const char * const msg) { Dgus.statusChange(msg); } void onHomingStart() { Dgus.HomingStart(); } void onHomingDone() { Dgus.HomingComplete(); } @@ -129,7 +129,7 @@ namespace ExtUI { // Called when power-loss state is detected void onPowerLoss() { /* handled internally */ } // Called on resume from power-loss - void onPowerLossResume() { Dgus.PowerLossRecovery(); } + void onPowerLossResume() { Dgus.powerLossRecovery(); } #endif #if HAS_PID_HEATING diff --git a/Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp index 2a7d635c6d7..876a8889187 100644 --- a/Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp @@ -220,7 +220,7 @@ void DGUSDisplay::ProcessRx() { } } -size_t DGUSDisplay::GetFreeTxBuffer() { return SERIAL_GET_TX_BUFFER_FREE(); } +size_t DGUSDisplay::GetFreeTxBuffer() { return LCD_SERIAL_TX_BUFFER_FREE(); } void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) { LCD_SERIAL.write(DGUS_HEADER1); diff --git a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp index bdfea5d1472..aa83ee2a4ee 100644 --- a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp @@ -157,7 +157,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } #endif char axiscode; - uint16_t speed = manual_feedrate_mm_m[X_AXIS]; // Default feedrate for manual moves + uint16_t speed = manual_feedrate_mm_m.x; // Default feedrate for manual moves switch (var.VP) { default: return; @@ -172,7 +172,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Y_AXIS case VP_MOVE_Y: axiscode = 'Y'; - speed = manual_feedrate_mm_m[Y_AXIS]; + speed = manual_feedrate_mm_m.y; if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; break; #endif @@ -180,7 +180,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Z_AXIS case VP_MOVE_Z: axiscode = 'Z'; - speed = manual_feedrate_mm_m[Z_AXIS]; + speed = manual_feedrate_mm_m.z; if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; break; #endif diff --git a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp index e37718e0a74..d0119d494f4 100644 --- a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp @@ -157,7 +157,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } #endif char axiscode; - uint16_t speed = manual_feedrate_mm_m[X_AXIS]; // Default feedrate for manual moves + uint16_t speed = manual_feedrate_mm_m.x; // Default feedrate for manual moves switch (var.VP) { default: return; @@ -172,7 +172,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Y_AXIS case VP_MOVE_Y: axiscode = 'Y'; - speed = manual_feedrate_mm_m[Y_AXIS]; + speed = manual_feedrate_mm_m.y; if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; break; #endif @@ -180,7 +180,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Z_AXIS case VP_MOVE_Z: axiscode = 'Z'; - speed = manual_feedrate_mm_m[Z_AXIS]; + speed = manual_feedrate_mm_m.z; if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; break; #endif diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp index f882ba33d01..ad89a715c36 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp @@ -739,7 +739,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { return; char axiscode; - uint16_t speed = manual_feedrate_mm_m[X_AXIS]; // Default feedrate for manual moves + uint16_t speed = manual_feedrate_mm_m.x; // Default feedrate for manual moves switch (var.VP) { // switch X Y Z or Home default: return; @@ -753,7 +753,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Y_AXIS case VP_MOVE_Y: axiscode = 'Y'; - speed = manual_feedrate_mm_m[Y_AXIS]; + speed = manual_feedrate_mm_m.y; if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; break; #endif @@ -761,7 +761,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Z_AXIS case VP_MOVE_Z: axiscode = 'Z'; - speed = manual_feedrate_mm_m[Z_AXIS]; + speed = manual_feedrate_mm_m.z; if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; break; #endif diff --git a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp index c274d7b431e..44f4a95cad2 100644 --- a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp @@ -157,7 +157,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } #endif char axiscode; - uint16_t speed = manual_feedrate_mm_m[X_AXIS]; // Default feedrate for manual moves + uint16_t speed = manual_feedrate_mm_m.x; // Default feedrate for manual moves switch (var.VP) { default: return; @@ -172,7 +172,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Y_AXIS case VP_MOVE_Y: axiscode = 'Y'; - speed = manual_feedrate_mm_m[Y_AXIS]; + speed = manual_feedrate_mm_m.y; if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; break; #endif @@ -180,7 +180,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { #if HAS_Z_AXIS case VP_MOVE_Z: axiscode = 'Z'; - speed = manual_feedrate_mm_m[Z_AXIS]; + speed = manual_feedrate_mm_m.z; if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; break; #endif diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp index 40f3bbf1d51..97ae7638c94 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp @@ -111,7 +111,7 @@ void DGUSRxHandler::ScreenChange(DGUS_VP &vp, void *data_ptr) { dgus_screen_handler.TriggerFullUpdate(); } - void DGUSRxHandler::SelectFile(DGUS_VP &vp, void *data_ptr) { + void DGUSRxHandler::selectFile(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); const uint8_t index = ((uint8_t*)data_ptr)[1]; diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h index d6d5855b9d8..b81b142d841 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h @@ -30,7 +30,7 @@ namespace DGUSRxHandler { #if HAS_MEDIA void Scroll(DGUS_VP &, void *); - void SelectFile(DGUS_VP &, void *); + void selectFile(DGUS_VP &, void *); void PrintFile(DGUS_VP &, void *); #endif diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp index e8c23b3226a..6a430e74a6d 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp @@ -148,7 +148,7 @@ void DGUSScreenHandler::Loop() { dgus_display.Loop(); } -void DGUSScreenHandler::PrinterKilled(FSTR_P const error, FSTR_P const component) { +void DGUSScreenHandler::printerKilled(FSTR_P const error, FSTR_P const component) { SetMessageLine(error, 1); SetMessageLine(component, 2); SetMessageLinePGM(NUL_STR, 3); @@ -271,7 +271,7 @@ void DGUSScreenHandler::PrintTimerStopped() { TriggerScreenChange(DGUS_Screen::PRINT_FINISHED); } -void DGUSScreenHandler::FilamentRunout(const ExtUI::extruder_t extruder) { +void DGUSScreenHandler::filamentRunout(const ExtUI::extruder_t extruder) { char buffer[21]; snprintf_P(buffer, sizeof(buffer), GET_TEXT(DGUS_MSG_FILAMENT_RUNOUT), extruder); diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h index 0f71ebdc3d4..2ecf7192fe4 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h @@ -37,7 +37,7 @@ public: static void Ready(); static void Loop(); - static void PrinterKilled(FSTR_P const error, FSTR_P const component); + static void printerKilled(FSTR_P const error, FSTR_P const component); static void UserConfirmRequired(const char * const msg); static void SettingsReset(); static void StoreSettings(char *buff); @@ -50,7 +50,7 @@ public: static void PrintTimerStarted(); static void PrintTimerPaused(); static void PrintTimerStopped(); - static void FilamentRunout(const ExtUI::extruder_t extruder); + static void filamentRunout(const ExtUI::extruder_t extruder); #if HAS_MEDIA /// Marlin informed us that a new SD has been inserted. diff --git a/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp b/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp index cd5408e190a..69f792c45d1 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp @@ -81,7 +81,7 @@ const struct DGUS_VP vp_list[] PROGMEM = { VP_HELPER_RX(DGUS_Addr::SCREENCHANGE_Printing, &DGUSRxHandler::ScreenChange), #if HAS_MEDIA - VP_HELPER_RX(DGUS_Addr::SD_SelectFile, &DGUSRxHandler::SelectFile), + VP_HELPER_RX(DGUS_Addr::SD_SelectFile, &DGUSRxHandler::selectFile), VP_HELPER_RX(DGUS_Addr::SD_Scroll, &DGUSRxHandler::Scroll), VP_HELPER_RX_NODATA(DGUS_Addr::SD_Print, &DGUSRxHandler::PrintFile), #endif diff --git a/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp b/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp index 75ef5f5d662..73dead1b56f 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp @@ -47,7 +47,7 @@ namespace ExtUI { } void onPrinterKilled(FSTR_P const error, FSTR_P const component) { - dgus_screen_handler.PrinterKilled(error, component); + dgus_screen_handler.printerKilled(error, component); } void onMediaInserted() { TERN_(HAS_MEDIA, dgus_screen_handler.SDCardInserted()); } @@ -71,7 +71,7 @@ namespace ExtUI { } void onFilamentRunout(const extruder_t extruder) { - dgus_screen_handler.FilamentRunout(extruder); + dgus_screen_handler.filamentRunout(extruder); } void onUserConfirmRequired(const char * const msg) { diff --git a/Marlin/src/lcd/extui/ia_creality/FileNavigator.cpp b/Marlin/src/lcd/extui/ia_creality/FileNavigator.cpp index 6aa9b7c7c88..f16bdde29aa 100644 --- a/Marlin/src/lcd/extui/ia_creality/FileNavigator.cpp +++ b/Marlin/src/lcd/extui/ia_creality/FileNavigator.cpp @@ -33,23 +33,23 @@ #if DGUS_LCD_UI_IA_CREALITY -#include "ia_creality_extui.h" +#include "ia_creality_rts.h" #include "FileNavigator.h" -using namespace ExtUI; +#include -FileList FileNavigator::filelist; // Instance of the Marlin file API -char FileNavigator::currentfoldername[MAX_PATH_LEN]; // Current folder path +ExtUI::FileList FileNavigator::filelist; // ExtUI file API +char FileNavigator::currentDirPath[MAX_PATH_LEN]; // Current folder path uint16_t FileNavigator::lastindex; uint8_t FileNavigator::folderdepth; -uint16_t FileNavigator::currentindex; // override the panel request +uint16_t FileNavigator::currentindex; // override the panel request FileNavigator filenavigator; FileNavigator::FileNavigator() { reset(); } void FileNavigator::reset() { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; folderdepth = 0; currentindex = 0; lastindex = 0; @@ -136,7 +136,7 @@ void FileNavigator::getFiles(uint16_t index) { rts.sendData((uint8_t)0, FilenameIcon + (fcnt+1)); rts.sendData((unsigned long)0xFFFF, (FilenameNature + ((1+fcnt) * 16))); // white } - SERIAL_ECHOLNPGM("-", seek, " '", filelist.filename(), "' '", currentfoldername, "", filelist.shortFilename(), "'\n"); + SERIAL_ECHOLNPGM("-", seek, " '", filelist.filename(), "' '", currentDirPath, "", filelist.shortFilename(), "'\n"); fcnt++; } } @@ -144,8 +144,8 @@ void FileNavigator::getFiles(uint16_t index) { void FileNavigator::changeDIR(char *folder) { if (folderdepth >= MAX_FOLDER_DEPTH) return; // limit the folder depth - strcat(currentfoldername, folder); - strcat(currentfoldername, "/"); + strcat(currentDirPath, folder); + strcat(currentDirPath, "/"); filelist.changeDir(folder); refresh(); folderdepth++; @@ -159,17 +159,17 @@ void FileNavigator::upDIR() { currentindex = 0; // Remove the last child folder from the stored path if (folderdepth == 0) { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; reset(); } else { char *pos = nullptr; for (uint8_t f = 0; f < folderdepth; f++) - pos = strchr(currentfoldername, '/'); + pos = strchr(currentDirPath, '/'); pos[1] = '\0'; } } -char* FileNavigator::getCurrentFolderName() { return currentfoldername; } +char* FileNavigator::getCurrentDirPath() { return currentDirPath; } #endif // DGUS_LCD_UI_IA_CREALITY diff --git a/Marlin/src/lcd/extui/ia_creality/FileNavigator.h b/Marlin/src/lcd/extui/ia_creality/FileNavigator.h index 28d97c67469..af98210a9f6 100644 --- a/Marlin/src/lcd/extui/ia_creality/FileNavigator.h +++ b/Marlin/src/lcd/extui/ia_creality/FileNavigator.h @@ -30,13 +30,12 @@ * Written by Insanity Automation * ***************************************/ +#include "../ui_api.h" + #define MAX_FOLDER_DEPTH 4 // Limit folder depth TFT has a limit for the file path -#define MAX_CMND_LEN 16 * MAX_FOLDER_DEPTH // Maximum Length for a Panel command #define MAX_PATH_LEN 16 * MAX_FOLDER_DEPTH // Maximum number of characters in a SD file path #define DISPLAY_FILES 4 -using namespace ExtUI; - class FileNavigator { public: FileNavigator(); @@ -45,15 +44,15 @@ class FileNavigator { static void upDIR(); static void changeDIR(char *); static void refresh(); - static char* getCurrentFolderName(); + static char* getCurrentDirPath(); static uint8_t folderdepth; static uint16_t currentindex; static bool getIndexisDir(uint16_t); const char *getIndexName(uint16_t); static uint16_t maxFiles(); private: - static FileList filelist; - static char currentfoldername[MAX_PATH_LEN]; + static ExtUI::FileList filelist; + static char currentDirPath[MAX_PATH_LEN]; static uint16_t lastindex; }; diff --git a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.cpp b/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.cpp index 51180206db3..4bfdfc6ec3c 100644 --- a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.cpp +++ b/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.cpp @@ -25,7 +25,7 @@ * **************************************** * Extensible_UI implementation for Creality DWIN * 10SPro, Max, CRX, and others - * Based original Creality release, ported to ExtUI for Marlin 2.0 + * Based original Creality release, ported to Marlin ExtUI * Written by Insanity Automation, sponsored by Tiny Machines 3D * * ***************************************/ @@ -34,1838 +34,137 @@ #if DGUS_LCD_UI_IA_CREALITY -#include "ia_creality_extui.h" +#include "ia_creality_rts.h" #include "FileNavigator.h" - -// Singleton instance -RTS rts; - -// Static data -DB RTS::recdat, RTS::snddat; -uint8_t RTS::databuf[DATA_BUF_SIZE]; -rx_datagram_state_t RTS::rx_datagram_state = DGUS_IDLE; -uint8_t RTS::rx_datagram_len = 0; - -// Local data -uint16_t fileIndex = 0; -uint8_t recordcount = 0; -uint8_t waitway_lock = 0; -const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE; -uint8_t startprogress = 0; - -char waitway = 0; -int16_t recnum = 0; -float ChangeMaterialbuf[2] = { 0 }; - -char NozzleTempStatus[3] = { 0 }; - -char PrinterStatusKey[2] = { 0 }; // PrinterStatusKey[1] 0:keep temperature, 1:heating, 2:cooling, 3:printing - // PrinterStatusKey[0] 0:ready - -uint8_t AxisPagenum = 0; // 0 for 10mm, 1 for 1mm, 2 for 0.1mm -bool InforShowStatus = true; -bool TPShowStatus = false; // true for only opening time and percentage, false for closing time and percentage. -bool AutohomeKey = false; -uint8_t AutoHomeIconNum; -int16_t userConfValidation = 0; - -uint8_t lastPauseMsgState = 0; - -creality_dwin_settings_t Settings; -uint8_t dwin_settings_version = 1; - -bool reEntryPrevent = false; -uint8_t reEntryCount = 0; -uint16_t idleThrottling = 0; - -bool pause_resume_selected = false; - -#if HAS_PID_HEATING - uint16_t pid_hotendAutoTemp = 150; - uint16_t pid_bedAutoTemp = 70; -#endif - -#ifndef IA_CREALITY_BOOT_DELAY - #define IA_CREALITY_BOOT_DELAY 500 -#endif - -void RTS::onStartup() { - DWIN_SERIAL.begin(115200); - recdat.head[0] = snddat.head[0] = FHONE; - recdat.head[1] = snddat.head[1] = FHTWO; - ZERO(databuf); - - delay_ms(IA_CREALITY_BOOT_DELAY); // Delay to allow screen startup - setTouchScreenConfiguration(); - sendData(StartSoundSet, SoundAddr); - delay_ms(400); // Delay to allow screen to configure - - onStatusChanged(MACHINE_NAME " Ready"); - - sendData(100, FeedrateDisplay); - - /***************turn off motor*****************/ - sendData(11, FilenameIcon); - - /***************transmit temperature to screen*****************/ - sendData(0, NozzlePreheat); - sendData(0, BedPreheat); - sendData(getActualTemp_celsius(H0), NozzleTemp); - sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); - sendData(getActualTemp_celsius(BED), Bedtemp); - /***************transmit Fan speed to screen*****************/ - sendData(getActualFan_percent((fan_t)getActiveTool()), FanKeyIcon); - - /***************transmit Printer information to screen*****************/ - for (int16_t j = 0; j < 20; j++) // clean filename - sendData(0, MacVersion + j); - char sizebuf[20] = {0}; - sprintf(sizebuf, "%d X %d X %d", Y_BED_SIZE, X_BED_SIZE, Z_MAX_POS); - sendData(MACHINE_NAME, MacVersion); - sendData(SHORT_BUILD_VERSION, SoftVersion); - sendData(sizebuf, PrinterSize); - sendData(WEBSITE_URL, CorpWebsite); - - /**************************some info init*******************************/ - sendData(0, PrintscheduleIcon); - sendData(0, PrintscheduleIcon + 1); - - /************************clean screen*******************************/ - for (int16_t i = 0; i < MaxFileNumber; i++) - for (int16_t j = 0; j < 10; j++) sendData(0, SDFILE_ADDR + i * 10 + j); - - for (int16_t j = 0; j < 10; j++) { - sendData(0, Printfilename + j); // clean screen. - sendData(0, Choosefilename + j); // clean filename - } - for (int16_t j = 0; j < 8; j++) sendData(0, FilenameCount + j); - for (int16_t j = 1; j <= MaxFileNumber; j++) { - sendData(10, FilenameIcon + j); - sendData(10, FilenameIcon1 + j); - } -} - -void RTS::onIdle() { - while (rts.receiveData() > 0 && (rts.recdat.data[0] != 0 || rts.recdat.addr != 0)) - rts.handleData(); - - if (reEntryPrevent && reEntryCount < 120) { reEntryCount++; return; } - reEntryCount = 0; - - if (idleThrottling++ < 750) return; - - // Always send temperature data - rts.sendData(getActualTemp_celsius(getActiveTool()), NozzleTemp); - rts.sendData(getActualTemp_celsius(BED), Bedtemp); - rts.sendData(getTargetTemp_celsius(getActiveTool()), NozzlePreheat); - rts.sendData(getTargetTemp_celsius(BED), BedPreheat); - rts.sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); - rts.sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); - TERN_(HAS_MULTI_HOTEND, rts.sendData(uint8_t(getActiveTool() + 1), ActiveToolVP)); - - if (awaitingUserConfirm() && (lastPauseMsgState != ExtUI::pauseModeStatus || userConfValidation > 99)) { - switch (ExtUI::pauseModeStatus) { - case PAUSE_MESSAGE_PARKING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_PAUSE_PRINT_PARKING)); break; - case PAUSE_MESSAGE_CHANGING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_INIT)); break; - case PAUSE_MESSAGE_UNLOAD: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_UNLOAD)); break; - case PAUSE_MESSAGE_WAITING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_ADVANCED_PAUSE_WAITING)); break; - case PAUSE_MESSAGE_INSERT: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_INSERT)); break; - case PAUSE_MESSAGE_LOAD: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_LOAD)); break; - case PAUSE_MESSAGE_PURGE: ExtUI::onUserConfirmRequired(GET_TEXT_F(TERN(ADVANCED_PAUSE_CONTINUOUS_PURGE, MSG_FILAMENT_CHANGE_CONT_PURGE, MSG_FILAMENT_CHANGE_PURGE))); break; - case PAUSE_MESSAGE_RESUME: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_RESUME)); break; - case PAUSE_MESSAGE_HEAT: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_HEAT)); break; - case PAUSE_MESSAGE_HEATING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_HEATING)); break; - case PAUSE_MESSAGE_OPTION: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_OPTION_HEADER)); break; - case PAUSE_MESSAGE_STATUS: break; - default: onUserConfirmRequired(PSTR("Confirm Continue")); break; - } - userConfValidation = 0; - } - else if (pause_resume_selected && !awaitingUserConfirm()) { - rts.sendData(ExchangePageBase + 53, ExchangepageAddr); - pause_resume_selected = false; - userConfValidation = 0; - } - else if (awaitingUserConfirm()) { - if (pause_resume_selected) { - pause_resume_selected = false; - userConfValidation = 100; - } - else - userConfValidation++; - } - - reEntryPrevent = true; - idleThrottling = 0; - if (waitway && !commandsInQueue()) - waitway_lock++; - else - waitway_lock = 0; - - if (waitway_lock > 100) { - waitway_lock = 0; - waitway = 0; // clear waitway if nothing is going on - } - - switch (waitway) { - case 1: - if (isPositionKnown()) { - InforShowStatus = true; - rts.sendData(ExchangePageBase + 54, ExchangepageAddr); - waitway = 0; - } - break; - - case 2: - if (isPositionKnown() && !commandsInQueue()) waitway = 0; - break; - - case 3: - //if(isPositionKnown() && (getActualTemp_celsius(BED) >= (getTargetTemp_celsius(BED)-1))) { - rts.sendData(ExchangePageBase + 64, ExchangepageAddr); - waitway = 7; - //return; - //} - break; - - case 4: - if (AutohomeKey && isPositionKnown() && !commandsInQueue()) { // Manual Move Home Done - //rts.sendData(ExchangePageBase + 71 + AxisPagenum, ExchangepageAddr); - AutohomeKey = false; - waitway = 0; - } - break; - case 5: - if (isPositionKnown() && !commandsInQueue()) { - InforShowStatus = true; - waitway = 0; - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); // exchange to 78 page - } - break; - case 6: - if (!commandsInQueue()) { - setAxisPosition_mm(BED_TRAMMING_HEIGHT, axis_t(Z)); - waitway = 0; - } - break; - case 7: - if (!commandsInQueue()) waitway = 0; - break; - } - - TERN_(HAS_MESH, rts.sendData(getLevelingActive() ? 3 : 2, AutoLevelIcon)); - TERN_(HAS_FILAMENT_SENSOR, rts.sendData(getFilamentRunoutEnabled() ? 3 : 2, RunoutToggle)); - TERN_(CASE_LIGHT_ENABLE, rts.sendData(getCaseLightState() ? 3 : 2, LedToggle)); - TERN_(POWER_LOSS_RECOVERY, rts.sendData(getPowerLossRecoveryEnabled() ? 3 : 2, PowerLossToggle)); - - if (startprogress == 0) { - startprogress += 25; - delay_ms(3000); // Delay to show bootscreen - } - else if (startprogress < 250) { - if (isMediaInserted()) // Re init media as it happens too early on STM32 boards often - onMediaInserted(); - else - injectCommands(F("M22\nM21")); - startprogress = 254; - InforShowStatus = true; - TPShowStatus = false; - rts.sendData(ExchangePageBase + 45, ExchangepageAddr); - reEntryPrevent = false; - return; - } - if (startprogress <= 100) - rts.sendData(startprogress, StartIcon); - else - rts.sendData(startprogress - 100, StartIcon + 1); - - //rts.sendData((startprogress++) % 5, ExchFlmntIcon); - - if (isPrinting()) { - rts.sendData(getActualFan_percent((fan_t)getActiveTool()), FanKeyIcon); - rts.sendData(getProgress_seconds_elapsed() / 3600, Timehour); - rts.sendData((getProgress_seconds_elapsed() % 3600) / 60, Timemin); - if (getProgress_percent() > 0) { - const uint16_t perc = getProgress_percent() + 1; - if (perc <= 50) { - rts.sendData(uint16_t(perc) * 2, PrintscheduleIcon); - rts.sendData(0, PrintscheduleIcon + 1); - } - else { - rts.sendData(100, PrintscheduleIcon); - rts.sendData(uint16_t(perc) * 2 - 100, PrintscheduleIcon + 1); - } - } - else { - rts.sendData(0, PrintscheduleIcon); - rts.sendData(0, PrintscheduleIcon + 1); - } - rts.sendData(uint16_t(getProgress_percent()), Percentage); - } - else { // Not printing settings - rts.sendData(map(constrain(Settings.display_volume, 0, 255), 0, 255, 0, 100), VolumeDisplay); - rts.sendData(Settings.screen_brightness, DisplayBrightness); - rts.sendData(Settings.standby_screen_brightness, DisplayStandbyBrightness); - rts.sendData(Settings.standby_time_seconds, DisplayStandbySeconds); - if (Settings.display_standby) - rts.sendData(3, DisplayStandbyEnableIndicator); - else - rts.sendData(2, DisplayStandbyEnableIndicator); - - rts.sendData(getAxisSteps_per_mm(X) * 10, StepMM_X); - rts.sendData(getAxisSteps_per_mm(Y) * 10, StepMM_Y); - rts.sendData(getAxisSteps_per_mm(Z) * 10, StepMM_Z); - rts.sendData(getAxisSteps_per_mm(E0) * 10, StepMM_E); - - rts.sendData(getAxisMaxAcceleration_mm_s2(X) / 100, Accel_X); - rts.sendData(getAxisMaxAcceleration_mm_s2(Y) / 100, Accel_Y); - rts.sendData(getAxisMaxAcceleration_mm_s2(Z) / 10, Accel_Z); - rts.sendData(getAxisMaxAcceleration_mm_s2(E0), Accel_E); - - rts.sendData(getAxisMaxFeedrate_mm_s(X), Feed_X); - rts.sendData(getAxisMaxFeedrate_mm_s(Y), Feed_Y); - rts.sendData(getAxisMaxFeedrate_mm_s(Z), Feed_Z); - rts.sendData(getAxisMaxFeedrate_mm_s(E0), Feed_E); - - rts.sendData(getAxisMaxJerk_mm_s(X) * 100, Jerk_X); - rts.sendData(getAxisMaxJerk_mm_s(Y) * 100, Jerk_Y); - rts.sendData(getAxisMaxJerk_mm_s(Z) * 100, Jerk_Z); - rts.sendData(getAxisMaxJerk_mm_s(E0) * 100, Jerk_E); - - #if HAS_HOTEND_OFFSET - rts.sendData(getNozzleOffset_mm(X, E1) * 10, T2Offset_X); - rts.sendData(getNozzleOffset_mm(Y, E1) * 10, T2Offset_Y); - rts.sendData(getNozzleOffset_mm(Z, E1) * 10, T2Offset_Z); - rts.sendData(getAxisSteps_per_mm(E1) * 10, T2StepMM_E); - #endif - - #if HAS_BED_PROBE - rts.sendData(getProbeOffset_mm(X) * 100, ProbeOffset_X); - rts.sendData(getProbeOffset_mm(Y) * 100, ProbeOffset_Y); - #endif - - #if HAS_PID_HEATING - rts.sendData(pid_hotendAutoTemp, HotendPID_AutoTmp); - rts.sendData(pid_bedAutoTemp, BedPID_AutoTmp); - rts.sendData(getPID_Kp(E0) * 10, HotendPID_P); - rts.sendData(getPID_Ki(E0) * 10, HotendPID_I); - rts.sendData(getPID_Kd(E0) * 10, HotendPID_D); - #if ENABLED(PIDTEMPBED) - rts.sendData(getBedPID_Kp() * 10, BedPID_P); - rts.sendData(getBedPID_Ki() * 10, BedPID_I); - rts.sendData(getBedPID_Kd() * 10, BedPID_D); - #endif - #endif - } - - rts.sendData(getZOffset_mm() * 100, ProbeOffset_Z); - rts.sendData(uint16_t(getFlow_percent(E0)), Flowrate); - - if (NozzleTempStatus[0] || NozzleTempStatus[2]) { // statuse of loadfilament and unloadfinement when temperature is less than - uint16_t IconTemp = getActualTemp_celsius(getActiveTool()) * 100 / getTargetTemp_celsius(getActiveTool()); - NOMORE(IconTemp, 100U); - rts.sendData(IconTemp, HeatPercentIcon); - if (getActualTemp_celsius(getActiveTool()) > EXTRUDE_MINTEMP && NozzleTempStatus[0] != 0) { - NozzleTempStatus[0] = 0; - rts.sendData(10 * ChangeMaterialbuf[0], FilamentUnit1); - rts.sendData(10 * ChangeMaterialbuf[1], FilamentUnit2); - rts.sendData(ExchangePageBase + 65, ExchangepageAddr); - } - else if (getActualTemp_celsius(getActiveTool()) >= getTargetTemp_celsius(getActiveTool()) && NozzleTempStatus[2]) { - NozzleTempStatus[2] = 0; - TPShowStatus = true; - rts.sendData(4, ExchFlmntIcon); - rts.sendData(ExchangePageBase + 83, ExchangepageAddr); - } - else if (NozzleTempStatus[2]) { - //rts.sendData((startprogress++) % 5, ExchFlmntIcon); - } - } - - if (AutohomeKey) { - rts.sendData(AutoHomeIconNum, AutoZeroIcon); - if (++AutoHomeIconNum > 9) AutoHomeIconNum = 0; - } - - if (isMediaInserted()) { - const uint16_t currPage = fileIndex == 0 ? 1 : CEIL(float(fileIndex) / float(DISPLAY_FILES)) + 1, - maxPageAdd = filenavigator.folderdepth ? 1 : 0, - maxPages = CEIL(float(filenavigator.maxFiles() + maxPageAdd) / float(DISPLAY_FILES) ); - - rts.sendData(currPage, FilesCurentPage); - rts.sendData(maxPages, FilesMaxPage); - } - else { - rts.sendData(0, FilesCurentPage); - rts.sendData(0, FilesMaxPage); - } - - if (rts.recdat.addr != DisplayZaxis && rts.recdat.addr != DisplayYaxis && rts.recdat.addr != DisplayZaxis) { - rts.sendData(10 * getAxisPosition_mm(axis_t(X)), DisplayXaxis); - rts.sendData(10 * getAxisPosition_mm(axis_t(Y)), DisplayYaxis); - rts.sendData(10 * getAxisPosition_mm(axis_t(Z)), DisplayZaxis); - } - reEntryPrevent = false; -} - -RTS::RTS() { - recdat.head[0] = snddat.head[0] = FHONE; - recdat.head[1] = snddat.head[1] = FHTWO; - ZERO(databuf); -} - -int16_t RTS::receiveData() { - uint8_t receivedbyte; - while (DWIN_SERIAL.available()) - switch (rx_datagram_state) { - - case DGUS_IDLE: // Waiting for the first header byte - receivedbyte = DWIN_SERIAL.read(); - if (FHONE == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN; - break; - - case DGUS_HEADER1_SEEN: // Waiting for the second header byte - receivedbyte = DWIN_SERIAL.read(); - rx_datagram_state = (FHTWO == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE; - break; - - case DGUS_HEADER2_SEEN: // Waiting for the length byte - rx_datagram_len = DWIN_SERIAL.read(); - //DEBUGLCDCOMM_ECHOPGM(" (", rx_datagram_len, ") "); - - // Telegram min len is 3 (command and one word of payload) - rx_datagram_state = WITHIN(rx_datagram_len, 3, DGUS_RX_BUFFER_SIZE) ? DGUS_WAIT_TELEGRAM : DGUS_IDLE; - break; - - case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive. - if (DWIN_SERIAL.available() < rx_datagram_len) return -1; - - uint8_t command = DWIN_SERIAL.read(); - - //DEBUGLCDCOMM_ECHOPGM("# ", command); - - uint8_t readlen = rx_datagram_len - 1; // command is part of len. - uint8_t tmp[rx_datagram_len - 1]; - uint8_t *ptmp = tmp; - while (readlen--) { - receivedbyte = DWIN_SERIAL.read(); - //DEBUGLCDCOMM_ECHOPGM(" ", receivedbyte); - *ptmp++ = receivedbyte; - } - //DEBUGLCDCOMM_ECHOPGM(" # "); - // mostly we'll get this: 5A A5 03 82 4F 4B -- ACK on 0x82, so discard it. - if (command == VarAddr_W && 'O' == tmp[0] && 'K' == tmp[1]) { - rx_datagram_state = DGUS_IDLE; - break; - } - - /* AutoUpload, (and answer to) Command 0x83 : - | tmp[0 1 2 3 4 ... ] - | Example 5A A5 06 83 20 01 01 78 01 …… - | / / | | \ / | \ \ - | Header | | | | \_____\_ DATA (Words!) - | DatagramLen / VPAdr | - | Command DataLen (in Words) */ - if (command == VarAddr_R) { - const uint16_t vp = tmp[0] << 8 | tmp[1]; - - const uint8_t dlen = tmp[2] << 1; // Convert to Bytes. (Display works with words) - recdat.addr = vp; - recdat.len = tmp[2]; - for (uint16_t i = 0; i < dlen; i += 2) { - recdat.data[i / 2] = tmp[3 + i]; - recdat.data[i / 2] = (recdat.data[i / 2] << 8 ) | tmp[4 + i]; - } - - rx_datagram_state = DGUS_IDLE; - return 2; - break; - } - - // discard anything else - rx_datagram_state = DGUS_IDLE; - } - return -1; -} - -void RTS::sendData() { - if (snddat.head[0] == FHONE && snddat.head[1] == FHTWO && snddat.len >= 3) { - databuf[0] = snddat.head[0]; - databuf[1] = snddat.head[1]; - databuf[2] = snddat.len; - databuf[3] = snddat.command; - if (snddat.command == 0x80) { // to write data to the register - databuf[4] = snddat.addr; - for (int16_t i = 0; i < (snddat.len - 2); i++) databuf[5 + i] = snddat.data[i]; - } - else if (snddat.len == 3 && (snddat.command == 0x81)) { // to read data from the register - databuf[4] = snddat.addr; - databuf[5] = snddat.bytelen; - } - else if (snddat.command == 0x82) { // to write data to the variate - databuf[4] = snddat.addr >> 8; - databuf[5] = snddat.addr & 0xFF; - for (int16_t i = 0; i < (snddat.len - 3); i += 2) { - databuf[6 + i] = snddat.data[i / 2] >> 8; - databuf[7 + i] = snddat.data[i / 2] & 0xFF; - } - } - else if (snddat.len == 4 && (snddat.command == 0x83)) { // to read data from the variate - databuf[4] = snddat.addr >> 8; - databuf[5] = snddat.addr & 0xFF; - databuf[6] = snddat.bytelen; - } - for (int16_t i = 0; i < (snddat.len + 3); i++) { - DWIN_SERIAL.write(databuf[i]); - delay_us(1); - } - - memset(&snddat, 0, sizeof(snddat)); - ZERO(databuf); - snddat.head[0] = FHONE; - snddat.head[1] = FHTWO; - } -} - -void RTS::sendData(const String &s, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { - if (s.length() < 1) return; - sendData(s.c_str(), addr, cmd); -} - -void RTS::sendData(const char *str, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { - int16_t len = strlen(str); - constexpr int16_t maxlen = DATA_BUF_SIZE - 6; - if (len > 0) { - if (len > maxlen) len = maxlen; - databuf[0] = FHONE; - databuf[1] = FHTWO; - databuf[2] = 3 + len; - databuf[3] = cmd; - databuf[4] = addr >> 8; - databuf[5] = addr & 0x00FF; - for (int16_t i = 0; i < len; i++) databuf[6 + i] = str[i]; - - for (int16_t i = 0; i < (len + 6); i++) { - DWIN_SERIAL.write(databuf[i]); - delay_us(1); - } - ZERO(databuf); - } -} - -void RTS::sendData(const char c, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { - snddat.command = cmd; - snddat.addr = addr; - snddat.data[0] = uint32_t(uint16_t(c) << 8); - snddat.len = 5; - sendData(); -} - -void RTS::sendData(const_float_t f, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { - int16_t n = f; - if (cmd == VarAddr_W) { - snddat.data[0] = n; - snddat.len = 5; - } - else if (cmd == RegAddr_W) { - snddat.data[0] = n; - snddat.len = 3; - } - else if (cmd == VarAddr_R) { - snddat.bytelen = n; - snddat.len = 4; - } - snddat.command = cmd; - snddat.addr = addr; - sendData(); -} - -void RTS::sendData(const int n, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { - if (cmd == VarAddr_W) { - if ((unsigned int)n > 0xFFFF) { - snddat.data[0] = n >> 16; - snddat.data[1] = n & 0xFFFF; - snddat.len = 7; - } - else { - snddat.data[0] = n; - snddat.len = 5; - } - } - else if (cmd == RegAddr_W) { - snddat.data[0] = n; - snddat.len = 3; - } - else if (cmd == VarAddr_R) { - snddat.bytelen = n; - snddat.len = 4; - } - snddat.command = cmd; - snddat.addr = addr; - sendData(); -} - -void RTS::sendData(const unsigned long n, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { - if (cmd == VarAddr_W) { - if (n > 0xFFFF) { - snddat.data[0] = n >> 16; - snddat.data[1] = n & 0xFFFF; - //snddat.data[0] = n >> 24; - //snddat.data[1] = n >> 16; - //snddat.data[2] = n >> 8; - //snddat.data[3] = n; - snddat.len = 7; - } - else { - snddat.data[0] = n; - snddat.len = 5; - } - } - else if (cmd == VarAddr_R) { - snddat.bytelen = n; - snddat.len = 4; - } - snddat.command = cmd; - snddat.addr = addr; - sendData(); -} - -void RTS::handleData() { - int16_t Checkkey = -1; - if (waitway > 0) { // for waiting - memset(&recdat, 0, sizeof(recdat)); - recdat.head[0] = FHONE; - recdat.head[1] = FHTWO; - return; - } - for (int16_t i = 0; Addrbuf[i] != 0; i++) - if (recdat.addr == Addrbuf[i]) { - if (Addrbuf[i] == NzBdSet || Addrbuf[i] == NozzlePreheat || Addrbuf[i] == BedPreheat || Addrbuf[i] == Flowrate) - Checkkey = ManualSetTemp; - else if (WITHIN(Addrbuf[i], Stopprint, Resumeprint)) - Checkkey = PrintChoice; - else if (WITHIN(Addrbuf[i], AutoZero, DisplayZaxis)) - Checkkey = XYZEaxis; - else if (WITHIN(Addrbuf[i], FilamentUnit1, FilamentUnit2)) - Checkkey = Filament; - else - Checkkey = i; - break; - } - - switch (recdat.addr) { - case Flowrate: - case StepMM_X ... StepMM_E: - case ProbeOffset_X ... ProbeOffset_Y: - case HotendPID_AutoTmp ... BedPID_AutoTmp: - case HotendPID_P ... HotendPID_D: - case BedPID_P ... BedPID_D: - case T2Offset_X ... T2StepMM_E: - case Accel_X ... Accel_E: - case Feed_X ... Feed_E: - case Jerk_X ... Jerk_E: - case RunoutToggle: - case PowerLossToggle: - case FanKeyIcon: - case LedToggle: - case e2Preheat: Checkkey = ManualSetTemp; break; - case ProbeOffset_Z: Checkkey = Zoffset_Value; break; - case VolumeDisplay: Checkkey = VolumeDisplay; break; - case DisplayBrightness: Checkkey = DisplayBrightness; break; - case DisplayStandbyBrightness: Checkkey = DisplayStandbyBrightness; break; - case DisplayStandbySeconds: Checkkey = DisplayStandbySeconds; break; - default: - if (WITHIN(recdat.addr, AutolevelVal, 4400)) // (int16_t(AutolevelVal) + GRID_MAX_POINTS * 2) = 4400 with 5x5 mesh - Checkkey = AutolevelVal; - else if (WITHIN(recdat.addr, SDFILE_ADDR, SDFILE_ADDR + 10 * (FileNum + 1))) - Checkkey = Filename; - break; - } - - if (Checkkey < 0) { - memset(&recdat, 0, sizeof(recdat)); - recdat.head[0] = FHONE; - recdat.head[1] = FHTWO; - return; - } - - constexpr float lfrb[4] = BED_TRAMMING_INSET_LFRB; - - switch (Checkkey) { - case Printfile: - if (recdat.data[0] == 1) { // card - InforShowStatus = false; - filenavigator.getFiles(0); - fileIndex = 0; - recordcount = 0; - sendData(ExchangePageBase + 46, ExchangepageAddr); - } - else if (recdat.data[0] == 2) { // return after printing result. - InforShowStatus = true; - TPShowStatus = false; - stopPrint(); - injectCommands(F("M84")); - sendData(11, FilenameIcon); - sendData(0, PrintscheduleIcon); - sendData(0, PrintscheduleIcon + 1); - sendData(0, Percentage); - delay_ms(2); - sendData(0, Timehour); - sendData(0, Timemin); - - sendData(ExchangePageBase + 45, ExchangepageAddr); // exchange to 45 page - } - else if (recdat.data[0] == 3) { // Temperature control - InforShowStatus = true; - TPShowStatus = false; - if (getTargetFan_percent((fan_t)getActiveTool()) == 0) - sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans off - else - sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on - } - else if (recdat.data[0] == 4) { // Settings - InforShowStatus = false; - } - break; - - case Adjust: - if (recdat.data[0] == 1) { - InforShowStatus = false; - } - else if (recdat.data[0] == 2) { - InforShowStatus = true; - if (PrinterStatusKey[1] == 3) // during heating - sendData(ExchangePageBase + 53, ExchangepageAddr); - else if (PrinterStatusKey[1] == 4) - sendData(ExchangePageBase + 54, ExchangepageAddr); - else - sendData(ExchangePageBase + 53, ExchangepageAddr); - } - else if (recdat.data[0] == 3) - setTargetFan_percent(getTargetFan_percent((fan_t)getActiveTool()) != 0 ? 100 : 0, FAN0); - - break; - - case Feedrate: - setFeedrate_percent(recdat.data[0]); - break; - - case PrintChoice: - if (recdat.addr == Stopprint) { - if (recdat.data[0] == 240) { // no - sendData(ExchangePageBase + 53, ExchangepageAddr); - } - else { - sendData(ExchangePageBase + 45, ExchangepageAddr); - sendData(0, Timehour); - sendData(0, Timemin); - stopPrint(); - } - } - else if (recdat.addr == Pauseprint) { - if (recdat.data[0] != 0xF1) - break; - - sendData(ExchangePageBase + 54, ExchangepageAddr); - pausePrint(); - } - else if (recdat.addr == Resumeprint && recdat.data[0] == 1) { - resumePrint(); - - PrinterStatusKey[1] = 0; - InforShowStatus = true; - - sendData(ExchangePageBase + 53, ExchangepageAddr); - } - if (recdat.addr == Resumeprint && recdat.data[0] == 2) { // warming - resumePrint(); - NozzleTempStatus[2] = 1; - PrinterStatusKey[1] = 0; - InforShowStatus = true; - sendData(ExchangePageBase + 82, ExchangepageAddr); - } - break; - - case Zoffset: - float tmp_zprobe_offset; - if (recdat.data[0] >= 32768) - tmp_zprobe_offset = (float(recdat.data[0]) - 65536) / 100; - else - tmp_zprobe_offset = float(recdat.data[0]) / 100; - if (WITHIN((tmp_zprobe_offset), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - int16_t tmpSteps = mmToWholeSteps(getZOffset_mm() - tmp_zprobe_offset, axis_t(Z)); - if (tmpSteps == 0) tmpSteps = getZOffset_mm() < tmp_zprobe_offset ? 1 : -1; - smartAdjustAxis_steps(-tmpSteps, axis_t(Z), false); - char zOffs[20], tmp1[11]; - sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); - onStatusChanged(zOffs); - } - else { - onStatusChanged(F("Requested Offset Beyond Limits")); - } - - sendData(getZOffset_mm() * 100, ProbeOffset_Z); - break; - - case TempControl: - if (recdat.data[0] == 0) { - InforShowStatus = true; - TPShowStatus = false; - } - else if (recdat.data[0] == 1) { - if (getTargetFan_percent((fan_t)getActiveTool()) == 0) - sendData(ExchangePageBase + 60, ExchangepageAddr); // exchange to 60 page, the fans off - else - sendData(ExchangePageBase + 59, ExchangepageAddr); // exchange to 59 page, the fans on - } - else if (recdat.data[0] == 2) { - InforShowStatus = true; - } - else if (recdat.data[0] == 3) { - if (getTargetFan_percent((fan_t)getActiveTool()) == 0) { // turn on the fan - setTargetFan_percent(100, FAN0); - sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on - } - else { // turn off the fan - setTargetFan_percent(0, FAN0); - sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans on - } - } - else if (recdat.data[0] == 5) { // PLA mode - setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, getActiveTool()); - setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED); - sendData(PREHEAT_1_TEMP_HOTEND, NozzlePreheat); - sendData(PREHEAT_1_TEMP_BED, BedPreheat); - } - else if (recdat.data[0] == 6) { // ABS mode - setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, getActiveTool()); - setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED); - sendData(PREHEAT_2_TEMP_HOTEND, NozzlePreheat); - sendData(PREHEAT_2_TEMP_BED, BedPreheat); - } - else if (recdat.data[0] == 0xF1) { - //InforShowStatus = true; - #if FAN_COUNT > 0 - for (uint8_t i = 0; i < FAN_COUNT; i++) setTargetFan_percent(0, (fan_t)i); - #endif - setTargetTemp_celsius(0.0, H0); - TERN_(HAS_MULTI_HOTEND, setTargetTemp_celsius(0.0, H1)); - setTargetTemp_celsius(0.0, BED); - sendData(0, NozzlePreheat); delay_ms(1); - sendData(0, BedPreheat); delay_ms(1); - sendData(ExchangePageBase + 57, ExchangepageAddr); - PrinterStatusKey[1] = 2; - } - break; - - case ManualSetTemp: - if (recdat.addr == NzBdSet) { - if (recdat.data[0] == 0) { - if (getTargetFan_percent((fan_t)getActiveTool()) == 0) - sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans off - else - sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on - } - else if (recdat.data[0] == 1) { - setTargetTemp_celsius(0.0, getActiveTool()); - sendData(0, NozzlePreheat); - } - else if (recdat.data[0] == 2) { - setTargetTemp_celsius(0.0, BED); - sendData(0, BedPreheat); - } - } - else if (recdat.addr == NozzlePreheat) { - setTargetTemp_celsius(float(recdat.data[0]), H0); - } - #if HAS_MULTI_HOTEND - else if (recdat.addr == e2Preheat) { - setTargetTemp_celsius(float(recdat.data[0]), H1); - } - #endif - else if (recdat.addr == BedPreheat) { - setTargetTemp_celsius(float(recdat.data[0]), BED); - } - else if (recdat.addr == Flowrate) { - setFlow_percent(int16_t(recdat.data[0]), getActiveTool()); - } - - #if HAS_PID_HEATING - else if (recdat.addr == HotendPID_AutoTmp) { - pid_hotendAutoTemp = uint16_t(recdat.data[0]); - } - else if (recdat.addr == BedPID_AutoTmp) { - pid_bedAutoTemp = uint16_t(recdat.data[0]); - } - #endif - - else if (recdat.addr == Accel_X) { - setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 100, X); - } - else if (recdat.addr == Accel_Y) { - setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 100, Y); - } - else if (recdat.addr == Accel_Z) { - setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 10, Z); - } - else if (recdat.addr == Accel_E) { - setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]), E0); - setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]), E1); - } - - else if (recdat.addr == Feed_X) { - setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), X); - } - else if (recdat.addr == Feed_Y) { - setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), Y); - } - else if (recdat.addr == Feed_Z) { - setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), Z); - } - else if (recdat.addr == Feed_E) { - setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), E0); - setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), E1); - } - else if (recdat.addr == FanKeyIcon) { - setTargetFan_percent(uint16_t(recdat.data[0]), (fan_t)getActiveTool()); - } - else { - float tmp_float_handling; - if (recdat.data[0] >= 32768) - tmp_float_handling = (float(recdat.data[0]) - 65536) / 100; - else - tmp_float_handling = float(recdat.data[0]) / 100; - if (recdat.addr == StepMM_X) { - setAxisSteps_per_mm(tmp_float_handling * 10, X); - } - else if (recdat.addr == StepMM_Y) { - setAxisSteps_per_mm(tmp_float_handling * 10, Y); - } - else if (recdat.addr == StepMM_Z) { - setAxisSteps_per_mm(tmp_float_handling * 10, Z); - } - else if (recdat.addr == StepMM_E) { - setAxisSteps_per_mm(tmp_float_handling * 10, E0); - #if DISABLED(DUAL_X_CARRIAGE) - setAxisSteps_per_mm(tmp_float_handling * 10, E1); - #endif - } - #if ENABLED(DUAL_X_CARRIAGE) - else if (recdat.addr == T2StepMM_E) { - setAxisSteps_per_mm(tmp_float_handling * 10, E1); - } - else if (recdat.addr == T2Offset_X) { - setNozzleOffset_mm(tmp_float_handling * 10, X, E1); - } - else if (recdat.addr == T2Offset_Y) { - setNozzleOffset_mm(tmp_float_handling * 10, Y, E1); - } - else if (recdat.addr == T2Offset_Z) { - setNozzleOffset_mm(tmp_float_handling * 10, Z, E1); - } - #endif - #if HAS_BED_PROBE - else if (recdat.addr == ProbeOffset_X) { - setProbeOffset_mm(tmp_float_handling, X); - } - else if (recdat.addr == ProbeOffset_Y) { - setProbeOffset_mm(tmp_float_handling, Y); - } - else if (recdat.addr == ProbeOffset_Z) { - setProbeOffset_mm(tmp_float_handling, Z); - } - #endif - - #if ENABLED(CLASSIC_JERK) - else if (recdat.addr == Jerk_X) { - setAxisMaxJerk_mm_s(tmp_float_handling, X); - } - else if (recdat.addr == Jerk_Y) { - setAxisMaxJerk_mm_s(tmp_float_handling, Y); - } - else if (recdat.addr == Jerk_Z) { - setAxisMaxJerk_mm_s(tmp_float_handling, Z); - } - else if (recdat.addr == Jerk_E) { - setAxisMaxJerk_mm_s(tmp_float_handling, E0); - setAxisMaxJerk_mm_s(tmp_float_handling, E1); - } - #endif - - #if HAS_FILAMENT_SENSOR - else if (recdat.addr == RunoutToggle) { - setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); - } - #endif - - #if ENABLED(POWER_LOSS_RECOVERY) - else if (recdat.addr == PowerLossToggle) { - setPowerLossRecoveryEnabled(!getPowerLossRecoveryEnabled()); - } - #endif - - #if ENABLED(CASE_LIGHT_ENABLE) - else if (recdat.addr == LedToggle) { - setCaseLightState(!getCaseLightState()); - } - #endif - - #if HAS_PID_HEATING - else if (recdat.addr == HotendPID_P) { - setPID(tmp_float_handling * 10, getPID_Ki(getActiveTool()), getPID_Kd(getActiveTool()), getActiveTool()); - } - else if (recdat.addr == HotendPID_I) { - setPID(getPID_Kp(getActiveTool()), tmp_float_handling * 10, getPID_Kd(getActiveTool()), getActiveTool()); - } - else if (recdat.addr == HotendPID_D) { - setPID(getPID_Kp(getActiveTool()), getPID_Ki(getActiveTool()), tmp_float_handling * 10, getActiveTool()); - } - #if ENABLED(PIDTEMPBED) - else if (recdat.addr == BedPID_P) { - setBedPID(tmp_float_handling * 10, getBedPID_Ki(), getBedPID_Kd()); - } - else if (recdat.addr == BedPID_I) { - setBedPID(getBedPID_Kp(), tmp_float_handling * 10, getBedPID_Kd()); - } - else if (recdat.addr == BedPID_D) { - setBedPID(getBedPID_Kp(), getBedPID_Ki(), tmp_float_handling * 10); - } - #endif - #endif // HAS_PID_HEATING - } - break; - - case Setting: - if (recdat.data[0] == 0) { // return to main page - InforShowStatus = true; - TPShowStatus = false; - } - else if (recdat.data[0] == 1) { // Bed Autoleveling - #if HAS_MESH - sendData(getLevelingActive() ? 3 : 2, AutoLevelIcon); - - if (ExtUI::getMeshValid()) { - uint8_t abl_probe_index = 0; - for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) - for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { - const bool zig = outer & 1; - const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; - sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + abl_probe_index * 2); - ++abl_probe_index; - } - } - #endif - sendData(10, FilenameIcon); // Motor Icon - injectCommands(isPositionKnown() ? F("G1F1000Z0.0") : F("G28\nG1F1000Z0.0")); - waitway = 2; - sendData(ExchangePageBase + 64, ExchangepageAddr); - } - else if (recdat.data[0] == 2) { // Exchange filament - InforShowStatus = true; - TPShowStatus = false; - ZERO(ChangeMaterialbuf); - ChangeMaterialbuf[1] = ChangeMaterialbuf[0] = 10; - sendData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show, instead of current_position.e in them. - sendData(10 * ChangeMaterialbuf[1], FilamentUnit2); - sendData(getActualTemp_celsius(H0), NozzleTemp); - sendData(getTargetTemp_celsius(H0), NozzlePreheat); - sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); - sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); - delay_ms(2); - sendData(ExchangePageBase + 65, ExchangepageAddr); - } - else if (recdat.data[0] == 3) { // Move - AxisPagenum = 0; - sendData(ExchangePageBase + 71, ExchangepageAddr); - } - else if (recdat.data[0] == 4) { // Language - // Just loads language screen, now used for tools - } - else if (recdat.data[0] == 5) { // Printer Information - sendData(WEBSITE_URL, CorpWebsite); - } - else if (recdat.data[0] == 6) { // Diabalestepper - injectCommands(F("M84")); - sendData(11, FilenameIcon); - } - break; - - case ReturnBack: - if (recdat.data[0] == 1) { // return to the tool page - InforShowStatus = false; - sendData(ExchangePageBase + 63, ExchangepageAddr); - } - if (recdat.data[0] == 2) // return to the Level mode page - sendData(ExchangePageBase + 64, ExchangepageAddr); - break; - - case Bedlevel: - switch (recdat.data[0]) { - case 1: { // Z-axis to home - // Disallow Z homing if X or Y are unknown - injectCommands(isAxisPositionKnown(axis_t(X)) && isAxisPositionKnown(axis_t(Y)) ? F("G28Z\nG1F1500Z0.0") : F("G28\nG1F1500Z0.0")); - sendData(getZOffset_mm() * 100, ProbeOffset_Z); - break; - } - case 2: { // Z-axis to Up - if (WITHIN((getZOffset_mm() + 0.1), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - smartAdjustAxis_steps(getAxisSteps_per_mm(Z) / 10, axis_t(Z), false); - //setZOffset_mm(getZOffset_mm() + 0.1); - sendData(getZOffset_mm() * 100, ProbeOffset_Z); - char zOffs[20], tmp1[11]; - sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); - onStatusChanged(zOffs); - } - break; - } - case 3: { // Z-axis to Down - if (WITHIN((getZOffset_mm() - 0.1), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - smartAdjustAxis_steps(-getAxisSteps_per_mm(Z) / 10, axis_t(Z), false); - //babystepAxis_steps(int16_t(-getAxisSteps_per_mm(Z)) / 10, axis_t(Z)); - //setZOffset_mm(getZOffset_mm() - 0.1); - sendData(getZOffset_mm() * 100, ProbeOffset_Z); - char zOffs[20], tmp1[11]; - sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); - onStatusChanged(zOffs); - } - break; - } - case 4: { // Assistant Level - TERN_(HAS_MESH, setLevelingActive(false)); - injectCommands(isPositionKnown() ? F("G1 F1000 Z0.0") : F("G28\nG1 F1000 Z0.0")); - waitway = 2; - sendData(ExchangePageBase + 84, ExchangepageAddr); - break; - } - case 5: { // AutoLevel "Measuring" Button - #if ENABLED(MESH_BED_LEVELING) - sendData(ExchangePageBase + 93, ExchangepageAddr); - #else - waitway = 3; // only for prohibiting to receive massage - sendData(3, AutolevelIcon); - uint8_t abl_probe_index = 0; - while (abl_probe_index < 25) { - sendData(0, AutolevelVal + abl_probe_index * 2); - ++abl_probe_index; - } - sendData(ExchangePageBase + 64, ExchangepageAddr); - injectCommands(F(MEASURING_GCODE)); - #endif - break; - } - - case 6: { // Assitant Level , Centre 1 - setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); - setAxisPosition_mm(X_CENTER, axis_t(X)); - setAxisPosition_mm(Y_CENTER, axis_t(Y)); - waitway = 6; - break; - } - case 7: { // Assitant Level , Front Left 2 - setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); - setAxisPosition_mm(X_MIN_BED + lfrb[0], axis_t(X)); - setAxisPosition_mm(Y_MIN_BED + lfrb[1], axis_t(Y)); - waitway = 6; - break; - } - case 8: { // Assitant Level , Front Right 3 - setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); - setAxisPosition_mm(X_MAX_BED - lfrb[2], axis_t(X)); - setAxisPosition_mm(Y_MIN_BED + lfrb[1], axis_t(Y)); - waitway = 6; - break; - } - case 9: { // Assitant Level , Back Right 4 - setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); - setAxisPosition_mm(X_MAX_BED - lfrb[2], axis_t(X)); - setAxisPosition_mm(Y_MAX_BED - lfrb[3], axis_t(Y)); - waitway = 6; - break; - } - case 10: { // Assitant Level , Back Left 5 - setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); - setAxisPosition_mm(X_MIN_BED + lfrb[0], axis_t(X)); - setAxisPosition_mm(Y_MAX_BED - lfrb[3], axis_t(Y)); - waitway = 6; - break; - } - case 11: { // Autolevel switch - #if HAS_MESH - const bool gla = !getLevelingActive(); - setLevelingActive(gla); - sendData(gla ? 3 : 2, AutoLevelIcon); - #endif - sendData(getZOffset_mm() * 100, ProbeOffset_Z); - break; - } - case 12: { - injectCommands(F("G26R255")); - onStatusChanged(F("Beginning G26.. Heating")); - break; - } - case 13: { - injectCommands(F("G29S1")); - onStatusChanged(F("Begin Manual Mesh")); - break; - } - case 14: { - injectCommands(F("G29S2")); - onStatusChanged(F("Moving to Next Mesh Point")); - break; - } - case 15: { - injectCommands(F("M211S0\nG91\nG1Z-0.025\nG90\nM211S1")); - onStatusChanged(F("Moved down 0.025")); - break; - } - case 16: { - injectCommands(F("M211S0\nG91\nG1Z0.025\nG90\nM211S1")); - onStatusChanged(F("Moved up 0.025")); - break; - } - case 17: { - Settings.display_volume = 0; - Settings.display_sound = false; - setTouchScreenConfiguration(); - break; - } - case 18: { - Settings.display_volume = 255; - Settings.display_sound = true; - setTouchScreenConfiguration(); - break; - } - case 19: { - Settings.screen_brightness = 10; - setTouchScreenConfiguration(); - break; - } - case 20: { - Settings.screen_brightness = 100; - setTouchScreenConfiguration(); - break; - } - case 21: { - Settings.display_standby ^= true; - setTouchScreenConfiguration(); - break; - } - case 22: { - Settings.screen_rotation = Settings.screen_rotation == 10 ? 0 : 10; - setTouchScreenConfiguration(); - break; - } - case 23: { // Set IDEX Autopark - injectCommands(F("M605S1\nG28X\nG1X0")); - break; - } - case 24: { // Set IDEX Duplication - injectCommands(F("M605S1\nT0\nG28\nM605S2\nG28X\nG1X0")); - break; - } - case 25: { // Set IDEX Mirrored Duplication - injectCommands(F("M605S1\nT0\nG28\nM605S2\nG28X\nG1X0\nM605S3")); - break; - } - case 26: { // Set IDEX Full Control - injectCommands(F("M605S0\nG28X")); - break; - } - case 27: { // Change Tool - setActiveTool(getActiveTool() == E0 ? E1 : E0, !isAxisPositionKnown(X)); - break; - } - default: break; - } - - sendData(10, FilenameIcon); - break; - - case XYZEaxis: { - axis_t axis = X; - float min = 0.0f, max = 0.0f; - waitway = 4; - if (recdat.addr == DisplayXaxis) { - axis = X; - min = X_MIN_POS; - max = X_MAX_POS; - } - else if (recdat.addr == DisplayYaxis) { - axis = Y; - min = Y_MIN_POS; - max = Y_MAX_POS; - } - else if (recdat.addr == DisplayZaxis) { - axis = Z; - min = Z_MIN_POS; - max = Z_MAX_POS; - } - else if (recdat.addr == AutoZero) { - if (recdat.data[0] == 3) { // autohome - waitway = 4; - injectCommands(F("G28\nG1 F1000 Z10")); - InforShowStatus = AutohomeKey = true; - AutoHomeIconNum = 0; - sendData(10, FilenameIcon); - } - else { - AxisPagenum = recdat.data[0]; - waitway = 0; - } - break; - } - - float targetPos = float(recdat.data[0]) / 10; - LIMIT(targetPos, min, max); - setAxisPosition_mm(targetPos, axis); - waitway = 0; - sendData(10, FilenameIcon); - break; - } - - case Filament: - - uint16_t IconTemp; - if (recdat.addr == Exchfilament) { - if (getActualTemp_celsius(getActiveTool()) < EXTRUDE_MINTEMP && recdat.data[0] < 5) { - sendData(int16_t(EXTRUDE_MINTEMP), 0x1020); - delay_ms(5); - sendData(ExchangePageBase + 66, ExchangepageAddr); - break; - } - - switch (recdat.data[0]) { - case 1: { // Unload filament1 - setAxisPosition_mm(getAxisPosition_mm(E0) - ChangeMaterialbuf[0], E0); - break; - } - case 2: { // Load filament1 - setAxisPosition_mm(getAxisPosition_mm(E0) + ChangeMaterialbuf[0], E0); - break; - } - case 3: { // Unload filament2 - setAxisPosition_mm(getAxisPosition_mm(E1) - ChangeMaterialbuf[1], E1); - break; - } - case 4: { // Load filament2 - setAxisPosition_mm(getAxisPosition_mm(E1) + ChangeMaterialbuf[1], E1); - break; - } - case 5: { // sure to heat - NozzleTempStatus[0] = 1; - - setTargetTemp_celsius((PREHEAT_1_TEMP_HOTEND + 10), getActiveTool()); - IconTemp = getActualTemp_celsius(getActiveTool()) * 100 / getTargetTemp_celsius(getActiveTool()); - NOMORE(IconTemp, 100U); - sendData(IconTemp, HeatPercentIcon); - - sendData(getActualTemp_celsius(H0), NozzleTemp); - sendData(getTargetTemp_celsius(H0), NozzlePreheat); - sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); - sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); - delay_ms(5); - sendData(ExchangePageBase + 68, ExchangepageAddr); - break; - } - case 6: { // cancel to heat - sendData(ExchangePageBase + 65, ExchangepageAddr); - break; - } - case 0xF1: { // Sure to cancel heating - NozzleTempStatus[0] = 0; - delay_ms(1); - sendData(ExchangePageBase + 65, ExchangepageAddr); - break; - } - case 0xF0: // not to cancel heating - break; - } - sendData(10 * ChangeMaterialbuf[0], FilamentUnit1); // It's ChangeMaterialbuf for show, instead of current_position.e in them. - sendData(10 * ChangeMaterialbuf[1], FilamentUnit2); - } - else if (recdat.addr == FilamentUnit1) { - ChangeMaterialbuf[0] = float(recdat.data[0]) / 10; - } - else if (recdat.addr == FilamentUnit2) { - ChangeMaterialbuf[1] = float(recdat.data[0]) / 10; - } - break; - - case LanguageChoice: - - //if (recdat.data[0] == 1) settings.save(); else injectCommands(F("M300")); - - // may at some point use language change screens to save eeprom explicitly - switch (recdat.data[0]) { - case 0: { - injectCommands(F("M500")); - break; - } - case 1: { - sendData(ExchangePageBase + 94, ExchangepageAddr); - break; - } - - #if ENABLED(PIDTEMP) - case 2: { - onStatusChanged(F("Hotend PID Started")); - startPIDTune(static_cast(pid_hotendAutoTemp), getActiveTool()); - break; - } - #endif - - case 3: { - injectCommands(F("M502\nM500")); - break; - } - case 4: { - injectCommands(F("M999\nM280P0S160")); - break; - } - - case 5: { - #if ENABLED(PIDTEMPBED) - onStatusChanged(F("Bed PID Started")); - startBedPIDTune(static_cast(pid_bedAutoTemp)); - #endif - break; - } - case 6: { - injectCommands(F("M500")); - break; - } - default: break; - } - break; - - case No_Filament: - if (recdat.data[0] == 1) { // Filament is out, resume / resume selected on screen - if (ExtUI::pauseModeStatus != PAUSE_MESSAGE_PURGE && ExtUI::pauseModeStatus != PAUSE_MESSAGE_OPTION) { - // setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); - setUserConfirmed(); - // PrinterStatusKey[1] = 3; - // pause_resume_selected = true; - } - else { - #if ENABLED(FILAMENT_RUNOUT_SENSOR) - bool runouton = false; - if (getFilamentRunoutState()) { - #if NUM_RUNOUT_SENSORS > 1 - if ((runouton = getFilamentRunoutEnabled(getActiveTool()))) - ExtUI::setFilamentRunoutEnabled(false, getActiveTool()); - #else - if ((runouton = getFilamentRunoutEnabled())) - ExtUI::setFilamentRunoutEnabled(false); - #endif - } - #else - constexpr bool runouton = false; - #endif - if (!runouton) { - setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); - setUserConfirmed(); - PrinterStatusKey[1] = 3; - pause_resume_selected = true; - } - } - } - else if (recdat.data[0] == 0) { // Filamet is out, Cancel Selected - if (ExtUI::pauseModeStatus == PAUSE_MESSAGE_PURGE || ExtUI::pauseModeStatus == PAUSE_MESSAGE_OPTION) { - setPauseMenuResponse(PAUSE_RESPONSE_EXTRUDE_MORE); - setUserConfirmed(); - } - } - break; - - #if ENABLED(POWER_LOSS_RECOVERY) - case PwrOffNoF: - if (recdat.data[0] == 1) // Yes: continue to print the 3Dmode during power-off. - injectCommands(F("M1000")); - else if (recdat.data[0] == 2) // No - injectCommands(F("M1000C")); - break; - #endif - - case Volume: - if (recdat.data[0] < 0) - Settings.display_volume = 0; - else if (recdat.data[0] > 255) - Settings.display_volume = 0xFF; - else - Settings.display_volume = recdat.data[0]; - - if (Settings.display_volume == 0) { - sendData(0, VolumeIcon); - sendData(9, SoundIcon); - } - else { - sendData((Settings.display_volume + 1) / 32 - 1, VolumeIcon); - sendData(8, SoundIcon); - } - sendData(Settings.display_volume << 8, SoundAddr + 1); - break; - - case Filename: - if (isMediaInserted() && recdat.addr == FilenameChs) { - - recordcount = recdat.data[0] - 1; - if (filenavigator.currentindex == 0 && filenavigator.folderdepth > 0 && (fileIndex + recordcount) == 0) { - filenavigator.upDIR(); - filenavigator.getFiles(0); - fileIndex = 0; - return; - } - - if (filenavigator.currentindex == 0 && filenavigator.folderdepth > 0) - recordcount = recordcount - 1; // account for return dir link in file index - - for (int16_t j = 1; j <= 4; j++) { // Clear filename BG Color and Frame - sendData(0xFFFFUL, FilenameNature + j * 16); // white - sendData(10, FilenameIcon1 + j); // clean - } - for (int16_t j = 0; j < 10; j++) // clear current filename - sendData(0, Choosefilename + j); - - if (filenavigator.getIndexisDir(fileIndex + recordcount)) { - filenavigator.changeDIR((char *)filenavigator.getIndexName(fileIndex + recordcount)); - filenavigator.getFiles(0); - fileIndex = 0; - return; - } - else { - sendData(filenavigator.getIndexName(fileIndex + recordcount), Choosefilename); - sendData(0x87F0UL, FilenameNature + recdat.data[0] * 16); // Change BG of selected line to Light Green - sendData(6, FilenameIcon1 + recdat.data[0]); // show frame - } - } - else if (recdat.addr == FilenamePlay) { - if (recdat.data[0] == 1 && isMediaInserted()) { // for sure - printFile(filenavigator.getIndexName(fileIndex + recordcount)); - - for (int16_t j = 0; j < 10; j++) // clean screen. - sendData(0, Printfilename + j); - - sendData(filenavigator.getIndexName(fileIndex + recordcount), Printfilename); - - delay_ms(4); - - sendData(ExchangePageBase + 53, ExchangepageAddr); - - TPShowStatus = InforShowStatus = true; - PrinterStatusKey[0] = 1; - PrinterStatusKey[1] = 3; - fileIndex = 0; - recordcount = 0; - } - else if (recdat.data[0] == 2) { // Page Down - if ((fileIndex + DISPLAY_FILES) < (filenavigator.maxFiles() + (filenavigator.folderdepth != 0))) { - fileIndex = fileIndex + DISPLAY_FILES; - // if(filenavigator.folderdepth!=0 && fileIndex!=0) //Shift to acknowledge Return DIR button on first page - // filenavigator.getFiles(fileIndex-1); - // else - filenavigator.getFiles(fileIndex); - // filenavigator.getFiles(filenavigator.currentindex+1); - } - } - else if (recdat.data[0] == 3) { // Page Up - if (fileIndex >= DISPLAY_FILES) { - fileIndex = fileIndex - DISPLAY_FILES; - // if(filenavigator.folderdepth!=0 && fileIndex!=0) //Shift to acknowledge Return DIR button on first page - // filenavigator.getFiles(filenavigator.currentindex-DISPLAY_FILES); - // else - filenavigator.getFiles(fileIndex); - } - } - else if (recdat.data[0] == 4) { // Page Up - injectCommands(F("M22\nM21")); - } - else if (recdat.data[0] == 0) { // return to main page - InforShowStatus = true; - TPShowStatus = false; - } - } - break; - - case VolumeDisplay: { - if (recdat.data[0] == 0) { - Settings.display_volume = 0; - Settings.display_sound = false; - } - else if (recdat.data[0] > 100) { - Settings.display_volume = 255; - Settings.display_sound = true; - } - else { - Settings.display_volume = (uint8_t)map(constrain(recdat.data[0], 0, 100), 0, 100, 0, 255); - Settings.display_sound = true; - } - setTouchScreenConfiguration(); - break; - } - - case DisplayBrightness: { - if (recdat.data[0] < 10) - Settings.screen_brightness = 10; - else if (recdat.data[0] > 100) - Settings.screen_brightness = 100; - else - Settings.screen_brightness = (uint8_t)recdat.data[0]; - setTouchScreenConfiguration(); - break; - } - - case DisplayStandbyBrightness: { - if (recdat.data[0] < 10) - Settings.standby_screen_brightness = 10; - else if (recdat.data[0] > 100) - Settings.standby_screen_brightness = 100; - else - Settings.standby_screen_brightness = (uint8_t)recdat.data[0]; - setTouchScreenConfiguration(); - break; - } - - case DisplayStandbySeconds: { - if (recdat.data[0] < 5) - Settings.standby_time_seconds = 5; - else if (recdat.data[0] > 100) - Settings.standby_time_seconds = 100; - else - Settings.standby_time_seconds = (uint8_t)recdat.data[0]; - setTouchScreenConfiguration(); - break; - } - - case AutolevelVal: { - uint8_t meshPoint = (recdat.addr - AutolevelVal) / 2, - yPnt = floor(meshPoint / GRID_MAX_POINTS_X), - xPnt = meshPoint - (yPnt * GRID_MAX_POINTS_X); - if (yPnt % 2 != 0) xPnt = (GRID_MAX_POINTS_X - 1) - xPnt; // zag row - - float meshVal = float(recdat.data[0] - (recdat.data[0] >= 32768 ? 65536 : 0)) / 1000; - - LIMIT(meshVal, Z_PROBE_LOW_POINT, Z_CLEARANCE_BETWEEN_PROBES); - xy_uint8_t point = { xPnt, yPnt }; - setMeshPoint(point, meshVal); - sendData(meshVal * 1000, recdat.addr); - break; - } - - default: break; - } - - memset(&recdat, 0, sizeof(recdat)); - recdat.head[0] = FHONE; - recdat.head[1] = FHTWO; -} - -void RTS::writeVariable(const uint16_t adr, const void * const values, uint8_t valueslen, const bool isstr/*=false*/, const char fillChar/*=' '*/) { - const char* myvalues = static_cast(values); - bool strend = !myvalues; - DWIN_SERIAL.write(FHONE); - DWIN_SERIAL.write(FHTWO); - DWIN_SERIAL.write(valueslen + 3); - DWIN_SERIAL.write(0x82); - DWIN_SERIAL.write(adr >> 8); - DWIN_SERIAL.write(adr & 0xFF); - while (valueslen--) { - char x; - if (!strend) x = *myvalues++; - if ((isstr && !x) || strend) { - strend = true; - x = fillChar; - } - DWIN_SERIAL.write(x); - } -} - -void RTS::setTouchScreenConfiguration() { - // Main configuration (System_Config) - LIMIT(Settings.screen_brightness, 10, 100); // Prevent a possible all-dark screen - LIMIT(Settings.standby_time_seconds, 10, 655); // Prevent a possible all-dark screen for standby, yet also don't go higher than the DWIN limitation - - uint8_t cfg_bits = (0x0 - | _BV(7) // 7: Enable Control ... TERN0(DWINOS_4, _BV(7)) - | _BV(5) // 5: load 22 touch file - | _BV(4) // 4: auto-upload should always be enabled - | (Settings.display_sound ? _BV(3) : 0) // 3: audio - | (Settings.display_standby ? _BV(2) : 0) // 2: backlight on standby - | (Settings.screen_rotation == 10 ? _BV(1) : 0) // 1 & 0: Inversion - #if LCD_SCREEN_ROTATE == 90 - | _BV(0) // Portrait Mode or 800x480 display has 0 point rotated 90deg from 480x272 display - #elif LCD_SCREEN_ROTATE - #error "Only 90° rotation is supported for the selected LCD." - #endif - ); - - const uint8_t config_set[] = { 0x5A, 0x00, TERN(DWINOS_4, 0x00, 0xFF), cfg_bits }; - writeVariable(0x80 /*System_Config*/, config_set, sizeof(config_set)); - - // Standby brightness (LED_Config) - uint16_t dwinStandbyTimeSeconds = 100 * Settings.standby_time_seconds; /* milliseconds, but divided by 10 (not 5 like the docs say) */ - const uint8_t brightness_set[] = { - Settings.screen_brightness /*% active*/, - Settings.standby_screen_brightness /*% standby*/, - static_cast(dwinStandbyTimeSeconds >> 8), - static_cast(dwinStandbyTimeSeconds) - }; - writeVariable(0x82 /*LED_Config*/, brightness_set, sizeof(brightness_set)); - - if (!Settings.display_sound) { - sendData(0, VolumeIcon); - sendData(9, SoundIcon); - } - else { - sendData((Settings.display_volume + 1) / 32 - 1, VolumeIcon); - sendData(8, SoundIcon); - } - sendData(Settings.display_volume, VolumeIcon - 2); - sendData(Settings.display_volume << 8, SoundAddr + 1); - sendData(map(constrain(Settings.display_volume, 0, 255), 0, 255, 0, 100), VolumeDisplay); - sendData(Settings.screen_brightness, DisplayBrightness); - sendData(Settings.standby_screen_brightness, DisplayStandbyBrightness); - sendData(Settings.standby_time_seconds, DisplayStandbySeconds); - if (Settings.display_standby) - sendData(3, DisplayStandbyEnableIndicator); - else - sendData(2, DisplayStandbyEnableIndicator); -} +#include "../ui_api.h" namespace ExtUI { - void onStartup() { rts.onStartup(); } +uint8_t dwin_settings_version = 1; - void onIdle() { rts.onIdle(); } +void onStartup() { rts.onStartup(); } - void onPrinterKilled(FSTR_P const error, FSTR_P const component) { - rts.sendData(ExchangePageBase + 88, ExchangepageAddr); - int16_t j = 0; - char outmsg[40]; - char killMsg[strlen_P(FTOP(error)) + strlen_P(FTOP(component)) + 3]; - sprintf_P(killMsg, PSTR(S_FMT ": " S_FMT), FTOP(error), FTOP(component)); - while (j < 4) outmsg[j++] = '*'; - while (const char c = killMsg[j - 4]) outmsg[j++] = c; - while (j < 40) outmsg[j++] = '*'; - rts.sendData(outmsg, MacVersion); - delay_ms(10); +void onIdle() { rts.onIdle(); } + +void onPrinterKilled(FSTR_P const error, FSTR_P const component) { + rts.sendData(ExchangePageBase + 88, ExchangepageAddr); + int16_t j = 0; + char outmsg[40]; + char killMsg[strlen_P(FTOP(error)) + strlen_P(FTOP(component)) + 3]; + sprintf_P(killMsg, PSTR(S_FMT ": " S_FMT), FTOP(error), FTOP(component)); + while (j < 4) outmsg[j++] = '*'; + while (const char c = killMsg[j - 4]) outmsg[j++] = c; + while (j < 40) outmsg[j++] = '*'; + rts.sendData(outmsg, MacVersion); + delay_ms(10); +} + +void onMediaInserted() { + filenavigator.reset(); + filenavigator.getFiles(0); + fileIndex = 0; + recordcount = 0; +} + +void onMediaError() { + filenavigator.reset(); + for (int16_t i = 0; i < MaxFileNumber; i++) + for (int16_t j = 0; j < 10; j++) rts.sendData(0, SDFILE_ADDR + i * 10 + j); + + for (int16_t j = 0; j < 10; j++) { + rts.sendData(0, Printfilename + j); // clean screen. + rts.sendData(0, Choosefilename + j); // clean filename } - - void onMediaInserted() { - filenavigator.reset(); - filenavigator.getFiles(0); - fileIndex = 0; - recordcount = 0; + for (int16_t j = 0; j < 8; j++) rts.sendData(0, FilenameCount + j); + for (int16_t j = 1; j <= MaxFileNumber; j++) { + rts.sendData(10, FilenameIcon + j); + rts.sendData(10, FilenameIcon1 + j); } +} - void onMediaError() { - filenavigator.reset(); - for (int16_t i = 0; i < MaxFileNumber; i++) - for (int16_t j = 0; j < 10; j++) rts.sendData(0, SDFILE_ADDR + i * 10 + j); +void onMediaRemoved() { + filenavigator.reset(); + for (int16_t i = 0; i < MaxFileNumber; i++) + for (int16_t j = 0; j < 10; j++) rts.sendData(0, SDFILE_ADDR + i * 10 + j); - for (int16_t j = 0; j < 10; j++) { - rts.sendData(0, Printfilename + j); // clean screen. - rts.sendData(0, Choosefilename + j); // clean filename + for (int16_t j = 0; j < 10; j++) { + rts.sendData(0, Printfilename + j); // clean screen. + rts.sendData(0, Choosefilename + j); // clean filename + } + for (int16_t j = 0; j < 8; j++) rts.sendData(0, FilenameCount + j); + for (int16_t j = 1; j <= MaxFileNumber; j++) { + rts.sendData(10, FilenameIcon + j); + rts.sendData(10, FilenameIcon1 + j); + } +} + +void onPlayTone(const uint16_t frequency, const uint16_t duration) { + rts.sendData(StartSoundSet, SoundAddr); +} + +void onPrintTimerStarted() { + if (waitway == 7) return; + printerStatusKey[1] = 3; + show_status = true; + delay_ms(1); + rts.sendData(ExchangePageBase + 53, ExchangepageAddr); +} + +void onPrintTimerPaused() { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); // Display Pause Screen + onStatusChanged(F("Pausing...")); +} + +void onPrintTimerStopped() { + if (waitway == 3) return; + + #if FAN_COUNT > 0 + for (uint8_t i = 0; i < FAN_COUNT; i++) setTargetFan_percent(FanOff, (fan_t)i); + #endif + + printerStatusKey[0] = 0; + show_status = true; + tpShowStatus = false; + rts.sendData(ExchangePageBase + 51, ExchangepageAddr); +} + +void onFilamentRunout() { + printerStatusKey[1] = 4; + tpShowStatus = false; + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); +} + +void onFilamentRunout(extruder_t extruder) { + printerStatusKey[1] = 4; + tpShowStatus = false; + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); +} + +void onUserConfirmRequired(const char *const msg) { + printerStatusKey[1] = 4; + tpShowStatus = false; + if (lastPauseMsgState == ExtUI::pauseModeStatus && msg == (const char*)GET_TEXT_F(MSG_FILAMENT_CHANGE_LOAD)) + return; + + switch (ExtUI::pauseModeStatus) { + case PAUSE_MESSAGE_WAITING: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Press Yes to Continue")); + break; } - for (int16_t j = 0; j < 8; j++) rts.sendData(0, FilenameCount + j); - for (int16_t j = 1; j <= MaxFileNumber; j++) { - rts.sendData(10, FilenameIcon + j); - rts.sendData(10, FilenameIcon1 + j); + case PAUSE_MESSAGE_INSERT: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Load Filament to Continue")); + break; } - } - - void onMediaRemoved() { - filenavigator.reset(); - for (int16_t i = 0; i < MaxFileNumber; i++) - for (int16_t j = 0; j < 10; j++) rts.sendData(0, SDFILE_ADDR + i * 10 + j); - - for (int16_t j = 0; j < 10; j++) { - rts.sendData(0, Printfilename + j); // clean screen. - rts.sendData(0, Choosefilename + j); // clean filename + case PAUSE_MESSAGE_HEAT: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Add Filament and Press Yes to Reheat")); + break; } - for (int16_t j = 0; j < 8; j++) rts.sendData(0, FilenameCount + j); - for (int16_t j = 1; j <= MaxFileNumber; j++) { - rts.sendData(10, FilenameIcon + j); - rts.sendData(10, FilenameIcon1 + j); - } - } - void onPlayTone(const uint16_t frequency, const uint16_t duration) { - rts.sendData(StartSoundSet, SoundAddr); - } - - void onPrintTimerStarted() { - if (waitway == 7) return; - PrinterStatusKey[1] = 3; - InforShowStatus = true; - delay_ms(1); - rts.sendData(ExchangePageBase + 53, ExchangepageAddr); - } - - void onPrintTimerPaused() { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); // Display Pause Screen - onStatusChanged(F("Pausing...")); - } - - void onPrintTimerStopped() { - if (waitway == 3) return; - - #if FAN_COUNT > 0 - for (uint8_t i = 0; i < FAN_COUNT; i++) setTargetFan_percent(FanOff, (fan_t)i); - #endif - - PrinterStatusKey[0] = 0; - InforShowStatus = true; - TPShowStatus = false; - rts.sendData(ExchangePageBase + 51, ExchangepageAddr); - } - - void onFilamentRunout() { - PrinterStatusKey[1] = 4; - TPShowStatus = false; - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - } - - void onFilamentRunout(extruder_t extruder) { - PrinterStatusKey[1] = 4; - TPShowStatus = false; - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - } - - void onUserConfirmRequired(const char *const msg) { - PrinterStatusKey[1] = 4; - TPShowStatus = false; - if (lastPauseMsgState == ExtUI::pauseModeStatus && msg == (const char*)GET_TEXT_F(MSG_FILAMENT_CHANGE_LOAD)) - return; - - switch (ExtUI::pauseModeStatus) { - case PAUSE_MESSAGE_WAITING: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Press Yes to Continue")); - break; - } - case PAUSE_MESSAGE_INSERT: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Load Filament to Continue")); - break; - } - case PAUSE_MESSAGE_HEAT: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Add Filament and Press Yes to Reheat")); - break; - } - - #if DISABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE) - case PAUSE_MESSAGE_PURGE: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - char newMsg[40] = "Yes to "; - strcat_P(newMsg, TERN1(FILAMENT_RUNOUT_SENSOR, !ExtUI::getFilamentRunoutState() && getFilamentRunoutEnabled()) ? PSTR("Continue") : PSTR("Disable ")); - strcat_P(newMsg, PSTR(" No to Purge")); - onStatusChanged(newMsg); - break; - } - #endif - - case PAUSE_MESSAGE_OPTION: { + #if DISABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE) + case PAUSE_MESSAGE_PURGE: { rts.sendData(ExchangePageBase + 78, ExchangepageAddr); char newMsg[40] = "Yes to "; strcat_P(newMsg, TERN1(FILAMENT_RUNOUT_SENSOR, !ExtUI::getFilamentRunoutState() && getFilamentRunoutEnabled()) ? PSTR("Continue") : PSTR("Disable ")); @@ -1873,221 +172,231 @@ namespace ExtUI { onStatusChanged(newMsg); break; } + #endif - case PAUSE_MESSAGE_PARKING: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Parking...")); - break; - } - case PAUSE_MESSAGE_CHANGING: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Beginning Filament Change")); - break; - } - case PAUSE_MESSAGE_UNLOAD: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Unloading...")); - break; - } - case PAUSE_MESSAGE_LOAD: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Reloading...")); - break; - } - case PAUSE_MESSAGE_RESUME: - #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE) - case PAUSE_MESSAGE_PURGE: { - rts.sendData(ExchangePageBase + 78, ExchangepageAddr); - onStatusChanged(F("Press Yes to Stop Purge")); - break; - } - #endif - - case PAUSE_MESSAGE_HEATING: { - rts.sendData(ExchangePageBase + 68, ExchangepageAddr); - onStatusChanged(F("Reheating")); - break; - } - - case PAUSE_MESSAGE_STATUS: - default: { - setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); - setUserConfirmed(); - break; - } + case PAUSE_MESSAGE_OPTION: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + char newMsg[40] = "Yes to "; + strcat_P(newMsg, TERN1(FILAMENT_RUNOUT_SENSOR, !ExtUI::getFilamentRunoutState() && getFilamentRunoutEnabled()) ? PSTR("Continue") : PSTR("Disable ")); + strcat_P(newMsg, PSTR(" No to Purge")); + onStatusChanged(newMsg); + break; } - lastPauseMsgState = ExtUI::pauseModeStatus; + + case PAUSE_MESSAGE_PARKING: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Parking...")); + break; + } + case PAUSE_MESSAGE_CHANGING: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Beginning Filament Change")); + break; + } + case PAUSE_MESSAGE_UNLOAD: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Unloading...")); + break; + } + case PAUSE_MESSAGE_LOAD: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Reloading...")); + break; + } + case PAUSE_MESSAGE_RESUME: + #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE) + case PAUSE_MESSAGE_PURGE: { + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); + onStatusChanged(F("Press Yes to Stop Purge")); + break; + } + #endif + + case PAUSE_MESSAGE_HEATING: { + rts.sendData(ExchangePageBase + 68, ExchangepageAddr); + onStatusChanged(F("Reheating")); + break; + } + + case PAUSE_MESSAGE_STATUS: + default: { + setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); + setUserConfirmed(); + break; + } + } + lastPauseMsgState = ExtUI::pauseModeStatus; +} + +void onStatusChanged(const char *const statMsg) { + for (int16_t j = 0; j < 20; j++) // Clear old message + rts.sendData(' ', StatusMessageString + j); + rts.sendData(statMsg, StatusMessageString); +} + +void onFactoryReset() { + dwin_settings.settings_size = sizeof(creality_dwin_settings_t); + dwin_settings.settings_version = dwin_settings_version; + dwin_settings.display_standby = true; + dwin_settings.display_sound = true; + dwin_settings.display_volume = 32; + dwin_settings.standby_brightness = 15; + dwin_settings.screen_brightness = 100; + dwin_settings.standby_time_seconds = 60; + dwin_settings.screen_rotation = 0; + onStartup(); + startprogress = 0; + show_status = true; +} + +void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state) {} + +void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval) { + if (waitway == 3) + if (isPositionKnown() && (getActualTemp_celsius(BED) >= (getTargetTemp_celsius(BED) - 1))) + rts.sendData(ExchangePageBase + 64, ExchangepageAddr); + #if HAS_MESH + uint8_t abl_probe_index = 0; + for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) + for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { + const bool zig = outer & 1; // != ((PR_OUTER_END) & 1); + const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; + if (point.x == xpos && outer == ypos) + rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + (abl_probe_index * 2)); + ++abl_probe_index; + } + #endif +} + +void onStoreSettings(char *buff) { + static_assert( + ExtUI::eeprom_data_size >= sizeof(creality_dwin_settings_t), + "Insufficient space in EEPROM for UI parameters" + ); + + // Write to buffer + memcpy(buff, &dwin_settings, sizeof(creality_dwin_settings_t)); +} + +void onLoadSettings(const char *buff) { + static_assert( + ExtUI::eeprom_data_size >= sizeof(creality_dwin_settings_t), + "Insufficient space in EEPROM for UI parameters" + ); + + creality_dwin_settings_t eepromSettings; + memcpy(&eepromSettings, buff, sizeof(creality_dwin_settings_t)); + + // If size is not the same, discard settings + if (eepromSettings.settings_size != sizeof(creality_dwin_settings_t)) { + onFactoryReset(); + return; } - void onStatusChanged(const char *const statMsg) { - for (int16_t j = 0; j < 20; j++) // Clear old message - rts.sendData(' ', StatusMessageString + j); - rts.sendData(statMsg, StatusMessageString); + if (eepromSettings.settings_version != dwin_settings_version) { + onFactoryReset(); + return; } - void onFactoryReset() { - Settings.settings_size = sizeof(creality_dwin_settings_t); - Settings.settings_version = dwin_settings_version; - Settings.display_standby = true; - Settings.display_sound = true; - Settings.display_volume = 32; - Settings.standby_screen_brightness = 15; - Settings.screen_brightness = 100; - Settings.standby_time_seconds = 60; - Settings.screen_rotation = 0; - onStartup(); - startprogress = 0; - InforShowStatus = true; - } + // Copy into final location + memcpy(&dwin_settings, &eepromSettings, sizeof(creality_dwin_settings_t)); - void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state) {} + rts.setTouchScreenConfiguration(); +} - void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval) { - if (waitway == 3) - if (isPositionKnown() && (getActualTemp_celsius(BED) >= (getTargetTemp_celsius(BED) - 1))) - rts.sendData(ExchangePageBase + 64, ExchangepageAddr); - #if HAS_MESH +void onSettingsStored(const bool success) { + // This is called after the entire EEPROM has been written, + // whether successful or not. +} + +void onSettingsLoaded(const bool success) { + #if HAS_MESH + if (ExtUI::getMeshValid()) { uint8_t abl_probe_index = 0; for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { - const bool zig = outer & 1; // != ((PR_OUTER_END) & 1); + const bool zig = outer & 1; const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; - if (point.x == xpos && outer == ypos) - rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + (abl_probe_index * 2)); + rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + (abl_probe_index * 2)); ++abl_probe_index; } - #endif - } - void onStoreSettings(char *buff) { - static_assert( - ExtUI::eeprom_data_size >= sizeof(creality_dwin_settings_t), - "Insufficient space in EEPROM for UI parameters" - ); - - // Write to buffer - memcpy(buff, &Settings, sizeof(creality_dwin_settings_t)); - } - - void onLoadSettings(const char *buff) { - static_assert( - ExtUI::eeprom_data_size >= sizeof(creality_dwin_settings_t), - "Insufficient space in EEPROM for UI parameters" - ); - - creality_dwin_settings_t eepromSettings; - memcpy(&eepromSettings, buff, sizeof(creality_dwin_settings_t)); - - // If size is not the same, discard settings - if (eepromSettings.settings_size != sizeof(creality_dwin_settings_t)) { - onFactoryReset(); - return; + rts.sendData(3, AutoLevelIcon); // 2=On, 3=Off + setLevelingActive(true); } - - if (eepromSettings.settings_version != dwin_settings_version) { - onFactoryReset(); - return; - } - - // Copy into final location - memcpy(&Settings, &eepromSettings, sizeof(creality_dwin_settings_t)); - - rts.setTouchScreenConfiguration(); - } - - void onSettingsStored(const bool success) { - // This is called after the entire EEPROM has been written, - // whether successful or not. - } - - void onSettingsLoaded(const bool success) { - #if HAS_MESH - if (ExtUI::getMeshValid()) { - uint8_t abl_probe_index = 0; - for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) - for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { - const bool zig = outer & 1; - const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; - rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + (abl_probe_index * 2)); - ++abl_probe_index; - } - - rts.sendData(3, AutoLevelIcon); // 2=On, 3=Off - setLevelingActive(true); - } - else { - rts.sendData(2, AutoLevelIcon); /*Off*/ - setLevelingActive(false); - } - #endif - - rts.sendData(getZOffset_mm() * 100, ProbeOffset_Z); - rts.setTouchScreenConfiguration(); - } - - #if ENABLED(POWER_LOSS_RECOVERY) - void onSetPowerLoss(const bool onoff) { - // Called when power-loss is enabled/disabled - } - void onPowerLoss() { - // Called when power-loss state is detected - } - void onPowerLossResume() { - startprogress = 254; - InforShowStatus = true; - TPShowStatus = false; - reEntryPrevent = false; - rts.sendData(ExchangePageBase + 76, ExchangepageAddr); + else { + rts.sendData(2, AutoLevelIcon); /*Off*/ + setLevelingActive(false); } #endif - #if HAS_PID_HEATING - void onPidTuning(const result_t rst) { - // Called for temperature PID tuning result - rts.sendData(pid_hotendAutoTemp, HotendPID_AutoTmp); - rts.sendData(pid_bedAutoTemp, BedPID_AutoTmp); - rts.sendData(uint16_t(getPID_Kp(E0)) * 10, HotendPID_P); - rts.sendData(uint16_t(getPID_Ki(E0)) * 10, HotendPID_I); - rts.sendData(uint16_t(getPID_Kd(E0)) * 10, HotendPID_D); - #if ENABLED(PIDTEMPBED) - rts.sendData(uint16_t(getBedPID_Kp()) * 10, BedPID_P); - rts.sendData(uint16_t(getBedPID_Ki()) * 10, BedPID_I); - rts.sendData(uint16_t(getBedPID_Kd()) * 10, BedPID_D); - #endif - onStatusChanged(F("PID Tune Finished")); + rts.sendData(getZOffset_mm() * 100, ProbeOffset_Z); + rts.setTouchScreenConfiguration(); +} + +#if ENABLED(POWER_LOSS_RECOVERY) + void onSetPowerLoss(const bool onoff) { + // Called when power-loss is enabled/disabled + } + void onPowerLoss() { + // Called when power-loss state is detected + } + void onPowerLossResume() { + startprogress = 254; + show_status = true; + tpShowStatus = false; + no_reentry = false; + rts.sendData(ExchangePageBase + 76, ExchangepageAddr); + } +#endif + +#if HAS_PID_HEATING + void onPidTuning(const result_t rst) { + // Called for temperature PID tuning result + rts.sendData(pid_hotendAutoTemp, HotendPID_AutoTmp); + rts.sendData(pid_bedAutoTemp, BedPID_AutoTmp); + rts.sendData(uint16_t(getPID_Kp(E0)) * 10, HotendPID_P); + rts.sendData(uint16_t(getPID_Ki(E0)) * 10, HotendPID_I); + rts.sendData(uint16_t(getPID_Kd(E0)) * 10, HotendPID_D); + #if ENABLED(PIDTEMPBED) + rts.sendData(uint16_t(getBedPID_Kp()) * 10, BedPID_P); + rts.sendData(uint16_t(getBedPID_Ki()) * 10, BedPID_I); + rts.sendData(uint16_t(getBedPID_Kd()) * 10, BedPID_D); + #endif + onStatusChanged(F("PID Tune Finished")); + } +#endif + +void onLevelingStart() {} + +void onLevelingDone() { + #if HAS_MESH + if (ExtUI::getMeshValid()) { + uint8_t abl_probe_index = 0; + for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) + for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { + const bool zig = outer & 1; + const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; + rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + abl_probe_index * 2); + ++abl_probe_index; + } + + rts.sendData(3, AutoLevelIcon); // 2=On, 3=Off + setLevelingActive(true); + } + else { + rts.sendData(2, AutoLevelIcon); /*Off*/ + setLevelingActive(false); } #endif +} - void onLevelingStart() {} - - void onLevelingDone() { - #if HAS_MESH - if (ExtUI::getMeshValid()) { - uint8_t abl_probe_index = 0; - for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) - for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { - const bool zig = outer & 1; - const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; - rts.sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + abl_probe_index * 2); - ++abl_probe_index; - } - - rts.sendData(3, AutoLevelIcon); // 2=On, 3=Off - setLevelingActive(true); - } - else { - rts.sendData(2, AutoLevelIcon); /*Off*/ - setLevelingActive(false); - } - #endif - } - - void onSteppersEnabled() {} - void onPrintDone() {} - void onHomingStart() {} - void onHomingDone() {} - void onSteppersDisabled() {} - void onPostprocessSettings() {} +void onSteppersEnabled() {} +void onPrintDone() {} +void onHomingStart() {} +void onHomingDone() {} +void onSteppersDisabled() {} +void onPostprocessSettings() {} } // namespace ExtUI diff --git a/Marlin/src/lcd/extui/ia_creality/ia_creality_rts.cpp b/Marlin/src/lcd/extui/ia_creality/ia_creality_rts.cpp new file mode 100644 index 00000000000..37ba539ff10 --- /dev/null +++ b/Marlin/src/lcd/extui/ia_creality/ia_creality_rts.cpp @@ -0,0 +1,1730 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* **************************************** + * lcd/extui/ia_creality/ia_creality_rts.cpp + * **************************************** + * Creality DWIN Resistive Touch Screen + * 10SPro, Max, CRX, and others + * Based original Creality release + * Written by Insanity Automation, sponsored by Tiny Machines 3D + * + * ***************************************/ + +#include "../../../inc/MarlinConfigPre.h" + +#if DGUS_LCD_UI_IA_CREALITY + +#include "ia_creality_rts.h" +#include "FileNavigator.h" +#include "../ui_api.h" + +using namespace ExtUI; + +#include // for memset + +// Singleton instance +RTS rts; + +// Static data +DB RTS::recdat, RTS::snddat; +uint8_t RTS::databuf[DATA_BUF_SIZE]; +rx_datagram_state_t RTS::rx_datagram_state = DGUS_IDLE; +uint8_t RTS::rx_datagram_len = 0; + +// Local data +uint16_t fileIndex = 0; +uint8_t recordcount = 0; +uint8_t waitway_lock = 0; +uint8_t startprogress = 0; + +char waitway = 0; +int16_t recnum = 0; +float changeMaterialBuf[2] = { 0 }; +char nozzleTempStatus[3] = { 0 }; +char printerStatusKey[2] = { 0 }; + +uint8_t axisPageNum = 0; // 0 for 10mm, 1 for 1mm, 2 for 0.1mm +bool show_status = true; +bool tpShowStatus = false; // true for only opening time and percentage, false for closing time and percentage. +bool autoHomeKey = false; +uint8_t autoHomeIconNum; +int16_t userConfValidation = 0; +uint8_t lastPauseMsgState = 0; + +creality_dwin_settings_t dwin_settings; + +bool no_reentry = false; +uint8_t reentryCount = 0; +uint16_t idleThrottling = 0; + +bool pause_resume_selected = false; + +#if HAS_PID_HEATING + uint16_t pid_hotendAutoTemp = 150; + uint16_t pid_bedAutoTemp = 70; +#endif + +#ifndef IA_CREALITY_BOOT_DELAY + #define IA_CREALITY_BOOT_DELAY 500 +#endif + +void RTS::onStartup() { + DWIN_SERIAL.begin(115200); + recdat.head[0] = snddat.head[0] = FHONE; + recdat.head[1] = snddat.head[1] = FHTWO; + ZERO(databuf); + + delay_ms(IA_CREALITY_BOOT_DELAY); // Delay to allow screen startup + setTouchScreenConfiguration(); + sendData(StartSoundSet, SoundAddr); + delay_ms(400); // Delay to allow screen to configure + + onStatusChanged(MACHINE_NAME " Ready"); + + sendData(100, FeedrateDisplay); + + /***************turn off motor*****************/ + sendData(11, FilenameIcon); + + /***************transmit temperature to screen*****************/ + sendData(0, NozzlePreheat); + sendData(0, BedPreheat); + sendData(getActualTemp_celsius(H0), NozzleTemp); + sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); + sendData(getActualTemp_celsius(BED), Bedtemp); + /***************transmit Fan speed to screen*****************/ + sendData(getActualFan_percent((fan_t)getActiveTool()), FanKeyIcon); + + /***************transmit Printer information to screen*****************/ + for (int16_t j = 0; j < 20; j++) // clean filename + sendData(0, MacVersion + j); + char sizebuf[20] = {0}; + sprintf(sizebuf, "%d X %d X %d", Y_BED_SIZE, X_BED_SIZE, Z_MAX_POS); + sendData(MACHINE_NAME, MacVersion); + sendData(SHORT_BUILD_VERSION, SoftVersion); + sendData(sizebuf, PrinterSize); + sendData(WEBSITE_URL, CorpWebsite); + + /**************************some info init*******************************/ + sendData(0, PrintscheduleIcon); + sendData(0, PrintscheduleIcon + 1); + + /************************clean screen*******************************/ + for (int16_t i = 0; i < MaxFileNumber; i++) + for (int16_t j = 0; j < 10; j++) sendData(0, SDFILE_ADDR + i * 10 + j); + + for (int16_t j = 0; j < 10; j++) { + sendData(0, Printfilename + j); // clean screen. + sendData(0, Choosefilename + j); // clean filename + } + for (int16_t j = 0; j < 8; j++) sendData(0, FilenameCount + j); + for (int16_t j = 1; j <= MaxFileNumber; j++) { + sendData(10, FilenameIcon + j); + sendData(10, FilenameIcon1 + j); + } +} + +void RTS::onIdle() { + while (rts.receiveData() > 0 && (rts.recdat.data[0] != 0 || rts.recdat.addr != 0)) + rts.handleData(); + + if (no_reentry && reentryCount < 120) { reentryCount++; return; } + reentryCount = 0; + + if (idleThrottling++ < 750) return; + + // Always send temperature data + rts.sendData(getActualTemp_celsius(getActiveTool()), NozzleTemp); + rts.sendData(getActualTemp_celsius(BED), Bedtemp); + rts.sendData(getTargetTemp_celsius(getActiveTool()), NozzlePreheat); + rts.sendData(getTargetTemp_celsius(BED), BedPreheat); + rts.sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); + rts.sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); + TERN_(HAS_MULTI_HOTEND, rts.sendData(uint8_t(getActiveTool() + 1), ActiveToolVP)); + + if (awaitingUserConfirm() && (lastPauseMsgState != ExtUI::pauseModeStatus || userConfValidation > 99)) { + switch (ExtUI::pauseModeStatus) { + case PAUSE_MESSAGE_PARKING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_PAUSE_PRINT_PARKING)); break; + case PAUSE_MESSAGE_CHANGING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_INIT)); break; + case PAUSE_MESSAGE_UNLOAD: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_UNLOAD)); break; + case PAUSE_MESSAGE_WAITING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_ADVANCED_PAUSE_WAITING)); break; + case PAUSE_MESSAGE_INSERT: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_INSERT)); break; + case PAUSE_MESSAGE_LOAD: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_LOAD)); break; + case PAUSE_MESSAGE_PURGE: ExtUI::onUserConfirmRequired(GET_TEXT_F(TERN(ADVANCED_PAUSE_CONTINUOUS_PURGE, MSG_FILAMENT_CHANGE_CONT_PURGE, MSG_FILAMENT_CHANGE_PURGE))); break; + case PAUSE_MESSAGE_RESUME: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_RESUME)); break; + case PAUSE_MESSAGE_HEAT: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_HEAT)); break; + case PAUSE_MESSAGE_HEATING: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_HEATING)); break; + case PAUSE_MESSAGE_OPTION: ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_OPTION_HEADER)); break; + case PAUSE_MESSAGE_STATUS: break; + default: onUserConfirmRequired(PSTR("Confirm Continue")); break; + } + userConfValidation = 0; + } + else if (pause_resume_selected && !awaitingUserConfirm()) { + rts.sendData(ExchangePageBase + 53, ExchangepageAddr); + pause_resume_selected = false; + userConfValidation = 0; + } + else if (awaitingUserConfirm()) { + if (pause_resume_selected) { + pause_resume_selected = false; + userConfValidation = 100; + } + else + userConfValidation++; + } + + no_reentry = true; + idleThrottling = 0; + if (waitway && !commandsInQueue()) + waitway_lock++; + else + waitway_lock = 0; + + if (waitway_lock > 100) { + waitway_lock = 0; + waitway = 0; // clear waitway if nothing is going on + } + + switch (waitway) { + case 1: + if (isPositionKnown()) { + show_status = true; + rts.sendData(ExchangePageBase + 54, ExchangepageAddr); + waitway = 0; + } + break; + + case 2: + if (isPositionKnown() && !commandsInQueue()) waitway = 0; + break; + + case 3: + //if(isPositionKnown() && (getActualTemp_celsius(BED) >= (getTargetTemp_celsius(BED)-1))) { + rts.sendData(ExchangePageBase + 64, ExchangepageAddr); + waitway = 7; + //return; + //} + break; + + case 4: + if (autoHomeKey && isPositionKnown() && !commandsInQueue()) { // Manual Move Home Done + //rts.sendData(ExchangePageBase + 71 + axisPageNum, ExchangepageAddr); + autoHomeKey = false; + waitway = 0; + } + break; + case 5: + if (isPositionKnown() && !commandsInQueue()) { + show_status = true; + waitway = 0; + rts.sendData(ExchangePageBase + 78, ExchangepageAddr); // exchange to 78 page + } + break; + case 6: + if (!commandsInQueue()) { + setAxisPosition_mm(BED_TRAMMING_HEIGHT, axis_t(Z)); + waitway = 0; + } + break; + case 7: + if (!commandsInQueue()) waitway = 0; + break; + } + + TERN_(HAS_MESH, rts.sendData(getLevelingActive() ? 3 : 2, AutoLevelIcon)); + TERN_(HAS_FILAMENT_SENSOR, rts.sendData(getFilamentRunoutEnabled() ? 3 : 2, RunoutToggle)); + TERN_(CASE_LIGHT_ENABLE, rts.sendData(getCaseLightState() ? 3 : 2, LedToggle)); + TERN_(POWER_LOSS_RECOVERY, rts.sendData(getPowerLossRecoveryEnabled() ? 3 : 2, PowerLossToggle)); + + if (startprogress == 0) { + startprogress += 25; + delay_ms(3000); // Delay to show bootscreen + } + else if (startprogress < 250) { + if (isMediaInserted()) // Re init media as it happens too early on STM32 boards often + onMediaInserted(); + else + injectCommands(F("M22\nM21")); + startprogress = 254; + show_status = true; + tpShowStatus = false; + rts.sendData(ExchangePageBase + 45, ExchangepageAddr); + no_reentry = false; + return; + } + if (startprogress <= 100) + rts.sendData(startprogress, StartIcon); + else + rts.sendData(startprogress - 100, StartIcon + 1); + + //rts.sendData((startprogress++) % 5, ExchFlmntIcon); + + if (isPrinting()) { + rts.sendData(getActualFan_percent((fan_t)getActiveTool()), FanKeyIcon); + rts.sendData(getProgress_seconds_elapsed() / 3600, Timehour); + rts.sendData((getProgress_seconds_elapsed() % 3600) / 60, Timemin); + if (getProgress_percent() > 0) { + const uint16_t perc = getProgress_percent() + 1; + if (perc <= 50) { + rts.sendData(uint16_t(perc) * 2, PrintscheduleIcon); + rts.sendData(0, PrintscheduleIcon + 1); + } + else { + rts.sendData(100, PrintscheduleIcon); + rts.sendData(uint16_t(perc) * 2 - 100, PrintscheduleIcon + 1); + } + } + else { + rts.sendData(0, PrintscheduleIcon); + rts.sendData(0, PrintscheduleIcon + 1); + } + rts.sendData(uint16_t(getProgress_percent()), Percentage); + } + else { // Not printing settings + rts.sendData(map(constrain(dwin_settings.display_volume, 0, 255), 0, 255, 0, 100), VolumeDisplay); + rts.sendData(dwin_settings.screen_brightness, DisplayBrightness); + rts.sendData(dwin_settings.standby_brightness, DisplayStandbyBrightness); + rts.sendData(dwin_settings.standby_time_seconds, DisplayStandbySeconds); + if (dwin_settings.display_standby) + rts.sendData(3, DisplayStandbyEnableIndicator); + else + rts.sendData(2, DisplayStandbyEnableIndicator); + + rts.sendData(getAxisSteps_per_mm(X) * 10, StepMM_X); + rts.sendData(getAxisSteps_per_mm(Y) * 10, StepMM_Y); + rts.sendData(getAxisSteps_per_mm(Z) * 10, StepMM_Z); + rts.sendData(getAxisSteps_per_mm(E0) * 10, StepMM_E); + + rts.sendData(getAxisMaxAcceleration_mm_s2(X) / 100, Accel_X); + rts.sendData(getAxisMaxAcceleration_mm_s2(Y) / 100, Accel_Y); + rts.sendData(getAxisMaxAcceleration_mm_s2(Z) / 10, Accel_Z); + rts.sendData(getAxisMaxAcceleration_mm_s2(E0), Accel_E); + + rts.sendData(getAxisMaxFeedrate_mm_s(X), Feed_X); + rts.sendData(getAxisMaxFeedrate_mm_s(Y), Feed_Y); + rts.sendData(getAxisMaxFeedrate_mm_s(Z), Feed_Z); + rts.sendData(getAxisMaxFeedrate_mm_s(E0), Feed_E); + + rts.sendData(getAxisMaxJerk_mm_s(X) * 100, Jerk_X); + rts.sendData(getAxisMaxJerk_mm_s(Y) * 100, Jerk_Y); + rts.sendData(getAxisMaxJerk_mm_s(Z) * 100, Jerk_Z); + rts.sendData(getAxisMaxJerk_mm_s(E0) * 100, Jerk_E); + + #if HAS_HOTEND_OFFSET + rts.sendData(getNozzleOffset_mm(X, E1) * 10, T2Offset_X); + rts.sendData(getNozzleOffset_mm(Y, E1) * 10, T2Offset_Y); + rts.sendData(getNozzleOffset_mm(Z, E1) * 10, T2Offset_Z); + rts.sendData(getAxisSteps_per_mm(E1) * 10, T2StepMM_E); + #endif + + #if HAS_BED_PROBE + rts.sendData(getProbeOffset_mm(X) * 100, ProbeOffset_X); + rts.sendData(getProbeOffset_mm(Y) * 100, ProbeOffset_Y); + #endif + + #if HAS_PID_HEATING + rts.sendData(pid_hotendAutoTemp, HotendPID_AutoTmp); + rts.sendData(pid_bedAutoTemp, BedPID_AutoTmp); + rts.sendData(getPID_Kp(E0) * 10, HotendPID_P); + rts.sendData(getPID_Ki(E0) * 10, HotendPID_I); + rts.sendData(getPID_Kd(E0) * 10, HotendPID_D); + #if ENABLED(PIDTEMPBED) + rts.sendData(getBedPID_Kp() * 10, BedPID_P); + rts.sendData(getBedPID_Ki() * 10, BedPID_I); + rts.sendData(getBedPID_Kd() * 10, BedPID_D); + #endif + #endif + } + + rts.sendData(getZOffset_mm() * 100, ProbeOffset_Z); + rts.sendData(uint16_t(getFlow_percent(E0)), Flowrate); + + if (nozzleTempStatus[0] || nozzleTempStatus[2]) { // statuse of loadfilament and unloadfinement when temperature is less than + uint16_t IconTemp = getActualTemp_celsius(getActiveTool()) * 100 / getTargetTemp_celsius(getActiveTool()); + NOMORE(IconTemp, 100U); + rts.sendData(IconTemp, HeatPercentIcon); + if (getActualTemp_celsius(getActiveTool()) > EXTRUDE_MINTEMP && nozzleTempStatus[0] != 0) { + nozzleTempStatus[0] = 0; + rts.sendData(10 * changeMaterialBuf[0], FilamentUnit1); + rts.sendData(10 * changeMaterialBuf[1], FilamentUnit2); + rts.sendData(ExchangePageBase + 65, ExchangepageAddr); + } + else if (getActualTemp_celsius(getActiveTool()) >= getTargetTemp_celsius(getActiveTool()) && nozzleTempStatus[2]) { + nozzleTempStatus[2] = 0; + tpShowStatus = true; + rts.sendData(4, ExchFlmntIcon); + rts.sendData(ExchangePageBase + 83, ExchangepageAddr); + } + else if (nozzleTempStatus[2]) { + //rts.sendData((startprogress++) % 5, ExchFlmntIcon); + } + } + + if (autoHomeKey) { + rts.sendData(autoHomeIconNum, AutoZeroIcon); + if (++autoHomeIconNum > 9) autoHomeIconNum = 0; + } + + if (isMediaInserted()) { + const uint16_t currPage = fileIndex == 0 ? 1 : CEIL(float(fileIndex) / float(DISPLAY_FILES)) + 1, + maxPageAdd = filenavigator.folderdepth ? 1 : 0, + maxPages = CEIL(float(filenavigator.maxFiles() + maxPageAdd) / float(DISPLAY_FILES) ); + + rts.sendData(currPage, FilesCurentPage); + rts.sendData(maxPages, FilesMaxPage); + } + else { + rts.sendData(0, FilesCurentPage); + rts.sendData(0, FilesMaxPage); + } + + if (rts.recdat.addr != DisplayZaxis && rts.recdat.addr != DisplayYaxis && rts.recdat.addr != DisplayZaxis) { + rts.sendData(10 * getAxisPosition_mm(axis_t(X)), DisplayXaxis); + rts.sendData(10 * getAxisPosition_mm(axis_t(Y)), DisplayYaxis); + rts.sendData(10 * getAxisPosition_mm(axis_t(Z)), DisplayZaxis); + } + no_reentry = false; +} + +RTS::RTS() { + recdat.head[0] = snddat.head[0] = FHONE; + recdat.head[1] = snddat.head[1] = FHTWO; + ZERO(databuf); +} + +int16_t RTS::receiveData() { + uint8_t receivedbyte; + while (DWIN_SERIAL.available()) + switch (rx_datagram_state) { + + case DGUS_IDLE: // Waiting for the first header byte + receivedbyte = DWIN_SERIAL.read(); + if (FHONE == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN; + break; + + case DGUS_HEADER1_SEEN: // Waiting for the second header byte + receivedbyte = DWIN_SERIAL.read(); + rx_datagram_state = (FHTWO == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE; + break; + + case DGUS_HEADER2_SEEN: // Waiting for the length byte + rx_datagram_len = DWIN_SERIAL.read(); + //DEBUGLCDCOMM_ECHOPGM(" (", rx_datagram_len, ") "); + + // Telegram min len is 3 (command and one word of payload) + rx_datagram_state = WITHIN(rx_datagram_len, 3, DGUS_RX_BUFFER_SIZE) ? DGUS_WAIT_TELEGRAM : DGUS_IDLE; + break; + + case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive. + if (DWIN_SERIAL.available() < rx_datagram_len) return -1; + + uint8_t command = DWIN_SERIAL.read(); + + //DEBUGLCDCOMM_ECHOPGM("# ", command); + + uint8_t readlen = rx_datagram_len - 1; // command is part of len. + uint8_t tmp[rx_datagram_len - 1]; + uint8_t *ptmp = tmp; + while (readlen--) { + receivedbyte = DWIN_SERIAL.read(); + //DEBUGLCDCOMM_ECHOPGM(" ", receivedbyte); + *ptmp++ = receivedbyte; + } + //DEBUGLCDCOMM_ECHOPGM(" # "); + // mostly we'll get this: 5A A5 03 82 4F 4B -- ACK on 0x82, so discard it. + if (command == VarAddr_W && 'O' == tmp[0] && 'K' == tmp[1]) { + rx_datagram_state = DGUS_IDLE; + break; + } + + /* AutoUpload, (and answer to) Command 0x83 : + | tmp[0 1 2 3 4 ... ] + | Example 5A A5 06 83 20 01 01 78 01 …… + | / / | | \ / | \ \ + | Header | | | | \_____\_ DATA (Words!) + | DatagramLen / VPAdr | + | Command DataLen (in Words) */ + if (command == VarAddr_R) { + const uint16_t vp = tmp[0] << 8 | tmp[1]; + + const uint8_t dlen = tmp[2] << 1; // Convert to Bytes. (Display works with words) + recdat.addr = vp; + recdat.len = tmp[2]; + for (uint16_t i = 0; i < dlen; i += 2) { + recdat.data[i / 2] = tmp[3 + i]; + recdat.data[i / 2] = (recdat.data[i / 2] << 8 ) | tmp[4 + i]; + } + + rx_datagram_state = DGUS_IDLE; + return 2; + break; + } + + // discard anything else + rx_datagram_state = DGUS_IDLE; + } + return -1; +} + +void RTS::sendData() { + if (snddat.head[0] == FHONE && snddat.head[1] == FHTWO && snddat.len >= 3) { + databuf[0] = snddat.head[0]; + databuf[1] = snddat.head[1]; + databuf[2] = snddat.len; + databuf[3] = snddat.command; + if (snddat.command == 0x80) { // to write data to the register + databuf[4] = snddat.addr; + for (int16_t i = 0; i < (snddat.len - 2); i++) databuf[5 + i] = snddat.data[i]; + } + else if (snddat.len == 3 && (snddat.command == 0x81)) { // to read data from the register + databuf[4] = snddat.addr; + databuf[5] = snddat.bytelen; + } + else if (snddat.command == 0x82) { // to write data to the variate + databuf[4] = snddat.addr >> 8; + databuf[5] = snddat.addr & 0xFF; + for (int16_t i = 0; i < (snddat.len - 3); i += 2) { + databuf[6 + i] = snddat.data[i / 2] >> 8; + databuf[7 + i] = snddat.data[i / 2] & 0xFF; + } + } + else if (snddat.len == 4 && (snddat.command == 0x83)) { // to read data from the variate + databuf[4] = snddat.addr >> 8; + databuf[5] = snddat.addr & 0xFF; + databuf[6] = snddat.bytelen; + } + for (int16_t i = 0; i < (snddat.len + 3); i++) { + DWIN_SERIAL.write(databuf[i]); + delay_us(1); + } + + memset(&snddat, 0, sizeof(snddat)); + ZERO(databuf); + snddat.head[0] = FHONE; + snddat.head[1] = FHTWO; + } +} + +void RTS::sendData(const String &s, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { + if (s.length() < 1) return; + sendData(s.c_str(), addr, cmd); +} + +void RTS::sendData(const char *str, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { + int16_t len = strlen(str); + constexpr int16_t maxlen = DATA_BUF_SIZE - 6; + if (len > 0) { + if (len > maxlen) len = maxlen; + databuf[0] = FHONE; + databuf[1] = FHTWO; + databuf[2] = 3 + len; + databuf[3] = cmd; + databuf[4] = addr >> 8; + databuf[5] = addr & 0x00FF; + for (int16_t i = 0; i < len; i++) databuf[6 + i] = str[i]; + + for (int16_t i = 0; i < (len + 6); i++) { + DWIN_SERIAL.write(databuf[i]); + delay_us(1); + } + ZERO(databuf); + } +} + +void RTS::sendData(const char c, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { + snddat.command = cmd; + snddat.addr = addr; + snddat.data[0] = uint32_t(uint16_t(c) << 8); + snddat.len = 5; + sendData(); +} + +void RTS::sendData(const_float_t f, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { + int16_t n = f; + if (cmd == VarAddr_W) { + snddat.data[0] = n; + snddat.len = 5; + } + else if (cmd == RegAddr_W) { + snddat.data[0] = n; + snddat.len = 3; + } + else if (cmd == VarAddr_R) { + snddat.bytelen = n; + snddat.len = 4; + } + snddat.command = cmd; + snddat.addr = addr; + sendData(); +} + +void RTS::sendData(const int n, const uint32_t addr, const uint8_t cmd/*=VarAddr_W*/) { + if (cmd == VarAddr_W) { + if ((unsigned int)n > 0xFFFF) { + snddat.data[0] = n >> 16; + snddat.data[1] = n & 0xFFFF; + snddat.len = 7; + } + else { + snddat.data[0] = n; + snddat.len = 5; + } + } + else if (cmd == RegAddr_W) { + snddat.data[0] = n; + snddat.len = 3; + } + else if (cmd == VarAddr_R) { + snddat.bytelen = n; + snddat.len = 4; + } + snddat.command = cmd; + snddat.addr = addr; + sendData(); +} + +void RTS::sendData(const unsigned long n, uint32_t addr, uint8_t cmd/*=VarAddr_W*/) { + if (cmd == VarAddr_W) { + if (n > 0xFFFF) { + snddat.data[0] = n >> 16; + snddat.data[1] = n & 0xFFFF; + //snddat.data[0] = n >> 24; + //snddat.data[1] = n >> 16; + //snddat.data[2] = n >> 8; + //snddat.data[3] = n; + snddat.len = 7; + } + else { + snddat.data[0] = n; + snddat.len = 5; + } + } + else if (cmd == VarAddr_R) { + snddat.bytelen = n; + snddat.len = 4; + } + snddat.command = cmd; + snddat.addr = addr; + sendData(); +} + +void RTS::handleData() { + int16_t Checkkey = -1; + if (waitway > 0) { // for waiting + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; + return; + } + for (int16_t i = 0; Addrbuf[i] != 0; i++) + if (recdat.addr == Addrbuf[i]) { + if (Addrbuf[i] == NzBdSet || Addrbuf[i] == NozzlePreheat || Addrbuf[i] == BedPreheat || Addrbuf[i] == Flowrate) + Checkkey = ManualSetTemp; + else if (WITHIN(Addrbuf[i], Stopprint, Resumeprint)) + Checkkey = PrintChoice; + else if (WITHIN(Addrbuf[i], AutoZero, DisplayZaxis)) + Checkkey = XYZEaxis; + else if (WITHIN(Addrbuf[i], FilamentUnit1, FilamentUnit2)) + Checkkey = Filament; + else + Checkkey = i; + break; + } + + switch (recdat.addr) { + case Flowrate: + case StepMM_X ... StepMM_E: + case ProbeOffset_X ... ProbeOffset_Y: + case HotendPID_AutoTmp ... BedPID_AutoTmp: + case HotendPID_P ... HotendPID_D: + case BedPID_P ... BedPID_D: + case T2Offset_X ... T2StepMM_E: + case Accel_X ... Accel_E: + case Feed_X ... Feed_E: + case Jerk_X ... Jerk_E: + case RunoutToggle: + case PowerLossToggle: + case FanKeyIcon: + case LedToggle: + case e2Preheat: Checkkey = ManualSetTemp; break; + case ProbeOffset_Z: Checkkey = Zoffset_Value; break; + case VolumeDisplay: Checkkey = VolumeDisplay; break; + case DisplayBrightness: Checkkey = DisplayBrightness; break; + case DisplayStandbyBrightness: Checkkey = DisplayStandbyBrightness; break; + case DisplayStandbySeconds: Checkkey = DisplayStandbySeconds; break; + default: + if (WITHIN(recdat.addr, AutolevelVal, 4400)) // (int16_t(AutolevelVal) + GRID_MAX_POINTS * 2) = 4400 with 5x5 mesh + Checkkey = AutolevelVal; + else if (WITHIN(recdat.addr, SDFILE_ADDR, SDFILE_ADDR + 10 * (FileNum + 1))) + Checkkey = Filename; + break; + } + + if (Checkkey < 0) { + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; + return; + } + + constexpr float lfrb[4] = BED_TRAMMING_INSET_LFRB; + + switch (Checkkey) { + case Printfile: + if (recdat.data[0] == 1) { // card + show_status = false; + filenavigator.getFiles(0); + fileIndex = 0; + recordcount = 0; + sendData(ExchangePageBase + 46, ExchangepageAddr); + } + else if (recdat.data[0] == 2) { // return after printing result. + show_status = true; + tpShowStatus = false; + stopPrint(); + injectCommands(F("M84")); + sendData(11, FilenameIcon); + sendData(0, PrintscheduleIcon); + sendData(0, PrintscheduleIcon + 1); + sendData(0, Percentage); + delay_ms(2); + sendData(0, Timehour); + sendData(0, Timemin); + + sendData(ExchangePageBase + 45, ExchangepageAddr); // exchange to 45 page + } + else if (recdat.data[0] == 3) { // Temperature control + show_status = true; + tpShowStatus = false; + if (getTargetFan_percent((fan_t)getActiveTool()) == 0) + sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans off + else + sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on + } + else if (recdat.data[0] == 4) { // Settings + show_status = false; + } + break; + + case Adjust: + if (recdat.data[0] == 1) { + show_status = false; + } + else if (recdat.data[0] == 2) { + show_status = true; + if (printerStatusKey[1] == 3) // during heating + sendData(ExchangePageBase + 53, ExchangepageAddr); + else if (printerStatusKey[1] == 4) + sendData(ExchangePageBase + 54, ExchangepageAddr); + else + sendData(ExchangePageBase + 53, ExchangepageAddr); + } + else if (recdat.data[0] == 3) + setTargetFan_percent(getTargetFan_percent((fan_t)getActiveTool()) != 0 ? 100 : 0, FAN0); + + break; + + case Feedrate: + setFeedrate_percent(recdat.data[0]); + break; + + case PrintChoice: + if (recdat.addr == Stopprint) { + if (recdat.data[0] == 240) { // no + sendData(ExchangePageBase + 53, ExchangepageAddr); + } + else { + sendData(ExchangePageBase + 45, ExchangepageAddr); + sendData(0, Timehour); + sendData(0, Timemin); + stopPrint(); + } + } + else if (recdat.addr == Pauseprint) { + if (recdat.data[0] != 0xF1) + break; + + sendData(ExchangePageBase + 54, ExchangepageAddr); + pausePrint(); + } + else if (recdat.addr == Resumeprint && recdat.data[0] == 1) { + resumePrint(); + + printerStatusKey[1] = 0; + show_status = true; + + sendData(ExchangePageBase + 53, ExchangepageAddr); + } + if (recdat.addr == Resumeprint && recdat.data[0] == 2) { // warming + resumePrint(); + nozzleTempStatus[2] = 1; + printerStatusKey[1] = 0; + show_status = true; + sendData(ExchangePageBase + 82, ExchangepageAddr); + } + break; + + case Zoffset: + float tmp_zprobe_offset; + if (recdat.data[0] >= 32768) + tmp_zprobe_offset = (float(recdat.data[0]) - 65536) / 100; + else + tmp_zprobe_offset = float(recdat.data[0]) / 100; + if (WITHIN((tmp_zprobe_offset), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { + int16_t tmpSteps = mmToWholeSteps(getZOffset_mm() - tmp_zprobe_offset, axis_t(Z)); + if (tmpSteps == 0) tmpSteps = getZOffset_mm() < tmp_zprobe_offset ? 1 : -1; + smartAdjustAxis_steps(-tmpSteps, axis_t(Z), false); + char zOffs[20], tmp1[11]; + sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); + onStatusChanged(zOffs); + } + else { + onStatusChanged(F("Requested Offset Beyond Limits")); + } + + sendData(getZOffset_mm() * 100, ProbeOffset_Z); + break; + + case TempControl: + if (recdat.data[0] == 0) { + show_status = true; + tpShowStatus = false; + } + else if (recdat.data[0] == 1) { + if (getTargetFan_percent((fan_t)getActiveTool()) == 0) + sendData(ExchangePageBase + 60, ExchangepageAddr); // exchange to 60 page, the fans off + else + sendData(ExchangePageBase + 59, ExchangepageAddr); // exchange to 59 page, the fans on + } + else if (recdat.data[0] == 2) { + show_status = true; + } + else if (recdat.data[0] == 3) { + if (getTargetFan_percent((fan_t)getActiveTool()) == 0) { // turn on the fan + setTargetFan_percent(100, FAN0); + sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on + } + else { // turn off the fan + setTargetFan_percent(0, FAN0); + sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans on + } + } + else if (recdat.data[0] == 5) { // PLA mode + setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, getActiveTool()); + setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED); + sendData(PREHEAT_1_TEMP_HOTEND, NozzlePreheat); + sendData(PREHEAT_1_TEMP_BED, BedPreheat); + } + else if (recdat.data[0] == 6) { // ABS mode + setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, getActiveTool()); + setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED); + sendData(PREHEAT_2_TEMP_HOTEND, NozzlePreheat); + sendData(PREHEAT_2_TEMP_BED, BedPreheat); + } + else if (recdat.data[0] == 0xF1) { + //show_status = true; + #if FAN_COUNT > 0 + for (uint8_t i = 0; i < FAN_COUNT; i++) setTargetFan_percent(0, (fan_t)i); + #endif + setTargetTemp_celsius(0.0, H0); + TERN_(HAS_MULTI_HOTEND, setTargetTemp_celsius(0.0, H1)); + setTargetTemp_celsius(0.0, BED); + sendData(0, NozzlePreheat); delay_ms(1); + sendData(0, BedPreheat); delay_ms(1); + sendData(ExchangePageBase + 57, ExchangepageAddr); + printerStatusKey[1] = 2; + } + break; + + case ManualSetTemp: + if (recdat.addr == NzBdSet) { + if (recdat.data[0] == 0) { + if (getTargetFan_percent((fan_t)getActiveTool()) == 0) + sendData(ExchangePageBase + 58, ExchangepageAddr); // exchange to 58 page, the fans off + else + sendData(ExchangePageBase + 57, ExchangepageAddr); // exchange to 57 page, the fans on + } + else if (recdat.data[0] == 1) { + setTargetTemp_celsius(0.0, getActiveTool()); + sendData(0, NozzlePreheat); + } + else if (recdat.data[0] == 2) { + setTargetTemp_celsius(0.0, BED); + sendData(0, BedPreheat); + } + } + else if (recdat.addr == NozzlePreheat) { + setTargetTemp_celsius(float(recdat.data[0]), H0); + } + #if HAS_MULTI_HOTEND + else if (recdat.addr == e2Preheat) { + setTargetTemp_celsius(float(recdat.data[0]), H1); + } + #endif + else if (recdat.addr == BedPreheat) { + setTargetTemp_celsius(float(recdat.data[0]), BED); + } + else if (recdat.addr == Flowrate) { + setFlow_percent(int16_t(recdat.data[0]), getActiveTool()); + } + + #if HAS_PID_HEATING + else if (recdat.addr == HotendPID_AutoTmp) { + pid_hotendAutoTemp = uint16_t(recdat.data[0]); + } + else if (recdat.addr == BedPID_AutoTmp) { + pid_bedAutoTemp = uint16_t(recdat.data[0]); + } + #endif + + else if (recdat.addr == Accel_X) { + setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 100, X); + } + else if (recdat.addr == Accel_Y) { + setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 100, Y); + } + else if (recdat.addr == Accel_Z) { + setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]) * 10, Z); + } + else if (recdat.addr == Accel_E) { + setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]), E0); + setAxisMaxAcceleration_mm_s2(uint16_t(recdat.data[0]), E1); + } + + else if (recdat.addr == Feed_X) { + setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), X); + } + else if (recdat.addr == Feed_Y) { + setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), Y); + } + else if (recdat.addr == Feed_Z) { + setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), Z); + } + else if (recdat.addr == Feed_E) { + setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), E0); + setAxisMaxFeedrate_mm_s(uint16_t(recdat.data[0]), E1); + } + else if (recdat.addr == FanKeyIcon) { + setTargetFan_percent(uint16_t(recdat.data[0]), (fan_t)getActiveTool()); + } + else { + float tmp_float_handling; + if (recdat.data[0] >= 32768) + tmp_float_handling = (float(recdat.data[0]) - 65536) / 100; + else + tmp_float_handling = float(recdat.data[0]) / 100; + if (recdat.addr == StepMM_X) { + setAxisSteps_per_mm(tmp_float_handling * 10, X); + } + else if (recdat.addr == StepMM_Y) { + setAxisSteps_per_mm(tmp_float_handling * 10, Y); + } + else if (recdat.addr == StepMM_Z) { + setAxisSteps_per_mm(tmp_float_handling * 10, Z); + } + else if (recdat.addr == StepMM_E) { + setAxisSteps_per_mm(tmp_float_handling * 10, E0); + #if DISABLED(DUAL_X_CARRIAGE) + setAxisSteps_per_mm(tmp_float_handling * 10, E1); + #endif + } + #if ENABLED(DUAL_X_CARRIAGE) + else if (recdat.addr == T2StepMM_E) { + setAxisSteps_per_mm(tmp_float_handling * 10, E1); + } + else if (recdat.addr == T2Offset_X) { + setNozzleOffset_mm(tmp_float_handling * 10, X, E1); + } + else if (recdat.addr == T2Offset_Y) { + setNozzleOffset_mm(tmp_float_handling * 10, Y, E1); + } + else if (recdat.addr == T2Offset_Z) { + setNozzleOffset_mm(tmp_float_handling * 10, Z, E1); + } + #endif + #if HAS_BED_PROBE + else if (recdat.addr == ProbeOffset_X) { + setProbeOffset_mm(tmp_float_handling, X); + } + else if (recdat.addr == ProbeOffset_Y) { + setProbeOffset_mm(tmp_float_handling, Y); + } + else if (recdat.addr == ProbeOffset_Z) { + setProbeOffset_mm(tmp_float_handling, Z); + } + #endif + + #if ENABLED(CLASSIC_JERK) + else if (recdat.addr == Jerk_X) { + setAxisMaxJerk_mm_s(tmp_float_handling, X); + } + else if (recdat.addr == Jerk_Y) { + setAxisMaxJerk_mm_s(tmp_float_handling, Y); + } + else if (recdat.addr == Jerk_Z) { + setAxisMaxJerk_mm_s(tmp_float_handling, Z); + } + else if (recdat.addr == Jerk_E) { + setAxisMaxJerk_mm_s(tmp_float_handling, E0); + setAxisMaxJerk_mm_s(tmp_float_handling, E1); + } + #endif + + #if HAS_FILAMENT_SENSOR + else if (recdat.addr == RunoutToggle) { + setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); + } + #endif + + #if ENABLED(POWER_LOSS_RECOVERY) + else if (recdat.addr == PowerLossToggle) { + setPowerLossRecoveryEnabled(!getPowerLossRecoveryEnabled()); + } + #endif + + #if ENABLED(CASE_LIGHT_ENABLE) + else if (recdat.addr == LedToggle) { + setCaseLightState(!getCaseLightState()); + } + #endif + + #if HAS_PID_HEATING + else if (recdat.addr == HotendPID_P) { + setPID(tmp_float_handling * 10, getPID_Ki(getActiveTool()), getPID_Kd(getActiveTool()), getActiveTool()); + } + else if (recdat.addr == HotendPID_I) { + setPID(getPID_Kp(getActiveTool()), tmp_float_handling * 10, getPID_Kd(getActiveTool()), getActiveTool()); + } + else if (recdat.addr == HotendPID_D) { + setPID(getPID_Kp(getActiveTool()), getPID_Ki(getActiveTool()), tmp_float_handling * 10, getActiveTool()); + } + #if ENABLED(PIDTEMPBED) + else if (recdat.addr == BedPID_P) { + setBedPID(tmp_float_handling * 10, getBedPID_Ki(), getBedPID_Kd()); + } + else if (recdat.addr == BedPID_I) { + setBedPID(getBedPID_Kp(), tmp_float_handling * 10, getBedPID_Kd()); + } + else if (recdat.addr == BedPID_D) { + setBedPID(getBedPID_Kp(), getBedPID_Ki(), tmp_float_handling * 10); + } + #endif + #endif // HAS_PID_HEATING + } + break; + + case Setting: + if (recdat.data[0] == 0) { // return to main page + show_status = true; + tpShowStatus = false; + } + else if (recdat.data[0] == 1) { // Bed Autoleveling + #if HAS_MESH + sendData(getLevelingActive() ? 3 : 2, AutoLevelIcon); + + if (ExtUI::getMeshValid()) { + uint8_t abl_probe_index = 0; + for (uint8_t outer = 0; outer < GRID_MAX_POINTS_Y; outer++) + for (uint8_t inner = 0; inner < GRID_MAX_POINTS_X; inner++) { + const bool zig = outer & 1; + const xy_uint8_t point = { uint8_t(zig ? (GRID_MAX_POINTS_X - 1) - inner : inner), outer }; + sendData(ExtUI::getMeshPoint(point) * 1000, AutolevelVal + abl_probe_index * 2); + ++abl_probe_index; + } + } + #endif + sendData(10, FilenameIcon); // Motor Icon + injectCommands(isPositionKnown() ? F("G1F1000Z0.0") : F("G28\nG1F1000Z0.0")); + waitway = 2; + sendData(ExchangePageBase + 64, ExchangepageAddr); + } + else if (recdat.data[0] == 2) { // Exchange filament + show_status = true; + tpShowStatus = false; + ZERO(changeMaterialBuf); + changeMaterialBuf[1] = changeMaterialBuf[0] = 10; + sendData(10 * changeMaterialBuf[0], FilamentUnit1); // It's changeMaterialBuf for show, instead of current_position.e in them. + sendData(10 * changeMaterialBuf[1], FilamentUnit2); + sendData(getActualTemp_celsius(H0), NozzleTemp); + sendData(getTargetTemp_celsius(H0), NozzlePreheat); + sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); + sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); + delay_ms(2); + sendData(ExchangePageBase + 65, ExchangepageAddr); + } + else if (recdat.data[0] == 3) { // Move + axisPageNum = 0; + sendData(ExchangePageBase + 71, ExchangepageAddr); + } + else if (recdat.data[0] == 4) { // Language + // Just loads language screen, now used for tools + } + else if (recdat.data[0] == 5) { // Printer Information + sendData(WEBSITE_URL, CorpWebsite); + } + else if (recdat.data[0] == 6) { // Diabalestepper + injectCommands(F("M84")); + sendData(11, FilenameIcon); + } + break; + + case ReturnBack: + if (recdat.data[0] == 1) { // return to the tool page + show_status = false; + sendData(ExchangePageBase + 63, ExchangepageAddr); + } + if (recdat.data[0] == 2) // return to the Level mode page + sendData(ExchangePageBase + 64, ExchangepageAddr); + break; + + case Bedlevel: + switch (recdat.data[0]) { + case 1: { // Z-axis to home + // Disallow Z homing if X or Y are unknown + injectCommands(isAxisPositionKnown(axis_t(X)) && isAxisPositionKnown(axis_t(Y)) ? F("G28Z\nG1F1500Z0.0") : F("G28\nG1F1500Z0.0")); + sendData(getZOffset_mm() * 100, ProbeOffset_Z); + break; + } + case 2: { // Z-axis to Up + if (WITHIN((getZOffset_mm() + 0.1), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { + smartAdjustAxis_steps(getAxisSteps_per_mm(Z) / 10, axis_t(Z), false); + //setZOffset_mm(getZOffset_mm() + 0.1); + sendData(getZOffset_mm() * 100, ProbeOffset_Z); + char zOffs[20], tmp1[11]; + sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); + onStatusChanged(zOffs); + } + break; + } + case 3: { // Z-axis to Down + if (WITHIN((getZOffset_mm() - 0.1), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { + smartAdjustAxis_steps(-getAxisSteps_per_mm(Z) / 10, axis_t(Z), false); + //babystepAxis_steps(int16_t(-getAxisSteps_per_mm(Z)) / 10, axis_t(Z)); + //setZOffset_mm(getZOffset_mm() - 0.1); + sendData(getZOffset_mm() * 100, ProbeOffset_Z); + char zOffs[20], tmp1[11]; + sprintf_P(zOffs, PSTR("Z Offset : %s"), dtostrf(getZOffset_mm(), 1, 3, tmp1)); + onStatusChanged(zOffs); + } + break; + } + case 4: { // Assistant Level + TERN_(HAS_MESH, setLevelingActive(false)); + injectCommands(isPositionKnown() ? F("G1 F1000 Z0.0") : F("G28\nG1 F1000 Z0.0")); + waitway = 2; + sendData(ExchangePageBase + 84, ExchangepageAddr); + break; + } + case 5: { // AutoLevel "Measuring" Button + #if ENABLED(MESH_BED_LEVELING) + sendData(ExchangePageBase + 93, ExchangepageAddr); + #else + waitway = 3; // only for prohibiting to receive massage + sendData(3, AutolevelIcon); + uint8_t abl_probe_index = 0; + while (abl_probe_index < 25) { + sendData(0, AutolevelVal + abl_probe_index * 2); + ++abl_probe_index; + } + sendData(ExchangePageBase + 64, ExchangepageAddr); + injectCommands(F(MEASURING_GCODE)); + #endif + break; + } + + case 6: { // Assitant Level , Centre 1 + setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); + setAxisPosition_mm(X_CENTER, axis_t(X)); + setAxisPosition_mm(Y_CENTER, axis_t(Y)); + waitway = 6; + break; + } + case 7: { // Assitant Level , Front Left 2 + setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); + setAxisPosition_mm(X_MIN_BED + lfrb[0], axis_t(X)); + setAxisPosition_mm(Y_MIN_BED + lfrb[1], axis_t(Y)); + waitway = 6; + break; + } + case 8: { // Assitant Level , Front Right 3 + setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); + setAxisPosition_mm(X_MAX_BED - lfrb[2], axis_t(X)); + setAxisPosition_mm(Y_MIN_BED + lfrb[1], axis_t(Y)); + waitway = 6; + break; + } + case 9: { // Assitant Level , Back Right 4 + setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); + setAxisPosition_mm(X_MAX_BED - lfrb[2], axis_t(X)); + setAxisPosition_mm(Y_MAX_BED - lfrb[3], axis_t(Y)); + waitway = 6; + break; + } + case 10: { // Assitant Level , Back Left 5 + setAxisPosition_mm(BED_TRAMMING_Z_HOP, axis_t(Z)); + setAxisPosition_mm(X_MIN_BED + lfrb[0], axis_t(X)); + setAxisPosition_mm(Y_MAX_BED - lfrb[3], axis_t(Y)); + waitway = 6; + break; + } + case 11: { // Autolevel switch + #if HAS_MESH + const bool gla = !getLevelingActive(); + setLevelingActive(gla); + sendData(gla ? 3 : 2, AutoLevelIcon); + #endif + sendData(getZOffset_mm() * 100, ProbeOffset_Z); + break; + } + case 12: { + injectCommands(F("G26R255")); + onStatusChanged(F("Beginning G26.. Heating")); + break; + } + case 13: { + injectCommands(F("G29S1")); + onStatusChanged(F("Begin Manual Mesh")); + break; + } + case 14: { + injectCommands(F("G29S2")); + onStatusChanged(F("Moving to Next Mesh Point")); + break; + } + case 15: { + injectCommands(F("M211S0\nG91\nG1Z-0.025\nG90\nM211S1")); + onStatusChanged(F("Moved down 0.025")); + break; + } + case 16: { + injectCommands(F("M211S0\nG91\nG1Z0.025\nG90\nM211S1")); + onStatusChanged(F("Moved up 0.025")); + break; + } + case 17: { + dwin_settings.display_volume = 0; + dwin_settings.display_sound = false; + setTouchScreenConfiguration(); + break; + } + case 18: { + dwin_settings.display_volume = 255; + dwin_settings.display_sound = true; + setTouchScreenConfiguration(); + break; + } + case 19: { + dwin_settings.screen_brightness = 10; + setTouchScreenConfiguration(); + break; + } + case 20: { + dwin_settings.screen_brightness = 100; + setTouchScreenConfiguration(); + break; + } + case 21: { + dwin_settings.display_standby ^= true; + setTouchScreenConfiguration(); + break; + } + case 22: { + dwin_settings.screen_rotation = dwin_settings.screen_rotation == 10 ? 0 : 10; + setTouchScreenConfiguration(); + break; + } + case 23: { // Set IDEX Autopark + injectCommands(F("M605S1\nG28X\nG1X0")); + break; + } + case 24: { // Set IDEX Duplication + injectCommands(F("M605S1\nT0\nG28\nM605S2\nG28X\nG1X0")); + break; + } + case 25: { // Set IDEX Mirrored Duplication + injectCommands(F("M605S1\nT0\nG28\nM605S2\nG28X\nG1X0\nM605S3")); + break; + } + case 26: { // Set IDEX Full Control + injectCommands(F("M605S0\nG28X")); + break; + } + case 27: { // Change Tool + setActiveTool(getActiveTool() == E0 ? E1 : E0, !isAxisPositionKnown(X)); + break; + } + default: break; + } + + sendData(10, FilenameIcon); + break; + + case XYZEaxis: { + axis_t axis = X; + float min = 0.0f, max = 0.0f; + waitway = 4; + if (recdat.addr == DisplayXaxis) { + axis = X; + min = X_MIN_POS; + max = X_MAX_POS; + } + else if (recdat.addr == DisplayYaxis) { + axis = Y; + min = Y_MIN_POS; + max = Y_MAX_POS; + } + else if (recdat.addr == DisplayZaxis) { + axis = Z; + min = Z_MIN_POS; + max = Z_MAX_POS; + } + else if (recdat.addr == AutoZero) { + if (recdat.data[0] == 3) { // autohome + waitway = 4; + injectCommands(F("G28\nG1 F1000 Z10")); + show_status = autoHomeKey = true; + autoHomeIconNum = 0; + sendData(10, FilenameIcon); + } + else { + axisPageNum = recdat.data[0]; + waitway = 0; + } + break; + } + + float targetPos = float(recdat.data[0]) / 10; + LIMIT(targetPos, min, max); + setAxisPosition_mm(targetPos, axis); + waitway = 0; + sendData(10, FilenameIcon); + break; + } + + case Filament: + + uint16_t IconTemp; + if (recdat.addr == Exchfilament) { + if (getActualTemp_celsius(getActiveTool()) < EXTRUDE_MINTEMP && recdat.data[0] < 5) { + sendData(int16_t(EXTRUDE_MINTEMP), 0x1020); + delay_ms(5); + sendData(ExchangePageBase + 66, ExchangepageAddr); + break; + } + + switch (recdat.data[0]) { + case 1: { // Unload filament1 + setAxisPosition_mm(getAxisPosition_mm(E0) - changeMaterialBuf[0], E0); + break; + } + case 2: { // Load filament1 + setAxisPosition_mm(getAxisPosition_mm(E0) + changeMaterialBuf[0], E0); + break; + } + case 3: { // Unload filament2 + setAxisPosition_mm(getAxisPosition_mm(E1) - changeMaterialBuf[1], E1); + break; + } + case 4: { // Load filament2 + setAxisPosition_mm(getAxisPosition_mm(E1) + changeMaterialBuf[1], E1); + break; + } + case 5: { // sure to heat + nozzleTempStatus[0] = 1; + + setTargetTemp_celsius((PREHEAT_1_TEMP_HOTEND + 10), getActiveTool()); + IconTemp = getActualTemp_celsius(getActiveTool()) * 100 / getTargetTemp_celsius(getActiveTool()); + NOMORE(IconTemp, 100U); + sendData(IconTemp, HeatPercentIcon); + + sendData(getActualTemp_celsius(H0), NozzleTemp); + sendData(getTargetTemp_celsius(H0), NozzlePreheat); + sendData(TERN0(HAS_MULTI_HOTEND, getActualTemp_celsius(H1)), e2Temp); + sendData(TERN0(HAS_MULTI_HOTEND, getTargetTemp_celsius(H1)), e2Preheat); + delay_ms(5); + sendData(ExchangePageBase + 68, ExchangepageAddr); + break; + } + case 6: { // cancel to heat + sendData(ExchangePageBase + 65, ExchangepageAddr); + break; + } + case 0xF1: { // Sure to cancel heating + nozzleTempStatus[0] = 0; + delay_ms(1); + sendData(ExchangePageBase + 65, ExchangepageAddr); + break; + } + case 0xF0: // not to cancel heating + break; + } + sendData(10 * changeMaterialBuf[0], FilamentUnit1); // It's changeMaterialBuf for show, instead of current_position.e in them. + sendData(10 * changeMaterialBuf[1], FilamentUnit2); + } + else if (recdat.addr == FilamentUnit1) { + changeMaterialBuf[0] = float(recdat.data[0]) / 10; + } + else if (recdat.addr == FilamentUnit2) { + changeMaterialBuf[1] = float(recdat.data[0]) / 10; + } + break; + + case LanguageChoice: + + //if (recdat.data[0] == 1) settings.save(); else injectCommands(F("M300")); + + // may at some point use language change screens to save eeprom explicitly + switch (recdat.data[0]) { + case 0: { + injectCommands(F("M500")); + break; + } + case 1: { + sendData(ExchangePageBase + 94, ExchangepageAddr); + break; + } + + #if ENABLED(PIDTEMP) + case 2: { + onStatusChanged(F("Hotend PID Started")); + startPIDTune(static_cast(pid_hotendAutoTemp), getActiveTool()); + break; + } + #endif + + case 3: { + injectCommands(F("M502\nM500")); + break; + } + case 4: { + injectCommands(F("M999\nM280P0S160")); + break; + } + + case 5: { + #if ENABLED(PIDTEMPBED) + onStatusChanged(F("Bed PID Started")); + startBedPIDTune(static_cast(pid_bedAutoTemp)); + #endif + break; + } + case 6: { + injectCommands(F("M500")); + break; + } + default: break; + } + break; + + case No_Filament: + if (recdat.data[0] == 1) { // Filament is out, resume / resume selected on screen + if (ExtUI::pauseModeStatus != PAUSE_MESSAGE_PURGE && ExtUI::pauseModeStatus != PAUSE_MESSAGE_OPTION) { + // setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); + setUserConfirmed(); + // printerStatusKey[1] = 3; + // pause_resume_selected = true; + } + else { + #if ENABLED(FILAMENT_RUNOUT_SENSOR) + bool runouton = false; + if (getFilamentRunoutState()) { + #if NUM_RUNOUT_SENSORS > 1 + if ((runouton = getFilamentRunoutEnabled(getActiveTool()))) + ExtUI::setFilamentRunoutEnabled(false, getActiveTool()); + #else + if ((runouton = getFilamentRunoutEnabled())) + ExtUI::setFilamentRunoutEnabled(false); + #endif + } + #else + constexpr bool runouton = false; + #endif + if (!runouton) { + setPauseMenuResponse(PAUSE_RESPONSE_RESUME_PRINT); + setUserConfirmed(); + printerStatusKey[1] = 3; + pause_resume_selected = true; + } + } + } + else if (recdat.data[0] == 0) { // Filamet is out, Cancel Selected + if (ExtUI::pauseModeStatus == PAUSE_MESSAGE_PURGE || ExtUI::pauseModeStatus == PAUSE_MESSAGE_OPTION) { + setPauseMenuResponse(PAUSE_RESPONSE_EXTRUDE_MORE); + setUserConfirmed(); + } + } + break; + + #if ENABLED(POWER_LOSS_RECOVERY) + case PwrOffNoF: + if (recdat.data[0] == 1) // Yes: continue to print the 3Dmode during power-off. + injectCommands(F("M1000")); + else if (recdat.data[0] == 2) // No + injectCommands(F("M1000C")); + break; + #endif + + case Volume: + if (recdat.data[0] < 0) + dwin_settings.display_volume = 0; + else if (recdat.data[0] > 255) + dwin_settings.display_volume = 0xFF; + else + dwin_settings.display_volume = recdat.data[0]; + + if (dwin_settings.display_volume == 0) { + sendData(0, VolumeIcon); + sendData(9, SoundIcon); + } + else { + sendData((dwin_settings.display_volume + 1) / 32 - 1, VolumeIcon); + sendData(8, SoundIcon); + } + sendData(dwin_settings.display_volume << 8, SoundAddr + 1); + break; + + case Filename: + if (isMediaInserted() && recdat.addr == FilenameChs) { + + recordcount = recdat.data[0] - 1; + if (filenavigator.currentindex == 0 && filenavigator.folderdepth > 0 && (fileIndex + recordcount) == 0) { + filenavigator.upDIR(); + filenavigator.getFiles(0); + fileIndex = 0; + return; + } + + if (filenavigator.currentindex == 0 && filenavigator.folderdepth > 0) + recordcount = recordcount - 1; // account for return dir link in file index + + for (int16_t j = 1; j <= 4; j++) { // Clear filename BG Color and Frame + sendData(0xFFFFUL, FilenameNature + j * 16); // white + sendData(10, FilenameIcon1 + j); // clean + } + for (int16_t j = 0; j < 10; j++) // clear current filename + sendData(0, Choosefilename + j); + + if (filenavigator.getIndexisDir(fileIndex + recordcount)) { + filenavigator.changeDIR((char *)filenavigator.getIndexName(fileIndex + recordcount)); + filenavigator.getFiles(0); + fileIndex = 0; + return; + } + else { + sendData(filenavigator.getIndexName(fileIndex + recordcount), Choosefilename); + sendData(0x87F0UL, FilenameNature + recdat.data[0] * 16); // Change BG of selected line to Light Green + sendData(6, FilenameIcon1 + recdat.data[0]); // show frame + } + } + else if (recdat.addr == FilenamePlay) { + if (recdat.data[0] == 1 && isMediaInserted()) { // for sure + printFile(filenavigator.getIndexName(fileIndex + recordcount)); + + for (int16_t j = 0; j < 10; j++) // clean screen. + sendData(0, Printfilename + j); + + sendData(filenavigator.getIndexName(fileIndex + recordcount), Printfilename); + + delay_ms(4); + + sendData(ExchangePageBase + 53, ExchangepageAddr); + + tpShowStatus = show_status = true; + printerStatusKey[0] = 1; + printerStatusKey[1] = 3; + fileIndex = 0; + recordcount = 0; + } + else if (recdat.data[0] == 2) { // Page Down + if ((fileIndex + DISPLAY_FILES) < (filenavigator.maxFiles() + (filenavigator.folderdepth != 0))) { + fileIndex = fileIndex + DISPLAY_FILES; + // if(filenavigator.folderdepth!=0 && fileIndex!=0) //Shift to acknowledge Return DIR button on first page + // filenavigator.getFiles(fileIndex-1); + // else + filenavigator.getFiles(fileIndex); + // filenavigator.getFiles(filenavigator.currentindex+1); + } + } + else if (recdat.data[0] == 3) { // Page Up + if (fileIndex >= DISPLAY_FILES) { + fileIndex = fileIndex - DISPLAY_FILES; + // if(filenavigator.folderdepth!=0 && fileIndex!=0) //Shift to acknowledge Return DIR button on first page + // filenavigator.getFiles(filenavigator.currentindex-DISPLAY_FILES); + // else + filenavigator.getFiles(fileIndex); + } + } + else if (recdat.data[0] == 4) { // Page Up + injectCommands(F("M22\nM21")); + } + else if (recdat.data[0] == 0) { // return to main page + show_status = true; + tpShowStatus = false; + } + } + break; + + case VolumeDisplay: { + if (recdat.data[0] == 0) { + dwin_settings.display_volume = 0; + dwin_settings.display_sound = false; + } + else if (recdat.data[0] > 100) { + dwin_settings.display_volume = 255; + dwin_settings.display_sound = true; + } + else { + dwin_settings.display_volume = (uint8_t)map(constrain(recdat.data[0], 0, 100), 0, 100, 0, 255); + dwin_settings.display_sound = true; + } + setTouchScreenConfiguration(); + break; + } + + case DisplayBrightness: { + if (recdat.data[0] < 10) + dwin_settings.screen_brightness = 10; + else if (recdat.data[0] > 100) + dwin_settings.screen_brightness = 100; + else + dwin_settings.screen_brightness = (uint8_t)recdat.data[0]; + setTouchScreenConfiguration(); + break; + } + + case DisplayStandbyBrightness: { + if (recdat.data[0] < 10) + dwin_settings.standby_brightness = 10; + else if (recdat.data[0] > 100) + dwin_settings.standby_brightness = 100; + else + dwin_settings.standby_brightness = (uint8_t)recdat.data[0]; + setTouchScreenConfiguration(); + break; + } + + case DisplayStandbySeconds: { + if (recdat.data[0] < 5) + dwin_settings.standby_time_seconds = 5; + else if (recdat.data[0] > 100) + dwin_settings.standby_time_seconds = 100; + else + dwin_settings.standby_time_seconds = (uint8_t)recdat.data[0]; + setTouchScreenConfiguration(); + break; + } + + case AutolevelVal: { + uint8_t meshPoint = (recdat.addr - AutolevelVal) / 2, + yPnt = floor(meshPoint / GRID_MAX_POINTS_X), + xPnt = meshPoint - (yPnt * GRID_MAX_POINTS_X); + if (yPnt % 2 != 0) xPnt = (GRID_MAX_POINTS_X - 1) - xPnt; // zag row + + float meshVal = float(recdat.data[0] - (recdat.data[0] >= 32768 ? 65536 : 0)) / 1000; + + LIMIT(meshVal, Z_PROBE_LOW_POINT, Z_CLEARANCE_BETWEEN_PROBES); + xy_uint8_t point = { xPnt, yPnt }; + setMeshPoint(point, meshVal); + sendData(meshVal * 1000, recdat.addr); + break; + } + + default: break; + } + + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; +} + +void RTS::writeVariable(const uint16_t adr, const void * const values, uint8_t valueslen, const bool isstr/*=false*/, const char fillChar/*=' '*/) { + const char* myvalues = static_cast(values); + bool strend = !myvalues; + DWIN_SERIAL.write(FHONE); + DWIN_SERIAL.write(FHTWO); + DWIN_SERIAL.write(valueslen + 3); + DWIN_SERIAL.write(0x82); + DWIN_SERIAL.write(adr >> 8); + DWIN_SERIAL.write(adr & 0xFF); + while (valueslen--) { + char x; + if (!strend) x = *myvalues++; + if ((isstr && !x) || strend) { + strend = true; + x = fillChar; + } + DWIN_SERIAL.write(x); + } +} + +void RTS::setTouchScreenConfiguration() { + // Main configuration (System_Config) + LIMIT(dwin_settings.screen_brightness, 10, 100); // Prevent a possible all-dark screen + LIMIT(dwin_settings.standby_time_seconds, 10, 655); // Prevent a possible all-dark screen for standby, yet also don't go higher than the DWIN limitation + + uint8_t cfg_bits = (0x0 + | _BV(7) // 7: Enable Control ... TERN0(DWINOS_4, _BV(7)) + | _BV(5) // 5: load 22 touch file + | _BV(4) // 4: auto-upload should always be enabled + | (dwin_settings.display_sound ? _BV(3) : 0) // 3: audio + | (dwin_settings.display_standby ? _BV(2) : 0) // 2: backlight on standby + | (dwin_settings.screen_rotation == 10 ? _BV(1) : 0) // 1 & 0: Inversion + #if LCD_SCREEN_ROTATE == 90 + | _BV(0) // Portrait Mode or 800x480 display has 0 point rotated 90deg from 480x272 display + #elif LCD_SCREEN_ROTATE + #error "Only 90° rotation is supported for the selected LCD." + #endif + ); + + const uint8_t config_set[] = { 0x5A, 0x00, TERN(DWINOS_4, 0x00, 0xFF), cfg_bits }; + writeVariable(0x80 /*System_Config*/, config_set, sizeof(config_set)); + + // Standby brightness (LED_Config) + uint16_t dwinStandbyTimeSeconds = 100 * dwin_settings.standby_time_seconds; /* milliseconds, but divided by 10 (not 5 like the docs say) */ + const uint8_t brightness_set[] = { + dwin_settings.screen_brightness /*% active*/, + dwin_settings.standby_brightness /*% standby*/, + static_cast(dwinStandbyTimeSeconds >> 8), + static_cast(dwinStandbyTimeSeconds) + }; + writeVariable(0x82 /*LED_Config*/, brightness_set, sizeof(brightness_set)); + + if (!dwin_settings.display_sound) { + sendData(0, VolumeIcon); + sendData(9, SoundIcon); + } + else { + sendData((dwin_settings.display_volume + 1) / 32 - 1, VolumeIcon); + sendData(8, SoundIcon); + } + sendData(dwin_settings.display_volume, VolumeIcon - 2); + sendData(dwin_settings.display_volume << 8, SoundAddr + 1); + sendData(map(constrain(dwin_settings.display_volume, 0, 255), 0, 255, 0, 100), VolumeDisplay); + sendData(dwin_settings.screen_brightness, DisplayBrightness); + sendData(dwin_settings.standby_brightness, DisplayStandbyBrightness); + sendData(dwin_settings.standby_time_seconds, DisplayStandbySeconds); + sendData(dwin_settings.display_standby ? 3 : 2, DisplayStandbyEnableIndicator); +} + +#endif // DGUS_LCD_UI_IA_CREALITY diff --git a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h b/Marlin/src/lcd/extui/ia_creality/ia_creality_rts.h similarity index 92% rename from Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h rename to Marlin/src/lcd/extui/ia_creality/ia_creality_rts.h index af3824e9048..9ec7d7872f9 100644 --- a/Marlin/src/lcd/extui/ia_creality/ia_creality_extui.h +++ b/Marlin/src/lcd/extui/ia_creality/ia_creality_rts.h @@ -22,18 +22,18 @@ #pragma once /* **************************************** - * lcd/extui/ia_creality/ia_creality_extui.h + * lcd/extui/ia_creality/ia_creality_rts.h * **************************************** * Extensible_UI implementation for Creality DWIN * 10SPro, Max, CRX, and others - * Based original Creality release, ported to ExtUI for Marlin 2.0 + * Based original Creality release * Written by Insanity Automation, sponsored by Tiny Machines 3D * * ***************************************/ -#include "../ui_api.h" +#include "../../../inc/MarlinConfig.h" -#include +#include /*********************************/ #define FHONE (0x5A) @@ -211,7 +211,7 @@ struct creality_dwin_settings_t { bool display_sound; int8_t screen_rotation; int16_t display_volume; - uint8_t standby_screen_brightness; + uint8_t standby_brightness; uint8_t screen_brightness; int16_t standby_time_seconds; }; @@ -297,3 +297,19 @@ void RTS_Update(); #else #define MEASURING_GCODE MAIN_MENU_ITEM_1_GCODE #endif + +// Data shared by RTS and ExtUI +extern uint16_t fileIndex; +extern uint8_t recordcount; +extern uint8_t startprogress; +extern char waitway; +extern char printerStatusKey[2]; // [0] = 0:ready [1] = 0:keep temperature, 1:heating, 2:cooling, 3:printing +extern bool show_status; +extern bool tpShowStatus; // true: opening time/percentage, false: closing time/percentage +extern uint8_t lastPauseMsgState; +extern creality_dwin_settings_t dwin_settings; +extern bool no_reentry; +#if HAS_PID_HEATING + extern uint16_t pid_hotendAutoTemp; + extern uint16_t pid_bedAutoTemp; +#endif diff --git a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp index be4682f68f1..71f4166ca89 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -137,7 +137,6 @@ void tft_lvgl_init() { #if ENABLED(USB_FLASH_DRIVE_SUPPORT) uint16_t usb_flash_loop = 1000; #if ENABLED(MULTI_VOLUME) && !HAS_SD_HOST_DRIVE - SET_INPUT_PULLUP(SD_DETECT_PIN); if (IS_SD_INSERTED()) card.changeMedia(&card.media_driver_sdcard); else diff --git a/Marlin/src/lcd/extui/nextion/FileNavigator.cpp b/Marlin/src/lcd/extui/nextion/FileNavigator.cpp index 6730370a94e..c00ccb4e369 100644 --- a/Marlin/src/lcd/extui/nextion/FileNavigator.cpp +++ b/Marlin/src/lcd/extui/nextion/FileNavigator.cpp @@ -39,18 +39,18 @@ using namespace ExtUI; #define DEBUG_OUT NEXDEBUGLEVEL #include "../../../core/debug_out.h" -FileList FileNavigator::filelist; // Instance of the Marlin file API -char FileNavigator::currentfoldername[MAX_PATH_LEN]; // Current folder path +FileList FileNavigator::filelist; // ExtUI file API +char FileNavigator::currentDirPath[MAX_PATH_LEN]; // Current folder path uint16_t FileNavigator::lastindex; uint8_t FileNavigator::folderdepth; -uint16_t FileNavigator::currentindex; // override the panel request +uint16_t FileNavigator::currentindex; // override the panel request FileNavigator filenavigator; FileNavigator::FileNavigator() { reset(); } void FileNavigator::reset() { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; folderdepth = 0; currentindex = 0; lastindex = 0; @@ -83,51 +83,51 @@ void FileNavigator::getFiles(uint16_t index) { #endif if (currentindex == 0 && folderdepth > 0) { // Add a link to go up a folder - nextion.SendtoTFT(F("vis p0,1")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("vis p0,1")); + nextion.tftSend(F("\xFF\xFF\xFF")); SEND_VAL("tmpUP", "0"); files--; } else { - nextion.SendtoTFT(F("vis p0,0")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("vis p0,0")); + nextion.tftSend(F("\xFF\xFF\xFF")); } for (uint16_t seek = currentindex; seek < currentindex + files; seek++) { if (filelist.seek(seek)) { - nextion.SendtoTFT(F("s")); + nextion.tftSend(F("s")); LCD_SERIAL.print(fcnt); - nextion.SendtoTFT(F(".txt=\"")); + nextion.tftSend(F(".txt=\"")); if (filelist.isDir()) { LCD_SERIAL.print(filelist.shortFilename()); - nextion.SendtoTFT(F("/\"")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("/\"")); + nextion.tftSend(F("\xFF\xFF\xFF")); - nextion.SendtoTFT(F("l")); + nextion.tftSend(F("l")); LCD_SERIAL.print(fcnt); - nextion.SendtoTFT(F(".txt=\"")); + nextion.tftSend(F(".txt=\"")); LCD_SERIAL.print(filelist.filename()); - nextion.SendtoTFT(F("\"")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("\"")); + nextion.tftSend(F("\xFF\xFF\xFF")); SEND_PCO2("l", fcnt, "1055"); } else { - LCD_SERIAL.print(currentfoldername); + LCD_SERIAL.print(currentDirPath); LCD_SERIAL.print(filelist.shortFilename()); - nextion.SendtoTFT(F("\"")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("\"")); + nextion.tftSend(F("\xFF\xFF\xFF")); - nextion.SendtoTFT(F("l")); + nextion.tftSend(F("l")); LCD_SERIAL.print(fcnt); - nextion.SendtoTFT(F(".txt=\"")); + nextion.tftSend(F(".txt=\"")); LCD_SERIAL.print(filelist.longFilename()); - nextion.SendtoTFT(F("\"")); - nextion.SendtoTFT(F("\xFF\xFF\xFF")); + nextion.tftSend(F("\"")); + nextion.tftSend(F("\xFF\xFF\xFF")); } fcnt++; fseek = seek; #if NEXDEBUG(AC_FILE) - DEBUG_ECHOLNPGM("-", seek, " '", filelist.longFilename(), "' '", currentfoldername, "", filelist.shortFilename(), "'\n"); + DEBUG_ECHOLNPGM("-", seek, " '", filelist.longFilename(), "' '", currentDirPath, "", filelist.shortFilename(), "'\n"); #endif } } @@ -137,11 +137,11 @@ void FileNavigator::getFiles(uint16_t index) { void FileNavigator::changeDIR(char *folder) { #if NEXDEBUG(AC_FILE) - DEBUG_ECHOLNPGM("currentfolder: ", currentfoldername, " New: ", folder); + DEBUG_ECHOLNPGM("currentfolder: ", currentDirPath, " New: ", folder); #endif if (folderdepth >= MAX_FOLDER_DEPTH) return; // limit the folder depth - strcat(currentfoldername, folder); - strcat(currentfoldername, "/"); + strcat(currentDirPath, folder); + strcat(currentDirPath, "/"); filelist.changeDir(folder); refresh(); folderdepth++; @@ -155,20 +155,20 @@ void FileNavigator::upDIR() { currentindex = 0; // Remove the last child folder from the stored path if (folderdepth == 0) { - currentfoldername[0] = '\0'; + currentDirPath[0] = '\0'; reset(); } else { char *pos = nullptr; for (uint8_t f = 0; f < folderdepth; f++) - pos = strchr(currentfoldername, '/'); + pos = strchr(currentDirPath, '/'); pos[1] = '\0'; } #if NEXDEBUG(AC_FILE) - DEBUG_ECHOLNPGM("depth: ", folderdepth, " currentfoldername: ", currentfoldername); + DEBUG_ECHOLNPGM("depth: ", folderdepth, " currentDirPath: ", currentDirPath); #endif } -char* FileNavigator::getCurrentFolderName() { return currentfoldername; } +char* FileNavigator::getCurrentDirPath() { return currentDirPath; } #endif // NEXTION_TFT diff --git a/Marlin/src/lcd/extui/nextion/FileNavigator.h b/Marlin/src/lcd/extui/nextion/FileNavigator.h index fd29bceadea..57773fab5e5 100644 --- a/Marlin/src/lcd/extui/nextion/FileNavigator.h +++ b/Marlin/src/lcd/extui/nextion/FileNavigator.h @@ -41,10 +41,10 @@ class FileNavigator { static void upDIR(); static void changeDIR(char *); static void refresh(); - static char* getCurrentFolderName(); + static char* getCurrentDirPath(); private: static FileList filelist; - static char currentfoldername[MAX_PATH_LEN]; + static char currentDirPath[MAX_PATH_LEN]; static uint16_t lastindex; static uint8_t folderdepth; static uint16_t currentindex; diff --git a/Marlin/src/lcd/extui/nextion/nextion_extui.cpp b/Marlin/src/lcd/extui/nextion/nextion_extui.cpp index bf40fe97ac7..da3e344a35a 100644 --- a/Marlin/src/lcd/extui/nextion/nextion_extui.cpp +++ b/Marlin/src/lcd/extui/nextion/nextion_extui.cpp @@ -35,9 +35,9 @@ namespace ExtUI { - void onStartup() { nextion.Startup(); } - void onIdle() { nextion.IdleLoop(); } - void onPrinterKilled(FSTR_P const error, FSTR_P const component) { nextion.PrinterKilled(error, component); } + void onStartup() { nextion.startup(); } + void onIdle() { nextion.idleLoop(); } + void onPrinterKilled(FSTR_P const error, FSTR_P const component) { nextion.printerKilled(error, component); } void onMediaInserted() {} void onMediaError() {} void onMediaRemoved() {} @@ -46,8 +46,8 @@ namespace ExtUI { void onPrintTimerPaused() {} void onPrintTimerStopped() {} void onFilamentRunout(const extruder_t) {} - void onUserConfirmRequired(const char * const msg) { nextion.ConfirmationRequest(msg); } - void onStatusChanged(const char * const msg) { nextion.StatusChange(msg); } + void onUserConfirmRequired(const char * const msg) { nextion.confirmationRequest(msg); } + void onStatusChanged(const char * const msg) { nextion.statusChange(msg); } void onHomingStart() {} void onHomingDone() {} @@ -117,7 +117,7 @@ namespace ExtUI { #if HAS_PID_HEATING void onPidTuning(const result_t rst) { // Called for temperature PID tuning result - nextion.PanelInfo(37); + nextion.panelInfo(37); } #endif diff --git a/Marlin/src/lcd/extui/nextion/nextion_tft.cpp b/Marlin/src/lcd/extui/nextion/nextion_tft.cpp index 788be5ac651..15c384808f8 100644 --- a/Marlin/src/lcd/extui/nextion/nextion_tft.cpp +++ b/Marlin/src/lcd/extui/nextion/nextion_tft.cpp @@ -53,7 +53,7 @@ NextionTFT nextion; NextionTFT::NextionTFT() {} -void NextionTFT::Startup() { +void NextionTFT::startup() { selectedfile[0] = '\0'; nextion_command[0] = '\0'; command_len = 0; @@ -76,15 +76,15 @@ void NextionTFT::Startup() { DEBUG_ECHOLNPGM("Nextion Debug Level ", NEXDEBUGLEVEL); } -void NextionTFT::IdleLoop() { - if (ReadTFTCommand()) { - ProcessPanelRequest(); +void NextionTFT::idleLoop() { + if (readTFTCommand()) { + processPanelRequest(); command_len = 0; } UpdateOnChange(); } -void NextionTFT::PrinterKilled(FSTR_P const error, FSTR_P const component) { +void NextionTFT::printerKilled(FSTR_P const error, FSTR_P const component) { SEND_TXT_END("page error"); SEND_TXT_F("t3", F("Error")); SEND_TXT_F("t4", component); @@ -96,21 +96,21 @@ void NextionTFT::PrintFinished() { SEND_TXT_END("page printfinished"); } -void NextionTFT::ConfirmationRequest(const char * const msg) { +void NextionTFT::confirmationRequest(const char * const msg) { SEND_VALasTXT("tmppage.M117", msg); #if NEXDEBUG(N_MARLIN) - DEBUG_ECHOLNPGM("ConfirmationRequest() ", msg, " printer_state:", printer_state); + DEBUG_ECHOLNPGM("confirmationRequest() ", msg, " printer_state:", printer_state); #endif } -void NextionTFT::StatusChange(const char * const msg) { +void NextionTFT::statusChange(const char * const msg) { #if NEXDEBUG(N_MARLIN) - DEBUG_ECHOLNPGM("StatusChange() ", msg, "\nprinter_state:", printer_state); + DEBUG_ECHOLNPGM("statusChange() ", msg, "\nprinter_state:", printer_state); #endif SEND_VALasTXT("tmppage.M117", msg); } -void NextionTFT::SendtoTFT(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel +void NextionTFT::tftSend(FSTR_P const fstr/*=nullptr*/) { // A helper to print PROGMEM string to the panel #if NEXDEBUG(N_SOME) DEBUG_ECHOF(fstr); #endif @@ -118,7 +118,7 @@ void NextionTFT::SendtoTFT(FSTR_P const fstr/*=nullptr*/) { // A helper to print while (const char c = pgm_read_byte(str++)) LCD_SERIAL.write(c); } -bool NextionTFT::ReadTFTCommand() { +bool NextionTFT::readTFTCommand() { bool command_ready = false; while ((LCD_SERIAL.available() > 0) && (command_len < MAX_CMND_LEN)) { nextion_command[command_len] = LCD_SERIAL.read(); @@ -149,15 +149,15 @@ bool NextionTFT::ReadTFTCommand() { return command_ready; } -void NextionTFT::SendFileList(int8_t startindex) { +void NextionTFT::sendFileList(int8_t startindex) { // respond to panel request for 7 files starting at index #if NEXDEBUG(N_INFO) - DEBUG_ECHOLNPGM("## SendFileList ## ", startindex); + DEBUG_ECHOLNPGM("## sendFileList ## ", startindex); #endif filenavigator.getFiles(startindex); } -void NextionTFT::SelectFile() { +void NextionTFT::selectFile() { strncpy(selectedfile, nextion_command + 4, command_len - 4); selectedfile[command_len - 5] = '\0'; #if NEXDEBUG(N_FILE) @@ -169,11 +169,11 @@ void NextionTFT::SelectFile() { break; case '<': // .. (go up folder level) filenavigator.upDIR(); - SendFileList(0); + sendFileList(0); break; default: // enter sub folder filenavigator.changeDIR(selectedfile); - SendFileList(0); + sendFileList(0); break; } } @@ -188,24 +188,24 @@ void NextionTFT::_format_time(char *outstr, uint32_t time) { sprintf_P(outstr, PSTR("%02d:%02ds"), min, sec); } -void NextionTFT::ProcessPanelRequest() { +void NextionTFT::processPanelRequest() { // Break these up into logical blocks as its easier to navigate than one huge switch case! if (nextion_command[0] == 'X') { int8_t req = atoi(&nextion_command[1]); // Information requests if (req <= 49) - PanelInfo(req); + panelInfo(req); // Simple Actions else if (req >= 50) - PanelAction(req); + panelAction(req); } } #define SEND_NA(A) SEND_TXT(A, "n/a") -void NextionTFT::PanelInfo(uint8_t req) { +void NextionTFT::panelInfo(uint8_t req) { switch (req) { case 0: break; @@ -216,7 +216,7 @@ void NextionTFT::PanelInfo(uint8_t req) { //SEND_TXT("tmppage.M117", msg_no_sd_card); } else if (nextion_command[3] == 'S') - SendFileList(atoi(&nextion_command[4])); + sendFileList(atoi(&nextion_command[4])); } break; @@ -488,7 +488,7 @@ void NextionTFT::PanelInfo(uint8_t req) { } } -void NextionTFT::PanelAction(uint8_t req) { +void NextionTFT::panelAction(uint8_t req) { switch (req) { case 50: // Pause SD print @@ -512,7 +512,7 @@ void NextionTFT::PanelAction(uint8_t req) { break; case 54: // A13 Select file - SelectFile(); + selectFile(); break; case 65: // Cool Down diff --git a/Marlin/src/lcd/extui/nextion/nextion_tft.h b/Marlin/src/lcd/extui/nextion/nextion_tft.h index 806630485cd..9e085b0f721 100644 --- a/Marlin/src/lcd/extui/nextion/nextion_tft.h +++ b/Marlin/src/lcd/extui/nextion/nextion_tft.h @@ -40,23 +40,23 @@ class NextionTFT { public: NextionTFT(); - static void Startup(); - static void IdleLoop(); - static void PrinterKilled(FSTR_P const, FSTR_P const); - static void ConfirmationRequest(const char * const); - static void StatusChange(const char * const); - static void SendtoTFT(FSTR_P const=nullptr); - //static void SendtoTFTLN(FSTR_P const=nullptr); + static void startup(); + static void idleLoop(); + static void printerKilled(FSTR_P const, FSTR_P const); + static void confirmationRequest(const char * const); + static void statusChange(const char * const); + static void tftSend(FSTR_P const=nullptr); + //static void tftSendLn(FSTR_P const=nullptr); static void UpdateOnChange(); static void PrintFinished(); - static void PanelInfo(uint8_t); + static void panelInfo(uint8_t); private: - static bool ReadTFTCommand(); - static void SendFileList(int8_t); - static void SelectFile(); - static void ProcessPanelRequest(); - static void PanelAction(uint8_t); + static bool readTFTCommand(); + static void sendFileList(int8_t); + static void selectFile(); + static void processPanelRequest(); + static void panelAction(uint8_t); static void _format_time(char *, uint32_t); }; diff --git a/Marlin/src/lcd/extui/nextion/nextion_tft_defs.h b/Marlin/src/lcd/extui/nextion/nextion_tft_defs.h index cdd91bf2a3c..061d29559c0 100644 --- a/Marlin/src/lcd/extui/nextion/nextion_tft_defs.h +++ b/Marlin/src/lcd/extui/nextion/nextion_tft_defs.h @@ -54,10 +54,10 @@ // TFT panel commands #define msg_welcome MACHINE_NAME " Ready." -#define SEND_TEMP(x,y,t,z) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F(".txt=\"")), LCD_SERIAL.print(y), nextion.SendtoTFT(F(t)), LCD_SERIAL.print(z), nextion.SendtoTFT(F("\"\xFF\xFF\xFF"))) -#define SEND_VAL(x,y) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F(".val=")), LCD_SERIAL.print(y), nextion.SendtoTFT(F("\xFF\xFF\xFF"))) -#define SEND_TXT(x,y) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F(".txt=\"")), nextion.SendtoTFT(F(y)), nextion.SendtoTFT(F("\"\xFF\xFF\xFF"))) -#define SEND_TXT_F(x,y) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F(".txt=\"")), nextion.SendtoTFT(y), nextion.SendtoTFT(F("\"\xFF\xFF\xFF"))) -#define SEND_VALasTXT(x,y) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F(".txt=\"")), LCD_SERIAL.print(y), nextion.SendtoTFT(F("\"\xFF\xFF\xFF"))) -#define SEND_TXT_END(x) (nextion.SendtoTFT(F(x)), nextion.SendtoTFT(F("\xFF\xFF\xFF"))) -#define SEND_PCO2(x,y,z) (nextion.SendtoTFT(F(x)), LCD_SERIAL.print(y), nextion.SendtoTFT(F(".pco=")), nextion.SendtoTFT(F(z)), nextion.SendtoTFT(F("\xFF\xFF\xFF"))) +#define SEND_TEMP(x,y,t,z) (nextion.tftSend(F(x)), nextion.tftSend(F(".txt=\"")), LCD_SERIAL.print(y), nextion.tftSend(F(t)), LCD_SERIAL.print(z), nextion.tftSend(F("\"\xFF\xFF\xFF"))) +#define SEND_VAL(x,y) (nextion.tftSend(F(x)), nextion.tftSend(F(".val=")), LCD_SERIAL.print(y), nextion.tftSend(F("\xFF\xFF\xFF"))) +#define SEND_TXT(x,y) (nextion.tftSend(F(x)), nextion.tftSend(F(".txt=\"")), nextion.tftSend(F(y)), nextion.tftSend(F("\"\xFF\xFF\xFF"))) +#define SEND_TXT_F(x,y) (nextion.tftSend(F(x)), nextion.tftSend(F(".txt=\"")), nextion.tftSend(y), nextion.tftSend(F("\"\xFF\xFF\xFF"))) +#define SEND_VALasTXT(x,y) (nextion.tftSend(F(x)), nextion.tftSend(F(".txt=\"")), LCD_SERIAL.print(y), nextion.tftSend(F("\"\xFF\xFF\xFF"))) +#define SEND_TXT_END(x) (nextion.tftSend(F(x)), nextion.tftSend(F("\xFF\xFF\xFF"))) +#define SEND_PCO2(x,y,z) (nextion.tftSend(F(x)), LCD_SERIAL.print(y), nextion.tftSend(F(".pco=")), nextion.tftSend(F(z)), nextion.tftSend(F("\xFF\xFF\xFF"))) diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 568ad49df0b..f74e24e93a1 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -748,9 +748,9 @@ namespace Language_en { LSTR MSG_MMU2_EJECT_FILAMENT = _UxGT("MMU Eject"); LSTR MSG_MMU2_EJECT_FILAMENT_N = _UxGT("MMU Eject ~"); LSTR MSG_MMU2_UNLOAD_FILAMENT = _UxGT("MMU Unload"); - LSTR MSG_MMU2_LOADING_FILAMENT = _UxGT("Loading Fil. %i..."); - LSTR MSG_MMU2_EJECTING_FILAMENT = _UxGT("Ejecting Fil. ..."); - LSTR MSG_MMU2_UNLOADING_FILAMENT = _UxGT("Unloading Fil...."); + LSTR MSG_MMU2_LOADING_FILAMENT = _UxGT("Filament %i Load..."); + LSTR MSG_MMU2_EJECTING_FILAMENT = _UxGT("Filament Eject..."); + LSTR MSG_MMU2_UNLOADING_FILAMENT = _UxGT("Filament Unload..."); LSTR MSG_MMU2_ALL = _UxGT("All"); LSTR MSG_MMU2_FILAMENT_N = _UxGT("Filament ~"); LSTR MSG_MMU2_RESET = _UxGT("Reset MMU");