Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_RedragonMouse.cpp |
|
||||
| |
|
||||
| RGBController for Redragon mouse |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 25 Mar 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_RedragonMouse.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Redragon Mice
|
||||
@category Mouse
|
||||
@type USB
|
||||
@save :robot:
|
||||
@direct :x:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectRedragonMice
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_RedragonMouse::RGBController_RedragonMouse(RedragonMouseController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetNameString();
|
||||
vendor = "Redragon";
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
description = "Redragon Mouse Device";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = REDRAGON_MOUSE_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Wave;
|
||||
Wave.name = "Wave";
|
||||
Wave.value = REDRAGON_MOUSE_MODE_WAVE;
|
||||
Wave.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Wave.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Wave);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = REDRAGON_MOUSE_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Breathing.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Rainbow;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = REDRAGON_MOUSE_MODE_RAINBOW;
|
||||
Rainbow.flags = MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Rainbow.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Rainbow);
|
||||
|
||||
mode Flashing;
|
||||
Flashing.name = "Flashing";
|
||||
Flashing.value = REDRAGON_MOUSE_MODE_FLASHING;
|
||||
Flashing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Flashing.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Flashing);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_RedragonMouse::~RGBController_RedragonMouse()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::SetupZones()
|
||||
{
|
||||
zone mouse_zone;
|
||||
mouse_zone.name = "Mouse";
|
||||
mouse_zone.type = ZONE_TYPE_SINGLE;
|
||||
mouse_zone.leds_min = REDRAGON_MOUSE_LED_COUNT;
|
||||
mouse_zone.leds_max = REDRAGON_MOUSE_LED_COUNT;
|
||||
mouse_zone.leds_count = REDRAGON_MOUSE_LED_COUNT;
|
||||
mouse_zone.matrix_map = NULL;
|
||||
zones.push_back(mouse_zone);
|
||||
|
||||
led mouse_led;
|
||||
mouse_led.name = "Mouse";
|
||||
leds.push_back(mouse_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
unsigned char blu = RGBGetBValue(colors[0]);
|
||||
|
||||
controller->SendMouseColor(red, grn, blu);
|
||||
controller->SendMouseApply();
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonMouse::DeviceUpdateMode()
|
||||
{
|
||||
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
unsigned char blu = RGBGetBValue(colors[0]);
|
||||
|
||||
if((modes[active_mode].value == REDRAGON_MOUSE_MODE_BREATHING) && random)
|
||||
{
|
||||
controller->SendMouseMode(REDRAGON_MOUSE_MODE_RANDOM_BREATHING, 0, red, grn, blu);
|
||||
}
|
||||
else
|
||||
{
|
||||
controller->SendMouseMode(modes[active_mode].value, 0, red, grn, blu);
|
||||
}
|
||||
|
||||
controller->SendMouseApply();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_RedragonMouse.h |
|
||||
| |
|
||||
| RGBController for Redragon mouse |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 25 Mar 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "RedragonMouseController.h"
|
||||
|
||||
class RGBController_RedragonMouse : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_RedragonMouse(RedragonMouseController* controller_ptr);
|
||||
~RGBController_RedragonMouse();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
RedragonMouseController* controller;
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RedragonControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for Redragon devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 15 Mar 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <hidapi.h>
|
||||
#include "Detector.h"
|
||||
#include "RedragonMouseController.h"
|
||||
#include "RGBController_RedragonMouse.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mouse product IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
#define REDRAGON_MOUSE_VID 0x04D9
|
||||
#define REDRAGON_MOUSE_USAGE_PAGE 0xFFA0
|
||||
#define REDRAGON_M711_PID 0xFC30
|
||||
#define REDRAGON_M715_PID 0xFC39
|
||||
#define REDRAGON_M716_PID 0xFC3A
|
||||
#define REDRAGON_M908_PID 0xFC4D
|
||||
#define REDRAGON_M602_PID 0xFC38
|
||||
#define REDRAGON_M808_PID 0xFC5F
|
||||
#define REDRAGON_M801_PID 0xFC58
|
||||
#define REDRAGON_M810_PID 0xFA7E
|
||||
#define REDRAGON_M987_PID 0xFC69
|
||||
#define REDRAGON_M921_PID 0xFC40
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRedragonMice *
|
||||
* *
|
||||
* Tests the USB address to see if a Redragon Mouse controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRedragonMice(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
RedragonMouseController* controller = new RedragonMouseController(dev, info->path, name);
|
||||
RGBController_RedragonMouse* rgb_controller = new RGBController_RedragonMouse(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------------------------------------------------------------------*\
|
||||
| Mice |
|
||||
\*---------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M711 Cobra", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M711_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M715 Dagger", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M715_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M716 Inquisitor", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M716_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M908 Impact", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M908_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M602 Griffin", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M602_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M808 Storm", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M808_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M801 Sniper", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M801_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M810 Taipan", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M810_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M987 Reaping", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M987_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
REGISTER_HID_DETECTOR_IP("Redragon M921 Azzinoth", DetectRedragonMice, REDRAGON_MOUSE_VID, REDRAGON_M921_PID, 2, REDRAGON_MOUSE_USAGE_PAGE);
|
||||
@@ -0,0 +1,167 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RedragonMouseController.cpp |
|
||||
| |
|
||||
| Driver for Redragon mouse |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 15 Mar 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include "RedragonMouseController.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
RedragonMouseController::RedragonMouseController(hid_device* dev_handle, const char* path, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
name = dev_name;
|
||||
|
||||
unsigned char active_profile = 0x00;
|
||||
|
||||
SendWritePacket(0x002C, 1, &active_profile);
|
||||
SendMouseApply();
|
||||
}
|
||||
|
||||
RedragonMouseController::~RedragonMouseController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string RedragonMouseController::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string RedragonMouseController::GetNameString()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string RedragonMouseController::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
void RedragonMouseController::SendMouseColor
|
||||
(
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char color_buf[3];
|
||||
|
||||
color_buf[0] = red;
|
||||
color_buf[1] = green;
|
||||
color_buf[2] = blue;
|
||||
|
||||
SendWritePacket(0x0449, 3, color_buf);
|
||||
}
|
||||
|
||||
void RedragonMouseController::SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed
|
||||
)
|
||||
{
|
||||
unsigned char mode_buf[3];
|
||||
|
||||
mode_buf[0] = 0x01; //On
|
||||
mode_buf[1] = speed;
|
||||
mode_buf[2] = mode;
|
||||
|
||||
SendWritePacket(0x044C, 3, mode_buf);
|
||||
}
|
||||
|
||||
void RedragonMouseController::SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char color_mode_buf[6];
|
||||
|
||||
color_mode_buf[0] = red;
|
||||
color_mode_buf[1] = green;
|
||||
color_mode_buf[2] = blue;
|
||||
color_mode_buf[3] = 0x01; //On
|
||||
color_mode_buf[4] = speed;
|
||||
color_mode_buf[5] = mode;
|
||||
|
||||
SendWritePacket(0x0449, 6, color_mode_buf);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonMouseController::SendMouseApply()
|
||||
{
|
||||
unsigned char usb_buf[REDRAGON_MOUSE_REPORT_SIZE];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, REDRAGON_MOUSE_REPORT_SIZE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = REDRAGON_MOUSE_REPORT_ID;
|
||||
usb_buf[0x01] = 0xF1;
|
||||
usb_buf[0x02] = 0x02;
|
||||
usb_buf[0x03] = 0x04;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, REDRAGON_MOUSE_REPORT_SIZE);
|
||||
}
|
||||
|
||||
void RedragonMouseController::SendWritePacket
|
||||
(
|
||||
unsigned short address,
|
||||
unsigned char data_size,
|
||||
unsigned char * data
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[REDRAGON_MOUSE_REPORT_SIZE];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, REDRAGON_MOUSE_REPORT_SIZE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = REDRAGON_MOUSE_REPORT_ID;
|
||||
usb_buf[0x01] = 0xF3;
|
||||
usb_buf[0x02] = address & 0xFF;
|
||||
usb_buf[0x03] = address >> 8;
|
||||
usb_buf[0x04] = data_size;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x08], data, data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, REDRAGON_MOUSE_REPORT_SIZE);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RedragonMouseController.h |
|
||||
| |
|
||||
| Driver for Redragon mouse |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 15 Mar 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
|
||||
#define REDRAGON_MOUSE_REPORT_ID 0x02
|
||||
#define REDRAGON_MOUSE_REPORT_SIZE 16
|
||||
#define REDRAGON_MOUSE_LED_COUNT 1
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_MOUSE_MODE_WAVE = 0x00,
|
||||
REDRAGON_MOUSE_MODE_RANDOM_BREATHING = 0x01,
|
||||
REDRAGON_MOUSE_MODE_STATIC = 0x02,
|
||||
REDRAGON_MOUSE_MODE_BREATHING = 0x04,
|
||||
REDRAGON_MOUSE_MODE_RAINBOW = 0x08,
|
||||
REDRAGON_MOUSE_MODE_FLASHING = 0x10
|
||||
};
|
||||
|
||||
class RedragonMouseController
|
||||
{
|
||||
public:
|
||||
RedragonMouseController(hid_device* dev_handle, const char* path, std::string dev_name);
|
||||
~RedragonMouseController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetNameString();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SendMouseApply();
|
||||
|
||||
void SendMouseColor
|
||||
(
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
void SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed
|
||||
);
|
||||
|
||||
void SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string name;
|
||||
|
||||
void SendWritePacket
|
||||
(
|
||||
unsigned short address,
|
||||
unsigned char data_size,
|
||||
unsigned char * data
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user