From a1f144daf223ecce74cc65ad658661f8d5092bc0 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Mon, 11 Aug 2025 18:29:59 -0500 Subject: [PATCH] Store name in KeychronKeyboardController to avoid setting it in detector --- .../KeychronKeyboardController.cpp | 14 +++++++------- .../KeychronKeyboardController.h | 7 ++++--- .../KeychronKeyboardControllerDetect.cpp | 4 ++-- .../RGBController_KeychronKeyboard.cpp | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp b/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp index c6ed6969..b0f55298 100644 --- a/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp +++ b/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp @@ -15,11 +15,11 @@ using namespace std::chrono_literals; -KeychronKeyboardController::KeychronKeyboardController(hid_device* dev_handle, const hid_device_info& info) +KeychronKeyboardController::KeychronKeyboardController(hid_device* dev_handle, const hid_device_info& info, std::string dev_name) { dev = dev_handle; - version = ""; location = info.path; + name = dev_name; } KeychronKeyboardController::~KeychronKeyboardController() @@ -32,6 +32,11 @@ std::string KeychronKeyboardController::GetDeviceLocation() return("HID: " + location); } +std::string KeychronKeyboardController::GetNameString() +{ + return(name); +} + std::string KeychronKeyboardController::GetSerialString() { wchar_t serial_string[128]; @@ -45,11 +50,6 @@ std::string KeychronKeyboardController::GetSerialString() return(StringUtils::wstring_to_string(serial_string)); } -std::string KeychronKeyboardController::GetFirmwareVersion() -{ - return(version); -} - void KeychronKeyboardController:: SetLedSequencePositions(std::vector positions) { led_sequence_positions = positions; diff --git a/Controllers/KeychronKeyboardController/KeychronKeyboardController.h b/Controllers/KeychronKeyboardController/KeychronKeyboardController.h index e4a7929d..32802221 100644 --- a/Controllers/KeychronKeyboardController/KeychronKeyboardController.h +++ b/Controllers/KeychronKeyboardController/KeychronKeyboardController.h @@ -91,12 +91,12 @@ enum class KeychronKeyboardController { public: - KeychronKeyboardController(hid_device* dev_handle, const hid_device_info& info); + KeychronKeyboardController(hid_device* dev_handle, const hid_device_info& info, std::string dev_name); ~KeychronKeyboardController(); - std::string GetSerialString(); std::string GetDeviceLocation(); - std::string GetFirmwareVersion(); + std::string GetNameString(); + std::string GetSerialString(); void SetLedSequencePositions(std::vector positions); void SetMode(std::vector modes, int active_mode, std::vector colors); @@ -106,6 +106,7 @@ protected: private: std::string location; + std::string name; std::string version; std::vector led_sequence_positions; diff --git a/Controllers/KeychronKeyboardController/KeychronKeyboardControllerDetect.cpp b/Controllers/KeychronKeyboardController/KeychronKeyboardControllerDetect.cpp index e1b554cc..75b0abc4 100644 --- a/Controllers/KeychronKeyboardController/KeychronKeyboardControllerDetect.cpp +++ b/Controllers/KeychronKeyboardController/KeychronKeyboardControllerDetect.cpp @@ -29,9 +29,9 @@ void DetectKeychronKeyboardControllers(hid_device_info* info, const std::string& if(dev) { - KeychronKeyboardController* controller = new KeychronKeyboardController(dev, *info); + KeychronKeyboardController* controller = new KeychronKeyboardController(dev, *info, name); RGBController_KeychronKeyboard* rgb_controller = new RGBController_KeychronKeyboard(controller); - rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); } } diff --git a/Controllers/KeychronKeyboardController/RGBController_KeychronKeyboard.cpp b/Controllers/KeychronKeyboardController/RGBController_KeychronKeyboard.cpp index 221ffe2e..d914a165 100644 --- a/Controllers/KeychronKeyboardController/RGBController_KeychronKeyboard.cpp +++ b/Controllers/KeychronKeyboardController/RGBController_KeychronKeyboard.cpp @@ -430,13 +430,13 @@ typedef struct RGBController_KeychronKeyboard::RGBController_KeychronKeyboard(KeychronKeyboardController* controller_ptr) { controller = controller_ptr; - name = "Keychron Keyboard"; + + name = controller->GetNameString(); vendor = "Keychron"; type = DEVICE_TYPE_KEYBOARD; description = name; location = controller->GetDeviceLocation(); serial = controller->GetSerialString(); - version = controller->GetFirmwareVersion(); mode Custom; Custom.name = "Custom";