Skip to content

Commit

Permalink
Fixes for linuxraw driver
Browse files Browse the repository at this point in the history
Triggered by libretro#16320, a few things are adjusted:
- device name is shown correctly (this was preventing config save)
- driver name fixed in autoconfig related calls
- hotplug reconnect was not working
- some logging added
  • Loading branch information
zoltanvb committed Mar 5, 2024
1 parent 952ac2a commit ec47121
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions input/drivers_joypad/linuxraw_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static bool linuxraw_joypad_init_pad(const char *path,

event.events = EPOLLIN;
event.data.ptr = pad;

RARCH_LOG("[linuxraw]: device name is \"%s\".\n",pad->ident);
if (epoll_ctl(linuxraw_epoll, EPOLL_CTL_ADD, pad->fd, &event) >= 0)
return true;
}
Expand Down Expand Up @@ -170,8 +170,12 @@ static void linuxraw_joypad_poll(void)
if (linuxraw_pads[idx].fd >= 0)
{
if (linuxraw_hotplug)
{
input_autoconfigure_disconnect(idx,
linuxraw_pads[idx].ident);
RARCH_LOG("[linuxraw]: disconnected \"%s\".\n",
linuxraw_pads[idx].ident);
}

close(linuxraw_pads[idx].fd);
linuxraw_pads[idx].buttons = 0;
Expand All @@ -183,7 +187,7 @@ static void linuxraw_joypad_poll(void)
input_autoconfigure_connect(
NULL,
NULL,
linuxraw_joypad_name(idx),
"linuxraw",
idx,
0,
0);
Expand All @@ -196,16 +200,20 @@ static void linuxraw_joypad_poll(void)
char path[256];
size_t _len = strlcpy(path, "/dev/input/", sizeof(path));
strlcpy(path + _len, event->name, sizeof(path) - _len);
RARCH_DBG("[linuxraw]: reconnecting \"%s\".\n",path);

if ( !string_is_empty(linuxraw_pads[idx].ident)
if ( string_is_empty(linuxraw_pads[idx].ident)
&& linuxraw_joypad_init_pad(path, &linuxraw_pads[idx]))
{
input_autoconfigure_connect(
linuxraw_pads[idx].ident,
NULL,
linuxraw_joypad.ident,
"linuxraw",
idx,
0,
0);
RARCH_LOG("[linuxraw]: reconnected \"%s\".\n",linuxraw_pads[idx].ident);
}
}
}
}
Expand All @@ -220,6 +228,7 @@ static void *linuxraw_joypad_init(void *data)
size_t i, _len;
char path[PATH_MAX_LENGTH];
int fd = epoll_create(32);
bool init_ok;

if (fd < 0)
return NULL;
Expand All @@ -231,15 +240,18 @@ static void *linuxraw_joypad_init(void *data)
{
struct linuxraw_joypad *pad = (struct linuxraw_joypad*)&linuxraw_pads[i];

pad->fd = -1;
pad->ident = input_config_get_device_name_ptr(i);
pad->fd = -1;
pad->ident = input_config_get_device_name_ptr(i);

snprintf(path + _len, sizeof(path) - _len, "%u", (uint32_t)i);

init_ok = linuxraw_joypad_init_pad(path, pad);

RARCH_DBG("[linuxraw]: scanning path \"%s\", ident \"%s\".\n",path,pad->ident);
input_autoconfigure_connect(pad->ident, NULL, "linuxraw",
i, 0, 0);

if (linuxraw_joypad_init_pad(path, pad))
if (init_ok)
linuxraw_poll_pad(pad);
}

Expand Down

0 comments on commit ec47121

Please sign in to comment.