Add Touch Calibration screen (#20049)

This commit is contained in:
Victor Oliveira
2020-11-15 19:39:58 -03:00
committed by GitHub
parent cab83ba840
commit ea371618da
45 changed files with 845 additions and 904 deletions

View File

@@ -23,42 +23,16 @@
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(TOUCH_SCREEN)
#include "tft_color.h"
#include "tft_image.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"
#endif
#include HAL_PATH(../../HAL, tft/xpt2046.h)
#define TOUCH_DRIVER XPT2046
#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
#endif
#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS
#define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500
#endif
#define TOUCH_ORIENTATION_NONE 0
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2
#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION))
#if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET)
#define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION
#define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#else
#define TOUCH_CALIBRATION_X 0
#define TOUCH_CALIBRATION_Y 0
#define TOUCH_OFFSET_X 0
#define TOUCH_OFFSET_Y 0
#define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE
#endif
#endif
// Menu Navigation
extern int8_t encoderTopLine, encoderLine, screen_items;
@@ -101,31 +75,6 @@ typedef struct __attribute__((__packed__)) {
intptr_t data;
} touch_control_t;
typedef struct __attribute__((__packed__)) {
int32_t x;
int32_t y;
int16_t offset_x;
int16_t offset_y;
uint8_t orientation;
} touch_calibration_t;
typedef struct __attribute__((__packed__)) {
uint16_t x;
uint16_t y;
int16_t raw_x;
int16_t raw_y;
} touch_calibration_point_t;
enum calibrationState : uint8_t {
CALIBRATION_POINT_1 = 0x00,
CALIBRATION_POINT_2,
CALIBRATION_POINT_3,
CALIBRATION_POINT_4,
CALIBRATION_SUCCESS,
CALIBRATION_FAIL,
CALIBRATION_NONE,
};
#define MAX_CONTROLS 16
#define MINIMUM_HOLD_TIME 15
#define TOUCH_REPEAT_DELAY 75
@@ -150,15 +99,6 @@ class Touch {
static void touch(touch_control_t *control);
static void hold(touch_control_t *control, millis_t delay = 0);
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
static calibrationState calibration_state;
static touch_calibration_point_t calibration_points[4];
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); }
#endif // TOUCH_SCREEN_CALIBRATION
public:
static void init();
static void reset() { controls_count = 0; touch_time = 0; current_control = NULL; }
@@ -175,17 +115,6 @@ class Touch {
static void enable() { enabled = true; }
static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
static touch_calibration_t calibration;
static void calibration_reset() { calibration = {TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION}; }
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
static calibrationState calibration_start() { calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; return calibration_state = CALIBRATION_POINT_1; }
static void calibration_end() { calibration_state = CALIBRATION_NONE; }
static calibrationState get_calibration_state() { return calibration_state; }
#endif // TOUCH_SCREEN_CALIBRATION
};
extern Touch touch;
#endif // TOUCH_SCREEN