Update joystick example with new failure mode

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-11-11 13:57:43 +01:00
1 parent 412f04f413
commit 5929295c37
2 files changed
+19

No files matched your search

+12
View File
@@ -238,8 +238,20 @@ struct js_event {
uint8_t number; /* axis/button number */
} 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)
{
if (UEV_ERROR == events) {
/* Possibly joystick was unplugged */
warn("Unrecoverable error, exiting");
uev_exit(w->ctx);
}
read(w->fd, &e, sizeof(e));
switch (e.type) {
+7
View File
@@ -37,8 +37,15 @@ struct js_event {
uint8_t number; /* axis/button number */
} e;
/*
* Always check for UEV_ERROR in watcher callback!
* Possibly joystick was unplugged
*/
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)
errx(errno, "Failed reading joystick event");