From 4b9bb85b1266e8febbcb1931c8427d410a05bf84 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Mar 2023 22:55:55 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20DGUS=5FLCD=5FUI=20RELOADED?= =?UTF-8?q?=20conditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/inc/SanityCheck.h | 2 + .../lcd/extui/dgus_reloaded/DGUSDisplay.cpp | 27 +++---- .../src/lcd/extui/dgus_reloaded/DGUSDisplay.h | 25 ++++--- .../lcd/extui/dgus_reloaded/DGUSRxHandler.cpp | 75 ++++++------------- .../extui/dgus_reloaded/DGUSScreenHandler.cpp | 9 +-- .../extui/dgus_reloaded/DGUSScreenHandler.h | 5 -- .../extui/dgus_reloaded/DGUSSetupHandler.cpp | 6 +- .../lcd/extui/dgus_reloaded/DGUSTxHandler.cpp | 6 +- 8 files changed, 56 insertions(+), 99 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 54ffcaf0ca..7d8f404591 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -4409,6 +4409,8 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive."); #error "DGUS_LCD_UI RELOADED requires BABYSTEP_ALWAYS_AVAILABLE." #elif DISABLED(BABYSTEP_ZPROBE_OFFSET) #error "DGUS_LCD_UI RELOADED requires BABYSTEP_ZPROBE_OFFSET." + #elif ENABLED(HOME_AFTER_DEACTIVATE) + #error "DGUS_LCD_UI RELOADED requires HOME_AFTER_DEACTIVATE to be disabled." #elif ENABLED(AUTO_BED_LEVELING_UBL) && DISABLED(UBL_SAVE_ACTIVE_ON_M500) #warning "Without UBL_SAVE_ACTIVE_ON_M500, your mesh will not be saved when using the touchscreen." #endif diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.cpp index 5bbeb0d7cc..7e215f887c 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.cpp @@ -125,8 +125,7 @@ void DGUSDisplay::WriteStringPGM(uint16_t addr, const void* data_ptr, uint8_t si const char* data = static_cast(data_ptr); size_t len = strlen_P(data); - uint8_t left_spaces = 0; - uint8_t right_spaces = 0; + uint8_t left_spaces = 0, right_spaces = 0; if (len < size) { if (!len) { @@ -147,15 +146,9 @@ void DGUSDisplay::WriteStringPGM(uint16_t addr, const void* data_ptr, uint8_t si len = size; } - while (left_spaces--) { - LCD_SERIAL.write(' '); - } - while (len--) { - LCD_SERIAL.write(pgm_read_byte(data++)); - } - while (right_spaces--) { - LCD_SERIAL.write(use_space ? ' ' : '\0'); - } + while (left_spaces--) LCD_SERIAL.write(' '); + while (len--) LCD_SERIAL.write(pgm_read_byte(data++)); + while (right_spaces--) LCD_SERIAL.write(use_space ? ' ' : '\0'); } void DGUSDisplay::ReadVersions() { @@ -340,11 +333,13 @@ void DGUSDisplay::ProcessRx() { } size_t DGUSDisplay::GetFreeTxBuffer() { - #ifdef LCD_SERIAL_GET_TX_BUFFER_FREE - return LCD_SERIAL_GET_TX_BUFFER_FREE(); - #else - return SIZE_MAX; - #endif + return ( + #ifdef LCD_SERIAL_GET_TX_BUFFER_FREE + LCD_SERIAL_GET_TX_BUFFER_FREE() + #else + SIZE_MAX + #endif + ); } void DGUSDisplay::FlushTx() { diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h b/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h index c4e3645f28..bfea5780a1 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h @@ -47,13 +47,13 @@ public: enum DGUS_ControlType : uint8_t { VARIABLE_DATA_INPUT = 0x00, - POPUP_WINDOW = 0x01, - INCREMENTAL_ADJUST = 0x02, - SLIDER_ADJUST = 0x03, - RTC_SETTINGS = 0x04, - RETURN_KEY_CODE = 0x05, - TEXT_INPUT = 0x06, - FIRMWARE_SETTINGS = 0x07 + POPUP_WINDOW = 0x01, + INCREMENTAL_ADJUST = 0x02, + SLIDER_ADJUST = 0x03, + RTC_SETTINGS = 0x04, + RETURN_KEY_CODE = 0x05, + TEXT_INPUT = 0x06, + FIRMWARE_SETTINGS = 0x07 }; DGUSDisplay() = default; @@ -63,8 +63,11 @@ public: static void Read(uint16_t addr, uint8_t size); static void Write(uint16_t addr, const void* data_ptr, uint8_t size); - static void WriteString(uint16_t addr, const void* data_ptr, uint8_t size, bool left = true, bool right = false, bool use_space = true); - static void WriteStringPGM(uint16_t addr, const void* data_ptr, uint8_t size, bool left = true, bool right = false, bool use_space = true); + static void WriteString(uint16_t addr, const void* data_ptr, uint8_t size, bool left=true, bool right=false, bool use_space=true); + static void WriteStringPGM(uint16_t addr, const void* data_ptr, uint8_t size, bool left=true, bool right=false, bool use_space=true); + static void WriteString(uint16_t addr, FSTR_P const fstr, uint8_t size, bool left=true, bool right=false, bool use_space=true) { + WriteStringPGM(addr, FTOP(fstr), size, left, right, use_space); + } template static void Write(uint16_t addr, T data) { @@ -83,7 +86,7 @@ public: // start: position at which the sound was stored on the display. // len: how many sounds to play. Sounds will play consecutively from start to start+len-1. // volume: playback volume. 0 keeps the current volume. - static void PlaySound(uint8_t start, uint8_t len = 1, uint8_t volume = 0); + static void PlaySound(uint8_t start, uint8_t len=1, uint8_t volume=0); // Enable/disable a specific touch control. // type: control type. // control: index of the control on the page (set during screen development). @@ -154,7 +157,7 @@ private: }; enum dgus_system_addr : uint16_t { - DGUS_VERSION = 0x000f // OS/GUI version + DGUS_VERSION = 0x000F // OS/GUI version }; static void WriteHeader(uint16_t addr, uint8_t command, uint8_t len); diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp index f149d3c419..7a0318a555 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp @@ -387,7 +387,7 @@ void DGUSRxHandler::Steppers(DGUS_VP &vp, void *data_ptr) { void DGUSRxHandler::ZOffset(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); - if (!ExtUI::isAxisPositionKnown(ExtUI::Z)) { + if (TERN0(NO_MOTION_BEFORE_HOMING, !ExtUI::isAxisPositionKnown(ExtUI::Z))) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_HOMING_REQUIRED)); return; } @@ -411,7 +411,7 @@ void DGUSRxHandler::ZOffset(DGUS_VP &vp, void *data_ptr) { void DGUSRxHandler::ZOffsetStep(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); - if (!ExtUI::isAxisPositionKnown(ExtUI::Z)) { + if (TERN0(NO_MOTION_BEFORE_HOMING, !ExtUI::isAxisPositionKnown(ExtUI::Z))) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_HOMING_REQUIRED)); return; } @@ -525,7 +525,7 @@ void DGUSRxHandler::Probe(DGUS_VP &vp, void *data_ptr) { #else queue.enqueue_now(F("G29")); #endif - queue.enqueue_now_P(DGUS_CMD_EEPROM_SAVE); + queue.enqueue_now(F("M500")); } void DGUSRxHandler::DisableABL(DGUS_VP &vp, void *data_ptr) { @@ -646,18 +646,12 @@ void DGUSRxHandler::Move(DGUS_VP &vp, void *data_ptr) { switch (vp.addr) { default: return; - case DGUS_Addr::MOVE_SetX: - axis = ExtUI::X; - break; - case DGUS_Addr::MOVE_SetY: - axis = ExtUI::Y; - break; - case DGUS_Addr::MOVE_SetZ: - axis = ExtUI::Z; - break; + case DGUS_Addr::MOVE_SetX: axis = ExtUI::X; break; + case DGUS_Addr::MOVE_SetY: axis = ExtUI::Y; break; + case DGUS_Addr::MOVE_SetZ: axis = ExtUI::Z; break; } - if (!ExtUI::isAxisPositionKnown(axis)) { + if (TERN0(NO_MOTION_BEFORE_HOMING, !ExtUI::isAxisPositionKnown(axis))) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_HOMING_REQUIRED)); return; } @@ -671,18 +665,11 @@ void DGUSRxHandler::MoveStep(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); float offset; - switch (dgus_screen_handler.move_steps) { default: return; - case DGUS_Data::StepSize::MM10: - offset = 10.0f; - break; - case DGUS_Data::StepSize::MM1: - offset = 1.0f; - break; - case DGUS_Data::StepSize::MMP1: - offset = 0.1f; - break; + case DGUS_Data::StepSize::MM10: offset = 10.0f; break; + case DGUS_Data::StepSize::MM1: offset = 1.0f; break; + case DGUS_Data::StepSize::MMP1: offset = 0.1f; break; } const DGUS_Data::MoveDirection direction = (DGUS_Data::MoveDirection)((uint8_t*)data_ptr)[1]; @@ -690,30 +677,15 @@ void DGUSRxHandler::MoveStep(DGUS_VP &vp, void *data_ptr) { switch (direction) { default: return; - case DGUS_Data::MoveDirection::XP: - axis = ExtUI::X; - break; - case DGUS_Data::MoveDirection::XM: - axis = ExtUI::X; - offset = -offset; - break; - case DGUS_Data::MoveDirection::YP: - axis = ExtUI::Y; - break; - case DGUS_Data::MoveDirection::YM: - axis = ExtUI::Y; - offset = -offset; - break; - case DGUS_Data::MoveDirection::ZP: - axis = ExtUI::Z; - break; - case DGUS_Data::MoveDirection::ZM: - axis = ExtUI::Z; - offset = -offset; - break; + case DGUS_Data::MoveDirection::XM: offset = -offset; + case DGUS_Data::MoveDirection::XP: axis = ExtUI::X; break; + case DGUS_Data::MoveDirection::YM: offset = -offset; + case DGUS_Data::MoveDirection::YP: axis = ExtUI::Y; break; + case DGUS_Data::MoveDirection::ZM: offset = -offset; + case DGUS_Data::MoveDirection::ZP: axis = ExtUI::Z; break; } - if (!ExtUI::isAxisPositionKnown(axis)) { + if (TERN0(NO_MOTION_BEFORE_HOMING, !ExtUI::isAxisPositionKnown(axis))) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_HOMING_REQUIRED)); return; } @@ -727,7 +699,6 @@ void DGUSRxHandler::MoveSetStep(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); const DGUS_Data::StepSize size = (DGUS_Data::StepSize)((uint8_t*)data_ptr)[1]; - dgus_screen_handler.move_steps = size; dgus_screen_handler.TriggerFullUpdate(); @@ -746,9 +717,7 @@ void DGUSRxHandler::GcodeExecute(DGUS_VP &vp, void *data_ptr) { UNUSED(vp); UNUSED(data_ptr); - if (!strlen(dgus_screen_handler.gcode)) { - return; - } + if (!strlen(dgus_screen_handler.gcode)) return; if (!dgus_screen_handler.IsPrinterIdle()) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_BUSY)); @@ -765,9 +734,7 @@ void DGUSRxHandler::ResetEEPROM(DGUS_VP &vp, void *data_ptr) { const DGUS_Data::Popup result = (DGUS_Data::Popup)((uint8_t*)data_ptr)[1]; - if (result != DGUS_Data::Popup::CONFIRMED) { - return; - } + if (result != DGUS_Data::Popup::CONFIRMED) return; if (!dgus_screen_handler.IsPrinterIdle()) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(DGUS_MSG_BUSY)); @@ -775,7 +742,7 @@ void DGUSRxHandler::ResetEEPROM(DGUS_VP &vp, void *data_ptr) { } queue.enqueue_now(F("M502")); - queue.enqueue_now_P(DGUS_CMD_EEPROM_SAVE); + queue.enqueue_now(F("M500")); } void DGUSRxHandler::SettingsExtra(DGUS_VP &vp, void *data_ptr) { @@ -908,7 +875,7 @@ void DGUSRxHandler::PIDRun(DGUS_VP &vp, void *data_ptr) { dgus_screen_handler.ShowWaitScreen(GET_TEXT_F(DGUS_MSG_PID_AUTOTUNING), DGUS_Screen::PID); queue.enqueue_one_now(buffer); - queue.enqueue_now_P(DGUS_CMD_EEPROM_SAVE); + queue.enqueue_now(F("M500")); } #if ENABLED(POWER_LOSS_RECOVERY) diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp index cc98126c9b..e1d8778567 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp @@ -69,11 +69,6 @@ bool DGUSScreenHandler::leveling_active = false; millis_t DGUSScreenHandler::status_expire = 0; millis_t DGUSScreenHandler::eeprom_save = 0; -const char DGUS_MSG_UNDEF[] PROGMEM = "-"; - -const char DGUS_CMD_HOME[] PROGMEM = "G28", - DGUS_CMD_EEPROM_SAVE[] PROGMEM = "M500"; - void DGUSScreenHandler::Init() { dgus_display.Init(); @@ -146,7 +141,7 @@ void DGUSScreenHandler::Loop() { if (eeprom_save > 0 && ELAPSED(ms, eeprom_save) && IsPrinterIdle()) { eeprom_save = 0; - queue.enqueue_now_P(DGUS_CMD_EEPROM_SAVE); + queue.enqueue_now(F("M500")); return; } @@ -385,7 +380,7 @@ void DGUSScreenHandler::SetStatusMessage(const char* msg, const millis_t duratio } void DGUSScreenHandler::SetStatusMessage(FSTR_P const fmsg, const millis_t duration) { - dgus_display.WriteStringPGM((uint16_t)DGUS_Addr::MESSAGE_Status, FTOP(fmsg), DGUS_STATUS_LEN, false, true); + dgus_display.WriteString((uint16_t)DGUS_Addr::MESSAGE_Status, fmsg, DGUS_STATUS_LEN, false, true); status_expire = (duration > 0 ? ExtUI::safe_millis() + duration : 0); } diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h index e872e8a823..295df311df 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h @@ -141,8 +141,3 @@ private: }; extern DGUSScreenHandler dgus_screen_handler; - -extern const char DGUS_MSG_UNDEF[]; - -extern const char DGUS_CMD_HOME[], - DGUS_CMD_EEPROM_SAVE[]; diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSSetupHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSSetupHandler.cpp index 3b243e4711..c95d7d0453 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSSetupHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSSetupHandler.cpp @@ -82,7 +82,7 @@ bool DGUSSetupHandler::LevelingMenu() { dgus_screen_handler.ShowWaitScreen(GET_TEXT_F(DGUS_MSG_HOMING), DGUS_Screen::LEVELING_MENU); - queue.enqueue_now_P(DGUS_CMD_HOME); + queue.enqueue_now(F("G28")); return false; } @@ -101,7 +101,7 @@ bool DGUSSetupHandler::LevelingManual() { dgus_screen_handler.ShowWaitScreen(GET_TEXT_F(DGUS_MSG_HOMING), DGUS_Screen::LEVELING_MANUAL); - queue.enqueue_now_P(DGUS_CMD_HOME); + queue.enqueue_now(F("G28")); return false; } @@ -130,7 +130,7 @@ bool DGUSSetupHandler::LevelingOffset() { dgus_screen_handler.ShowWaitScreen(GET_TEXT_F(DGUS_MSG_HOMING), DGUS_Screen::LEVELING_OFFSET); - queue.enqueue_now_P(DGUS_CMD_HOME); + queue.enqueue_now(F("G28")); return false; } diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp index eb1b3aa510..dc2aea8bef 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp @@ -522,7 +522,7 @@ void DGUSTxHandler::PrintTime(DGUS_VP &vp) { dgus_display.WriteString((uint16_t)vp.addr, buffer, vp.size); #else - dgus_display.WriteStringPGM((uint16_t)vp.addr, DGUS_MSG_UNDEF, vp.size); + dgus_display.WriteString((uint16_t)vp.addr, F("-"), vp.size); #endif } @@ -533,7 +533,7 @@ void DGUSTxHandler::LongestPrint(DGUS_VP &vp) { dgus_display.WriteString((uint16_t)vp.addr, buffer, vp.size); #else - dgus_display.WriteStringPGM((uint16_t)vp.addr, DGUS_MSG_UNDEF, vp.size); + dgus_display.WriteString((uint16_t)vp.addr, F("-"), vp.size); #endif } @@ -544,7 +544,7 @@ void DGUSTxHandler::FilamentUsed(DGUS_VP &vp) { dgus_display.WriteString((uint16_t)vp.addr, buffer, vp.size); #else - dgus_display.WriteStringPGM((uint16_t)vp.addr, DGUS_MSG_UNDEF, vp.size); + dgus_display.WriteString((uint16_t)vp.addr, F("-"), vp.size); #endif }