1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/touch_dev/main.c

85 lines
1.9 KiB
C
Raw Normal View History

2020-04-16 10:34:54 +02:00
/*
* Copyright (C) 2020 Inria
*
* 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>
*
* @}
*/
#include <stdio.h>
#include <stdbool.h>
2022-01-01 16:48:05 +01:00
#include "ztimer.h"
2020-04-16 10:34:54 +02:00
#include "touch_dev.h"
2021-05-19 11:29:42 +02:00
#if IS_USED(MODULE_STMPE811)
2020-04-16 10:34:54 +02:00
#include "stmpe811.h"
#include "test_utils/expect.h"
2021-05-19 11:29:42 +02:00
#endif
2020-04-16 10:34:54 +02:00
static void _touch_event_cb(void *arg)
{
(void)arg;
printf("Event: ");
2020-04-16 10:34:54 +02:00
}
int main(void)
{
2021-05-19 11:29:42 +02:00
/* Use the first screen */
touch_dev_reg_t *touch_dev = touch_dev_reg_find_screen(0);
if (!touch_dev) {
puts("No screen found!");
return -1;
}
2020-04-16 10:34:54 +02:00
2021-05-19 11:29:42 +02:00
touch_dev_set_touch_event_callback(touch_dev->dev, _touch_event_cb, NULL);
2020-04-16 10:34:54 +02:00
2021-05-19 11:29:42 +02:00
#if IS_USED(MODULE_STMPE811)
uint16_t xmax = touch_dev_width(touch_dev->dev);
uint16_t ymax = touch_dev_height(touch_dev->dev);
2020-04-16 10:34:54 +02:00
2021-05-19 11:29:42 +02:00
stmpe811_t *stmpe811 = (stmpe811_t *)touch_dev->dev;
expect(xmax == stmpe811->params.xmax);
expect(ymax == stmpe811->params.ymax);
#endif
2020-04-16 10:34:54 +02:00
2021-05-19 11:29:42 +02:00
uint8_t last_touches = touch_dev_touches(touch_dev->dev, NULL, 1);
2020-04-16 10:34:54 +02:00
while (1) {
touch_t touches[1];
2021-05-19 11:29:42 +02:00
uint8_t current_touches = touch_dev_touches(touch_dev->dev, touches, 1);
2020-04-16 10:34:54 +02:00
if (current_touches != last_touches) {
if (current_touches == 0) {
puts("released!");
}
if (current_touches > 0) {
puts("pressed!");
2020-04-16 10:34:54 +02:00
}
last_touches = current_touches;
}
/* Display touch position if pressed */
if (current_touches == 1) {
printf("X: %i, Y:%i\n", touches[0].x, touches[0].y);
}
2022-01-01 16:48:05 +01:00
ztimer_sleep(ZTIMER_MSEC, 10);
2020-04-16 10:34:54 +02:00
}
return 0;
}