[Touchscreen] Add expire of touch record. (#5986)

* Add expire of touch record.

* Implement suggested changes.

* Alternative implementation to detect touch release.

* add `cancel_timeout`.

* Add touch timeout as configurable element.

---------

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Fabian
2023-12-24 20:16:53 +01:00
committed by GitHub
parent 46fc37b691
commit 93ac765425
4 changed files with 38 additions and 16 deletions

View File

@@ -47,6 +47,11 @@ void Touchscreen::loop() {
} else {
this->store_.touched = false;
this->defer([this]() { this->send_touches_(); });
if (this->touch_timeout_ > 0) {
// Simulate a touch after <this->touch_timeout_> ms. This will reset any existing timeout operation.
// This is to detect touch release.
this->set_timeout(TAG, this->touch_timeout_, [this]() { this->store_.touched = true; });
}
}
}
}
@@ -90,6 +95,9 @@ void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_r
void Touchscreen::send_touches_() {
if (!this->is_touched_) {
if (this->touch_timeout_ > 0) {
this->cancel_timeout(TAG);
}
this->release_trigger_.trigger();
for (auto *listener : this->touch_listeners_)
listener->release();