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

This commit is contained in:
Gregory Nutt 2014-02-10 10:14:22 -06:00
parent f41e81e080
commit 81746b5117
5 changed files with 78 additions and 11 deletions

View File

@ -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).

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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: