touch calibration screen for LVGL
This commit is contained in:
parent
8ca4ac15e0
commit
95c629a20e
6 changed files with 184 additions and 9 deletions
|
|
@ -27,6 +27,8 @@
|
||||||
#include "../gcode.h"
|
#include "../gcode.h"
|
||||||
#if DISABLED(TFT_LVGL_UI)
|
#if DISABLED(TFT_LVGL_UI)
|
||||||
#include "../../lcd/menu/menu.h"
|
#include "../../lcd/menu/menu.h"
|
||||||
|
#else
|
||||||
|
#include "../../lcd/extui/lib/mks_ui/draw_touch_calibration.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,7 +38,7 @@ void GcodeSuite::M995() {
|
||||||
#if DISABLED(TFT_LVGL_UI)
|
#if DISABLED(TFT_LVGL_UI)
|
||||||
ui.goto_screen(touch_screen_calibration);
|
ui.goto_screen(touch_screen_calibration);
|
||||||
#else
|
#else
|
||||||
//TODO: show LVGL UI calibration screen
|
lv_draw_touch_calibration_screen();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
118
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp
Normal file
118
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
* 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_TFT_LVGL_UI && ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
|
||||||
|
#include "draw_ui.h"
|
||||||
|
#include "draw_touch_calibration.h"
|
||||||
|
#include <lv_conf.h>
|
||||||
|
|
||||||
|
#include "../../../../inc/MarlinConfig.h"
|
||||||
|
#include "../../../tft_io/touch_calibration.h"
|
||||||
|
#include "SPI_TFT.h"
|
||||||
|
|
||||||
|
static lv_obj_t *scr;
|
||||||
|
static lv_obj_t *status_label;
|
||||||
|
|
||||||
|
static void event_handler(lv_obj_t *obj, lv_event_t event);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ID_TC_RETURN = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
static void drawCross(uint16_t x, uint16_t y, uint16_t color) {
|
||||||
|
SPI_TFT.tftio.set_window(x - 15, y, x + 15, y);
|
||||||
|
SPI_TFT.tftio.WriteMultiple(color, 31);
|
||||||
|
SPI_TFT.tftio.set_window(x, y - 15, x, y + 15);
|
||||||
|
SPI_TFT.tftio.WriteMultiple(color, 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_update_touch_calibration_screen() {
|
||||||
|
uint16_t x, y;
|
||||||
|
|
||||||
|
calibrationState calibration_stage = touch_calibration.get_calibration_state();
|
||||||
|
if (calibration_stage == CALIBRATION_NONE) {
|
||||||
|
// start and clear screen
|
||||||
|
calibration_stage = touch_calibration.calibration_start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// clear last cross
|
||||||
|
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;
|
||||||
|
drawCross(x, y, LV_COLOR_BACKGROUND.full);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *str = nullptr;
|
||||||
|
if (calibration_stage < CALIBRATION_SUCCESS) {
|
||||||
|
// handle current state
|
||||||
|
switch (calibration_stage) {
|
||||||
|
case CALIBRATION_TOP_LEFT: str = "Top Left"; break;
|
||||||
|
case CALIBRATION_BOTTOM_LEFT: str = "Bottom Left"; break;
|
||||||
|
case CALIBRATION_TOP_RIGHT: str = "Top Right"; break;
|
||||||
|
case CALIBRATION_BOTTOM_RIGHT: str = "Bottom Right"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = touch_calibration.calibration_points[calibration_stage].x;
|
||||||
|
y = touch_calibration.calibration_points[calibration_stage].y;
|
||||||
|
drawCross(x, y, LV_COLOR_WHITE.full);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// end calibration
|
||||||
|
str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed, send M995 to try again";
|
||||||
|
touch_calibration.calibration_end();
|
||||||
|
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_TC_RETURN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw current message
|
||||||
|
lv_label_set_text(status_label, str);
|
||||||
|
lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||||
|
if (event != LV_EVENT_RELEASED) return;
|
||||||
|
switch (obj->mks_obj_id) {
|
||||||
|
case ID_TC_RETURN:
|
||||||
|
TERN_(MKS_TEST, curent_disp_ui = 1);
|
||||||
|
lv_clear_touch_calibration_screen();
|
||||||
|
lv_draw_ready_print();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_draw_touch_calibration_screen(void) {
|
||||||
|
scr = lv_screen_create(TOUCH_CALIBRATION_UI, "");
|
||||||
|
|
||||||
|
status_label = lv_label_create(scr, "");
|
||||||
|
lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
|
||||||
|
lv_refr_now(lv_refr_get_disp_refreshing());
|
||||||
|
|
||||||
|
lv_update_touch_calibration_screen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_clear_touch_calibration_screen() {
|
||||||
|
lv_obj_del(scr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // HAS_TFT_LVGL_UI
|
||||||
35
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h
Normal file
35
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" { /* C-declarations for C++ */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void lv_draw_touch_calibration_screen(void);
|
||||||
|
extern void lv_clear_touch_calibration_screen();
|
||||||
|
extern void lv_update_touch_calibration_screen();
|
||||||
|
|
||||||
|
//extern void disp_temp_ready_print();
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* C-declarations for C++ */
|
||||||
|
#endif
|
||||||
|
|
@ -48,6 +48,10 @@
|
||||||
#include "../../../../feature/pause.h"
|
#include "../../../../feature/pause.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
#include "draw_touch_calibration.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
CFG_ITMES gCfgItems;
|
CFG_ITMES gCfgItems;
|
||||||
UI_CFG uiCfg;
|
UI_CFG uiCfg;
|
||||||
DISP_STATE_STACK disp_state_stack;
|
DISP_STATE_STACK disp_state_stack;
|
||||||
|
|
@ -1360,6 +1364,11 @@ void clear_cur_ui() {
|
||||||
lv_clear_encoder_settings();
|
lv_clear_encoder_settings();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
case TOUCH_CALIBRATION_UI:
|
||||||
|
lv_clear_touch_calibration_screen();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
//GUI_Clear();
|
//GUI_Clear();
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,8 @@ typedef enum {
|
||||||
EEPROM_SETTINGS_UI,
|
EEPROM_SETTINGS_UI,
|
||||||
WIFI_SETTINGS_UI,
|
WIFI_SETTINGS_UI,
|
||||||
HOMING_SENSITIVITY_UI,
|
HOMING_SENSITIVITY_UI,
|
||||||
ENCODER_SETTINGS_UI
|
ENCODER_SETTINGS_UI,
|
||||||
|
TOUCH_CALIBRATION_UI
|
||||||
} DISP_STATE;
|
} DISP_STATE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ XPT2046 touch;
|
||||||
#include "../../../../feature/powerloss.h"
|
#include "../../../../feature/powerloss.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
#include "../../../tft_io/touch_calibration.h"
|
||||||
|
#include "draw_touch_calibration.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
#ifndef TFT_WIDTH
|
#ifndef TFT_WIDTH
|
||||||
|
|
@ -240,17 +245,22 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) {
|
||||||
static bool get_point(int16_t *x, int16_t *y) {
|
static bool get_point(int16_t *x, int16_t *y) {
|
||||||
bool is_touched = touch.getRawPoint(x, y);
|
bool is_touched = touch.getRawPoint(x, y);
|
||||||
|
|
||||||
if (is_touched) {
|
if (!is_touched) return false;
|
||||||
|
|
||||||
|
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
const calibrationState state = touch_calibration.get_calibration_state();
|
||||||
|
if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) {
|
||||||
|
if (touch_calibration.handleTouch(*x, *y)) lv_update_touch_calibration_screen();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
|
||||||
|
*y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
|
||||||
|
#else
|
||||||
*x = int16_t((int32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
|
*x = int16_t((int32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
|
||||||
*y = int16_t((int32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
|
*y = int16_t((int32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
|
||||||
}
|
|
||||||
|
|
||||||
#if (TFT_ROTATION & TFT_ROTATE_180)
|
|
||||||
*x = int16_t((TFT_WIDTH) - (int)(*x));
|
|
||||||
*y = int16_t((TFT_HEIGHT) - (int)(*y));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return is_touched;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
|
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue