diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-12-14 11:11:04 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-12-14 11:11:04 -0600 |
commit | 376ecd917eba449840e476eaeb21c78b3af0ec13 (patch) | |
tree | 16ac19827084fc92d5d0058d36ef49b35c5854d9 | |
parent | 7dd014763ab79f0e906990b53640d2f2dbda1385 (diff) | |
download | nuttx-376ecd917eba449840e476eaeb21c78b3af0ec13.tar.gz nuttx-376ecd917eba449840e476eaeb21c78b3af0ec13.tar.bz2 nuttx-376ecd917eba449840e476eaeb21c78b3af0ec13.zip |
SIM: Several fixes to the simulated joystick driver. Still buggy
-rw-r--r-- | apps/graphics/traveler/src/trv_input.c | 16 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_ajoystick.c | 81 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_x11framebuffer.c | 5 |
3 files changed, 44 insertions, 58 deletions
diff --git a/apps/graphics/traveler/src/trv_input.c b/apps/graphics/traveler/src/trv_input.c index a2275e131..5a7b7dbba 100644 --- a/apps/graphics/traveler/src/trv_input.c +++ b/apps/graphics/traveler/src/trv_input.c @@ -149,7 +149,7 @@ static int trv_joystick_wait(void) { int errcode = errno; - fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errcode); + fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errcode); return -errcode; } @@ -158,7 +158,7 @@ static int trv_joystick_wait(void) #endif /**************************************************************************** - * Name: trv_joystick_sample + * Name: trv_joystick_read * * Description: * Read one sample from the analog joystick @@ -524,18 +524,14 @@ void trv_input_read(void) #if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) #if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) struct ajoy_sample_s sample; - ssize_t nread; + int ret; /* Read data from the analog joystick */ - nread = trv_joystick_read(&sample); - if (nread < 0) - { - trv_abort("ERROR: Joystick read error: %d\n", errno); - } - else if (nread != sizeof(struct ajoy_sample_s)) + ret = trv_joystick_read(&sample); + if (ret < 0) { - trv_abort("ERROR: Unexpected joystick read size: %ld\n", (long)nread); + trv_abort("ERROR: trv_joystick_read() failed: %d\n", ret); } /* Determine the input data to return to the POV logic */ diff --git a/nuttx/arch/sim/src/up_ajoystick.c b/nuttx/arch/sim/src/up_ajoystick.c index 69dd149e8..00c2163b0 100644 --- a/nuttx/arch/sim/src/up_ajoystick.c +++ b/nuttx/arch/sim/src/up_ajoystick.c @@ -91,12 +91,15 @@ static const struct ajoy_lowerhalf_s g_ajoylower = /* Driver state data */ -static volatile bool g_ajoy_valid; /* True: Sample data is valid */ -static volatile bool g_ajoy_waiting; /* True: Waiting for button data */ -static sem_t g_ajoy_waitsem; /* Semaphore used to support waiting */ +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 */ +static ajoy_handler_t g_ajoy_handler; /* "Interrupt" handler */ +static void *g_ajoy_arg; /* Handler argument */ +static ajoy_buttonset_t g_ajoy_pset; /* Set of press waited for */ +static ajoy_buttonset_t g_ajoy_rset; /* Set of releases waited for */ + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -156,45 +159,14 @@ static ajoy_buttonset_t ajoy_buttons(FAR const struct ajoy_lowerhalf_s *lower) ****************************************************************************/ static void ajoy_enable(FAR const struct ajoy_lowerhalf_s *lower, - ajoy_buttonset_t pressset, ajoy_buttonset_t releaseset, - ajoy_handler_t handler, FAR void *arg) + ajoy_buttonset_t press, ajoy_buttonset_t release, + ajoy_handler_t handler, FAR void *arg) { - if (handler) - { - ajoy_buttonset_t changed; - ajoy_buttonset_t pressed; - ajoy_buttonset_t released; - - g_ajoy_waiting = true; - while (!g_ajoy_valid) - { - (void)sem_wait(&g_ajoy_waitsem); - - if (g_ajoy_valid) - { - g_ajoy_valid = false; - changed = g_ajoy_buttons ^ g_ajoy_sample.as_buttons; - - pressed = changed & (AJOY_SUPPORTED & g_ajoy_buttons); - if ((pressed & pressset) != 0 ) - { - break; - } - - released = changed & (AJOY_SUPPORTED & ~g_ajoy_buttons); - if ((released & releaseset) != 0) - { - break; - } - } - } - - g_ajoy_waiting = false; - - /* Call the interrupt handler */ - - handler(&g_ajoylower, arg); - } + g_ajoy_handler = NULL; + g_ajoy_pset = press; + g_ajoy_rset = release; + g_ajoy_arg = arg; + g_ajoy_handler = handler; } /**************************************************************************** @@ -213,10 +185,6 @@ int sim_ajoy_initialize(void) { int ret; - /* Initialize the wait semaphore */ - - sem_init(&g_ajoy_waitsem, 0, 0); - /* Register the joystick device as /dev/ajoy0 */ ret = ajoy_register("/dev/ajoy0", &g_ajoylower); @@ -226,6 +194,8 @@ int sim_ajoy_initialize(void) g_eventloop = 1; } + + return ret; } /**************************************************************************** @@ -234,6 +204,10 @@ int sim_ajoy_initialize(void) int up_buttonevent(int x, int y, int buttons) { + ajoy_buttonset_t changed; + ajoy_buttonset_t pressed; + ajoy_buttonset_t released; + /* Same the positional data */ g_ajoy_sample.as_x = x; @@ -261,11 +235,22 @@ int up_buttonevent(int x, int y, int buttons) g_ajoy_valid = true; - /* Is there a task waiting for joystick input? */ + /* Is there an "interrupt" handler attached? */ - if (g_ajoy_waiting) + if (g_ajoy_handler) { - sem_post(&g_ajoy_waitsem); + /* Check button presses */ + + changed = g_ajoy_buttons ^ g_ajoy_sample.as_buttons; + pressed = changed & (AJOY_SUPPORTED & g_ajoy_buttons); + released = changed & (AJOY_SUPPORTED & ~g_ajoy_buttons); + + if ((pressed & g_ajoy_pset) != 0 || (released & g_ajoy_rset) != 0) + { + /* Call the interrupt handler */ + + g_ajoy_handler(&g_ajoylower, g_ajoy_arg); + } } return OK; diff --git a/nuttx/arch/sim/src/up_x11framebuffer.c b/nuttx/arch/sim/src/up_x11framebuffer.c index 5eb3b2a23..b686bd53a 100644 --- a/nuttx/arch/sim/src/up_x11framebuffer.c +++ b/nuttx/arch/sim/src/up_x11framebuffer.c @@ -131,8 +131,13 @@ static inline int up_x11createframe(void) /* Select window input events */ +#if defined(CONFIG_SIM_AJOYSTICK) + XSelectInput(g_display, g_window, + ButtonPressMask|ButtonReleaseMask|PointerMotionMask); +#else XSelectInput(g_display, g_window, ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask); +#endif /* Release queued events on the display */ |