Feed the edge swipe from the touchscreen triggers again (0.2.34)
The 0.2.32 edge swipe listened on LVGL's input device, but the LVGL 9.5.0 bundled by ESPHome sends the indev PRESSED and RELEASED without PRESSING, so the swipe never received a position update: on Studio 1 the log showed the GT911 press and then nothing. The Guition follows the swipe through on_touch, on_update and on_release again, the route that worked live in 0.2.24 once the card-close fix was in, with ESPHome's own rotation mapping, the 45-degree rule, end() on release so a stale armed state cannot fire on the next touch, and the "genegeerd"/"niet gevuurd" log lines. Firmware 0.2.29 for both boards; the app only moves its target version. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -130,18 +130,25 @@ class TouchGuard {
|
||||
inline TouchGuard touch_guard;
|
||||
|
||||
// Page navigation by swiping in from a side edge (Guition, firmware 0.2.24+). Fed from
|
||||
// LVGL's own pointer events (PRESSED/PRESSING), so the coordinates are already rotated the
|
||||
// way the user sees the screen. A touch that starts within `band` pixels of the left or
|
||||
// right edge and travels `travel` pixels inward, more sideways than up or down, flips one
|
||||
// page: from the right edge leftwards is "next", from the left edge rightwards "previous".
|
||||
// No speed requirement; a touch that starts in the middle never counts, so tapping and
|
||||
// dragging on tiles cannot change the page by accident.
|
||||
// ESPHome's touchscreen triggers: on_touch begins, on_update updates, on_release ends.
|
||||
// LVGL 9.5 does not send PRESSING to the input device, so the native touch points are
|
||||
// used and rotated here the way ESPHome's LVGL component rotates its pointer. A touch that
|
||||
// starts within `band` pixels of the left or right edge of the screen as the user sees it
|
||||
// and travels `travel` pixels inward, more sideways than up or down, flips one page: from
|
||||
// the right edge leftwards is "next", from the left edge rightwards "previous". No speed
|
||||
// requirement; a touch that starts in the middle never counts, so tapping and dragging on
|
||||
// tiles cannot change the page by accident.
|
||||
class EdgeSwipe {
|
||||
public:
|
||||
void configure(int band, int travel) { band_ = band; travel_ = travel; }
|
||||
// `width` is the screen width as the user sees it (LVGL's horizontal resolution).
|
||||
void begin(int x, int y, int width) {
|
||||
void configure(int width, int height, int band, int travel) {
|
||||
width_ = width; height_ = height; band_ = band; travel_ = travel;
|
||||
}
|
||||
// Native touch coordinates plus the LVGL rotation in degrees (0, 90, 180, 270).
|
||||
void begin(int x, int y, int rotation = 0) {
|
||||
rotation_ = rotation;
|
||||
rotate(x, y);
|
||||
start_x_ = x; start_y_ = y;
|
||||
const int width = (rotation == 90 || rotation == 270) ? height_ : width_;
|
||||
from_ = x < band_ ? 1 : x >= width - band_ ? -1 : 0; // 1: left edge, -1: right edge
|
||||
done_ = false;
|
||||
inward_ = sideways_ = 0;
|
||||
@@ -150,6 +157,7 @@ class EdgeSwipe {
|
||||
// +1 next page, -1 previous page, 0 nothing; fires at most once per touch.
|
||||
int update(int x, int y) {
|
||||
if (!armed()) return 0;
|
||||
rotate(x, y);
|
||||
const int dx = x - start_x_, dy = y - start_y_;
|
||||
const int inward = from_ == 1 ? dx : -dx;
|
||||
inward_ = std::max(inward_, inward);
|
||||
@@ -158,11 +166,19 @@ class EdgeSwipe {
|
||||
done_ = true;
|
||||
return from_ == 1 ? -1 : 1;
|
||||
}
|
||||
// The finger left the glass: a stale armed state must never fire on the next touch
|
||||
// (ESPHome runs on_update before on_touch in the first cycle of a new touch).
|
||||
void end() { done_ = true; }
|
||||
// How far the finger got, for the log when an edge touch ends without a page flip.
|
||||
int inward() const { return inward_; }
|
||||
int sideways() const { return sideways_; }
|
||||
private:
|
||||
int band_{32}, travel_{40};
|
||||
void rotate(int &x, int &y) const {
|
||||
if (rotation_ == 90) { const int tmp = y; y = width_ - x - 1; x = tmp; }
|
||||
else if (rotation_ == 180) { x = width_ - x - 1; y = height_ - y - 1; }
|
||||
else if (rotation_ == 270) { const int tmp = x; x = height_ - y - 1; y = tmp; }
|
||||
}
|
||||
int width_{480}, height_{480}, band_{32}, travel_{40}, rotation_{0};
|
||||
int start_x_{0}, start_y_{0}, from_{0}, inward_{0}, sideways_{0};
|
||||
bool done_{true};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user