Import Upstream version 1.2.5
This commit is contained in:
1 parent
3f84e6db54
commit
7347e0eb26
8 files changed
+408
-176
No files matched your search
@@ -12,12 +12,12 @@
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with g15lcd; if not, write to the Free Software
|
||||
along with libg15; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
(c) 2006 - 2007 The G15tools Project - g15tools.sf.net
|
||||
(c) 2006-2007 The G15tools Project - g15tools.sf.net
|
||||
|
||||
$Revision: 270 $ - $Date: 2007-11-25 15:32:03 +1030 (Sun, 25 Nov 2007) $ $Author: mlampard $
|
||||
$Revision: 278 $ - $Date: 2008-01-02 14:26:25 +1030 (Wed, 02 Jan 2008) $ $Author: mlampard $
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <usb.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "config.h"
|
||||
|
||||
static usb_dev_handle *keyboard_device = 0;
|
||||
static int libg15_debugging_enabled = 0;
|
||||
@@ -38,14 +39,13 @@ static int g15_keys_endpoint = 0;
|
||||
static int g15_lcd_endpoint = 0;
|
||||
static pthread_mutex_t libusb_mutex;
|
||||
|
||||
|
||||
/* to add a new device, simply create a new DEVICE() in this list */
|
||||
/* Fields are: "Name",VendorID,ProductID,Capabilities */
|
||||
const libg15_devices_t g15_devices[] = {
|
||||
DEVICE("Logitech G15",0x46d,0xc222,G15_LCD|G15_KEYS),
|
||||
DEVICE("Logitech G11",0x46d,0xc225,G15_KEYS),
|
||||
DEVICE("Logitech Z-10",0x46d,0x0a07,G15_LCD|G15_KEYS|G15_DEVICE_IS_SHARED),
|
||||
DEVICE("Logitech G15 v2",0x46d,0xc227,G15_LCD|G15_KEYS|G15_DEVICE_5BYTE_RETURN),
|
||||
DEVICE("Logitech G15 v2",0x46d,0xc227,G15_LCD|G15_KEYS),
|
||||
DEVICE(NULL,0,0,0)
|
||||
};
|
||||
|
||||
@@ -301,7 +301,13 @@ int initLibG15()
|
||||
retval = initLibUsb();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
|
||||
g15_log(stderr,G15_LOG_INFO,"%s\n",PACKAGE_STRING);
|
||||
|
||||
#ifdef SUN_LIBUSB
|
||||
g15_log(stderr,G15_LOG_INFO,"Using Sun libusb.\n");
|
||||
#endif
|
||||
|
||||
g15NumberOfConnectedDevices();
|
||||
|
||||
keyboard_device = findAndOpenG15();
|
||||
@@ -317,8 +323,10 @@ 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);
|
||||
@@ -411,6 +419,7 @@ static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char con
|
||||
}
|
||||
|
||||
int handle_usb_errors(const char *prefix, int ret) {
|
||||
|
||||
switch (ret){
|
||||
case -ETIMEDOUT:
|
||||
return G15_ERROR_READING_USB_DEVICE; /* backward-compatibility */
|
||||
@@ -425,7 +434,7 @@ int handle_usb_errors(const char *prefix, int ret) {
|
||||
case -EAGAIN: /* try again */
|
||||
case -EFBIG: /* too many frames to handle */
|
||||
case -EMSGSIZE: /* msgsize is invalid */
|
||||
g15_log(stderr,G15_LOG_INFO,"usb error: %s (%i)\n",prefix,ret);
|
||||
g15_log(stderr,G15_LOG_INFO,"usb error: %s %s (%i)\n",prefix,usb_strerror(),ret);
|
||||
break;
|
||||
case -EPIPE: /* endpoint is stalled */
|
||||
g15_log(stderr,G15_LOG_INFO,"usb error: %s EPIPE! clearing...\n",prefix);
|
||||
@@ -434,7 +443,7 @@ int handle_usb_errors(const char *prefix, int ret) {
|
||||
pthread_mutex_unlock(&libusb_mutex);
|
||||
break;
|
||||
default: /* timed out */
|
||||
g15_log(stderr,G15_LOG_INFO,"Unknown usb error: %s !! (err is %i)\n",prefix,ret);
|
||||
g15_log(stderr,G15_LOG_INFO,"Unknown usb error: %s !! (err is %i (%s))\n",prefix,ret,usb_strerror());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -461,7 +470,9 @@ int writePixmapToLCD(unsigned char const *data)
|
||||
I'm not sure how successful this will be in combatting ENOSPC, but we'll give it try in the real-world. */
|
||||
|
||||
if(enospc_slowdown != 0){
|
||||
#ifndef LIBUSB_BLOCKS
|
||||
pthread_mutex_lock(&libusb_mutex);
|
||||
#endif
|
||||
for(transfercount = 0;transfercount<=31;transfercount++){
|
||||
ret = usb_interrupt_write(keyboard_device, g15_lcd_endpoint, (char*)lcd_buffer+(32*transfercount), 32, 1000);
|
||||
if (ret != 32)
|
||||
@@ -471,12 +482,18 @@ int writePixmapToLCD(unsigned char const *data)
|
||||
}
|
||||
usleep(100);
|
||||
}
|
||||
#ifndef LIBUSB_BLOCKS
|
||||
pthread_mutex_unlock(&libusb_mutex);
|
||||
#endif
|
||||
}else{
|
||||
/* transfer entire buffer in one hit */
|
||||
#ifdef LIBUSB_BLOCKS
|
||||
ret = usb_interrupt_write(keyboard_device, g15_lcd_endpoint, (char*)lcd_buffer, G15_BUFFER_LEN, 1000);
|
||||
#else
|
||||
pthread_mutex_lock(&libusb_mutex);
|
||||
ret = usb_interrupt_write(keyboard_device, g15_lcd_endpoint, (char*)lcd_buffer, G15_BUFFER_LEN, 1000);
|
||||
pthread_mutex_unlock(&libusb_mutex);
|
||||
#endif
|
||||
if (ret != G15_BUFFER_LEN)
|
||||
{
|
||||
handle_usb_errors ("LCDPixmap Write",ret);
|
||||
@@ -593,7 +610,7 @@ static unsigned char g15KeyToLogitechKeyCode(int key)
|
||||
}
|
||||
}
|
||||
|
||||
static void processKeyEvent8Byte(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
static void processKeyEvent9Byte(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -749,31 +766,26 @@ int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
|
||||
{
|
||||
unsigned char buffer[9];
|
||||
int ret = 0;
|
||||
#ifdef LIBUSB_BLOCKS
|
||||
ret = usb_interrupt_read(keyboard_device, g15_keys_endpoint, (char*)buffer, 9, timeout);
|
||||
#else
|
||||
pthread_mutex_lock(&libusb_mutex);
|
||||
ret = usb_interrupt_read(keyboard_device, g15_keys_endpoint, (char*)buffer, 9, timeout);
|
||||
pthread_mutex_unlock(&libusb_mutex);
|
||||
|
||||
if(g15DeviceCapabilities() & G15_DEVICE_5BYTE_RETURN) { /* new 5byte protocol */
|
||||
if (buffer[0] == 1)
|
||||
return G15_ERROR_TRY_AGAIN;
|
||||
if (ret == 5) {
|
||||
|
||||
processKeyEvent5Byte(pressed_keys, buffer);
|
||||
|
||||
return G15_NO_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ret == 9)
|
||||
{
|
||||
if (buffer[0] == 1)
|
||||
return G15_ERROR_TRY_AGAIN;
|
||||
#endif
|
||||
if(ret>0) {
|
||||
if(buffer[0] == 1)
|
||||
return G15_ERROR_TRY_AGAIN;
|
||||
}
|
||||
|
||||
processKeyEvent8Byte(pressed_keys, buffer);
|
||||
|
||||
switch(ret) {
|
||||
case 5:
|
||||
processKeyEvent5Byte(pressed_keys, buffer);
|
||||
return G15_NO_ERROR;
|
||||
case 9:
|
||||
processKeyEvent9Byte(pressed_keys, buffer);
|
||||
return G15_NO_ERROR;
|
||||
}
|
||||
default:
|
||||
return handle_usb_errors("Keyboard Read", ret); /* allow the app to deal with errors */
|
||||
}
|
||||
return handle_usb_errors("Keyboard Read", ret); /* allow the app to deal with errors */
|
||||
}
|
||||
Reference in new issue
Block a user