Skip to content

Commit

Permalink
TFT: Enable displaying remaining time on 320x240 displays
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbogusz committed Oct 11, 2022
1 parent e121cba commit 5d8c96e
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 57 deletions.
197 changes: 142 additions & 55 deletions Marlin/src/lcd/tft/ui_320x240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,44 +221,42 @@ void MarlinUI::draw_status_screen() {

TERN_(TOUCH_SCREEN, touch.clear());

// heaters and fan
uint16_t i, x, y = TFT_STATUS_TOP_Y;

for (i = 0 ; i < ITEMS_COUNT; i++) {
x = (320 / ITEMS_COUNT - 64) / 2 + (320 * i / ITEMS_COUNT);
// 1st horizontal group - heaters and fans (height = 100)
for (uint16_t i = 0; i < ITEMS_COUNT; i++) {
uint16_t x = (320 / ITEMS_COUNT - 64) / 2 + (320 * i / ITEMS_COUNT);
switch (i) {
#ifdef ITEM_E0
case ITEM_E0: draw_heater_status(x, y, H_E0); break;
case ITEM_E0: draw_heater_status(x, TFT_STATUS_TOP_Y, H_E0); break;
#endif
#ifdef ITEM_E1
case ITEM_E1: draw_heater_status(x, y, H_E1); break;
case ITEM_E1: draw_heater_status(x, TFT_STATUS_TOP_Y, H_E1); break;
#endif
#ifdef ITEM_E2
case ITEM_E2: draw_heater_status(x, y, H_E2); break;
case ITEM_E2: draw_heater_status(x, TFT_STATUS_TOP_Y, H_E2); break;
#endif
#ifdef ITEM_BED
case ITEM_BED: draw_heater_status(x, y, H_BED); break;
case ITEM_BED: draw_heater_status(x, TFT_STATUS_TOP_Y, H_BED); break;
#endif
#ifdef ITEM_CHAMBER
case ITEM_CHAMBER: draw_heater_status(x, y, H_CHAMBER); break;
case ITEM_CHAMBER: draw_heater_status(x, TFT_STATUS_TOP_Y, H_CHAMBER); break;
#endif
#ifdef ITEM_COOLER
case ITEM_COOLER: draw_heater_status(x, y, H_COOLER); break;
case ITEM_COOLER: draw_heater_status(x, TFT_STATUS_TOP_Y, H_COOLER); break;
#endif
#ifdef ITEM_FAN
case ITEM_FAN: draw_fan_status(x, y, blink); break;
case ITEM_FAN: draw_fan_status(x, TFT_STATUS_TOP_Y, blink); break;
#endif
}
}

// coordinates
tft.canvas(4, 103, 312, 24);
// 2nd horizontal group - current coordinates (height = 24, top margin = 3)
tft.canvas(4, 103, 312, FONT_LINE_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft.add_rectangle(0, 0, 312, 24, COLOR_AXIS_HOMED);
tft.add_rectangle(0, 0, 312, FONT_LINE_HEIGHT, COLOR_AXIS_HOMED);

if (TERN0(LCD_SHOW_E_TOTAL, printingIsActive())) {
#if ENABLED(LCD_SHOW_E_TOTAL)
tft.add_text( 10, 3, COLOR_AXIS_HOMED , "E");
tft.add_text(10, 3, COLOR_AXIS_HOMED, "E");
const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm
tft_string.set(ftostr4sign(e_move_accumulator / escale));
tft_string.add(escale == 10 ? 'c' : 'm');
Expand All @@ -267,22 +265,23 @@ void MarlinUI::draw_status_screen() {
#endif
}
else {
tft.add_text( 10, 3, COLOR_AXIS_HOMED , "X");
tft.add_text(10, 3, COLOR_AXIS_HOMED, "X");
const bool nhx = axis_should_home(X_AXIS);
tft_string.set(blink && nhx ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
tft.add_text( 68 - tft_string.width(), 3, nhx ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
tft.add_text(68 - tft_string.width(), 3, nhx ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);

tft.add_text(127, 3, COLOR_AXIS_HOMED , "Y");
tft.add_text(127, 3, COLOR_AXIS_HOMED, "Y");
const bool nhy = axis_should_home(Y_AXIS);
tft_string.set(blink && nhy ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
tft.add_text(185 - tft_string.width(), 3, nhy ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
}

tft.add_text(219, 3, COLOR_AXIS_HOMED , "Z");
tft.add_text(219, 3, COLOR_AXIS_HOMED, "Z");
const bool nhz = axis_should_home(Z_AXIS);
uint16_t offset = 25;
if (blink && nhz)
if (blink && nhz) {
tft_string.set('?');
}
else {
const float z = LOGICAL_Z_POSITION(current_position.z);
tft_string.set(ftostr52sp((int16_t)z));
Expand All @@ -295,55 +294,144 @@ void MarlinUI::draw_status_screen() {
tft.add_text(301 - tft_string.width() - offset, 3, nhz ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 0, 103, 312, 24));

// 3rd horizontal group - controls and times (height = 64, top margin = 3)
// 3rd group, subgroup A - controls (on the sides)
#if ENABLED(TOUCH_SCREEN)
add_control(256, 130, menu_main, imgSettings);
TERN_(SDSUPPORT, add_control(0, 130, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
#endif

// 3rd group, subgroup B - speeds (center, top half)
// feed rate
tft.canvas(70, 136, 80, 32);
tft.canvas(70, 132, 80, 32);
tft.set_background(COLOR_BACKGROUND);
uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
tft.add_image(0, 0, imgFeedRate, color);
tft_string.set(i16tostr3rj(feedrate_percentage));
tft_string.add('%');
tft.add_text(32, 6, color , tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 70, 136, 80, 32));
tft.add_text(32, 6, color, tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 70, 132, 80, 32));

// flow rate
tft.canvas(170, 136, 80, 32);
tft.canvas(170, 132, 80, 32);
tft.set_background(COLOR_BACKGROUND);
color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
tft.add_image(0, 0, imgFlowRate, color);
tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
tft_string.add('%');
tft.add_text(32, 6, color , tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 170, 136, 80, 32, active_extruder));
tft.add_text(32, 6, color, tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 170, 132, 80, 32, active_extruder));

// 3rd group, subgroup C - times (center, bottom half)
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
#if ENABLED(SHOW_ELAPSED_TIME) && DISABLED(SHOW_REMAINING_TIME)
// Print duration so far (time elapsed) - centered
char elapsed_str[18];
duration_t elapsed = print_job_timer.duration();
elapsed.toString(elapsed_str, true);

const uint16_t time_str_width = 180;
const uint16_t image_width = 34;
tft.canvas((TFT_WIDTH - time_str_width) / 2, 164, time_str_width, 32);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(elapsed_str);
uint16_t text_pos_x = tft_string.center(time_str_width - image_width);
tft.add_image(text_pos_x, 0, imgTimeElapsed, COLOR_PRINT_TIME);
tft.add_text(text_pos_x + image_width, 1, COLOR_PRINT_TIME, tft_string);

#elif DISABLED(SHOW_ELAPSED_TIME) && ENABLED(SHOW_REMAINING_TIME)
// Print time remaining estimation - centered
char estimate_str[18];
duration_t elapsed = print_job_timer.duration();

// Get the estimate, first from M73
uint32_t estimate_remaining = (0
#if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
+ get_remaining_time()
#endif
);
// If no M73 estimate is available but we have progress data, calculate time remaining assuming time elapsed is linear with progress
if (!estimate_remaining && progress > 0) {
estimate_remaining = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
}

// Generate estimate string
if (!estimate_remaining) {
tft_string.set("N/A");
}
else {
duration_t estimation = estimate_remaining;
estimation.toString(estimate_str, true);
tft_string.set(estimate_str);
}

// print duration
char buffer[14];
duration_t elapsed = print_job_timer.duration();
elapsed.toDigital(buffer);
const uint16_t time_str_width = 180;
const uint16_t image_width = 34;
tft.canvas((TFT_WIDTH - time_str_width) / 2, 164, time_str_width, 32);
tft.set_background(COLOR_BACKGROUND);
color = printingIsActive() ? COLOR_PRINT_TIME : COLOR_INACTIVE;
uint16_t text_pos_x = tft_string.center(128 - image_width);
tft.add_image(text_pos_x, 0, imgTimeRemaining, color);
tft.add_text(text_pos_x + image_width, 1, color, tft_string);

#elif BOTH(SHOW_REMAINING_TIME, SHOW_ELAPSED_TIME)
// Print duration so far (time elapsed) - aligned under feed rate
char elapsed_str[18];
duration_t elapsed = print_job_timer.duration();
elapsed.toString(elapsed_str, true);

tft.canvas(70, 164, 88, 32);
tft.set_background(COLOR_BACKGROUND);
tft.add_image(0, 0, imgTimeElapsed, COLOR_PRINT_TIME);
tft_string.set(elapsed_str);
tft.add_text(34, 1, COLOR_PRINT_TIME, tft_string);

tft.canvas(96, 176, 128, 20);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(buffer);
tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
// Print time remaining estimation - aligned under flow rate
char estimate_str[18];

// progress bar
const uint8_t progress = ui.get_progress_percent();
tft.canvas(4, 198, 312, 9);
// Get the estimate, first from M73
uint32_t estimate_remaining = (0
#if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
+ get_remaining_time()
#endif
);
// If no M73 estimate is available but we have progress data, calculate time remaining assuming time elapsed is linear with progress
if (!estimate_remaining && progress > 0) {
estimate_remaining = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
}

// Generate estimate string
if (!estimate_remaining) {
tft_string.set("N/A");
}
else {
duration_t estimation = estimate_remaining;
estimation.toString(estimate_str, true);
tft_string.set(estimate_str);
}

// Push out the estimate to the screen
tft.canvas(162, 164, 88, 32);
tft.set_background(COLOR_BACKGROUND);
color = printingIsActive() ? COLOR_PRINT_TIME : COLOR_INACTIVE;
tft.add_image(0, 0, imgTimeRemaining, color);
tft.add_text(34, 1, color, tft_string);
#endif

// Fourth horizontal group - progress bar (height = 9, top margin = 4)
tft.canvas(4, 198, TFT_WIDTH - 8, 9);
tft.set_background(COLOR_PROGRESS_BG);
tft.add_rectangle(0, 0, 312, 9, COLOR_PROGRESS_FRAME);
if (progress)
tft.add_bar(1, 1, (310 * progress) / 100, 7, COLOR_PROGRESS_BAR);
tft.add_rectangle(0, 0, TFT_WIDTH - 8, 9, COLOR_PROGRESS_FRAME);
if (progress) {
tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress / (PROGRESS_SCALE)) / 100, 7, COLOR_PROGRESS_BAR);
}

// status message
tft.canvas(0, 216, 320, 20);
// Fifth horizontal group - status message (height = 20, top margin = 7, bottom margin = 6)
tft.canvas(0, 214, 320, 20);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(status_message);
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);

#if ENABLED(TOUCH_SCREEN)
add_control(256, 130, menu_main, imgSettings);
TERN_(SDSUPPORT, add_control(0, 130, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
#endif
}

// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
Expand Down Expand Up @@ -384,7 +472,6 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
#endif

if (ui.can_show_slider()) {

#define SLIDER_LENGTH 224
#define SLIDER_Y_POSITION 140

Expand Down Expand Up @@ -439,7 +526,7 @@ void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, con
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
#if ENABLED(TOUCH_SCREEN)
if (no) add_control( 48, TFT_HEIGHT - 64, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
if (no) add_control(48, TFT_HEIGHT - 64, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
if (yes) add_control(208, TFT_HEIGHT - 64, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
#endif
}
Expand All @@ -450,7 +537,7 @@ void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, con
#if ENABLED(TOUCH_SCREEN)
touch.clear();
draw_menu_navigation = false;
touch.add_control(RESUME_CONTINUE , 0, 0, TFT_WIDTH, TFT_HEIGHT);
touch.add_control(RESUME_CONTINUE, 0, 0, TFT_WIDTH, TFT_HEIGHT);
#endif

menu_line(row);
Expand Down Expand Up @@ -616,7 +703,7 @@ static void drawCurESelection() {
tft.canvas(motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set('E');
tft.add_text(0, 0, E_BTN_COLOR , tft_string);
tft.add_text(0, 0, E_BTN_COLOR, tft_string);
tft.add_text(tft_string.width(), 0, E_BTN_COLOR, ui8tostr3rj(motionAxisState.e_selection));
}

Expand Down Expand Up @@ -666,9 +753,9 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0;
const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment,
new_probe_offset = probe.offset.z + bsDiff,
new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET
, do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff
, new_probe_offset
new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET,
do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff,
new_probe_offset
);
if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
babystep.add_steps(Z_AXIS, babystep_increment);
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/tft/ui_320x240.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#define MARLIN_LOGO_FULL_SIZE MarlinLogo320x240x16

#include "ui_common.h"

#define TFT_STATUS_TOP_Y 0
#define TFT_TOP_LINE_Y 2

Expand All @@ -35,8 +37,7 @@

#define MENU_ITEM_HEIGHT 32
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)
#define FONT_LINE_HEIGHT 24

#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols

#include "ui_common.h"

0 comments on commit 5d8c96e

Please sign in to comment.