Skip to content

Commit

Permalink
Swap print timer when a remaining time available is available #208
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebazzz committed Mar 3, 2021
1 parent bfa2e78 commit 5b4a8d2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
59 changes: 58 additions & 1 deletion Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ void DGUSScreenHandler::DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var
// 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_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
// Clear if changed and we shouldn't display
static bool last_shouldDisplay = true;
bool shouldDisplay = ui.remaining_time == 0;
if (last_shouldDisplay != shouldDisplay) {
if (!shouldDisplay) {
dgusdisplay.WriteVariable(VP_PrintTime, nullptr, var.size, true);
}
}

last_shouldDisplay = shouldDisplay;
if (!shouldDisplay) return;

// Write if changed
duration_t elapsed = print_job_timer.duration();

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

void DGUSScreenHandler::DGUSLCD_SendPrintTimeWithRemainingToDisplay(DGUS_VP_Variable &var) {
// Clear if changed and we shouldn't display
static bool last_shouldDisplay = true;
bool shouldDisplay = ui.remaining_time != 0;
if (last_shouldDisplay != shouldDisplay) {
if (!shouldDisplay) {
dgusdisplay.WriteVariable(VP_PrintTimeWithRemainingVisible, nullptr, var.size, true);
}
}

last_shouldDisplay = shouldDisplay;
if (!shouldDisplay) return;

// Write if changed
duration_t elapsed = print_job_timer.duration();

static uint32_t last_elapsed;
if (elapsed == last_elapsed) {
return;
}

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

last_elapsed = elapsed.second();
}

// 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();
uint32_t remaining_time = ui.remaining_time;
if (lastRemainingTime == remaining_time) {
return;
}

bool has_remaining_time = remaining_time != 0;

// Update display of SPs (toggle between large and small print timer)
if (has_remaining_time) {
dgusdisplay.WriteVariable(VP_HideRemainingTime_Ico, ICON_REMAINING_VISIBLE);
} else {
dgusdisplay.WriteVariable(VP_HideRemainingTime_Ico, ICON_REMAINING_HIDDEN);
}

if (!has_remaining_time) {
// Clear remaining time
dgusdisplay.WriteVariable(VP_PrintTimeRemaining, nullptr, var.size, true);
lastRemainingTime = remaining_time;
return;
}

// Send a progress update to the display if anything is different.
// This allows custom M117 commands to override the displayed string if desired.

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

Expand All @@ -192,6 +193,7 @@ const uint16_t VPList_PrintScreen[] PROGMEM = {
VP_PrintProgress_Percentage,
VP_PrintTimeProgressBar,
VP_PrintTime,
VP_PrintTimeWithRemainingVisible,
VP_PrintTimeRemaining,
VP_LINEAR_ADVANCE_FACTOR,

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

VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay),
VPHELPER_STR(VP_PrintTimeWithRemainingVisible, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeWithRemainingToDisplay),
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,11 +235,15 @@ 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_PrintTimeWithRemainingVisible = 0x2335;
constexpr uint16_t VP_PrintTime_LEN = 19;

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

constexpr uint16_t VP_HideRemainingTime_Ico = 0x21b4;
constexpr uint16_t ICON_REMAINING_VISIBLE = 26;
constexpr uint16_t ICON_REMAINING_HIDDEN = 27;

constexpr uint16_t VP_Z_OFFSET = 0x1026;

Expand Down

0 comments on commit 5b4a8d2

Please # to comment.