Skip to content

Commit

Permalink
Send print time as a separate value to the display #208
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebazzz committed Mar 2, 2021
1 parent ad407de commit 1896f47
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
39 changes: 20 additions & 19 deletions Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,37 +286,38 @@ void DGUSScreenHandler::DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var
// It is using a hex display for that: It expects BSD coded data in the format xxyyzz
void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
duration_t elapsed = print_job_timer.duration();

char buf[32];
elapsed.toString(buf);
dgusdisplay.WriteVariable(VP_PrintTime, buf, var.size, true);
}

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

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

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

// Add the "remaining" string
char buffer[buffer_size] = {0};
strcpy_P(buffer, remainingStr);
// Write the duration
char buffer[buffer_size] = {0};
remaining.toString(buffer);

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

setstatusmessage(buffer);
}
lastRemainingTime = remaining_time;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class DGUSScreenHandler {
static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
static void DGUSLCD_SendPrintTimeRemainingToDisplay(DGUS_VP_Variable &var);
#if ENABLED(PRINTCOUNTER)
static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const uint16_t VPList_PrintPausingError[] PROGMEM = {
VP_PrintProgress_Percentage,
VP_PrintTimeProgressBar,
VP_PrintTime,
VP_PrintTimeRemaining,

0x0000
};
Expand All @@ -190,6 +191,7 @@ const uint16_t VPList_PrintScreen[] PROGMEM = {
VP_PrintProgress_Percentage,
VP_PrintTimeProgressBar,
VP_PrintTime,
VP_PrintTimeRemaining,

VP_FWRETRACT_INDICATOR_ICON,

Expand Down Expand Up @@ -576,6 +578,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
#endif

VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay),
VPHELPER_STR(VP_PrintTimeRemaining, nullptr, VP_PrintTimeRemaining_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeRemainingToDisplay),
VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr),
VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ constexpr uint16_t VP_PrintProgress_Percentage = 0x1016; // 2 Byte Integer (0..1
constexpr uint16_t VP_PrintTimeProgressBar = 0x100E;

constexpr uint16_t VP_PrintTime = 0x21a0;
constexpr uint16_t VP_PrintTime_LEN = 12;
constexpr uint16_t VP_PrintTime_LEN = 19;

constexpr uint16_t VP_PrintTimeRemaining = 0x231f;
constexpr uint16_t VP_PrintTimeRemaining_LEN = 21;


constexpr uint16_t VP_Z_OFFSET = 0x1026;

Expand Down

0 comments on commit 1896f47

Please # to comment.