mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
tests/driver_stmpe811: don't poll for touch events
Now that the interrupt of the driver works properly, we don't have to rely on polling. Instead, wake the thread by touch interrupt.
This commit is contained in:
parent
cbae0186ca
commit
f857b7116b
@ -2,7 +2,6 @@ BOARD ?= stm32f429i-disc1
|
||||
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += stmpe811
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -20,25 +20,25 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include "stmpe811.h"
|
||||
#include "stmpe811_params.h"
|
||||
|
||||
static void _touch_event_cb(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
puts("Pressed!");
|
||||
mutex_unlock(arg);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mutex_t lock = MUTEX_INIT_LOCKED;
|
||||
stmpe811_t dev;
|
||||
|
||||
puts("STMPE811 test application\n");
|
||||
|
||||
printf("+------------Initializing------------+\n");
|
||||
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, NULL);
|
||||
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, &lock);
|
||||
if (ret != STMPE811_OK) {
|
||||
puts("[Error] Initialization failed");
|
||||
return 1;
|
||||
@ -51,8 +51,16 @@ int main(void)
|
||||
stmpe811_touch_state_t last_touch_state = current_touch_state;
|
||||
|
||||
while (1) {
|
||||
|
||||
/* wait for touch event */
|
||||
mutex_lock(&lock);
|
||||
|
||||
stmpe811_read_touch_state(&dev, ¤t_touch_state);
|
||||
|
||||
if (current_touch_state != last_touch_state) {
|
||||
if (current_touch_state == STMPE811_TOUCH_STATE_PRESSED) {
|
||||
puts("Pressed!");
|
||||
}
|
||||
if (current_touch_state == STMPE811_TOUCH_STATE_RELEASED) {
|
||||
puts("Released!");
|
||||
}
|
||||
@ -65,8 +73,6 @@ int main(void)
|
||||
stmpe811_read_touch_position(&dev, &position);
|
||||
printf("X: %i, Y:%i\n", position.x, position.y);
|
||||
}
|
||||
|
||||
xtimer_usleep(10 * US_PER_MS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user