Store name in PatriotViperMouseController to avoid setting it in detector

This commit is contained in:
Adam Honse 2025-08-14 19:13:11 -05:00
parent f8d3c7a838
commit 67e08d3415
4 changed files with 30 additions and 26 deletions

View file

@ -11,29 +11,35 @@
#include <PatriotViperMouseController.h>
PatriotViperMouseController::PatriotViperMouseController(hid_device* dev_handle, const char* path)
PatriotViperMouseController::PatriotViperMouseController(hid_device* dev_handle, const char* path, std::string dev_name)
{
_dev = dev_handle;
_location = path;
dev = dev_handle;
location = path;
name = dev_name;
const unsigned char init_packet[64] = {0x01, 0x00, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0xDE, 0x8D, 0x77, 0x09, 0xDF, 0x8D, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x58, 0x7C, 0x77, 0x78, 0x81, 0x43, 0x00, 0x30, 0x58, 0x7C, 0x77, 0x8C, 0x5D, 0x9B, 0x77, 0x00, 0x00, 0x3D, 0x00, 0x98, 0xF5, 0x19, 0x08, 0x00, 0x00, 0x00, 0xEE};
hid_send_feature_report(_dev, init_packet, 64);
hid_send_feature_report(dev, init_packet, 64);
}
PatriotViperMouseController::~PatriotViperMouseController()
{
hid_close(_dev);
hid_close(dev);
}
std::string PatriotViperMouseController::GetLocation()
{
return "HID " + _location;
return("HID " + location);
}
std::string PatriotViperMouseController::GetName()
{
return(name);
}
std::string PatriotViperMouseController::GetSerial()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(_dev, serial_string, 128);
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
serial_string[0] = '\0';
@ -43,7 +49,6 @@ std::string PatriotViperMouseController::GetSerial()
void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
{
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\
| led red green blue checksum |
\*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
@ -56,11 +61,9 @@ void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
buffer[5] = RGBGetGValue(colors[led_index]);
buffer[6] = RGBGetBValue(colors[led_index]);
/*--------------------------------------*\
| calculate the last checksum byte |
\*--------------------------------------*/
unsigned char xor_value = 0;
for(int i = 0; i < 63; ++i)
@ -77,7 +80,6 @@ void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
buffer[63] = (xor_value - 1) % 256;
}
hid_send_feature_report(_dev, buffer, 64);
hid_send_feature_report(dev, buffer, 64);
}
}

View file

@ -19,14 +19,17 @@
class PatriotViperMouseController
{
public:
PatriotViperMouseController(hid_device* dev_handle, const char* path);
PatriotViperMouseController(hid_device* dev_handle, const char* path, std::string dev_name);
~PatriotViperMouseController();
std::string GetLocation();
std::string GetName();
std::string GetSerial();
void SetRGB(std::vector<RGBColor> colors);
private:
hid_device* _dev;
std::string _location;
hid_device* dev;
std::string location;
std::string name;
};

View file

@ -28,9 +28,8 @@ void DetectPatriotViperMouseControllers(hid_device_info* info, const std::string
if(dev)
{
PatriotViperMouseController* controller = new PatriotViperMouseController(dev, info->path);
PatriotViperMouseController* controller = new PatriotViperMouseController(dev, info->path, name);
RGBController_PatriotViperMouse* rgb_controller = new RGBController_PatriotViperMouse(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}

View file

@ -26,7 +26,7 @@ RGBController_PatriotViperMouse::RGBController_PatriotViperMouse(PatriotViperMou
{
controller = controller_ptr;
name = "Patriot Viper Mouse";
name = controller->GetName();
vendor = "Patriot";
type = DEVICE_TYPE_MOUSE;
description = "Patriot Viper Mouse";