Corrected Logical errors in ResourceManager.cpp

* Removed comparison of -1 to unsigned int
* Corrected comparison of current_device to HID_INTERFACE_ANY
* Exposed downstream errors in Windows implementation of CM_MP750
controller corrected
* Added "Off" mode
This commit is contained in:
Chris 2021-01-01 22:32:04 +11:00 committed by Adam Honse
parent 14834e1e28
commit 215baa487a
5 changed files with 57 additions and 56 deletions

View file

@ -11,20 +11,17 @@
static unsigned char colour_mode_data[][6] =
{
{ 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 */
{ 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] =
static unsigned char speed_mode_data[9] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },/* Static */
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Blinking */
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Breathing */
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Colour Cycle */
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 } /* Colour Breath */
0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 /* Speed Definition */
};
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, char *_path)
@ -57,9 +54,9 @@ CMMP750Controller::~CMMP750Controller()
void CMMP750Controller::GetStatus()
{
unsigned char buffer[0x40] = { 0x00 };
unsigned char buffer[0x41] = { 0x00 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
buffer[0] = 0x07;
buffer[1] = 0x07;
hid_write(dev, buffer, buffer_size);
hid_read(dev, buffer, buffer_size);
@ -71,7 +68,7 @@ void CMMP750Controller::GetStatus()
current_green = buffer[4];
current_blue = buffer[5];
for(int i = 0; speed_mode_data[current_mode][i] >= buffer[6]; i++)
for(int i = 0; (speed_mode_data[i] >= buffer[6] && i <= MP750_SPEED_FASTEST); i++)
{
current_speed = i;
}
@ -79,7 +76,7 @@ void CMMP750Controller::GetStatus()
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_mode = CM_MP750_MODE_COLOR_CYCLE; //Unicorn Spew
current_red = 0xFF;
current_green = 0xFF;
current_blue = 0xFF;
@ -146,18 +143,18 @@ void CMMP750Controller::SetColor(unsigned char red, unsigned char green, unsigne
void CMMP750Controller::SendUpdate()
{
unsigned char buffer[0x40] = { 0x00 };
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] = colour_mode_data[current_mode][i];
buffer[i+1] = colour_mode_data[current_mode][i];
}
if(current_mode > MP750_MODE_BREATHING)
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_mode][current_speed];
buffer[CM_RED_BYTE] = speed_mode_data[current_speed];
}
else
{
@ -165,7 +162,7 @@ void CMMP750Controller::SendUpdate()
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_mode][current_speed];
buffer[CM_SPEED_BYTE] = speed_mode_data[current_speed];
}
hid_write(dev, buffer, buffer_size);