From 105f5fbfcbbf411deefddac8039ccb3b03477609 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Feb 2014 10:14:22 -0600 Subject: Add a mouse interface that is similar to the touchscreen interface except that it can handle multple buttons and continuously reports positional data so that it can control a cursor --- apps/ChangeLog.txt | 3 ++- apps/examples/README.txt | 14 +++++----- apps/examples/touchscreen/Kconfig | 7 +++++ apps/examples/touchscreen/tc.h | 14 ++++++++-- apps/examples/touchscreen/tc_main.c | 51 +++++++++++++++++++++++++++++++++++-- 5 files changed, 78 insertions(+), 11 deletions(-) (limited to 'apps') diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 8e5cb03a8..db1afab2c 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -818,4 +818,5 @@ an option and can be replaces with the EMACX-like CLE (about 2KB) (2014-02-02). * Several changes to restore Windows native build (2014-2-7) - + * apps/examples/touchscreen: Can not be configured to work with a mouse + interface as well (2014-2-10). diff --git a/apps/examples/README.txt b/apps/examples/README.txt index 78b6d1bbf..c64e62da0 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -1621,13 +1621,15 @@ examples/touchscreen corresponds to touchscreen device /dev/inputN. Note this value must with CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH. Default 0. CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH - The path to the touchscreen - device. This must be consistent with CONFIG_EXAMPLES_TOUCHSCREEN_MINOR. - Default: "/dev/input0" + device. This must be consistent with CONFIG_EXAMPLES_TOUCHSCREEN_MINOR. + Default: "/dev/input0" CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS - is defined, then the number of samples is provided on the command line - and this value is ignored. Otherwise, this number of samples is - collected and the program terminates. Default: Samples are collected - indefinitely. + is defined, then the number of samples is provided on the command line + and this value is ignored. Otherwise, this number of samples is + collected and the program terminates. Default: Samples are collected + indefinitely. + CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE - The touchscreen test can also be + configured to work with a mouse driver by setting this option. The following additional configurations must be set in the NuttX configuration file: diff --git a/apps/examples/touchscreen/Kconfig b/apps/examples/touchscreen/Kconfig index f493ea893..5e7739c35 100644 --- a/apps/examples/touchscreen/Kconfig +++ b/apps/examples/touchscreen/Kconfig @@ -36,4 +36,11 @@ config EXAMPLES_TOUCHSCREEN_NSAMPLES Otherwise, this number of samples is collected and the program terminates. Default: Zero (Samples are collected indefinitely). +config EXAMPLES_TOUCHSCREEN_MOUSE + bool "Mouse interface" + default n + ---help--- + The touchscreen test can also be configured to work with a mouse + driver by setting this option. + endif diff --git a/apps/examples/touchscreen/tc.h b/apps/examples/touchscreen/tc.h index 1757fe0c8..2a8dde203 100644 --- a/apps/examples/touchscreen/tc.h +++ b/apps/examples/touchscreen/tc.h @@ -59,6 +59,8 @@ * and this value is ignored. Otherwise, this number of samples is * collected and the program terminates. Default: Zero (Samples are collected * indefinitely). + * CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE - The touchscreen test can also be + * configured to work with a mouse driver by setting this option. */ #ifndef CONFIG_INPUT @@ -68,13 +70,21 @@ #ifndef CONFIG_EXAMPLES_TOUCHSCREEN_MINOR # undef CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH # define CONFIG_EXAMPLES_TOUCHSCREEN_MINOR 0 -# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/input0" +# ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE +# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/mouse0" +# else +# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/input0" +# endif #endif #ifndef CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH # undef CONFIG_EXAMPLES_TOUCHSCREEN_MINOR # define CONFIG_EXAMPLES_TOUCHSCREEN_MINOR 0 -# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/input0" +# ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE +# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/mouse0" +# else +# define CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH "/dev/input0" +# endif #endif #ifndef CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES diff --git a/apps/examples/touchscreen/tc_main.c b/apps/examples/touchscreen/tc_main.c index d786a6775..13a192a0d 100644 --- a/apps/examples/touchscreen/tc_main.c +++ b/apps/examples/touchscreen/tc_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/touchscreen/tc_main.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,10 @@ #include #include +#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE +# include +#endif + #include #include "tc.h" @@ -86,7 +90,11 @@ int tc_main(int argc, char *argv[]) { +#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE + struct mouse_report_s sample; +#else struct touch_sample_s sample; +#endif ssize_t nbytes; #if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES > 0 long nsamples; @@ -153,6 +161,44 @@ int tc_main(int argc, char *argv[]) msgflush(); +#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE + /* Read one sample */ + + ivdbg("Reading...\n"); + nbytes = read(fd, &sample, sizeof(struct mouse_report_s)); + ivdbg("Bytes read: %d\n", nbytes); + + /* Handle unexpected return values */ + + if (nbytes < 0) + { + errval = errno; + if (errval != EINTR) + { + message("tc_main: read %s failed: %d\n", + CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH, errval); + errval = 3; + goto errout_with_dev; + } + + message("tc_main: Interrupted read...\n"); + } + else if (nbytes != sizeof(struct mouse_report_s)) + { + message("tc_main: Unexpected read size=%d, expected=%d, Ignoring\n", + nbytes, sizeof(struct mouse_report_s)); + } + + /* Print the sample data on successful return */ + + else + { + message("Sample :\n"); + message(" buttons : %02x\n", sample.buttons); + message(" x : %d\n", sample.x); + message(" y : %d\n", sample.y); + } +#else /* Read one sample */ ivdbg("Reading...\n"); @@ -177,7 +223,7 @@ int tc_main(int argc, char *argv[]) else if (nbytes != sizeof(struct touch_sample_s)) { message("tc_main: Unexpected read size=%d, expected=%d, Ignoring\n", - nbytes, sizeof(struct touch_sample_s)); + nbytes, sizeof(struct touch_sample_s)); } /* Print the sample data on successful return */ @@ -195,6 +241,7 @@ int tc_main(int argc, char *argv[]) message(" w : %d\n", sample.point[0].w); message(" pressure : %d\n", sample.point[0].pressure); } +#endif } errout_with_dev: -- cgit v1.2.3