Skip to content
Snippets Groups Projects
Commit 0a3a1e62 authored by mi4code's avatar mi4code Committed by Adam Honse
Browse files

Add support for Patriot Viper V550

parent a4476055
No related branches found
No related tags found
No related merge requests found
/*---------------------------------------------------------*\
| 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.h>
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<RGBColor> 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
/*---------------------------------------------------------*\
| 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 <hidapi.h>
#include "StringUtils.h"
#include <cstring>
#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<RGBColor> colors);
private:
hid_device* _dev;
std::string _location;
};
\ No newline at end of file
/*---------------------------------------------------------*\
| 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);
/*---------------------------------------------------------*\
| 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);
}
}
/*---------------------------------------------------------*\
| 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;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment