Skip to content

Commit

Permalink
apps/examples/lcd_test/: Add example test case for callback touch fun…
Browse files Browse the repository at this point in the history
…ctionality

    Touch hold/move event
    Total touch points 3
    TOUCH COORDINATES id: 0, x : 313 y : 162 touch type: 2
    Touch hold/move event
    TOUCH COORDINATES id: 1, x : 398 y : 282 touch type: 2
    Touch hold/move event
    TOUCH COORDINATES id: 2, x : 561 y : 321 touch type: 2
    Touch hold/move event
    Total touch points 3
    TOUCH COORDINATES id: 0, x : 313 y : 162 touch type: 2
    Touch hold/move event
  • Loading branch information
abhinav-s235 committed Nov 27, 2024
1 parent 54895ab commit 07a1610
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions apps/examples/lcd_test/example_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ static int yres;
#define EXAMPLE_LCD_FPS_TEST 5000
#endif

#if defined(CONFIG_TOUCH) && defined(CONFIG_TOUCH_CALLBACK)
static struct touch_set_callback_s touch_set_callback;
#endif

static void putarea(int x1, int x2, int y1, int y2, int color)
{
struct lcddev_area_s area;
Expand Down Expand Up @@ -370,6 +374,9 @@ static void test_fps(void)
}

#ifdef CONFIG_TOUCH

#ifdef CONFIG_TOUCH_POLL

static void touch_test(void)
{
/* read first 10 events */
Expand Down Expand Up @@ -408,6 +415,37 @@ static void touch_test(void)
}
close(fd);
}

#elif CONFIG_TOUCH_CALLBACK

void is_touch_detected(int status)
{
if (status == OK) {
printf("Total touch points %d\n", touch_set_callback.touch_points->npoints);
for (int i = 0; i < touch_set_callback.touch_points->npoints; i++) {
printf("TOUCH COORDINATES id: %d, x : %d y : %d touch type: %d\n", touch_set_callback.touch_points->point[i].id, touch_set_callback.touch_points->point[i].x, touch_set_callback.touch_points->point[i].y, touch_set_callback.touch_points->point[i].flags);
if (touch_set_callback.touch_points->point[i].flags == TOUCH_DOWN) {
printf("Touch press event \n");
} else if (touch_set_callback.touch_points->point[i].flags == TOUCH_MOVE) {
printf("Touch hold/move event \n");
} else if (touch_set_callback.touch_points->point[i].flags == TOUCH_UP) {
printf("Touch release event \n");
}
}
} else if (status == -EINVAL) { // -EINVAL Error signifies touch_set_callback.touch_points is NULL
if (touch_set_callback.touch_points == NULL) {
touch_set_callback.touch_points = (struct touch_sample_s *)malloc(sizeof(struct touch_sample_s));
if (!touch_set_callback.touch_points) {
printf("Error: Touch point buffer memory allocation failed\n");
}
}
} else {
printf("Error: Touch detection failed\n");
}
}

#endif

#endif

#ifdef CONFIG_BUILD_KERNEL
Expand All @@ -422,10 +460,35 @@ int lcd_test_main(int argc, char *argv[])
int p = 0;
char port[20] = { '\0' };
#ifdef CONFIG_TOUCH

#ifdef CONFIG_TOUCH_POLL
pid_t touch = task_create("touch", SCHED_PRIORITY_DEFAULT, 8096, touch_test, NULL);
if (touch < 0) {
printf("Error: Failed to create touch reader, error : %d\n", get_errno());
}

#elif CONFIG_TOUCH_CALLBACK

touch_set_callback.touch_points = (struct touch_sample_s *)malloc(sizeof(struct touch_sample_s));
if (!touch_set_callback.touch_points) {
printf("Error: Touch point buffer memory allocation failed\n");
return;
}
touch_set_callback.is_touch_detected = is_touch_detected;
int touch_fd = open(TOUCH_DEV_PATH, O_RDWR);
if (touch_fd < 0) {
printf("Error: Failed to open /dev/touch0, errno : %d\n", get_errno());
return;
}
int ret = ioctl(touch_fd, TSIOC_SETAPPNOTIFY, &touch_set_callback);
if (ret != OK) {
printf("ERROR: Touch callback register from application to touch driver failed\n");
close(touch_fd);
return;
}

#endif

#endif

sprintf(port, LCD_DEV_PATH, p);
Expand All @@ -447,7 +510,12 @@ int lcd_test_main(int argc, char *argv[])
test_fps();
close(fd);
#ifdef CONFIG_TOUCH
#ifdef CONFIG_TOUCH_POLL
task_delete(touch);
#elif CONFIG_TOUCH_CALLBACK
close(touch_fd);
#endif

#endif
return OK;
}

0 comments on commit 07a1610

Please sign in to comment.