From 13e8f704388ab915aea0007960751a8eae34ef69 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 6 Aug 2025 11:27:37 -0500 Subject: [PATCH] Store name in DarkProjectrKeyboardController to avoid setting it in detector --- .../DarkProjectControllerDetect.cpp | 4 ++-- .../DarkProjectKeyboardController.cpp | 23 +++++++------------ .../DarkProjectKeyboardController.h | 9 ++++---- .../RGBController_DarkProjectKeyboard.cpp | 4 ++-- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Controllers/DarkProject/DarkProjectControllerDetect.cpp b/Controllers/DarkProject/DarkProjectControllerDetect.cpp index fca2fd81d..ab4c6055b 100644 --- a/Controllers/DarkProject/DarkProjectControllerDetect.cpp +++ b/Controllers/DarkProject/DarkProjectControllerDetect.cpp @@ -28,9 +28,9 @@ void DetectDarkProjectKeyboardControllers(hid_device_info* info, const std::stri if(dev) { - DarkProjectKeyboardController* controller = new DarkProjectKeyboardController(dev, info->path); + DarkProjectKeyboardController* controller = new DarkProjectKeyboardController(dev, info->path, name); RGBController_DarkProjectKeyboard* rgb_controller = new RGBController_DarkProjectKeyboard(controller); - rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); } } diff --git a/Controllers/DarkProject/DarkProjectKeyboardController.cpp b/Controllers/DarkProject/DarkProjectKeyboardController.cpp index 131c9612f..1b963ccec 100644 --- a/Controllers/DarkProject/DarkProjectKeyboardController.cpp +++ b/Controllers/DarkProject/DarkProjectKeyboardController.cpp @@ -45,10 +45,11 @@ static uint8_t packet_map[88] = /* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */ }; -DarkProjectKeyboardController::DarkProjectKeyboardController(hid_device* dev_handle, const char* path) +DarkProjectKeyboardController::DarkProjectKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name) { dev = dev_handle; location = path; + name = dev_name; } DarkProjectKeyboardController::~DarkProjectKeyboardController() @@ -56,17 +57,14 @@ DarkProjectKeyboardController::~DarkProjectKeyboardController() hid_close(dev); } -std::string DarkProjectKeyboardController::GetDeviceName() +std::string DarkProjectKeyboardController::GetLocation() { - wchar_t name_string[128]; - int ret = hid_get_manufacturer_string(dev, name_string, 128); + return("HID: " + location); +} - if(ret != 0) - { - return(""); - } - - return(StringUtils::wstring_to_string(name_string)); +std::string DarkProjectKeyboardController::GetName() +{ + return(name); } std::string DarkProjectKeyboardController::GetSerial() @@ -82,11 +80,6 @@ std::string DarkProjectKeyboardController::GetSerial() return(StringUtils::wstring_to_string(serial_string)); } -std::string DarkProjectKeyboardController::GetLocation() -{ - return("HID: " + location); -} - void DarkProjectKeyboardController::SetLedsDirect(std::vector colors) { uint8_t RGbuffer[DARKPROJECTKEYBOARD_PACKET_SIZE] = { 0x08, 0x07, 0x00, 0x00, 0x00 }; diff --git a/Controllers/DarkProject/DarkProjectKeyboardController.h b/Controllers/DarkProject/DarkProjectKeyboardController.h index 3e9605e1b..05f7a76de 100644 --- a/Controllers/DarkProject/DarkProjectKeyboardController.h +++ b/Controllers/DarkProject/DarkProjectKeyboardController.h @@ -37,15 +37,16 @@ enum class DarkProjectKeyboardController { public: - DarkProjectKeyboardController(hid_device* dev_handle, const char* path); + DarkProjectKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name); ~DarkProjectKeyboardController(); - std::string GetDeviceName(); - std::string GetSerial(); std::string GetLocation(); + std::string GetName(); + std::string GetSerial(); void SetLedsDirect(std::vector colors); private: - std::string location; hid_device* dev; + std::string location; + std::string name; }; diff --git a/Controllers/DarkProject/RGBController_DarkProjectKeyboard.cpp b/Controllers/DarkProject/RGBController_DarkProjectKeyboard.cpp index cbb757845..915434601 100644 --- a/Controllers/DarkProject/RGBController_DarkProjectKeyboard.cpp +++ b/Controllers/DarkProject/RGBController_DarkProjectKeyboard.cpp @@ -134,10 +134,10 @@ RGBController_DarkProjectKeyboard::RGBController_DarkProjectKeyboard(DarkProject { controller = controller_ptr; - name = "Dark Project Keyboard"; + name = controller->GetName(); vendor = "Dark Project"; type = DEVICE_TYPE_KEYBOARD; - description = controller->GetDeviceName(); + description = "Dark Project Keyboard Device"; serial = controller->GetSerial(); location = controller->GetLocation();