Organize most controller files into subfolders

This commit is contained in:
Adam Honse
2024-04-30 17:18:39 -05:00
parent ba57bad361
commit d52ad02c5c
415 changed files with 44 additions and 43 deletions

View File

@@ -0,0 +1,207 @@
/*-------------------------------------------------------------------*\
| CMR6000Controller.cpp |
| |
| Driver for Coolermaster based AMD Radeon GPU (6000 series) |
| |
| Eric S (edbgon) 2nd Feb 2021 |
\*-------------------------------------------------------------------*/
#include "CMR6000Controller.h"
#include <cstring>
CMR6000Controller::CMR6000Controller(hid_device* dev_handle, char *_path, uint16_t _pid)
{
dev = dev_handle;
location = _path;
pid = _pid;
const int szTemp = 256;
wchar_t tmpName[szTemp];
hid_get_manufacturer_string(dev, tmpName, szTemp);
std::wstring wName = std::wstring(tmpName);
device_name = std::string(wName.begin(), wName.end());
hid_get_product_string(dev, tmpName, szTemp);
wName = std::wstring(tmpName);
device_name.append(" ").append(std::string(wName.begin(), wName.end()));
hid_get_serial_number_string(dev, tmpName, szTemp);
wName = std::wstring(tmpName);
serial = std::string(wName.begin(), wName.end());
}
CMR6000Controller::~CMR6000Controller()
{
if(dev)
{
hid_close(dev);
}
}
std::string CMR6000Controller::GetDeviceName()
{
return device_name;
}
std::string CMR6000Controller::GetSerial()
{
return serial;
}
std::string CMR6000Controller::GetLocation()
{
return("HID: " + location);
}
unsigned char CMR6000Controller::GetMode()
{
return current_mode;
}
unsigned char CMR6000Controller::GetLedSpeed()
{
return current_speed;
}
unsigned char CMR6000Controller::GetBrightness()
{
return current_brightness;
}
bool CMR6000Controller::GetRandomColours()
{
return current_random;
}
uint16_t CMR6000Controller::GetPID()
{
return pid;
}
void CMR6000Controller::SetMode(unsigned char mode, unsigned char speed, RGBColor color1, RGBColor color2, unsigned char random, unsigned char brightness)
{
current_mode = mode;
current_speed = speed;
primary = color1;
secondary = color2;
current_random = random;
current_brightness = brightness;
SendUpdate();
}
void CMR6000Controller::SendUpdate()
{
if(current_mode == CM_MR6000_MODE_OFF)
{
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x41, 0x43 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
hid_write(dev, buffer, buffer_size);
}
else
{
SendEnableCommand();
if(pid == COOLERMASTER_RADEON_6900_PID)
{
SendSecondColour();
}
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
memset(buffer, 0xFF, buffer_size);
buffer[0x00] = 0x00;
buffer[0x01] = 0x51;
buffer[0x02] = 0x2C;
buffer[0x03] = 0x01;
buffer[0x04] = 0x00;
buffer[0x05] = current_mode;
buffer[0x06] = current_speed;
buffer[0x07] = current_random; //random (A0)
//buffer[0x09] = 0xFF;
buffer[0x0A] = current_brightness;
buffer[0x0B] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : RGBGetRValue(primary);
buffer[0x0C] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : RGBGetGValue(primary);
buffer[0x0D] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : RGBGetBValue(primary);
buffer[0x0E] = 0x00;
buffer[0x0F] = 0x00;
buffer[0x10] = 0x00;
/*-----------------------------------------------------------------*\
| Index 0x08 looks to be mode specific flags / options |
\*-----------------------------------------------------------------*/
switch(current_mode)
{
case CM_MR6000_MODE_BREATHE:
buffer[0x08] = 0x03;
break;
case CM_MR6000_MODE_RAINBOW:
buffer[0x08] = 0x05;
break;
case CM_MR6000_MODE_CHASE:
buffer[0x08] = 0xC3;
break;
case CM_MR6000_MODE_SWIRL:
buffer[0x08] = 0x4A;
break;
default:
buffer[0x08] = 0xFF;
}
hid_write(dev, buffer, buffer_size);
SendColourConfig();
SendApplyCommand();
}
}
void CMR6000Controller::SendEnableCommand()
{
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x41, 0x80 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
hid_write(dev, buffer, buffer_size);
hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT);
}
void CMR6000Controller::SendApplyCommand()
{
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x51, 0x28, 0x00, 0x00, 0xE0 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
hid_write(dev, buffer, buffer_size);
hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT);
}
void CMR6000Controller::SendColourConfig()
{
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x51, 0xA0, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x06 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
for(int i = 0x0B; i < 0x1A; i++)
{
buffer[i] = current_mode;
}
hid_write(dev, buffer, buffer_size);
hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT);
}
void CMR6000Controller::SendSecondColour()
{
unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x51, 0x9C, 0x01, 0x00 };
buffer[5] = RGBGetRValue(primary);
buffer[6] = RGBGetGValue(primary);
buffer[7] = RGBGetBValue(primary);
buffer[8] = RGBGetRValue(secondary);
buffer[9] = RGBGetGValue(secondary);
buffer[10] = RGBGetBValue(secondary);
hid_write(dev, buffer, CM_6K_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_6K_PACKET_SIZE, CM_6K_INTERRUPT_TIMEOUT);
}

View File

@@ -0,0 +1,96 @@
/*-------------------------------------------------------------------*\
| CMR6000Controller.h |
| |
| Driver for Coolermaster based AMD Radeon GPU (6000 series) |
| |
| Eric S (edbgon) 2nd Feb 2021 |
\*-------------------------------------------------------------------*/
#include <string>
#include <array>
#include <hidapi/hidapi.h>
#include "RGBController.h"
#pragma once
#define COOLERMASTER_RADEON_6000_PID 0x014D
#define COOLERMASTER_RADEON_6900_PID 0x015B
#define CM_6K_PACKET_SIZE 65 //Includes extra first byte for non HID Report packets
#define CM_6K_INTERRUPT_TIMEOUT 250
#define CM_6K_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
#define CM_6K_SERIAL_SIZE (sizeof(serial) / sizeof(serial[ 0 ]))
#define HID_MAX_STR 255
enum
{
CM_MR6000_MODE_DIRECT = 0x00, //Direct Mode
CM_MR6000_MODE_BREATHE = 0x01, //Breathe Mode
CM_MR6000_MODE_COLOR_CYCLE = 0x02, //Color cycle
CM_MR6000_MODE_RAINBOW = 0x07, //Rainbow
CM_MR6000_MODE_BOUNCE = 0x08, //Bounce
CM_MR6000_MODE_CHASE = 0x09, //Chase
CM_MR6000_MODE_SWIRL = 0x0A, //Swirl
CM_MR6000_MODE_OFF = 0xFF, //Off
};
enum
{
MR6000_CYCLE_SPEED_SLOWEST = 0x96, /* Slowest speed */
MR6000_CYCLE_SPEED_SLOW = 0x8C, /* Slow speed */
MR6000_CYCLE_SPEED_NORMAL = 0x80, /* Normal speed */
MR6000_CYCLE_SPEED_FAST = 0x6E, /* Fast speed */
MR6000_CYCLE_SPEED_FASTEST = 0x68, /* Fastest speed */
MR6000_RAINBOW_SPEED_SLOWEST = 0x78, /* Slowest speed */
MR6000_RAINBOW_SPEED_NORMAL = 0x6B, /* Normal speed */
MR6000_RAINBOW_SPEED_FASTEST = 0x60, /* Fastest speed */
MR6000_BREATHE_SPEED_SLOWEST = 0x3C, /* Slowest speed */
MR6000_BREATHE_SPEED_SLOW = 0x37, /* Slow speed */
MR6000_BREATHE_SPEED_NORMAL = 0x31, /* Normal speed */
MR6000_BREATHE_SPEED_FAST = 0x2C, /* Fast speed */
MR6000_BREATHE_SPEED_FASTEST = 0x26, /* Fastest speed */
};
class CMR6000Controller
{
public:
CMR6000Controller(hid_device* dev_handle, char *_path, uint16_t _pid);
~CMR6000Controller();
std::string GetDeviceName();
std::string GetSerial();
std::string GetLocation();
unsigned char GetMode();
unsigned char GetLedSpeed();
unsigned char GetBrightness();
bool GetRandomColours();
uint16_t GetPID();
void SetMode(unsigned char mode, unsigned char speed, RGBColor color1, RGBColor color2, unsigned char random, unsigned char brightness);
private:
std::string device_name;
std::string serial;
std::string location;
hid_device* dev;
uint16_t pid;
unsigned char current_mode;
unsigned char current_speed;
unsigned char current_random;
unsigned char current_brightness;
RGBColor primary;
RGBColor secondary;
void SendUpdate();
void SendEnableCommand();
void SendApplyCommand();
void SendColourConfig();
void SendSecondColour();
};

View File

@@ -0,0 +1,229 @@
/*-------------------------------------------------------------------*\
| RGBController_CMR6000Controller.cpp |
| |
| Driver for Coolermaster based AMD Radeon GPU (6000 series) |
| |
| Eric S (edbgon) 2nd Feb 2021 |
\*-------------------------------------------------------------------*/
#include "RGBController_CMR6000Controller.h"
/**------------------------------------------------------------------*\
@name AMD Radeon 6000
@category GPU
@type USB
@save :x:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectCoolerMasterGPU
@comment Similar to the Wraith Spire before it the AMD branded Radeon
GPUs have an RGB controller provided by Coolermaster.
\*-------------------------------------------------------------------*/
RGBController_CMR6000Controller::RGBController_CMR6000Controller(CMR6000Controller* controller_ptr)
{
controller = controller_ptr;
name = "AMD RX 6xxx GPU";
vendor = "Cooler Master";
type = DEVICE_TYPE_GPU;
description = controller->GetDeviceName();
serial = controller->GetSerial();
location = controller->GetLocation();
mode Off;
Off.name = "Off";
Off.flags = 0;
Off.value = CM_MR6000_MODE_OFF;
Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off);
mode Direct;
Direct.name = "Direct";
Direct.value = CM_MR6000_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR| MODE_FLAG_HAS_BRIGHTNESS;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.speed = 0xFF;
Direct.brightness_min = 0x00;
Direct.brightness_max = 0xFF;
Direct.brightness = 0xFF;
modes.push_back(Direct);
mode ColorCycle;
ColorCycle.name = "Spectrum Cycle";
ColorCycle.value = CM_MR6000_MODE_COLOR_CYCLE;
ColorCycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
ColorCycle.speed_min = MR6000_CYCLE_SPEED_SLOWEST;
ColorCycle.speed = MR6000_CYCLE_SPEED_NORMAL;
ColorCycle.speed_max = MR6000_CYCLE_SPEED_FASTEST;
ColorCycle.color_mode = MODE_COLORS_NONE;
ColorCycle.speed = MR6000_CYCLE_SPEED_NORMAL;
ColorCycle.brightness_min = 0x00;
ColorCycle.brightness_max = 0xFF;
ColorCycle.brightness = 0x7F;
modes.push_back(ColorCycle);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = CM_MR6000_MODE_BREATHE;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
Breathing.speed_min = MR6000_BREATHE_SPEED_SLOWEST;
Breathing.speed = MR6000_BREATHE_SPEED_NORMAL;
Breathing.speed_max = MR6000_BREATHE_SPEED_FASTEST;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors_min = 1;
Breathing.colors_max = 1;
Breathing.colors.resize(1);
Breathing.speed = MR6000_BREATHE_SPEED_NORMAL;
modes.push_back(Breathing);
if(controller->GetPID() == COOLERMASTER_RADEON_6900_PID)
{
mode Rainbow;
Rainbow.name = "Rainbow Wave";
Rainbow.value = CM_MR6000_MODE_RAINBOW;
Rainbow.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
Rainbow.speed_min = MR6000_RAINBOW_SPEED_SLOWEST;
Rainbow.speed = MR6000_RAINBOW_SPEED_NORMAL;
Rainbow.speed_max = MR6000_RAINBOW_SPEED_FASTEST;
Rainbow.color_mode = MODE_COLORS_NONE;
Rainbow.speed = MR6000_RAINBOW_SPEED_NORMAL;
Rainbow.brightness_min = 0x00;
Rainbow.brightness_max = 0xFF;
Rainbow.brightness = 0xFF;
modes.push_back(Rainbow);
mode Bounce;
Bounce.name = "Bounce";
Bounce.value = CM_MR6000_MODE_BOUNCE;
Bounce.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
Bounce.speed_min = MR6000_CYCLE_SPEED_SLOWEST;
Bounce.speed = MR6000_CYCLE_SPEED_NORMAL;
Bounce.speed_max = MR6000_CYCLE_SPEED_FASTEST;
Bounce.color_mode = MODE_COLORS_NONE;
Bounce.speed = MR6000_CYCLE_SPEED_NORMAL;
Bounce.brightness_min = 0x00;
Bounce.brightness_max = 0xFF;
Bounce.brightness = 0xFF;
modes.push_back(Bounce);
mode Chase;
Chase.name = "Chase";
Chase.value = CM_MR6000_MODE_CHASE;
Chase.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Chase.speed_min = MR6000_CYCLE_SPEED_SLOWEST;
Chase.speed = MR6000_CYCLE_SPEED_NORMAL;
Chase.speed_max = MR6000_CYCLE_SPEED_FASTEST;
Chase.color_mode = MODE_COLORS_MODE_SPECIFIC;
Chase.colors_min = 2;
Chase.colors_max = 2;
Chase.colors.resize(2);
Chase.speed = MR6000_CYCLE_SPEED_NORMAL;
Chase.brightness_min = 0;
Chase.brightness_max = 0xFF;
Chase.brightness = 0xFF;
modes.push_back(Chase);
mode Swirl;
Swirl.name = "Swirl";
Swirl.value = CM_MR6000_MODE_SWIRL;
Swirl.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Swirl.speed_min = MR6000_CYCLE_SPEED_SLOWEST;
Swirl.speed = MR6000_CYCLE_SPEED_NORMAL;
Swirl.speed_max = MR6000_CYCLE_SPEED_FASTEST;
Swirl.color_mode = MODE_COLORS_MODE_SPECIFIC;
Swirl.colors_min = 1;
Swirl.colors_max = 1;
Swirl.colors.resize(1);
Swirl.speed = MR6000_CYCLE_SPEED_NORMAL;
Swirl.brightness_min = 0;
Swirl.brightness_max = 0xFF;
Swirl.brightness = 0xFF;
modes.push_back(Swirl);
}
SetupZones();
active_mode = 1;
}
RGBController_CMR6000Controller::~RGBController_CMR6000Controller()
{
delete controller;
}
void RGBController_CMR6000Controller::SetupZones()
{
zone GP_zone;
GP_zone.name = "GPU";
GP_zone.type = ZONE_TYPE_SINGLE;
GP_zone.leds_min = 1;
GP_zone.leds_max = 1;
GP_zone.leds_count = 1;
GP_zone.matrix_map = NULL;
zones.push_back(GP_zone);
led GP_led;
GP_led.name = "Logo";
GP_led.value = 0;
leds.push_back(GP_led);
SetupColors();
}
void RGBController_CMR6000Controller::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_CMR6000Controller::DeviceUpdateLEDs()
{
mode new_mode = modes[active_mode];
RGBColor color1 = (new_mode.colors.size() > 0) ? new_mode.colors[0] : colors[0];
RGBColor color2 = (new_mode.colors.size() > 1) ? new_mode.colors[1] : 0;
unsigned char bri = (new_mode.flags & MODE_FLAG_HAS_BRIGHTNESS) ? new_mode.brightness : 0xFF;
unsigned char rnd = 0x20;
switch(new_mode.value)
{
/*-----------------------------------------------------------------*\
| Breathing mode requires value 0x20 when in MODE_SPECIFIC_COLOR |
\*-----------------------------------------------------------------*/
case CM_MR6000_MODE_BREATHE:
if(new_mode.color_mode == MODE_COLORS_RANDOM)
{
rnd = 0xA0;
}
break;
case CM_MR6000_MODE_SWIRL:
case CM_MR6000_MODE_CHASE:
rnd = new_mode.direction;
break;
default:
rnd = 0;
}
controller->SetMode(new_mode.value, new_mode.speed, color1, color2, rnd, bri);
}
void RGBController_CMR6000Controller::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_CMR6000Controller::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_CMR6000Controller::SetCustomMode()
{
active_mode = 1;
}
void RGBController_CMR6000Controller::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}

View File

@@ -0,0 +1,32 @@
/*-------------------------------------------------------------------*\
| RGBController_CMR6000Controller.h |
| |
| Driver for Coolermaster based AMD Radeon GPU (6000 series) |
| |
| Eric S (edbgon) 2nd Feb 2021 |
\*-------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CMR6000Controller.h"
class RGBController_CMR6000Controller : public RGBController
{
public:
RGBController_CMR6000Controller(CMR6000Controller* controller_ptr);
~RGBController_CMR6000Controller();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
CMR6000Controller* controller;
int GetDeviceMode();
};