Logitech G915 TKL mode support

This commit is contained in:
Lanzaa 2022-05-05 22:56:30 +00:00 committed by Adam Honse
parent 817d5d55df
commit 04ba474030
3 changed files with 218 additions and 43 deletions

View file

@ -16,6 +16,7 @@ LogitechG915Controller::LogitechG915Controller(hid_device* dev_handle, bool wire
if(wired)
{
device_index = 0xFF;
feature_4522_idx = 0x0E;
feature_8040_idx = 0x13;
feature_8071_idx = 0x09;
@ -23,6 +24,7 @@ LogitechG915Controller::LogitechG915Controller(hid_device* dev_handle, bool wire
}
else
{
device_index = 0x01;
feature_4522_idx = 0x0F;
feature_8040_idx = 0x14;
feature_8071_idx = 0x0A;
@ -69,14 +71,42 @@ void LogitechG915Controller::SetMode
(
unsigned char mode,
unsigned short speed,
unsigned short brightness,
unsigned char red,
unsigned char green,
unsigned char blue
)
{
SendMode(LOGITECH_G915_ZONE_MODE_KEYBOARD, mode, speed, red, green, blue);
SendMode(LOGITECH_G915_ZONE_MODE_LOGO, mode, speed, red, green, blue);
SendCommit();
BeginModeSet();
uint8_t logo_mode = mode;
switch(mode)
{
case LOGITECH_G915_MODE_OFF:
case LOGITECH_G915_MODE_STATIC:
{
logo_mode = mode; // static and off match
break;
}
case LOGITECH_G915_MODE_BREATHING:
{
logo_mode = LOGITECH_G915_LOGO_MODE_BREATHING; //0x03
break;
}
case LOGITECH_G915_MODE_CYCLE:
case LOGITECH_G915_MODE_WAVE:
{
logo_mode = LOGITECH_G915_LOGO_MODE_CYCLE; //0x02
break;
}
case LOGITECH_G915_MODE_RIPPLE:
{
logo_mode = LOGITECH_G915_LOGO_MODE_STATIC;
break;
}
}
SendMode(LOGITECH_G915_ZONE_MODE_KEYBOARD, mode, speed, brightness, red, green, blue);
SendMode(LOGITECH_G915_ZONE_MODE_LOGO, logo_mode, speed, brightness, red, green, blue);
}
/*-------------------------------------------------------------------------------------------------*\
@ -96,7 +126,7 @@ void LogitechG915Controller::SendCommit()
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8081_idx;
usb_buf[0x03] = LOGITECH_G915_COMMIT_BYTE;
@ -107,7 +137,7 @@ void LogitechG915Controller::SendCommit()
hid_read_timeout(dev_handle, (unsigned char *)usb_buf, 20, LOGITECH_READ_TIMEOUT);
}
void LogitechG915Controller::InitializeDirect()
void LogitechG915Controller::BeginModeSet()
{
char usb_buf[20];
@ -120,7 +150,7 @@ void LogitechG915Controller::InitializeDirect()
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_4522_idx;
usb_buf[0x03] = 0x3E;
@ -139,7 +169,77 @@ void LogitechG915Controller::InitializeDirect()
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_4522_idx;
usb_buf[0x03] = 0x1E;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_handle, (unsigned char *)usb_buf, 20);
hid_read(dev_handle, (unsigned char *)usb_buf, 20);
}
void LogitechG915Controller::InitializeModeSet()
{
char usb_buf[20];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8071_idx;
usb_buf[0x03] = 0x5E;
usb_buf[0x04] = 0x01;
usb_buf[0x05] = 0x03;
usb_buf[0x06] = 0x07;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_handle, (unsigned char *)usb_buf, 20);
hid_read(dev_handle, (unsigned char *)usb_buf, 20);
}
void LogitechG915Controller::InitializeDirect()
{
char usb_buf[20];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_4522_idx;
usb_buf[0x03] = 0x3E;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_handle, (unsigned char *)usb_buf, 20);
hid_read(dev_handle, (unsigned char *)usb_buf, 20);
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_4522_idx;
usb_buf[0x03] = 0x1E;
@ -158,7 +258,7 @@ void LogitechG915Controller::InitializeDirect()
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8071_idx;
usb_buf[0x03] = 0x1E;
usb_buf[0x10] = 0x01;
@ -178,7 +278,7 @@ void LogitechG915Controller::InitializeDirect()
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8071_idx;
usb_buf[0x03] = 0x1E;
usb_buf[0x04] = 0x01;
@ -210,7 +310,7 @@ void LogitechG915Controller::SendSingleLed
| Set up a 6F packet with a single color |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8081_idx;
usb_buf[0x03] = LOGITECH_G915_ZONE_FRAME_TYPE_LITTLE;
@ -244,7 +344,7 @@ void LogitechG915Controller::SendDirectFrame
| Set up Lighting Control packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8081_idx;
usb_buf[0x03] = frame_type;
@ -265,6 +365,7 @@ void LogitechG915Controller::SendMode
unsigned char zone,
unsigned char mode,
unsigned short speed,
unsigned short brightness,
unsigned char red,
unsigned char green,
unsigned char blue
@ -282,35 +383,53 @@ void LogitechG915Controller::SendMode
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0x01;
usb_buf[0x02] = feature_8040_idx;
usb_buf[0x03] = 0x3D; //TODO: Check if it is the correct value for G915
usb_buf[0x04] = zone;
usb_buf[0x01] = device_index;
usb_buf[0x02] = feature_8071_idx;
usb_buf[0x03] = 0x1E;
usb_buf[0x04] = zone;
usb_buf[0x05] = mode;
usb_buf[0x06] = red;
usb_buf[0x07] = green;
usb_buf[0x08] = blue;
speed = 100 * speed;
if(mode != LOGITECH_G915_MODE_RIPPLE)
{
speed = 100 * speed;
}
if(mode == LOGITECH_G915_MODE_CYCLE)
// mode == LOGITECH_G915_MODE_OFF; No data to set
if(mode == LOGITECH_G915_MODE_STATIC)
{
usb_buf[0x0B] = speed >> 8;
usb_buf[0x0C] = speed & 0xFF;
usb_buf[0x0D] = 0x64;
usb_buf[0x09] = 0x02;
}
else if(mode == LOGITECH_G915_MODE_BREATHING)
else if((mode == LOGITECH_G915_MODE_BREATHING && zone == LOGITECH_G915_ZONE_MODE_KEYBOARD) \
|| (mode == LOGITECH_G915_LOGO_MODE_BREATHING && zone == LOGITECH_G915_ZONE_MODE_LOGO))
{
usb_buf[0x09] = speed >> 8;
usb_buf[0x0A] = speed & 0xFF;
usb_buf[0x0C] = 0x64;
usb_buf[0x09] = speed >> 8;
usb_buf[0x0A] = speed & 0xFF;
usb_buf[0x0C] = brightness & 0xFF;
}
else
else if((mode == LOGITECH_G915_MODE_CYCLE && zone == LOGITECH_G915_ZONE_MODE_KEYBOARD) \
|| (mode == LOGITECH_G915_LOGO_MODE_CYCLE && zone == LOGITECH_G915_ZONE_MODE_LOGO))
{
return;
usb_buf[0x0B] = speed >> 8;
usb_buf[0x0C] = speed & 0xFF;
usb_buf[0x0D] = brightness & 0xFF;
}
else if(mode == LOGITECH_G915_MODE_WAVE)
{
usb_buf[0x0C] = speed & 0xFF;
usb_buf[0x0D] = 0x01; // Direction control 0x01 is horizontal
usb_buf[0x0E] = brightness & 0xFF;
usb_buf[0x0F] = speed >> 8;
}
else if(mode == LOGITECH_G915_MODE_RIPPLE)
{
usb_buf[0x0B] = speed & 0xFF;
}
usb_buf[0x10] = 0x01;
/*-----------------------------------------------------*\
| Send packet |