Simulated touchscreen debug fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3994 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2011-09-28 23:39:57 +00:00
parent 87557f7f2b
commit 22e969a197
5 changed files with 116 additions and 24 deletions
+8 -8
View File
@@ -114,12 +114,16 @@
* Public Variables * Public Variables
**************************************************************************/ **************************************************************************/
#ifndef __ASSEMBLY__
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
extern volatile int g_evloopactive;
#endif
/************************************************************************** /**************************************************************************
* Public Function Prototypes * Public Function Prototypes
**************************************************************************/ **************************************************************************/
#ifndef __ASSEMBLY__
/* up_setjmp.S ************************************************************/ /* up_setjmp.S ************************************************************/
extern int up_setjmp(int *jb); extern int up_setjmp(int *jb);
@@ -160,20 +164,16 @@ extern int up_x11cmap(unsigned short first, unsigned short len,
/* up_eventloop.c ***********************************************************/ /* up_eventloop.c ***********************************************************/
#ifdef CONFIG_SIM_X11FB #if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
#ifdef CONFIG_SIM_TOUCHSCREEN
extern int up_x11eventloop(void); extern int up_x11eventloop(void);
#endif #endif
#endif
/* up_eventloop.c ***********************************************************/ /* up_eventloop.c ***********************************************************/
#ifdef CONFIG_SIM_X11FB #if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
#ifdef CONFIG_SIM_TOUCHSCREEN
extern int up_tcenter(int x, int y, int buttons); extern int up_tcenter(int x, int y, int buttons);
extern int up_tcleave(int x, int y, int buttons); extern int up_tcleave(int x, int y, int buttons);
#endif #endif
#endif
/* up_tapdev.c ************************************************************/ /* up_tapdev.c ************************************************************/
+70 -5
View File
@@ -103,6 +103,7 @@ struct up_dev_s
{ {
uint8_t nwaiters; /* Number of threads waiting for touchscreen data */ uint8_t nwaiters; /* Number of threads waiting for touchscreen data */
uint8_t id; /* Current touch point ID */ uint8_t id; /* Current touch point ID */
uint8_t minor; /* Minor device number */
bool penchange; /* An unreported event is buffered */ bool penchange; /* An unreported event is buffered */
sem_t devsem; /* Manages exclusive access to this structure */ sem_t devsem; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */ sem_t waitsem; /* Used to wait for the availability of data */
@@ -601,7 +602,7 @@ errout:
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_simtouchscreen * Name: sim_tcinitialize
* *
* Description: * Description:
* Configure the simulated touchscreen. This will register the driver as * Configure the simulated touchscreen. This will register the driver as
@@ -616,13 +617,13 @@ errout:
* *
****************************************************************************/ ****************************************************************************/
int up_simtouchscreen(int minor) int sim_tcinitialize(int minor)
{ {
FAR struct up_dev_s *priv = ( FAR struct up_dev_s *)&g_simtouchscreen; FAR struct up_dev_s *priv = ( FAR struct up_dev_s *)&g_simtouchscreen;
char devname[DEV_NAMELEN]; char devname[DEV_NAMELEN];
int ret; int ret;
ivdbg("dev: %p minor: %d\n", dev, minor); ivdbg("minor: %d\n", minor);
/* Debug-only sanity checks */ /* Debug-only sanity checks */
@@ -634,6 +635,8 @@ int up_simtouchscreen(int minor)
sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */ sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */ sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
priv->minor = minor;
/* Start the X11 event loop */ /* Start the X11 event loop */
ret = up_x11eventloop(); ret = up_x11eventloop();
@@ -655,7 +658,7 @@ int up_simtouchscreen(int minor)
goto errout_with_priv; goto errout_with_priv;
} }
/* And return success (?) */ /* And return success */
return OK; return OK;
@@ -665,6 +668,64 @@ errout_with_priv:
return ret; return ret;
} }
/****************************************************************************
* Name: sim_tcuninitialize
*
* Description:
* Uninitialized the simulated touchscreen
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/
void sim_tcuninitialize(void)
{
FAR struct up_dev_s *priv = ( FAR struct up_dev_s *)&g_simtouchscreen;
char devname[DEV_NAMELEN];
int ret;
/* Get exclusive access */
do
{
ret = sem_wait(&priv->devsem);
if (ret < 0)
{
/* This should only happen if the wait was canceled by an signal */
DEBUGASSERT(errno == EINTR);
}
}
while (ret != OK);
/* Stop the event loop (Hmm.. the caller must be sure that there are no
* open references to the touchscreen driver. This might better be
* done in close() using a reference count).
*/
g_evloopactive = 0;
/* Un-register the device*/
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, priv->minor);
ivdbg("Un-registering %s\n", devname);
ret = runegister_driver(devname);
if (ret < 0)
{
idbg("uregister_driver() failed: %d\n", ret);
}
/* Clean up any resources. Ouch! While we are holding the semaphore? */
sem_destroy(&priv->waitsem);
sem_destroy(&priv->devsem);
}
/**************************************************************************** /****************************************************************************
* Name: up_tcenter * Name: up_tcenter
****************************************************************************/ ****************************************************************************/
@@ -672,7 +733,9 @@ errout_with_priv:
int up_tcenter(int x, int y, int buttons) int up_tcenter(int x, int y, int buttons)
{ {
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen; FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
bool pendown; /* true: pend is down */ bool pendown; /* true: pen is down */
ivdbg("x=%d y=%d buttons=%02x\n", x, y, buttons);
/* Any button press will count as pendown. */ /* Any button press will count as pendown. */
@@ -735,6 +798,8 @@ int up_tcleave(int x, int y, int buttons)
{ {
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen; FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
ivdbg("x=%d y=%d buttons=%02x\n", x, y, buttons);
/* Treat leaving as penup */ /* Treat leaving as penup */
/* Ignore the pen up if the pen was already up (CONTACT_NONE == pen up and /* Ignore the pen up if the pen was already up (CONTACT_NONE == pen up and
+3 -1
View File
@@ -71,6 +71,7 @@ extern Display *g_display;
extern Window g_window; extern Window g_window;
pthread_t g_eventloop; pthread_t g_eventloop;
volatile int g_evloopactive;
/**************************************************************************** /****************************************************************************
* Private Variables * Private Variables
@@ -147,7 +148,7 @@ static void *up_x11eventthread(void *arg)
* within the following loop. * within the following loop.
*/ */
for (;;) while (g_evloopactive)
{ {
XNextEvent(g_display, &event); XNextEvent(g_display, &event);
switch (event.type) switch (event.type)
@@ -196,6 +197,7 @@ int up_x11eventloop(void)
{ {
/* Start the X11 event loop */ /* Start the X11 event loop */
g_evloopactive = 1;
return pthread_create(&g_eventloop, 0, up_x11eventthread, 0); return pthread_create(&g_eventloop, 0, up_x11eventthread, 0);
} }
+14 -7
View File
@@ -267,16 +267,23 @@ nx11
CONFIG_SIM_TOUCHSCREEN=y CONFIG_SIM_TOUCHSCREEN=y
Then you must also have some application logic that will call Then you must also have some application logic that will call
up_simtouchscreen(0) to register the touchscreen driver. sim_tcinitializ(0) to register the touchscreen driver.
NOTES: NOTES:
1. If you do not have this call, the build will mysteriously
fail claiming that is can't find up_tcenter(0 and up_tcleave().
That is a consequence of the crazy way that the simulation is
built and can only be eliminated by call up_simtouchscreen(0)
from your application.
2. You must first call 1. If you do not have the call to sim_tcinitializE(0), the build
will mysteriously fail claiming that is can't find up_tcenter()
and up_tcleave(). That is a consequence of the crazy way that
the simulation is built and can only be eliminated by calling
up_simtouchscreen(0) from your application.
2. You must first up_fbinitialize() before calling up_simtouchscreen()
or you will get a crash.
3. Call sim_tcuninintialize() when you are finished with the
simulated touchscreen.
4. Enable CONFIG_DEBUG_INPUT=y for touchscreen debug output.
X11 Build Issues X11 Build Issues
---------------- ----------------
+21 -3
View File
@@ -128,11 +128,11 @@ extern "C" {
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: up_simtouchscreen * Name: sim_tcinitialize
* *
* Description: * Description:
* Configure the simulated touchscreen. This will register the driver as * Configure the simulated touchscreen. This will register the driver as
* /dev/inputN where N is the minor device number * /dev/inputN where N is the minor device number.
* *
* Input Parameters: * Input Parameters:
* minor - The input device minor number * minor - The input device minor number
@@ -144,7 +144,25 @@ extern "C" {
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN) #if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
EXTERN int up_simtouchscreen(int minor); EXTERN int sim_tcinitialize(int minor);
#endif
/****************************************************************************
* Name: sim_tcuninitialize
*
* Description:
* Uninitialized the simulated touchscreen
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
EXTERN void sim_tcuninitialize(void);
#endif #endif
#undef EXTERN #undef EXTERN