Skip to content

Commit 5b4a8d2

Browse files
committed
Swap print timer when a remaining time available is available #208
1 parent bfa2e78 commit 5b4a8d2

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

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

+58-1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ void DGUSScreenHandler::DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var
285285
// Send the current print time to the display.
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) {
288+
// Clear if changed and we shouldn't display
289+
static bool last_shouldDisplay = true;
290+
bool shouldDisplay = ui.remaining_time == 0;
291+
if (last_shouldDisplay != shouldDisplay) {
292+
if (!shouldDisplay) {
293+
dgusdisplay.WriteVariable(VP_PrintTime, nullptr, var.size, true);
294+
}
295+
}
296+
297+
last_shouldDisplay = shouldDisplay;
298+
if (!shouldDisplay) return;
299+
300+
// Write if changed
288301
duration_t elapsed = print_job_timer.duration();
289302

290303
static uint32_t last_elapsed;
@@ -299,16 +312,60 @@ void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
299312
last_elapsed = elapsed.second();
300313
}
301314

315+
void DGUSScreenHandler::DGUSLCD_SendPrintTimeWithRemainingToDisplay(DGUS_VP_Variable &var) {
316+
// Clear if changed and we shouldn't display
317+
static bool last_shouldDisplay = true;
318+
bool shouldDisplay = ui.remaining_time != 0;
319+
if (last_shouldDisplay != shouldDisplay) {
320+
if (!shouldDisplay) {
321+
dgusdisplay.WriteVariable(VP_PrintTimeWithRemainingVisible, nullptr, var.size, true);
322+
}
323+
}
324+
325+
last_shouldDisplay = shouldDisplay;
326+
if (!shouldDisplay) return;
327+
328+
// Write if changed
329+
duration_t elapsed = print_job_timer.duration();
330+
331+
static uint32_t last_elapsed;
332+
if (elapsed == last_elapsed) {
333+
return;
334+
}
335+
336+
char buf[32];
337+
elapsed.toString(buf);
338+
dgusdisplay.WriteVariable(VP_PrintTimeWithRemainingVisible, buf, var.size, true);
339+
340+
last_elapsed = elapsed.second();
341+
}
342+
302343
// Send the current print time to the display.
303344
// It is using a hex display for that: It expects BSD coded data in the format xxyyzz
304345
void DGUSScreenHandler::DGUSLCD_SendPrintTimeRemainingToDisplay(DGUS_VP_Variable &var) {
305346
#if ENABLED(SHOW_REMAINING_TIME)
306347
static uint32_t lastRemainingTime = -1;
307-
uint32_t remaining_time = ui.get_remaining_time();
348+
uint32_t remaining_time = ui.remaining_time;
308349
if (lastRemainingTime == remaining_time) {
309350
return;
310351
}
311352

353+
bool has_remaining_time = remaining_time != 0;
354+
355+
// Update display of SPs (toggle between large and small print timer)
356+
if (has_remaining_time) {
357+
dgusdisplay.WriteVariable(VP_HideRemainingTime_Ico, ICON_REMAINING_VISIBLE);
358+
} else {
359+
dgusdisplay.WriteVariable(VP_HideRemainingTime_Ico, ICON_REMAINING_HIDDEN);
360+
}
361+
362+
if (!has_remaining_time) {
363+
// Clear remaining time
364+
dgusdisplay.WriteVariable(VP_PrintTimeRemaining, nullptr, var.size, true);
365+
lastRemainingTime = remaining_time;
366+
return;
367+
}
368+
312369
// Send a progress update to the display if anything is different.
313370
// This allows custom M117 commands to override the displayed string if desired.
314371

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_SendPrintTimeWithRemainingToDisplay(DGUS_VP_Variable &var);
220221
static void DGUSLCD_SendPrintTimeRemainingToDisplay(DGUS_VP_Variable &var);
221222
#if ENABLED(PRINTCOUNTER)
222223
static void DGUSLCD_SendPrintAccTimeToDisplay(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_PrintTimeWithRemainingVisible,
177178
VP_PrintTimeRemaining,
178179
VP_LINEAR_ADVANCE_FACTOR,
179180

@@ -192,6 +193,7 @@ const uint16_t VPList_PrintScreen[] PROGMEM = {
192193
VP_PrintProgress_Percentage,
193194
VP_PrintTimeProgressBar,
194195
VP_PrintTime,
196+
VP_PrintTimeWithRemainingVisible,
195197
VP_PrintTimeRemaining,
196198
VP_LINEAR_ADVANCE_FACTOR,
197199

@@ -580,6 +582,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
580582
#endif
581583

582584
VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay),
585+
VPHELPER_STR(VP_PrintTimeWithRemainingVisible, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeWithRemainingToDisplay),
583586
VPHELPER_STR(VP_PrintTimeRemaining, nullptr, VP_PrintTimeRemaining_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeRemainingToDisplay),
584587
VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr),
585588
VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr),

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

+4
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,15 @@ 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_PrintTimeWithRemainingVisible = 0x2335;
238239
constexpr uint16_t VP_PrintTime_LEN = 19;
239240

240241
constexpr uint16_t VP_PrintTimeRemaining = 0x231f;
241242
constexpr uint16_t VP_PrintTimeRemaining_LEN = 21;
242243

244+
constexpr uint16_t VP_HideRemainingTime_Ico = 0x21b4;
245+
constexpr uint16_t ICON_REMAINING_VISIBLE = 26;
246+
constexpr uint16_t ICON_REMAINING_HIDDEN = 27;
243247

244248
constexpr uint16_t VP_Z_OFFSET = 0x1026;
245249

0 commit comments

Comments
 (0)