Improve Touch Calibration screen (#20524)
This commit is contained in:
@ -28,6 +28,7 @@ TouchCalibration touch_calibration;
|
||||
touch_calibration_t TouchCalibration::calibration;
|
||||
calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
|
||||
touch_calibration_point_t TouchCalibration::calibration_points[4];
|
||||
uint8_t TouchCalibration::failed_count;
|
||||
|
||||
void TouchCalibration::validate_calibration() {
|
||||
const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3);
|
||||
@ -44,6 +45,8 @@ void TouchCalibration::validate_calibration() {
|
||||
else {
|
||||
calibration_state = CALIBRATION_FAIL;
|
||||
calibration_reset();
|
||||
// Retry up to 5 times before reporting the failure
|
||||
if (need_calibration() && failed_count++ < 5) calibration_state = CALIBRATION_TOP_LEFT;
|
||||
}
|
||||
|
||||
if (calibration_state == CALIBRATION_SUCCESS) {
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
static void validate_calibration();
|
||||
|
||||
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 }; }
|
||||
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
|
||||
|
||||
@ -75,10 +76,15 @@ public:
|
||||
calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
|
||||
calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
|
||||
calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
|
||||
failed_count = 0;
|
||||
return calibration_state;
|
||||
}
|
||||
static void calibration_end() { calibration_state = CALIBRATION_NONE; }
|
||||
static calibrationState get_calibration_state() { return calibration_state; }
|
||||
static bool calibration_loaded() {
|
||||
if (need_calibration()) calibration_reset();
|
||||
return !need_calibration();
|
||||
}
|
||||
|
||||
static bool handleTouch(uint16_t x, uint16_t y);
|
||||
};
|
||||
|
Reference in New Issue
Block a user