Skip to content

Commit 3f4eedb

Browse files
rmoravcikthinkyhead
authored andcommitted
Add M73 R to set remaining time
1 parent 328ddda commit 3f4eedb

File tree

6 files changed

+60
-31
lines changed

6 files changed

+60
-31
lines changed

Marlin/Configuration_adv.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,10 @@
908908
#if HAS_GRAPHICAL_LCD && HAS_PRINT_PROGRESS
909909
//#define PRINT_PROGRESS_SHOW_DECIMALS // Show progress with decimal digits
910910
//#define SHOW_REMAINING_TIME // Display estimated time to completion
911-
//#define ROTATE_PROGRESS_DISPLAY // Display (P)rogress, (E)lapsed, and (R)emaining time
911+
#if ENABLED(SHOW_REMAINING_TIME)
912+
//#define USE_M73_REMAINING_TIME // Use remaining time from M73 command instead of estimation
913+
//#define ROTATE_PROGRESS_DISPLAY // Display (P)rogress, (E)lapsed, and (R)emaining time
914+
#endif
912915
#endif
913916

914917
#if HAS_CHARACTER_LCD && HAS_PRINT_PROGRESS

Marlin/src/Marlin.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ void startOrResumeJob() {
380380
#if ENABLED(LCD_SHOW_E_TOTAL)
381381
e_move_accumulator = 0;
382382
#endif
383+
#if ENABLED(USE_M73_REMAINING_TIME)
384+
ui.reset_remaining_time();
385+
#endif
383386
}
384387
print_job_timer.start();
385388
}

Marlin/src/gcode/lcd/M73.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void GcodeSuite::M73() {
4343
? parser.value_float() * (PROGRESS_SCALE)
4444
: parser.value_byte()
4545
);
46+
#if ENABLED(USE_M73_REMAINING_TIME)
47+
if (parser.seen('R')) ui.set_remaining_time(60 * parser.value_ulong());
48+
#endif
4649
}
4750

4851
#endif // LCD_SET_PROGRESS_MANUALLY

Marlin/src/lcd/dogm/status_screen_DOGM.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,25 @@ void MarlinUI::draw_status_screen() {
455455

456456
#if ENABLED(SHOW_REMAINING_TIME)
457457
if (!(ev & 0x3)) {
458-
duration_t estimation = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
459-
if (estimation.value == 0) {
458+
uint32_t timeval = (0
459+
#if ENABLED(USE_M73_REMAINING_TIME)
460+
+ get_remaining_time()
461+
#endif
462+
);
463+
if (!timeval) timeval = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
464+
if (!timeval) {
460465
estimation_string[0] = '\0';
461466
estimation_x_pos = _SD_INFO_X(0);
462467
}
463468
else {
469+
duration_t estimation = timeval;
464470
const bool has_days = (estimation.value >= 60*60*24L);
465471
const uint8_t len = estimation.toDigital(estimation_string, has_days);
466-
#if BOTH(DOGM_SD_PERCENT, ROTATE_PROGRESS_DISPLAY)
467-
estimation_x_pos = _SD_INFO_X(len);
468-
#else
469-
estimation_x_pos = _SD_INFO_X(len + 1);
470-
#endif
472+
estimation_x_pos = _SD_INFO_X(len
473+
#if !BOTH(DOGM_SD_PERCENT, ROTATE_PROGRESS_DISPLAY)
474+
+ 1
475+
#endif
476+
);
471477
}
472478
}
473479
#endif

Marlin/src/lcd/ultralcd.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959

6060
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
6161
MarlinUI::progress_t MarlinUI::progress_override; // = 0
62+
#if ENABLED(USE_M73_REMAINING_TIME)
63+
uint32_t MarlinUI::remaining_time;
64+
#endif
6265
#endif
6366

6467
#if HAS_BUZZER

Marlin/src/lcd/ultralcd.h

+34-23
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,16 @@ class MarlinUI {
302302
static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
303303
static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
304304
static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
305+
#if ENABLED(USE_M73_REMAINING_TIME)
306+
static uint32_t remaining_time;
307+
FORCE_INLINE static void set_remaining_time(const uint32_t r) { remaining_time = r; }
308+
FORCE_INLINE static uint32_t get_remaining_time() { return remaining_time; }
309+
FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
310+
#endif
305311
#endif
306312
static progress_t _get_progress();
307313
#if HAS_PRINT_PROGRESS_PERMYRIAD
308-
static uint16_t get_progress_permyriad() { return _get_progress(); }
314+
FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
309315
#endif
310316
static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
311317
#else
@@ -319,9 +325,9 @@ class MarlinUI {
319325
static bool detected();
320326

321327
static LCDViewAction lcdDrawUpdate;
322-
static inline bool should_draw() { return bool(lcdDrawUpdate); }
323-
static inline void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
324-
static inline void refresh() { refresh(LCDVIEW_CLEAR_CALL_REDRAW); }
328+
FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
329+
FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
330+
FORCE_INLINE static void refresh() { refresh(LCDVIEW_CLEAR_CALL_REDRAW); }
325331

326332
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
327333
static void draw_custom_bootscreen(const uint8_t frame=0);
@@ -351,7 +357,7 @@ class MarlinUI {
351357
static void draw_progress_bar(const uint8_t percent);
352358
#if PROGRESS_MSG_EXPIRE > 0
353359
static millis_t expire_status_ms; // = 0
354-
static inline void reset_progress_bar_timeout() { expire_status_ms = 0; }
360+
FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
355361
#endif
356362
#endif
357363

@@ -362,7 +368,7 @@ class MarlinUI {
362368
#if HAS_LCD_CONTRAST
363369
static int16_t contrast;
364370
static void set_contrast(const int16_t value);
365-
static inline void refresh_contrast() { set_contrast(contrast); }
371+
FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
366372
#endif
367373

368374
#if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
@@ -470,18 +476,18 @@ class MarlinUI {
470476
#if ENABLED(TURBO_BACK_MENU_ITEM)
471477
// Various menu items require a "void (*)()" to point to
472478
// this function so a default argument *won't* work
473-
static inline void goto_previous_screen() { goto_previous_screen(false); }
479+
FORCE_INLINE static void goto_previous_screen() { goto_previous_screen(false); }
474480
#endif
475481

476482
static void return_to_status();
477483
static inline bool on_status_screen() { return currentScreen == status_screen; }
478-
static inline void run_current_screen() { (*currentScreen)(); }
484+
FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
479485

480486
#if ENABLED(LIGHTWEIGHT_UI)
481487
static void lcd_in_status(const bool inStatus);
482488
#endif
483489

484-
static inline void defer_status_screen(const bool defer=true) {
490+
FORCE_INLINE static void defer_status_screen(const bool defer=true) {
485491
#if LCD_TIMEOUT_TO_STATUS
486492
defer_return_to_status = defer;
487493
#else
@@ -499,7 +505,7 @@ class MarlinUI {
499505
#endif
500506

501507
#if ENABLED(G26_MESH_VALIDATION)
502-
static inline void chirp() {
508+
FORCE_INLINE static void chirp() {
503509
#if HAS_BUZZER
504510
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
505511
#endif
@@ -516,7 +522,7 @@ class MarlinUI {
516522

517523
static constexpr bool lcd_clicked = false;
518524
static constexpr bool on_status_screen() { return true; }
519-
static inline void run_current_screen() { status_screen(); }
525+
FORCE_INLINE static void run_current_screen() { status_screen(); }
520526

521527
#endif
522528

@@ -562,22 +568,27 @@ class MarlinUI {
562568

563569
#if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
564570
static int8_t encoderDirection;
565-
static inline void encoder_direction_normal() { encoderDirection = ENCODERBASE; }
566571
#else
567572
static constexpr int8_t encoderDirection = ENCODERBASE;
568-
static inline void encoder_direction_normal() {}
569573
#endif
570574

571-
#if ENABLED(REVERSE_MENU_DIRECTION)
572-
static inline void encoder_direction_menus() { encoderDirection = -(ENCODERBASE); }
573-
#else
574-
static inline void encoder_direction_menus() {}
575-
#endif
576-
#if ENABLED(REVERSE_SELECT_DIRECTION)
577-
static inline void encoder_direction_select() { encoderDirection = -(ENCODERBASE); }
578-
#else
579-
static inline void encoder_direction_select() {}
580-
#endif
575+
FORCE_INLINE static void encoder_direction_normal() {
576+
#if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
577+
encoderDirection = ENCODERBASE;
578+
#endif
579+
}
580+
581+
FORCE_INLINE static void encoder_direction_menus() {
582+
#if ENABLED(REVERSE_MENU_DIRECTION)
583+
encoderDirection = -(ENCODERBASE);
584+
#endif
585+
}
586+
587+
FORCE_INLINE static void encoder_direction_select() {
588+
#if ENABLED(REVERSE_SELECT_DIRECTION)
589+
encoderDirection = -(ENCODERBASE);
590+
#endif
591+
}
581592

582593
#else
583594

0 commit comments

Comments
 (0)