summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Ponyatykh <lazyranma@gmail.com>2019-05-10 11:45:05 +0200
committerAlexander Ponyatykh <lazyranma@gmail.com>2019-05-10 11:45:05 +0200
commitcd3374b407901cb7a70909ee23ec2a3775e565bc (patch)
tree47603a51706ae074cfe5f81f1e9f44d554a672e5
parent1b84f9ae6d42581e88b2af107c6d54a89824e064 (diff)
fix re_initLibG15() to properly reset internal state.archive/debian/1.2.7-3
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libusb/+bug/1357556 Forwarded: no Last-Update: 2015-05-17 =================================================================== Gbp-Pq: Name 00-fix-reinit.patch
-rw-r--r--libg15.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/libg15.c b/libg15.c
index 9670a7a..0723393 100644
--- a/libg15.c
+++ b/libg15.c
@@ -275,19 +275,36 @@ static usb_dev_handle * findAndOpenG15() {
return keyboard_device;
}
+/* 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);
+ usleep(50*1000);
+#endif
+#if 0
+ retval = usb_reset(keyboard_device);
+ usleep(50*1000);
+#endif
+ usb_close(keyboard_device);
+ keyboard_device=0;
+ return retval;
+ }
+ return -1;
+}
int re_initLibG15()
{
+ closeKeyboardDevice();
- usb_init();
-
- /**
- * 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 */
-
- if (!usb_find_devices())
- return G15_ERROR_OPENING_USB_DEVICE;
+ usb_find_busses();
+ usb_find_devices();
keyboard_device = findAndOpenG15();
if (!keyboard_device)
@@ -319,28 +336,12 @@ int initLibG15()
return retval;
}
-/* reset the keyboard, returning it to a known state */
int exitLibG15()
{
- int retval = G15_NO_ERROR;
- if (keyboard_device){
-#ifndef SUN_LIBUSB
- retval = usb_release_interface (keyboard_device, 0);
- usleep(50*1000);
-#endif
-#if 0
- retval = usb_reset(keyboard_device);
- usleep(50*1000);
-#endif
- usb_close(keyboard_device);
- keyboard_device=0;
- pthread_mutex_destroy(&libusb_mutex);
- return retval;
- }
- return -1;
+ pthread_mutex_destroy(&libusb_mutex);
+ return closeKeyboardDevice();
}
-
static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char const *data)
{
/*