Skip to content

Commit 2d3409b

Browse files
committed
tests/drivers/touch_dev_gestures: add gesture recognition test
1 parent 54ec84d commit 2d3409b

5 files changed

Lines changed: 164 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BOARD ?= stm32f746-disco
2+
include ../Makefile.drivers_common
3+
4+
DISABLE_MODULE += test_utils_interactive_sync
5+
6+
USEMODULE += touch_dev_gestures
7+
8+
include $(RIOTBASE)/Makefile.include
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BOARD_INSUFFICIENT_MEMORY := \
2+
atmega8 \
3+
#
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# About
2+
3+
This is a manual test application for gesture recognition for touch devices
4+
that are using the generic touch device API.
5+
6+
# Usage
7+
8+
This test application initializes the touch device and then waits for touch events using interrupts by default. Once touch events are received, it calls the gesture recognition. The application generates an output like the following:
9+
```
10+
Single Tap X: 276, Y:185
11+
Single Tap X: 271, Y:178
12+
Double Tap X: 271, Y:182
13+
Pressed X: 235, Y:168
14+
Moving X: 246, Y:170
15+
Moving X: 255, Y:171
16+
Moving X: 266, Y:173
17+
Moving X: 277, Y:175
18+
Moving X: 283, Y:176
19+
Moving X: 294, Y:178
20+
Moving X: 303, Y:180
21+
Released X: 310, Y:180
22+
Swipe right
23+
Swipe up
24+
Swipe down
25+
Swipe left
26+
```
27+
28+
To use the touch device in polling mode, the environment variable
29+
`TOUCH_DEV_POLLING_MODE` must be set to 1. The polling period in milliseconds
30+
is defined by the environment variable `TOUCH_DEV_POLLING_PERIOD`. It is
31+
50 ms by default and can be changed by setting the environment variable
32+
`TOUCH_DEV_POLLING_PERIOD` in the make command, for example:
33+
```
34+
TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \
35+
BOARD=... make -C tests/drivers/touch_dev_gestures flash term
36+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this file enables modules defined in Kconfig. Do not use this file for
2+
# application configuration. This is only needed during migration.
3+
CONFIG_MODULE_TOUCH_DEV_GESTURES=y
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (C) 2020 Inria
3+
* 2023 Gunar Schorcht
4+
*
5+
* This file is subject to the terms and conditions of the GNU Lesser
6+
* General Public License v2.1. See the file LICENSE in the top level
7+
* directory for more details.
8+
*/
9+
10+
/**
11+
* @ingroup tests
12+
* @{
13+
*
14+
* @file
15+
* @brief Generic touch device test application
16+
*
17+
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
18+
* @author Gunar Schorcht <gunar@schorcht.net>
19+
*
20+
* @}
21+
*/
22+
23+
#include <stdio.h>
24+
#include <stdbool.h>
25+
26+
#include "mutex.h"
27+
#include "ztimer.h"
28+
29+
#include "touch_dev.h"
30+
#include "touch_dev_gestures.h"
31+
32+
#ifndef TOUCH_DEV_POLLING_PERIOD
33+
#define TOUCH_DEV_POLLING_PERIOD 50
34+
#endif
35+
36+
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
37+
static void _touch_event_cb(void *arg)
38+
{
39+
mutex_unlock(arg);
40+
}
41+
#endif
42+
43+
int main(void)
44+
{
45+
/* Use the first screen */
46+
touch_dev_reg_t *touch_reg = touch_dev_reg_find_screen(0);
47+
if (!touch_reg) {
48+
puts("No screen found!");
49+
return -1;
50+
}
51+
52+
touch_dev_t *dev = touch_reg->dev;
53+
touch_dev_gesture_ctx_t ctx;
54+
55+
touch_dev_init_gesture(dev, &ctx);
56+
57+
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
58+
mutex_t lock = MUTEX_INIT_LOCKED;
59+
touch_dev_set_touch_event_callback(dev, _touch_event_cb, &lock);
60+
#endif
61+
62+
while (1) {
63+
64+
#if IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
65+
ztimer_sleep(ZTIMER_MSEC, TOUCH_DEV_POLLING_PERIOD);
66+
#else
67+
/* wait for event */
68+
mutex_lock(&lock);
69+
#endif
70+
71+
touch_t pos;
72+
touch_dev_gesture_t gesture = touch_dev_recognize_gesture(&ctx, &pos);
73+
74+
switch (gesture) {
75+
case TOUCH_DEV_GEST_SINGLE_TAP:
76+
printf("Single Tap X: %u, Y:%u\n", pos.x, pos.y);
77+
break;
78+
case TOUCH_DEV_GEST_DOUBLE_TAP:
79+
printf("Double Tap X: %u, Y:%u\n", pos.x, pos.y);
80+
break;
81+
case TOUCH_DEV_GEST_PRESSED:
82+
printf("Pressed X: %u, Y:%u\n", pos.x, pos.y);
83+
break;
84+
case TOUCH_DEV_GEST_RELEASED:
85+
printf("Released X: %u, Y:%u\n", pos.x, pos.y);
86+
break;
87+
case TOUCH_DEV_GEST_MOVE:
88+
printf("Moving X: %u, Y:%u\n", pos.x, pos.y);
89+
break;
90+
case TOUCH_DEV_GEST_SWIPE_LEFT:
91+
printf("Swipe left\n");
92+
break;
93+
case TOUCH_DEV_GEST_SWIPE_RIGHT:
94+
printf("Swipe right\n");
95+
break;
96+
case TOUCH_DEV_GEST_SWIPE_UP:
97+
printf("Swipe up\n");
98+
break;
99+
case TOUCH_DEV_GEST_SWIPE_DOWN:
100+
printf("Swipe down\n");
101+
break;
102+
case TOUCH_DEV_GEST_ZOOM_IN:
103+
printf("Zoom in (spread)\n");
104+
break;
105+
case TOUCH_DEV_GEST_ZOOM_OUT:
106+
printf("Zoom out (pinch)\n");
107+
break;
108+
default:
109+
break;
110+
}
111+
}
112+
113+
return 0;
114+
}

0 commit comments

Comments
 (0)