From bd1fbd998308cb851a445580f388992822b80d4a Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sat, 29 Oct 2016 22:49:35 +0200 Subject: [PATCH] Optimize multiple pid detection --- src/main.cpp | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f9b8ebb..4f57260 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -221,30 +221,8 @@ void findG810() { libusb_device_descriptor desc = {0}; libusb_get_device_descriptor(device, &desc); if (desc.idVendor == 0x046d) { - if (desc.idProduct == 0xc331) lg_pid=0xc331; - if (desc.idProduct == 0xc337) lg_pid=0xc337; - } - } - libusb_free_device_list(devs, 1); - libusb_exit(ctx); -} - -void findG410() { - libusb_device **devs; - libusb_context *ctx = NULL; - int r; - ssize_t cnt; - r = libusb_init(&ctx); - if(r < 0) return; - cnt = libusb_get_device_list(ctx, &devs); - if(cnt < 0) return; - ssize_t i; - for(i = 0; i < cnt; i++) { - libusb_device *device = devs[i]; - libusb_device_descriptor desc = {0}; - libusb_get_device_descriptor(device, &desc); - if (desc.idVendor == 0x046d) { - if (desc.idProduct == 0xc330) lg_pid=0xc330; + if (desc.idProduct == 0xc331) { lg_pid=0xc331; break; } + if (desc.idProduct == 0xc337) { lg_pid=0xc337; break; } } } libusb_free_device_list(devs, 1); @@ -258,7 +236,7 @@ int main(int argc, char *argv[]) { size_t split = str.find_last_of("/\\"); str = str.substr(split + 1); - if (str == "g410-led") findG410(); + if (str == "g410-led") lg_pid=0xc330; else findG810(); if (argc > 1) {