input: double tap
Added input double tap psuedo device Signed-off-by: Helmut Lord <kellyhlord@gmail.com>
This commit is contained in:
parent
d3815dae43
commit
15c4df0aaa
12 changed files with 322 additions and 0 deletions
|
@ -154,6 +154,14 @@
|
|||
long-delay-ms = <100>;
|
||||
};
|
||||
|
||||
double_tap: doubletap {
|
||||
input = <&double_tap>;
|
||||
compatible = "zephyr,input-double-tap";
|
||||
input-codes = <0>;
|
||||
double-tap-codes = <0>;
|
||||
double-tap-delay-ms = <0>;
|
||||
};
|
||||
|
||||
i2c@1 {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
|
9
tests/subsys/input/double_tap/CMakeLists.txt
Normal file
9
tests/subsys/input/double_tap/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(input_double_tap)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
21
tests/subsys/input/double_tap/boards/native_sim.overlay
Normal file
21
tests/subsys/input/double_tap/boards/native_sim.overlay
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2024 Kelly Helmut Lord
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
fake_input_device: fake-device {
|
||||
compatible = "vnd,input-device";
|
||||
};
|
||||
|
||||
double_tap: doubletap {
|
||||
input = <&fake_input_device>;
|
||||
compatible = "zephyr,input-double-tap";
|
||||
input-codes = <INPUT_KEY_0>, <INPUT_KEY_1>;
|
||||
double-tap-codes = <INPUT_KEY_X>, <INPUT_KEY_Y>;
|
||||
double-tap-delay-ms = <300>;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* Copyright 2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "native_sim.overlay"
|
5
tests/subsys/input/double_tap/prj.conf
Normal file
5
tests/subsys/input/double_tap/prj.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_INPUT=y
|
||||
CONFIG_INPUT_MODE_SYNCHRONOUS=y
|
78
tests/subsys/input/double_tap/src/main.c
Normal file
78
tests/subsys/input/double_tap/src/main.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2024 Kelly Helmut Lord
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/input/input.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
static const struct device *const fake_dev = DEVICE_DT_GET(
|
||||
DT_NODELABEL(fake_input_device));
|
||||
static const struct device *const double_tap_dev = DEVICE_DT_GET(
|
||||
DT_NODELABEL(double_tap));
|
||||
|
||||
DEVICE_DT_DEFINE(DT_INST(0, vnd_input_device), NULL, NULL, NULL, NULL,
|
||||
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
|
||||
|
||||
static int event_count;
|
||||
static struct input_event last_events[2];
|
||||
|
||||
static void test_cb(struct input_event *evt, void *user_data)
|
||||
{
|
||||
TC_PRINT("%s: %d %x %d\n", __func__, event_count, evt->code, evt->value);
|
||||
|
||||
event_count++;
|
||||
memcpy(&last_events[1], &last_events[0], sizeof(struct input_event));
|
||||
memcpy(&last_events[0], evt, sizeof(struct input_event));
|
||||
}
|
||||
INPUT_CALLBACK_DEFINE(double_tap_dev, test_cb, NULL);
|
||||
|
||||
ZTEST(double_tap, test_double_tap_test)
|
||||
{
|
||||
zassert_equal(event_count, 0);
|
||||
|
||||
/* ignored */
|
||||
input_report_key(fake_dev, INPUT_KEY_3, 1, true, K_FOREVER);
|
||||
input_report_key(fake_dev, INPUT_KEY_3, 0, true, K_FOREVER);
|
||||
zassert_equal(event_count, 0);
|
||||
input_report_abs(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER);
|
||||
input_report_abs(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER);
|
||||
zassert_equal(event_count, 0);
|
||||
|
||||
/* double tap*/
|
||||
input_report_key(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER);
|
||||
zassert_equal(event_count, 2);
|
||||
zassert_equal(last_events[1].type, INPUT_EV_KEY);
|
||||
zassert_equal(last_events[1].code, INPUT_KEY_X);
|
||||
zassert_equal(last_events[1].value, 1);
|
||||
zassert_equal(last_events[0].type, INPUT_EV_KEY);
|
||||
zassert_equal(last_events[0].code, INPUT_KEY_X);
|
||||
zassert_equal(last_events[0].value, 0);
|
||||
|
||||
/* double tap - other key */
|
||||
input_report_key(fake_dev, INPUT_KEY_1, 1, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_1, 0, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_1, 1, true, K_FOREVER);
|
||||
k_sleep(K_MSEC(50));
|
||||
input_report_key(fake_dev, INPUT_KEY_1, 0, true, K_FOREVER);
|
||||
zassert_equal(event_count, 4);
|
||||
zassert_equal(last_events[1].type, INPUT_EV_KEY);
|
||||
zassert_equal(last_events[1].code, INPUT_KEY_Y);
|
||||
zassert_equal(last_events[1].value, 1);
|
||||
zassert_equal(last_events[0].type, INPUT_EV_KEY);
|
||||
zassert_equal(last_events[0].code, INPUT_KEY_Y);
|
||||
zassert_equal(last_events[0].value, 0);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(double_tap, NULL, NULL, NULL, NULL, NULL);
|
12
tests/subsys/input/double_tap/testcase.yaml
Normal file
12
tests/subsys/input/double_tap/testcase.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
tests:
|
||||
input.input_double_tap:
|
||||
platform_allow:
|
||||
- native_sim
|
||||
- native_sim/native/64
|
||||
tags:
|
||||
- drivers
|
||||
- input
|
||||
integration_platforms:
|
||||
- native_sim
|
Loading…
Add table
Add a link
Reference in a new issue