Provide a usb_detect_one wrapper which only plugs one device at a time, breaking out otherwise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/usbutils.c b/usbutils.c
index 316e31e..db2835a 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2184,7 +2184,8 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
return NULL;
}
-void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *))
+void __usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *),
+ bool single)
{
libusb_device **list;
ssize_t count, i;
@@ -2244,6 +2245,8 @@ void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struc
}
free(found);
}
+ if (single)
+ break;
}
}
diff --git a/usbutils.h b/usbutils.h
index c7b86ea..c47e41e 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -430,7 +430,10 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu);
void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
-void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *));
+void __usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *),
+ bool single);
+#define usb_detect(drv, cgpu) __usb_detect(drv, cgpu, false)
+#define usb_detect_one(drv, cgpu) __usb_detect(drv, cgpu, true)
struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu);
void usb_reset(struct cgpu_info *cgpu);