From 91dd39f3f394d55de38263f48f193c11384a0180 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 8 May 2021 13:40:19 -0500 Subject: [PATCH] Start implementing Corsair Wireless (K57) controller. Detects both keyboard and dongle, no other functionality implemented yet --- .../CorsairWirelessController.cpp | 75 ++++++++++++++++ .../CorsairWirelessController.h | 40 +++++++++ .../CorsairWirelessControllerDetect.cpp | 50 +++++++++++ .../RGBController_CorsairWireless.cpp | 85 +++++++++++++++++++ .../RGBController_CorsairWireless.h | 36 ++++++++ OpenRGB.pro | 6 ++ 6 files changed, 292 insertions(+) create mode 100644 Controllers/CorsairWirelessController/CorsairWirelessController.cpp create mode 100644 Controllers/CorsairWirelessController/CorsairWirelessController.h create mode 100644 Controllers/CorsairWirelessController/CorsairWirelessControllerDetect.cpp create mode 100644 Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp create mode 100644 Controllers/CorsairWirelessController/RGBController_CorsairWireless.h diff --git a/Controllers/CorsairWirelessController/CorsairWirelessController.cpp b/Controllers/CorsairWirelessController/CorsairWirelessController.cpp new file mode 100644 index 00000000..ed54558e --- /dev/null +++ b/Controllers/CorsairWirelessController/CorsairWirelessController.cpp @@ -0,0 +1,75 @@ +/*-----------------------------------------*\ +| CorsairWirelessController.cpp | +| | +| Driver for Corsair RGB wireless keyboard | +| lighting controller | +| | +| Adam Honse (CalcProgrammer1) 5/8/2021 | +\*-----------------------------------------*/ + +#include "CorsairWirelessController.h" + +#include + +using namespace std::chrono_literals; + +CorsairWirelessController::CorsairWirelessController(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; + + type = DEVICE_TYPE_KEYBOARD; +} + +CorsairWirelessController::~CorsairWirelessController() +{ + hid_close(dev); +} + +device_type CorsairWirelessController::GetDeviceType() +{ + return type; +} + +std::string CorsairWirelessController::GetDeviceLocation() +{ + return("HID: " + location); +} + +std::string CorsairWirelessController::GetFirmwareString() +{ + return firmware_version; +} + +std::string CorsairWirelessController::GetName() +{ + return name; +} + +std::string CorsairWirelessController::GetSerialString() +{ + wchar_t serial_string[128]; + hid_get_serial_number_string(dev, serial_string, 128); + + std::wstring return_wstring = serial_string; + std::string return_string(return_wstring.begin(), return_wstring.end()); + + return(return_string); +} + +void CorsairWirelessController::SetLEDs(std::vectorcolors) +{ +} + +void CorsairWirelessController::SetLEDsKeyboardFull(std::vector colors) +{ +} + +void CorsairWirelessController::SetName(std::string device_name) +{ + name = device_name; +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ diff --git a/Controllers/CorsairWirelessController/CorsairWirelessController.h b/Controllers/CorsairWirelessController/CorsairWirelessController.h new file mode 100644 index 00000000..03485161 --- /dev/null +++ b/Controllers/CorsairWirelessController/CorsairWirelessController.h @@ -0,0 +1,40 @@ +/*-----------------------------------------*\ +| CorsairWirelessController.h | +| | +| Definitions and types for Corsair RGB | +| wireless keyboard lighting controller | +| | +| Adam Honse (CalcProgrammer1) 5/8/2021 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +class CorsairWirelessController +{ +public: + CorsairWirelessController(hid_device* dev_handle, const char* path); + ~CorsairWirelessController(); + + device_type GetDeviceType(); + std::string GetDeviceLocation(); + std::string GetFirmwareString(); + std::string GetName(); + std::string GetSerialString(); + + void SetLEDs(std::vector colors); + void SetLEDsKeyboardFull(std::vector colors); + void SetName(std::string device_name); + +private: + hid_device* dev; + + std::string firmware_version; + std::string location; + std::string name; + device_type type; +}; diff --git a/Controllers/CorsairWirelessController/CorsairWirelessControllerDetect.cpp b/Controllers/CorsairWirelessController/CorsairWirelessControllerDetect.cpp new file mode 100644 index 00000000..7c54c246 --- /dev/null +++ b/Controllers/CorsairWirelessController/CorsairWirelessControllerDetect.cpp @@ -0,0 +1,50 @@ +#include "Detector.h" +#include "CorsairWirelessController.h" +#include "RGBController.h" +#include "RGBController_CorsairWireless.h" +#include + +/*-----------------------------------------------------*\ +| Corsair vendor ID | +\*-----------------------------------------------------*/ +#define CORSAIR_VID 0x1B1C + +/*-----------------------------------------------------*\ +| Keyboard product IDs | +\*-----------------------------------------------------*/ +#define CORSAIR_K57_RGB_WIRED_PID 0x1B6E +#define CORSAIR_K57_RGB_WIRELESS_PID 0x1B62 + +/******************************************************************************************\ +* * +* DetectCorsairWirelessControllers * +* * +* Tests the USB address to see if a Corsair RGB Keyboard controller exists there. * +* * +\******************************************************************************************/ + +void DetectCorsairWirelessControllers(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + if( dev ) + { + CorsairWirelessController* controller = new CorsairWirelessController(dev, info->path); + controller->SetName(name); + + if(controller->GetDeviceType() != DEVICE_TYPE_UNKNOWN) + { + RGBController_CorsairWireless* rgb_controller = new RGBController_CorsairWireless(controller); + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + else + { + delete controller; + } + } +} /* DetectCorsairWirelessControllers() */ + +/*-----------------------------------------------------------------------------------------------------*\ +| Keyboards | +\*-----------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_IPU("Corsair K57 RGB (Wired)", DetectCorsairWirelessControllers, CORSAIR_VID, CORSAIR_K57_RGB_WIRED_PID, 1, 0xFF42, 1); +REGISTER_HID_DETECTOR_IPU("Corsair K57 RGB (Wireless)", DetectCorsairWirelessControllers, CORSAIR_VID, CORSAIR_K57_RGB_WIRELESS_PID, 1, 0xFF42, 1); diff --git a/Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp b/Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp new file mode 100644 index 00000000..56fe1584 --- /dev/null +++ b/Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp @@ -0,0 +1,85 @@ +/*-----------------------------------------*\ +| RGBController_CorsairWireless.cpp | +| | +| Generic RGB Interface for Corsair RGB | +| wireless keyboard devices | +| | +| Adam Honse (CalcProgrammer1) 5/8/2021 | +\*-----------------------------------------*/ + +#include "RGBController_CorsairWireless.h" + +RGBController_CorsairWireless::RGBController_CorsairWireless(CorsairWirelessController* corsair_ptr) +{ + corsair = corsair_ptr; + + name = corsair->GetName(); + vendor = "Corsair"; + description = "Corsair RGB Peripheral Device"; + type = corsair->GetDeviceType(); + version = corsair->GetFirmwareString(); + location = corsair->GetDeviceLocation(); + serial = corsair->GetSerialString(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = 0; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); + + SetupZones(); +} + +RGBController_CorsairWireless::~RGBController_CorsairWireless() +{ + /*---------------------------------------------------------*\ + | Delete the matrix map | + \*---------------------------------------------------------*/ + for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++) + { + if(zones[zone_index].matrix_map != NULL) + { + delete zones[zone_index].matrix_map; + } + } + + delete corsair; +} + +void RGBController_CorsairWireless::SetupZones() +{ + SetupColors(); +} + +void RGBController_CorsairWireless::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_CorsairWireless::DeviceUpdateLEDs() +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairWireless::UpdateZoneLEDs(int /*zone*/) +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairWireless::UpdateSingleLED(int /*led*/) +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairWireless::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_CorsairWireless::DeviceUpdateMode() +{ + +} diff --git a/Controllers/CorsairWirelessController/RGBController_CorsairWireless.h b/Controllers/CorsairWirelessController/RGBController_CorsairWireless.h new file mode 100644 index 00000000..15b73686 --- /dev/null +++ b/Controllers/CorsairWirelessController/RGBController_CorsairWireless.h @@ -0,0 +1,36 @@ +/*-----------------------------------------*\ +| RGBController_CorsairWireless.h | +| | +| Generic RGB Interface for Corsair RGB | +| wireless keyboard devices | +| | +| Adam Honse (CalcProgrammer1) 5/8/2021 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "CorsairWirelessController.h" + +class RGBController_CorsairWireless : public RGBController +{ +public: + RGBController_CorsairWireless(CorsairWirelessController* corsair_ptr); + ~RGBController_CorsairWireless(); + + int physical_layout; + int logical_layout; + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + CorsairWirelessController* corsair; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index e611bf2e..8a1bb042 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -73,6 +73,7 @@ INCLUDEPATH += Controllers/CorsairLightingNodeController/ \ Controllers/CorsairVengeanceController/ \ Controllers/CorsairVengeanceProController/ \ + Controllers/CorsairWirelessController/ \ Controllers/CreativeController/ \ Controllers/CrucialController/ \ Controllers/DasKeyboardController/ \ @@ -207,6 +208,8 @@ HEADERS += Controllers/CorsairVengeanceController/RGBController_CorsairVengeance.h \ Controllers/CorsairVengeanceProController/CorsairVengeanceProController.h \ Controllers/CorsairVengeanceProController/RGBController_CorsairVengeancePro.h \ + Controllers/CorsairWirelessController/CorsairWirelessController.h \ + Controllers/CorsairWirelessController/RGBController_CorsairWireless.h \ Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h \ Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h \ Controllers/CrucialController/CrucialController.h \ @@ -459,6 +462,9 @@ SOURCES += Controllers/CorsairVengeanceProController/CorsairVengeanceProController.cpp \ Controllers/CorsairVengeanceProController/CorsairVengeanceProControllerDetect.cpp \ Controllers/CorsairVengeanceProController/RGBController_CorsairVengeancePro.cpp \ + Controllers/CorsairWirelessController/CorsairWirelessController.cpp \ + Controllers/CorsairWirelessController/CorsairWirelessControllerDetect.cpp \ + Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp \ Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp \ Controllers/CreativeController/CreativeControllerDetect.cpp \ Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp \