|
6 | 6 |
|
7 | 7 | constexpr const char* TAG = "EspLcdTouch"; |
8 | 8 |
|
| 9 | +// Enable this to log all touch events (can be very verbose) |
| 10 | +#define LOG_TOUCH_EVENTS 1 |
| 11 | + |
| 12 | +#if LOG_TOUCH_EVENTS |
| 13 | +static void touch_event_callback(lv_event_t* e) { |
| 14 | + TT_LOG_I(TAG, "Touch event callback triggered"); |
| 15 | + lv_event_code_t code = lv_event_get_code(e); |
| 16 | + lv_indev_t* indev = (lv_indev_t*)lv_event_get_target(e); |
| 17 | + |
| 18 | + // Get the last point from the indev |
| 19 | + lv_point_t point; |
| 20 | + lv_indev_get_point(indev, &point); |
| 21 | + |
| 22 | + if (code == LV_EVENT_PRESSED) { |
| 23 | + TT_LOG_I(TAG, "Touch: state=PRESSED, x=%d, y=%d", point.x, point.y); |
| 24 | + } else if (code == LV_EVENT_PRESSING) { |
| 25 | + TT_LOG_I(TAG, "Touch: state=PRESSING, x=%d, y=%d", point.x, point.y); |
| 26 | + } else if (code == LV_EVENT_RELEASED) { |
| 27 | + TT_LOG_I(TAG, "Touch: state=RELEASED"); |
| 28 | + } |
| 29 | +} |
| 30 | +#endif |
| 31 | + |
9 | 32 | bool EspLcdTouch::start() { |
10 | 33 | if (!createIoHandle(ioHandle) != ESP_OK) { |
11 | 34 | TT_LOG_E(TAG, "Touch IO failed"); |
@@ -63,6 +86,14 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) { |
63 | 86 | return false; |
64 | 87 | } |
65 | 88 |
|
| 89 | +#if LOG_TOUCH_EVENTS |
| 90 | + // Add event listener to log touch events |
| 91 | + lv_indev_add_event_cb(lvglDevice, touch_event_callback, LV_EVENT_PRESSED, nullptr); |
| 92 | + lv_indev_add_event_cb(lvglDevice, touch_event_callback, LV_EVENT_PRESSING, nullptr); |
| 93 | + lv_indev_add_event_cb(lvglDevice, touch_event_callback, LV_EVENT_RELEASED, nullptr); |
| 94 | + TT_LOG_I(TAG, "Touch event logging enabled"); |
| 95 | +#endif |
| 96 | + |
66 | 97 | return true; |
67 | 98 | } |
68 | 99 |
|
|
0 commit comments