Skip to content

Commit

Permalink
Make LVGL acts like COLORUI when touchscreen calibration is missing o…
Browse files Browse the repository at this point in the history
…r invalid
  • Loading branch information
X-Ryl669 committed Dec 21, 2020
1 parent 834a126 commit 2028e5e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
12 changes: 12 additions & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#include "../../../../feature/pause.h"
#endif

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
#endif

extern lv_group_t *g;
static lv_obj_t *scr, *tempText1, *filament_bar;

Expand Down Expand Up @@ -161,6 +166,13 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
else if (DIALOG_IS(REVERT_EEPROM_TIPS)) {
TERN_(EEPROM_SETTINGS, (void)settings.reset());
clear_cur_ui();
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
if (touch_calibration.need_calibration()) {
disp_state_stack._disp_index--; // We are asynchronous from the dialog, so let's remove the dialog from the stack
lv_draw_touch_calibration_screen();
}
else
#endif
draw_return_ui();
}
else if (DIALOG_IS(WIFI_CONFIG_TIPS)) {
Expand Down
13 changes: 13 additions & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include "../../../../module/temperature.h"
#include "../../../../inc/MarlinConfig.h"

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
#endif

#include <stdio.h>

//static lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
Expand Down Expand Up @@ -215,6 +220,14 @@ void lv_draw_ready_print(void) {
lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT);
}

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
// If calibration is required, let's trigger it now, handles the case when there is default value in configuration files
if (!touch_calibration.calibration_loaded()) {
lv_clear_ready_print();
lv_draw_touch_calibration_screen();
}
#endif
}

void lv_clear_ready_print() {
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_TC_RETURN:
TERN_(MKS_TEST, curent_disp_ui = 1);
lv_clear_touch_calibration_screen();
lv_draw_ready_print();
draw_return_ui();
break;
}
}

void lv_draw_touch_calibration_screen() {
disp_state_stack._disp_index = 0;
ZERO(disp_state_stack._disp_state);
// disp_state_stack._disp_index = 0;
// ZERO(disp_state_stack._disp_state);
scr = lv_screen_create(TOUCH_CALIBRATION_UI, "");

status_label = lv_label_create(scr, "");
Expand Down
7 changes: 1 addition & 6 deletions Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,7 @@ void tft_lvgl_init() {
#endif

if (ready) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
if (touch_calibration.need_calibration()) lv_draw_touch_calibration_screen();
else lv_draw_ready_print();
#else
lv_draw_ready_print();
#endif
lv_draw_ready_print();
}

if (mks_test_flag == 0x1E)
Expand Down
7 changes: 1 addition & 6 deletions Marlin/src/lcd/tft_io/touch_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ class TouchCalibration {
static touch_calibration_t calibration;
static uint8_t failed_count;
static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
// Don't nuke the current touchscreen calibration if it'll be replaced by invalid values, else it'll make navigation in the printer unusable
static void calibration_smart_reset() {
if (need_calibration() && (TOUCH_CALIBRATION_X || TOUCH_CALIBRATION_Y || TOUCH_OFFSET_X || TOUCH_OFFSET_Y)) calibration_reset();
else failed_count = (uint8_t)(-1); // Remember a reset was asked so we can substitute the value with a zeroed area if queried to save in EEPROM
}
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }

static calibrationState calibration_start() {
Expand All @@ -86,7 +81,7 @@ class TouchCalibration {
}
static void calibration_end() { calibration_state = CALIBRATION_NONE; }
static calibrationState get_calibration_state() { return calibration_state; }
static void calibration_loaded() { if (need_calibration()) calibration_reset(); }
static bool calibration_loaded() { if (!need_calibration()) return true; calibration_reset(); return need_calibration(); }

static bool handleTouch(uint16_t x, uint16_t y);
};
Expand Down
10 changes: 2 additions & 8 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,12 +1357,7 @@ void MarlinSettings::postprocess() {
// TOUCH_SCREEN_CALIBRATION
//
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
if (touch_calibration.failed_count != (uint8_t)-1) EEPROM_WRITE(touch_calibration.calibration);
else {
// Calibration should have been restored to a zero'd default yet it's in use (so it's not zero), so let's write zeros instead
for (uint8_t c = 0, t = 0; t < sizeof(touch_calibration.calibration); t++)
EEPROM_WRITE(c);
}
EEPROM_WRITE(touch_calibration.calibration);
#endif

//
Expand Down Expand Up @@ -2247,7 +2242,6 @@ void MarlinSettings::postprocess() {
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
_FIELD_TEST(touch_calibration_data);
EEPROM_READ(touch_calibration.calibration);
touch_calibration.calibration_loaded();
#endif

//
Expand Down Expand Up @@ -2579,7 +2573,7 @@ void MarlinSettings::reset() {
//
// TOUCH_SCREEN_CALIBRATION
//
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_smart_reset());
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());

//
// Buzzer enable/disable
Expand Down

0 comments on commit 2028e5e

Please sign in to comment.