You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/02/11 20:15:18 UTC
[incubator-nuttx] 01/04: arch/sim: Make eventloop as an internal
variable to simplify up_idle.
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 14a82f40d25e58e9d1ee7fbebdd5a9f4026779c9
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Feb 10 01:30:43 2020 +0800
arch/sim: Make eventloop as an internal variable to simplify up_idle.
---
arch/sim/src/sim/up_ajoystick.c | 10 +++++++---
arch/sim/src/sim/up_idle.c | 15 ++++++---------
arch/sim/src/sim/up_internal.h | 13 +++----------
arch/sim/src/sim/up_touchscreen.c | 15 ++++++++++-----
arch/sim/src/sim/up_x11eventloop.c | 6 ++----
5 files changed, 28 insertions(+), 31 deletions(-)
diff --git a/arch/sim/src/sim/up_ajoystick.c b/arch/sim/src/sim/up_ajoystick.c
index cbbe74b..d6adee5 100644
--- a/arch/sim/src/sim/up_ajoystick.c
+++ b/arch/sim/src/sim/up_ajoystick.c
@@ -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;
}
diff --git a/arch/sim/src/sim/up_idle.c b/arch/sim/src/sim/up_idle.c
index 2b53cbf..a8d3862 100644
--- a/arch/sim/src/sim/up_idle.c
+++ b/arch/sim/src/sim/up_idle.c
@@ -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;
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 67b906a..b536c78 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -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 ***********************************************************/
diff --git a/arch/sim/src/sim/up_touchscreen.c b/arch/sim/src/sim/up_touchscreen.c
index 7bf2628..f5703b4 100644
--- a/arch/sim/src/sim/up_touchscreen.c
+++ b/arch/sim/src/sim/up_touchscreen.c
@@ -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;
}
diff --git a/arch/sim/src/sim/up_x11eventloop.c b/arch/sim/src/sim/up_x11eventloop.c
index fea5b10..35d01ef 100644
--- a/arch/sim/src/sim/up_x11eventloop.c
+++ b/arch/sim/src/sim/up_x11eventloop.c
@@ -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)