diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-02-10 10:14:22 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-02-10 10:14:22 -0600 |
commit | 105f5fbfcbbf411deefddac8039ccb3b03477609 (patch) | |
tree | 9391251ac4481cf2f8d6f066949920d439ad86cd /apps/examples/touchscreen | |
parent | affcb091dfe86c33c3a4dca58005a1c0670dc8ce (diff) | |
download | nuttx-105f5fbfcbbf411deefddac8039ccb3b03477609.tar.gz nuttx-105f5fbfcbbf411deefddac8039ccb3b03477609.tar.bz2 nuttx-105f5fbfcbbf411deefddac8039ccb3b03477609.zip |
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
Diffstat (limited to 'apps/examples/touchscreen')
-rw-r--r-- | apps/examples/touchscreen/Kconfig | 7 | ||||
-rw-r--r-- | apps/examples/touchscreen/tc.h | 14 | ||||
-rw-r--r-- | apps/examples/touchscreen/tc_main.c | 51 |
3 files changed, 68 insertions, 4 deletions
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 <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,10 @@ #include <errno.h> #include <debug.h> +#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE +# include <nuttx/input/mouse.h> +#endif + #include <nuttx/input/touchscreen.h> #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: |