system/input: add input tool button support

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2022-02-16 10:58:00 +08:00 committed by Xiang Xiao
parent 009e668745
commit db4fc86465

View File

@ -19,11 +19,13 @@
****************************************************************************/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <nuttx/input/buttons.h>
#include <nuttx/input/touchscreen.h>
/****************************************************************************
@ -55,8 +57,8 @@ static int input_utouch_tap(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
****************************************************************************/
@ -67,6 +69,7 @@ static const struct input_cmd_s g_input_cmd_list[] =
{"sleep", input_sleep },
{"tap", input_utouch_tap },
{"swipe", input_utouch_swipe},
{"button", input_button },
{NULL, NULL }
};
@ -220,6 +223,29 @@ static int input_utouch_swipe(int argc, char** argv)
return 0;
}
static int input_button(int argc, char **argv)
{
int fd;
btn_buttonset_t button;
if (argc != 2)
{
return -EINVAL;
}
button = strtoul(argv[1], NULL, 0);
fd = open("/dev/ubutton", O_WRONLY);
if (fd < 0)
{
return -errno;
}
write(fd, &button, sizeof(button));
close(fd);
return 0;
}
/****************************************************************************
* Name: intput_help
****************************************************************************/
@ -231,10 +257,12 @@ static int input_help(int argc, char** argv)
"\thelp\n"
"\tsleep <time(ms)>\n"
"\ttap <x> <y> [interval(ms)]\n"
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)] [distance(pix)]\n\n"
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)] [distance(pix)]\n"
"\tbutton <buttonvalue>\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");
"\tdistance: Report the pixel distance of the sample twice\n"
"\tbuttonvalue: button value in hex format\n");
return 0;
}
@ -256,6 +284,11 @@ int main(int argc, char** argv)
int i;
int ret = -EINVAL;
if (argv[1] == NULL)
{
goto errout;
}
for (i = 0; g_input_cmd_list[i].cmd != NULL; i++)
{
/* Matching the function corresponding to the command */
@ -267,10 +300,12 @@ int main(int argc, char** argv)
}
}
if (ret < 0)
errout:
if (ret != 0)
{
input_help(argc, argv);
return EXIT_FAILURE;
}
return ret;
return EXIT_SUCCESS;
}