Code Cleanup for Coolermaster MP750

This commit is contained in:
Chris 2020-11-12 00:42:06 +11:00 committed by Adam Honse
parent dd36a7362a
commit b495c7723f
4 changed files with 27 additions and 42 deletions

View file

@ -27,20 +27,25 @@ static unsigned char speed_mode_data[][9] =
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 } /* Colour Breath */
};
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path)
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, char *_path)
{
std::size_t tmp_size = wcslen(_vendor);
dev = dev_handle;
location = _path;
dev = dev_handle;
location = _path;
for(std::size_t i = 0; (i < tmp_size) && (i < CM_DEVICE_NAME_SIZE); i++)
{
device_name[i] = (char)_vendor[i];
}
for(std::size_t j = 0; (j < wcslen(_vendor)) && (tmp_size + j < CM_DEVICE_NAME_SIZE); j++)
{
device_name[tmp_size + j] = (char)_device_name[j];
}
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
}
@ -82,12 +87,12 @@ void CMMP750Controller::GetStatus()
}
}
char* CMMP750Controller::GetDeviceName()
std::string CMMP750Controller::GetDeviceName()
{
return device_name;
}
char* CMMP750Controller::GetSerial()
std::string CMMP750Controller::GetSerial()
{
return serial;
}

View file

@ -60,11 +60,11 @@ enum
class CMMP750Controller
{
public:
CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path);
CMMP750Controller(hid_device* dev_handle, char *_path);
~CMMP750Controller();
char* GetDeviceName();
char* GetSerial();
std::string GetDeviceName();
std::string GetSerial();
std::string GetLocation();
unsigned char GetMode();
@ -76,8 +76,8 @@ public:
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
private:
char device_name[32];
char serial[32];
std::string device_name;
std::string serial;
std::string location;
hid_device* dev;

View file

@ -74,7 +74,7 @@ void DetectCoolerMasterControllers(std::vector<RGBController*>& rgb_controllers)
{
if (dev_type == DEVICE_TYPE_MOUSEMAT)
{
CMMP750Controller* controller = new CMMP750Controller(dev, info->manufacturer_string, info->product_string, info->path);
CMMP750Controller* controller = new CMMP750Controller(dev, info->path);
RGBController_CMMP750Controller* rgb_controller = new RGBController_CMMP750Controller(controller);
rgb_controllers.push_back(rgb_controller);
}

View file

@ -18,7 +18,7 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
type = DEVICE_TYPE_MOUSEMAT;
description = cmmp750->GetDeviceName();
version = "1.0";
serial = "";
serial = cmmp750->GetSerial();
location = cmmp750->GetLocation();
mode Static;
@ -143,25 +143,5 @@ void RGBController_CMMP750Controller::SetCustomMode()
void RGBController_CMMP750Controller::DeviceUpdateMode()
{
switch(modes[active_mode].value)
{
case MP750_MODE_STATIC:
cmmp750->SetMode(MP750_MODE_STATIC, modes[active_mode].speed);
break;
case MP750_MODE_BLINK:
cmmp750->SetMode(MP750_MODE_BLINK, modes[active_mode].speed);
break;
case MP750_MODE_BREATHING:
cmmp750->SetMode(MP750_MODE_BREATHING, modes[active_mode].speed);
break;
case MP750_MODE_COLOR_CYCLE:
cmmp750->SetMode(MP750_MODE_COLOR_CYCLE, modes[active_mode].speed);
break;
case MP750_MODE_BREATH_CYCLE:
cmmp750->SetMode(MP750_MODE_BREATH_CYCLE, modes[active_mode].speed);
break;
default:
cmmp750->SetMode(MP750_MODE_BREATHING, modes[active_mode].speed);
break;
}
cmmp750->SetMode(modes[active_mode].value, modes[active_mode].speed);
}