touchscreen driver fixes (#6356)

This commit is contained in:
Clyde Stubbs 2024-03-13 05:20:16 +11:00 committed by GitHub
parent f5b02056b9
commit f264151537
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -71,7 +71,7 @@ class FT5x06Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice
this->x_raw_max_ = this->display_->get_native_width(); this->x_raw_max_ = this->display_->get_native_width();
} }
if (this->y_raw_max_ == this->y_raw_min_) { if (this->y_raw_max_ == this->y_raw_min_) {
this->x_raw_max_ = this->display_->get_native_height(); this->y_raw_max_ = this->display_->get_native_height();
} }
} }
esph_log_config(TAG, "FT5x06 Touchscreen setup complete"); esph_log_config(TAG, "FT5x06 Touchscreen setup complete");

View File

@ -39,7 +39,6 @@ void Touchscreen::loop() {
ESP_LOGVV(TAG, "<< Do Touch loop >>"); ESP_LOGVV(TAG, "<< Do Touch loop >>");
this->first_touch_ = this->touches_.empty(); this->first_touch_ = this->touches_.empty();
this->need_update_ = false; this->need_update_ = false;
this->was_touched_ = this->is_touched_;
this->is_touched_ = false; this->is_touched_ = false;
this->skip_update_ = false; this->skip_update_ = false;
for (auto &tp : this->touches_) { for (auto &tp : this->touches_) {
@ -62,7 +61,11 @@ void Touchscreen::loop() {
if (this->touch_timeout_ > 0) { if (this->touch_timeout_ > 0) {
// Simulate a touch after <this->touch_timeout_> ms. This will reset any existing timeout operation. // Simulate a touch after <this->touch_timeout_> ms. This will reset any existing timeout operation.
// This is to detect touch release. // This is to detect touch release.
this->set_timeout(TAG, this->touch_timeout_, [this]() { this->store_.touched = true; }); if (this->is_touched_) {
this->set_timeout(TAG, this->touch_timeout_, [this]() { this->store_.touched = true; });
} else {
this->cancel_timeout(TAG);
}
} }
} }
} }
@ -111,6 +114,7 @@ void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_r
void Touchscreen::send_touches_() { void Touchscreen::send_touches_() {
TouchPoints_t touches; TouchPoints_t touches;
ESP_LOGV(TAG, "Touch status: is_touched=%d, was_touched=%d", this->is_touched_, this->was_touched_);
for (auto tp : this->touches_) { for (auto tp : this->touches_) {
ESP_LOGV(TAG, "Touch status: %d/%d: raw:(%4d,%4d,%4d) calc:(%3d,%4d)", tp.second.id, tp.second.state, ESP_LOGV(TAG, "Touch status: %d/%d: raw:(%4d,%4d,%4d) calc:(%3d,%4d)", tp.second.id, tp.second.state,
tp.second.x_raw, tp.second.y_raw, tp.second.z_raw, tp.second.x, tp.second.y); tp.second.x_raw, tp.second.y_raw, tp.second.z_raw, tp.second.x, tp.second.y);
@ -124,14 +128,10 @@ void Touchscreen::send_touches_() {
} }
if (!this->is_touched_) { if (!this->is_touched_) {
if (this->was_touched_) { if (this->was_touched_) {
if (this->touch_timeout_ > 0) {
this->cancel_timeout(TAG);
}
this->release_trigger_.trigger(); this->release_trigger_.trigger();
for (auto *listener : this->touch_listeners_) for (auto *listener : this->touch_listeners_)
listener->release(); listener->release();
this->touches_.clear(); this->touches_.clear();
this->was_touched_ = false;
} }
} else { } else {
if (this->first_touch_) { if (this->first_touch_) {
@ -142,6 +142,7 @@ void Touchscreen::send_touches_() {
} }
} }
} }
this->was_touched_ = this->is_touched_;
} }
int16_t Touchscreen::normalize_(int16_t val, int16_t min_val, int16_t max_val, bool inverted) { int16_t Touchscreen::normalize_(int16_t val, int16_t min_val, int16_t max_val, bool inverted) {