Skip to content

Commit

Permalink
🚸 Adjust Progress / Completion (MarlinFirmware#26466)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and classicrocker883 committed Dec 26, 2023
1 parent cbfacb1 commit 76d33da
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/stats/M31.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void GcodeSuite::M31() {
char buffer[22];
duration_t(print_job_timer.duration()).toString(buffer);

ui.set_status(buffer, ENABLED(DWIN_LCD_PROUI)); // No expire on ProUI
ui.set_status_no_expire(buffer);

SERIAL_ECHO_MSG("Print time: ", buffer);
}
6 changes: 5 additions & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,11 @@
#define HAS_MEDIA_SUBCALLS 1
#endif

#if ANY(SHOW_PROGRESS_PERCENT, SHOW_ELAPSED_TIME, SHOW_REMAINING_TIME, SHOW_INTERACTION_TIME) && !HAS_GRAPHICAL_TFT
#if ANY(SHOW_ELAPSED_TIME, SHOW_REMAINING_TIME, SHOW_INTERACTION_TIME)
#define HAS_TIME_DISPLAY 1
#endif

#if ANY(SHOW_PROGRESS_PERCENT, HAS_TIME_DISPLAY) && !HAS_GRAPHICAL_TFT
#define HAS_EXTRA_PROGRESS 1
#endif

Expand Down
21 changes: 11 additions & 10 deletions Marlin/src/lcd/dogm/fontdata/fontdata_6x9_marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#pragma once

/**
Fontname: -Misc-Fixed-Medium-R-Normal--9-90-75-75-C-60-ISO10646-1
Copyright: Public domain font. Share and enjoy.
Capital A Height: 6, '1' Height: 6
Calculated Max Values w= 6 h= 9 x= 5 y= 5 dx= 6 dy= 0 ascent= 7 len= 9
Font Bounding box w= 6 h= 9 x= 0 y=-2
Calculated Min Values x= 0 y=-2 dx= 0 dy= 0
Pure Font ascent = 6 descent=-2
X Font ascent = 6 descent=-2
Max Font ascent = 7 descent=-2
* Fontname: -Misc-Fixed-Medium-R-Normal--9-90-75-75-C-60-ISO10646-1
* Copyright: Public domain font. Share and enjoy.
* Capital A Height: 6, '1' Height: 6
* Calculated Max Values w= 6 h= 9 x= 5 y= 5 dx= 6 dy= 0 ascent= 7 len= 9
* Font Bounding box w= 6 h= 9 x= 0 y=-2
* Calculated Min Values x= 0 y=-2 dx= 0 dy= 0
* Pure Font ascent = 6 descent=-2
* X Font ascent = 6 descent=-2
* Max Font ascent = 7 descent=-2
*/
#include <U8glib-HAL.h>
const u8g_fntpgm_uint8_t u8g_font_6x9[2434] U8G_FONT_SECTION(".progmem.u8g_font_6x9") = {
Expand Down Expand Up @@ -186,4 +186,5 @@ const u8g_fntpgm_uint8_t u8g_font_6x9[2434] U8G_FONT_SECTION(".progmem.u8g_font_
0x00,0x50,0x00,0x90,0x90,0x90,0x70,0x04,0x09,0x09,0x06,0x01,0xFE,0x20,0x40,0x00,
0x90,0x90,0x90,0x70,0x90,0x60,0x04,0x08,0x08,0x06,0x01,0xFE,0x80,0x80,0xE0,0x90,
0x90,0xE0,0x80,0x80,0x04,0x08,0x08,0x06,0x01,0xFE,0x50,0x00,0x90,0x90,0x90,0x70,
0x90,0x60};
0x90,0x60
};
68 changes: 37 additions & 31 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@
#define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
#define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)

#define PCENTERED // Center percent value over progress bar, else right-align
#define PROGRESS_BAR_X TERN(PCENTERED, 54, 40)
#define PROGRESS_BAR_Y (EXTRAS_BASELINE + TERN(PCENTERED, 1, -3))
#define PCT_X TERN(PCENTERED, PROGRESS_BAR_X, LCD_PIXEL_WIDTH - TERN(PRINT_PROGRESS_SHOW_DECIMALS, 5, 4) * INFO_FONT_WIDTH)
#define PCT_Y (EXTRAS_BASELINE + TERN(PCENTERED, 0, 3))
#define PROGRESS_BAR_WIDTH TERN(PCENTERED, LCD_PIXEL_WIDTH - PROGRESS_BAR_X, PCT_X - PROGRESS_BAR_X - 1)
#define PROGRESS_BAR_HEIGHT TERN(PCENTERED, 4, 5)

#if DISABLED(PCENTERED) && HAS_TIME_DISPLAY
#error "PCENTERED is required for extra progress display options."
#endif

#if ANIM_HBCC
enum HeatBits : uint8_t {
DRAWBIT_HOTEND,
Expand Down Expand Up @@ -188,10 +200,6 @@
}
#endif

#define PROGRESS_BAR_X 54
#define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1)
#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)

FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, const uint8_t ty) {
const char *str;
uint8_t len;
Expand Down Expand Up @@ -471,46 +479,44 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
// Prepare strings for progress display
#if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS)
static MarlinUI::progress_t progress = 0;
static char bufferc[13];
static MString<12> progressString;
#endif

#if HAS_EXTRA_PROGRESS

static void prepare_time_string(const duration_t &time, char prefix) {
char str[13];
memset(&bufferc[2], 0x20, 5); // partialy fill with spaces to avoid artifacts and terminator
bufferc[0] = prefix;
bufferc[1] = ':';
int str_length = time.toDigital(str, time.value >= 60*60*24L);
strcpy(&bufferc[sizeof(bufferc) - str_length - 1], str);
}

#if HAS_TIME_DISPLAY
static void prepare_time_string(const duration_t &time, char prefix) {
char str[10];
const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars
progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces
}
#endif
#if ENABLED(SHOW_PROGRESS_PERCENT)
void MarlinUI::drawPercent() {
if (progress != 0) {
#define PCENTERED 1 // center percent value over progress bar, else align to the right
#define PPOS TERN(PCENTERED, 4, 0)
#define PLEN TERN(PRINT_PROGRESS_SHOW_DECIMALS, 4, 3)
memset(&bufferc, 0x20, 12);
memcpy(&bufferc[PPOS], TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))), PLEN);
bufferc[PPOS+PLEN] = '%';
}
if (progress == 0) return;
progressString.set(
OPTITEM(PCENTERED, spaces_t(4))
TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))), '%'
);
}
#endif
#if ENABLED(SHOW_REMAINING_TIME)
void MarlinUI::drawRemain() {
if (printJobOngoing() && get_remaining_time() != 0)
prepare_time_string(get_remaining_time(), 'R'); }
prepare_time_string(get_remaining_time(), 'R');
}
#endif
#if ENABLED(SHOW_INTERACTION_TIME)
void MarlinUI::drawInter() {
if (printingIsActive() && interaction_time)
prepare_time_string(interaction_time, 'C'); }
prepare_time_string(interaction_time, 'C');
}
#endif
#if ENABLED(SHOW_ELAPSED_TIME)
void MarlinUI::drawElapsed() {
if (printJobOngoing())
prepare_time_string(print_job_timer.duration(), 'E'); }
prepare_time_string(print_job_timer.duration(), 'E');
}
#endif

#endif // HAS_EXTRA_PROGRESS
Expand Down Expand Up @@ -779,17 +785,17 @@ void MarlinUI::draw_status_screen() {

#if HAS_PRINT_PROGRESS
// Progress bar frame
if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3))
u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4);
if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + PROGRESS_BAR_HEIGHT - 1))
u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT);

// Progress bar solid part
if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2))
u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2);
if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + PROGRESS_BAR_HEIGHT - 3))
u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, PROGRESS_BAR_HEIGHT - 2);

// Progress strings
if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
if (PAGE_CONTAINS(PCT_Y - INFO_FONT_ASCENT, PCT_Y - 1)) {
ui.rotate_progress();
lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, bufferc);
lcd_put_u8str(PCT_X, PCT_Y, progressString);
}
#endif

Expand Down
22 changes: 12 additions & 10 deletions Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,17 @@ bool ST7920_Lite_Status_Screen::indicators_changed() {
#if HAS_PRINT_PROGRESS
static char screenstr[8];

char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) {
static char str[6];
memset(&screenstr, 0x20, 8); // fill with spaces to avoid artifacts, not doing right-justification to save cycles
screenstr[0] = prefix;
TERN_(HOTENDS == 1, screenstr[1] = 0x07;) // add bullet • separator when there is space
int str_length = time.toDigital(str);
memcpy(&screenstr[TERN(HOTENDS == 1, 2, 1)], str, str_length); //memcpy because we can't have terminator
return screenstr;
}
#if HAS_TIME_DISPLAY
char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) {
static char str[6];
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts, not doing right-justification to save cycles
screenstr[0] = prefix;
TERN_(HOTENDS == 1, screenstr[1] = 0x07;) // add bullet • separator when there is space
int str_length = time.toDigital(str);
memcpy(&screenstr[TERN(HOTENDS == 1, 2, 1)], str, str_length); //memcpy because we can't have terminator
return screenstr;
}
#endif

void ST7920_Lite_Status_Screen::draw_progress_string(uint8_t addr, const char *str) {
set_ddram_address(addr);
Expand All @@ -687,7 +689,7 @@ bool ST7920_Lite_Status_Screen::indicators_changed() {
void ST7920_Lite_Status_Screen::drawPercent() {
#define LSHIFT TERN(HOTENDS == 1, 0, 1)
const uint8_t progress = ui.get_progress_percent();
memset(&screenstr, 0x20, 8); // fill with spaces to avoid artifacts
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts
if (progress){
memcpy(&screenstr[2 - LSHIFT], \
TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)), \
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/dogm/status_screen_lite_ST7920.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ class ST7920_Lite_Status_Screen {
static void draw_bed_temp(const int16_t temp, const int16_t target, bool forceUpdate=false);
static void draw_fan_speed(const uint8_t value);
#if HAS_PRINT_PROGRESS
#if HAS_TIME_DISPLAY
static char* prepare_time_string(const duration_t &time, char prefix=' ');
#endif
static void draw_progress_bar(const uint8_t value);
static char* prepare_time_string(const duration_t &time, char prefix=' ');
static void draw_progress_string(uint8_t addr, const char *str);
static void update_progress(const bool forceUpdate);
#endif
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus_e3s1pro/DGUSTxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void DGUSTxHandler::sdCardInsertionStatus(DGUS_VP &vp) {
}
#endif // PIDTEMPBED

static duration_t _PrintRemainingDurationEstimate() {
static duration_t _printRemainingDurationEstimate() {
duration_t remainingDuration = 0;

if (ExtUI::isPrinting()) {
Expand All @@ -120,12 +120,12 @@ static duration_t _PrintRemainingDurationEstimate() {
}

void DGUSTxHandler::printRemainingHours(DGUS_VP &vp) {
const int16_t data = _PrintRemainingDurationEstimate().hour();
const int16_t data = _printRemainingDurationEstimate().hour();
dgus.write((uint16_t)vp.addr, Endianness::toBE(data));
}

void DGUSTxHandler::printRemainingMinutes(DGUS_VP &vp) {
const int16_t data = _PrintRemainingDurationEstimate().minute() % 60;
const int16_t data = _printRemainingDurationEstimate().minute() % 60;
dgus.write((uint16_t)vp.addr, Endianness::toBE(data));
}

Expand Down

0 comments on commit 76d33da

Please sign in to comment.