Add support for Logitech G502 Proteus Spectrum and G512 RGB.

- Set the G512 RGB to use G810 driver
- Add driver and interface for the G502 Proteus Spectrum
This commit is contained in:
kernzerfall
2020-07-28 19:28:20 +03:00
committed by Adam Honse
parent ee61b87fe4
commit c15ceaa26c
6 changed files with 302 additions and 0 deletions

View File

@@ -2,11 +2,13 @@
#include "LogitechG203Controller.h"
#include "LogitechG203LController.h"
#include "LogitechG403Controller.h"
#include "LogitechG502PSController.h"
#include "LogitechG810Controller.h"
#include "RGBController.h"
#include "RGBController_LogitechG203.h"
#include "RGBController_LogitechG203L.h"
#include "RGBController_LogitechG403.h"
#include "RGBController_LogitechG502PS.h"
#include "RGBController_LogitechG810.h"
#include <vector>
#include <hidapi/hidapi.h>
@@ -21,6 +23,7 @@
#define LOGITECH_G810_1_PID 0xC337
#define LOGITECH_G810_2_PID 0xC331
#define LOGITECH_G512_PID 0xC342
#define LOGITECH_G512_RGB_PID 0xC33C
/*-----------------------------------------------------*\
| Mouse product IDs |
\*-----------------------------------------------------*/
@@ -28,6 +31,7 @@
#define LOGITECH_G203L_PID 0xC092
#define LOGITECH_G403_PID 0xC083
#define LOGITECH_G403H_PID 0xC08F
#define LOGITECH_G502_PS_PID 0xC332
typedef struct
{
@@ -48,6 +52,7 @@ static const logitech_device device_list[] =
{ LOGITECH_VID, LOGITECH_G810_1_PID, 1, DEVICE_TYPE_KEYBOARD, "Logitech G810 Orion Spectrum" },
{ LOGITECH_VID, LOGITECH_G810_2_PID, 1, DEVICE_TYPE_KEYBOARD, "Logitech G810 Orion Spectrum" },
{ LOGITECH_VID, LOGITECH_G512_PID, 1, DEVICE_TYPE_KEYBOARD, "Logitech G512" },
{ LOGITECH_VID, LOGITECH_G512_RGB_PID, 1, DEVICE_TYPE_KEYBOARD, "Logitech G512 RGB" },
/*-------------------------------------------------------------------------------------------------------------*\
| Mice |
\*-------------------------------------------------------------------------------------------------------------*/
@@ -55,6 +60,7 @@ static const logitech_device device_list[] =
{ 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" },
{ LOGITECH_VID, LOGITECH_G502_PS_PID, 1, DEVICE_TYPE_MOUSE, "Logitech G502 Proteus Spectrum"},
/*-------------------------------------------------------------------------------------------------------------*\
| Mousemats |
\*-------------------------------------------------------------------------------------------------------------*/
@@ -195,6 +201,13 @@ void DetectLogitechControllers(std::vector<RGBController*>& rgb_controllers)
RGBController_LogitechG403* rgb_controller = new RGBController_LogitechG403(controller);
rgb_controller->name = device_list[device_idx].name;
rgb_controllers.push_back(rgb_controller);
}
case LOGITECH_G502_PS_PID:
{
LogitechG502PSController* controller = new LogitechG502PSController(dev);
RGBController_LogitechG502PS* rgb_controller = new RGBController_LogitechG502PS(controller);
rgb_controller->name = device_list[device_idx].name;
rgb_controllers.push_back(rgb_controller);
}

View File

@@ -0,0 +1,77 @@
/*-----------------------------------------*\
| Logitech502PSController.cpp |
| |
| Driver for Logitech G502 Proteus |
| Spectrum mouse lighting controller |
| |
| kernzerfall 07/28/2020 |
\*-----------------------------------------*/
#include "LogitechG502PSController.h"
#include <cstring>
LogitechG502PSController::LogitechG502PSController(hid_device* dev_handle)
{
dev = dev_handle;
}
LogitechG502PSController::~LogitechG502PSController()
{
hid_close(dev);
}
void LogitechG502PSController::SendMouseMode
(
unsigned char mode,
std::uint16_t speed,
unsigned char channel,
unsigned char red,
unsigned char green,
unsigned char blue
)
{
unsigned char usb_buf[20];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Lighting Control packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x02;
usb_buf[0x03] = 0x3A;
usb_buf[0x04] = channel;
usb_buf[0x05] = mode;
usb_buf[0x06] = red;
usb_buf[0x07] = green;
usb_buf[0x08] = blue;
speed = 1000 + 4750 * (LOGITECH_G502_PS_SPEED_FASTEST - speed);
if(mode == LOGITECH_G502_PS_MODE_CYCLE)
{
usb_buf[0x0B] = speed >> 8;
usb_buf[0x0C] = speed & 0xFF;
usb_buf[0x0D] = 0x64;
}
else if(mode == LOGITECH_G502_PS_MODE_BREATHING)
{
usb_buf[0x09] = speed >> 8;
usb_buf[0x0A] = speed & 0xFF;
usb_buf[0x0C] = 0x64;
}else if(mode == LOGITECH_G502_PS_MODE_STATIC){
usb_buf[0x09] = 0x02;
}
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 20);
hid_read(dev, usb_buf, 20);
}

View File

@@ -0,0 +1,53 @@
/*-----------------------------------------*\
| Logitech502PSController.h |
| |
| Definitions and types for Logitech |
| G502 Proteus Spectrum mouse lighting |
| controller |
| |
| kernzerfall 07/28/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
LOGITECH_G502_PS_MODE_OFF = 0x00,
LOGITECH_G502_PS_MODE_STATIC = 0x01,
LOGITECH_G502_PS_MODE_CYCLE = 0x03,
LOGITECH_G502_PS_MODE_BREATHING = 0x02
};
enum
{
LOGITECH_G502_PS_SPEED_SLOWEST = 0x00, /* Slowest speed */
LOGITECH_G502_PS_SPEED_SLOW = 0x01, /* Slow speed */
LOGITECH_G502_PS_SPEED_NORMAL = 0x02, /* Normal speed */
LOGITECH_G502_PS_SPEED_FAST = 0x03, /* Fast speed */
LOGITECH_G502_PS_SPEED_FASTEST = 0x04, /* Fastest speed */
};
class LogitechG502PSController
{
public:
LogitechG502PSController(hid_device* dev_handle);
~LogitechG502PSController();
void SendMouseMode
(
unsigned char mode,
unsigned short speed,
unsigned char channel,
unsigned char red,
unsigned char green,
unsigned char blue
);
private:
hid_device* dev;
};