mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-29 21:18:45 +00:00
Update joystick example with new failure mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
412f04f413
commit
5929295c37
2 files changed
+19
No files matched your search
@@ -238,8 +238,20 @@ struct js_event {
|
|||||||
uint8_t number; /* axis/button number */
|
uint8_t number; /* axis/button number */
|
||||||
} e;
|
} e;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called on any joystick event
|
||||||
|
*
|
||||||
|
* Note: We handle errors here by exiting, for a background daemon with
|
||||||
|
* multiple watchers you may want another approach.
|
||||||
|
*/
|
||||||
static void joystick_cb(uev_t *w, void *arg, int events)
|
static void joystick_cb(uev_t *w, void *arg, int events)
|
||||||
{
|
{
|
||||||
|
if (UEV_ERROR == events) {
|
||||||
|
/* Possibly joystick was unplugged */
|
||||||
|
warn("Unrecoverable error, exiting");
|
||||||
|
uev_exit(w->ctx);
|
||||||
|
}
|
||||||
|
|
||||||
read(w->fd, &e, sizeof(e));
|
read(w->fd, &e, sizeof(e));
|
||||||
|
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
|
|||||||
@@ -37,8 +37,15 @@ struct js_event {
|
|||||||
uint8_t number; /* axis/button number */
|
uint8_t number; /* axis/button number */
|
||||||
} e;
|
} e;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Always check for UEV_ERROR in watcher callback!
|
||||||
|
* Possibly joystick was unplugged
|
||||||
|
*/
|
||||||
static void joystick_cb(uev_t *w, void *arg, int events)
|
static void joystick_cb(uev_t *w, void *arg, int events)
|
||||||
{
|
{
|
||||||
|
if (UEV_ERROR == events)
|
||||||
|
errx(EBADF, "Unrecoverable error, exiting");
|
||||||
|
|
||||||
if (read(w->fd, &e, sizeof(e)) < 0)
|
if (read(w->fd, &e, sizeof(e)) < 0)
|
||||||
errx(errno, "Failed reading joystick event");
|
errx(errno, "Failed reading joystick event");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user