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:
parent
f41e81e080
commit
81746b5117
@ -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).
|
||||
|
@ -1628,6 +1628,8 @@ examples/touchscreen
|
||||
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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
# 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
|
||||
# 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
|
||||
|
@ -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");
|
||||
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user