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,44 +11,49 @@
#include <PatriotViperMouseController.h> #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; dev = dev_handle;
_location = path; 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}; 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() PatriotViperMouseController::~PatriotViperMouseController()
{ {
hid_close(_dev); hid_close(dev);
} }
std::string PatriotViperMouseController::GetLocation() std::string PatriotViperMouseController::GetLocation()
{ {
return "HID " + _location; return("HID " + location);
} }
std::string PatriotViperMouseController::GetSerial() std::string PatriotViperMouseController::GetName()
{
return(name);
}
std::string PatriotViperMouseController::GetSerial()
{ {
wchar_t serial_string[128]; 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) if(ret != 0)
{ {
serial_string[0] = '\0'; serial_string[0] = '\0';
} }
return StringUtils::wstring_to_string(serial_string); return StringUtils::wstring_to_string(serial_string);
} }
void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors) void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
{ {
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\
| led red green blue checksum | | led red green blue checksum |
\*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ \*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
unsigned char buffer[64] = { 0x01, 0x13, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEC}; unsigned char buffer[64] = { 0x01, 0x13, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEC};
for(unsigned char led_index = 0x00; led_index < 0x07; led_index++) for(unsigned char led_index = 0x00; led_index < 0x07; led_index++)
{ {
buffer[2] = led_index; buffer[2] = led_index;
@ -56,11 +61,9 @@ void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
buffer[5] = RGBGetGValue(colors[led_index]); buffer[5] = RGBGetGValue(colors[led_index]);
buffer[6] = RGBGetBValue(colors[led_index]); buffer[6] = RGBGetBValue(colors[led_index]);
/*--------------------------------------*\ /*--------------------------------------*\
| calculate the last checksum byte | | calculate the last checksum byte |
\*--------------------------------------*/ \*--------------------------------------*/
unsigned char xor_value = 0; unsigned char xor_value = 0;
for(int i = 0; i < 63; ++i) for(int i = 0; i < 63; ++i)
@ -71,13 +74,12 @@ void PatriotViperMouseController::SetRGB(std::vector<RGBColor> colors)
if(xor_value % 2 == 0) if(xor_value % 2 == 0)
{ {
buffer[63] = (xor_value + 1) % 256; buffer[63] = (xor_value + 1) % 256;
} }
else else
{ {
buffer[63] = (xor_value - 1) % 256; 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 class PatriotViperMouseController
{ {
public: public:
PatriotViperMouseController(hid_device* dev_handle, const char* path); PatriotViperMouseController(hid_device* dev_handle, const char* path, std::string dev_name);
~PatriotViperMouseController(); ~PatriotViperMouseController();
std::string GetLocation(); std::string GetLocation();
std::string GetName();
std::string GetSerial(); std::string GetSerial();
void SetRGB(std::vector<RGBColor> colors);
void SetRGB(std::vector<RGBColor> colors);
private: private:
hid_device* _dev; hid_device* dev;
std::string _location; std::string location;
}; std::string name;
};

View file

@ -28,9 +28,8 @@ void DetectPatriotViperMouseControllers(hid_device_info* info, const std::string
if(dev) 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); RGBController_PatriotViperMouse* rgb_controller = new RGBController_PatriotViperMouse(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller); ResourceManager::get()->RegisterRGBController(rgb_controller);
} }

View file

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