diff --git a/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp b/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp new file mode 100644 index 00000000..54b18b52 --- /dev/null +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseController.cpp @@ -0,0 +1,83 @@ +/*---------------------------------------------------------*\ +| PatriotViperMouseController.cpp | +| | +| Detector for Patriot Viper Mouse | +| | +| mi4code 23 May 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include + +PatriotViperMouseController::PatriotViperMouseController(hid_device* dev_handle, const char* path) +{ + _dev = dev_handle; + _location = path; + + 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); +} + +PatriotViperMouseController::~PatriotViperMouseController() +{ + hid_close(_dev); +} + +std::string PatriotViperMouseController::GetLocation() +{ + return "HID " + _location; +} + +std::string PatriotViperMouseController::GetSerial() +{ + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(_dev, serial_string, 128); + if(ret != 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; + buffer[4] = RGBGetRValue(colors[led_index]); + 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) + { + xor_value ^= buffer[i]; + } + + if(xor_value % 2 == 0) + { + buffer[63] = (xor_value + 1) % 256; + } + else + { + buffer[63] = (xor_value - 1) % 256; + } + + 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 new file mode 100644 index 00000000..3bc7259a --- /dev/null +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseController.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------*\ +| PatriotViperMouseController.h | +| | +| Detector for Patriot Viper Mouse | +| | +| mi4code 23 May 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#pragma once + +#include +#include "StringUtils.h" +#include +#include "RGBController.h" + +class PatriotViperMouseController +{ +public: + PatriotViperMouseController(hid_device* dev_handle, const char* path); + ~PatriotViperMouseController(); + + std::string GetLocation(); + std::string GetSerial(); + void SetRGB(std::vector colors); + +private: + hid_device* _dev; + std::string _location; +}; \ No newline at end of file diff --git a/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp b/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp new file mode 100644 index 00000000..fce791a8 --- /dev/null +++ b/Controllers/PatriotViperMouseController/PatriotViperMouseControllerDetect.cpp @@ -0,0 +1,39 @@ +/*---------------------------------------------------------*\ +| PatriotViperMouseControllerDetect.cpp | +| | +| Detector for Patriot Viper Mouse | +| | +| mi4code 07 Apr 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include "Detector.h" +#include "PatriotViperMouseController.h" +#include "RGBController_PatriotViperMouse.h" + + +/*-----------------------------------------------------*\ +| Patriot Viper Mouse IDs | +\*-----------------------------------------------------*/ + +#define PATRIOT_VID 0x0C45 +#define VIPER_V550_PID 0x7E18 + + +void DetectPatriotViperMouseControllers(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + PatriotViperMouseController* controller = new PatriotViperMouseController(dev, info->path); + RGBController_PatriotViperMouse* rgb_controller = new RGBController_PatriotViperMouse(controller); + rgb_controller->name = name; + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + +REGISTER_HID_DETECTOR_IPU("Patriot Viper V550", DetectPatriotViperMouseControllers, PATRIOT_VID, VIPER_V550_PID, 2, 0xFF18, 0x01); diff --git a/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp new file mode 100644 index 00000000..e574b143 --- /dev/null +++ b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.cpp @@ -0,0 +1,121 @@ +/*---------------------------------------------------------*\ +| RGBController_PatriotViperMouse.cpp | +| | +| RGBController for Patriot Viper Mouse | +| | +| mi4code 07 Apr 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include "RGBController_PatriotViperMouse.h" + +/**------------------------------------------------------------------*\ + @name Patriot Viper V550 + @category Mouse + @type USB + @save :o: + @direct :white_check_mark: + @effects :o: + @detectors DetectPatriotViperMouseControllers + @comment +\*-------------------------------------------------------------------*/ + +RGBController_PatriotViperMouse::RGBController_PatriotViperMouse(PatriotViperMouseController* controller_ptr) +{ + controller = controller_ptr; + + name = "Patriot Viper Mouse"; + vendor = "Patriot"; + type = DEVICE_TYPE_MOUSE; + description = "Patriot Viper Mouse"; + location = controller->GetLocation(); + serial = controller->GetSerial(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = 1; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); + + SetupZones(); +}; + +RGBController_PatriotViperMouse::~RGBController_PatriotViperMouse() +{ + delete controller; +} + +void RGBController_PatriotViperMouse::SetupZones() +{ + zone left_zone; + left_zone.name = "Left"; + left_zone.type = ZONE_TYPE_LINEAR; + left_zone.leds_min = 3; + left_zone.leds_max = 3; + left_zone.leds_count = 3; + left_zone.matrix_map = NULL; + zones.push_back(left_zone); + + zone right_zone; + right_zone.name = "Right"; + right_zone.type = ZONE_TYPE_LINEAR; + right_zone.leds_min = 3; + right_zone.leds_max = 3; + right_zone.leds_count = 3; + right_zone.matrix_map = NULL; + zones.push_back(right_zone); + + zone wheel_zone; + wheel_zone.name = "Mousewheel"; + wheel_zone.type = ZONE_TYPE_SINGLE; + wheel_zone.leds_min = 1; + wheel_zone.leds_max = 1; + wheel_zone.leds_count = 1; + wheel_zone.matrix_map = NULL; + zones.push_back(wheel_zone); + + for(unsigned char i = 0x00; i < 0x07; i++) + { + led new_led; + new_led.name = "LED " + std::to_string(i+1); + leds.push_back(new_led); + } + + SetupColors(); +} + +void RGBController_PatriotViperMouse::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_PatriotViperMouse::DeviceUpdateLEDs() +{ + DeviceUpdateMode(); +} + +void RGBController_PatriotViperMouse::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_PatriotViperMouse::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_PatriotViperMouse::DeviceUpdateMode() +{ + /*-----------------*\ + | Direct mode | + \*-----------------*/ + if(modes[active_mode].value == 1) + { + controller->SetRGB(colors); + } +} diff --git a/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.h b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.h new file mode 100644 index 00000000..5d9ea63b --- /dev/null +++ b/Controllers/PatriotViperMouseController/RGBController_PatriotViperMouse.h @@ -0,0 +1,35 @@ +/*---------------------------------------------------------*\ +| RGBController_PatriotViperMouse.h | +| | +| RGBController for Patriot Viper Mouse | +| | +| mi4code 07 Apr 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#pragma once + +#include "RGBController.h" +#include "PatriotViperMouseController.h" + +class RGBController_PatriotViperMouse : public RGBController +{ +public: + RGBController_PatriotViperMouse(PatriotViperMouseController* controller_ptr); + ~RGBController_PatriotViperMouse(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void DeviceUpdateMode(); + +private: + PatriotViperMouseController* controller; +};