diff --git a/60-openrgb.rules b/60-openrgb.rules index 39946f0c..977d3f47 100644 --- a/60-openrgb.rules +++ b/60-openrgb.rules @@ -348,6 +348,7 @@ SUBSYSTEMS=="usb", ATTR{idVendor}=="0cf2", ATTR{idProduct}=="7750", TAG+="uacces # Logitech G810 #2 # # Logitech G813 # # Logitech G815 # +# Logitech G915 # # # # Mice: # # Logitech G203 Prodigy # @@ -388,6 +389,8 @@ SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c337", TAG+="uacces 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" #G910 +SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c541", TAG+="uaccess" #G915 Receiver +SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c33e", TAG+="uaccess" #G915 Wired SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c084", TAG+="uaccess" SUBSYSTEMS=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c092", TAG+="uaccess" diff --git a/Controllers/LogitechController/LogitechControllerDetect.cpp b/Controllers/LogitechController/LogitechControllerDetect.cpp index 29fb9428..a5523d13 100644 --- a/Controllers/LogitechController/LogitechControllerDetect.cpp +++ b/Controllers/LogitechController/LogitechControllerDetect.cpp @@ -8,6 +8,7 @@ #include "LogitechG810Controller.h" #include "LogitechG910Controller.h" #include "LogitechG815Controller.h" +#include "LogitechG915Controller.h" #include "LogitechGLightsyncController.h" #include "LogitechLightspeedController.h" #include "LogitechX56Controller.h" @@ -19,6 +20,7 @@ #include "RGBController_LogitechG810.h" #include "RGBController_LogitechG910.h" #include "RGBController_LogitechG815.h" +#include "RGBController_LogitechG915.h" #include "RGBController_LogitechGLightsync.h" #include "RGBController_LogitechGLightsync1zone.h" #include "RGBController_LogitechLightspeed.h" @@ -49,6 +51,8 @@ using namespace std::chrono_literals; #define LOGITECH_G810_2_PID 0xC337 #define LOGITECH_G813_PID 0xC232 #define LOGITECH_G815_PID 0xC33F +#define LOGITECH_G915_WIRED_PID 0xC33E +#define LOGITECH_G915_RECEIVER_PID 0xC541 #define LOGITECH_G910_ORION_SPARK_PID 0xC32B #define LOGITECH_G910_PID 0xC335 @@ -314,6 +318,140 @@ void DetectLogitechKeyboardG815(hid_device_info* info, const std::string& name) #endif } +void DetectLogitechKeyboardG915(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_0x0001 = nullptr; + hid_device* dev_usage_0x0002 = 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 2 + && info_temp->usage_page == info->usage_page) // constant 0xFF00 + { + if(info_temp->usage == 0x0001) + { + dev_usage_0x0001 = hid_open_path(info_temp->path); + } + else if(info_temp->usage == 0x0002) + { + dev_usage_0x0002 = hid_open_path(info_temp->path); + } + } + if(dev_usage_0x0001 && dev_usage_0x0002) + { + break; + } + info_temp = info_temp->next; + } + if(dev_usage_0x0001 && dev_usage_0x0002) + { + LogitechG915Controller* controller = new LogitechG915Controller(dev_usage_0x0001, dev_usage_0x0002, false); + RGBController_LogitechG915* rgb_controller = new RGBController_LogitechG915(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + else + { + /*-------------------------------------------------*\ + | Not all of them could be opened, do some cleanup | + \*-------------------------------------------------*/ + if(dev_usage_0x0001) + { + hid_close(dev_usage_0x0001); + } + if(dev_usage_0x0002) + { + hid_close(dev_usage_0x0002); + } + } +#else + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + LogitechG915Controller* controller = new LogitechG915Controller(dev, dev, false); + RGBController_LogitechG915* rgb_controller = new RGBController_LogitechG915(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +#endif +} + +void DetectLogitechKeyboardG915Wired(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_0x0001 = nullptr; + hid_device* dev_usage_0x0002 = 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 2 + && info_temp->usage_page == info->usage_page) // constant 0xFF00 + { + if(info_temp->usage == 0x0001) + { + dev_usage_0x0001 = hid_open_path(info_temp->path); + } + else if(info_temp->usage == 0x0002) + { + dev_usage_0x0002 = hid_open_path(info_temp->path); + } + } + if(dev_usage_0x0001 && dev_usage_0x0002) + { + break; + } + info_temp = info_temp->next; + } + if(dev_usage_0x0001 && dev_usage_0x0002) + { + LogitechG915Controller* controller = new LogitechG915Controller(dev_usage_0x0001, dev_usage_0x0002, true); + RGBController_LogitechG915* rgb_controller = new RGBController_LogitechG915(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + else + { + /*-------------------------------------------------*\ + | Not all of them could be opened, do some cleanup | + \*-------------------------------------------------*/ + if(dev_usage_0x0001) + { + hid_close(dev_usage_0x0001); + } + if(dev_usage_0x0002) + { + hid_close(dev_usage_0x0002); + } + } +#else + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + LogitechG915Controller* controller = new LogitechG915Controller(dev, dev, true); + RGBController_LogitechG915* rgb_controller = new RGBController_LogitechG915(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +#endif +} + /*-----------------------------------------------------*\ | Logitech Mice | \*-----------------------------------------------------*/ @@ -539,6 +677,8 @@ 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 G915 Wireless RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardG915, LOGITECH_VID, LOGITECH_G915_RECEIVER_PID, 2, 0xFF00); +REGISTER_HID_DETECTOR_IP ("Logitech G915 Wireless RGB Mechanical Gaming Keyboard (Wired)", DetectLogitechKeyboardG915Wired, LOGITECH_VID, LOGITECH_G915_WIRED_PID, 2, 0xFF00); /*-------------------------------------------------------------------------------------------------------------------------------------------------*\ | Mice | \*-------------------------------------------------------------------------------------------------------------------------------------------------*/ diff --git a/Controllers/LogitechController/LogitechG915Controller.cpp b/Controllers/LogitechController/LogitechG915Controller.cpp new file mode 100644 index 00000000..ff6208ae --- /dev/null +++ b/Controllers/LogitechController/LogitechG915Controller.cpp @@ -0,0 +1,317 @@ +/*-----------------------------------------*\ +| LogitechG915Controller.cpp | +| | +| Generic RGB Interface for Logitech G915 | +| RGB Mechanical Gaming Keyboard | +| | +| Cheerpipe 3/20/2021 | +\*-----------------------------------------*/ + +#include "LogitechG915Controller.h" +#include + +LogitechG915Controller::LogitechG915Controller(hid_device* dev_handle_0x11, hid_device* dev_handle_0x12, bool wired) +{ + dev_pkt_0x11 = dev_handle_0x11; + dev_pkt_0x12 = dev_handle_0x12; + if (wired) { + feature_4522_idx = 0x0e; + feature_8040_idx = 0x13; + feature_8071_idx = 0x09; + feature_8081_idx = 0x0a; + } else { + feature_4522_idx = 0x0f; + feature_8040_idx = 0x14; + feature_8071_idx = 0x0a; + feature_8081_idx = 0x0b; + } +} + +LogitechG915Controller::~LogitechG915Controller() +{ + +} + +std::string LogitechG915Controller::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 LogitechG915Controller::Commit() +{ + SendCommit(); +} + +void LogitechG915Controller::SetDirect + ( + unsigned char frame_type, + unsigned char * frame_data + ) +{ + SendDirectFrame(frame_type, frame_data); +} + +void LogitechG915Controller::SetMode + ( + unsigned char mode, + unsigned short speed, + 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(); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +void LogitechG915Controller::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] = 0x01; + usb_buf[0x02] = feature_8081_idx; + usb_buf[0x03] = LOGITECH_G915_COMMIT_BYTE; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read_timeout(dev_pkt_0x11, (unsigned char *)usb_buf, 20, LOGITECH_READ_TIMEOUT); +} + +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] = 0x01; + usb_buf[0x02] = feature_4522_idx; + usb_buf[0x03] = 0x3E; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (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] = 0x01; + usb_buf[0x02] = feature_4522_idx; + usb_buf[0x03] = 0x1E; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (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] = 0x01; + usb_buf[0x02] = feature_8071_idx; + usb_buf[0x03] = 0x1E; + usb_buf[0x10] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (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] = 0x01; + usb_buf[0x02] = feature_8071_idx; + usb_buf[0x03] = 0x1E; + usb_buf[0x04] = 0x01; + usb_buf[0x10] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20); +} + +void LogitechG915Controller::SendSingleLed + ( + unsigned char keyCode, + unsigned char r, + unsigned char g, + unsigned char b + ) +{ + char usb_buf[20]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | Set up a 6F packet with a single color | + \*-----------------------------------------------------*/ + usb_buf[0x00] = 0x11; + usb_buf[0x01] = 0x01; + usb_buf[0x02] = feature_8081_idx; + usb_buf[0x03] = LOGITECH_G915_ZONE_FRAME_TYPE_LITTLE; + + usb_buf[0x04] = keyCode; + + usb_buf[0x05] = r; + usb_buf[0x06] = g; + usb_buf[0x07] = b; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20); +} + +void LogitechG915Controller::SendDirectFrame + ( + unsigned char frame_type, + unsigned char * frame_data + ) +{ + 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] = 0x01; + usb_buf[0x02] = feature_8081_idx; + usb_buf[0x03] = frame_type; + + /*-----------------------------------------------------*\ + | Copy in frame data | + \*-----------------------------------------------------*/ + memcpy(&usb_buf[0x04], frame_data, 16); + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read_timeout(dev_pkt_0x11, (unsigned char *)usb_buf, 20, LOGITECH_READ_TIMEOUT); +} + +void LogitechG915Controller::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] = 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[0x05] = mode; + + usb_buf[0x06] = red; + usb_buf[0x07] = green; + usb_buf[0x08] = blue; + + speed = 100 * speed; + + if(mode == LOGITECH_G915_MODE_CYCLE) + { + usb_buf[0x0B] = speed >> 8; + usb_buf[0x0C] = speed & 0xFF; + usb_buf[0x0D] = 0x64; + } + else if(mode == LOGITECH_G915_MODE_BREATHING) + { + usb_buf[0x09] = speed >> 8; + usb_buf[0x0A] = speed & 0xFF; + usb_buf[0x0C] = 0x64; + } + else + { + return; + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev_pkt_0x11, (unsigned char *)usb_buf, 20); + hid_read(dev_pkt_0x11, (unsigned char *)usb_buf, 20); +} diff --git a/Controllers/LogitechController/LogitechG915Controller.h b/Controllers/LogitechController/LogitechG915Controller.h new file mode 100644 index 00000000..5c93dfe1 --- /dev/null +++ b/Controllers/LogitechController/LogitechG915Controller.h @@ -0,0 +1,118 @@ +/*-----------------------------------------*\ +| LogitechG915Controller.h | +| | +| Generic RGB Interface for Logitech G915 | +| RGB Mechanical Gaming Keyboard | +| | +| Cheerpipe 3/20/2021 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#define LOGITECH_G915_COMMIT_BYTE 0x7F +#define LOGITECH_READ_TIMEOUT 300 //Timeout in ms + +#pragma once + +enum +{ + LOGITECH_G915_ZONE_MODE_KEYBOARD = 0x00, + LOGITECH_G915_ZONE_MODE_LOGO = 0x01, + LOGITECH_G915_ZONE_MODE_MULTIMEDIA = 0X02, + LOGITECH_G915_ZONE_MODE_GKEYS = 0x03, + LOGITECH_G915_ZONE_MODE_MODIFIERS = 0x04 +}; + +enum +{ + LOGITECH_G915_ZONE_FRAME_TYPE_LITTLE = 0x1F, + LOGITECH_G915_ZONE_FRAME_TYPE_BIG = 0x6F +}; + +enum +{ + LOGITECH_G915_ZONE_DIRECT_KEYBOARD = 0x01, + LOGITECH_G915_ZONE_DIRECT_MEDIA = 0x02, + LOGITECH_G915_ZONE_DIRECT_LOGO = 0x10, + LOGITECH_G915_ZONE_DIRECT_INDICATORS = 0x40, +}; + +enum +{ + LOGITECH_G915_MODE_OFF = 0x00, + LOGITECH_G915_MODE_STATIC = 0x01, + LOGITECH_G915_MODE_BREATHING = 0x02, + LOGITECH_G915_MODE_CYCLE = 0x03, + LOGITECH_G915_MODE_WAVE = 0x04, + LOGITECH_G915_MODE_DIRECT = 0x05, +}; + +/*---------------------------------------------------------------------------------------------*\ +| Speed is 1000 for fast and 20000 for slow. | +| Values are multiplied by 100 later to give lots of GUI steps. | +\*---------------------------------------------------------------------------------------------*/ +enum +{ + LOGITECH_G915_SPEED_SLOWEST = 0xC8, /* Slowest speed */ + LOGITECH_G915_SPEED_NORMAL = 0x32, /* Normal speed */ + LOGITECH_G915_SPEED_FASTEST = 0x0A, /* Fastest speed */ +}; + +class LogitechG915Controller +{ +public: + LogitechG915Controller(hid_device* dev_handle_0x11, hid_device* dev_handle_0x12, bool wired); + ~LogitechG915Controller(); + + std::string GetSerialString(); + void Commit(); + void InitializeDirect(); + void SetDirect + ( + unsigned char frame_type, + unsigned char * frame_data + ); + void SendSingleLed + ( + unsigned char keyCode, + unsigned char r, + unsigned char g, + unsigned char b + ); + 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; + char feature_4522_idx; + char feature_8040_idx; + char feature_8071_idx; + char feature_8081_idx; + + void SendDirectFrame + ( + unsigned char frame_type, + 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(); +}; diff --git a/Controllers/LogitechController/RGBController_LogitechG915.cpp b/Controllers/LogitechController/RGBController_LogitechG915.cpp new file mode 100644 index 00000000..82d4f707 --- /dev/null +++ b/Controllers/LogitechController/RGBController_LogitechG915.cpp @@ -0,0 +1,526 @@ +/*-----------------------------------------*\ +| RGBController_LogitechG915.cpp | +| | +| Generic RGB Interface for Logitech G915 | +| RGB Mechanical Gaming Keyboard | +| | +| Cheerpipe 3/20/2021 | +\*-----------------------------------------*/ + +#include "RGBController_LogitechG915.h" +#include +#include +#include + +#define NA 0xFFFFFFFF +const size_t max_key_per_color = 13; +const size_t data_size = 16; + +static unsigned int matrix_map[7][27] = + { { 110, NA, NA, NA, NA, NA, NA, NA, NA, NA, 111, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA }, + { NA, NA, 37, NA, 54, 55, 56, 57, NA, 58, 59, 60, 61, NA, 62, 63, 64, 65, NA, 66, 67, 68, NA, 106, 107, 108, 109 }, + { 112, NA, 49, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, NA, 41, 42, 38, NA, NA, 69, 70, 71, NA, 79, 80, 81, 82 }, + { 113, NA, 39, NA, 16, 22, 4, 17, NA, 19, 24, 20, 8, 14, 15, 43, 44, 45, NA, 72, 73, 74, NA, 91, 92, 93, 83 }, + { 114, NA, 53, NA, 0, 18, 3, 5, NA, 6, 7, 9, 10, 11, 47, 48, 46, 36, NA, NA, NA, NA, NA, 88, 89, 90, NA }, + { 115, NA, 99, NA, 25, 23, 2, 21, NA, 1, NA, 13, 12, 50, 51, 52, 103, NA, NA, NA, 78, NA, NA, 85, 86, 87, 84 }, + { 116, NA, 98, 101, 100, NA, NA, NA, NA, 40, NA, NA, NA, NA, 104, 105, 97, 102, NA, 76, 77, 75, NA, 94, NA, 95, NA } }; + +static const char* zone_names[] = +{ + "Keyboard", +}; + +static zone_type zone_types[] = +{ + ZONE_TYPE_MATRIX, +}; + +static const unsigned int zone_sizes[] = +{ + 117, +}; + +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_G915_ZONE_DIRECT_KEYBOARD, 0x04 }, + { "Key: B", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x05 }, + { "Key: C", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x06 }, + { "Key: D", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x07 }, + { "Key: E", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x08 }, + { "Key: F", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x09 }, + { "Key: G", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0A }, + { "Key: H", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0B }, + { "Key: I", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0C }, + { "Key: J", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0D }, + { "Key: K", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0E }, + { "Key: L", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x0F }, + { "Key: M", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x10 }, + { "Key: N", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x11 }, + { "Key: O", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x12 }, + { "Key: P", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x13 }, + { "Key: Q", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x14 }, + { "Key: R", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x15 }, + { "Key: S", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x16 }, + { "Key: T", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x17 }, + { "Key: U", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x18 }, + { "Key: V", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x19 }, + { "Key: W", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1A }, + { "Key: X", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1B }, + { "Key: Y", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1C }, + { "Key: Z", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1D }, + { "Key: 1", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1E }, + { "Key: 2", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x1F }, + { "Key: 3", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x20 }, + { "Key: 4", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x21 }, + { "Key: 5", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x22 }, + { "Key: 6", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x23 }, + { "Key: 7", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x24 }, + { "Key: 8", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x25 }, + { "Key: 9", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x26 }, + { "Key: 0", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x27 }, + { "Key: Enter", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x28 }, + { "Key: Escape", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x29 }, + { "Key: Backspace", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2A }, + { "Key: Tab", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2B }, + { "Key: Space", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2C }, + { "Key: -", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2D }, + { "Key: =", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2E }, + { "Key: [", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x2F }, + { "Key: ]", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x30 }, + { "Key: \\ (ANSI)", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x31 },//ANSI only + { "Key: #", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x32 },//ISO only + { "Key: ;", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x33 }, + { "Key: '", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x34 }, + { "Key: `", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x35 }, + { "Key: ,", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x36 }, + { "Key: .", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x37 }, + { "Key: /", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x38 }, + { "Key: Caps Lock", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x39 }, + { "Key: F1", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3A }, + { "Key: F2", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3B }, + { "Key: F3", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3C }, + { "Key: F4", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3D }, + { "Key: F5", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3E }, + { "Key: F6", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x3F }, + { "Key: F7", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x40 }, + { "Key: F8", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x41 }, + { "Key: F9", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x42 }, + { "Key: F10", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x43 }, + { "Key: F11", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x44 }, + { "Key: F12", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x45 }, + { "Key: Print Screen", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x46 }, + { "Key: Scroll Lock", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x47 }, + { "Key: Pause/Break", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x48 }, + { "Key: Insert", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x49 }, + { "Key: Home", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4A }, + { "Key: Page Up", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4B }, + { "Key: Delete", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4C }, + { "Key: End", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4D }, + { "Key: Page Down", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4E }, + { "Key: Right Arrow", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x4F }, + { "Key: Left Arrow", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x50 }, + { "Key: Down Arrow", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x51 }, + { "Key: Up Arrow", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x52 }, + { "Key: Num Lock", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x53 }, + { "Key: Number Pad /", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x54 }, + { "Key: Number Pad *", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x55 }, + { "Key: Number Pad -", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x56 }, + { "Key: Number Pad +", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x57 }, + { "Key: Number Pad Enter", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x58 }, + { "Key: Number Pad 1", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x59 }, + { "Key: Number Pad 2", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5A }, + { "Key: Number Pad 3", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5B }, + { "Key: Number Pad 4", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5C }, + { "Key: Number Pad 5", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5D }, + { "Key: Number Pad 6", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5E }, + { "Key: Number Pad 7", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x5F }, + { "Key: Number Pad 8", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x60 }, + { "Key: Number Pad 9", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x61 }, + { "Key: Number Pad 0", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x62 }, + { "Key: Number Pad .", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x63 }, + { "Key: \\ (ISO)", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x64 },//ISO only + { "Key: Menu", LOGITECH_G915_ZONE_DIRECT_KEYBOARD, 0x65 }, + { "Key: Left Control", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE0 }, + { "Key: Left Shift", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE1 }, + { "Key: Left Alt", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE2 }, + { "Key: Left Windows", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE3 }, + { "Key: Right Control", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE4 }, + { "Key: Right Shift", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE5 }, + { "Key: Right Alt", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE6 }, + { "Key: Right Windows", LOGITECH_G915_ZONE_MODE_MODIFIERS, 0xE7 }, + { "Key: Media Previous", LOGITECH_G915_ZONE_DIRECT_MEDIA, 0x9E }, + { "Key: Media Play/Pause", LOGITECH_G915_ZONE_DIRECT_MEDIA, 0x9B }, + { "Key: Media Next", LOGITECH_G915_ZONE_DIRECT_MEDIA, 0x9D }, + { "Key: Media Mute", LOGITECH_G915_ZONE_DIRECT_MEDIA, 0x9C }, + { "Logo", LOGITECH_G915_ZONE_DIRECT_LOGO, 0x01 }, + { "Lighting", LOGITECH_G915_ZONE_DIRECT_INDICATORS, 0x99 }, + { "Key: G1", LOGITECH_G915_ZONE_MODE_GKEYS, 0x01 }, + { "Key: G2", LOGITECH_G915_ZONE_MODE_GKEYS, 0x02 }, + { "Key: G3", LOGITECH_G915_ZONE_MODE_GKEYS, 0x03 }, + { "Key: G4", LOGITECH_G915_ZONE_MODE_GKEYS, 0x04 }, + { "Key: G5", LOGITECH_G915_ZONE_MODE_GKEYS, 0x05 }, +}; + +RGBController_LogitechG915::RGBController_LogitechG915(LogitechG915Controller* logitech_ptr) +{ + logitech = logitech_ptr; + + name = "Logitech G915 Keyboard Device"; + vendor = "Logitech"; + type = DEVICE_TYPE_KEYBOARD; + description = "Logitech G915 Keyboard Device"; + serial = logitech->GetSerialString(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = LOGITECH_G915_MODE_DIRECT; + 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_G915_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_G915_MODE_OFF; + Off.flags = 0; + Off.color_mode = MODE_COLORS_NONE; + modes.push_back(Off); + + mode Cycle; + Cycle.name = "Cycle"; + Cycle.value = LOGITECH_G915_MODE_CYCLE; + Cycle.flags = MODE_FLAG_HAS_SPEED; + Cycle.color_mode = MODE_COLORS_NONE; + Cycle.speed_min = LOGITECH_G915_SPEED_SLOWEST; + Cycle.speed_max = LOGITECH_G915_SPEED_FASTEST; + Cycle.speed = LOGITECH_G915_SPEED_NORMAL; + modes.push_back(Cycle); + + mode Breathing; + Breathing.name = "Breathing"; + Breathing.value = LOGITECH_G915_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_G915_SPEED_SLOWEST; + Breathing.speed_max = LOGITECH_G915_SPEED_FASTEST; + Breathing.speed = LOGITECH_G915_SPEED_NORMAL; + modes.push_back(Breathing); + + SetupZones(); + std::copy(colors.begin(), colors.end(),std::back_inserter(current_colors)); +} + +RGBController_LogitechG915::~RGBController_LogitechG915() +{ + /*---------------------------------------------------------*\ + | 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; + } + } +} + +void RGBController_LogitechG915::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 = 27; + 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_LogitechG915::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_LogitechG915::DeviceUpdateLEDs() +{ + std::map> ledsByColors; + std::vector new_colors; + unsigned char zone = 0; + unsigned char idx = 0; + unsigned char frame_buffer_big_mode[data_size]; + unsigned char frame_buffer_little_mode[data_size]; + RGBColor colorkey; + + /*---------------------------------------------------------*\ + | Freeze colors array because prepare framebuffers | + | may take some time. | + \*---------------------------------------------------------*/ + std::copy(colors.begin(), colors.end(),std::back_inserter(new_colors)); + + /*---------------------------------------------------------*\ + | Get unique colors to create mode 1F and 6F frame_buffers | + \*---------------------------------------------------------*/ + for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++) + { + zone = ( leds[led_idx].value >> 8 ); + idx = ( leds[led_idx].value ); + + if (current_colors[led_idx]==new_colors[led_idx]) + { + /*-------------------------------------------------*\ + | Don't send if key color is not changed | + \*-------------------------------------------------*/ + continue; + } + + switch (zone) + { + case LOGITECH_G915_ZONE_MODE_GKEYS: + idx = ((idx & 0x00ff) + 0xb3); + break; + + case LOGITECH_G915_ZONE_MODE_MODIFIERS: + idx = ((idx & 0x00ff) - 0x78); + break; + + case LOGITECH_G915_ZONE_DIRECT_KEYBOARD: + idx = ((idx & 0x00ff) - 0x03); + break; + + case LOGITECH_G915_ZONE_DIRECT_LOGO: + idx = ((idx & 0x00ff) + 0xd1); + break; + + default: + idx = (idx & 0x00ff); + break; + } + + colorkey = new_colors[led_idx]; + + if (ledsByColors.count(colorkey) == 0) + { + ledsByColors.insert(std::pair>(colorkey, {})); + } + + ledsByColors[colorkey].push_back(idx); + } + + uint8_t led_in_little_frame = 0; + uint8_t bi = 0; + size_t frame_pos = 3; + uint8_t li = 0; + + /*---------------------------------------------------------*\ + | Create frame_buffers of type 1F (Little, up to 4 leds | + | per packet) and 6F (big, up to 13 leds per packet). | + \*---------------------------------------------------------*/ + for(std::pair>& x: ledsByColors) + { + /*-----------------------------------------------------*\ + | For colors with more than 4 keys. Better to use big | + | (6F) packets to save USB transfers. | + \*-----------------------------------------------------*/ + if(x.second.size() > 4) + { + bi = 0; + + while(bi < x.second.size()) + { + frame_buffer_big_mode[0] = RGBGetRValue(x.first); + frame_buffer_big_mode[1] = RGBGetGValue(x.first); + frame_buffer_big_mode[2] = RGBGetBValue(x.first); + frame_pos = 3; + + for(uint8_t i = 0; i < max_key_per_color; i++) + { + if(bi + i < x.second.size()) + { + frame_buffer_big_mode[frame_pos] = x.second[bi+i]; + frame_pos++; + } + } + + if (frame_pos < data_size) + { + /*-----------------------------------------*\ + | Zeroing just what is needed and if needed | + \*-----------------------------------------*/ + memset(frame_buffer_big_mode + frame_pos, 0x00, sizeof(frame_buffer_big_mode) - frame_pos); + + /*-----------------------------------------*\ + | End of Data byte | + \*-----------------------------------------*/ + frame_buffer_big_mode[frame_pos] = 0xFF; + } + + /*-----------------------------------------------------*\ + | Zeroing just what is needed | + \*-----------------------------------------------------*/ + logitech->SetDirect(LOGITECH_G915_ZONE_FRAME_TYPE_BIG, frame_buffer_big_mode); + bi = bi + max_key_per_color; + } + } + /*-----------------------------------------------------*\ + | For colors with up to 4 keys. Use 1F packet to send | + | up to 4 colors-keys combinations per packet. | + \*-----------------------------------------------------*/ + else + { + li = 0; + + while(li < x.second.size()) + { + frame_buffer_little_mode[led_in_little_frame*4 + 0] = x.second[li]; + frame_buffer_little_mode[led_in_little_frame*4 + 1] = RGBGetRValue(x.first); + frame_buffer_little_mode[led_in_little_frame*4 + 2] = RGBGetGValue(x.first); + frame_buffer_little_mode[led_in_little_frame*4 + 3] = RGBGetBValue(x.first); + li++; + led_in_little_frame++; + + if (led_in_little_frame == 4) + { + /*-----------------------------------------*\ + | No End of Data byte if the packet is full | + \*-----------------------------------------*/ + logitech->SetDirect(LOGITECH_G915_ZONE_FRAME_TYPE_LITTLE, frame_buffer_little_mode); + led_in_little_frame=0; + } + } + } + } + + /*---------------------------------------------------------*\ + | If there is a left 1F packet with less than 4 keys, send | + | it and add an End of Data byte. | + \*---------------------------------------------------------*/ + if(led_in_little_frame > 0) + { + /*-----------------------------------------------------*\ + | Zeroing just what is needed | + \*-----------------------------------------------------*/ + memset(frame_buffer_little_mode + (led_in_little_frame * 4 + 1), 0x00, sizeof(frame_buffer_little_mode) - led_in_little_frame * 4); + + /*-----------------------------------------------------*\ + | Data byte | + \*-----------------------------------------------------*/ + frame_buffer_little_mode[led_in_little_frame*4 + 0] = 0xFF; + + /*-----------------------------------------------------*\ + | Send little frame and clear little frame buffer | + \*-----------------------------------------------------*/ + logitech->SetDirect(LOGITECH_G915_ZONE_FRAME_TYPE_LITTLE, frame_buffer_little_mode); + } + if(ledsByColors.size() > 0) + { + /*-----------------------------------------------------*\ + | Copy the current color vector to avoid set keys that | + | has not being | + \*-----------------------------------------------------*/ + logitech->Commit(); + std::copy(new_colors.begin(), new_colors.end(),current_colors.begin()); + } +} + +void RGBController_LogitechG915::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_LogitechG915::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_LogitechG915::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_LogitechG915::DeviceUpdateMode() +{ + /*---------------------------------------------------------*\ + | Direct mode does not send a mode packet | + | Call UpdateLEDs to send direct packet | + \*---------------------------------------------------------*/ + if(modes[active_mode].value == LOGITECH_G915_MODE_DIRECT) + { + /*-----------------------------------------------------*\ + | Send real direct mode initialization. I used same | + | sequence as GHUB for screen capture. | + \*-----------------------------------------------------*/ + logitech->InitializeDirect(); + + /*-----------------------------------------------------*\ + | Set one key to get direct mode engaged. | + \*-----------------------------------------------------*/ + logitech->SendSingleLed(0x29,0,0,0); + logitech->Commit(); + 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); +} diff --git a/Controllers/LogitechController/RGBController_LogitechG915.h b/Controllers/LogitechController/RGBController_LogitechG915.h new file mode 100644 index 00000000..527f3fef --- /dev/null +++ b/Controllers/LogitechController/RGBController_LogitechG915.h @@ -0,0 +1,34 @@ +/*-----------------------------------------*\ +| RGBController_LogitechG915.h | +| | +| Generic RGB Interface for Logitech G915 | +| RGB Mechanical Gaming Keyboard | +| | +| Cheerpipe 3/20/2021 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "LogitechG915Controller.h" + +class RGBController_LogitechG915 : public RGBController +{ +public: + RGBController_LogitechG915(LogitechG915Controller* logitech_ptr); + ~RGBController_LogitechG915(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + LogitechG915Controller* logitech; + std::vector current_colors; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index e7781233..f88a34bc 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -333,6 +333,7 @@ HEADERS += Controllers/LogitechController/LogitechG810Controller.h \ Controllers/LogitechController/LogitechG910Controller.h \ Controllers/LogitechController/LogitechG815Controller.h \ + Controllers/LogitechController/LogitechG915Controller.h \ Controllers/LogitechController/LogitechGLightsyncController.h \ Controllers/LogitechController/LogitechLightspeedController.h \ Controllers/LogitechController/LogitechX56Controller.h \ @@ -343,6 +344,7 @@ HEADERS += Controllers/LogitechController/RGBController_LogitechG810.h \ Controllers/LogitechController/RGBController_LogitechG910.h \ Controllers/LogitechController/RGBController_LogitechG815.h \ + Controllers/LogitechController/RGBController_LogitechG915.h \ Controllers/LogitechController/RGBController_LogitechGLightsync.h \ Controllers/LogitechController/RGBController_LogitechGLightsync1zone.h \ Controllers/LogitechController/RGBController_LogitechGPowerPlay.h \ @@ -707,6 +709,7 @@ SOURCES += Controllers/LogitechController/LogitechG810Controller.cpp \ Controllers/LogitechController/LogitechG910Controller.cpp \ Controllers/LogitechController/LogitechG815Controller.cpp \ + Controllers/LogitechController/LogitechG915Controller.cpp \ Controllers/LogitechController/LogitechGLightsyncController.cpp \ Controllers/LogitechController/LogitechLightspeedController.cpp \ Controllers/LogitechController/LogitechX56Controller.cpp \ @@ -717,6 +720,7 @@ SOURCES += Controllers/LogitechController/RGBController_LogitechG810.cpp \ Controllers/LogitechController/RGBController_LogitechG910.cpp \ Controllers/LogitechController/RGBController_LogitechG815.cpp \ + Controllers/LogitechController/RGBController_LogitechG915.cpp \ Controllers/LogitechController/RGBController_LogitechGLightsync.cpp \ Controllers/LogitechController/RGBController_LogitechGLightsync1zone.cpp \ Controllers/LogitechController/RGBController_LogitechGPowerPlay.cpp \