Skip to content

Commit 8d77e17

Browse files
committed
Fix: Implement software calibration for touch sensor and clamp coordinates
- Config.hpp: Enable custom calibration (X:360, Y:220) to fix compressed range - TouchDriver.hpp: Add constrain() to prevent LVGL out-of-bounds warnings - TouchDriver.hpp: Revert to simple/clean initialization sequence
1 parent 4bb4d42 commit 8d77e17

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

display/src/core/Config.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@
9393
#define TOUCH_MAP_Y2 0
9494

9595
// --- Custom Calibration (Uncomment if your specific screen has a compressed range) ---
96-
// #define USE_CUSTOM_CALIBRATION
97-
// #ifdef USE_CUSTOM_CALIBRATION
98-
// #undef TOUCH_MAP_X2
99-
// #undef TOUCH_MAP_Y2
100-
// #define TOUCH_MAP_X2 320 // Fix for compressed X axis
101-
// #define TOUCH_MAP_Y2 220 // Fix for compressed Y axis
102-
// #endif
96+
#define USE_CUSTOM_CALIBRATION
97+
#ifdef USE_CUSTOM_CALIBRATION
98+
#undef TOUCH_MAP_X2
99+
#undef TOUCH_MAP_Y2
100+
#define TOUCH_MAP_X2 330 // Adjusted margin (Raw ~338 -> 800)
101+
#define TOUCH_MAP_Y2 220 // Adjusted margin (Raw ~224 -> 480)
102+
#endif
103103

104104
#endif // CONFIG_HPP

display/src/core/TouchDriver.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ inline bool touch_touched() {
4242
touch_last_x = map(raw_x, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, SCREEN_WIDTH - 1);
4343
touch_last_y = map(raw_y, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, SCREEN_HEIGHT - 1);
4444

45+
// Clamp values to valid screen range to prevent LVGL warnings (e.g., X > 800)
46+
touch_last_x = constrain(touch_last_x, 0, SCREEN_WIDTH - 1);
47+
touch_last_y = constrain(touch_last_y, 0, SCREEN_HEIGHT - 1);
48+
4549
printf("[Touch] Raw: (%d, %d) -> Mapped: (%d, %d)\n", raw_x, raw_y, touch_last_x, touch_last_y);
4650
return true;
4751
}

0 commit comments

Comments
 (0)