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 4b9bb85
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 99 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
25 changes: 14 additions & 11 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class DGUSDisplay {

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;
Expand All @@ -63,8 +63,11 @@ class DGUSDisplay {
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<typename T>
static void Write(uint16_t addr, T data) {
Expand All @@ -83,7 +86,7 @@ class DGUSDisplay {
// 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).
Expand Down Expand Up @@ -154,7 +157,7 @@ class DGUSDisplay {
};

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);
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
9 changes: 2 additions & 7 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 Expand Up @@ -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);
}
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 4b9bb85

Please sign in to comment.