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,199 @@
/*-------------------------------------------------------------------*\
| CMMM711Controller.cpp |
| |
| Driver for Coolermaster Master Mouse 711 |
| |
| Chris M (Dr_No) 14th Feb 2021 |
| |
\*-------------------------------------------------------------------*/
#include "CMMM711Controller.h"
#include <cstring>
CMMM711Controller::CMMM711Controller(hid_device* dev_handle, char *_path)
{
const int szTemp = HID_MAX_STR;
wchar_t tmpName[szTemp];
dev = dev_handle;
location = _path;
current_speed = CM_MM711_SPEED_NORMAL;
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_indexed_string(dev, 2, tmpName, szTemp);
wName = std::wstring(tmpName);
serial = std::string(wName.begin(), wName.end());
SendInitPacket();
GetColourStatus();
GetCustomStatus();
GetModeStatus();
}
CMMM711Controller::~CMMM711Controller()
{
hid_close(dev);
}
void CMMM711Controller::GetColourStatus()
{
uint8_t buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x52, 0x2B };
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
current_brightness = buffer[CM_MM711_BRIGHTNESS_BYTE - 1];
current_red = buffer[CM_MM711_RED_BYTE - 1];
current_green = buffer[CM_MM711_GREEN_BYTE - 1];
current_blue = buffer[CM_MM711_BLUE_BYTE - 1];
}
void CMMM711Controller::GetCustomStatus()
{
uint8_t buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x52, 0xA8 };
int read_size = CM_MM711_PACKET_SIZE - 1;
int result = 0;
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
do
{
result = hid_read_timeout(dev, buffer, read_size, CM_MM711_INTERRUPT_TIMEOUT);
}while(buffer[1] != 0xA8 && result == read_size);
if(result == read_size)
{
wheel_colour = ToRGBColor(buffer[4], buffer[5], buffer[6]);
logo_colour = ToRGBColor(buffer[7], buffer[8], buffer[9]);
}
}
void CMMM711Controller::GetModeStatus()
{
uint8_t buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x52, 0x28 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
hid_write(dev, buffer, buffer_size);
hid_read_timeout(dev, buffer, buffer_size, CM_MM711_INTERRUPT_TIMEOUT);
current_mode = buffer[CM_MM711_MODE_BYTE - 1];
}
std::string CMMM711Controller::GetDeviceName()
{
return device_name;
}
std::string CMMM711Controller::GetSerial()
{
return serial;
}
std::string CMMM711Controller::GetLocation()
{
return("HID: " + location);
}
unsigned char CMMM711Controller::GetMode()
{
return current_mode;
}
unsigned char CMMM711Controller::GetLedRed()
{
return current_red;
}
unsigned char CMMM711Controller::GetLedGreen()
{
return current_green;
}
unsigned char CMMM711Controller::GetLedBlue()
{
return current_blue;
}
unsigned char CMMM711Controller::GetLedSpeed()
{
return current_speed;
}
RGBColor CMMM711Controller::GetWheelColour()
{
return wheel_colour;
}
RGBColor CMMM711Controller::GetLogoColour()
{
return logo_colour;
}
void CMMM711Controller::SetLedsDirect(RGBColor wheel_colour, RGBColor logo_colour)
{
unsigned char buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x51, 0xA8, 0x00, 0x00 };
buffer[CM_MM711_MODE_BYTE] = RGBGetRValue(wheel_colour);
buffer[CM_MM711_SPEED_BYTE] = RGBGetGValue(wheel_colour);
buffer[CM_MM711_NFI_1] = RGBGetBValue(wheel_colour);
buffer[CM_MM711_NFI_2] = RGBGetRValue(logo_colour);
buffer[CM_MM711_NFI_3] = RGBGetGValue(logo_colour);
buffer[CM_MM711_BRIGHTNESS_BYTE] = RGBGetBValue(logo_colour);
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
//SendApplyPacket(0xB0); //Apply custom mode
}
void CMMM711Controller::SendUpdate(uint8_t mode, uint8_t speed, RGBColor colour, uint8_t brightness)
{
unsigned char buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x51, 0x2B, 0x00, 0x00 };
buffer[CM_MM711_MODE_BYTE] = mode;
buffer[CM_MM711_SPEED_BYTE] = speed;
buffer[CM_MM711_NFI_1] = 0x20;
buffer[CM_MM711_NFI_2] = 0xFF;
buffer[CM_MM711_NFI_3] = 0xFF;
buffer[CM_MM711_BRIGHTNESS_BYTE] = brightness;
buffer[CM_MM711_RED_BYTE] = RGBGetRValue(colour);
buffer[CM_MM711_GREEN_BYTE] = RGBGetGValue(colour);
buffer[CM_MM711_BLUE_BYTE] = RGBGetBValue(colour);
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
SendApplyPacket(mode);
}
void CMMM711Controller::SendInitPacket()
{
unsigned char buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x41, 0x80 };
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
}
void CMMM711Controller::SendApplyPacket(uint8_t mode)
{
unsigned char buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x51, 0x28, 0x00, 0x00 };
buffer[CM_MM711_MODE_BYTE] = mode;
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
}
void CMMM711Controller::SendSavePacket()
{
unsigned char buffer[CM_MM711_PACKET_SIZE] = { 0x00, 0x50, 0x55 };
hid_write(dev, buffer, CM_MM711_PACKET_SIZE);
hid_read_timeout(dev, buffer, CM_MM711_PACKET_SIZE, CM_MM711_INTERRUPT_TIMEOUT);
}

View File

@@ -0,0 +1,101 @@
/*-------------------------------------------------------------------*\
| CMMM711Controller.h |
| |
| Driver for Coolermaster Master Mouse 711 |
| |
| Chris M (Dr_No) 14th Feb 2021 |
| |
\*-------------------------------------------------------------------*/
#include <string>
#include <array>
#include <hidapi/hidapi.h>
#include "RGBController.h"
#pragma once
#define CM_MM711_PACKET_SIZE 65
#define CM_MM711_COLOUR_MODE_DATA_SIZE (sizeof(colour_mode_data[0]) / sizeof(colour_mode_data[0][0]))
#define CM_MM711_HEADER_DATA_SIZE (sizeof(argb_header_data) / sizeof(argb_headers) )
#define CM_MM711_INTERRUPT_TIMEOUT 250
#define CM_MM711_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
#define HID_MAX_STR 255
enum
{
CM_MM711_REPORT_BYTE = 1,
CM_MM711_COMMAND_BYTE = 2,
CM_MM711_FUNCTION_BYTE = 3,
CM_MM711_ZONE_BYTE = 4,
CM_MM711_MODE_BYTE = 5,
CM_MM711_SPEED_BYTE = 6,
CM_MM711_NFI_1 = 7,
CM_MM711_NFI_2 = 8,
CM_MM711_NFI_3 = 9,
CM_MM711_BRIGHTNESS_BYTE = 10,
CM_MM711_RED_BYTE = 11,
CM_MM711_GREEN_BYTE = 12,
CM_MM711_BLUE_BYTE = 13,
};
enum
{
CM_MM711_MODE_STATIC = 0, //Static Mode
CM_MM711_MODE_BREATHING = 1, //Breathing Mode
CM_MM711_MODE_SPECTRUM_CYCLE = 2, //Spectrum Cycle Mode
CM_MM711_MODE_INDICATOR = 4, //Indicator Mode
CM_MM711_MODE_CUSTOM = 176, //Custom LED Control
CM_MM711_MODE_OFF = 254 //Turn Off
};
enum
{
CM_MM711_SPEED_SLOWEST = 0x5F, // Slowest speed
CM_MM711_SPEED_NORMAL = 0x38, // Normal speed
CM_MM711_SPEED_FASTEST = 0x20, // Fastest speed
};
class CMMM711Controller
{
public:
CMMM711Controller(hid_device* dev_handle, char *_path);
~CMMM711Controller();
std::string GetDeviceName();
std::string GetSerial();
std::string GetLocation();
uint8_t GetZoneIndex();
uint8_t GetMode();
uint8_t GetLedRed();
uint8_t GetLedGreen();
uint8_t GetLedBlue();
uint8_t GetLedSpeed();
RGBColor GetWheelColour();
RGBColor GetLogoColour();
void SendUpdate(uint8_t mode, uint8_t speed, RGBColor colour, uint8_t brightness);
void SetLedsDirect(RGBColor wheel_colour, RGBColor logo_colour);
void SendSavePacket();
private:
std::string device_name;
std::string serial;
std::string location;
hid_device* dev;
uint8_t current_mode;
uint8_t current_speed;
uint8_t current_brightness;
uint8_t current_red;
uint8_t current_green;
uint8_t current_blue;
RGBColor wheel_colour;
RGBColor logo_colour;
void GetColourStatus();
void GetCustomStatus();
void GetModeStatus();
void SendInitPacket();
void SendApplyPacket(uint8_t mode);
};

View File

@@ -0,0 +1,216 @@
/*-------------------------------------------------------------------*\
| RGBController_CMMM711Controller.cpp |
| |
| Driver for Coolermaster MM711 Controller |
| |
| Chris M (Dr_No) 14th Feb 2021 |
| |
\*-------------------------------------------------------------------*/
#define applyBrightness(c, bright) ((RGBColor) ((RGBGetBValue(c) * bright / CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT) << 16 | (RGBGetGValue(c) * bright / CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT) << 8 | (RGBGetRValue(c) * bright / CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT)))
#include "RGBController_CMMM711Controller.h"
/**------------------------------------------------------------------*\
@name Coolermaster Master Mouse
@category Mouse
@type USB
@save :robot:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectCoolerMasterMouse
@comment
\*-------------------------------------------------------------------*/
RGBController_CMMM711Controller::RGBController_CMMM711Controller(CMMM711Controller* controller_ptr)
{
controller = controller_ptr;
name = controller->GetDeviceName();
vendor = "Cooler Master";
type = DEVICE_TYPE_MOUSE;
description = controller->GetDeviceName();
serial = controller->GetSerial();
location = controller->GetLocation();
mode Custom;
Custom.name = "Direct";
Custom.value = CM_MM711_MODE_CUSTOM;
Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Custom.brightness_min = CM_MM_ARGB_BRIGHTNESS_MIN;
Custom.brightness_max = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Custom.brightness = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Custom.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Custom);
mode Static;
Static.name = "Static";
Static.value = CM_MM711_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Static.brightness_min = CM_MM_ARGB_BRIGHTNESS_MIN;
Static.brightness_max = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Static.brightness = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Static.colors_min = 1;
Static.colors_max = 1;
Static.colors.resize(Static.colors_max);
Static.speed_min = CM_MM711_SPEED_SLOWEST;
Static.speed_max = CM_MM711_SPEED_FASTEST;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.speed = CM_MM711_SPEED_NORMAL;
modes.push_back(Static);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = CM_MM711_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Breathing.brightness_min = CM_MM_ARGB_BRIGHTNESS_MIN;
Breathing.brightness_max = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Breathing.brightness = CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT;
Breathing.colors_min = 1;
Breathing.colors_max = 1;
Breathing.colors.resize(Breathing.colors_max);
Breathing.speed_min = CM_MM711_SPEED_SLOWEST;
Breathing.speed_max = CM_MM711_SPEED_FASTEST;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.speed = CM_MM711_SPEED_NORMAL;
modes.push_back(Breathing);
mode Spectrum_Cycle;
Spectrum_Cycle.name = "Spectrum Cycle";
Spectrum_Cycle.value = CM_MM711_MODE_SPECTRUM_CYCLE;
Spectrum_Cycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Spectrum_Cycle.brightness_min = CM_MM_ARGB_BRIGHTNESS_MIN;
Spectrum_Cycle.brightness_max = CM_MM_ARGB_BRIGHTNESS_MAX_SPECTRUM;
Spectrum_Cycle.brightness = CM_MM_ARGB_BRIGHTNESS_MAX_SPECTRUM;
Spectrum_Cycle.speed_min = CM_MM711_SPEED_SLOWEST;
Spectrum_Cycle.speed_max = CM_MM711_SPEED_FASTEST;
Spectrum_Cycle.color_mode = MODE_COLORS_NONE;
Spectrum_Cycle.speed = CM_MM711_SPEED_NORMAL;
modes.push_back(Spectrum_Cycle);
mode Indicator;
Indicator.name = "Indicator";
Indicator.value = CM_MM711_MODE_INDICATOR;
Indicator.flags = MODE_FLAG_MANUAL_SAVE;
Indicator.color_mode = MODE_COLORS_NONE;
modes.push_back(Indicator);
mode Off;
Off.name = "Turn Off";
Off.value = CM_MM711_MODE_OFF;
Off.flags = MODE_FLAG_MANUAL_SAVE;
Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off);
Init_Controller(); //Only processed on first run
SetupZones();
uint8_t temp_mode = controller->GetMode();
for(int mode_index = 0; mode_index < (int)modes.size(); mode_index++)
{
if(modes[mode_index].value == temp_mode)
{
active_mode = mode_index;
break;
}
}
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
modes[active_mode].colors[0] = ToRGBColor(controller->GetLedRed(),controller->GetLedGreen(),controller->GetLedBlue());
}
colors[0] = controller->GetWheelColour();
colors[1] = controller->GetLogoColour();
}
RGBController_CMMM711Controller::~RGBController_CMMM711Controller()
{
delete controller;
}
void RGBController_CMMM711Controller::Init_Controller()
{
zone mouse_zone;
mouse_zone.name = name;
mouse_zone.type = ZONE_TYPE_LINEAR;
mouse_zone.leds_min = 2;
mouse_zone.leds_max = 2;
mouse_zone.leds_count = 2;
mouse_zone.matrix_map = NULL;
zones.push_back(mouse_zone);
led wheel_led;
wheel_led.name = "Scroll Wheel LED";
wheel_led.value = 0;
leds.push_back(wheel_led);
led logo_led;
logo_led.name = "Logo LED";
logo_led.value = 1;
leds.push_back(logo_led);
}
void RGBController_CMMM711Controller::SetupZones()
{
SetupColors();
}
void RGBController_CMMM711Controller::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_CMMM711Controller::DeviceUpdateLEDs()
{
RGBColor wheel = applyBrightness(colors[0], modes[active_mode].brightness);
RGBColor logo = applyBrightness(colors[1], modes[active_mode].brightness);
controller->SetLedsDirect( wheel, logo);
}
void RGBController_CMMM711Controller::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_CMMM711Controller::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_CMMM711Controller::SetCustomMode()
{
for(int mode_index = 0; mode_index < (int)modes.size(); mode_index++)
{
if(modes[mode_index].value == CM_MM711_MODE_CUSTOM)
{
active_mode = mode_index;
break;
}
}
}
void RGBController_CMMM711Controller::DeviceUpdateMode()
{
RGBColor colour = 0;
if(modes[active_mode].value != CM_MM711_MODE_CUSTOM)
{
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC )
{
colour = modes[active_mode].colors[0];
}
controller->SendUpdate(modes[active_mode].value, modes[active_mode].speed, colour, modes[active_mode].brightness);
}
}
void RGBController_CMMM711Controller::DeviceSaveMode()
{
DeviceUpdateMode();
controller->SendSavePacket();
}

View File

@@ -0,0 +1,40 @@
/*-------------------------------------------------------------------*\
| RGBController_CMMM711Controller.h |
| |
| Driver for Coolermaster MM711 Controller |
| |
| Chris M (Dr_No) 14th Feb 2021 |
| |
\*-------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CMMM711Controller.h"
#include <vector>
#define CM_MM_ARGB_BRIGHTNESS_MIN 0x00
#define CM_MM_ARGB_BRIGHTNESS_MAX_DEFAULT 0xFF
#define CM_MM_ARGB_BRIGHTNESS_MAX_SPECTRUM 0x7F
class RGBController_CMMM711Controller : public RGBController
{
public:
RGBController_CMMM711Controller(CMMM711Controller* controller_ptr);
~RGBController_CMMM711Controller();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
void DeviceSaveMode();
private:
void Init_Controller();
int GetDeviceMode();
CMMM711Controller* controller;
};