[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:
1 parent
46fc37b691
commit
93ac765425
4 files changed
+38
-16
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user