Skip to content

Commit a8ad320

Browse files
leonardocavagnisfacchinm
authored andcommitted
add touch management to LVGL Demo
1 parent 9e87a04 commit a8ad320

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

libraries/H7_Video/examples/LVGLDemo/LVGLDemo.ino

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,36 @@
44

55
H7_Video Display(480,800);
66

7-
//@TODO: Complete demo with 4 main features + touch management
7+
//@TODO: Complete demo with 4 main features
8+
9+
void my_touchpad_read(lv_indev_drv_t * indev, lv_indev_data_t * data) {
10+
data->state = (touchpad_pressed) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
11+
if(data->state == LV_INDEV_STATE_PR) {
12+
data->point.x = giga_get_touch_x();
13+
data->point.y = giga_get_touch_y();
14+
touchpad_pressed = false;
15+
16+
Serial.print("Touch detected: ");
17+
Serial.print(data->point.x);
18+
Serial.print(",");
19+
Serial.println(data->point.y);
20+
}
21+
22+
return;
23+
}
824

925
void setup() {
1026
Serial.begin(115200);
1127
giga_touch_setup();
1228

1329
Display.begin();
1430

31+
static lv_indev_drv_t indev_drv; /* Descriptor of a input device driver */
32+
lv_indev_drv_init(&indev_drv); /* Basic initialization */
33+
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
34+
indev_drv.read_cb = my_touchpad_read; /* Set your driver function */
35+
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv); /* Register the driver in LVGL and save the created input device object */
36+
1537
/* Change the active screen's background color */
1638
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x03989e), LV_PART_MAIN);
1739

@@ -24,7 +46,7 @@ void setup() {
2446

2547
void loop() {
2648
/* Touch handler */
27-
giga_touch_loop();
49+
giga_touch_handler();
2850

2951
/* Feed LVGL engine */
3052
lv_timer_handler();

libraries/H7_Video/examples/LVGLDemo/giga_touch.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ bool touchpad_pressed;
2424

2525
void handleTouch(int8_t contacts, GTPoint *points) {
2626
touchpad_pressed = true;
27-
printf("Contacts: %d\n", contacts);
27+
//printf("Contacts: %d\n", contacts);
2828
for (uint8_t i = 0; i < contacts; i++) {
2929
if (i == 0) {
3030
touchpad_x = points[i].x;
3131
touchpad_y = points[i].y;
3232
}
33-
printf("C%d: #%d %d,%d s:%d\n", i, points[i].trackId, points[i].x, points[i].y, points[i].area);
33+
//printf("C%d: #%d %d,%d s:%d\n", i, points[i].trackId, points[i].x, points[i].y, points[i].area);
3434
yield();
3535
}
3636
}
@@ -57,8 +57,6 @@ void touchStart() {
5757
}
5858

5959
void giga_touch_setup() {
60-
Serial.println("\nGoodix GT911x touch driver");
61-
6260
Wire.setClock(400000);
6361
Wire.begin();
6462
delay(300);
@@ -67,7 +65,15 @@ void giga_touch_setup() {
6765
touchStart();
6866
}
6967

70-
void giga_touch_loop() {
68+
void giga_touch_handler() {
7169
touch.loop();
7270
delay(1);
7371
}
72+
73+
uint16_t giga_get_touch_x() {
74+
return touchpad_x;
75+
}
76+
77+
uint16_t giga_get_touch_y() {
78+
return touchpad_y;
79+
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
extern uint16_t touchpad_x;
2-
extern uint16_t touchpad_y;
3-
extern bool touchpad_pressed;
4-
51
void giga_touch_setup();
6-
void giga_touch_loop();
2+
void giga_touch_handler();
3+
4+
uint16_t giga_get_touch_x();
5+
uint16_t giga_get_touch_y();
6+
7+
extern bool touchpad_pressed;

0 commit comments

Comments
 (0)