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,169 @@
/*-------------------------------------------------------------------*\
| CMMP750Controller.cpp |
| |
| Driver for Coolermaster MP750 mousepad |
| |
| Chris M (Dr_No) 16th Apr 2020 |
| |
\*-------------------------------------------------------------------*/
#include "CMMP750Controller.h"
static unsigned char colour_mode_data[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Off */
{ 0x01, 0x04, 0xFF, 0x00, 0xFF, 0x00 }, /* Static */
{ 0x02, 0x04, 0xFF, 0x00, 0xFF, 0x80 }, /* Blinking */
{ 0x03, 0x04, 0xFF, 0x00, 0xFF, 0x80 }, /* Breathing */
{ 0x04, 0x04, 0x80, 0x00, 0x00, 0x00 }, /* Colour Cycle */
{ 0x05, 0x04, 0x80, 0x00, 0x00, 0x00 } /* Colour Breath */
};
static unsigned char speed_mode_data[9] =
{
0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 /* Speed Definition */
};
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, char *_path)
{
dev = dev_handle;
location = _path;
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());
GetStatus(); //When setting up device get current status
}
CMMP750Controller::~CMMP750Controller()
{
hid_close(dev);
}
void CMMP750Controller::GetStatus()
{
unsigned char buffer[0x41] = { 0x00 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
buffer[1] = 0x07;
hid_write(dev, buffer, buffer_size);
hid_read(dev, buffer, buffer_size);
if((buffer[0] == 0x80) && (buffer[1] == 0x05))
{
current_mode = buffer[2];
current_red = buffer[3];
current_green = buffer[4];
current_blue = buffer[5];
for(int i = 0; (speed_mode_data[i] >= buffer[6] && i <= MP750_SPEED_FASTEST); i++)
{
current_speed = i;
}
}
else
{
//Code should never reach here however just in case there is a failure set something
current_mode = CM_MP750_MODE_COLOR_CYCLE; //Unicorn Spew
current_red = 0xFF;
current_green = 0xFF;
current_blue = 0xFF;
current_speed = MP750_SPEED_NORMAL;
}
}
std::string CMMP750Controller::GetDeviceName()
{
return device_name;
}
std::string CMMP750Controller::GetSerial()
{
return serial;
}
std::string CMMP750Controller::GetLocation()
{
return("HID: " + location);
}
unsigned char CMMP750Controller::GetMode()
{
return current_mode;
}
unsigned char CMMP750Controller::GetLedRed()
{
return current_red;
}
unsigned char CMMP750Controller::GetLedGreen()
{
return current_green;
}
unsigned char CMMP750Controller::GetLedBlue()
{
return current_blue;
}
unsigned char CMMP750Controller::GetLedSpeed()
{
return current_speed;
}
void CMMP750Controller::SetMode(unsigned char mode, unsigned char speed)
{
current_mode = mode;
current_speed = speed;
SendUpdate();
}
void CMMP750Controller::SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
current_red = red;
current_green = green;
current_blue = blue;
SendUpdate();
}
void CMMP750Controller::SendUpdate()
{
unsigned char buffer[0x41] = { 0x00 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
for(std::size_t i = 0; i < CM_COLOUR_MODE_DATA_SIZE; i++)
{
buffer[i+1] = colour_mode_data[current_mode][i];
}
if(current_mode > CM_MP750_MODE_BREATHING)
{
//If the mode is random colours set SPEED at BYTE2
buffer[CM_RED_BYTE] = speed_mode_data[current_speed];
}
else
{
//Otherwise SPEED is BYTE5
buffer[CM_RED_BYTE] = current_red;
buffer[CM_GREEN_BYTE] = current_green;
buffer[CM_BLUE_BYTE] = current_blue;
buffer[CM_SPEED_BYTE] = speed_mode_data[current_speed];
}
hid_write(dev, buffer, buffer_size);
}

View File

@@ -0,0 +1,95 @@
/*-------------------------------------------------------------------*\
| CMMP750Controller.h |
| |
| Driver for Coolermaster MP750 mousepad |
| |
| Chris M (Dr_No) 16th Apr 2020 |
| |
| Simple RGB device with 5 modes |
| BYTE0 = Mode (0x01 thru 0x05 |
| BYTE1 = ?? Must be set to 0x04 for colour modes otherwise ignored |
| BYTE2 = Colour Modes: RED else Cycle SPEED |
| BYTE3 = Colour Modes: GREEN else ignored |
| BYTE4 = Colour Modes: BLUE else ignored |
| BYTE5 = Colour Modes: SPEED else ignored |
\*-------------------------------------------------------------------*/
#include <string>
#include <array>
#include <hidapi/hidapi.h>
#pragma once
#define CM_COLOUR_MODE_DATA_SIZE (sizeof(colour_mode_data[0]) / sizeof(colour_mode_data[0][0]))
#define CM_INTERRUPT_TIMEOUT 250
#define CM_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
#define CM_SERIAL_SIZE (sizeof(serial) / sizeof(serial[ 0 ]))
#define HID_MAX_STR 255
enum
{
CM_MODE_BYTE = 1,
CM_LENGTH_BYTE = 2,
CM_RED_BYTE = 3,
CM_GREEN_BYTE = 4,
CM_BLUE_BYTE = 5,
CM_SPEED_BYTE = 6
};
enum
{
CM_MP750_MODE_OFF = 0x00, //Off
CM_MP750_MODE_STATIC = 0x01, //Static Mode
CM_MP750_MODE_BLINK = 0x02, //Blinking Mode
CM_MP750_MODE_BREATHING = 0x03, //Breathing Mode
CM_MP750_MODE_COLOR_CYCLE = 0x04, //Color Cycle Mode
CM_MP750_MODE_BREATH_CYCLE = 0x05 //Breathing Cycle Mode
};
enum
{
MP750_SPEED_SLOWEST = 0x00, /* Slowest speed */
MP750_SPEED_SLOWER = 0x01, /* Slower speed */
MP750_SPEED_SLOW = 0x02, /* Slow speed */
MP750_SPEED_SLOWISH = 0x03, /* Slowish speed */
MP750_SPEED_NORMAL = 0x04, /* Normal speed */
MP750_SPEED_FASTISH = 0x05, /* Fastish speed */
MP750_SPEED_FAST = 0x06, /* Fast speed */
MP750_SPEED_FASTER = 0x07, /* Faster speed */
MP750_SPEED_FASTEST = 0x08, /* Fastest speed */
};
class CMMP750Controller
{
public:
CMMP750Controller(hid_device* dev_handle, char *_path);
~CMMP750Controller();
std::string GetDeviceName();
std::string GetSerial();
std::string GetLocation();
unsigned char GetMode();
unsigned char GetLedRed();
unsigned char GetLedGreen();
unsigned char GetLedBlue();
unsigned char GetLedSpeed();
void SetMode(unsigned char mode, unsigned char speed);
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
private:
std::string device_name;
std::string serial;
std::string location;
hid_device* dev;
unsigned char current_mode;
unsigned char current_speed;
unsigned char current_red;
unsigned char current_green;
unsigned char current_blue;
void GetStatus();
void SendUpdate();
};

View File

@@ -0,0 +1,184 @@
/*-------------------------------------------------------------------*\
| RGBController_CMMP750Controller.cpp |
| |
| Driver for Coolermaster MP750 mousepad |
| |
| Chris M (Dr_No) 18th Apr 2020 |
| |
\*-------------------------------------------------------------------*/
#include "RGBController_CMMP750Controller.h"
/**------------------------------------------------------------------*\
@name Coolermaster Mouse Pad
@category Mousemat
@type USB
@save :robot:
@direct :x:
@effects :white_check_mark:
@detectors DetectCoolerMasterMousemats
@comment
\*-------------------------------------------------------------------*/
RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controller* controller_ptr)
{
controller = controller_ptr;
unsigned char speed = controller->GetLedSpeed();
name = controller->GetDeviceName();
vendor = "Cooler Master";
type = DEVICE_TYPE_MOUSEMAT;
description = controller->GetDeviceName();
serial = controller->GetSerial();
location = controller->GetLocation();
mode Static;
Static.name = "Static";
Static.value = CM_MP750_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Static.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Static);
mode Blink;
Blink.name = "Blink";
Blink.value = CM_MP750_MODE_BLINK;
Blink.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
Blink.speed_min = MP750_SPEED_SLOWEST;
Blink.speed_max = MP750_SPEED_FASTEST;
Blink.color_mode = MODE_COLORS_PER_LED;
Blink.speed = speed;
modes.push_back(Blink);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = CM_MP750_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
Breathing.speed_min = MP750_SPEED_SLOWEST;
Breathing.speed_max = MP750_SPEED_FASTEST;
Breathing.color_mode = MODE_COLORS_PER_LED;
Breathing.speed = speed;
modes.push_back(Breathing);
mode ColorCycle;
ColorCycle.name = "Color Cycle";
ColorCycle.value = CM_MP750_MODE_COLOR_CYCLE;
ColorCycle.flags = MODE_FLAG_HAS_SPEED;
ColorCycle.speed_min = MP750_SPEED_SLOWEST;
ColorCycle.speed_max = MP750_SPEED_FASTEST;
ColorCycle.color_mode = MODE_COLORS_NONE;
ColorCycle.speed = speed;
modes.push_back(ColorCycle);
mode BreathCycle;
BreathCycle.name = "Breath Cycle";
BreathCycle.value = CM_MP750_MODE_BREATH_CYCLE;
BreathCycle.flags = MODE_FLAG_HAS_SPEED;
BreathCycle.speed_min = MP750_SPEED_SLOWEST;
BreathCycle.speed_max = MP750_SPEED_FASTEST;
BreathCycle.color_mode = MODE_COLORS_NONE;
BreathCycle.speed = speed;
modes.push_back(BreathCycle);
mode Off;
Off.name = "Turn Off";
Off.value = CM_MP750_MODE_OFF;
Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off);
SetupZones();
active_mode = GetDeviceMode();
}
RGBController_CMMP750Controller::~RGBController_CMMP750Controller()
{
delete controller;
}
int RGBController_CMMP750Controller::GetDeviceMode()
{
int temp_mode = controller->GetMode();
for(unsigned int i = 0; i < modes.size(); i++)
{
if (temp_mode == modes[i].value)
{
return i;
}
}
/*---------------------------------------------------------*\
| If not found return 0 |
\*---------------------------------------------------------*/
return 0;
}
void RGBController_CMMP750Controller::SetupZones()
{
zone MP_zone;
MP_zone.name = "Mousepad";
MP_zone.type = ZONE_TYPE_SINGLE;
MP_zone.leds_min = 1;
MP_zone.leds_max = 1;
MP_zone.leds_count = 1;
MP_zone.matrix_map = NULL;
zones.push_back(MP_zone);
led MP_led;
MP_led.name = "Mousepad LED";
leds.push_back(MP_led);
SetupColors();
/*---------------------------------------------------------*\
| Initialize colors for each LED |
\*---------------------------------------------------------*/
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
{
unsigned char red = controller->GetLedRed();
unsigned char grn = controller->GetLedGreen();
unsigned char blu = controller->GetLedBlue();
colors[led_idx] = ToRGBColor(red, grn, blu);
}
}
void RGBController_CMMP750Controller::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_CMMP750Controller::DeviceUpdateLEDs()
{
unsigned char red = RGBGetRValue(colors[0]);
unsigned char grn = RGBGetGValue(colors[0]);
unsigned char blu = RGBGetBValue(colors[0]);
controller->SetColor(red, grn, blu);
}
void RGBController_CMMP750Controller::UpdateZoneLEDs(int zone)
{
RGBColor color = colors[zone];
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
controller->SetColor(red, grn, blu);
}
void RGBController_CMMP750Controller::UpdateSingleLED(int led)
{
UpdateZoneLEDs(led);
}
void RGBController_CMMP750Controller::SetCustomMode()
{
active_mode = 0;
}
void RGBController_CMMP750Controller::DeviceUpdateMode()
{
controller->SetMode(modes[active_mode].value, modes[active_mode].speed);
}

View File

@@ -0,0 +1,33 @@
/*-------------------------------------------------------------------*\
| RGBController_CMMP750Controller.h |
| |
| Driver for Coolermaster MP750 mousepad |
| |
| Chris M (Dr_No) 18th Apr 2020 |
| |
\*-------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CMMP750Controller.h"
class RGBController_CMMP750Controller : public RGBController
{
public:
RGBController_CMMP750Controller(CMMP750Controller* controller_ptr);
~RGBController_CMMP750Controller();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
CMMP750Controller* controller;
int GetDeviceMode();
};