Store name in EVGAUSBControllers to avoid setting it in detectors

This commit is contained in:
Adam Honse 2025-08-08 00:11:31 -05:00
parent abe7068197
commit 8813c9936d
7 changed files with 44 additions and 68 deletions

View file

@ -57,23 +57,13 @@ static uint8_t packet_map[EVGA_KEYBOARD_FULL_SIZE_KEYCOUNT + EVGA_KEYBOARD_Z20_E
82, 102 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; dev = dev_handle;
location = path; location = path;
name = dev_name;
pid = kb_pid; 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(); SetSleepTime();
} }
@ -82,9 +72,9 @@ EVGAKeyboardController::~EVGAKeyboardController()
hid_close(dev); hid_close(dev);
} }
std::string EVGAKeyboardController::GetDeviceName() std::string EVGAKeyboardController::GetName()
{ {
return(device_name); return(name);
} }
std::string EVGAKeyboardController::GetSerial() std::string EVGAKeyboardController::GetSerial()
@ -197,11 +187,11 @@ void EVGAKeyboardController::GetStatus(mode *mode)
mode->speed = buffer[EVGA_KB_SPEED_LSB]; mode->speed = buffer[EVGA_KB_SPEED_LSB];
break; 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 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) 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]); return(buffer[index]);
} }
else 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); return(0);
} }
} }

View file

@ -91,10 +91,10 @@ enum EVGA_Keyboard_Controller_Speed
class EVGAKeyboardController class EVGAKeyboardController
{ {
public: 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(); ~EVGAKeyboardController();
std::string GetDeviceName(); std::string GetName();
std::string GetSerial(); std::string GetSerial();
std::string GetLocation(); std::string GetLocation();
@ -108,7 +108,7 @@ public:
uint8_t GetMode(); uint8_t GetMode();
uint16_t GetPid(); uint16_t GetPid();
private: private:
std::string device_name; std::string name;
std::string location; std::string location;
hid_device* dev; hid_device* dev;
uint16_t pid; uint16_t pid;

View file

@ -205,10 +205,10 @@ RGBController_EVGAKeyboard::RGBController_EVGAKeyboard(EVGAKeyboardController* c
controller = controller_ptr; controller = controller_ptr;
name = "EVGA USB Keyboard"; name = controller->GetName();
vendor = "EVGA"; vendor = "EVGA";
type = DEVICE_TYPE_KEYBOARD; type = DEVICE_TYPE_KEYBOARD;
description = controller->GetDeviceName(); description = "EVGA Keyboard Device";
serial = controller->GetSerial(); serial = controller->GetSerial();
location = controller->GetLocation(); location = controller->GetLocation();

View file

@ -46,23 +46,13 @@ static bool BuffersAreEqual(unsigned char *buffer1, unsigned char *buffer2, int
return true; 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; dev = dev_handle;
location = _path; location = path;
name = dev_name;
this->connection_type = connection_type; 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); led_states.resize(EVGA_PERIPHERAL_LED_COUNT);
for(EVGAMouseControllerDeviceState &led_state : led_states) for(EVGAMouseControllerDeviceState &led_state : led_states)
{ {
@ -76,12 +66,12 @@ EVGAMouseController::EVGAMouseController(hid_device* dev_handle, char *_path, in
EVGAMouseController::~EVGAMouseController() EVGAMouseController::~EVGAMouseController()
{ {
hid_close(dev);
} }
std::string EVGAMouseController::GetDeviceName() std::string EVGAMouseController::GetName()
{ {
return device_name; return(name);
} }
std::string EVGAMouseController::GetSerial() std::string EVGAMouseController::GetSerial()
@ -134,14 +124,14 @@ void EVGAMouseController::SetMode(uint8_t mode, uint8_t index)
if(err == -1) if(err == -1)
{ {
const wchar_t* err_str = hid_error(dev); 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; led_states[index].mode = mode;
err = hid_get_feature_report(dev, buffer, EVGA_PERIPHERAL_PACKET_SIZE); err = hid_get_feature_report(dev, buffer, EVGA_PERIPHERAL_PACKET_SIZE);
if(err == -1) if(err == -1)
{ {
const wchar_t* err_str = hid_error(dev); 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) if(err == -1)
{ {
const wchar_t* err_str = hid_error(dev); 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].brightness = brightness;
led_states[index].speed = speed; led_states[index].speed = speed;
@ -257,7 +247,7 @@ void EVGAMouseController::RefreshDeviceState(int led)
if(err == -1) if(err == -1)
{ {
const wchar_t* err_str = hid_error(dev); 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 | | 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]; int color_count = buffer[EVGA_PERIPHERAL_COLOR_COUNT_BYTE];
if(color_count == 0) 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; return;
} }
led_states[led].mode = buffer[EVGA_PERIPHERAL_MODE_BYTE]; 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) if(bytes_read == -1)
{ {
const wchar_t* err_str = hid_error(dev); 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; return false;
} }
else if(IsResponseNotReadyPacket(buffer)) 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; return false;
} }
else if(IsAsleepPacket(buffer)) 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 false;
} }
return true; return true;

View file

@ -91,10 +91,10 @@ struct EVGAMouseControllerDeviceState
class EVGAMouseController class EVGAMouseController
{ {
public: 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(); ~EVGAMouseController();
std::string GetDeviceName(); std::string GetName();
std::string GetSerial(); std::string GetSerial();
std::string GetLocation(); std::string GetLocation();
@ -144,6 +144,12 @@ public:
void SetAllLedsAndActivate(uint8_t brightness, uint8_t speed, const std::vector<RGBColor>& colors); void SetAllLedsAndActivate(uint8_t brightness, uint8_t speed, const std::vector<RGBColor>& colors);
private: private:
hid_device* dev;
std::string location;
std::string name;
int connection_type;
std::vector<EVGAMouseControllerDeviceState> led_states;
/*----------------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------------*\
| Sets the led to the given colors with the given brightness and speed. if activate is true, activates the current | | 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. | | read from the device should be retried at a later time. |
\*------------------------------------------------------------------------------*/ \*------------------------------------------------------------------------------*/
bool IsResponseNotReadyPacket(unsigned char *buffer); bool IsResponseNotReadyPacket(unsigned char *buffer);
std::string device_name;
std::string location;
hid_device* dev;
int connection_type;
std::vector<EVGAMouseControllerDeviceState> led_states;
}; };

View file

@ -27,10 +27,10 @@ RGBController_EVGAMouse::RGBController_EVGAMouse(EVGAMouseController* controller
{ {
controller = controller_ptr; controller = controller_ptr;
name = controller->GetDeviceName(); name = controller->GetName();
vendor = "EVGA"; vendor = "EVGA";
type = DEVICE_TYPE_MOUSE; type = DEVICE_TYPE_MOUSE;
description = controller->GetDeviceName(); description = "EVGA Mouse Device";
serial = controller->GetSerial(); serial = controller->GetSerial();
location = controller->GetLocation(); location = controller->GetLocation();
@ -94,7 +94,7 @@ RGBController_EVGAMouse::RGBController_EVGAMouse(EVGAMouseController* controller
modes.push_back(Pulse); modes.push_back(Pulse);
mode Trigger; mode Trigger;
Trigger.name = "Trigger"; Trigger.name = "Trigger";
/*-----------------------------------*\ /*-----------------------------------*\
| Pulse to Trigger skips from 4 to 6. | | Pulse to Trigger skips from 4 to 6. |
\*-----------------------------------*/ \*-----------------------------------*/

View file

@ -37,24 +37,22 @@ void DetectEVGAKeyboardControllers(hid_device_info* info, const std::string& nam
if(dev) 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); RGBController_EVGAKeyboard* rgb_controller = new RGBController_EVGAKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller); 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); 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); RGBController_EVGAMouse* rgb_controller = new RGBController_EVGAMouse(controller);
/*-------------------------*\
| Constructor sets the name |
\*-------------------------*/
ResourceManager::get()->RegisterRGBController(rgb_controller); ResourceManager::get()->RegisterRGBController(rgb_controller);
} }
} }