Browse Source

Add logitech g pro keyboard support

merge-requests/901/head
sanchezzzs 2 months ago
committed by Adam Honse
parent
commit
2ccd141dab
  1. 2
      60-openrgb.rules
  2. 63
      Controllers/LogitechController/LogitechControllerDetect.cpp
  3. 186
      Controllers/LogitechController/LogitechGProKeyboardController.cpp
  4. 99
      Controllers/LogitechController/LogitechGProKeyboardController.h
  5. 370
      Controllers/LogitechController/RGBController_LogitechGProKeyboard.cpp
  6. 33
      Controllers/LogitechController/RGBController_LogitechGProKeyboard.h
  7. 4
      OpenRGB.pro

2
60-openrgb.rules

@ -351,6 +351,7 @@ SUBSYSTEMS=="usb", ATTR{idVendor}=="0cf2", ATTR{idProduct}=="7750", TAG+="uacces
# Logitech G813 #
# Logitech G815 #
# Logitech G915 #
# Logitech G Pro #
# #
# Mice: #
# Logitech G203 Prodigy #
@ -389,6 +390,7 @@ SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c333", TAG+="uacces
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c338", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c331", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c337", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c339", TAG+="uaccess" #G Pro Keyboard
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c232", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c33f", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c335", TAG+="uaccess", TAG+="G910"

63
Controllers/LogitechController/LogitechControllerDetect.cpp

@ -6,6 +6,7 @@
#include "LogitechG560Controller.h"
#include "LogitechG933Controller.h"
#include "LogitechG810Controller.h"
#include "LogitechGProKeyboardController.h"
#include "LogitechG910Controller.h"
#include "LogitechG815Controller.h"
#include "LogitechG915Controller.h"
@ -18,6 +19,7 @@
#include "RGBController_LogitechG560.h"
#include "RGBController_LogitechG933.h"
#include "RGBController_LogitechG810.h"
#include "RGBController_LogitechGProKeyboard.h"
#include "RGBController_LogitechG910.h"
#include "RGBController_LogitechG815.h"
#include "RGBController_LogitechG915.h"
@ -55,6 +57,7 @@ using namespace std::chrono_literals;
#define LOGITECH_G915_RECEIVER_PID 0xC541
#define LOGITECH_G910_ORION_SPARK_PID 0xC32B
#define LOGITECH_G910_PID 0xC335
#define LOGITECH_GPRO_KEYBOARD_1_PID 0xC339
/*-----------------------------------------------------*\
| Mouse product IDs |
@ -348,6 +351,65 @@ void DetectLogitechKeyboardG915Wired(hid_device_info* info, const std::string& n
}
}
void DetectLogitechKeyboardGPro(hid_device_info* info, const std::string& name)
{
/*-------------------------------------------------------------------------------------------------*\
| Logitech keyboards use two different usages, one for 20-byte packets and one for 64-byte packets |
| Usage 0x0602 for 20 byte, usage 0x0604 for 64 byte, both are on usage page 0xFF43 |
\*-------------------------------------------------------------------------------------------------*/
#ifdef USE_HID_USAGE
hid_device* dev_usage_0x0602 = nullptr;
hid_device* dev_usage_0x0604 = nullptr;
hid_device_info* info_temp = info;
while(info_temp)
{
if(info_temp->vendor_id == info->vendor_id // constant LOGITECH_VID
&& info_temp->product_id == info->product_id // NON-constant
&& info_temp->interface_number == info->interface_number // constant 1
&& info_temp->usage_page == info->usage_page) // constant 0xFF43
{
if(info_temp->usage == 0x0602)
{
dev_usage_0x0602 = hid_open_path(info_temp->path);
}
else if(info_temp->usage == 0x0604)
{
dev_usage_0x0604 = hid_open_path(info_temp->path);
}
}
if(dev_usage_0x0602 && dev_usage_0x0604)
{
break;
}
info_temp = info_temp->next;
}
if(dev_usage_0x0602 && dev_usage_0x0604)
{
LogitechGProKeyboardController* controller = new LogitechGProKeyboardController(dev_usage_0x0602, dev_usage_0x0604);
RGBController_LogitechGProKeyboard* rgb_controller = new RGBController_LogitechGProKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
else
{
// Not all of them could be opened, do some cleanup
hid_close(dev_usage_0x0602);
hid_close(dev_usage_0x0604);
}
#else
hid_device* dev = hid_open_path(info->path);
if(dev)
{
LogitechGProKeyboardController* controller = new LogitechGProKeyboardController(dev, dev);
RGBController_LogitechGProKeyboard* rgb_controller = new RGBController_LogitechGProKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
#endif
}
/*-----------------------------------------------------*\
| Logitech Mice |
\*-----------------------------------------------------*/
@ -568,6 +630,7 @@ REGISTER_HID_DETECTOR_IP ("Logitech G813 RGB Mechanical Gaming Keyboard", Dete
REGISTER_HID_DETECTOR_IP ("Logitech G815 RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardG815, LOGITECH_VID, LOGITECH_G815_PID, 1, 0xFF43);
REGISTER_HID_DETECTOR_IP ("Logitech G910 Orion Spark", DetectLogitechKeyboardG910, LOGITECH_VID, LOGITECH_G910_ORION_SPARK_PID, 1, 0xFF43);
REGISTER_HID_DETECTOR_IP ("Logitech G910 Orion Spectrum", DetectLogitechKeyboardG910, LOGITECH_VID, LOGITECH_G910_PID, 1, 0xFF43);
REGISTER_HID_DETECTOR_IP ("Logitech G Pro RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardGPro, LOGITECH_VID, LOGITECH_GPRO_KEYBOARD_1_PID, 1, 0xFF43);
REGISTER_HID_DETECTOR_IPU("Logitech G915 Wireless RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardG915, LOGITECH_VID, LOGITECH_G915_RECEIVER_PID, 2, 0xFF00, 2);
REGISTER_HID_DETECTOR_IPU("Logitech G915 Wireless RGB Mechanical Gaming Keyboard (Wired)", DetectLogitechKeyboardG915Wired, LOGITECH_VID, LOGITECH_G915_WIRED_PID, 2, 0xFF00, 2);
/*-------------------------------------------------------------------------------------------------------------------------------------------------*\

186
Controllers/LogitechController/LogitechGProKeyboardController.cpp

@ -0,0 +1,186 @@
/*-----------------------------------------*\
| LogitechGProController.cpp |
| |
| Driver for Logitech G Pro |
| keyboard light controller |
| |
| sanchezzzs 20/10/2021 |
\*-----------------------------------------*/
#include "LogitechGProKeyboardController.h"
#include <cstring>
LogitechGProKeyboardController::LogitechGProKeyboardController(hid_device* dev_handle_0x11, hid_device* dev_handle_0x12)
{
dev_pkt_0x11 = dev_handle_0x11;
dev_pkt_0x12 = dev_handle_0x12;
}
LogitechGProKeyboardController::~LogitechGProKeyboardController()
{
hid_close(dev_pkt_0x11);
hid_close(dev_pkt_0x12);
}
std::string LogitechGProKeyboardController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev_pkt_0x11, serial_string, 128);
if(ret != 0)
{
return("");
}
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
void LogitechGProKeyboardController::Commit()
{
SendCommit();
}
void LogitechGProKeyboardController::SetDirect
(
unsigned char zone,
unsigned char frame_count,
unsigned char * frame_data
)
{
SendDirectFrame(zone, frame_count, frame_data);
}
void LogitechGProKeyboardController::SetMode
(
unsigned char mode,
unsigned short speed,
unsigned char red,
unsigned char green,
unsigned char blue
)
{
SendMode(LOGITECH_GPRO_ZONE_MODE_KEYBOARD, mode, speed, red, green, blue);
SendMode(LOGITECH_GPRO_ZONE_MODE_LOGO, mode, speed, red, green, blue);
SendCommit();
}
/*-------------------------------------------------------------------------------------------------*\
| Private packet sending functions. |
\*-------------------------------------------------------------------------------------------------*/
void LogitechGProKeyboardController::SendCommit()
{
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] = 0xFF;
usb_buf[0x02] = 0x0C;
usb_buf[0x03] = 0x5D;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20);
hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20);
}
void LogitechGProKeyboardController::SendDirectFrame
(
unsigned char zone,
unsigned char frame_count,
unsigned char * frame_data
)
{
char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Lighting Control packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x12;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x0C;
usb_buf[0x03] = 0x3D;
usb_buf[0x05] = zone;
usb_buf[0x07] = frame_count;
/*-----------------------------------------------------*\
| Copy in frame data |
\*-----------------------------------------------------*/
memcpy(&usb_buf[0x08], frame_data, frame_count * 4);
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_pkt_0x12, (unsigned char *)usb_buf, 64);
hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20);
}
void LogitechGProKeyboardController::SendMode
(
unsigned char zone,
unsigned char mode,
unsigned short speed,
unsigned char red,
unsigned char green,
unsigned char blue
)
{
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] = 0x0D;
usb_buf[0x03] = 0x3D;
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_GPRO_MODE_CYCLE)
{
usb_buf[0x0B] = speed >> 8;
usb_buf[0x0C] = speed & 0xFF;
usb_buf[0x0D] = 0x64;
}
else if(mode == LOGITECH_GPRO_MODE_BREATHING)
{
usb_buf[0x09] = speed >> 8;
usb_buf[0x0A] = speed & 0xFF;
usb_buf[0x0C] = 0x64;
}
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20);
hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20);
}

99
Controllers/LogitechController/LogitechGProKeyboardController.h

@ -0,0 +1,99 @@
/*-----------------------------------------*\
| LogitechGProController.h |
| |
| Definitions and types for Logitech G Pro |
| keyboard light controller |
| |
| sanchezzzs 20/10/2021 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
LOGITECH_GPRO_ZONE_MODE_KEYBOARD = 0x00,
LOGITECH_GPRO_ZONE_MODE_LOGO = 0x01,
};
enum
{
LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD = 0x01,
LOGITECH_GPRO_ZONE_DIRECT_MEDIA = 0x02,
LOGITECH_GPRO_ZONE_DIRECT_LOGO = 0x10,
LOGITECH_GPRO_ZONE_DIRECT_INDICATORS = 0x40,
};
enum
{
LOGITECH_GPRO_MODE_OFF = 0x00,
LOGITECH_GPRO_MODE_STATIC = 0x01,
LOGITECH_GPRO_MODE_BREATHING = 0x02,
LOGITECH_GPRO_MODE_CYCLE = 0x03,
LOGITECH_GPRO_MODE_WAVE = 0x04,
};
/*---------------------------------------------------------------------------------------------*\
| Speed is 1000 for fast and 20000 for slow. |
| Values are multiplied by 100 later to give lots of GUI steps. |
\*---------------------------------------------------------------------------------------------*/
enum
{
LOGITECH_GPRO_SPEED_SLOWEST = 0xC8, /* Slowest speed */
LOGITECH_GPRO_SPEED_NORMAL = 0x32, /* Normal speed */
LOGITECH_GPRO_SPEED_FASTEST = 0x0A, /* Fastest speed */
};
class LogitechGProKeyboardController
{
public:
LogitechGProKeyboardController(hid_device* dev_handle_0x11, hid_device* dev_handle_0x12);
~LogitechGProKeyboardController();
std::string GetSerialString();
void Commit();
void SetDirect
(
unsigned char zone,
unsigned char frame_count,
unsigned char * frame_data
);
void SetMode
(
unsigned char mode,
unsigned short speed,
unsigned char red,
unsigned char green,
unsigned char blue
);
private:
hid_device* dev_pkt_0x11;
hid_device* dev_pkt_0x12;
void SendDirectFrame
(
unsigned char zone,
unsigned char frame_count,
unsigned char * frame_data
);
void SendMode
(
unsigned char zone,
unsigned char mode,
unsigned short speed,
unsigned char red,
unsigned char green,
unsigned char blue
);
void SendCommit();
};

370
Controllers/LogitechController/RGBController_LogitechGProKeyboard.cpp

@ -0,0 +1,370 @@
/*-----------------------------------------*\
| RGBController_LogitechGPro.cpp |
| |
| Generic RGB Interface for Logitech G Pro |
| Keyboard |
| |
| sanchezzzs 20/10/2021 |
\*-----------------------------------------*/
#include "RGBController_LogitechGProKeyboard.h"
//0xFFFFFFFF indicates an unused entry in matrix
#define NA 0xFFFFFFFF
static unsigned int matrix_map[7][19] =
{ { 111, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 116, 114, NA, NA, 113, NA, 112 },
{ 37, NA, 54, 55, 56, 57, NA, 58, 59, 60, 61, NA, 62, 63, 64, 65, 66, 67, 68 },
{ 49, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, NA, 41, 42, 38, NA, 69, 70, 71 },
{ 39, NA, 16, 22, 4, 17, NA, 19, 24, 20, 8, 14, 15, 43, 44, 45, 72, 73, 74 },
{ 53, NA, 0, 18, 3, 5, NA, 6, 7, 9, 10, 11, 47, 48, 46, 36, NA, NA, NA },
{ 99, 96, 25, 23, 2, 21, NA, 1, NA, 13, 12, 50, 51, 52, 103, NA, NA, 78, NA },
{ 98, 101, 100, NA, NA, NA, NA, 40, NA, NA, NA, NA, 104, 105, 97, 102, 76, 77, 75 } };
static const char* zone_names[] =
{
"Keyboard",
};
static zone_type zone_types[] =
{
ZONE_TYPE_MATRIX,
};
static const unsigned int zone_sizes[] =
{
94,
};
typedef struct
{
const char * name;
const unsigned char zone;
const unsigned char idx;
} led_type;
static const led_type led_names[] =
{
/* Key Label Zone, Index */
{ "Key: A", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x04 },
{ "Key: B", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x05 },
{ "Key: C", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x06 },
{ "Key: D", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x07 },
{ "Key: E", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x08 },
{ "Key: F", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x09 },
{ "Key: G", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0A },
{ "Key: H", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0B },
{ "Key: I", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0C },
{ "Key: J", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0D },
{ "Key: K", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0E },
{ "Key: L", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x0F },
{ "Key: M", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x10 },
{ "Key: N", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x11 },
{ "Key: O", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x12 },
{ "Key: P", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x13 },
{ "Key: Q", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x14 },
{ "Key: R", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x15 },
{ "Key: S", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x16 },
{ "Key: T", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x17 },
{ "Key: U", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x18 },
{ "Key: V", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x19 },
{ "Key: W", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1A },
{ "Key: X", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1B },
{ "Key: Y", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1C },
{ "Key: Z", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1D },
{ "Key: 1", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1E },
{ "Key: 2", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x1F },
{ "Key: 3", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x20 },
{ "Key: 4", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x21 },
{ "Key: 5", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x22 },
{ "Key: 6", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x23 },
{ "Key: 7", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x24 },
{ "Key: 8", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x25 },
{ "Key: 9", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x26 },
{ "Key: 0", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x27 },
{ "Key: Enter", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x28 },
{ "Key: Escape", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x29 },
{ "Key: Backspace", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2A },
{ "Key: Tab", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2B },
{ "Key: Space", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2C },
{ "Key: -", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2D },
{ "Key: =", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2E },
{ "Key: [", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x2F },
{ "Key: ]", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x30 },
{ "Key: \\ (ANSI)", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x31 },//ANSI only
{ "Key: #", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x32 },//ISO only
{ "Key: ;", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x33 },
{ "Key: '", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x34 },
{ "Key: `", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x35 },
{ "Key: ,", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x36 },
{ "Key: .", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x37 },
{ "Key: /", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x38 },
{ "Key: Caps Lock", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x39 },
{ "Key: F1", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3A },
{ "Key: F2", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3B },
{ "Key: F3", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3C },
{ "Key: F4", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3D },
{ "Key: F5", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3E },
{ "Key: F6", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x3F },
{ "Key: F7", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x40 },
{ "Key: F8", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x41 },
{ "Key: F9", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x42 },
{ "Key: F10", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x43 },
{ "Key: F11", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x44 },
{ "Key: F12", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x45 },
{ "Key: Print Screen", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x46 },
{ "Key: Scroll Lock", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x47 },
{ "Key: Pause/Break", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x48 },
{ "Key: Insert", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x49 },
{ "Key: Home", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4A },
{ "Key: Page Up", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4B },
{ "Key: Delete", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4C },
{ "Key: End", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4D },
{ "Key: Page Down", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4E },
{ "Key: Right Arrow", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x4F },
{ "Key: Left Arrow", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x50 },
{ "Key: Down Arrow", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x51 },
{ "Key: Up Arrow", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x52 },
{ "Key: \\ (ISO)", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x64 },//ISO only
{ "Key: Menu", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0x65 },
{ "Key: Left Control", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE0 },
{ "Key: Left Shift", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE1 },
{ "Key: Left Alt", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE2 },
{ "Key: Left Windows", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE3 },
{ "Key: Right Control", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE4 },
{ "Key: Right Shift", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE5 },
{ "Key: Right Alt", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE6 },
{ "Key: Fn", LOGITECH_GPRO_ZONE_DIRECT_KEYBOARD, 0xE7 },
{ "Logo", LOGITECH_GPRO_ZONE_DIRECT_LOGO, 0x01 },
{ "Lighting", LOGITECH_GPRO_ZONE_DIRECT_INDICATORS, 0x01 },
{ "Game Mode", LOGITECH_GPRO_ZONE_DIRECT_INDICATORS, 0x02 },
{ "Caps Lock Indicator", LOGITECH_GPRO_ZONE_DIRECT_INDICATORS, 0x03 },
{ "Scroll Lock Indicator", LOGITECH_GPRO_ZONE_DIRECT_INDICATORS, 0x04 },
};
RGBController_LogitechGProKeyboard::RGBController_LogitechGProKeyboard(LogitechGProKeyboardController* logitech_ptr)
{
logitech = logitech_ptr;
name = "Logitech Keyboard Device";
vendor = "Logitech";
type = DEVICE_TYPE_KEYBOARD;
description = "Logitech Keyboard Device";
serial = logitech->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Static;
Static.name = "Static";
Static.value = LOGITECH_GPRO_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Static.colors_min = 1;
Static.colors_max = 1;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.colors.resize(1);
modes.push_back(Static);
mode Off;
Off.name = "Off";
Off.value = LOGITECH_GPRO_MODE_OFF;
Off.flags = 0;
Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off);
mode Cycle;
Cycle.name = "Cycle";
Cycle.value = LOGITECH_GPRO_MODE_CYCLE;
Cycle.flags = MODE_FLAG_HAS_SPEED;
Cycle.color_mode = MODE_COLORS_NONE;
Cycle.speed_min = LOGITECH_GPRO_SPEED_SLOWEST;
Cycle.speed_max = LOGITECH_GPRO_SPEED_FASTEST;
Cycle.speed = LOGITECH_GPRO_SPEED_NORMAL;
modes.push_back(Cycle);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = LOGITECH_GPRO_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED;
Breathing.colors_min = 1;
Breathing.colors_max = 1;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors.resize(1);
Breathing.speed_min = LOGITECH_GPRO_SPEED_SLOWEST;
Breathing.speed_max = LOGITECH_GPRO_SPEED_FASTEST;
Breathing.speed = LOGITECH_GPRO_SPEED_NORMAL;
modes.push_back(Breathing);
SetupZones();
}
RGBController_LogitechGProKeyboard::~RGBController_LogitechGProKeyboard()
{
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
{
if(zones[zone_index].matrix_map != NULL)
{
delete zones[zone_index].matrix_map;
}
}
delete logitech;
}
void RGBController_LogitechGProKeyboard::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
unsigned int total_led_count = 0;
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{
zone new_zone;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_sizes[zone_idx];
new_zone.leds_max = zone_sizes[zone_idx];
new_zone.leds_count = zone_sizes[zone_idx];
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
{
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = 7;
new_zone.matrix_map->width = 19;
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
}
else
{
new_zone.matrix_map = NULL;
}
zones.push_back(new_zone);
total_led_count += zone_sizes[zone_idx];
}
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
{
led new_led;
new_led.name = led_names[led_idx].name;
new_led.value = ( led_names[led_idx].zone << 8 ) + led_names[led_idx].idx;
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_LogitechGProKeyboard::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_LogitechGProKeyboard::DeviceUpdateLEDs()
{
#define MAX_FRAMES_PER_PACKET 0x0E
unsigned char frame_buf[MAX_FRAMES_PER_PACKET * 4];
unsigned char frame_cnt = 0;
unsigned char prev_zone = 0;
unsigned char zone = 0;
unsigned char idx = 0;
/*---------------------------------------------------------*\
| TODO: Send packets with multiple LED frames |
\*---------------------------------------------------------*/
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
{
zone = ( leds[led_idx].value >> 8 );
idx = ( leds[led_idx].value & 0xFF );
if((zone != prev_zone) && (frame_cnt != 0))
{
logitech->SetDirect(prev_zone, frame_cnt, frame_buf);
frame_cnt = 0;
}
frame_buf[(frame_cnt * 4) + 0] = idx;
frame_buf[(frame_cnt * 4) + 1] = RGBGetRValue(colors[led_idx]);
frame_buf[(frame_cnt * 4) + 2] = RGBGetGValue(colors[led_idx]);
frame_buf[(frame_cnt * 4) + 3] = RGBGetBValue(colors[led_idx]);
frame_cnt++;
prev_zone = zone;
if(frame_cnt == MAX_FRAMES_PER_PACKET)
{
logitech->SetDirect(prev_zone, frame_cnt, frame_buf);
frame_cnt = 0;
}
}
if(frame_cnt != 0)
{
logitech->SetDirect(prev_zone, frame_cnt, frame_buf);
}
logitech->Commit();
}
void RGBController_LogitechGProKeyboard::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_LogitechGProKeyboard::UpdateSingleLED(int led)
{
unsigned char frame[4];
unsigned char zone;
unsigned char idx;
zone = ( leds[led].value >> 8 );
idx = ( leds[led].value & 0xFF );
frame[0] = idx;
frame[1] = RGBGetRValue(colors[led]);
frame[2] = RGBGetGValue(colors[led]);
frame[3] = RGBGetBValue(colors[led]);
logitech->SetDirect(zone, 1, frame);
logitech->Commit();
}
void RGBController_LogitechGProKeyboard::SetCustomMode()
{
active_mode = 0;
}
void RGBController_LogitechGProKeyboard::DeviceUpdateMode()
{
/*---------------------------------------------------------*\
| Direct mode does not send a mode packet |
| Call UpdateLEDs to send direct packet |
\*---------------------------------------------------------*/
if(active_mode == 0xFFFF)
{
UpdateLEDs();
return;
}
unsigned char red = 0;
unsigned char grn = 0;
unsigned char blu = 0;
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
red = RGBGetRValue(modes[active_mode].colors[0]);
grn = RGBGetGValue(modes[active_mode].colors[0]);
blu = RGBGetBValue(modes[active_mode].colors[0]);
}
logitech->SetMode(modes[active_mode].value, modes[active_mode].speed, red, grn, blu);
}

33
Controllers/LogitechController/RGBController_LogitechGProKeyboard.h

@ -0,0 +1,33 @@
/*-----------------------------------------*\
| RGBController_LogitechGPro.h |
| |
| Generic RGB Interface for Logitech G Pro |
| keyboard |
| |
| sanchezzzs 20/10/2021 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "LogitechGProKeyboardController.h"
class RGBController_LogitechGProKeyboard : public RGBController
{
public:
RGBController_LogitechGProKeyboard(LogitechGProKeyboardController* logitech_ptr);
~RGBController_LogitechGProKeyboard();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
LogitechGProKeyboardController* logitech;
};

4
OpenRGB.pro

@ -363,6 +363,7 @@ HEADERS +=
Controllers/LogitechController/LogitechG560Controller.h \
Controllers/LogitechController/LogitechG933Controller.h \
Controllers/LogitechController/LogitechG810Controller.h \
Controllers/LogitechController/LogitechGProKeyboardController.h \
Controllers/LogitechController/LogitechG910Controller.h \
Controllers/LogitechController/LogitechG815Controller.h \
Controllers/LogitechController/LogitechG915Controller.h \
@ -374,6 +375,7 @@ HEADERS +=
Controllers/LogitechController/RGBController_LogitechG560.h \
Controllers/LogitechController/RGBController_LogitechG933.h \
Controllers/LogitechController/RGBController_LogitechG810.h \
Controllers/LogitechController/RGBController_LogitechGProKeyboard.h \
Controllers/LogitechController/RGBController_LogitechG910.h \
Controllers/LogitechController/RGBController_LogitechG815.h \
Controllers/LogitechController/RGBController_LogitechG915.h \
@ -763,6 +765,7 @@ SOURCES +=
Controllers/LogitechController/LogitechG560Controller.cpp \
Controllers/LogitechController/LogitechG933Controller.cpp \
Controllers/LogitechController/LogitechG810Controller.cpp \
Controllers/LogitechController/LogitechGProKeyboardController.cpp \
Controllers/LogitechController/LogitechG910Controller.cpp \
Controllers/LogitechController/LogitechG815Controller.cpp \
Controllers/LogitechController/LogitechG915Controller.cpp \
@ -774,6 +777,7 @@ SOURCES +=
Controllers/LogitechController/RGBController_LogitechG560.cpp \
Controllers/LogitechController/RGBController_LogitechG933.cpp \
Controllers/LogitechController/RGBController_LogitechG810.cpp \
Controllers/LogitechController/RGBController_LogitechGProKeyboard.cpp \
Controllers/LogitechController/RGBController_LogitechG910.cpp \
Controllers/LogitechController/RGBController_LogitechG815.cpp \
Controllers/LogitechController/RGBController_LogitechG915.cpp \

Loading…
Cancel
Save