From 8813c9936d86f87d92781c1cb5a033097981b8f0 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 8 Aug 2025 00:11:31 -0500 Subject: [PATCH] Store name in EVGAUSBControllers to avoid setting it in detectors --- .../EVGAKeyboardController.cpp | 26 ++++--------- .../EVGAKeyboardController.h | 6 +-- .../RGBController_EVGAKeyboard.cpp | 4 +- .../EVGAMouseController.cpp | 38 +++++++------------ .../EVGAMouseController/EVGAMouseController.h | 18 ++++----- .../RGBController_EVGAMouse.cpp | 6 +-- .../EVGAUSBControllerDetect.cpp | 14 +++---- 7 files changed, 44 insertions(+), 68 deletions(-) diff --git a/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.cpp b/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.cpp index ea207ba2..15ba5f3d 100644 --- a/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.cpp +++ b/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.cpp @@ -57,23 +57,13 @@ static uint8_t packet_map[EVGA_KEYBOARD_FULL_SIZE_KEYCOUNT + EVGA_KEYBOARD_Z20_E 82, 102 }; -EVGAKeyboardController::EVGAKeyboardController(hid_device* dev_handle, const char* path, uint16_t kb_pid) +EVGAKeyboardController::EVGAKeyboardController(hid_device* dev_handle, const char* path, uint16_t kb_pid, std::string dev_name) { dev = dev_handle; location = path; + name = dev_name; pid = kb_pid; - /*---------------------------------------------------------*\ - | Get device name from HID manufacturer and product strings | - \*---------------------------------------------------------*/ - wchar_t name_string[HID_MAX_STR]; - - hid_get_manufacturer_string(dev, name_string, HID_MAX_STR); - device_name = StringUtils::wstring_to_string(name_string); - - hid_get_product_string(dev, name_string, HID_MAX_STR); - device_name.append(" ").append(StringUtils::wstring_to_string(name_string)); - SetSleepTime(); } @@ -82,9 +72,9 @@ EVGAKeyboardController::~EVGAKeyboardController() hid_close(dev); } -std::string EVGAKeyboardController::GetDeviceName() +std::string EVGAKeyboardController::GetName() { - return(device_name); + return(name); } std::string EVGAKeyboardController::GetSerial() @@ -197,11 +187,11 @@ void EVGAKeyboardController::GetStatus(mode *mode) mode->speed = buffer[EVGA_KB_SPEED_LSB]; break; } - LOG_DEBUG("[%s] Mode %d Setup with %d colours @ %04X speed and %02X brightness", device_name.c_str(), mode->value, mode->colors.size(), mode->speed, mode->brightness); + LOG_DEBUG("[%s] Mode %d Setup with %d colours @ %04X speed and %02X brightness", name.c_str(), mode->value, mode->colors.size(), mode->speed, mode->brightness); } else { - LOG_INFO("[%s] An error occured reading data for mode %d", device_name.c_str(), mode->value); + LOG_INFO("[%s] An error occured reading data for mode %d", name.c_str(), mode->value); } } @@ -389,12 +379,12 @@ uint8_t EVGAKeyboardController::GetMode() if(result > 0) { - LOG_DEBUG("[%s] Returned mode %02X - %02X %02X %02X %02X %02X", device_name.c_str(), buffer[index], buffer[index-2], buffer[index-1], buffer[index], buffer[index+1], buffer[index+2]); + LOG_DEBUG("[%s] Returned mode %02X - %02X %02X %02X %02X %02X", name.c_str(), buffer[index], buffer[index-2], buffer[index-1], buffer[index], buffer[index+1], buffer[index+2]); return(buffer[index]); } else { - LOG_INFO("[%s] An error occured reading current mode", device_name.c_str()); + LOG_INFO("[%s] An error occured reading current mode", name.c_str()); return(0); } } diff --git a/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.h b/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.h index 57f36608..c26a0eb1 100644 --- a/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.h +++ b/Controllers/EVGAUSBController/EVGAKeyboardController/EVGAKeyboardController.h @@ -91,10 +91,10 @@ enum EVGA_Keyboard_Controller_Speed class EVGAKeyboardController { public: - EVGAKeyboardController(hid_device* dev_handle, const char* path, uint16_t kb_pid); + EVGAKeyboardController(hid_device* dev_handle, const char* path, uint16_t kb_pid, std::string dev_name); ~EVGAKeyboardController(); - std::string GetDeviceName(); + std::string GetName(); std::string GetSerial(); std::string GetLocation(); @@ -108,7 +108,7 @@ public: uint8_t GetMode(); uint16_t GetPid(); private: - std::string device_name; + std::string name; std::string location; hid_device* dev; uint16_t pid; diff --git a/Controllers/EVGAUSBController/EVGAKeyboardController/RGBController_EVGAKeyboard.cpp b/Controllers/EVGAUSBController/EVGAKeyboardController/RGBController_EVGAKeyboard.cpp index b174d172..3559334c 100644 --- a/Controllers/EVGAUSBController/EVGAKeyboardController/RGBController_EVGAKeyboard.cpp +++ b/Controllers/EVGAUSBController/EVGAKeyboardController/RGBController_EVGAKeyboard.cpp @@ -205,10 +205,10 @@ RGBController_EVGAKeyboard::RGBController_EVGAKeyboard(EVGAKeyboardController* c controller = controller_ptr; - name = "EVGA USB Keyboard"; + name = controller->GetName(); vendor = "EVGA"; type = DEVICE_TYPE_KEYBOARD; - description = controller->GetDeviceName(); + description = "EVGA Keyboard Device"; serial = controller->GetSerial(); location = controller->GetLocation(); diff --git a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp index c8cc777d..1d0315d0 100644 --- a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp +++ b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp @@ -46,23 +46,13 @@ static bool BuffersAreEqual(unsigned char *buffer1, unsigned char *buffer2, int return true; } -EVGAMouseController::EVGAMouseController(hid_device* dev_handle, char *_path, int connection_type) +EVGAMouseController::EVGAMouseController(hid_device* dev_handle, char * path, int connection_type, std::string dev_name) { dev = dev_handle; - location = _path; + location = path; + name = dev_name; this->connection_type = connection_type; - /*---------------------------------------------------------*\ - | Get device name from HID manufacturer and product strings | - \*---------------------------------------------------------*/ - wchar_t name_string[HID_MAX_STR]; - - hid_get_manufacturer_string(dev, name_string, HID_MAX_STR); - device_name = StringUtils::wstring_to_string(name_string); - - hid_get_product_string(dev, name_string, HID_MAX_STR); - device_name.append(" ").append(StringUtils::wstring_to_string(name_string)); - led_states.resize(EVGA_PERIPHERAL_LED_COUNT); for(EVGAMouseControllerDeviceState &led_state : led_states) { @@ -76,12 +66,12 @@ EVGAMouseController::EVGAMouseController(hid_device* dev_handle, char *_path, in EVGAMouseController::~EVGAMouseController() { - + hid_close(dev); } -std::string EVGAMouseController::GetDeviceName() +std::string EVGAMouseController::GetName() { - return device_name; + return(name); } std::string EVGAMouseController::GetSerial() @@ -134,14 +124,14 @@ void EVGAMouseController::SetMode(uint8_t mode, uint8_t index) if(err == -1) { const wchar_t* err_str = hid_error(dev); - LOG_DEBUG("[%s] Error writing buffer %s", device_name.c_str(), err_str); + LOG_DEBUG("[%s] Error writing buffer %s", name.c_str(), err_str); } led_states[index].mode = mode; err = hid_get_feature_report(dev, buffer, EVGA_PERIPHERAL_PACKET_SIZE); if(err == -1) { const wchar_t* err_str = hid_error(dev); - LOG_DEBUG("[%s] Error reading buffer %s", device_name.c_str(), err_str); + LOG_DEBUG("[%s] Error reading buffer %s", name.c_str(), err_str); } } @@ -225,7 +215,7 @@ void EVGAMouseController::SetLed(uint8_t index, uint8_t brightness, uint8_t spee if(err == -1) { const wchar_t* err_str = hid_error(dev); - LOG_DEBUG("[%s] Error writing buffer %s", device_name.c_str(), err_str); + LOG_DEBUG("[%s] Error writing buffer %s", name.c_str(), err_str); } led_states[index].brightness = brightness; led_states[index].speed = speed; @@ -257,7 +247,7 @@ void EVGAMouseController::RefreshDeviceState(int led) if(err == -1) { const wchar_t* err_str = hid_error(dev); - LOG_DEBUG("[%s] Error writing buffer %s", device_name.c_str(), err_str); + LOG_DEBUG("[%s] Error writing buffer %s", name.c_str(), err_str); } /*------------------------------------------------------------------------------*\ | Wait in wireless mode or else packets might be sent too quickly to take effect | @@ -268,7 +258,7 @@ void EVGAMouseController::RefreshDeviceState(int led) int color_count = buffer[EVGA_PERIPHERAL_COLOR_COUNT_BYTE]; if(color_count == 0) { - LOG_VERBOSE("[%s] No colors read from response. The device is likely asleep.", device_name.c_str()); + LOG_VERBOSE("[%s] No colors read from response. The device is likely asleep.", name.c_str()); return; } led_states[led].mode = buffer[EVGA_PERIPHERAL_MODE_BYTE]; @@ -291,17 +281,17 @@ bool EVGAMouseController::ReadPacketOrLogErrors(unsigned char *buffer, int max_a if(bytes_read == -1) { const wchar_t* err_str = hid_error(dev); - LOG_DEBUG("[%s] Error reading buffer %s", device_name.c_str(), err_str); + LOG_DEBUG("[%s] Error reading buffer %s", name.c_str(), err_str); return false; } else if(IsResponseNotReadyPacket(buffer)) { - LOG_VERBOSE("[%s] Retries exhausted reading from device. Write may have failed.", device_name.c_str()); + LOG_VERBOSE("[%s] Retries exhausted reading from device. Write may have failed.", name.c_str()); return false; } else if(IsAsleepPacket(buffer)) { - LOG_VERBOSE("[%s] Device is asleep. Cannot send or receive packets until the device is awoken.", device_name.c_str()); + LOG_VERBOSE("[%s] Device is asleep. Cannot send or receive packets until the device is awoken.", name.c_str()); return false; } return true; diff --git a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h index ce8e5554..2978ecfa 100644 --- a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h +++ b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h @@ -91,10 +91,10 @@ struct EVGAMouseControllerDeviceState class EVGAMouseController { public: - EVGAMouseController(hid_device* dev_handle, char *_path, int connection_type); + EVGAMouseController(hid_device* dev_handle, char * path, int connection_type, std::string dev_name); ~EVGAMouseController(); - std::string GetDeviceName(); + std::string GetName(); std::string GetSerial(); std::string GetLocation(); @@ -144,6 +144,12 @@ public: void SetAllLedsAndActivate(uint8_t brightness, uint8_t speed, const std::vector& colors); private: + hid_device* dev; + std::string location; + std::string name; + int connection_type; + + std::vector led_states; /*----------------------------------------------------------------------------------------------------------------*\ | Sets the led to the given colors with the given brightness and speed. if activate is true, activates the current | @@ -196,13 +202,5 @@ private: | read from the device should be retried at a later time. | \*------------------------------------------------------------------------------*/ bool IsResponseNotReadyPacket(unsigned char *buffer); - - std::string device_name; - std::string location; - hid_device* dev; - - int connection_type; - - std::vector led_states; }; diff --git a/Controllers/EVGAUSBController/EVGAMouseController/RGBController_EVGAMouse.cpp b/Controllers/EVGAUSBController/EVGAMouseController/RGBController_EVGAMouse.cpp index b05e66b7..0e4344ad 100644 --- a/Controllers/EVGAUSBController/EVGAMouseController/RGBController_EVGAMouse.cpp +++ b/Controllers/EVGAUSBController/EVGAMouseController/RGBController_EVGAMouse.cpp @@ -27,10 +27,10 @@ RGBController_EVGAMouse::RGBController_EVGAMouse(EVGAMouseController* controller { controller = controller_ptr; - name = controller->GetDeviceName(); + name = controller->GetName(); vendor = "EVGA"; type = DEVICE_TYPE_MOUSE; - description = controller->GetDeviceName(); + description = "EVGA Mouse Device"; serial = controller->GetSerial(); location = controller->GetLocation(); @@ -94,7 +94,7 @@ RGBController_EVGAMouse::RGBController_EVGAMouse(EVGAMouseController* controller modes.push_back(Pulse); mode Trigger; - Trigger.name = "Trigger"; + Trigger.name = "Trigger"; /*-----------------------------------*\ | Pulse to Trigger skips from 4 to 6. | \*-----------------------------------*/ diff --git a/Controllers/EVGAUSBController/EVGAUSBControllerDetect.cpp b/Controllers/EVGAUSBController/EVGAUSBControllerDetect.cpp index f27e9417..44e77975 100644 --- a/Controllers/EVGAUSBController/EVGAUSBControllerDetect.cpp +++ b/Controllers/EVGAUSBController/EVGAUSBControllerDetect.cpp @@ -37,24 +37,22 @@ void DetectEVGAKeyboardControllers(hid_device_info* info, const std::string& nam if(dev) { - EVGAKeyboardController* controller = new EVGAKeyboardController(dev, info->path, info->product_id); + EVGAKeyboardController* controller = new EVGAKeyboardController(dev, info->path, info->product_id, name); RGBController_EVGAKeyboard* rgb_controller = new RGBController_EVGAKeyboard(controller); - rgb_controller->name = name; ResourceManager::get()->RegisterRGBController(rgb_controller); } } -void DetectEVGAMouse(hid_device_info* info, const std::string &, int connection_type) +void DetectEVGAMouse(hid_device_info* info, const std::string &name, int connection_type) { hid_device* dev = hid_open_path(info->path); - if (dev) + + if(dev) { - EVGAMouseController* controller = new EVGAMouseController(dev, info->path, connection_type); + EVGAMouseController* controller = new EVGAMouseController(dev, info->path, connection_type, name); RGBController_EVGAMouse* rgb_controller = new RGBController_EVGAMouse(controller); - /*-------------------------*\ - | Constructor sets the name | - \*-------------------------*/ + ResourceManager::get()->RegisterRGBController(rgb_controller); } }