10 static const char *
const TAG =
"xpt2046";
29 ESP_LOGD(TAG,
"Falling penirq edge, forcing update");
51 this->
z_raw = z1 + 4095 - z2;
75 ESP_LOGV(TAG,
"Update [x, y] = [%d, %d], z = %d%s", this->
x_raw, this->
y_raw, this->
z_raw, (touch ?
" touched" :
""));
88 x_val = 0x7fff - x_val;
92 y_val = 0x7fff - y_val;
95 x_val = (int16_t)((
int) x_val * this->
x_dim_ / 0x7fff);
96 y_val = (int16_t)((
int) y_val * this->
y_dim_ / 0x7fff);
99 ESP_LOGD(TAG,
"Raw [x, y] = [%d, %d], transformed = [%d, %d]", this->
x_raw, this->
y_raw, x_val, y_val);
108 button->touch(this->
x, this->
y);
112 ESP_LOGD(TAG,
"Released [%d, %d]", this->
x, this->
y);
133 ESP_LOGCONFIG(TAG,
"XPT2046:");
135 LOG_PIN(
" IRQ Pin: ", this->
irq_pin_);
136 ESP_LOGCONFIG(TAG,
" X min: %d", this->
x_raw_min_);
137 ESP_LOGCONFIG(TAG,
" X max: %d", this->
x_raw_max_);
138 ESP_LOGCONFIG(TAG,
" Y min: %d", this->
y_raw_min_);
139 ESP_LOGCONFIG(TAG,
" Y max: %d", this->
y_raw_max_);
140 ESP_LOGCONFIG(TAG,
" X dim: %d", this->
x_dim_);
141 ESP_LOGCONFIG(TAG,
" Y dim: %d", this->
y_dim_);
143 ESP_LOGCONFIG(TAG,
" Swap X/Y");
145 ESP_LOGCONFIG(TAG,
" threshold: %d", this->
threshold_);
148 LOG_UPDATE_INTERVAL(
this);
157 da = (x >
y) ? x - y : y - x;
158 db = (x > z) ? x - z : z - x;
159 dc = (z >
y) ? z - y : y - z;
161 if (da <= db && da <= dc) {
163 }
else if (db <= da && db <= dc) {
175 if (val <= min_val) {
177 }
else if (val >= max_val) {
180 ret = (int16_t)((
int) 0x7fff * (val - min_val) / (max_val - min_val));
193 return ((data[0] << 8) | data[1]) >> 3;
199 bool touched = (x >= this->x_min_ && x <= this->x_max_ && y >= this->y_min_ && y <= this->y_max_);
202 this->publish_state(
true);
211 this->publish_state(
false);
212 this->state_ =
false;
const float DATA
For components that import data from directly connected sensors like DHT.
int16_t read_adc_(uint8_t ctrl)
void dump_config() override
static int16_t normalize(int16_t val, int16_t min_val, int16_t max_val)
XPT2046OnStateTrigger * on_state_trigger_
void write_byte(uint8_t data)
void set_calibration(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max)
Set the coordinates for the touch screen edges.
uint32_t IRAM_ATTR HOT millis()
float get_setup_priority() const override
bool touched
True if the component currently detects the touch.
virtual bool digital_read()=0
void process(int x, int y, bool touched)
void swap(optional< T > &x, optional< T > &y)
static int16_t best_two_avg(int16_t x, int16_t y, int16_t z)
void update() override
Read and process the values from the hardware.
std::vector< XPT2046Button * > buttons_
int16_t x
Coordinates of the touch position.
int16_t x_raw
Raw sensor values of the coordinates and the pressure.
void loop() override
Detect the touch if the irq pin is specified.