Skip to content

Commit 1896f47

Browse files
committed
Send print time as a separate value to the display #208
1 parent ad407de commit 1896f47

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp

+20-19
Original file line numberDiff line numberDiff line change
@@ -286,37 +286,38 @@ void DGUSScreenHandler::DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var
286286
// It is using a hex display for that: It expects BSD coded data in the format xxyyzz
287287
void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
288288
duration_t elapsed = print_job_timer.duration();
289+
289290
char buf[32];
290291
elapsed.toString(buf);
291292
dgusdisplay.WriteVariable(VP_PrintTime, buf, var.size, true);
293+
}
292294

295+
// Send the current print time to the display.
296+
// It is using a hex display for that: It expects BSD coded data in the format xxyyzz
297+
void DGUSScreenHandler::DGUSLCD_SendPrintTimeRemainingToDisplay(DGUS_VP_Variable &var) {
293298
#if ENABLED(SHOW_REMAINING_TIME)
294299
static uint32_t lastRemainingTime = -1;
295300
uint32_t remaining_time = ui.get_remaining_time();
296-
if (lastRemainingTime != remaining_time && remaining_time) {
297-
// Send a progress update to the display if anything is different.
298-
// This allows custom M117 commands to override the displayed string if desired.
301+
if (lastRemainingTime == remaining_time) {
302+
return;
303+
}
299304

300-
// Remaining time is seconds. When Marlin accepts a M73 R[minutes] command, it multiplies
301-
// the R value by 60 to make a number of seconds. But... Marlin can also predict time
302-
// if the M73 R command has not been used.
305+
// Send a progress update to the display if anything is different.
306+
// This allows custom M117 commands to override the displayed string if desired.
303307

304-
duration_t remaining(remaining_time);
305-
306-
// So duration_t wants 21 bytes and we want to prepend remaining before it
307-
static PGM_P remainingStr = PSTR("Remaining: ");
308-
constexpr size_t buffer_size = 11 /* remaining */ + 21 /*for duration_t*/ + 2 /*zero bytes*/;
308+
// Remaining time is seconds. When Marlin accepts a M73 R[minutes] command, it multiplies
309+
// the R value by 60 to make a number of seconds. But... Marlin can also predict time
310+
// if the M73 R command has not been used. So we should be good either way.
311+
duration_t remaining(remaining_time);
312+
constexpr size_t buffer_size = 21;
309313

310-
// Add the "remaining" string
311-
char buffer[buffer_size] = {0};
312-
strcpy_P(buffer, remainingStr);
314+
// Write the duration
315+
char buffer[buffer_size] = {0};
316+
remaining.toString(buffer);
313317

314-
// Write the duration
315-
char* duration_buffer_str = buffer + 11;
316-
remaining.toString(duration_buffer_str);
318+
dgusdisplay.WriteVariable(VP_PrintTimeRemaining, buffer, var.size, true);
317319

318-
setstatusmessage(buffer);
319-
}
320+
lastRemainingTime = remaining_time;
320321
#endif
321322
}
322323

Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class DGUSScreenHandler {
217217
static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
218218
static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
219219
static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
220+
static void DGUSLCD_SendPrintTimeRemainingToDisplay(DGUS_VP_Variable &var);
220221
#if ENABLED(PRINTCOUNTER)
221222
static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
222223
static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);

Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ const uint16_t VPList_PrintPausingError[] PROGMEM = {
174174
VP_PrintProgress_Percentage,
175175
VP_PrintTimeProgressBar,
176176
VP_PrintTime,
177+
VP_PrintTimeRemaining,
177178

178179
0x0000
179180
};
@@ -190,6 +191,7 @@ const uint16_t VPList_PrintScreen[] PROGMEM = {
190191
VP_PrintProgress_Percentage,
191192
VP_PrintTimeProgressBar,
192193
VP_PrintTime,
194+
VP_PrintTimeRemaining,
193195

194196
VP_FWRETRACT_INDICATOR_ICON,
195197

@@ -576,6 +578,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
576578
#endif
577579

578580
VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay),
581+
VPHELPER_STR(VP_PrintTimeRemaining, nullptr, VP_PrintTimeRemaining_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeRemainingToDisplay),
579582
VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr),
580583
VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr),
581584

Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ constexpr uint16_t VP_PrintProgress_Percentage = 0x1016; // 2 Byte Integer (0..1
235235
constexpr uint16_t VP_PrintTimeProgressBar = 0x100E;
236236

237237
constexpr uint16_t VP_PrintTime = 0x21a0;
238-
constexpr uint16_t VP_PrintTime_LEN = 12;
238+
constexpr uint16_t VP_PrintTime_LEN = 19;
239+
240+
constexpr uint16_t VP_PrintTimeRemaining = 0x231f;
241+
constexpr uint16_t VP_PrintTimeRemaining_LEN = 21;
242+
239243

240244
constexpr uint16_t VP_Z_OFFSET = 0x1026;
241245

0 commit comments

Comments
 (0)