Skip to content

Commit de31eb9

Browse files
committed
TFT: Enable displaying remaining time on 480xY displays
1 parent 5766e09 commit de31eb9

File tree

2 files changed

+81
-21
lines changed

2 files changed

+81
-21
lines changed

Marlin/src/inc/Conditionals_LCD.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,9 @@
15961596
#elif HAS_UI_1024x600
15971597
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 12, 13) // Fewer lines with touch buttons onscreen
15981598
#endif
1599+
#if ANY(HAS_UI_480x320, HAS_UI_480x272)
1600+
#define CAN_SHOW_REMAINING_TIME 1
1601+
#endif
15991602

16001603
// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
16011604
#if ENABLED(TOUCH_SCREEN)

Marlin/src/lcd/tft/ui_480x320.cpp

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ void MarlinUI::draw_status_screen() {
221221

222222
TERN_(TOUCH_SCREEN, touch.clear());
223223

224-
// heaters and fan
225224
uint16_t i, x, y = TFT_STATUS_TOP_Y;
226225

226+
// heaters and fan
227227
for (i = 0 ; i < ITEMS_COUNT; i++) {
228228
x = (TFT_WIDTH / ITEMS_COUNT - 80) / 2 + (TFT_WIDTH * i / ITEMS_COUNT);
229229
switch (i) {
@@ -298,57 +298,114 @@ void MarlinUI::draw_status_screen() {
298298

299299
y += TERN(HAS_UI_480x272, 38, 48);
300300
// feed rate
301-
tft.canvas(96, y, 100, 32);
301+
tft.canvas(96, y, 144, 32);
302302
tft.set_background(COLOR_BACKGROUND);
303303
uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
304304
tft.add_image(0, 0, imgFeedRate, color);
305305
tft_string.set(i16tostr3rj(feedrate_percentage));
306306
tft_string.add('%');
307-
tft.add_text(36, 1, color , tft_string);
307+
tft.add_text(36, 1, color, tft_string);
308308
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32));
309309

310310
// flow rate
311-
tft.canvas(284, y, 100, 32);
311+
tft.canvas(256, y, 144, 32);
312312
tft.set_background(COLOR_BACKGROUND);
313313
color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
314314
tft.add_image(0, 0, imgFlowRate, color);
315315
tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
316316
tft_string.add('%');
317-
tft.add_text(36, 1, color , tft_string);
317+
tft.add_text(36, 1, color, tft_string);
318318
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder));
319319

320320
#if ENABLED(TOUCH_SCREEN)
321-
add_control(404, y, menu_main, imgSettings);
322-
TERN_(SDSUPPORT, add_control(12, y, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
321+
uint16_t controls_y_offset = TERN(HAS_UI_480x272, 4, 8);
322+
add_control(404, y + controls_y_offset, menu_main, imgSettings);
323+
#if ENABLED(SDSUPPORT)
324+
color = card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED;
325+
add_control(12, y + controls_y_offset, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, color);
326+
#endif
323327
#endif
324328

325329
y += TERN(HAS_UI_480x272, 36, 44);
326-
// print duration
327-
char buffer[14];
328-
duration_t elapsed = print_job_timer.duration();
329-
elapsed.toDigital(buffer);
330330

331-
tft.canvas((TFT_WIDTH - 128) / 2, y, 128, 29);
332-
tft.set_background(COLOR_BACKGROUND);
333-
tft_string.set(buffer);
334-
tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
331+
#if DISABLED(SHOW_REMAINING_TIME)
332+
// print duration so far (time elapsed) - centered
333+
char elapsed_str[22];
334+
duration_t elapsed = print_job_timer.duration();
335+
elapsed.toString(elapsed_str);
336+
337+
// Same width constraints as feedrate/flowrate controls
338+
uint16_t time_str_width = 288;
339+
uint16_t image_width = 36;
335340

336-
y += TERN(HAS_UI_480x272, 28, 36);
341+
tft.canvas((TFT_WIDTH - time_str_width) / 2, y, time_str_width, 32);
342+
tft.set_background(COLOR_BACKGROUND);
343+
tft_string.set(elapsed_str);
344+
uint16_t text_pos_x = tft_string.center(time_str_width - image_width);
345+
tft.add_image(text_pos_x, 0, imgFeedRate, COLOR_PRINT_TIME);
346+
tft.add_text(text_pos_x + image_width, 1, COLOR_PRINT_TIME, tft_string);
347+
#else
348+
// Print duration so far (time elapsed) - aligned under feed rate
349+
char elapsed_str[18];
350+
duration_t elapsed = print_job_timer.duration();
351+
elapsed.toString(elapsed_str, true);
352+
353+
tft.canvas(96, y, 144, 32);
354+
tft.set_background(COLOR_BACKGROUND);
355+
tft.add_image(0, 0, imgFeedRate, COLOR_PRINT_TIME);
356+
tft_string.set(elapsed_str);
357+
tft.add_text(36, 1, COLOR_PRINT_TIME, tft_string);
358+
359+
// Print time remaining estimation - aligned under flow rate
360+
char estimate_str[18];
361+
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
362+
363+
// Get the estimate, first from M73
364+
uint32_t estimate_remaining = (0
365+
#if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
366+
+ get_remaining_time()
367+
#endif
368+
);
369+
// If no M73 estimate is available but we have progress data, calculate time remaining assuming time elapsed is linear with progress
370+
if (!estimate_remaining && progress > 0) {
371+
estimate_remaining = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
372+
}
373+
374+
// Generate estimate string
375+
if (!estimate_remaining) {
376+
tft_string.set("N/A");
377+
}
378+
else {
379+
duration_t estimation = estimate_remaining;
380+
estimation.toString(estimate_str, true);
381+
tft_string.set(estimate_str);
382+
}
383+
384+
// Push out the estimate to the screen
385+
tft.canvas(256, y, 144, 32);
386+
tft.set_background(COLOR_BACKGROUND);
387+
color = printingIsActive() ? COLOR_PRINT_TIME : COLOR_INACTIVE;
388+
tft.add_image(0, 0, imgFeedRate, color);
389+
tft.add_text(36, 1, color, tft_string);
390+
#endif
391+
392+
y += TERN(HAS_UI_480x272, 36, 44);
337393
// progress bar
338-
const uint8_t progress = ui.get_progress_percent();
339394
tft.canvas(4, y, TFT_WIDTH - 8, 9);
340395
tft.set_background(COLOR_PROGRESS_BG);
341396
tft.add_rectangle(0, 0, TFT_WIDTH - 8, 9, COLOR_PROGRESS_FRAME);
342397
if (progress)
343-
tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress) / 100, 7, COLOR_PROGRESS_BAR);
398+
tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress / (PROGRESS_SCALE)) / 100, 7, COLOR_PROGRESS_BAR);
344399

345-
y += 20;
400+
y += 12;
346401
// status message
347-
tft.canvas(0, y, TFT_WIDTH, FONT_LINE_HEIGHT - 5);
402+
// canvas height should be 40px on 480x320 and 28 on 480x272
403+
uint16_t status_height = TFT_HEIGHT - y;
404+
tft.canvas(0, y, TFT_WIDTH, status_height);
348405
tft.set_background(COLOR_BACKGROUND);
349406
tft_string.set(status_message);
350407
tft_string.trim();
351-
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
408+
tft.add_text(tft_string.center(TFT_WIDTH), (status_height - FONT_LINE_HEIGHT) / 2, COLOR_STATUS_MESSAGE, tft_string);
352409
}
353410

354411
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace

0 commit comments

Comments
 (0)