mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/drivers/touch_dev_gestures: add gesture recognition test
This commit is contained in:
parent
54ec84df88
commit
2d3409b67f
8
tests/drivers/touch_dev_gestures/Makefile
Normal file
8
tests/drivers/touch_dev_gestures/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
BOARD ?= stm32f746-disco
|
||||
include ../Makefile.drivers_common
|
||||
|
||||
DISABLE_MODULE += test_utils_interactive_sync
|
||||
|
||||
USEMODULE += touch_dev_gestures
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
3
tests/drivers/touch_dev_gestures/Makefile.ci
Normal file
3
tests/drivers/touch_dev_gestures/Makefile.ci
Normal file
@ -0,0 +1,3 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
atmega8 \
|
||||
#
|
36
tests/drivers/touch_dev_gestures/README.md
Normal file
36
tests/drivers/touch_dev_gestures/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
# About
|
||||
|
||||
This is a manual test application for gesture recognition for touch devices
|
||||
that are using the generic touch device API.
|
||||
|
||||
# Usage
|
||||
|
||||
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:
|
||||
```
|
||||
Single Tap X: 276, Y:185
|
||||
Single Tap X: 271, Y:178
|
||||
Double Tap X: 271, Y:182
|
||||
Pressed X: 235, Y:168
|
||||
Moving X: 246, Y:170
|
||||
Moving X: 255, Y:171
|
||||
Moving X: 266, Y:173
|
||||
Moving X: 277, Y:175
|
||||
Moving X: 283, Y:176
|
||||
Moving X: 294, Y:178
|
||||
Moving X: 303, Y:180
|
||||
Released X: 310, Y:180
|
||||
Swipe right
|
||||
Swipe up
|
||||
Swipe down
|
||||
Swipe left
|
||||
```
|
||||
|
||||
To use the touch device in polling mode, the environment variable
|
||||
`TOUCH_DEV_POLLING_MODE` must be set to 1. The polling period in milliseconds
|
||||
is defined by the environment variable `TOUCH_DEV_POLLING_PERIOD`. It is
|
||||
50 ms by default and can be changed by setting the environment variable
|
||||
`TOUCH_DEV_POLLING_PERIOD` in the make command, for example:
|
||||
```
|
||||
TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \
|
||||
BOARD=... make -C tests/drivers/touch_dev_gestures flash term
|
||||
```
|
3
tests/drivers/touch_dev_gestures/app.config.test
Normal file
3
tests/drivers/touch_dev_gestures/app.config.test
Normal file
@ -0,0 +1,3 @@
|
||||
# this file enables modules defined in Kconfig. Do not use this file for
|
||||
# application configuration. This is only needed during migration.
|
||||
CONFIG_MODULE_TOUCH_DEV_GESTURES=y
|
114
tests/drivers/touch_dev_gestures/main.c
Normal file
114
tests/drivers/touch_dev_gestures/main.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Inria
|
||||
* 2023 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Generic touch device test application
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "mutex.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "touch_dev.h"
|
||||
#include "touch_dev_gestures.h"
|
||||
|
||||
#ifndef TOUCH_DEV_POLLING_PERIOD
|
||||
#define TOUCH_DEV_POLLING_PERIOD 50
|
||||
#endif
|
||||
|
||||
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
static void _touch_event_cb(void *arg)
|
||||
{
|
||||
mutex_unlock(arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Use the first screen */
|
||||
touch_dev_reg_t *touch_reg = touch_dev_reg_find_screen(0);
|
||||
if (!touch_reg) {
|
||||
puts("No screen found!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
touch_dev_t *dev = touch_reg->dev;
|
||||
touch_dev_gesture_ctx_t ctx;
|
||||
|
||||
touch_dev_init_gesture(dev, &ctx);
|
||||
|
||||
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
mutex_t lock = MUTEX_INIT_LOCKED;
|
||||
touch_dev_set_touch_event_callback(dev, _touch_event_cb, &lock);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
|
||||
#if IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
ztimer_sleep(ZTIMER_MSEC, TOUCH_DEV_POLLING_PERIOD);
|
||||
#else
|
||||
/* wait for event */
|
||||
mutex_lock(&lock);
|
||||
#endif
|
||||
|
||||
touch_t pos;
|
||||
touch_dev_gesture_t gesture = touch_dev_recognize_gesture(&ctx, &pos);
|
||||
|
||||
switch (gesture) {
|
||||
case TOUCH_DEV_GEST_SINGLE_TAP:
|
||||
printf("Single Tap X: %u, Y:%u\n", pos.x, pos.y);
|
||||
break;
|
||||
case TOUCH_DEV_GEST_DOUBLE_TAP:
|
||||
printf("Double Tap X: %u, Y:%u\n", pos.x, pos.y);
|
||||
break;
|
||||
case TOUCH_DEV_GEST_PRESSED:
|
||||
printf("Pressed X: %u, Y:%u\n", pos.x, pos.y);
|
||||
break;
|
||||
case TOUCH_DEV_GEST_RELEASED:
|
||||
printf("Released X: %u, Y:%u\n", pos.x, pos.y);
|
||||
break;
|
||||
case TOUCH_DEV_GEST_MOVE:
|
||||
printf("Moving X: %u, Y:%u\n", pos.x, pos.y);
|
||||
break;
|
||||
case TOUCH_DEV_GEST_SWIPE_LEFT:
|
||||
printf("Swipe left\n");
|
||||
break;
|
||||
case TOUCH_DEV_GEST_SWIPE_RIGHT:
|
||||
printf("Swipe right\n");
|
||||
break;
|
||||
case TOUCH_DEV_GEST_SWIPE_UP:
|
||||
printf("Swipe up\n");
|
||||
break;
|
||||
case TOUCH_DEV_GEST_SWIPE_DOWN:
|
||||
printf("Swipe down\n");
|
||||
break;
|
||||
case TOUCH_DEV_GEST_ZOOM_IN:
|
||||
printf("Zoom in (spread)\n");
|
||||
break;
|
||||
case TOUCH_DEV_GEST_ZOOM_OUT:
|
||||
printf("Zoom out (pinch)\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user