Added brightness to profile loading and saving

* Bumped profile version to 3
* Loading a v1/v2 profile onto a device with brightness will work
* Loading a v3 profile onto a device without brightness also works
* Add profile version parameter to Get/SetModeDescription

Commit amended for code style and to update versioning by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
Chris 2021-02-10 16:40:39 +11:00 committed by Adam Honse
parent 6fd2ea9276
commit a46eccef3c
6 changed files with 130 additions and 20 deletions

View file

@ -14,8 +14,9 @@
| 0: Initial (unversioned) protocol | | 0: Initial (unversioned) protocol |
| 1: Add versioning, vendor string (Release 0.5) | | 1: Add versioning, vendor string (Release 0.5) |
| 2: Add profile controls (Release 0.6) | | 2: Add profile controls (Release 0.6) |
| 3: Add brightness field to modes (Release 0.7) |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
#define OPENRGB_SDK_PROTOCOL_VERSION 2 #define OPENRGB_SDK_PROTOCOL_VERSION 3
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Default OpenRGB SDK port is 6742 | | Default OpenRGB SDK port is 6742 |

View file

@ -685,7 +685,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
if(header.pkt_dev_idx < controllers.size()) if(header.pkt_dev_idx < controllers.size())
{ {
controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data); controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data, client_info->client_protocol_version);
controllers[header.pkt_dev_idx]->UpdateMode(); controllers[header.pkt_dev_idx]->UpdateMode();
} }
break; break;

View file

@ -273,17 +273,20 @@ bool ProfileManager::LoadDeviceFromListWithOptions
{ {
for(std::size_t mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++) for(std::size_t mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++)
{ {
if((temp_controller->modes[mode_index].name == load_controller->modes[mode_index].name ) if((temp_controller->modes[mode_index].name == load_controller->modes[mode_index].name )
&&(temp_controller->modes[mode_index].value == load_controller->modes[mode_index].value ) &&(temp_controller->modes[mode_index].value == load_controller->modes[mode_index].value )
&&(temp_controller->modes[mode_index].flags == load_controller->modes[mode_index].flags ) &&(temp_controller->modes[mode_index].flags == load_controller->modes[mode_index].flags )
&&(temp_controller->modes[mode_index].speed_min == load_controller->modes[mode_index].speed_min ) &&(temp_controller->modes[mode_index].speed_min == load_controller->modes[mode_index].speed_min )
&&(temp_controller->modes[mode_index].speed_max == load_controller->modes[mode_index].speed_max ) &&(temp_controller->modes[mode_index].speed_max == load_controller->modes[mode_index].speed_max )
&&(temp_controller->modes[mode_index].colors_min == load_controller->modes[mode_index].colors_min) //&&(temp_controller->modes[mode_index].brightness_min == load_controller->modes[mode_index].brightness_min)
&&(temp_controller->modes[mode_index].colors_max == load_controller->modes[mode_index].colors_max)) //&&(temp_controller->modes[mode_index].brightness_max == load_controller->modes[mode_index].brightness_max)
&&(temp_controller->modes[mode_index].colors_min == load_controller->modes[mode_index].colors_min )
&&(temp_controller->modes[mode_index].colors_max == load_controller->modes[mode_index].colors_max ))
{ {
load_controller->modes[mode_index].speed = temp_controller->modes[mode_index].speed; load_controller->modes[mode_index].speed = temp_controller->modes[mode_index].speed;
load_controller->modes[mode_index].direction = temp_controller->modes[mode_index].direction; load_controller->modes[mode_index].brightness = temp_controller->modes[mode_index].brightness;
load_controller->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode; load_controller->modes[mode_index].direction = temp_controller->modes[mode_index].direction;
load_controller->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode;
load_controller->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size()); load_controller->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size());

View file

@ -90,9 +90,18 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
data_size += sizeof(modes[mode_index].flags); data_size += sizeof(modes[mode_index].flags);
data_size += sizeof(modes[mode_index].speed_min); data_size += sizeof(modes[mode_index].speed_min);
data_size += sizeof(modes[mode_index].speed_max); data_size += sizeof(modes[mode_index].speed_max);
if(protocol_version >= 3)
{
data_size += sizeof(modes[mode_index].brightness_min);
data_size += sizeof(modes[mode_index].brightness_max);
}
data_size += sizeof(modes[mode_index].colors_min); data_size += sizeof(modes[mode_index].colors_min);
data_size += sizeof(modes[mode_index].colors_max); data_size += sizeof(modes[mode_index].colors_max);
data_size += sizeof(modes[mode_index].speed); data_size += sizeof(modes[mode_index].speed);
if(protocol_version >= 3)
{
data_size += sizeof(modes[mode_index].brightness);
}
data_size += sizeof(modes[mode_index].direction); data_size += sizeof(modes[mode_index].direction);
data_size += sizeof(modes[mode_index].color_mode); data_size += sizeof(modes[mode_index].color_mode);
data_size += sizeof(mode_num_colors[mode_index]); data_size += sizeof(mode_num_colors[mode_index]);
@ -262,6 +271,19 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
memcpy(&data_buf[data_ptr], &modes[mode_index].speed_max, sizeof(modes[mode_index].speed_max)); memcpy(&data_buf[data_ptr], &modes[mode_index].speed_max, sizeof(modes[mode_index].speed_max));
data_ptr += sizeof(modes[mode_index].speed_max); data_ptr += sizeof(modes[mode_index].speed_max);
/*---------------------------------------------------------*\
| Copy in mode brightness_min and brightness_max (data) if |
| protocol 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&data_buf[data_ptr], &modes[mode_index].brightness_min, sizeof(modes[mode_index].brightness_min));
data_ptr += sizeof(modes[mode_index].brightness_min);
memcpy(&data_buf[data_ptr], &modes[mode_index].brightness_max, sizeof(modes[mode_index].brightness_max));
data_ptr += sizeof(modes[mode_index].brightness_max);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode colors_min (data) | | Copy in mode colors_min (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -280,6 +302,15 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
memcpy(&data_buf[data_ptr], &modes[mode_index].speed, sizeof(modes[mode_index].speed)); memcpy(&data_buf[data_ptr], &modes[mode_index].speed, sizeof(modes[mode_index].speed));
data_ptr += sizeof(modes[mode_index].speed); data_ptr += sizeof(modes[mode_index].speed);
/*---------------------------------------------------------*\
| Copy in mode brightness (data) if protocol 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&data_buf[data_ptr], &modes[mode_index].brightness, sizeof(modes[mode_index].brightness));
data_ptr += sizeof(modes[mode_index].brightness);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode direction (data) | | Copy in mode direction (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -468,7 +499,7 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
data_ptr += name_len; data_ptr += name_len;
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in vendor if profile version is 1 or higher | | Copy in vendor if protocol version is 1 or higher |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
if(protocol_version >= 1) if(protocol_version >= 1)
{ {
@ -574,6 +605,19 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
memcpy(&new_mode.speed_max, &data_buf[data_ptr], sizeof(new_mode.speed_max)); memcpy(&new_mode.speed_max, &data_buf[data_ptr], sizeof(new_mode.speed_max));
data_ptr += sizeof(new_mode.speed_max); data_ptr += sizeof(new_mode.speed_max);
/*---------------------------------------------------------*\
| Copy in mode brightness min and max if protocol version |
| is 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&new_mode.brightness_min, &data_buf[data_ptr], sizeof(new_mode.brightness_min));
data_ptr += sizeof(new_mode.brightness_min);
memcpy(&new_mode.brightness_max, &data_buf[data_ptr], sizeof(new_mode.brightness_max));
data_ptr += sizeof(new_mode.brightness_max);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode colors_min (data) | | Copy in mode colors_min (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -592,6 +636,15 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
memcpy(&new_mode.speed, &data_buf[data_ptr], sizeof(new_mode.speed)); memcpy(&new_mode.speed, &data_buf[data_ptr], sizeof(new_mode.speed));
data_ptr += sizeof(new_mode.speed); data_ptr += sizeof(new_mode.speed);
/*---------------------------------------------------------*\
| Copy in mode brightness if protocol version is 3 or higher|
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&new_mode.brightness, &data_buf[data_ptr], sizeof(new_mode.brightness));
data_ptr += sizeof(new_mode.brightness);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode direction (data) | | Copy in mode direction (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -790,7 +843,7 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
SetupColors(); SetupColors();
} }
unsigned char * RGBController::GetModeDescription(int mode) unsigned char * RGBController::GetModeDescription(int mode, unsigned int protocol_version)
{ {
unsigned int data_ptr = 0; unsigned int data_ptr = 0;
unsigned int data_size = 0; unsigned int data_size = 0;
@ -812,9 +865,18 @@ unsigned char * RGBController::GetModeDescription(int mode)
data_size += sizeof(modes[mode].flags); data_size += sizeof(modes[mode].flags);
data_size += sizeof(modes[mode].speed_min); data_size += sizeof(modes[mode].speed_min);
data_size += sizeof(modes[mode].speed_max); data_size += sizeof(modes[mode].speed_max);
if(protocol_version >= 3)
{
data_size += sizeof(modes[mode].brightness_min);
data_size += sizeof(modes[mode].brightness_max);
}
data_size += sizeof(modes[mode].colors_min); data_size += sizeof(modes[mode].colors_min);
data_size += sizeof(modes[mode].colors_max); data_size += sizeof(modes[mode].colors_max);
data_size += sizeof(modes[mode].speed); data_size += sizeof(modes[mode].speed);
if(protocol_version >= 3)
{
data_size += sizeof(modes[mode].brightness);
}
data_size += sizeof(modes[mode].direction); data_size += sizeof(modes[mode].direction);
data_size += sizeof(modes[mode].color_mode); data_size += sizeof(modes[mode].color_mode);
data_size += sizeof(mode_num_colors); data_size += sizeof(mode_num_colors);
@ -870,6 +932,19 @@ unsigned char * RGBController::GetModeDescription(int mode)
memcpy(&data_buf[data_ptr], &modes[mode].speed_max, sizeof(modes[mode].speed_max)); memcpy(&data_buf[data_ptr], &modes[mode].speed_max, sizeof(modes[mode].speed_max));
data_ptr += sizeof(modes[mode].speed_max); data_ptr += sizeof(modes[mode].speed_max);
/*---------------------------------------------------------*\
| Copy in mode brightness min and max if protocol version |
| is 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&data_buf[data_ptr], &modes[mode].brightness_min, sizeof(modes[mode].brightness_min));
data_ptr += sizeof(modes[mode].brightness_min);
memcpy(&data_buf[data_ptr], &modes[mode].brightness_max, sizeof(modes[mode].brightness_max));
data_ptr += sizeof(modes[mode].brightness_max);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode colors_min (data) | | Copy in mode colors_min (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -888,6 +963,15 @@ unsigned char * RGBController::GetModeDescription(int mode)
memcpy(&data_buf[data_ptr], &modes[mode].speed, sizeof(modes[mode].speed)); memcpy(&data_buf[data_ptr], &modes[mode].speed, sizeof(modes[mode].speed));
data_ptr += sizeof(modes[mode].speed); data_ptr += sizeof(modes[mode].speed);
/*---------------------------------------------------------*\
| Copy in mode brightness if protocol version is 3 or higher|
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&data_buf[data_ptr], &modes[mode].brightness, sizeof(modes[mode].brightness));
data_ptr += sizeof(modes[mode].brightness);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode direction (data) | | Copy in mode direction (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -921,7 +1005,7 @@ unsigned char * RGBController::GetModeDescription(int mode)
return(data_buf); return(data_buf);
} }
void RGBController::SetModeDescription(unsigned char* data_buf) void RGBController::SetModeDescription(unsigned char* data_buf, unsigned int protocol_version)
{ {
int mode_idx; int mode_idx;
unsigned int data_ptr = sizeof(unsigned int); unsigned int data_ptr = sizeof(unsigned int);
@ -984,6 +1068,19 @@ void RGBController::SetModeDescription(unsigned char* data_buf)
memcpy(&new_mode->speed_max, &data_buf[data_ptr], sizeof(new_mode->speed_max)); memcpy(&new_mode->speed_max, &data_buf[data_ptr], sizeof(new_mode->speed_max));
data_ptr += sizeof(new_mode->speed_max); data_ptr += sizeof(new_mode->speed_max);
/*---------------------------------------------------------*\
| Copy in mode brightness_min and brightness_max (data) if |
| protocol 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&new_mode->brightness_min, &data_buf[data_ptr], sizeof(new_mode->brightness_min));
data_ptr += sizeof(new_mode->brightness_min);
memcpy(&new_mode->brightness_max, &data_buf[data_ptr], sizeof(new_mode->brightness_max));
data_ptr += sizeof(new_mode->brightness_max);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode colors_min (data) | | Copy in mode colors_min (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -1002,6 +1099,15 @@ void RGBController::SetModeDescription(unsigned char* data_buf)
memcpy(&new_mode->speed, &data_buf[data_ptr], sizeof(new_mode->speed)); memcpy(&new_mode->speed, &data_buf[data_ptr], sizeof(new_mode->speed));
data_ptr += sizeof(new_mode->speed); data_ptr += sizeof(new_mode->speed);
/*---------------------------------------------------------*\
| Copy in mode brightness (data) if protocol 3 or higher |
\*---------------------------------------------------------*/
if(protocol_version >= 3)
{
memcpy(&new_mode->brightness, &data_buf[data_ptr], sizeof(new_mode->brightness));
data_ptr += sizeof(new_mode->brightness);
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Copy in mode direction (data) | | Copy in mode direction (data) |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/

View file

@ -172,8 +172,8 @@ public:
virtual unsigned char * GetDeviceDescription(unsigned int protocol_version) = 0; virtual unsigned char * GetDeviceDescription(unsigned int protocol_version) = 0;
virtual void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version) = 0; virtual void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version) = 0;
virtual unsigned char * GetModeDescription(int mode) = 0; virtual unsigned char * GetModeDescription(int mode, unsigned int protocol_version) = 0;
virtual void SetModeDescription(unsigned char* data_buf) = 0; virtual void SetModeDescription(unsigned char* data_buf, unsigned int protocol_version) = 0;
virtual unsigned char * GetColorDescription() = 0; virtual unsigned char * GetColorDescription() = 0;
virtual void SetColorDescription(unsigned char* data_buf) = 0; virtual void SetColorDescription(unsigned char* data_buf) = 0;
@ -251,8 +251,8 @@ public:
unsigned char * GetDeviceDescription(unsigned int protocol_version); unsigned char * GetDeviceDescription(unsigned int protocol_version);
void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version); void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version);
unsigned char * GetModeDescription(int mode); unsigned char * GetModeDescription(int mode, unsigned int protocol_version);
void SetModeDescription(unsigned char* data_buf); void SetModeDescription(unsigned char* data_buf, unsigned int protocol_version);
unsigned char * GetColorDescription(); unsigned char * GetColorDescription();
void SetColorDescription(unsigned char* data_buf); void SetColorDescription(unsigned char* data_buf);

View file

@ -69,7 +69,7 @@ void RGBController_Network::SetCustomMode()
void RGBController_Network::DeviceUpdateMode() void RGBController_Network::DeviceUpdateMode()
{ {
unsigned char * data = GetModeDescription(active_mode); unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion());
unsigned int size; unsigned int size;
memcpy(&size, &data[0], sizeof(unsigned int)); memcpy(&size, &data[0], sizeof(unsigned int));