mirror of
https://github.com/esphome/esphome.git
synced 2026-03-03 19:28:20 -07:00
[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:
@@ -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