diff --git a/libfxlink/devices.c b/libfxlink/devices.c index a1ca83e..8f08cd2 100644 --- a/libfxlink/devices.c +++ b/libfxlink/devices.c @@ -817,13 +817,16 @@ bool fxlink_device_list_track(struct fxlink_device_list *list, libusb_context *ctx) { memset(list, 0, sizeof *list); + list->ctx = ctx; if(!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) { elog("libusb doesn't handle hotplug; devices may not be detected\n"); + list->hotplug_supported = false; + enumerate_devices(ctx, list); return false; } - list->ctx = ctx; + list->hotplug_supported = true; libusb_hotplug_register_callback(ctx, /* Both arriving and departing devices */ LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, @@ -839,6 +842,9 @@ bool fxlink_device_list_track(struct fxlink_device_list *list, void fxlink_device_list_refresh(struct fxlink_device_list *list) { + if(!list->hotplug_supported) + enumerate_devices(list->ctx, list); + for(int i = 0; i < list->count; i++) { struct fxlink_device *fdev = &list->devices[i]; /* Finish analysis */ diff --git a/libfxlink/include/fxlink/devices.h b/libfxlink/include/fxlink/devices.h index 4a5d6dc..0d14fd6 100644 --- a/libfxlink/include/fxlink/devices.h +++ b/libfxlink/include/fxlink/devices.h @@ -299,6 +299,9 @@ struct fxlink_device_list { libusb_context *ctx; /* Callback handle */ libusb_hotplug_callback_handle hotplug_handle; + /* Whether the hotplug callback could be installed. If not, refreshes + will be made manually. */ + bool hotplug_supported; /* Array of connected devices */ struct fxlink_device *devices; /* Number of elements in `devices` */