Support for TFT & Touch Screens (#18130)

This commit is contained in:
Alexander Gavrilenko
2020-07-30 09:43:19 +03:00
committed by Scott Lahteine
parent 3fbc002bad
commit 8f8b0d84ae
176 changed files with 14747 additions and 303 deletions

View File

@ -86,7 +86,7 @@ void MarlinUI::save_previous_screen() {
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
TERN(TURBO_BACK_MENU_ITEM,,constexpr bool is_back = false);
TERN_(TOUCH_BUTTONS, on_edit_screen = false);
TERN_(HAS_TOUCH_XPT2046, on_edit_screen = false);
if (screen_history_depth > 0) {
menuPosition &sh = screen_history[--screen_history_depth];
goto_screen(sh.menu_function,
@ -133,7 +133,7 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg
* MenuItem_int3::draw(encoderLine == _thisItemNr, _lcdLineNr, plabel, &feedrate_percentage, 10, 999)
*/
void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) {
TERN_(TOUCH_BUTTONS, ui.repeat_delay = BUTTON_DELAY_EDIT);
TERN_(HAS_TOUCH_XPT2046, ui.repeat_delay = BUTTON_DELAY_EDIT);
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
if (int32_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue;
if (ui.should_draw())
@ -155,7 +155,7 @@ void MenuEditItemBase::goto_edit_screen(
const screenFunc_t cb, // Callback after edit
const bool le // Flag to call cb() during editing
) {
TERN_(TOUCH_BUTTONS, ui.on_edit_screen = true);
TERN_(HAS_TOUCH_XPT2046, ui.on_edit_screen = true);
ui.screen_changed = true;
ui.save_previous_screen();
ui.refresh();
@ -214,7 +214,7 @@ bool printer_busy() {
void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
if (currentScreen != screen) {
TERN_(TOUCH_BUTTONS, repeat_delay = BUTTON_DELAY_MENU);
TERN_(HAS_TOUCH_XPT2046, repeat_delay = BUTTON_DELAY_MENU);
TERN_(LCD_SET_PROGRESS_MANUALLY, progress_reset());

View File

@ -652,3 +652,7 @@ void _lcd_draw_homing();
#if ENABLED(POWER_LOSS_RECOVERY)
void menu_job_recovery();
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
void touch_screen_calibration();
#endif

View File

@ -220,7 +220,7 @@ static PGM_P pause_header() {
#define HOTEND_STATUS_ITEM() do { \
if (_menuLineNr == _thisItemNr) { \
if (ui.should_draw()) { \
MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT); \
TERN(HAS_GRAPHICAL_TFT,, MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT)); \
ui.draw_hotend_status(_lcdLineNr, hotend_status_extruder); \
} \
if (_skipStatic && encoderLine <= _thisItemNr) { \

View File

@ -195,16 +195,21 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
if (axis == Z_AXIS && (SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
extern const char NUL_STR[];
SUBMENU_P(NUL_STR, []{ _goto_manual_move(float(SHORT_MANUAL_Z_MOVE)); });
MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
char tmp[20], numstr[10];
// Determine digits needed right of decimal
const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
!UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
char tmp[20], numstr[10];
// Determine digits needed right of decimal
const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
!UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
#if DISABLED(HAS_GRAPHICAL_TFT)
extern const char NUL_STR[];
SUBMENU_P(NUL_STR, []{ _goto_manual_move(float(SHORT_MANUAL_Z_MOVE)); });
MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
lcd_put_u8str(tmp);
MENU_ITEM_ADDON_END();
MENU_ITEM_ADDON_END();
#else
SUBMENU_P(tmp, []{ _goto_manual_move(float(SHORT_MANUAL_Z_MOVE)); });
#endif
}
}
END_MENU();

View File

@ -0,0 +1,34 @@
/**
* 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 ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "menu.h"
#include "../ultralcd.h"
void touch_screen_calibration() {
ui.touch_calibration();
}
#endif // TOUCH_SCREEN_CALIBRATION

View File

@ -68,6 +68,7 @@ static void _lcd_mesh_fine_tune(PGM_P const msg) {
const float rounded_f = rounded_mesh_value();
MenuEditItemBase::draw_edit_screen(msg, ftostr43sign(rounded_f));
TERN_(MESH_EDIT_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(rounded_f));
TERN_(HAS_GRAPHICAL_TFT, ui.refresh(LCDVIEW_NONE));
}
}
@ -77,6 +78,7 @@ static void _lcd_mesh_fine_tune(PGM_P const msg) {
float lcd_mesh_edit() { return rounded_mesh_value(); }
void lcd_mesh_edit_setup(const float &initial) {
TERN_(HAS_GRAPHICAL_TFT, ui.clear_lcd());
mesh_edit_accumulator = initial;
ui.goto_screen([]{ _lcd_mesh_fine_tune(GET_TEXT(MSG_MESH_EDIT_Z)); });
}
@ -456,8 +458,8 @@ void ubl_map_screen() {
do {
// Now, keep the encoder position within range
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS - 1;
if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = 0;
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS + TERN(TOUCH_SCREEN, ui.encoderPosition, -1);
if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = TERN(TOUCH_SCREEN, ui.encoderPosition - GRID_MAX_POINTS, 0);
// Draw the grid point based on the encoder
x = ui.encoderPosition % (GRID_MAX_POINTS_X);