refactor(DisplayManager): add hitTestRaw() and remove touch coordinate filtering
This commit is contained in:
@@ -378,18 +378,12 @@ TouchEvent DisplayDriverTFT::readTouch() {
|
|||||||
uint16_t tx, ty;
|
uint16_t tx, ty;
|
||||||
uint8_t touched = _tft.getTouch(&tx, &ty, 100);
|
uint8_t touched = _tft.getTouch(&tx, &ty, 100);
|
||||||
|
|
||||||
// Filter out invalid coordinates (touch panel can return garbage on release)
|
// Debug: log touch state changes with transformed coords
|
||||||
// Check against actual display dimensions (320x480 for this board)
|
|
||||||
bool validCoords = !(tx > 320 || ty > 480);
|
|
||||||
if(touched && !validCoords) {
|
|
||||||
touched = 0;
|
|
||||||
return evt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug: log touch state changes
|
|
||||||
if(touched != _touchWasPressed) {
|
if(touched != _touchWasPressed) {
|
||||||
Serial.printf("[TOUCH] raw touched=%d wasPressed=%d (x=%d,y=%d)\n", touched,
|
int tx_form = tx, ty_form = ty;
|
||||||
_touchWasPressed, tx, ty);
|
transformTouch(&tx_form, &ty_form);
|
||||||
|
Serial.printf("[TOUCH] raw touched=%d wasPressed=%d (raw=%d,%d trans=%d,%d)\n", touched,
|
||||||
|
_touchWasPressed, tx, ty, tx_form, ty_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect transitions (press/release)
|
// Detect transitions (press/release)
|
||||||
@@ -431,7 +425,9 @@ TouchEvent DisplayDriverTFT::readTouch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DisplayDriverTFT::transformTouch(int* x, int* y) {
|
void DisplayDriverTFT::transformTouch(int* x, int* y) {
|
||||||
// Resistive touch panel is rotated 90° vs display - swap coordinates
|
// Resistive touch panel is rotated 90° vs display - swap and adjust
|
||||||
|
// Touch panel: 320x480 (portrait), Display: 480x320 (landscape)
|
||||||
|
// This was the original working transform
|
||||||
int temp = *x;
|
int temp = *x;
|
||||||
*x = *y;
|
*x = *y;
|
||||||
*y = temp;
|
*y = temp;
|
||||||
|
|||||||
@@ -182,16 +182,42 @@ public:
|
|||||||
int height() { return _drv ? _drv->height() : 0; }
|
int height() { return _drv ? _drv->height() : 0; }
|
||||||
|
|
||||||
/// Handle dashboard touch - returns action for tapped tile, or NONE
|
/// Handle dashboard touch - returns action for tapped tile, or NONE
|
||||||
|
/// Note: x,y are already in display coordinates (transformed by driver)
|
||||||
TileAction handleDashboardTouch(int x, int y) const {
|
TileAction handleDashboardTouch(int x, int y) const {
|
||||||
HitResult hr = hitTest(x, y);
|
HitResult hr = hitTestRaw(x, y);
|
||||||
Serial.printf("[HIT] x=%d y=%d type=%d idx=%d _headerHeight=%d\n", x, y, (int)hr.type,
|
|
||||||
hr.index, _headerHeight);
|
|
||||||
if(hr.type == UIElementType::TILE && hr.index >= 0 && hr.index < DASHBOARD_TILE_COUNT) {
|
if(hr.type == UIElementType::TILE && hr.index >= 0 && hr.index < DASHBOARD_TILE_COUNT) {
|
||||||
return DASHBOARD_TILES[hr.index].action;
|
return DASHBOARD_TILES[hr.index].action;
|
||||||
}
|
}
|
||||||
return TileAction::NONE;
|
return TileAction::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perform hit test at coordinates (already in display space, no transform)
|
||||||
|
HitResult hitTestRaw(int x, int y) const {
|
||||||
|
if(!_drv)
|
||||||
|
return HitResult();
|
||||||
|
|
||||||
|
int dispW = _drv->width();
|
||||||
|
int dispH = _drv->height();
|
||||||
|
int headerH = _headerHeight;
|
||||||
|
|
||||||
|
// Check header
|
||||||
|
Rect headerRect = UIElements::header(dispW, headerH);
|
||||||
|
if(headerRect.contains(x, y)) {
|
||||||
|
return HitResult(UIElementType::HEADER, 0, headerRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check tiles
|
||||||
|
for(int i = 0; i < _tileCount; i++) {
|
||||||
|
const TileLayout& lay = _layouts[i];
|
||||||
|
Rect tileRect(lay.x, lay.y, lay.w, lay.h);
|
||||||
|
if(tileRect.contains(x, y)) {
|
||||||
|
return HitResult(UIElementType::TILE, i, tileRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return HitResult();
|
||||||
|
}
|
||||||
|
|
||||||
/// Perform hit test at coordinates - returns element type, index, and bounds
|
/// Perform hit test at coordinates - returns element type, index, and bounds
|
||||||
HitResult hitTest(int x, int y) const {
|
HitResult hitTest(int x, int y) const {
|
||||||
if(!_drv)
|
if(!_drv)
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ void DoorbellLogic::onSerialCommand(const String& cmd) {
|
|||||||
if(comma > 0) {
|
if(comma > 0) {
|
||||||
int x = args.substring(0, comma).toInt();
|
int x = args.substring(0, comma).toInt();
|
||||||
int y = args.substring(comma + 1).toInt();
|
int y = args.substring(comma + 1).toInt();
|
||||||
HitResult hr = _display->hitTest(x, y);
|
HitResult hr = _display->hitTestRaw(x, y);
|
||||||
Serial.printf("[Hittest] raw:(%d,%d) type:%d index:%d bounds:(%d,%d,%d,%d)\n", x, y,
|
Serial.printf("[Hittest] raw:(%d,%d) type:%d index:%d bounds:(%d,%d,%d,%d)\n", x, y,
|
||||||
(int)hr.type, hr.index, hr.bounds.x, hr.bounds.y, hr.bounds.w, hr.bounds.h);
|
(int)hr.type, hr.index, hr.bounds.x, hr.bounds.y, hr.bounds.w, hr.bounds.h);
|
||||||
Serial.printf("[Display] w:%d h:%d headerH:%d\n", _display->width(), _display->height(),
|
Serial.printf("[Display] w:%d h:%d headerH:%d\n", _display->width(), _display->height(),
|
||||||
|
|||||||
Reference in New Issue
Block a user