Graphical TFT fixes, cleanup (#20861)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Tanguy Pruvot 2021-01-25 08:44:39 +01:00 committed by Scott Lahteine
parent 4ce87eeb91
commit 69da8719cf
14 changed files with 526 additions and 658 deletions

View File

@ -1155,36 +1155,37 @@
#endif
#endif
#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_320x240_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_320x240
#endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x320_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320
#endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x272_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x272
#if ENABLED(TFT_COLOR_UI)
#if TFT_HEIGHT == 240
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_320x240_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_320x240
#endif
#elif TFT_HEIGHT == 320
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x320_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320
#endif
#elif TFT_HEIGHT == 272
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x272_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x272
#endif
#endif
#endif
// Fewer lines with touch buttons on-screen
#if EITHER(TFT_320x240, TFT_320x240_SPI)
#define HAS_UI_320x240 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x320, TFT_480x320_SPI)
#define HAS_UI_480x320 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x272, TFT_480x272_SPI)
#define HAS_UI_480x272 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif
#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272)
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
#endif
// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'

View File

@ -802,8 +802,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if ENABLED(BABYSTEP_XY)
static_assert(BABYSTEP_MULTIPLICATOR_XY <= 0.25f, "BABYSTEP_MULTIPLICATOR_XY must be less than or equal to 0.25mm.");
#endif
#elif ENABLED(BABYSTEP_DISPLAY_TOTAL) && ANY(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)
#error "New Color UI (TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) does not support BABYSTEP_DISPLAY_TOTAL yet."
#endif
#endif

View File

@ -174,12 +174,13 @@ static inline void _lcd_level_bed_corners_get_next_position() {
MenuItem_static::draw(0, GET_TEXT(MSG_PROBING_MESH), SS_INVERT); // "Probing Mesh" heading
uint8_t cy = LCD_HEIGHT - 1, y = LCD_ROW_Y(cy);
uint8_t cy = TERN(TFT_COLOR_UI, 3, LCD_HEIGHT - 1), y = LCD_ROW_Y(cy);
// Display # of good points found vs total needed
if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
SETCURSOR(0, cy);
SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_GOOD_POINTS));
IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, cy));
lcd_put_u8str(GOOD_POINTS_TO_STR(good_points));
lcd_put_wchar('/');
lcd_put_u8str(GOOD_POINTS_TO_STR(nr_edge_points));
@ -190,8 +191,9 @@ static inline void _lcd_level_bed_corners_get_next_position() {
// Display the Last Z value
if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
SETCURSOR(0, cy);
SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_LAST_Z));
IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, 2));
lcd_put_u8str(LAST_Z_TO_STR(last_z));
}
}

View File

@ -71,9 +71,16 @@
const bool in_view = TERN1(HAS_MARLINUI_U8GLIB, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1));
if (in_view) {
TERN_(HAS_MARLINUI_U8GLIB, ui.set_font(FONT_MENU));
lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
#if ENABLED(TFT_COLOR_UI)
lcd_moveto(4, 3);
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
lcd_moveto(10, 3);
#else
lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
#endif
lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)]));
}
#endif

View File

@ -20,8 +20,11 @@
*
*/
#include "../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_TFT
#include "tft_image.h"
#include <stddef.h>
const tImage NoLogo = { nullptr, 0, 0, NOCOLORS };
@ -70,4 +73,38 @@ const tImage Leveling_32x32x4 = { (void *)leveling_32x32x4, 32, 32, GREYSC
const tImage Slider8x16x4 = { (void *)slider_8x16x4, 8, 16, GREYSCALE4 };
extern const tImage Images[imgCount];
const tImage Images[imgCount] = {
TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MARLIN_LOGO_FULL_SIZE), NoLogo),
HotEnd_64x64x4,
Bed_64x64x4,
Bed_Heated_64x64x4,
Chamber_64x64x4,
Chamber_Heated_64x64x4,
Fan0_64x64x4,
Fan_Slow0_64x64x4,
Fan_Slow1_64x64x4,
Fan_Fast0_64x64x4,
Fan_Fast1_64x64x4,
Feedrate_32x32x4,
Flowrate_32x32x4,
SD_64x64x4,
Menu_64x64x4,
Settings_64x64x4,
Directory_32x32x4,
Confirm_64x64x4,
Cancel_64x64x4,
Increase_64x64x4,
Decrease_64x64x4,
Back_32x32x4,
Up_32x32x4,
Down_32x32x4,
Left_32x32x4,
Right_32x32x4,
Refresh_32x32x4,
Leveling_32x32x4,
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
};
#endif // HAS_GRAPHICAL_TFT

View File

@ -21,9 +21,10 @@
*/
#pragma once
#include "stdint.h"
#include "../../inc/MarlinConfigPre.h"
#include <stdint.h>
extern const uint8_t marlin_logo_112x38x1[];
extern const uint8_t marlin_logo_228x255x2[];
extern const uint8_t marlin_logo_228x255x4[];

View File

@ -36,7 +36,7 @@ font_t *TFT_String::font_header;
uint8_t TFT_String::data[];
uint16_t TFT_String::span;
uint16_t TFT_String::length;
uint8_t TFT_String::length;
void TFT_String::set_font(const uint8_t *font) {
font_header = (font_t *)font;
@ -122,13 +122,14 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
eol();
}
void TFT_String::add(uint8_t *string) {
void TFT_String::add(uint8_t *string, uint8_t max_len) {
wchar_t wchar;
while (*string) {
while (*string && max_len) {
string = get_utf8_value_cb(string, read_byte, &wchar);
if (wchar > 255) wchar |= 0x0080;
uint8_t ch = uint8_t(wchar & 0x00FF);
add_character(ch);
max_len--;
}
eol();
}

View File

@ -69,7 +69,7 @@ class TFT_String {
static uint8_t data[MAX_STRING_LENGTH + 1];
static uint16_t span; // in pixels
static uint16_t length; // in characters
static uint8_t length; // in characters
static void add_character(uint8_t character);
static void eol() { data[length] = 0x00; }
@ -85,7 +85,7 @@ class TFT_String {
static void set();
static void add(uint8_t character) { add_character(character); eol(); }
static void add(uint8_t *string);
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr);
static void set(uint8_t *string) { set(); add(string); };
static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); };
@ -96,6 +96,9 @@ class TFT_String {
static void trim(uint8_t character=0x20);
static void rtrim(uint8_t character=0x20);
static void ltrim(uint8_t character=0x20);
static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
static uint16_t width() { return span; }
static uint8_t *string() { return data; }
static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }

View File

@ -24,7 +24,7 @@
#if HAS_UI_320x240
#include "ui_320x240.h"
#include "ui_common.h"
#include "../marlinui.h"
#include "../menu/menu.h"
@ -45,12 +45,6 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif
#if !HAS_LCD_MENU
#error "Seriously? High resolution TFT screen without menu?"
#endif
static bool draw_menu_navigation = false;
void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
if (draw_menu_navigation) {
@ -65,28 +59,6 @@ void MarlinUI::tft_idle() {
TERN_(TOUCH_SCREEN, touch.idle());
}
void MarlinUI::init_lcd() {
tft.init();
tft.set_font(MENU_FONT_NAME);
#ifdef SYMBOLS_FONT_NAME
tft.add_glyphs(SYMBOLS_FONT_NAME);
#endif
TERN_(TOUCH_SCREEN, touch.init());
clear_lcd();
}
bool MarlinUI::detected() { return true; }
void MarlinUI::clear_lcd() {
#if ENABLED(TOUCH_SCREEN)
touch.reset();
draw_menu_navigation = false;
#endif
tft.queue.reset();
tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
}
#if ENABLED(SHOW_BOOTSCREEN)
void MarlinUI::show_bootscreen() {
tft.queue.reset();
@ -98,8 +70,8 @@ void MarlinUI::clear_lcd() {
#define SITE_URL_Y (TFT_HEIGHT - 46)
tft.set_background(COLOR_BACKGROUND);
#else
#define BOOT_LOGO_W 320 // MarlinLogo320x240x16
#define BOOT_LOGO_H 240
#define BOOT_LOGO_W TFT_WIDTH // MarlinLogo320x240x16
#define BOOT_LOGO_H TFT_HEIGHT
#define SITE_URL_Y (TFT_HEIGHT - 52)
#endif
tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen);
@ -148,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
currentTemperature = thermalManager.degHotend(Heater);
targetTemperature = thermalManager.degTargetHotend(Heater);
}
#if HAS_HEATED_BED
else if (Heater == H_BED) {
currentTemperature = thermalManager.degBed();
targetTemperature = thermalManager.degTargetBed();
}
#endif // HAS_HEATED_BED
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
currentTemperature = thermalManager.degChamber();
#if HAS_HEATED_CHAMBER
targetTemperature = thermalManager.degTargetChamber();
#else
targetTemperature = ABSOLUTE_ZERO;
#endif
}
#endif // HAS_TEMP_CHAMBER
#if HAS_HEATED_BED
else if (Heater == H_BED) {
currentTemperature = thermalManager.degBed();
targetTemperature = thermalManager.degTargetBed();
}
#endif
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
currentTemperature = thermalManager.degChamber();
#if HAS_HEATED_CHAMBER
targetTemperature = thermalManager.degTargetChamber();
#else
targetTemperature = ABSOLUTE_ZERO;
#endif
}
#endif
else return;
TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 64, 100, Heater));
@ -176,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
if (currentTemperature >= 50) Color = COLOR_HOTEND;
}
#if HAS_HEATED_BED
else if (Heater == H_BED) {
if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
image = targetTemperature > 0 ? imgBedHeated : imgBed;
}
#endif // HAS_HEATED_BED
else if (Heater == H_BED) {
if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
image = targetTemperature > 0 ? imgBedHeated : imgBed;
}
#endif
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
if (currentTemperature >= 50) Color = COLOR_CHAMBER;
image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
}
#endif // HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
if (currentTemperature >= 50) Color = COLOR_CHAMBER;
image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
}
#endif
tft.add_image(0, 18, image, Color);
@ -200,7 +172,6 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
tft_string.add(LCD_STR_DEGREE);
tft_string.trim();
tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string);
}
}
@ -232,7 +203,7 @@ void MarlinUI::draw_status_screen() {
TERN_(TOUCH_SCREEN, touch.clear());
// heaters and fan
uint16_t i, x, y = POS_Y;
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);
@ -341,49 +312,6 @@ void MarlinUI::draw_status_screen() {
#endif
}
// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
menu_item(row);
tft_string.set(pstr, itemIndex, itemString);
if (vstr)
tft_string.add(vstr);
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
}
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
menu_item(row, sel);
uint8_t *string = (uint8_t *)pstr;
MarlinImage image = noImage;
switch (*string) {
case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
}
uint8_t offset = MENU_TEXT_X_OFFSET;
if (image != noImage) {
string++;
offset = 32;
tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
}
tft_string.set(string, itemIndex, itemString);
tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
menu_item(row, sel);
tft_string.set(pstr, itemIndex, itemString);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
if (data) {
tft_string.set(data);
tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
}
}
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal();
@ -483,16 +411,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif
}
#if ENABLED(SDSUPPORT)
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
menu_item(row, sel);
if (isDir)
tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
}
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
#if ENABLED(TOUCH_SCREEN)
touch.clear();
@ -513,6 +433,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
#endif // ADVANCED_PAUSE_FEATURE
#if ENABLED(AUTO_BED_LEVELING_UBL)
@ -562,18 +483,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft_string.trim();
tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32);
constexpr uint8_t w = (TFT_WIDTH) / 10;
tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, w, 32);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(x_plot));
tft_string.trim();
tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32);
tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, w, 32);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(y_plot));
tft_string.trim();
tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
#if ENABLED(TOUCH_SCREEN)
touch.clear();
@ -588,104 +509,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
}
#endif // AUTO_BED_LEVELING_UBL
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
void MarlinUI::touch_calibration_screen() {
uint16_t x, y;
calibrationState calibration_stage = touch_calibration.get_calibration_state();
if (calibration_stage == CALIBRATION_NONE) {
defer_status_screen(true);
clear_lcd();
calibration_stage = touch_calibration.calibration_start();
}
else {
x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
}
touch.clear();
if (calibration_stage < CALIBRATION_SUCCESS) {
switch (calibration_stage) {
case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
default: break;
}
x = touch_calibration.calibration_points[calibration_stage].x;
y = touch_calibration.calibration_points[calibration_stage].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
}
else {
tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
defer_status_screen(false);
touch_calibration.calibration_end();
touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
}
tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
tft.set_background(COLOR_BACKGROUND);
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
}
#endif // TOUCH_SCREEN_CALIBRATION
void menu_line(const uint8_t row, uint16_t color) {
tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32);
tft.set_background(color);
}
void menu_pause_option();
void menu_item(const uint8_t row, bool sel ) {
#if ENABLED(TOUCH_SCREEN)
if (row == 0) {
touch.clear();
draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
}
#endif
menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
#if ENABLED(TOUCH_SCREEN)
const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
touch.add_control(tct, 0, 2 + 34 * row, TFT_WIDTH, 32, encoderTopLine + row);
#endif
}
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43);
tft.set_background(COLOR_BACKGROUND);
}
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
tft_string.set();
tft_string.add(c);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
return tft_string.width();
}
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
tft_string.set(utf8_str_P);
tft_string.trim();
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
return tft_string.width();
}
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
return lcd_put_u8str_max_P(utf8_str, max_length);
}
void MarlinUI::move_axis_screen() {
}

View File

@ -21,88 +21,22 @@
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#define MARLIN_LOGO_FULL_SIZE MarlinLogo320x240x16
#include "tft.h"
#include "tft_image.h"
#define TFT_STATUS_TOP_Y 0
#define TFT_TOP_LINE_Y 2
#if ENABLED(TOUCH_SCREEN)
#include "touch.h"
#endif
#define MENU_TEXT_X_OFFSET 10
#define MENU_TEXT_Y_OFFSET 7
void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
#define MENU_ITEM_ICON_X 0
#define MENU_ITEM_ICON_Y 0
#define MENU_ITEM_ICON_SPACE 32
#define MENU_TEXT_X_OFFSET 10
#define MENU_TEXT_Y_OFFSET 7
void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
void menu_item(const uint8_t row, bool sel = false);
#define MENU_ITEM_HEIGHT 32
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)
#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols
#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols
#define ABSOLUTE_ZERO -273.15
const tImage Images[imgCount] = {
TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo320x240x16), NoLogo),
HotEnd_64x64x4,
Bed_64x64x4,
Bed_Heated_64x64x4,
Chamber_64x64x4,
Chamber_Heated_64x64x4,
Fan0_64x64x4,
Fan_Slow0_64x64x4,
Fan_Slow1_64x64x4,
Fan_Fast0_64x64x4,
Fan_Fast1_64x64x4,
Feedrate_32x32x4,
Flowrate_32x32x4,
SD_64x64x4,
Menu_64x64x4,
Settings_64x64x4,
Directory_32x32x4,
Confirm_64x64x4,
Cancel_64x64x4,
Increase_64x64x4,
Decrease_64x64x4,
Back_32x32x4,
Up_32x32x4,
Down_32x32x4,
Left_32x32x4,
Right_32x32x4,
Refresh_32x32x4,
Leveling_32x32x4,
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
};
#if HAS_TEMP_CHAMBER && HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_CHAMBER 3
#define ITEM_FAN 4
#define ITEMS_COUNT 5
#define POS_Y 0
#elif HAS_TEMP_CHAMBER
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_CHAMBER 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#define POS_Y 0
#elif HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#define POS_Y 0
#else
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_FAN 2
#define ITEMS_COUNT 3
#define POS_Y 0
#endif
#include "ui_common.h"

View File

@ -24,7 +24,7 @@
#if HAS_UI_480x320 || HAS_UI_480x272
#include "ui_480x320.h"
#include "ui_common.h"
#include "../marlinui.h"
#include "../menu/menu.h"
@ -45,14 +45,6 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif
#if !HAS_LCD_MENU
#error "Seriously? High resolution TFT screen without menu?"
#endif
#if ENABLED(TOUCH_SCREEN)
static bool draw_menu_navigation = false;
#endif
void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
if (draw_menu_navigation) {
@ -67,28 +59,6 @@ void MarlinUI::tft_idle() {
TERN_(TOUCH_SCREEN, touch.idle());
}
void MarlinUI::init_lcd() {
tft.init();
tft.set_font(MENU_FONT_NAME);
#ifdef SYMBOLS_FONT_NAME
tft.add_glyphs(SYMBOLS_FONT_NAME);
#endif
TERN_(TOUCH_SCREEN, touch.init());
clear_lcd();
}
bool MarlinUI::detected() { return true; }
void MarlinUI::clear_lcd() {
#if ENABLED(TOUCH_SCREEN)
touch.reset();
draw_menu_navigation = false;
#endif
tft.queue.reset();
tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
}
#if ENABLED(SHOW_BOOTSCREEN)
void MarlinUI::show_bootscreen() {
tft.queue.reset();
@ -100,8 +70,8 @@ void MarlinUI::clear_lcd() {
#define SITE_URL_Y (TFT_HEIGHT - 70)
tft.set_background(COLOR_BACKGROUND);
#else
#define BOOT_LOGO_W 480 // MarlinLogo480x320x16
#define BOOT_LOGO_H 320
#define BOOT_LOGO_W TFT_WIDTH // MarlinLogo480x320x16
#define BOOT_LOGO_H TFT_HEIGHT
#define SITE_URL_Y (TFT_HEIGHT - 90)
#endif
tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen);
@ -150,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
currentTemperature = thermalManager.degHotend(Heater);
targetTemperature = thermalManager.degTargetHotend(Heater);
}
#if HAS_HEATED_BED
else if (Heater == H_BED) {
currentTemperature = thermalManager.degBed();
targetTemperature = thermalManager.degTargetBed();
}
#endif // HAS_HEATED_BED
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
currentTemperature = thermalManager.degChamber();
#if HAS_HEATED_CHAMBER
targetTemperature = thermalManager.degTargetChamber();
#else
targetTemperature = ABSOLUTE_ZERO;
#endif
}
#endif // HAS_TEMP_CHAMBER
#if HAS_HEATED_BED
else if (Heater == H_BED) {
currentTemperature = thermalManager.degBed();
targetTemperature = thermalManager.degTargetBed();
}
#endif
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
currentTemperature = thermalManager.degChamber();
#if HAS_HEATED_CHAMBER
targetTemperature = thermalManager.degTargetChamber();
#else
targetTemperature = ABSOLUTE_ZERO;
#endif
}
#endif
else return;
TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 80, 120, Heater));
@ -178,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
if (currentTemperature >= 50) Color = COLOR_HOTEND;
}
#if HAS_HEATED_BED
else if (Heater == H_BED) {
if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
image = targetTemperature > 0 ? imgBedHeated : imgBed;
}
#endif // HAS_HEATED_BED
else if (Heater == H_BED) {
if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
image = targetTemperature > 0 ? imgBedHeated : imgBed;
}
#endif
#if HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
if (currentTemperature >= 50) Color = COLOR_CHAMBER;
image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
}
#endif // HAS_TEMP_CHAMBER
else if (Heater == H_CHAMBER) {
if (currentTemperature >= 50) Color = COLOR_CHAMBER;
image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
}
#endif
tft.add_image(8, 28, image, Color);
@ -233,7 +203,7 @@ void MarlinUI::draw_status_screen() {
TERN_(TOUCH_SCREEN, touch.clear());
// heaters and fan
uint16_t i, x, y = POS_Y;
uint16_t i, x, y = TFT_STATUS_TOP_Y;
for (i = 0 ; i < ITEMS_COUNT; i++) {
x = (TFT_WIDTH / ITEMS_COUNT - 80) / 2 + (TFT_WIDTH * i / ITEMS_COUNT);
@ -349,49 +319,6 @@ void MarlinUI::draw_status_screen() {
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
}
// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
menu_item(row);
tft_string.set(pstr, itemIndex, itemString);
if (vstr)
tft_string.add(vstr);
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
}
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
menu_item(row, sel);
uint8_t *string = (uint8_t *)pstr;
MarlinImage image = noImage;
switch (*string) {
case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
}
uint8_t offset = MENU_TEXT_X_OFFSET;
if (image != noImage) {
string++;
offset = 42;
tft.add_image(5, 5, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
}
tft_string.set(string, itemIndex, itemString);
tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
menu_item(row, sel);
tft_string.set(pstr, itemIndex, itemString);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
if (data) {
tft_string.set(data);
tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
}
}
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal();
@ -491,16 +418,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif
}
#if ENABLED(SDSUPPORT)
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
menu_item(row, sel);
if (isDir)
tft.add_image(5, 5, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
tft.add_text(42, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
}
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
#if ENABLED(TOUCH_SCREEN)
touch.clear();
@ -521,6 +440,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
}
#endif // ADVANCED_PAUSE_FEATURE
#if ENABLED(AUTO_BED_LEVELING_UBL)
@ -570,18 +490,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT);
constexpr uint8_t w = (TFT_WIDTH) / 10;
tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, w, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(x_plot));
tft_string.trim();
tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT);
tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, w, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(y_plot));
tft_string.trim();
tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
#if ENABLED(TOUCH_SCREEN)
touch.clear();
@ -596,97 +516,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
}
#endif // AUTO_BED_LEVELING_UBL
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
void MarlinUI::touch_calibration_screen() {
uint16_t x, y;
calibrationState calibration_stage = touch_calibration.get_calibration_state();
if (calibration_stage == CALIBRATION_NONE) {
defer_status_screen(true);
clear_lcd();
calibration_stage = touch_calibration.calibration_start();
}
else {
x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
}
touch.clear();
if (calibration_stage < CALIBRATION_SUCCESS) {
switch (calibration_stage) {
case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
default: break;
}
x = touch_calibration.calibration_points[calibration_stage].x;
y = touch_calibration.calibration_points[calibration_stage].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
}
else {
tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
defer_status_screen(false);
touch_calibration.calibration_end();
touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
}
tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
tft.set_background(COLOR_BACKGROUND);
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
}
#endif // TOUCH_SCREEN_CALIBRATION
void menu_line(const uint8_t row, uint16_t color) {
tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT);
tft.set_background(color);
}
void menu_pause_option();
void menu_item(const uint8_t row, bool sel ) {
#if ENABLED(TOUCH_SCREEN)
if (row == 0) {
touch.clear();
draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
}
#endif
menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
#if ENABLED(TOUCH_SCREEN)
const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
#endif
}
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43);
tft.set_background(COLOR_BACKGROUND);
}
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
tft_string.set(utf8_str_P);
tft_string.trim();
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
return tft_string.width();
}
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
return lcd_put_u8str_max_P(utf8_str, max_length);
}
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
#include "../../feature/babystep.h"
#endif
@ -889,37 +718,14 @@ static void moveAxis(AxisEnum axis, const int8_t direction) {
drawAxisValue(axis);
}
static void e_plus() {
moveAxis(E_AXIS, 1);
}
static void e_minus() {
moveAxis(E_AXIS, -1);
}
static void x_minus() {
moveAxis(X_AXIS, -1);
}
static void x_plus() {
moveAxis(X_AXIS, 1);
}
static void y_plus() {
moveAxis(Y_AXIS, 1);
}
static void y_minus() {
moveAxis(Y_AXIS, -1);
}
static void z_plus() {
moveAxis(Z_AXIS, 1);
}
static void z_minus() {
moveAxis(Z_AXIS, -1);
}
static void e_plus() { moveAxis(E_AXIS, 1); }
static void e_minus() { moveAxis(E_AXIS, -1); }
static void x_minus() { moveAxis(X_AXIS, -1); }
static void x_plus() { moveAxis(X_AXIS, 1); }
static void y_plus() { moveAxis(Y_AXIS, 1); }
static void y_minus() { moveAxis(Y_AXIS, -1); }
static void z_plus() { moveAxis(Z_AXIS, 1); }
static void z_minus() { moveAxis(Z_AXIS, -1); }
#if ENABLED(TOUCH_SCREEN)
static void e_select() {
@ -1002,8 +808,9 @@ void MarlinUI::move_axis_screen() {
const bool busy = printingIsActive();
// if we have baby step and we are printing, select baby step
if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
// Babysteps during printing? Select babystep for Z probe offset
if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET))
motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
// ROW 1 -> E- Y- CurY Z+
int x = X_MARGIN, y = Y_MARGIN, spacing = 0;
@ -1089,7 +896,7 @@ void MarlinUI::move_axis_screen() {
TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
}
// alinged with x+
// aligned with x+
drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));

View File

@ -21,97 +21,29 @@
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#define MARLIN_LOGO_FULL_SIZE MarlinLogo480x320x16
#include "tft.h"
#include "tft_image.h"
#include "ui_common.h"
#if ENABLED(TOUCH_SCREEN)
#include "touch.h"
#endif
#define TFT_STATUS_TOP_Y 4
#define TFT_TOP_LINE_Y 4
void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
#define MENU_TEXT_X_OFFSET 16
#define MENU_TEXT_Y_OFFSET 7
#define MENU_TEXT_X_OFFSET 16
#define MENU_TEXT_Y_OFFSET 7
void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
void menu_item(const uint8_t row, bool sel = false);
#define MENU_ITEM_ICON_X 5
#define MENU_ITEM_ICON_Y 5
#define MENU_ITEM_ICON_SPACE 42
#if HAS_UI_480x320
#define MENU_FONT_NAME Helvetica18
#define SYMBOLS_FONT_NAME Helvetica18_symbols
#define MENU_ITEM_HEIGHT 43
#define FONT_LINE_HEIGHT 34
#define MENU_FONT_NAME Helvetica18
#define SYMBOLS_FONT_NAME Helvetica18_symbols
#define MENU_ITEM_HEIGHT 43
#define FONT_LINE_HEIGHT 34
#elif HAS_UI_480x272
#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols
#define MENU_ITEM_HEIGHT 36
#define FONT_LINE_HEIGHT 24
#endif
#define ABSOLUTE_ZERO -273.15
const tImage Images[imgCount] = {
TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo480x320x16), NoLogo),
HotEnd_64x64x4,
Bed_64x64x4,
Bed_Heated_64x64x4,
Chamber_64x64x4,
Chamber_Heated_64x64x4,
Fan0_64x64x4,
Fan_Slow0_64x64x4,
Fan_Slow1_64x64x4,
Fan_Fast0_64x64x4,
Fan_Fast1_64x64x4,
Feedrate_32x32x4,
Flowrate_32x32x4,
SD_64x64x4,
Menu_64x64x4,
Settings_64x64x4,
Directory_32x32x4,
Confirm_64x64x4,
Cancel_64x64x4,
Increase_64x64x4,
Decrease_64x64x4,
Back_32x32x4,
Up_32x32x4,
Down_32x32x4,
Left_32x32x4,
Right_32x32x4,
Refresh_32x32x4,
Leveling_32x32x4,
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
};
#if HAS_TEMP_CHAMBER && HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_CHAMBER 3
#define ITEM_FAN 4
#define ITEMS_COUNT 5
#define POS_Y 4
#elif HAS_TEMP_CHAMBER
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_CHAMBER 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#define POS_Y 4
#elif HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#define POS_Y 4
#else
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_FAN 2
#define ITEMS_COUNT 3
#define POS_Y 4
#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols
#define MENU_ITEM_HEIGHT 36
#define FONT_LINE_HEIGHT 24
#endif
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)

View File

@ -0,0 +1,246 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfigPre.h"
#if HAS_GRAPHICAL_TFT
#include "ui_common.h"
#include "../lcdprint.h"
#include "../../libs/numtostr.h"
#include "../menu/menu.h"
void menu_pause_option();
static xy_uint_t cursor;
#if ENABLED(TOUCH_SCREEN)
bool draw_menu_navigation = false;
#endif
void menu_line(const uint8_t row, uint16_t color) {
cursor.set(0, row);
tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT);
tft.set_background(color);
}
void menu_item(const uint8_t row, bool sel ) {
#if ENABLED(TOUCH_SCREEN)
if (row == 0) {
touch.clear();
draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
}
#endif
menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
#if ENABLED(TOUCH_SCREEN)
const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
touch.add_control(tct, 0, TFT_TOP_LINE_Y + row * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
#endif
}
//
// lcdprint.h functions
//
#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
void lcd_gotopixel(const uint16_t x, const uint16_t y) {
if (x >= TFT_WIDTH) return;
cursor.set(x / (TFT_COL_WIDTH), y / MENU_LINE_HEIGHT);
tft.canvas(x, TFT_TOP_LINE_Y + y, (TFT_WIDTH) - x, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
}
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
lcd_gotopixel(int(col) * (TFT_COL_WIDTH), int(row) * MENU_LINE_HEIGHT);
}
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
if (max_length < 1) return 0;
tft_string.set();
tft_string.add(c);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT);
return tft_string.width();
}
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
if (max_length < 1) return 0;
tft_string.set(utf8_str_P);
tft_string.trim();
tft_string.truncate(max_length);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT);
return tft_string.width();
}
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
return lcd_put_u8str_max_P(utf8_str, max_length);
}
void lcd_put_int(const int i) {
// 3 digits max for this one...
const char* str = i16tostr3left(int16_t(i));
lcd_put_u8str_max(str, 3);
}
//
// Menu Item methods
//
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
menu_item(row, sel);
uint8_t *string = (uint8_t *)pstr;
MarlinImage image = noImage;
switch (*string) {
case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
}
uint8_t offset = MENU_TEXT_X_OFFSET;
if (image != noImage) {
string++;
offset = MENU_ITEM_ICON_SPACE;
tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
}
tft_string.set(string, itemIndex, itemString);
tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
menu_item(row, sel);
tft_string.set(pstr, itemIndex, itemString);
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
if (data) {
tft_string.set(data);
tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
}
}
// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
menu_item(row);
tft_string.set(pstr, itemIndex, itemString);
if (vstr)
tft_string.add(vstr);
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
}
#if ENABLED(SDSUPPORT)
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
menu_item(row, sel);
if (isDir)
tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
}
#endif
//
// MarlinUI methods
//
bool MarlinUI::detected() { return true; }
void MarlinUI::init_lcd() {
tft.init();
tft.set_font(MENU_FONT_NAME);
#ifdef SYMBOLS_FONT_NAME
tft.add_glyphs(SYMBOLS_FONT_NAME);
#endif
TERN_(TOUCH_SCREEN, touch.init());
clear_lcd();
}
void MarlinUI::clear_lcd() {
#if ENABLED(TOUCH_SCREEN)
touch.reset();
draw_menu_navigation = false;
#endif
tft.queue.reset();
tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
cursor.set(0, 0);
}
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
void MarlinUI::touch_calibration_screen() {
uint16_t x, y;
calibrationState calibration_stage = touch_calibration.get_calibration_state();
if (calibration_stage == CALIBRATION_NONE) {
defer_status_screen(true);
clear_lcd();
calibration_stage = touch_calibration.calibration_start();
}
else {
x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
}
touch.clear();
if (calibration_stage < CALIBRATION_SUCCESS) {
switch (calibration_stage) {
case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
default: break;
}
x = touch_calibration.calibration_points[calibration_stage].x;
y = touch_calibration.calibration_points[calibration_stage].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
}
else {
tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
defer_status_screen(false);
touch_calibration.calibration_end();
touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
}
tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
tft.set_background(COLOR_BACKGROUND);
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
}
#endif // TOUCH_SCREEN_CALIBRATION
#endif // HAS_GRAPHICAL_TFT

View File

@ -0,0 +1,76 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#if !HAS_LCD_MENU
#error "Seriously? High resolution TFT screen without menu?"
#endif
#include "tft.h"
#include "tft_image.h"
#if ENABLED(TOUCH_SCREEN)
#include "touch.h"
extern bool draw_menu_navigation;
#endif
#if HAS_UI_320x240
#include "ui_320x240.h"
#elif HAS_UI_480x320 || HAS_UI_480x272
#include "ui_480x320.h"
#endif
void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
void menu_item(const uint8_t row, bool sel = false);
#define ABSOLUTE_ZERO -273.15
#if HAS_TEMP_CHAMBER && HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_CHAMBER 3
#define ITEM_FAN 4
#define ITEMS_COUNT 5
#elif HAS_TEMP_CHAMBER
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_CHAMBER 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#elif HOTENDS > 1
#define ITEM_E0 0
#define ITEM_E1 1
#define ITEM_BED 2
#define ITEM_FAN 3
#define ITEMS_COUNT 4
#else
#define ITEM_E0 0
#define ITEM_BED 1
#define ITEM_FAN 2
#define ITEMS_COUNT 3
#endif