diff --git a/Controllers/LogitechController/LogitechControllerDetect.cpp b/Controllers/LogitechController/LogitechControllerDetect.cpp index 2a71d17c..a6fac38e 100644 --- a/Controllers/LogitechController/LogitechControllerDetect.cpp +++ b/Controllers/LogitechController/LogitechControllerDetect.cpp @@ -36,86 +36,86 @@ using namespace std::chrono_literals; /*-----------------------------------------------------*\ | Logitech vendor ID | \*-----------------------------------------------------*/ -#define LOGITECH_VID 0x046D -#define LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY 10 +#define LOGITECH_VID 0x046D +#define LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY 10 /*-----------------------------------------------------*\ | Keyboard product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_G213_PID 0xC336 -#define LOGITECH_G512_PID 0xC342 -#define LOGITECH_G512_RGB_PID 0xC33C -#define LOGITECH_G610_1_PID 0xC333 -#define LOGITECH_G610_2_PID 0xC338 -#define LOGITECH_G810_1_PID 0xC331 -#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 +#define LOGITECH_G213_PID 0xC336 +#define LOGITECH_G512_PID 0xC342 +#define LOGITECH_G512_RGB_PID 0xC33C +#define LOGITECH_G610_1_PID 0xC333 +#define LOGITECH_G610_2_PID 0xC338 +#define LOGITECH_G810_1_PID 0xC331 +#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 /*-----------------------------------------------------*\ | Mouse product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_G203_PID 0xC084 -#define LOGITECH_G203_LIGHTSYNC_PID 0xC092 -#define LOGITECH_G303_PID 0xC080 -#define LOGITECH_G403_PID 0xC083 -#define LOGITECH_G403_HERO_PID 0xC08F -#define LOGITECH_G403_LIGHTSPEED_PID 0xC082 -#define LOGITECH_G502_PROTEUS_SPECTRUM_PID 0xC332 -#define LOGITECH_G502_HERO_PID 0xC08B -#define LOGITECH_G502_LIGHTSPEED_PID 0xC08D -#define LOGITECH_G703_LIGHTSPEED_PID 0xC087 -#define LOGITECH_G900_LIGHTSPEED_PID 0xC081 -#define LOGITECH_G903_LIGHTSPEED_PID 0xC086 -#define LOGITECH_G_PRO_PID 0xC085 -#define LOGITECH_G_PRO_HERO_PID 0xC08C -#define LOGITECH_G_PRO_WIRELESS_PID 0xC088 +#define LOGITECH_G203_PID 0xC084 +#define LOGITECH_G203_LIGHTSYNC_PID 0xC092 +#define LOGITECH_G303_PID 0xC080 +#define LOGITECH_G403_PID 0xC083 +#define LOGITECH_G403_HERO_PID 0xC08F +#define LOGITECH_G403_LIGHTSPEED_PID 0xC082 +#define LOGITECH_G502_PROTEUS_SPECTRUM_PID 0xC332 +#define LOGITECH_G502_HERO_PID 0xC08B +#define LOGITECH_G502_LIGHTSPEED_PID 0xC08D +#define LOGITECH_G703_LIGHTSPEED_PID 0xC087 +#define LOGITECH_G900_LIGHTSPEED_PID 0xC081 +#define LOGITECH_G903_LIGHTSPEED_PID 0xC086 +#define LOGITECH_G_PRO_PID 0xC085 +#define LOGITECH_G_PRO_HERO_PID 0xC08C +#define LOGITECH_G_PRO_WIRELESS_PID 0xC088 /*-----------------------------------------------------*\ | Mousemat product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_G_LIGHTSPEED_POWERPLAY_PID 0xC53A +#define LOGITECH_G_LIGHTSPEED_POWERPLAY_PID 0xC53A /*-----------------------------------------------------*\ | Speaker product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_G560_PID 0x0A78 +#define LOGITECH_G560_PID 0x0A78 /*-----------------------------------------------------*\ | Headset product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_G933_PID 0x0A5B -#define LOGITECH_G733_PID 0x0AB5 +#define LOGITECH_G933_PID 0x0A5B +#define LOGITECH_G733_PID 0x0AB5 /*-----------------------------------------------------*\ | Unifying Device IDs (Including Lightspeed receivers) | | NB: Not used but preserved for debugging | \*-----------------------------------------------------*/ -#define LOGITECH_G_UNIFYING_RECEIVER_1_PID 0xC52B -#define LOGITECH_G_NANO_RECEIVER_PID 0xC52F -#define LOGITECH_G_G700_RECEIVER_PID 0xC531 -#define LOGITECH_G_UNIFYING_RECEIVER_2_PID 0xC532 -#define LOGITECH_G_G602_RECEIVER_PID 0xC537 +#define LOGITECH_G_UNIFYING_RECEIVER_1_PID 0xC52B +#define LOGITECH_G_NANO_RECEIVER_PID 0xC52F +#define LOGITECH_G_G700_RECEIVER_PID 0xC531 +#define LOGITECH_G_UNIFYING_RECEIVER_2_PID 0xC532 +#define LOGITECH_G_G602_RECEIVER_PID 0xC537 -#define LOGITECH_G_LIGHTSPEED_RECEIVER_PID 0xC539 -#define LOGITECH_G403_LIGHTSPEED_VIRTUAL_PID 0x405D -#define LOGITECH_G502_LIGHTSPEED_VIRTUAL_PID 0x407F -#define LOGITECH_G703_LIGHTSPEED_VIRTUAL_PID 0x4070 -#define LOGITECH_G900_LIGHTSPEED_VIRTUAL_PID 0x4053 -#define LOGITECH_G903_LIGHTSPEED_VIRTUAL_PID 0x4067 -#define LOGITECH_G_PRO_WIRELESS_VIRTUAL_PID 0x4079 -#define LOGITECH_POWERPLAY_MAT_VIRTUAL_PID 0x405F +#define LOGITECH_G_LIGHTSPEED_RECEIVER_PID 0xC539 +#define LOGITECH_G403_LIGHTSPEED_VIRTUAL_PID 0x405D +#define LOGITECH_G502_LIGHTSPEED_VIRTUAL_PID 0x407F +#define LOGITECH_G703_LIGHTSPEED_VIRTUAL_PID 0x4070 +#define LOGITECH_G900_LIGHTSPEED_VIRTUAL_PID 0x4053 +#define LOGITECH_G903_LIGHTSPEED_VIRTUAL_PID 0x4067 +#define LOGITECH_G_PRO_WIRELESS_VIRTUAL_PID 0x4079 +#define LOGITECH_POWERPLAY_MAT_VIRTUAL_PID 0x405F /*-----------------------------------------------------*\ | Joystick product IDs | \*-----------------------------------------------------*/ -#define LOGITECH_X56_VID 0x0738 -#define LOGITECH_X56_JOYSTICK_PID 0x2221 -#define LOGITECH_X56_THROTTLE_PID 0xA221 +#define LOGITECH_X56_VID 0x0738 +#define LOGITECH_X56_JOYSTICK_PID 0x2221 +#define LOGITECH_X56_THROTTLE_PID 0xA221 /*-----------------------------------------------------*\ | Logitech Keyboards | @@ -494,11 +494,6 @@ void DetectLogitechMouseG403(hid_device_info* info, const std::string& name) addLogitechLightsyncMouse2zone(info, name, 0xFF, 0x0E, 0x3A); } -void DetectLogitechMouseG502PS(hid_device_info* info, const std::string& name) -{ - addLogitechLightsyncMouse2zone(info, name, 0xFF, 0x02, 0x3A); -} - void DetectLogitechMouseGPRO(hid_device_info* info, const std::string& name) { addLogitechLightsyncMouse1zone(info, name, 0xFF, 0x0E, 0x3C); @@ -555,46 +550,108 @@ void DetectLogitechX56(hid_device_info* info, const std::string& name) } } -/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Keyboards | -\*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IPU("Logitech G213", DetectLogitechKeyboardG213, LOGITECH_VID, LOGITECH_G213_PID, 1, 0xFF43, 0x0602); -REGISTER_HID_DETECTOR_IP ("Logitech G512", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G512_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G512 RGB", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G512_RGB_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G610 Orion", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G610_1_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G610 Orion", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G610_2_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G810 Orion Spectrum", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G810_1_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G810 Orion Spectrum", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G810_2_PID, 1, 0xFF43); -REGISTER_HID_DETECTOR_IP ("Logitech G813 RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardG815, LOGITECH_VID, LOGITECH_G813_PID, 1, 0xFF43); -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); +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Keyboards | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IPU("Logitech G213", DetectLogitechKeyboardG213, LOGITECH_VID, LOGITECH_G213_PID, 1, 0xFF43, 0x0602); +REGISTER_HID_DETECTOR_IP ("Logitech G512", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G512_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G512 RGB", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G512_RGB_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G610 Orion", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G610_1_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G610 Orion", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G610_2_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G810 Orion Spectrum", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G810_1_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G810 Orion Spectrum", DetectLogitechKeyboardG810, LOGITECH_VID, LOGITECH_G810_2_PID, 1, 0xFF43); +REGISTER_HID_DETECTOR_IP ("Logitech G813 RGB Mechanical Gaming Keyboard", DetectLogitechKeyboardG815, LOGITECH_VID, LOGITECH_G813_PID, 1, 0xFF43); +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_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); -/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Mice | -\*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP ("Logitech G203 Prodigy", DetectLogitechMouseG203, LOGITECH_VID, LOGITECH_G203_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IPU("Logitech G203 Lightsync", DetectLogitechMouseG203L, LOGITECH_VID, LOGITECH_G203_LIGHTSYNC_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IP ("Logitech G303 Daedalus Apex", DetectLogitechMouseG303, LOGITECH_VID, LOGITECH_G303_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IP ("Logitech G403 Hero", DetectLogitechMouseG403, LOGITECH_VID, LOGITECH_G403_HERO_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IP ("Logitech G502 Proteus Spectrum Gaming Mouse", DetectLogitechMouseG502PS, LOGITECH_VID, LOGITECH_G502_PROTEUS_SPECTRUM_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IP ("Logitech G502 Hero Gaming Mouse", DetectLogitechMouseG502PS, LOGITECH_VID, LOGITECH_G502_HERO_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IP ("Logitech G Pro Gaming Mouse", DetectLogitechMouseGPRO, LOGITECH_VID, LOGITECH_G_PRO_PID, 1, 0xFF00); -REGISTER_HID_DETECTOR_IP ("Logitech G Pro (HERO) Gaming Mouse", DetectLogitechMouseGPRO, LOGITECH_VID, LOGITECH_G_PRO_HERO_PID, 1, 0xFF00); -/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Speakers | -\*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IPU("Logitech G560 Lightsync Speaker", DetectLogitechG560, LOGITECH_VID, LOGITECH_G560_PID, 2, 0xFF43, 514); -/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Headsets | -\*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IPU("Logitech G933 Lightsync Headset", DetectLogitechG933, LOGITECH_VID, LOGITECH_G933_PID, 3, 0xFF43, 514); -/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Joysticks | -\*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP("Logitech X56 Rhino Hotas Joystick", DetectLogitechX56, LOGITECH_X56_VID, LOGITECH_X56_JOYSTICK_PID, 2, 0xFF00); -REGISTER_HID_DETECTOR_IP("Logitech X56 Rhino Hotas Throttle", DetectLogitechX56, LOGITECH_X56_VID, LOGITECH_X56_THROTTLE_PID, 2, 0xFF00); +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Mice | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IP ("Logitech G203 Prodigy", DetectLogitechMouseG203, LOGITECH_VID, LOGITECH_G203_PID, 1, 0xFF00); +REGISTER_HID_DETECTOR_IPU("Logitech G203 Lightsync", DetectLogitechMouseG203L, LOGITECH_VID, LOGITECH_G203_LIGHTSYNC_PID, 1, 0xFF00, 2); +REGISTER_HID_DETECTOR_IP ("Logitech G303 Daedalus Apex", DetectLogitechMouseG303, LOGITECH_VID, LOGITECH_G303_PID, 1, 0xFF00); +REGISTER_HID_DETECTOR_IP ("Logitech G403 Hero", DetectLogitechMouseG403, LOGITECH_VID, LOGITECH_G403_HERO_PID, 1, 0xFF00); +REGISTER_HID_DETECTOR_IP ("Logitech G Pro Gaming Mouse", DetectLogitechMouseGPRO, LOGITECH_VID, LOGITECH_G_PRO_PID, 1, 0xFF00); +REGISTER_HID_DETECTOR_IP ("Logitech G Pro (HERO) Gaming Mouse", DetectLogitechMouseGPRO, LOGITECH_VID, LOGITECH_G_PRO_HERO_PID, 1, 0xFF00); +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Speakers | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IPU("Logitech G560 Lightsync Speaker", DetectLogitechG560, LOGITECH_VID, LOGITECH_G560_PID, 2, 0xFF43, 514); +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Headsets | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IPU("Logitech G933 Lightsync Headset", DetectLogitechG933, LOGITECH_VID, LOGITECH_G933_PID, 3, 0xFF43, 514); +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Joysticks | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IP("Logitech X56 Rhino Hotas Joystick", DetectLogitechX56, LOGITECH_X56_VID, LOGITECH_X56_JOYSTICK_PID, 2, 0xFF00); +REGISTER_HID_DETECTOR_IP("Logitech X56 Rhino Hotas Throttle", DetectLogitechX56, LOGITECH_X56_VID, LOGITECH_X56_THROTTLE_PID, 2, 0xFF00); + + + + + +/*---------------------------------------------------------------------------------------------------------*\ +| Common Lightspeed Detection | +| | +\*---------------------------------------------------------------------------------------------------------*/ + +void CreateLogitechLightspeedDevice(char *path, usages device_usages, uint8_t device_index, uint16_t pid, bool wireless, std::shared_ptr mutex_ptr) +{ + LogitechLightspeedController* controller = new LogitechLightspeedController(device_usages.find(2)->second, path); + bool lightspeedDeviceIsValid = false; + int retryCount = 0; + + while (!lightspeedDeviceIsValid && retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) + { + std::this_thread::sleep_for(50ms); + controller->lightspeed = new logitech_device(path, device_usages, device_index, wireless, mutex_ptr); + lightspeedDeviceIsValid = controller->lightspeed->is_valid(); + retryCount++; + } + + if (retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) + { + RGBController_LogitechLightspeed* rgb_controller = new RGBController_LogitechLightspeed(controller); + rgb_controller->pid = pid; + ResourceManager::get()->RegisterRGBController(rgb_controller); + LOG_DEBUG("Added controller in %i retries", retryCount); + } + else + { + delete controller; + LOG_DEBUG("Failed to set up device - exceeded retries"); + } +} + +void DetectLogitechWired(hid_device_info* info, const std::string& /*name*/) +{ + /*-----------------------------------------------------------------*\ + | Wired lightspeed devices don't use the FAP short message | + | Be sure to specify a Page AND Usage when using this detector | + | i.e. REGISTER_HID_DETECTOR_IPU | + \*-----------------------------------------------------------------*/ + //char *path = info->path; + usages device_usages; + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + LOG_DEBUG("Adding Usage %i for device @ path %s", info->usage, info->path); + device_usages.emplace((uint8_t)info->usage, dev); + } + else + { + LOG_DEBUG("Error opening Usage %i for device @ path %s", info->usage, info->path); + } + + if(device_usages.size() > 0) + { + CreateLogitechLightspeedDevice(info->path, device_usages, LOGITECH_DEFAULT_DEVICE_INDEX, info->product_id, false, nullptr); + } +} /*---------------------------------------------------------------------------------------------------------*\ | Windows and MacOS Lightspeed Detection | @@ -646,33 +703,6 @@ usages BundleLogitechUsages(hid_device_info* info) return temp_usages; } -void CreateLogitechLightspeedDevice(char *path, usages device_usages, uint8_t device_index, bool wireless, std::shared_ptr mutex_ptr) -{ - LogitechLightspeedController* controller = new LogitechLightspeedController(device_usages.find(2)->second, path); - bool lightspeedDeviceIsValid = false; - int retryCount = 0; - - while (!lightspeedDeviceIsValid && retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) - { - std::this_thread::sleep_for(50ms); - controller->lightspeed = new logitech_device(path, device_usages, device_index, wireless, mutex_ptr); - lightspeedDeviceIsValid = controller->lightspeed->is_valid(); - retryCount++; - } - - if (retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) - { - RGBController_LogitechLightspeed* rgb_controller = new RGBController_LogitechLightspeed(controller); - ResourceManager::get()->RegisterRGBController(rgb_controller); - LOG_DEBUG("Added controller in %i retries", retryCount); - } - else - { - delete controller; - LOG_DEBUG("Failed to set up device - exceeded retries"); - } -} - void DetectLogitechLightspeedReceiver(hid_device_info* info, const std::string& /*name*/) { /*-----------------------------------------------------------------*\ @@ -700,17 +730,32 @@ void DetectLogitechLightspeedReceiver(hid_device_info* info, const std::string& for(wireless_map::iterator wd = wireless_devices.begin(); wd != wireless_devices.end(); wd++) { - CreateLogitechLightspeedDevice(path, device_usages, wd->second, true, logitech_mutex); + CreateLogitechLightspeedDevice(path, device_usages, wd->second, dev_pid, true, logitech_mutex); } } } -void DetectLogitechWired(hid_device_info* info, const std::string& /*name*/) +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Lightspeed Receivers (Windows Wireless) | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IP("Logitech Lightspeed Receiver", DetectLogitechLightspeedReceiver, LOGITECH_VID, LOGITECH_G_LIGHTSPEED_RECEIVER_PID, 2, 0xFF00); +REGISTER_HID_DETECTOR_IP("Logitech G Powerplay Mousepad", DetectLogitechLightspeedReceiver, LOGITECH_VID, LOGITECH_G_LIGHTSPEED_POWERPLAY_PID, 2, 0xFF00); + +#endif + +/*---------------------------------------------------------------------------------------------------------*\ +| Linux Lightspeed Detection | +| | +| The Linux kernel handles detecting wireless devices connected to a Unifying Receiver. | +\*---------------------------------------------------------------------------------------------------------*/ +#ifdef __linux__ + +void DetectLogitechWireless(hid_device_info* info, const std::string& /*name*/) { /*-----------------------------------------------------------------*\ - | Wired lightspeed devices don't use the FAP short message | - | Be sure to specify a Page AND Usage when using this detector | - | i.e. REGISTER_HID_DETECTOR_IPU | + | Wireless lightspeed devices on Linux are handled by the Kernel | + | and as such can largely be treated as Wired with the caveat | + | that they may not be connected | \*-----------------------------------------------------------------*/ //char *path = info->path; usages device_usages; @@ -728,85 +773,16 @@ void DetectLogitechWired(hid_device_info* info, const std::string& /*name*/) if(device_usages.size() > 0) { - CreateLogitechLightspeedDevice(info->path, device_usages, 0xFF, false, nullptr); + /*-------------------------------------------------*\ + | Create mutex to prevent the controllers sharing a | + | receiver from interfering with each other | + \*-------------------------------------------------*/ + std::shared_ptr logitech_mutex = std::make_shared(); + + CreateLogitechLightspeedDevice(info->path, device_usages, LOGITECH_DEFAULT_DEVICE_INDEX, info->product_id, true, logitech_mutex); } } -/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Lightspeed Receivers (Windows Wireless) | -\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP("Logitech Lightspeed Receiver", DetectLogitechLightspeedReceiver, LOGITECH_VID, LOGITECH_G_LIGHTSPEED_RECEIVER_PID, 2, 0xFF00); -REGISTER_HID_DETECTOR_IP("Logitech G Powerplay Mousepad", DetectLogitechLightspeedReceiver, LOGITECH_VID, LOGITECH_G_LIGHTSPEED_POWERPLAY_PID, 2, 0xFF00); - -/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Lightspeed Wireless Devices (Windows Wired) | -\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IPU("Logitech G403 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G403_LIGHTSPEED_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G502 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G502_LIGHTSPEED_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G703 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G703_LIGHTSPEED_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G900 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G900_LIGHTSPEED_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G903 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G903_LIGHTSPEED_PID, 1, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G Pro Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G_PRO_WIRELESS_PID, 2, 0xFF00, 2); -REGISTER_HID_DETECTOR_IPU("Logitech G733 Gaming Headset", DetectLogitechWired, LOGITECH_VID, LOGITECH_G733_PID, 2, 0xFF43, 514); - -#endif - -/*---------------------------------------------------------------------------------------------------------*\ -| Linux Lightspeed Detection | -| | -| The Linux kernel handles detecting wireless devices connected to a Unifying Receiver. | -\*---------------------------------------------------------------------------------------------------------*/ -#ifdef __linux__ - -void CreateLogitechLightspeedDevice(hid_device_info* info, bool wireless) -{ - usages device_usages; - - hid_device* dev = hid_open_path(info->path); - - if(dev) - { - device_usages.emplace((uint8_t)info->usage, dev); - } - - if(device_usages.size() > 0) - { - LogitechLightspeedController* controller = new LogitechLightspeedController(device_usages.find(0)->second, info->path); - bool lightspeedDeviceIsValid = false; - int retryCount = 0; - - while (!lightspeedDeviceIsValid && retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) - { - std::this_thread::sleep_for(50ms); - controller->lightspeed = new logitech_device(info->path, device_usages, 0xFF, wireless); - lightspeedDeviceIsValid = controller->lightspeed->is_valid(); - retryCount++; - } - - if (retryCount < LOGITECH_LIGHTSPEED_DETECT_MAX_RETRY) - { - RGBController_LogitechLightspeed* rgb_controller = new RGBController_LogitechLightspeed(controller); - ResourceManager::get()->RegisterRGBController(rgb_controller); - LOG_DEBUG("Added controller in %i retries", retryCount); - } - else - { - delete controller; - LOG_DEBUG("Failed to set up device - exceeded retries"); - } - } -} - -void DetectLogitechWireless(hid_device_info* info, const std::string& /*name*/) -{ - CreateLogitechLightspeedDevice(info, true); -} - -void DetectLogitechWired(hid_device_info* info, const std::string& /*name*/) -{ - CreateLogitechLightspeedDevice(info, false); -} - /*-------------------------------------------------------------------------------------------------------------------------------------------------*\ | Lightspeed Devices (Linux Wireless) | \*-------------------------------------------------------------------------------------------------------------------------------------------------*/ @@ -818,9 +794,14 @@ REGISTER_HID_DETECTOR_IPU("Logitech G903 Wireless Gaming Mouse", REGISTER_HID_DETECTOR_IPU("Logitech G Pro Wireless Gaming Mouse", DetectLogitechWireless, LOGITECH_VID, LOGITECH_G_PRO_WIRELESS_VIRTUAL_PID, 2, 0xFF00, 2); REGISTER_HID_DETECTOR_IPU("Logitech Powerplay Mat", DetectLogitechWireless, LOGITECH_VID, LOGITECH_POWERPLAY_MAT_VIRTUAL_PID, 2, 0xFF00, 2); +#endif + /*-------------------------------------------------------------------------------------------------------------------------------------------------*\ -| Lightspeed Wireless Devices (Linux Wired) | +| Lightspeed Wireless Devices (Common Wired) | \*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IPU("Logitech G502 Proteus Spectrum Gaming Mouse", DetectLogitechWired, LOGITECH_VID, LOGITECH_G502_PROTEUS_SPECTRUM_PID, 1, 0xFF00, 2); +REGISTER_HID_DETECTOR_IPU("Logitech G502 Hero Gaming Mouse", DetectLogitechWired, LOGITECH_VID, LOGITECH_G502_HERO_PID, 1, 0xFF00, 2); + REGISTER_HID_DETECTOR_IPU("Logitech G403 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G403_LIGHTSPEED_PID, 1, 0xFF00, 2); REGISTER_HID_DETECTOR_IPU("Logitech G502 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G502_LIGHTSPEED_PID, 1, 0xFF00, 2); REGISTER_HID_DETECTOR_IPU("Logitech G703 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G703_LIGHTSPEED_PID, 1, 0xFF00, 2); @@ -828,5 +809,3 @@ REGISTER_HID_DETECTOR_IPU("Logitech G900 Wireless Gaming Mouse (wired)", REGISTER_HID_DETECTOR_IPU("Logitech G903 Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G903_LIGHTSPEED_PID, 1, 0xFF00, 2); REGISTER_HID_DETECTOR_IPU("Logitech G Pro Wireless Gaming Mouse (wired)", DetectLogitechWired, LOGITECH_VID, LOGITECH_G_PRO_WIRELESS_PID, 2, 0xFF00, 2); REGISTER_HID_DETECTOR_IPU("Logitech G733 Gaming Headset", DetectLogitechWired, LOGITECH_VID, LOGITECH_G733_PID, 2, 0xFF43, 514); - -#endif diff --git a/Controllers/LogitechController/LogitechLightspeedController.cpp b/Controllers/LogitechController/LogitechLightspeedController.cpp index a8acb55e..7b0d94ab 100644 --- a/Controllers/LogitechController/LogitechLightspeedController.cpp +++ b/Controllers/LogitechController/LogitechLightspeedController.cpp @@ -37,10 +37,10 @@ std::string LogitechLightspeedController::GetSerialString() else { wchar_t serial_string[128]; - int ret = hid_get_serial_number_string(dev, serial_string, 128); - LOG_DEBUG("[%s] hid_get_serial_number_string Returned status - %i : %s", lightspeed->device_name.c_str(), ret, ((ret == 0) ? "SUCCESS" : "FAILED")); + //int ret = hid_get_serial_number_string(dev, serial_string, 128); + //LOG_DEBUG("[%s] hid_get_serial_number_string Returned status - %i : %s", lightspeed->device_name.c_str(), ret, ((ret == 0) ? "SUCCESS" : "FAILED")); - if(ret != 0) + //if(ret != 0) { return(""); } @@ -55,13 +55,14 @@ std::string LogitechLightspeedController::GetSerialString() void LogitechLightspeedController::SendMouseMode ( unsigned char mode, - std::uint16_t speed, + uint16_t speed, unsigned char zone, unsigned char red, unsigned char green, - unsigned char blue - // unsigned char brightness + unsigned char blue, + unsigned char brightness, + bool bright_cycle_swap ) { - lightspeed->setMode(mode, speed, zone, red, green, blue, 0x64); + lightspeed->setMode(mode, speed, zone, red, green, blue, brightness, bright_cycle_swap); } diff --git a/Controllers/LogitechController/LogitechLightspeedController.h b/Controllers/LogitechController/LogitechLightspeedController.h index ac4dd39d..0fbf33fa 100644 --- a/Controllers/LogitechController/LogitechLightspeedController.h +++ b/Controllers/LogitechController/LogitechLightspeedController.h @@ -16,6 +16,8 @@ #include #pragma once +#define LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MIN 0x01 +#define LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX 0x64 enum { @@ -50,12 +52,13 @@ public: void SendMouseMode ( unsigned char mode, - unsigned short speed, + uint16_t speed, unsigned char zone, unsigned char red, unsigned char green, - unsigned char blue -// unsigned char brightness + unsigned char blue, + unsigned char brightness, + bool bright_cycle_swap ); private: diff --git a/Controllers/LogitechController/LogitechProtocolCommon.cpp b/Controllers/LogitechController/LogitechProtocolCommon.cpp index 8615499c..511220e7 100644 --- a/Controllers/LogitechController/LogitechProtocolCommon.cpp +++ b/Controllers/LogitechController/LogitechProtocolCommon.cpp @@ -11,8 +11,8 @@ static std::vector logitech_RGB_pages = { - 0x8070, - 0x8071 + LOGITECH_HIDPP_PAGE_RGB_EFFECTS1, + LOGITECH_HIDPP_PAGE_RGB_EFFECTS2 }; int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless_devices) @@ -39,7 +39,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless response.init(); shortFAPrequest get_connected_devices; - get_connected_devices.init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST); + get_connected_devices.init(LOGITECH_RECEIVER_DEVICE_INDEX, LOGITECH_GET_REGISTER_REQUEST); result = hid_write(dev_use1, get_connected_devices.buffer, get_connected_devices.size()); result = hid_read_timeout(dev_use1, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); @@ -48,7 +48,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless if (!wireless_notifications) { response.init(); //zero out the response - get_connected_devices.init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST); + get_connected_devices.init(LOGITECH_RECEIVER_DEVICE_INDEX, LOGITECH_SET_REGISTER_REQUEST); get_connected_devices.data[1] = 1; result = hid_write(dev_use1, get_connected_devices.buffer, get_connected_devices.size()); result = hid_read_timeout(dev_use1, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); @@ -60,7 +60,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless } response.init(); //zero out the response - get_connected_devices.init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST); + get_connected_devices.init(LOGITECH_RECEIVER_DEVICE_INDEX, LOGITECH_GET_REGISTER_REQUEST); get_connected_devices.feature_command = 0x02; //0x02 Connection State register. Essentially asking for count of paired devices result = hid_write(dev_use1, get_connected_devices.buffer, get_connected_devices.size()); result = hid_read_timeout(dev_use1, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); @@ -74,7 +74,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless device_count++; //Add 1 to the device_count to include the receiver response.init(); - get_connected_devices.init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST); + get_connected_devices.init(LOGITECH_RECEIVER_DEVICE_INDEX, LOGITECH_SET_REGISTER_REQUEST); get_connected_devices.feature_index = LOGITECH_SET_REGISTER_REQUEST; get_connected_devices.feature_command = 0x02; //0x02 Connection State register get_connected_devices.data[0] = 0x02; //Writting 0x02 to the connection state register will ask the receiver to fake a reconnect of paired devices @@ -93,7 +93,7 @@ int getWirelessDevice(usages device_usages, uint16_t pid, wireless_map *wireless | We need to read the receiver from the HID device queue but | | there is no need to add it as it's own device | \*-----------------------------------------------------------------*/ - if(devices.device_index != 0xFF) + if(devices.device_index != LOGITECH_RECEIVER_DEVICE_INDEX) { wireless_devices->emplace(wireless_PID, devices.device_index); } @@ -147,12 +147,20 @@ void logitech_device::initialiseDevice() if(is_connected) { - getDeviceName(); //This will get the name of the device if it exists + getDeviceName(); + + /*-----------------------------------------------------------------*\ + | If this is running with DEBUG or higher loglevel then | + | dump the entire Feature list to log | + \*-----------------------------------------------------------------*/ if(LogManager::get()->getLoglevel() > 4) { getDeviceFeatureList(); //This will populate the feature list } + /*-----------------------------------------------------------------*\ + | Check device for known RGB Effects Feature pages & save the index | + \*-----------------------------------------------------------------*/ for(std::vector::iterator page = logitech_RGB_pages.begin(); page != logitech_RGB_pages.end(); page++) { int feature_index = getFeatureIndex(*page); @@ -163,17 +171,13 @@ void logitech_device::initialiseDevice() } } + /*-----------------------------------------------------------------*\ + | If there was no RGB Effect Feature page found | + | dump the entire Feature list to log | + \*-----------------------------------------------------------------*/ if (RGB_feature_index == 0) { - /*-----------------------------------------------------------------*\ - | If there was no RGB Effect Feature page found | - | dump the entire Feature list to log | - \*-----------------------------------------------------------------*/ LOG_INFO("[%s] Unable add this device due to missing RGB Effects Feature", device_name.c_str()); - /*for(features::iterator feature = feature_list.begin(); feature != feature_list.end(); feature++) - { - LOG_INFO("Feature Index: %02X\tFeature Page: %04X", feature->second, feature->first); - }*/ } else { @@ -332,13 +336,12 @@ int logitech_device::getDeviceFeatureList() int result = 0; /*-----------------------------------------------------------------*\ - | Check the usage map for usage1 (0x10 Short FAP Message) & usage2 | - | (0x11 Long FAP Message) then list all features for device | + | Check the usage map for usage2 (0x11 Long FAP Message) | + | then list all features for device | \*-----------------------------------------------------------------*/ - //hid_device* dev_use1 = getDevice(1); hid_device* dev_use2 = getDevice(2); - if(/*dev_use1 &&*/ dev_use2) + if(dev_use2) { /*-----------------------------------------------------------------*\ | Create a buffer for reads | @@ -355,26 +358,18 @@ int logitech_device::getDeviceFeatureList() /*-----------------------------------------------------------------*\ | Get the count of Features | \*-----------------------------------------------------------------*/ - //shortFAPrequest get_count; longFAPrequest get_count; - //get_count.init(device_index, feature_index); - //get_count.feature_command = LOGITECH_CMD_FEATURE_SET_GET_COUNT; get_count.init(device_index, feature_index, LOGITECH_CMD_FEATURE_SET_GET_COUNT); - //result = hid_write(dev_use1, get_count.buffer, get_count.size()); result = hid_write(dev_use2, get_count.buffer, get_count.size()); result = hid_read_timeout(dev_use2, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); unsigned int feature_count = response.data[0]; - //shortFAPrequest get_features; longFAPrequest get_features; - //get_features.init(device_index, feature_index); - //get_features.feature_command = LOGITECH_CMD_FEATURE_SET_GET_ID; get_features.init(device_index, feature_index, LOGITECH_CMD_FEATURE_SET_GET_ID); for(std::size_t i = 1; feature_list.size() < feature_count; i++ ) { get_features.data[0] = i; - //result = hid_write(dev_use1, get_features.buffer, get_features.size()); result = hid_write(dev_use2, get_features.buffer, get_features.size()); result = hid_read_timeout(dev_use2, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); LOG_DEBUG("[%s] Feature %04X @ index: %02X", device_name.c_str(), (response.data[0] << 8) | response.data[1], i); @@ -383,14 +378,7 @@ int logitech_device::getDeviceFeatureList() } else { - /*if(!dev_use1) - { - LOG_INFO("[%s] Unable get the feature index list - missing Short Message (0x10) usage", device_name.c_str()); - }*/ - if(!dev_use2) - { - LOG_INFO("[%s] Unable get the feature index list - missing FAP Long Message (0x11) usage", device_name.c_str()); - } + LOG_INFO("[%s] Unable get the feature index list - missing FAP Long Message (0x11) usage", device_name.c_str()); } return feature_list.size(); @@ -418,28 +406,6 @@ int logitech_device::getDeviceName() \*-----------------------------------------------------------------*/ int feature_index = getFeatureIndex(LOGITECH_HIDPP_PAGE_DEVICE_NAME_TYPE); - /*-----------------------------------------------------------------*\ - | Check if the feature_list contains an index for the Device_name | - | feature otherwise query the root index. If not found return 0 | - \*-----------------------------------------------------------------*/ - /*uint8_t name_feature_index; - features::iterator find_feature = feature_list.find(LOGITECH_HIDPP_PAGE_DEVICE_NAME_TYPE); - if (find_feature == feature_list.end()) - { - longFAPrequest get_index; - get_index.init(device_index, LOGITECH_HIDPP_PAGE_ROOT_IDX, LOGITECH_CMD_ROOT_GET_FEATURE); - get_index.data[0] = LOGITECH_HIDPP_PAGE_DEVICE_NAME_TYPE >> 8; //Get feature index of the Feature Set 0x0001 - get_index.data[1] = LOGITECH_HIDPP_PAGE_DEVICE_NAME_TYPE & 0xFF; - - result = hid_write(dev_use2, get_index.buffer, get_index.size()); - result = hid_read_timeout(dev_use2, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); - name_feature_index = response.data[0]; - } - else - { - name_feature_index = find_feature->second; - }*/ - /*-----------------------------------------------------------------*\ | Get the device name length | \*-----------------------------------------------------------------*/ @@ -563,14 +529,12 @@ uint8_t logitech_device::setDirectMode(bool direct) int result = 0; /*-----------------------------------------------------------------*\ - | Check the usage map for usage1 (0x10 Short FAP Message) & usage2 | - | (0x11 Long FAP Message) then set the device into direct mode | - | via register 0x8A | + | Check the usage map for usage2 (0x11 Long FAP Message) | + | then set the device into direct mode via register 0x80 | \*-----------------------------------------------------------------*/ - //hid_device* dev_use1 = getDevice(1); hid_device* dev_use2 = getDevice(2); - if(/*dev_use1 &&*/ dev_use2) + if(dev_use2) { /*-----------------------------------------------------------------*\ | Create a buffer for reads | @@ -581,10 +545,7 @@ uint8_t logitech_device::setDirectMode(bool direct) /*-----------------------------------------------------------------*\ | Turn the direct mode on or off via the RGB_feature_index | \*-----------------------------------------------------------------*/ - //shortFAPrequest set_direct; longFAPrequest set_direct; - //set_direct.init(device_index, RGB_feature_index); - //set_direct.feature_command = LOGITECH_CMD_RGB_EFFECTS_UNKNOWN; set_direct.init(device_index, RGB_feature_index, LOGITECH_CMD_RGB_EFFECTS_UNKNOWN); set_direct.data[0] = (direct) ? 1 : 0; set_direct.data[1] = set_direct.data[0]; @@ -600,13 +561,11 @@ uint8_t logitech_device::setDirectMode(bool direct) { std::lock_guard guard(*mutex); - //result = hid_write(dev_use1, set_direct.buffer, set_direct.size()); result = hid_write(dev_use2, set_direct.buffer, set_direct.size()); result = hid_read_timeout(dev_use2, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); } else { - //result = hid_write(dev_use1, set_direct.buffer, set_direct.size()); result = hid_write(dev_use2, set_direct.buffer, set_direct.size()); result = hid_read_timeout(dev_use2, response.buffer, response.size(), LOGITECH_PROTOCOL_TIMEOUT); } @@ -614,7 +573,7 @@ uint8_t logitech_device::setDirectMode(bool direct) return result; } -uint8_t logitech_device::setMode(uint8_t mode, uint16_t speed, uint8_t zone, uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) +uint8_t logitech_device::setMode(uint8_t mode, uint16_t speed, uint8_t zone, uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness, bool bright_cycle_swap) { int result = 0; @@ -651,12 +610,20 @@ uint8_t logitech_device::setMode(uint8_t mode, uint16_t speed, uint8_t zone, uin } else if(mode == 2) //Spectrum Cycle { + if(bright_cycle_swap) + { + set_mode.data[1] = 3; + } set_mode.data[7] = speed >> 8; set_mode.data[8] = speed & 0xFF; set_mode.data[9] = brightness; } else if(mode == 3) //Breathing { + if(bright_cycle_swap) + { + set_mode.data[1] = 2; + } set_mode.data[5] = speed >> 8; set_mode.data[6] = speed & 0xFF; set_mode.data[8] = brightness; diff --git a/Controllers/LogitechController/LogitechProtocolCommon.h b/Controllers/LogitechController/LogitechProtocolCommon.h index 992ed575..405b6f4f 100644 --- a/Controllers/LogitechController/LogitechProtocolCommon.h +++ b/Controllers/LogitechController/LogitechProtocolCommon.h @@ -14,21 +14,22 @@ #pragma once -#define LOGITECH_PROTOCOL_TIMEOUT 300 //Timeout in ms -#define LOGITECH_HEADER_SIZE 3 -#define LOGITECH_SHORT_MESSAGE 0x10 -#define LOGITECH_SHORT_MESSAGE_LEN 7 -#define LOGITECH_LONG_MESSAGE 0x11 -#define LOGITECH_LONG_MESSAGE_LEN 20 -#define LOGITECH_FAP_RESPONSE_LEN 64 //Define a universal response buffer and allow the hidapi to determine the size +#define LOGITECH_PROTOCOL_TIMEOUT 300 //Timeout in ms +#define LOGITECH_HEADER_SIZE 3 +#define LOGITECH_SHORT_MESSAGE 0x10 +#define LOGITECH_SHORT_MESSAGE_LEN 7 +#define LOGITECH_LONG_MESSAGE 0x11 +#define LOGITECH_LONG_MESSAGE_LEN 20 +#define LOGITECH_FAP_RESPONSE_LEN 64 //Define a universal response buffer and allow the hidapi to determine the size -#define LOGITECH_RECEIVER_ADDRESS 0xFF //The Unifying receiver uses RAP or register access protocol -#define LOGITECH_SET_REGISTER_REQUEST 0x80 -#define LOGITECH_GET_REGISTER_REQUEST 0x81 +#define LOGITECH_DEFAULT_DEVICE_INDEX 0xFF +#define LOGITECH_RECEIVER_DEVICE_INDEX 0xFF //The Unifying receiver uses RAP or register access protocol +#define LOGITECH_SET_REGISTER_REQUEST 0x80 +#define LOGITECH_GET_REGISTER_REQUEST 0x81 -#define LOGITECH_HIDPP_PAGE_ROOT_IDX 0x00 //Used for querying the feature index -#define LOGITECH_CMD_ROOT_GET_FEATURE 0x01 -#define LOGITECH_CMD_ROOT_GET_PROTOCOL 0x11 +#define LOGITECH_HIDPP_PAGE_ROOT_IDX 0x00 //Used for querying the feature index +#define LOGITECH_CMD_ROOT_GET_FEATURE 0x01 +#define LOGITECH_CMD_ROOT_GET_PROTOCOL 0x11 #define LOGITECH_HIDPP_PAGE_FEATURE_SET 0x0001 #define LOGITECH_CMD_FEATURE_SET_GET_COUNT 0x01 @@ -216,7 +217,7 @@ public: uint8_t getFeatureIndex(uint16_t feature_page); uint8_t getLEDinfo(); uint8_t setDirectMode(bool direct); - uint8_t setMode(uint8_t mode, uint16_t speed, uint8_t zone, uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness); + uint8_t setMode(uint8_t mode, uint16_t speed, uint8_t zone, uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness, bool bright_cycle_swap); int getDeviceName(); private: std::vector leds; diff --git a/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp b/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp index c21a1dad..224c145b 100644 --- a/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp +++ b/Controllers/LogitechController/RGBController_LogitechLightspeed.cpp @@ -62,8 +62,11 @@ RGBController_LogitechLightspeed::RGBController_LogitechLightspeed(LogitechLight mode Static; Static.name = "Static"; Static.value = LOGITECH_G_PRO_WIRELESS_MODE_STATIC; - Static.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS; Static.color_mode = MODE_COLORS_PER_LED; + Static.brightness_min = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MIN; + Static.brightness_max = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; + Static.brightness = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; modes.push_back(Static); mode Cycle; @@ -71,6 +74,9 @@ RGBController_LogitechLightspeed::RGBController_LogitechLightspeed(LogitechLight Cycle.value = LOGITECH_G_PRO_WIRELESS_MODE_CYCLE; Cycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; Cycle.color_mode = MODE_COLORS_NONE; + Cycle.brightness_min = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MIN; + Cycle.brightness_max = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; + Cycle.brightness = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; Cycle.speed_min = LOGITECH_G_PRO_WIRELESS_SPEED_SLOWEST; Cycle.speed_max = LOGITECH_G_PRO_WIRELESS_SPEED_FASTEST; Cycle.speed = LOGITECH_G_PRO_WIRELESS_SPEED_NORMAL; @@ -81,6 +87,9 @@ RGBController_LogitechLightspeed::RGBController_LogitechLightspeed(LogitechLight Breathing.value = LOGITECH_G_PRO_WIRELESS_MODE_BREATHING; Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; Breathing.color_mode = MODE_COLORS_PER_LED; + Breathing.brightness_min = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MIN; + Breathing.brightness_max = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; + Breathing.brightness = LOGITECH_G_PRO_WIRELESS_BRIGHTNESS_MAX; Breathing.speed_min = LOGITECH_G_PRO_WIRELESS_SPEED_SLOWEST; Breathing.speed_max = LOGITECH_G_PRO_WIRELESS_SPEED_FASTEST; Breathing.speed = LOGITECH_G_PRO_WIRELESS_SPEED_NORMAL; @@ -148,16 +157,21 @@ void RGBController_LogitechLightspeed::DeviceUpdateLEDs() void RGBController_LogitechLightspeed::UpdateZoneLEDs(int zone) { - unsigned char red = RGBGetRValue(colors[zone]); - unsigned char grn = RGBGetGValue(colors[zone]); - unsigned char blu = RGBGetBValue(colors[zone]); + unsigned char red = RGBGetRValue(colors[zone]); + unsigned char grn = RGBGetGValue(colors[zone]); + unsigned char blu = RGBGetBValue(colors[zone]); + + /*---------------------------------------------------------*\ + | Workaround for G502 mode breathing / spectrum cycle swap | + \*---------------------------------------------------------*/ + bool bright_cycle_swap = (pid == 0xC08B || pid == 0xC332); /*---------------------------------------------------------*\ | Replace direct mode with static when sending to controller| \*---------------------------------------------------------*/ unsigned char temp_mode = (modes[active_mode].value == 0xFF) ? LOGITECH_G_PRO_WIRELESS_MODE_STATIC : modes[active_mode].value; - logitech->SendMouseMode(temp_mode, modes[active_mode].speed, zone, red, grn, blu); + logitech->SendMouseMode(temp_mode, modes[active_mode].speed, zone, red, grn, blu, modes[active_mode].brightness, bright_cycle_swap); } void RGBController_LogitechLightspeed::UpdateSingleLED(int led) diff --git a/Controllers/LogitechController/RGBController_LogitechLightspeed.h b/Controllers/LogitechController/RGBController_LogitechLightspeed.h index 0edec179..9e4830d1 100644 --- a/Controllers/LogitechController/RGBController_LogitechLightspeed.h +++ b/Controllers/LogitechController/RGBController_LogitechLightspeed.h @@ -28,6 +28,7 @@ public: void SetCustomMode(); void DeviceUpdateMode(); + uint16_t pid; //This is a workaround fix for G502 mode breathing / spectrum cycle swap private: LogitechLightspeedController* logitech; };