Skip to content

Commit 85675e4

Browse files
thisiskeithbernisv
authored andcommitted
🩹 Fix Touch Calibration first point (MarlinFirmware#25298)
1 parent 0fb3ed4 commit 85675e4

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ void lv_encoder_pin_init() {
494494
}
495495

496496
#if 1 // HAS_ENCODER_ACTION
497+
497498
void lv_update_encoder() {
498499
static uint32_t encoder_time1;
499500
uint32_t tmpTime, diffTime = 0;
@@ -554,7 +555,7 @@ void lv_encoder_pin_init() {
554555

555556
#endif // HAS_ENCODER_WHEEL
556557

557-
} // next_button_update_ms
558+
} // encoder_time1
558559
}
559560

560561
#endif // HAS_ENCODER_ACTION

Marlin/src/lcd/tft/touch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void Touch::touch(touch_control_t *control) {
152152
case CALIBRATE:
153153
if (touch_calibration.handleTouch(x, y)) ui.refresh();
154154
break;
155-
#endif // TOUCH_SCREEN_CALIBRATION
155+
#endif
156156

157157
case MENU_SCREEN: ui.goto_screen((screenFunc_t)control->data); break;
158158
case BACK: ui.goto_previous_screen(); break;

Marlin/src/lcd/tft_io/touch_calibration.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ touch_calibration_t TouchCalibration::calibration;
4141
calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
4242
touch_calibration_point_t TouchCalibration::calibration_points[4];
4343
uint8_t TouchCalibration::failed_count;
44+
millis_t TouchCalibration::next_touch_update_ms; // = 0;
4445

4546
void TouchCalibration::validate_calibration() {
4647
#define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B)
@@ -89,11 +90,11 @@ void TouchCalibration::validate_calibration() {
8990
}
9091
}
9192

92-
bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) {
93-
static millis_t next_button_update_ms = 0;
93+
bool TouchCalibration::handleTouch(const uint16_t x, const uint16_t y) {
9494
const millis_t now = millis();
95-
if (PENDING(now, next_button_update_ms)) return false;
96-
next_button_update_ms = now + BUTTON_DELAY_MENU;
95+
96+
if (next_touch_update_ms && PENDING(now, next_touch_update_ms)) return false;
97+
next_touch_update_ms = now + BUTTON_DELAY_MENU;
9798

9899
if (calibration_state < CALIBRATION_SUCCESS) {
99100
calibration_points[calibration_state].raw_x = x;

Marlin/src/lcd/tft_io/touch_calibration.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ class TouchCalibration {
5757
public:
5858
static calibrationState calibration_state;
5959
static touch_calibration_point_t calibration_points[4];
60+
static millis_t next_touch_update_ms;
6061

6162
static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; }
6263
static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); }
6364
static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); }
6465
static void validate_calibration();
6566

6667
static touch_calibration_t calibration;
67-
static uint8_t failed_count;
68+
static uint8_t failed_count;
6869
static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
6970
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
7071

7172
static calibrationState calibration_start() {
73+
next_touch_update_ms = millis() + 750UL;
7274
calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE };
7375
calibration_state = CALIBRATION_TOP_LEFT;
7476
calibration_points[CALIBRATION_TOP_LEFT].x = 30;
@@ -89,7 +91,7 @@ class TouchCalibration {
8991
return !need_calibration();
9092
}
9193

92-
static bool handleTouch(uint16_t x, uint16_t y);
94+
static bool handleTouch(const uint16_t x, const uint16_t y);
9395
};
9496

9597
extern TouchCalibration touch_calibration;

Marlin/src/lcd/touch/touch_buttons.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ uint8_t TouchButtons::read_buttons() {
9191
y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
9292
#endif
9393
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
94-
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? touchIO.getPoint(&y, &x) : touchIO.getPoint(&x, &y));
94+
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? touchIO.getPoint(&y, &x) : touchIO.getPoint(&x, &y));
9595
if (!is_touched) return 0;
9696
#endif
9797

0 commit comments

Comments
 (0)