Import Upstream version 1.2.4
This commit is contained in:
1 parent
429a74151c
commit
3f84e6db54
15 files changed
+377
-50
No files matched your search
@@ -17,7 +17,7 @@
|
||||
|
||||
(c) 2006 - 2007 The G15tools Project - g15tools.sf.net
|
||||
|
||||
$Revision: 260 $ - $Date: 2007-10-18 12:17:48 +0930 (Thu, 18 Oct 2007) $ $Author: mlampard $
|
||||
$Revision: 270 $ - $Date: 2007-11-25 15:32:03 +1030 (Sun, 25 Nov 2007) $ $Author: mlampard $
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
@@ -45,7 +45,7 @@ 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),
|
||||
DEVICE("Logitech G15 v2",0x46d,0xc227,G15_LCD|G15_KEYS|G15_DEVICE_5BYTE_RETURN),
|
||||
DEVICE(NULL,0,0,0)
|
||||
};
|
||||
|
||||
@@ -196,7 +196,7 @@ static usb_dev_handle * findAndOpenDevice(libg15_devices_t handled_device, int d
|
||||
}
|
||||
else
|
||||
{
|
||||
g15_log(stderr,G15_LOG_INFO,"Sorry, I could not detached the driver, giving up\n");
|
||||
g15_log(stderr,G15_LOG_INFO,"Sorry, I could not detach the driver, giving up\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -334,32 +334,79 @@ int exitLibG15()
|
||||
|
||||
static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char const *data)
|
||||
{
|
||||
unsigned int offset_from_start = G15_LCD_OFFSET;
|
||||
/*
|
||||
|
||||
For a set of bytes (A, B, C, etc.) the bits representing pixels will appear on the LCD like this:
|
||||
|
||||
A0 B0 C0
|
||||
A1 B1 C1
|
||||
A2 B2 C2
|
||||
A3 B3 C3 ... and across for G15_LCD_WIDTH bytes
|
||||
A4 B4 C4
|
||||
A5 B5 C5
|
||||
A6 B6 C6
|
||||
A7 B7 C7
|
||||
|
||||
A0
|
||||
A1 <- second 8-pixel-high row starts straight after the last byte on
|
||||
A2 the previous row
|
||||
A3
|
||||
A4
|
||||
A5
|
||||
A6
|
||||
A7
|
||||
A8
|
||||
|
||||
A0
|
||||
...
|
||||
A0
|
||||
...
|
||||
A0
|
||||
...
|
||||
A0
|
||||
A1 <- only the first three bits are shown on the bottom row (the last three
|
||||
A2 pixels of the 43-pixel high display.)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
unsigned int output_offset = G15_LCD_OFFSET;
|
||||
unsigned int base_offset = 0;
|
||||
unsigned int curr_row = 0;
|
||||
unsigned int curr_col = 0;
|
||||
|
||||
for (curr_row=0;curr_row<G15_LCD_HEIGHT;++curr_row)
|
||||
{
|
||||
for (curr_col=0;curr_col<G15_LCD_WIDTH;++curr_col)
|
||||
{
|
||||
unsigned int pixel_offset = curr_row*G15_LCD_WIDTH + curr_col;
|
||||
unsigned int byte_offset = pixel_offset / 8;
|
||||
unsigned int bit_offset = pixel_offset % 8;
|
||||
unsigned int val = data[byte_offset] & 1<<(7-bit_offset);
|
||||
|
||||
unsigned int row = curr_row / 8;
|
||||
unsigned int offset = G15_LCD_WIDTH*row + curr_col;
|
||||
unsigned int bit = curr_row % 8;
|
||||
|
||||
/*
|
||||
if (val)
|
||||
printf("Setting pixel at row %d col %d to %d offset %d bit %d\n",curr_row,curr_col, val, offset, bit);
|
||||
|
||||
/* Five 8-pixel rows + a little 3-pixel row. This formula will calculate
|
||||
the minimum number of bytes required to hold a complete column. (It
|
||||
basically divides by eight and rounds up the result to the nearest byte,
|
||||
but at compile time.
|
||||
*/
|
||||
if (val)
|
||||
lcd_buffer[offset_from_start + offset] = lcd_buffer[offset_from_start + offset] | 1 << bit;
|
||||
else
|
||||
lcd_buffer[offset_from_start + offset] = lcd_buffer[offset_from_start + offset] & ~(1 << bit);
|
||||
|
||||
#define G15_LCD_HEIGHT_IN_BYTES ((G15_LCD_HEIGHT + ((8 - (G15_LCD_HEIGHT % 8)) % 8)) / 8)
|
||||
|
||||
for (curr_row = 0; curr_row < G15_LCD_HEIGHT_IN_BYTES; ++curr_row)
|
||||
{
|
||||
for (curr_col = 0; curr_col < G15_LCD_WIDTH; ++curr_col)
|
||||
{
|
||||
unsigned int bit = curr_col % 8;
|
||||
/* Copy a 1x8 column of pixels across from the source image to the LCD buffer. */
|
||||
|
||||
lcd_buffer[output_offset] =
|
||||
(((data[base_offset ] << bit) & 0x80) >> 7) |
|
||||
(((data[base_offset + G15_LCD_WIDTH/8 ] << bit) & 0x80) >> 6) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 2)] << bit) & 0x80) >> 5) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 3)] << bit) & 0x80) >> 4) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 4)] << bit) & 0x80) >> 3) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 5)] << bit) & 0x80) >> 2) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 6)] << bit) & 0x80) >> 1) |
|
||||
(((data[base_offset + (G15_LCD_WIDTH/8 * 7)] << bit) & 0x80) >> 0);
|
||||
++output_offset;
|
||||
if (bit == 7)
|
||||
base_offset++;
|
||||
}
|
||||
/* Jump down seven pixel-rows in the source image, since we've just
|
||||
done a row of eight pixels in one pass (and we counted one pixel-row
|
||||
while we were going, so now we skip the next seven pixel-rows.) */
|
||||
base_offset += G15_LCD_WIDTH - (G15_LCD_WIDTH / 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +444,10 @@ int writePixmapToLCD(unsigned char const *data)
|
||||
int ret = 0;
|
||||
int transfercount=0;
|
||||
unsigned char lcd_buffer[G15_BUFFER_LEN];
|
||||
memset(lcd_buffer,0,G15_BUFFER_LEN);
|
||||
/* The pixmap conversion function will overwrite everything after G15_LCD_OFFSET, so we only need to blank
|
||||
the buffer up to this point. (Even though the keyboard only cares about bytes 0-23.) */
|
||||
memset(lcd_buffer, 0, G15_LCD_OFFSET); /* G15_BUFFER_LEN); */
|
||||
|
||||
dumpPixmapIntoLCDFormat(lcd_buffer, data);
|
||||
|
||||
if(!(g15_devices[found_devicetype].caps & G15_LCD))
|
||||
@@ -543,7 +593,7 @@ static unsigned char g15KeyToLogitechKeyCode(int key)
|
||||
}
|
||||
}
|
||||
|
||||
static void processKeyEvent(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
static void processKeyEvent8Byte(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -634,6 +684,67 @@ static void processKeyEvent(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
static void processKeyEvent5Byte(unsigned int *pressed_keys, unsigned char *buffer)
|
||||
{
|
||||
int i;
|
||||
|
||||
*pressed_keys = 0;
|
||||
|
||||
g15_log(stderr,G15_LOG_WARN,"Keyboard: %x, %x, %x, %x, %x\n",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
|
||||
|
||||
if (buffer[0] == 0x02)
|
||||
{
|
||||
if (buffer[1]&0x01)
|
||||
*pressed_keys |= G15_KEY_G1;
|
||||
|
||||
if (buffer[1]&0x02)
|
||||
*pressed_keys |= G15_KEY_G2;
|
||||
|
||||
if (buffer[1]&0x04)
|
||||
*pressed_keys |= G15_KEY_G3;
|
||||
|
||||
if (buffer[1]&0x08)
|
||||
*pressed_keys |= G15_KEY_G4;
|
||||
|
||||
if (buffer[1]&0x10)
|
||||
*pressed_keys |= G15_KEY_G5;
|
||||
|
||||
if (buffer[1]&0x20)
|
||||
*pressed_keys |= G15_KEY_G6;
|
||||
|
||||
if (buffer[1]&0x40)
|
||||
*pressed_keys |= G15_KEY_M1;
|
||||
|
||||
if (buffer[1]&0x80)
|
||||
*pressed_keys |= G15_KEY_M2;
|
||||
|
||||
if (buffer[2]&0x20)
|
||||
*pressed_keys |= G15_KEY_M3;
|
||||
|
||||
if (buffer[2]&0x40)
|
||||
*pressed_keys |= G15_KEY_MR;
|
||||
|
||||
if (buffer[2]&0x80)
|
||||
*pressed_keys |= G15_KEY_L1;
|
||||
|
||||
if (buffer[2]&0x2)
|
||||
*pressed_keys |= G15_KEY_L2;
|
||||
|
||||
if (buffer[2]&0x4)
|
||||
*pressed_keys |= G15_KEY_L3;
|
||||
|
||||
if (buffer[2]&0x8)
|
||||
*pressed_keys |= G15_KEY_L4;
|
||||
|
||||
if (buffer[2]&0x10)
|
||||
*pressed_keys |= G15_KEY_L5;
|
||||
|
||||
if (buffer[2]&0x1)
|
||||
*pressed_keys |= G15_KEY_LIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
|
||||
{
|
||||
unsigned char buffer[9];
|
||||
@@ -641,15 +752,28 @@ int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
|
||||
pthread_mutex_lock(&libusb_mutex);
|
||||
ret = usb_interrupt_read(keyboard_device, g15_keys_endpoint, (char*)buffer, 9, timeout);
|
||||
pthread_mutex_unlock(&libusb_mutex);
|
||||
|
||||
if (ret == 9)
|
||||
{
|
||||
if (buffer[0] == 1)
|
||||
return G15_ERROR_TRY_AGAIN;
|
||||
|
||||
processKeyEvent(pressed_keys, buffer);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
processKeyEvent8Byte(pressed_keys, buffer);
|
||||
|
||||
return G15_NO_ERROR;
|
||||
}
|
||||
}
|
||||
return handle_usb_errors("Keyboard Read", ret); /* allow the app to deal with errors */
|
||||
}
|
||||
Reference in new issue
Block a user