diff --git a/debian/changelog b/debian/changelog index 45ccc3d..a355542 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,7 +3,7 @@ libg15 (1.3.0~svn324-2) unstable; urgency=medium * Migrate from legacy libusb-0.1 to libusb-1.0 (closes: bug#810409, bug#611649). - -- Alexander Ponyatykh Sun, 17 Nov 2019 14:29:55 +0300 + -- Alexander Ponyatykh Mon, 18 Nov 2019 02:44:19 +0300 libg15 (1.3.0~svn324-1) unstable; urgency=medium diff --git a/debian/patches/02-Migrate-from-legacy-libusb-0.1-to-libusb-1.0.patch b/debian/patches/02-Migrate-from-legacy-libusb-0.1-to-libusb-1.0.patch index aee2cc4..b5a21b1 100644 --- a/debian/patches/02-Migrate-from-legacy-libusb-0.1-to-libusb-1.0.patch +++ b/debian/patches/02-Migrate-from-legacy-libusb-0.1-to-libusb-1.0.patch @@ -4,8 +4,8 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0 --- configure.in | 5 +- - libg15.c | 504 +++++++++++++++++++++++++++++------------------------------ - 2 files changed, 249 insertions(+), 260 deletions(-) + libg15.c | 615 +++++++++++++++++++++++++++++++---------------------------- + 2 files changed, 327 insertions(+), 293 deletions(-) diff --git a/configure.in b/configure.in index 074d98e..b533d2c 100644 @@ -31,10 +31,10 @@ index 074d98e..b533d2c 100644 # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git a/libg15.c b/libg15.c -index ba1c94b..ba01ae0 100644 +index ba1c94b..4c0afc4 100644 --- a/libg15.c +++ b/libg15.c -@@ -24,20 +24,21 @@ +@@ -24,20 +24,22 @@ #include "libg15.h" #include #include @@ -54,12 +54,13 @@ index ba1c94b..ba01ae0 100644 static int shared_device = 0; static int g15_keys_endpoint = 0; static int g15_lcd_endpoint = 0; ++static int g15_interface_id = -1; static pthread_mutex_t libusb_mutex; +static libusb_context *libg15_libusb_context = NULL; /* to add a new device, simply create a new DEVICE() in this list */ /* Fields are: "Name",VendorID,ProductID,Capabilities */ -@@ -67,7 +68,9 @@ int g15DeviceCapabilities() { +@@ -67,7 +69,9 @@ int g15DeviceCapabilities() { void libg15Debug(int option) { libg15_debugging_enabled = option; @@ -70,7 +71,7 @@ index ba1c94b..ba01ae0 100644 } /* debugging wrapper */ -@@ -86,191 +89,207 @@ static int g15_log (FILE *fd, unsigned int level, const char *fmt, ...) { +@@ -86,234 +90,281 @@ static int g15_log (FILE *fd, unsigned int level, const char *fmt, ...) { /* return number of connected and supported devices */ int g15NumberOfConnectedDevices() { @@ -114,13 +115,13 @@ index ba1c94b..ba01ae0 100644 static int initLibUsb() { - usb_init(); -- ++ int errcode = libusb_init(&libg15_libusb_context); + - /** - * usb_find_busses and usb_find_devices both report the number of devices - * / busses added / removed since the last call. since this is the first - * call we have to return values != 0 or else we didnt find anything */ -+ int errcode = libusb_init(&libg15_libusb_context); - +- - if (!usb_find_busses()) + if (errcode != 0) + { @@ -136,19 +137,21 @@ index ba1c94b..ba01ae0 100644 } -static usb_dev_handle * findAndOpenDevice(libg15_devices_t handled_device, int device_index) -+static libusb_device_handle * findAndOpenDevice(libg15_devices_t handled_device, int device_index) ++static libusb_device_handle* findAndOpenG15() { - struct usb_bus *bus = 0; - struct usb_device *dev = 0; - int retries=0; - int j,i,k,l; - int interface=0; -+ struct libusb_device_descriptor desc; ++ struct libusb_config_descriptor *cfg = NULL; + libusb_device_handle *devh = 0; ++ libusb_device *dev = NULL; + libusb_device **list = 0; -+ libusb_device *dev = 0; -+ int interface = 0; -+ int retries = 0; ++ /* Use configuration 1 by default. */ ++ int configuration = 1; ++ int unconfigured = 0; ++ int found_dev = -1; + int ret; + + ssize_t cnt = libusb_get_device_list(libg15_libusb_context, &list); @@ -160,14 +163,16 @@ index ba1c94b..ba01ae0 100644 + } - for (bus = usb_busses; bus; bus = bus->next) -+ for (ssize_t devno = 0; devno < cnt; devno++) ++ for (ssize_t devno = 0; devno < cnt && found_dev == -1; devno++) { - for (dev = bus->devices; dev; dev = dev->next) -+ libusb_get_device_descriptor(list[devno], &desc); -+ if (desc.idVendor == handled_device.vendorid && desc.idProduct == handled_device.productid) - { +- { - if ((dev->descriptor.idVendor == handled_device.vendorid && dev->descriptor.idProduct == handled_device.productid)) -- { ++ struct libusb_device_descriptor desc; ++ libusb_get_device_descriptor(list[devno], &desc); ++ for (int i = 0; g15_devices[i].name != NULL && found_dev == -1; i++) { ++ if (desc.idVendor == g15_devices[i].vendorid && desc.idProduct == g15_devices[i].productid) + { - int ret=0; - char name_buffer[65535]; - name_buffer[0] = 0; @@ -187,89 +192,23 @@ index ba1c94b..ba01ae0 100644 - g15_log(stderr,G15_LOG_INFO, "Perhaps you don't have enough permissions to access it\n"); - return 0; - } -+ dev = list[devno]; -+ break; -+ } -+ } - +- - usleep(50*1000); -+ if (!dev) { -+ libusb_free_device_list(list, 1); -+ return 0; -+ } - +- - g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n",dev->descriptor.bNumConfigurations); -+ found_devicetype = device_index; - +- - /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */ - if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED) - shared_device = 1; -+ g15_log(stderr,G15_LOG_INFO,"Found %s, trying to open it\n",handled_device.name); -+ -+ ret = libusb_open(dev, &devh); -+ libusb_free_device_list(list, 1); -+ -+ if (ret || !devh) -+ { -+ g15_log(stderr,G15_LOG_INFO, "Error, could not open the keyboard: %s\n", libusb_strerror(ret)); -+ return 0; -+ } - +- - for (j = 0; jdescriptor.bNumConfigurations;j++){ - struct usb_config_descriptor *cfg = &dev->config[j]; -+ usleep(50*1000); -+ -+ g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n", desc.bNumConfigurations); -+ -+ /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */ -+ if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED) -+ shared_device = 1; -+ -+ for (int j = 0; j < desc.bNumConfigurations; j++) -+ { -+ struct libusb_config_descriptor *cfg; -+ if (libusb_get_config_descriptor(dev, j, &cfg)) continue; -+ -+ for (int i = 0; i < cfg->bNumInterfaces; i++) -+ { -+ if (g15DeviceCapabilities() & G15_DEVICE_G510) -+ { -+ if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue; -+ } -+ -+ const struct libusb_interface *ifp = &cfg->interface[i]; -+ /* if endpoints are already known, finish up */ -+ if (g15_keys_endpoint && g15_lcd_endpoint) -+ break; -+ g15_log(stderr, G15_LOG_INFO, "Device has %i Alternate Settings\n", ifp->num_altsetting); - +- - for (i=0;ibNumInterfaces; i++){ - if (g15DeviceCapabilities()&G15_DEVICE_G510){ - if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue; -+ for (int k=0; k < ifp->num_altsetting; k++) -+ { -+ const struct libusb_interface_descriptor *as = &ifp->altsetting[k]; -+ /* verify that the interface is for a HID device */ -+ if (as->bInterfaceClass == LIBUSB_CLASS_HID) -+ { -+ g15_log(stderr, G15_LOG_INFO, "Interface %i has %i Endpoints\n", i, as->bNumEndpoints); -+ usleep(50*1000); -+ -+ if (libusb_kernel_driver_active(devh, i) == 1) -+ { -+ g15_log(stderr, G15_LOG_INFO, "Trying to detach driver currently attached.\n"); -+ -+ ret = libusb_detach_kernel_driver(devh, i); -+ if (!ret) -+ { -+ g15_log(stderr,G15_LOG_INFO,"Success, detached the driver\n"); -+ } -+ else -+ { -+ g15_log(stderr,G15_LOG_INFO,"Could not detach the driver, giving up: %s\n", libusb_strerror(ret)); -+ break; - } - +- } +- - struct usb_interface *ifp = &cfg->interface[i]; - /* if endpoints are already known, finish up */ - if(g15_keys_endpoint && g15_lcd_endpoint) @@ -353,83 +292,209 @@ index ba1c94b..ba01ae0 100644 - g15_log(stderr, G15_LOG_INFO, "Error setting Alternate Interface\n"); - } - } -+ } -+ /* don't set configuration if device is shared */ -+ if (0 == shared_device) { -+ ret = libusb_set_configuration(devh, 1); -+ if (ret) -+ { -+ g15_log(stderr,G15_LOG_INFO,"Error setting the configuration, this is fatal: %s\n", libusb_strerror(ret)); -+ break; - } - } +- } +- } - } -+ usleep(50*1000); -+ while((ret = libusb_claim_interface(devh,i)) && retries <10) { -+ usleep(50*1000); -+ retries++; -+ g15_log(stderr,G15_LOG_INFO,"Trying to claim interface\n"); -+ } - -+ if (ret) -+ { -+ g15_log(stderr,G15_LOG_INFO,"Error claiming interface, good day cruel world: %s\n", libusb_strerror(ret)); -+ break; -+ } - +- +- - g15_log(stderr,G15_LOG_INFO,"Done opening the keyboard\n"); - usleep(500*1000); // sleep a bit for good measure - return devh; -+ for (int l = 0; l < as->bNumEndpoints; l++) -+ { -+ const struct libusb_endpoint_descriptor *ep=&as->endpoint[l]; -+ g15_log(stderr, G15_LOG_INFO, "Found %s endpoint %i with address 0x%X maxtransfersize=%i \n", -+ 0x80&ep->bEndpointAddress?"\"Extra Keys\"":"\"LCD\"", -+ ep->bEndpointAddress&0x0f,ep->bEndpointAddress, ep->wMaxPacketSize -+ ); -+ -+ if(0x80 & ep->bEndpointAddress) -+ { -+ g15_keys_endpoint = ep->bEndpointAddress; -+ } else { -+ g15_lcd_endpoint = ep->bEndpointAddress; -+ } -+ } -+ } ++ found_dev = i; ++ dev = list[devno]; ++ g15_log(stderr, G15_LOG_INFO, "Found bus %03u port %03u device %03u ID %04x:%04x %s\n", ++ libusb_get_bus_number(list[devno]), ++ libusb_get_port_number(list[devno]), ++ libusb_get_device_address(list[devno]), ++ desc.idVendor, ++ desc.idProduct, ++ g15_devices[i].name); ++ g15_log(stderr, G15_LOG_INFO, "Device has %u possible configuration%s\n", desc.bNumConfigurations, desc.bNumConfigurations > 1 ? "s" : ""); } } -+ -+ libusb_free_config_descriptor(cfg); -+ } -+ -+ if (g15_keys_endpoint || g15_lcd_endpoint) { -+ g15_log(stderr,G15_LOG_INFO,"Done opening the keyboard\n"); -+ usleep(500*1000); // sleep a bit for good measure -+ return devh; -+ } else { -+ found_devicetype = -1; -+ libusb_release_interface(devh, 0); -+ libusb_attach_kernel_driver(devh, 0); -+ libusb_close(devh); -+ return 0; } - return 0; - } +-} ++ if (found_dev == -1) { ++ libusb_free_device_list(list, 1); ++ g15_log(stderr, G15_LOG_INFO, "No supported devices found\n"); ++ return 0; ++ } -static usb_dev_handle * findAndOpenG15() { -+static libusb_device_handle * findAndOpenG15() { - int i; - for (i=0; g15_devices[i].name !=NULL ;i++){ - g15_log(stderr,G15_LOG_INFO,"Trying to find %s\n",g15_devices[i].name); -@@ -288,19 +307,13 @@ static int closeKeyboardDevice() - { - int retval = G15_NO_ERROR; - -- enospc_slowdown = shared_device = g15_keys_endpoint = g15_lcd_endpoint = 0; +- int i; +- for (i=0; g15_devices[i].name !=NULL ;i++){ +- g15_log(stderr,G15_LOG_INFO,"Trying to find %s\n",g15_devices[i].name); +- if(keyboard_device = findAndOpenDevice(g15_devices[i],i)){ ++ pthread_mutex_lock(&libusb_mutex); ++ ++ if (found_devicetype != -1) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error, device is already open\n"); ++ goto error; ++ } ++ ++ found_devicetype = found_dev; ++ ret = libusb_open(dev, &devh); ++ libusb_free_device_list(list, 1); ++ list = NULL; ++ ++ if (ret || !devh) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error, could not open the keyboard: %s\n", libusb_strerror(ret)); ++ goto error; ++ } ++ ++ /* If device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls. */ ++ if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED) ++ { ++ shared_device = 1; ++ ret = libusb_get_configuration(devh, &configuration); ++ if (ret) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error, could not retrieve current configuration: %s\n", libusb_strerror(ret)); ++ goto error; ++ } ++ else if (configuration < 1) ++ { ++ unconfigured = 1; ++ configuration = 1; ++ } ++ else if (configuration != 1) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Warning, using unknown configuration %i for shared device\n", configuration); ++ } ++ } ++ ++ ret = libusb_get_config_descriptor_by_value(dev, configuration, &cfg); ++ ++ if (ret) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error, could not retrieve descriptor for configuration %i: %s\n", ++ configuration, libusb_strerror(ret)); ++ ++ goto error; ++ } ++ ++ g15_log(stderr, G15_LOG_INFO, "Device has %u possible interface%s for configuration %i\n", ++ cfg->bNumInterfaces, cfg->bNumInterfaces > 1 ? "s" : "", configuration); ++ ++ const struct libusb_interface_descriptor *iface = NULL; ++ for (int i = 0; i < cfg->bNumInterfaces; i++) ++ { ++ /* Always use altsetting 0, others are not supported even if exist. */ ++ iface = &cfg->interface[i].altsetting[0]; ++ if ((g15DeviceCapabilities() & G15_DEVICE_G510) && iface->bInterfaceNumber == G510_STANDARD_KEYBOARD_INTERFACE) continue; ++ ++ if (iface->bInterfaceClass == LIBUSB_CLASS_HID && iface->bNumEndpoints > 0) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Selecting HID interface %u, it has %u possible altsetting%s\n", ++ iface->bInterfaceNumber, cfg->interface[i].num_altsetting, cfg->interface[i].num_altsetting > 1 ? "s" : ""); ++ ++ g15_interface_id = iface->bInterfaceNumber; + break; + } ++ } ++ ++ if (g15_interface_id == -1) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error, could not find suitable HID interface\n"); ++ goto error; ++ } ++ ++ for (int i = 0; i < iface->bNumEndpoints; i++) ++ { ++ const struct libusb_endpoint_descriptor *ep = &iface->endpoint[i]; ++ g15_log(stderr, G15_LOG_INFO, "Found %s endpoint %i with address 0x%X maxtransfersize=%i\n", ++ 0x80 & ep->bEndpointAddress ? "\"Extra Keys\"" : "\"LCD\"", ++ ep->bEndpointAddress & 0x0f, ep->bEndpointAddress, ep->wMaxPacketSize); ++ ++ if (0x80 & ep->bEndpointAddress) ++ { ++ g15_keys_endpoint = ep->bEndpointAddress; ++ } + else +- g15_log(stderr,G15_LOG_INFO,"%s not found\n",g15_devices[i].name); ++ { ++ g15_lcd_endpoint = ep->bEndpointAddress; ++ } ++ } ++ ++ if (libusb_kernel_driver_active(devh, g15_interface_id) == 1) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Trying to detach driver currently attached\n"); ++ ++ ret = libusb_detach_kernel_driver(devh, g15_interface_id); ++ if (!ret) ++ { ++ g15_log(stderr,G15_LOG_INFO,"Success, detached the driver\n"); ++ } ++ else ++ { ++ g15_log(stderr,G15_LOG_INFO,"Could not detach the driver, giving up: %s\n", libusb_strerror(ret)); ++ goto error; ++ } ++ } ++ ++ if(!shared_device || unconfigured) ++ { ++ /* Set configuration, reset state, reset altsetting to 0 */ ++ ret = libusb_set_configuration(devh, 1); ++ if (ret) ++ { ++ g15_log(stderr,G15_LOG_INFO,"Error setting the configuration: %s\n", libusb_strerror(ret)); ++ goto error; ++ } ++ } ++ ++ ret = 1; ++ for (int i = 0; i < 10 && ret; i++) ++ { ++ usleep(50 * 1000); ++ g15_log(stderr, G15_LOG_INFO, "Trying to claim interface\n"); ++ ret = libusb_claim_interface(devh, g15_interface_id); ++ } ++ ++ if (ret) ++ { ++ g15_log(stderr, G15_LOG_INFO, "Error claiming interface, good day cruel world: %s\n", libusb_strerror(ret)); ++ goto error; ++ } ++ ++ libusb_free_config_descriptor(cfg); ++ ++ g15_log(stderr, G15_LOG_INFO, "Done opening the keyboard\n"); ++ ++ pthread_mutex_unlock(&libusb_mutex); ++ ++ return devh; ++ ++error: ++ if (devh) ++ { ++ libusb_attach_kernel_driver(devh, 0); ++ libusb_close(devh); + } +- return keyboard_device; ++ if (cfg) libusb_free_config_descriptor(cfg); ++ if (list) libusb_free_device_list(list, 1); + shared_device = g15_keys_endpoint = g15_lcd_endpoint = 0; - found_devicetype = -1; ++ g15_interface_id = found_devicetype = -1; ++ pthread_mutex_unlock(&libusb_mutex); ++ ++ return 0; + } ++ + /* reset the keyboard, returning it to a known state */ + static int closeKeyboardDevice() + { +- int retval = G15_NO_ERROR; +- +- enospc_slowdown = shared_device = g15_keys_endpoint = g15_lcd_endpoint = 0; +- found_devicetype = -1; +- - if (keyboard_device){ -#ifndef SUN_LIBUSB - retval = usb_release_interface (keyboard_device, 0); @@ -440,14 +505,28 @@ index ba1c94b..ba01ae0 100644 - usleep(50*1000); -#endif - usb_close(keyboard_device); +- keyboard_device=0; +- return retval; ++ int retval = G15_ERROR_OPENING_USB_DEVICE; ++ ++ pthread_mutex_lock(&libusb_mutex); + if (keyboard_device) { + retval = libusb_release_interface(keyboard_device, 0); + libusb_attach_kernel_driver(keyboard_device, 0); + libusb_close(keyboard_device); - keyboard_device=0; - return retval; ++ keyboard_device = NULL; ++ retval = G15_NO_ERROR; } -@@ -311,9 +324,6 @@ int re_initLibG15() +- return -1; ++ ++ shared_device = g15_keys_endpoint = g15_lcd_endpoint = 0; ++ g15_interface_id = found_devicetype = -1; ++ pthread_mutex_unlock(&libusb_mutex); ++ ++ return retval; + } + + int re_initLibG15() { closeKeyboardDevice(); @@ -457,29 +536,54 @@ index ba1c94b..ba01ae0 100644 keyboard_device = findAndOpenG15(); if (!keyboard_device) return G15_ERROR_OPENING_USB_DEVICE; -@@ -330,10 +340,6 @@ int initLibG15() +@@ -323,31 +374,33 @@ int re_initLibG15() - g15_log(stderr,G15_LOG_INFO,"%s\n",PACKAGE_STRING); + int initLibG15() + { +- int retval = G15_NO_ERROR; +- retval = initLibUsb(); +- if (retval) +- return retval; ++ int retval = initLibUsb(); + +- g15_log(stderr,G15_LOG_INFO,"%s\n",PACKAGE_STRING); ++ if (retval) return retval; -#ifdef SUN_LIBUSB - g15_log(stderr,G15_LOG_INFO,"Using Sun libusb.\n"); -#endif -- - g15NumberOfConnectedDevices(); ++ g15_log(stderr, G15_LOG_INFO, "%s\n", PACKAGE_STRING); +- g15NumberOfConnectedDevices(); ++ if (libg15_debugging_enabled) g15NumberOfConnectedDevices(); + ++ pthread_mutex_init(&libusb_mutex, NULL); keyboard_device = findAndOpenG15(); -@@ -347,7 +353,9 @@ int initLibG15() +- if (!keyboard_device) ++ if (!keyboard_device) ++ { ++ pthread_mutex_destroy(&libusb_mutex); + return G15_ERROR_OPENING_USB_DEVICE; ++ } + +- pthread_mutex_init(&libusb_mutex, NULL); +- return retval; ++ return G15_NO_ERROR; + } + int exitLibG15() { ++ closeKeyboardDevice(); ++ if (libg15_libusb_context) libusb_exit(libg15_libusb_context); ++ libg15_libusb_context = NULL; ++ pthread_mutex_destroy(&libusb_mutex); - return closeKeyboardDevice(); -+ int ret = closeKeyboardDevice(); -+ libusb_exit(libg15_libusb_context); -+ libg15_libusb_context = NULL; ++ return G15_NO_ERROR; } static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char const *data) -@@ -428,36 +436,6 @@ static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char con +@@ -428,36 +481,6 @@ static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char con } } @@ -516,7 +620,7 @@ index ba1c94b..ba01ae0 100644 int writePixmapToLCD(unsigned char const *data) { int ret = 0; -@@ -474,43 +452,27 @@ int writePixmapToLCD(unsigned char const *data) +@@ -474,43 +497,27 @@ int writePixmapToLCD(unsigned char const *data) /* the keyboard needs this magic byte */ lcd_buffer[0] = 0x03; @@ -546,9 +650,9 @@ index ba1c94b..ba01ae0 100644 + if (ret || transferred != G15_BUFFER_LEN) + { + if (!ret) { -+ g15_log(stderr,G15_LOG_INFO,"LCDPixmap write error: short write.\n"); ++ g15_log(stderr,G15_LOG_INFO,"LCDPixmap write error: short write\n"); + } else { -+ g15_log(stderr,G15_LOG_INFO,"LCDPixmap write error: %s.\n", libusb_strerror(ret)); ++ g15_log(stderr,G15_LOG_INFO,"LCDPixmap write error: %s\n", libusb_strerror(ret)); } -#ifndef LIBUSB_BLOCKS - pthread_mutex_unlock(&libusb_mutex); @@ -578,7 +682,7 @@ index ba1c94b..ba01ae0 100644 return 0; } -@@ -535,7 +497,9 @@ int setLCDContrast(unsigned int level) +@@ -535,7 +542,9 @@ int setLCDContrast(unsigned int level) usb_data[3] = 18; } pthread_mutex_lock(&libusb_mutex); @@ -589,7 +693,7 @@ index ba1c94b..ba01ae0 100644 pthread_mutex_unlock(&libusb_mutex); return retval; } -@@ -553,7 +517,9 @@ int setLEDs(unsigned int leds) +@@ -553,7 +562,9 @@ int setLEDs(unsigned int leds) return G15_ERROR_UNSUPPORTED; pthread_mutex_lock(&libusb_mutex); @@ -600,7 +704,7 @@ index ba1c94b..ba01ae0 100644 pthread_mutex_unlock(&libusb_mutex); return retval; } -@@ -578,7 +544,9 @@ int setLCDBrightness(unsigned int level) +@@ -578,7 +589,9 @@ int setLCDBrightness(unsigned int level) usb_data[2] = 0x00; } pthread_mutex_lock(&libusb_mutex); @@ -611,7 +715,7 @@ index ba1c94b..ba01ae0 100644 pthread_mutex_unlock(&libusb_mutex); return retval; } -@@ -604,7 +572,9 @@ int setKBBrightness(unsigned int level) +@@ -604,7 +617,9 @@ int setKBBrightness(unsigned int level) usb_data[2] = 0x0; } pthread_mutex_lock(&libusb_mutex); @@ -622,7 +726,7 @@ index ba1c94b..ba01ae0 100644 pthread_mutex_unlock(&libusb_mutex); return retval; } -@@ -619,7 +589,9 @@ int setG510LEDColor(unsigned char r, unsigned char g, unsigned char b) +@@ -619,7 +634,9 @@ int setG510LEDColor(unsigned char r, unsigned char g, unsigned char b) usb_data[3] = b; pthread_mutex_lock(&libusb_mutex); @@ -633,7 +737,7 @@ index ba1c94b..ba01ae0 100644 pthread_mutex_unlock(&libusb_mutex); return retval; } -@@ -1033,38 +1005,54 @@ static void processKeyEvent4Byte(unsigned int *pressed_keys, unsigned char *buff +@@ -1033,38 +1050,54 @@ static void processKeyEvent4Byte(unsigned int *pressed_keys, unsigned char *buff int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout) { unsigned char buffer[G15_KEY_READ_LENGTH]; @@ -664,7 +768,7 @@ index ba1c94b..ba01ae0 100644 + pthread_mutex_unlock(&libusb_mutex); + //no break + default: -+ g15_log(stderr,G15_LOG_INFO,"USB error on keybaord read: %s.\n", libusb_strerror(ret)); ++ g15_log(stderr,G15_LOG_INFO,"USB error on keybaord read: %s\n", libusb_strerror(ret)); + return G15_ERROR_READING_USB_DEVICE; + } + @@ -706,7 +810,7 @@ index ba1c94b..ba01ae0 100644 + processKeyEvent9Byte(pressed_keys, buffer); + return G15_NO_ERROR; + default: -+ g15_log(stderr, G15_LOG_INFO,"USB error on keybaord read: unsupported packet size.\n"); ++ g15_log(stderr, G15_LOG_INFO,"USB error on keybaord read: unsupported packet size\n"); + return G15_ERROR_READING_USB_DEVICE; } }