Coolermaster MP750 now supports on load status from device
Previous issues with hidapi-hidraw vs hidapi-libusb have been resolved. CMMP750Controller.cpp now calls GetStatus in the constructor to query device and set current state. Added "Getters" to the public interface to allow the RGBController_CMMP750Controller.cpp to access current state in construction.
This commit is contained in:
parent
ac2d911566
commit
ffc02e6c98
5 changed files with 93 additions and 19 deletions
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path)
|
||||
{
|
||||
int tmp_size = wcslen(_vendor);
|
||||
|
||||
dev = dev_handle;
|
||||
int tmp_size = wcslen(_vendor);
|
||||
dev = dev_handle;
|
||||
location = _path;
|
||||
|
||||
for (int i=0; ( i<tmp_size && i<CM_DEVICE_NAME_SIZE); i++)
|
||||
{
|
||||
|
|
@ -22,10 +22,7 @@ CMMP750Controller::CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, w
|
|||
for (int j=0; ( j<wcslen(_vendor) && tmp_size+j<CM_DEVICE_NAME_SIZE); j++)
|
||||
device_name[tmp_size+j] = (char)_device_name[j];
|
||||
|
||||
location = _path;
|
||||
|
||||
current_mode = MP750_MODE_STATIC;
|
||||
current_speed = MP750_SPEED_NORMAL;
|
||||
GetStatus(); //When setting up device get current status
|
||||
}
|
||||
|
||||
CMMP750Controller::~CMMP750Controller()
|
||||
|
|
@ -33,6 +30,36 @@ CMMP750Controller::~CMMP750Controller()
|
|||
hid_close(dev);
|
||||
}
|
||||
|
||||
void CMMP750Controller::GetStatus()
|
||||
{
|
||||
unsigned char buffer[0x40] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
buffer[0] = 0x07;
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read(dev, buffer, buffer_size);
|
||||
|
||||
if( buffer[0] == 0x80 && buffer[1] == 0x05 )
|
||||
{
|
||||
current_mode = buffer[2] - 1;
|
||||
current_red = buffer[3];
|
||||
current_green = buffer[4];
|
||||
current_blue = buffer[5];
|
||||
|
||||
for( int i = 0; speed_mode_data[current_mode][i] >= buffer[6]; i++)
|
||||
current_speed = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Code should never reach here however just in case there is a failure set something
|
||||
current_mode = MP750_MODE_COLOR_CYCLE; //Unicorn Spew
|
||||
current_red = 0xFF;
|
||||
current_green = 0xFF;
|
||||
current_blue = 0xFF;
|
||||
current_speed = MP750_SPEED_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
char* CMMP750Controller::GetDeviceName()
|
||||
{
|
||||
return device_name;
|
||||
|
|
@ -48,6 +75,31 @@ std::string CMMP750Controller::GetLocation()
|
|||
return 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;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,11 @@ public:
|
|||
char* 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);
|
||||
|
||||
|
|
@ -101,5 +106,6 @@ private:
|
|||
unsigned char current_green;
|
||||
unsigned char current_blue;
|
||||
|
||||
void GetStatus();
|
||||
void SendUpdate();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ void DetectCoolerMasterControllers(std::vector<RGBController*>& rgb_controllers)
|
|||
|
||||
if(dev)
|
||||
{
|
||||
CMMP750Controller* controller = new CMMP750Controller(dev, info->manufacturer_string, info->product_string, info->path);
|
||||
CMMP750Controller* controller = new CMMP750Controller(dev, info->manufacturer_string, info->product_string, info->path);
|
||||
RGBController_CMMP750Controller* rgb_controller = new RGBController_CMMP750Controller(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,15 @@
|
|||
|
||||
RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controller* cmmp_ptr)
|
||||
{
|
||||
cmmp750 = cmmp_ptr;
|
||||
cmmp750 = cmmp_ptr;
|
||||
unsigned char speed = cmmp750->GetLedSpeed();
|
||||
|
||||
name = cmmp750->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOUSEMAT;
|
||||
description = cmmp750->GetDeviceName();
|
||||
version = "1.0";
|
||||
serial = "";
|
||||
location = cmmp750->GetLocation();
|
||||
name = cmmp750->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOUSEMAT;
|
||||
description = cmmp750->GetDeviceName();
|
||||
version = "1.0";
|
||||
serial = "";
|
||||
location = cmmp750->GetLocation();
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
|
|
@ -34,7 +35,7 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
|
|||
Blink.speed_min = MP750_SPEED_SLOWEST;
|
||||
Blink.speed_max = MP750_SPEED_FASTEST;
|
||||
Blink.color_mode = MODE_COLORS_PER_LED;
|
||||
Blink.speed = MP750_SPEED_NORMAL;
|
||||
Blink.speed = speed;
|
||||
modes.push_back(Blink);
|
||||
|
||||
mode Breathing;
|
||||
|
|
@ -44,7 +45,7 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
|
|||
Breathing.speed_min = MP750_SPEED_SLOWEST;
|
||||
Breathing.speed_max = MP750_SPEED_FASTEST;
|
||||
Breathing.color_mode = MODE_COLORS_PER_LED;
|
||||
Breathing.speed = MP750_SPEED_NORMAL;
|
||||
Breathing.speed = speed;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode ColorCycle;
|
||||
|
|
@ -54,7 +55,7 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
|
|||
ColorCycle.speed_min = MP750_SPEED_SLOWEST;
|
||||
ColorCycle.speed_max = MP750_SPEED_FASTEST;
|
||||
ColorCycle.color_mode = MODE_COLORS_NONE;
|
||||
ColorCycle.speed = MP750_SPEED_NORMAL;
|
||||
ColorCycle.speed = speed;
|
||||
modes.push_back(ColorCycle);
|
||||
|
||||
mode BreathCycle;
|
||||
|
|
@ -64,10 +65,11 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
|
|||
BreathCycle.speed_min = MP750_SPEED_SLOWEST;
|
||||
BreathCycle.speed_max = MP750_SPEED_FASTEST;
|
||||
BreathCycle.color_mode = MODE_COLORS_NONE;
|
||||
BreathCycle.speed = MP750_SPEED_NORMAL;
|
||||
BreathCycle.speed = speed;
|
||||
modes.push_back(BreathCycle);
|
||||
|
||||
SetupZones();
|
||||
active_mode = cmmp750->GetMode();
|
||||
}
|
||||
|
||||
RGBController_CMMP750Controller::~RGBController_CMMP750Controller()
|
||||
|
|
@ -91,6 +93,18 @@ void RGBController_CMMP750Controller::SetupZones()
|
|||
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 = cmmp750->GetLedRed();
|
||||
unsigned char grn = cmmp750->GetLedGreen();
|
||||
unsigned char blu = cmmp750->GetLedBlue();
|
||||
|
||||
colors[led_idx] = ToRGBColor(red, grn, blu);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_CMMP750Controller::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
|
|
|
|||
|
|
@ -28,4 +28,6 @@ public:
|
|||
void UpdateMode();
|
||||
private:
|
||||
CMMP750Controller* cmmp750;
|
||||
|
||||
int GetDeviceMode();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue