mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
matrix_keypad: add test application
This commit is contained in:
parent
7f3cbfdfc7
commit
1d33455116
7
tests/driver_matrix_keypad/Makefile
Normal file
7
tests/driver_matrix_keypad/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
# required modules
|
||||
USEMODULE += matrix_keypad
|
||||
USEMODULE += ztimer_msec
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
10
tests/driver_matrix_keypad/README.md
Normal file
10
tests/driver_matrix_keypad/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
matrix_keypad
|
||||
=============
|
||||
|
||||
This is a test application for the matrix_keypad module.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
The test application will print the key row and column when it is pressed or
|
||||
released.
|
53
tests/driver_matrix_keypad/main.c
Normal file
53
tests/driver_matrix_keypad/main.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Koen Zandberg
|
||||
*
|
||||
* 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 Test application for the matrix_keypad driver
|
||||
*
|
||||
* @author Koen Zandberg <koen@bergzand.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "matrix_keypad.h"
|
||||
#include "matrix_keypad_params.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
void _callback(void *arg, size_t col, size_t row, bool state)
|
||||
{
|
||||
(void)arg;
|
||||
printf("Key switch at column %u and row %u is ", (unsigned)col, (unsigned)row);
|
||||
if (state) {
|
||||
puts("pressed!");
|
||||
}
|
||||
else {
|
||||
puts("released!");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
matrix_keypad_t dev;
|
||||
|
||||
puts("Generated RIOT application: 'matrix_keypad'");
|
||||
if (matrix_keypad_init(&dev, &matrix_keypad_params[0], _callback, NULL) == 0) {
|
||||
puts("[OK]\n");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
matrix_keypad_scan(&dev);
|
||||
ztimer_sleep(ZTIMER_MSEC, 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user