Add support for Logitech G203 Lightsync

This commit is contained in:
Katzenbiber
2020-07-28 21:26:28 +02:00
committed by Adam Honse
parent 3bbc3da48b
commit 1be9f6e460
6 changed files with 382 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
#include "LogitechG203Controller.h"
#include "LogitechG203LController.h"
#include "LogitechG403Controller.h"
#include "LogitechG810Controller.h"
#include "RGBController.h"
#include "RGBController_LogitechG203.h"
#include "RGBController_LogitechG203L.h"
#include "RGBController_LogitechG403.h"
#include "RGBController_LogitechG810.h"
#include <vector>
@@ -22,6 +24,7 @@
| Mouse product IDs |
\*-----------------------------------------------------*/
#define LOGITECH_G203_PID 0xC084
#define LOGITECH_G203L_PID 0xC092
#define LOGITECH_G403_PID 0xC083
#define LOGITECH_G403H_PID 0xC08F
@@ -48,6 +51,7 @@ static const logitech_device device_list[] =
| Mice |
\*-------------------------------------------------------------------------------------------------------------*/
{ LOGITECH_VID, LOGITECH_G203_PID, 1, DEVICE_TYPE_MOUSE, "Logitech G203 Prodigy" },
{ LOGITECH_VID, LOGITECH_G203L_PID, 1, DEVICE_TYPE_MOUSE, "Logitech G203 Lightsync" },
{ LOGITECH_VID, LOGITECH_G403_PID, 1, DEVICE_TYPE_MOUSE, "Logitech G403 Prodigy" },
{ LOGITECH_VID, LOGITECH_G403H_PID, 1, DEVICE_TYPE_MOUSE, "Logitech G403 Hero" },
/*-------------------------------------------------------------------------------------------------------------*\
@@ -172,6 +176,17 @@ void DetectLogitechControllers(std::vector<RGBController*>& rgb_controllers)
}
break;
case LOGITECH_G203L_PID:
{
LogitechG203LController* controller = new LogitechG203LController(dev);
RGBController_LogitechG203L* rgb_controller = new RGBController_LogitechG203L(controller);
rgb_controller->name = device_list[device_idx].name;
rgb_controllers.push_back(rgb_controller);
}
break;
case LOGITECH_G403_PID:
case LOGITECH_G403H_PID:
{

View File

@@ -0,0 +1,140 @@
#include "LogitechG203LController.h"
#include <cstring>
LogitechG203LController::LogitechG203LController(hid_device* dev_handle)
{
dev = dev_handle;
}
void LogitechG203LController::SendApply()
{
unsigned char usb_buf[20];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x7A;
hid_write(dev, usb_buf, 20);
hid_read(dev, usb_buf, 20);
}
void LogitechG203LController::SetSingleLED(int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[20];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x19;
usb_buf[0x04] = (unsigned char)led;
usb_buf[0x05] = red;
usb_buf[0x06] = green;
usb_buf[0x07] = blue;
usb_buf[0x08] = 0xFF;
hid_write(dev, usb_buf, 20);
hid_read(dev, usb_buf, 20);
SendApply();
}
void LogitechG203LController::SetMode(
int mode,
int speed,
unsigned char bright,
unsigned char dir,
unsigned char red,
unsigned char green,
unsigned char blue)
{
unsigned char usb_buf[20];
memset(usb_buf, 0x00, sizeof(usb_buf));
//Header
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x0E;
usb_buf[0x03] = 0x1A;
//Common Data
usb_buf[0x04] = 0x00;
usb_buf[0x05] = (unsigned char)mode;
usb_buf[0x06] = red;
usb_buf[0x07] = green;
usb_buf[0x08] = blue;
//mode specific Data and position
if(mode == LOGITECH_G203L_MODE_STATIC) usb_buf[0x09] = 0x02;
if(mode == LOGITECH_G203L_MODE_CYCLE)
{
usb_buf[0x0B] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = bright;
}
if(mode == LOGITECH_G203L_MODE_BREATHING)
{
usb_buf[0x09] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0A] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0C] = bright;
}
if(mode == LOGITECH_G203L_MODE_WAVE)
{
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = dir ? 0x01 : 0x06; //0x01: Left->Right 0x06: Right->Left
usb_buf[0x0E] = bright;
usb_buf[0x0F] = (unsigned char)((speed>>8) & 0x000000FF);
}
if(mode == LOGITECH_G203L_MODE_COLORMIXING)
{
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0E] = bright;
}
//END BYTE
usb_buf[0x10] = 0x01;
hid_write(dev, usb_buf, 20);
hid_read(dev, usb_buf, 20);
}
void LogitechG203LController::SetDevice(std::vector<RGBColor> colors)
{
unsigned char usb_buf[20];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x1A;
usb_buf[0x04] = 0x01;
usb_buf[0x05] = RGBGetRValue(colors[0]);
usb_buf[0x06] = RGBGetGValue(colors[0]);
usb_buf[0x07] = RGBGetBValue(colors[0]);
usb_buf[0x08] = 0x02;
usb_buf[0x09] = RGBGetRValue(colors[1]);
usb_buf[0x0A] = RGBGetGValue(colors[1]);
usb_buf[0x0B] = RGBGetBValue(colors[1]);
usb_buf[0x0C] = 0x03;
usb_buf[0x0D] = RGBGetRValue(colors[2]);
usb_buf[0x0E] = RGBGetGValue(colors[2]);
usb_buf[0x0F] = RGBGetBValue(colors[2]);
usb_buf[0x10] = 0xFF;
hid_write(dev, usb_buf, 20);
hid_read(dev, usb_buf, 20);
SendApply();
}

View File

@@ -0,0 +1,32 @@
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
LOGITECH_G203L_MODE_DIRECT = 0x07,
LOGITECH_G203L_MODE_OFF = 0x00,
LOGITECH_G203L_MODE_STATIC = 0x01,
LOGITECH_G203L_MODE_CYCLE = 0x02,
LOGITECH_G203L_MODE_WAVE = 0x03,
LOGITECH_G203L_MODE_BREATHING = 0x04,
LOGITECH_G203L_MODE_COLORMIXING = 0x06,
};
class LogitechG203LController
{
public:
LogitechG203LController(hid_device* dev_handle);
~LogitechG203LController();
void SetSingleLED(int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(int mode, int speed, unsigned char brightness, unsigned char dir, unsigned char red, unsigned char green, unsigned char blue);
void SetDevice(std::vector<RGBColor> colors);
private:
hid_device* dev;
void SendApply();
};