Skip to content

Commit

Permalink
🩹 Fix Touch Calibration first point (MarlinFirmware#25298)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisiskeithb authored and Andy-Big committed Jul 11, 2023
1 parent 9a26873 commit bb03a14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ void lv_encoder_pin_init() {
}

#if 1 // HAS_ENCODER_ACTION

void lv_update_encoder() {
static uint32_t encoder_time1;
uint32_t tmpTime, diffTime = 0;
Expand Down Expand Up @@ -552,7 +553,7 @@ void lv_encoder_pin_init() {

#endif // HAS_ENCODER_WHEEL

} // next_button_update_ms
} // encoder_time1
}

#endif // HAS_ENCODER_ACTION
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void Touch::touch(touch_control_t *control)
case CALIBRATE:
if (touch_calibration.handleTouch(x, y)) ui.refresh();
break;
#endif // TOUCH_SCREEN_CALIBRATION
#endif

case MENU_SCREEN: ui.push_current_screen(); ui.goto_screen((screenFunc_t)control->data); break;

Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/lcd/tft_io/touch_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ touch_calibration_t TouchCalibration::calibration;
calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
touch_calibration_point_t TouchCalibration::calibration_points[4];
uint8_t TouchCalibration::failed_count;
millis_t TouchCalibration::next_touch_update_ms; // = 0;

void TouchCalibration::validate_calibration() {
#define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B)
Expand Down Expand Up @@ -90,11 +91,11 @@ void TouchCalibration::validate_calibration() {
}
}

bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) {
static millis_t next_button_update_ms = 0;
bool TouchCalibration::handleTouch(const uint16_t x, const uint16_t y) {
const millis_t now = millis();
if (PENDING(now, next_button_update_ms)) return false;
next_button_update_ms = now + BUTTON_DELAY_MENU;

if (next_touch_update_ms && PENDING(now, next_touch_update_ms)) return false;
next_touch_update_ms = now + BUTTON_DELAY_MENU;

if (calibration_state < CALIBRATION_SUCCESS) {
calibration_points[calibration_state].raw_x = x;
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/lcd/tft_io/touch_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ class TouchCalibration {
public:
static calibrationState calibration_state;
static touch_calibration_point_t calibration_points[4];
static millis_t next_touch_update_ms;

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

static touch_calibration_t calibration;
static uint8_t failed_count;
static uint8_t failed_count;
static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }

static calibrationState calibration_start() {
next_touch_update_ms = millis() + 750UL;
calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE };
calibration_state = CALIBRATION_TOP_LEFT;
calibration_points[CALIBRATION_TOP_LEFT].x = 30;
Expand All @@ -89,7 +91,7 @@ class TouchCalibration {
return !need_calibration();
}

static bool handleTouch(uint16_t x, uint16_t y);
static bool handleTouch(const uint16_t x, const uint16_t y);
};

extern TouchCalibration touch_calibration;
2 changes: 1 addition & 1 deletion Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ uint8_t TouchButtons::read_buttons() {
y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? touchIO.getPoint(&y, &x) : touchIO.getPoint(&x, &y));
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? touchIO.getPoint(&y, &x) : touchIO.getPoint(&x, &y));
if (!is_touched) return 0;
#endif

Expand Down

0 comments on commit bb03a14

Please sign in to comment.