arch/sim: Make eventloop as an internal variable to simplify up_idle.

This commit is contained in:
Xiang Xiao 2020-02-10 01:30:43 +08:00 committed by Ouss4
parent 28d7061550
commit 14a82f40d2
5 changed files with 28 additions and 31 deletions

View File

@ -85,6 +85,7 @@ static const struct ajoy_lowerhalf_s g_ajoylower =
/* Driver state data */
static int g_eventloop;
static bool g_ajoy_valid; /* True: Sample data is valid */
static struct ajoy_sample_s g_ajoy_sample; /* Last sample data */
static ajoy_buttonset_t g_ajoy_buttons; /* Last buttons set */
@ -196,12 +197,17 @@ int sim_ajoy_initialize(void)
* Name: up_buttonevent
****************************************************************************/
int up_buttonevent(int x, int y, int buttons)
void up_buttonevent(int x, int y, int buttons)
{
ajoy_buttonset_t changed;
ajoy_buttonset_t pressed;
ajoy_buttonset_t released;
if (g_eventloop == 0)
{
return;
}
/* Same the positional data */
g_ajoy_sample.as_x = x;
@ -248,6 +254,4 @@ int up_buttonevent(int x, int y, int buttons)
}
}
}
return OK;
}

View File

@ -107,6 +107,12 @@ void up_idle(void)
up_devconloop();
#endif
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
/* Drive the X11 event loop */
up_x11events();
#endif
#if defined(CONFIG_NET_ETHERNET) && defined(CONFIG_SIM_NETDEV)
/* Run the network if enabled */
@ -148,15 +154,6 @@ void up_idle(void)
#ifdef CONFIG_SIM_X11FB
if (g_x11initialized)
{
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
/* Drive the X11 event loop */
if (g_eventloop)
{
up_x11events();
}
#endif
/* Update the display periodically */
g_x11refresh += 1000000 / CLK_TCK;

View File

@ -199,9 +199,6 @@
#ifdef CONFIG_SIM_X11FB
extern int g_x11initialized;
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
extern volatile int g_eventloop;
#endif
#endif
#ifdef CONFIG_SMP
@ -300,21 +297,17 @@ int up_x11cmap(unsigned short first, unsigned short len,
/* up_touchscreen.c *********************************************************/
#ifdef CONFIG_SIM_TOUCHSCREEN
int sim_tsc_initialize(int minor);
void sim_tsc_uninitialize(void);
/* up_eventloop.c ***********************************************************/
#if defined(CONFIG_SIM_X11FB) && \
(defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK))
void up_x11events(void);
#endif
/* up_eventloop.c ***********************************************************/
#if defined(CONFIG_SIM_X11FB) && \
(defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK))
int up_buttonevent(int x, int y, int buttons);
void up_x11events(void);
void up_buttonevent(int x, int y, int buttons);
#endif
/* up_ajoystick.c ***********************************************************/

View File

@ -108,6 +108,7 @@ struct up_sample_s
struct up_dev_s
{
int eventloop;
volatile uint8_t nwaiters; /* Number of threads waiting for touchscreen data */
uint8_t id; /* Current touch point ID */
uint8_t minor; /* Minor device number */
@ -650,7 +651,7 @@ int sim_tsc_initialize(int minor)
/* Enable X11 event processing from the IDLE loop */
g_eventloop = 1;
priv->eventloop = 1;
/* And return success */
@ -691,7 +692,7 @@ void sim_tsc_uninitialize(void)
* done in close() using a reference count).
*/
g_eventloop = 0;
priv->eventloop = 0;
/* Un-register the device */
@ -714,11 +715,16 @@ void sim_tsc_uninitialize(void)
* Name: up_buttonevent
****************************************************************************/
int up_buttonevent(int x, int y, int buttons)
void up_buttonevent(int x, int y, int buttons)
{
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
bool pendown; /* true: pen is down */
if (priv->eventloop == 0)
{
return;
}
iinfo("x=%d y=%d buttons=%02x\n", x, y, buttons);
iinfo("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
@ -736,7 +742,7 @@ int up_buttonevent(int x, int y, int buttons)
if (priv->sample.contact == CONTACT_NONE)
{
return OK;
return;
}
/* Not yet reported */
@ -772,5 +778,4 @@ int up_buttonevent(int x, int y, int buttons)
/* Notify any waiters that new touchscreen data is available */
up_notify(priv);
return OK;
}

View File

@ -45,7 +45,7 @@
* Public Function Prototypes
****************************************************************************/
extern int up_buttonevent(int x, int y, int buttons);
extern void up_buttonevent(int x, int y, int buttons);
/****************************************************************************
* Public Data
@ -55,8 +55,6 @@ extern int up_buttonevent(int x, int y, int buttons);
extern Display *g_display;
volatile int g_eventloop;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -107,7 +105,7 @@ void up_x11events(void)
/* Check if there are any pending, queue X11 events. */
if (XPending(g_display) > 0)
if (g_display && XPending(g_display) > 0)
{
/* Yes, get the event (this should not block since we know there are
* pending events)