system/input: add input tools keyboard support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
451f528bbb
commit
6895da98e3
@ -6,7 +6,7 @@
|
|||||||
menuconfig SYSTEM_INPUT
|
menuconfig SYSTEM_INPUT
|
||||||
tristate "Enable input tool"
|
tristate "Enable input tool"
|
||||||
default n
|
default n
|
||||||
select INPUT_UINPUT
|
depends on INPUT_UINPUT
|
||||||
---help---
|
---help---
|
||||||
Enable support for a command line input tool.
|
Enable support for a command line input tool.
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <nuttx/input/buttons.h>
|
#include <nuttx/input/buttons.h>
|
||||||
|
#include <nuttx/input/keyboard.h>
|
||||||
#include <nuttx/input/touchscreen.h>
|
#include <nuttx/input/touchscreen.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -56,24 +57,29 @@ struct input_cmd_s
|
|||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int input_button(int argc, char **argv);
|
||||||
|
static int input_help(int argc, char **argv);
|
||||||
|
static int input_keydown(int argc, char **argv);
|
||||||
|
static int input_keyup(int argc, char **argv);
|
||||||
|
static int input_sleep(int argc, char **argv);
|
||||||
|
static void input_utouch_move(int fd, int x, int y, int pendown);
|
||||||
static int input_utouch_tap(int argc, char **argv);
|
static int input_utouch_tap(int argc, char **argv);
|
||||||
static int input_utouch_swipe(int argc, char **argv);
|
static int input_utouch_swipe(int argc, char **argv);
|
||||||
static int input_sleep(int argc, char **argv);
|
|
||||||
static int input_help(int argc, char **argv);
|
|
||||||
static int input_button(int argc, char **argv);
|
|
||||||
static void input_utouch_move(int fd, int x, int y, int pendown);
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static const struct input_cmd_s g_input_cmd_list[] =
|
static const struct input_cmd_s g_input_cmd_list[] =
|
||||||
{
|
{
|
||||||
{"help", input_help },
|
{"help", input_help },
|
||||||
{"sleep", input_sleep },
|
{"sleep", input_sleep },
|
||||||
{"tap", input_utouch_tap },
|
{"tap", input_utouch_tap },
|
||||||
{"swipe", input_utouch_swipe},
|
{"swipe", input_utouch_swipe},
|
||||||
{"button", input_button },
|
{"button", input_button },
|
||||||
{NULL, NULL }
|
{"keyup", input_keyup },
|
||||||
|
{"keydown", input_keydown },
|
||||||
|
{NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -249,6 +255,62 @@ static int input_button(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: input_keyup
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int input_keyup(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
struct keyboard_event_s key;
|
||||||
|
|
||||||
|
if (argc != 2 || argv[1] == NULL)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open("/dev/ukeyboard", O_WRONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
key.code = strtoul(argv[1], NULL, 0);
|
||||||
|
key.type = KEYBOARD_RELEASE;
|
||||||
|
|
||||||
|
write(fd, &key, sizeof(struct keyboard_event_s));
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: input_keydown
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int input_keydown(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
struct keyboard_event_s key;
|
||||||
|
|
||||||
|
if (argc != 2 || argv[1] == NULL)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open("/dev/ukbd", O_WRONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
key.code = strtoul(argv[1], NULL, 0);
|
||||||
|
key.type = KEYBOARD_PRESS;
|
||||||
|
|
||||||
|
write(fd, &key, sizeof(struct keyboard_event_s));
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: intput_help
|
* Name: intput_help
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -262,10 +324,17 @@ static int input_help(int argc, char **argv)
|
|||||||
"\ttap <x> <y> [interval(ms)]\n"
|
"\ttap <x> <y> [interval(ms)]\n"
|
||||||
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)] [distance(pix)]\n"
|
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)] [distance(pix)]\n"
|
||||||
"\tbutton <buttonvalue>\n"
|
"\tbutton <buttonvalue>\n"
|
||||||
|
"\tkeyup: <keycode>, input keyup 0x61\n"
|
||||||
|
"\tkeydown: <keycode>, input keydown 0x61\n"
|
||||||
"\tinterval: Time interval between two reports of sample\n"
|
"\tinterval: Time interval between two reports of sample\n"
|
||||||
"\tduration: Duration of sliding\n"
|
"\tduration: Duration of sliding\n"
|
||||||
"\tdistance: Report the pixel distance of the sample twice\n"
|
"\tdistance: Report the pixel distance of the sample twice\n"
|
||||||
"\tbuttonvalue: button value in hex format\n");
|
"\tinterval: Time interval between two reports of sample\n"
|
||||||
|
"\tduration: Duration of sliding\n"
|
||||||
|
"\tdistance: Report the pixel distance of the sample twice\n"
|
||||||
|
"\tbuttonvalue: button value in hex format\n"
|
||||||
|
"\tkeycode: x11 key code, hexadecimal format\n"
|
||||||
|
);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user