diff --git a/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp b/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp index 54b18b52..98b0fdda 100644 --- a/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp @@ -11,44 +11,49 @@ #include -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::GetSerial() +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'; + serial_string[0] = '\0'; } return StringUtils::wstring_to_string(serial_string); } void PatriotViperMouseController::SetRGB(std::vector colors) { - /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\ | 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}; - + for(unsigned char led_index = 0x00; led_index < 0x07; led_index++) { buffer[2] = led_index; @@ -56,11 +61,9 @@ void PatriotViperMouseController::SetRGB(std::vector 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) @@ -71,13 +74,12 @@ void PatriotViperMouseController::SetRGB(std::vector colors) if(xor_value % 2 == 0) { buffer[63] = (xor_value + 1) % 256; - } - else + } + else { buffer[63] = (xor_value - 1) % 256; } - hid_send_feature_report(_dev, buffer, 64); + hid_send_feature_report(dev, buffer, 64); } - -} \ No newline at end of file +} diff --git a/Controllers/PatriotViperMouseController/PatriotViperMouseController.h b/Controllers/PatriotViperMouseController/PatriotViperMouseController.h index 3bc7259a..3478c292 100644 --- a/Controllers/PatriotViperMouseController/PatriotViperMouseController.h +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseController.h @@ -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 colors); + + void SetRGB(std::vector colors); private: - hid_device* _dev; - std::string _location; -}; \ No newline at end of file + hid_device* dev; + std::string location; + std::string name; +}; diff --git a/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp b/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp index fce791a8..35be5700 100644 --- a/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp @@ -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); } diff --git a/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp index e574b143..aea8d8a3 100644 --- a/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp +++ b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp @@ -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";