Skip to content

Commit bb79fbf

Browse files
Add controller flags field with flags for controller location and update behavior
1 parent 1967ec9 commit bb79fbf

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

NetworkClient.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * d
593593

594594
new_controller->ReadDeviceDescription((unsigned char *)data, GetProtocolVersion());
595595

596+
/*-----------------------------------------------------*\
597+
| Mark this controller as remote owned |
598+
\*-----------------------------------------------------*/
599+
new_controller->flags &= ~CONTROLLER_FLAG_LOCAL;
600+
new_controller->flags |= CONTROLLER_FLAG_REMOTE;
601+
596602
ControllerListMutex.lock();
597603

598604
if(dev_idx >= server_controllers.size())

NetworkProtocol.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
| 2: Add profile controls (Release 0.6) |
2020
| 3: Add brightness field to modes (Release 0.7) |
2121
| 4: Add segments field to zones, network plugins (Release 0.9) |
22-
| 5: Zone flags, resizable effects-only zones (Release 1.0) |
22+
| 5: Zone flags, controller flags, resizable effects-only zones |
23+
(Release 1.0) |
2324
\*---------------------------------------------------------------------*/
2425
#define OPENRGB_SDK_PROTOCOL_VERSION 5
2526

RGBController/RGBController.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ zone::~zone()
5858

5959
RGBController::RGBController()
6060
{
61+
flags = 0;
6162
DeviceThreadRunning = true;
6263
DeviceCallThread = new std::thread(&RGBController::DeviceCallThreadFunction, this);
6364
}
@@ -288,6 +289,14 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
288289
}
289290
}
290291

292+
/*---------------------------------------------------------*\
293+
| Controller flags |
294+
\*---------------------------------------------------------*/
295+
if(protocol_version >= 5)
296+
{
297+
data_size += sizeof(flags);
298+
}
299+
291300
data_size += sizeof(num_colors);
292301
data_size += num_colors * sizeof(RGBColor);
293302

@@ -731,6 +740,15 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
731740
}
732741
}
733742

743+
/*---------------------------------------------------------*\
744+
| Controller flags data |
745+
\*---------------------------------------------------------*/
746+
if(protocol_version >= 5)
747+
{
748+
memcpy(&data_buf[data_ptr], &flags, sizeof(flags));
749+
data_ptr += sizeof(flags);
750+
}
751+
734752
delete[] mode_name_len;
735753
delete[] zone_name_len;
736754
delete[] led_name_len;
@@ -1188,6 +1206,15 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
11881206
}
11891207
}
11901208

1209+
/*---------------------------------------------------------*\
1210+
| Copy in controller flags data |
1211+
\*---------------------------------------------------------*/
1212+
if(protocol_version >= 5)
1213+
{
1214+
memcpy(&flags, &data_buf[data_ptr], sizeof(flags));
1215+
data_ptr += sizeof(flags);
1216+
}
1217+
11911218
/*---------------------------------------------------------*\
11921219
| Setup colors |
11931220
\*---------------------------------------------------------*/
@@ -2090,13 +2117,29 @@ void RGBController::DeviceCallThreadFunction()
20902117
{
20912118
if(CallFlag_UpdateMode.load() == true)
20922119
{
2093-
DeviceUpdateMode();
2094-
CallFlag_UpdateMode = false;
2120+
if(flags & CONTROLLER_FLAG_RESET_BEFORE_UPDATE)
2121+
{
2122+
CallFlag_UpdateMode = false;
2123+
DeviceUpdateMode();
2124+
}
2125+
else
2126+
{
2127+
DeviceUpdateMode();
2128+
CallFlag_UpdateMode = false;
2129+
}
20952130
}
20962131
if(CallFlag_UpdateLEDs.load() == true)
20972132
{
2098-
DeviceUpdateLEDs();
2099-
CallFlag_UpdateLEDs = false;
2133+
if(flags & CONTROLLER_FLAG_RESET_BEFORE_UPDATE)
2134+
{
2135+
CallFlag_UpdateLEDs = false;
2136+
DeviceUpdateLEDs();
2137+
}
2138+
else
2139+
{
2140+
DeviceUpdateLEDs();
2141+
CallFlag_UpdateLEDs = false;
2142+
}
21002143
}
21012144
else
21022145
{

RGBController/RGBController.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ enum
215215
DEVICE_TYPE_UNKNOWN,
216216
};
217217

218+
/*------------------------------------------------------------------*\
219+
| Controller Flags |
220+
\*------------------------------------------------------------------*/
221+
enum
222+
{
223+
CONTROLLER_FLAG_LOCAL = (1 << 0), /* Device is local to this instance */
224+
CONTROLLER_FLAG_REMOTE = (1 << 1), /* Device is on a remote instance */
225+
CONTROLLER_FLAG_VIRTUAL = (1 << 2), /* Device is a virtual device */
226+
227+
CONTROLLER_FLAG_RESET_BEFORE_UPDATE = (1 << 8), /* Device resets update flag before */
228+
/* calling update function */
229+
};
230+
218231
/*------------------------------------------------------------------*\
219232
| RGBController Callback Types |
220233
\*------------------------------------------------------------------*/
@@ -313,6 +326,7 @@ class RGBController : public RGBControllerInterface
313326
int active_mode = 0;/* active mode */
314327
std::vector<std::string>
315328
led_alt_names; /* alternate LED names */
329+
unsigned int flags; /* controller flags */
316330

317331
/*---------------------------------------------------------*\
318332
| RGBController base class constructor |

ResourceManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ std::vector<i2c_smbus_interface*> & ResourceManager::GetI2CBusses()
255255

256256
void ResourceManager::RegisterRGBController(RGBController *rgb_controller)
257257
{
258+
/*-------------------------------------------------*\
259+
| Mark this controller as locally owned |
260+
\*-------------------------------------------------*/
261+
rgb_controller->flags &= ~CONTROLLER_FLAG_REMOTE;
262+
rgb_controller->flags |= CONTROLLER_FLAG_LOCAL;
263+
258264
LOG_INFO("[%s] Registering RGB controller", rgb_controller->name.c_str());
259265
rgb_controllers_hw.push_back(rgb_controller);
260266

0 commit comments

Comments
 (0)