Skip to content

Commit

Permalink
🔧 Add DGUS_LCD_UI RELOADED conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 7, 2023
1 parent cc31537 commit e90c213
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 87 deletions.
2 changes: 2 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 11 additions & 16 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ void DGUSDisplay::WriteStringPGM(uint16_t addr, const void* data_ptr, uint8_t si

const char* data = static_cast<const char*>(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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
75 changes: 21 additions & 54 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -671,49 +665,27 @@ 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];
ExtUI::axis_t axis;

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;
}
Expand All @@ -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();
Expand All @@ -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));
Expand All @@ -765,17 +734,15 @@ 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));
return;
}

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) {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,3 @@ class DGUSScreenHandler {
};

extern DGUSScreenHandler dgus_screen_handler;

extern const char DGUS_MSG_UNDEF[];

extern const char DGUS_CMD_HOME[],
DGUS_CMD_EEPROM_SAVE[];
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSSetupHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit e90c213

Please sign in to comment.