diff --git a/NetworkClient.cpp b/NetworkClient.cpp index 52389aac..9ea9a3b3 100644 --- a/NetworkClient.cpp +++ b/NetworkClient.cpp @@ -593,6 +593,12 @@ void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * d new_controller->ReadDeviceDescription((unsigned char *)data, GetProtocolVersion()); + /*-----------------------------------------------------*\ + | Mark this controller as remote owned | + \*-----------------------------------------------------*/ + new_controller->flags &= ~CONTROLLER_FLAG_LOCAL; + new_controller->flags |= CONTROLLER_FLAG_REMOTE; + ControllerListMutex.lock(); if(dev_idx >= server_controllers.size()) diff --git a/NetworkProtocol.h b/NetworkProtocol.h index 05fe1bb1..b8973954 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -19,7 +19,8 @@ | 2: Add profile controls (Release 0.6) | | 3: Add brightness field to modes (Release 0.7) | | 4: Add segments field to zones, network plugins (Release 0.9) | -| 5: Zone flags, resizable effects-only zones (Release 1.0) | +| 5: Zone flags, controller flags, resizable effects-only zones | + (Release 1.0) | \*---------------------------------------------------------------------*/ #define OPENRGB_SDK_PROTOCOL_VERSION 5 diff --git a/RGBController/RGBController.cpp b/RGBController/RGBController.cpp index 84d653d3..a67fa86f 100644 --- a/RGBController/RGBController.cpp +++ b/RGBController/RGBController.cpp @@ -58,6 +58,7 @@ zone::~zone() RGBController::RGBController() { + flags = 0; DeviceThreadRunning = true; DeviceCallThread = new std::thread(&RGBController::DeviceCallThreadFunction, this); } @@ -288,6 +289,14 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio } } + /*---------------------------------------------------------*\ + | Controller flags | + \*---------------------------------------------------------*/ + if(protocol_version >= 5) + { + data_size += sizeof(flags); + } + data_size += sizeof(num_colors); data_size += num_colors * sizeof(RGBColor); @@ -731,6 +740,15 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio } } + /*---------------------------------------------------------*\ + | Controller flags data | + \*---------------------------------------------------------*/ + if(protocol_version >= 5) + { + memcpy(&data_buf[data_ptr], &flags, sizeof(flags)); + data_ptr += sizeof(flags); + } + delete[] mode_name_len; delete[] zone_name_len; delete[] led_name_len; @@ -1188,6 +1206,15 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int } } + /*---------------------------------------------------------*\ + | Copy in controller flags data | + \*---------------------------------------------------------*/ + if(protocol_version >= 5) + { + memcpy(&flags, &data_buf[data_ptr], sizeof(flags)); + data_ptr += sizeof(flags); + } + /*---------------------------------------------------------*\ | Setup colors | \*---------------------------------------------------------*/ @@ -2090,13 +2117,29 @@ void RGBController::DeviceCallThreadFunction() { if(CallFlag_UpdateMode.load() == true) { - DeviceUpdateMode(); - CallFlag_UpdateMode = false; + if(flags & CONTROLLER_FLAG_RESET_BEFORE_UPDATE) + { + CallFlag_UpdateMode = false; + DeviceUpdateMode(); + } + else + { + DeviceUpdateMode(); + CallFlag_UpdateMode = false; + } } if(CallFlag_UpdateLEDs.load() == true) { - DeviceUpdateLEDs(); - CallFlag_UpdateLEDs = false; + if(flags & CONTROLLER_FLAG_RESET_BEFORE_UPDATE) + { + CallFlag_UpdateLEDs = false; + DeviceUpdateLEDs(); + } + else + { + DeviceUpdateLEDs(); + CallFlag_UpdateLEDs = false; + } } else { diff --git a/RGBController/RGBController.h b/RGBController/RGBController.h index b016b561..939f77c3 100644 --- a/RGBController/RGBController.h +++ b/RGBController/RGBController.h @@ -215,6 +215,19 @@ enum DEVICE_TYPE_UNKNOWN, }; +/*------------------------------------------------------------------*\ +| Controller Flags | +\*------------------------------------------------------------------*/ +enum +{ + CONTROLLER_FLAG_LOCAL = (1 << 0), /* Device is local to this instance */ + CONTROLLER_FLAG_REMOTE = (1 << 1), /* Device is on a remote instance */ + CONTROLLER_FLAG_VIRTUAL = (1 << 2), /* Device is a virtual device */ + + CONTROLLER_FLAG_RESET_BEFORE_UPDATE = (1 << 8), /* Device resets update flag before */ + /* calling update function */ +}; + /*------------------------------------------------------------------*\ | RGBController Callback Types | \*------------------------------------------------------------------*/ @@ -313,6 +326,7 @@ public: int active_mode = 0;/* active mode */ std::vector led_alt_names; /* alternate LED names */ + unsigned int flags; /* controller flags */ /*---------------------------------------------------------*\ | RGBController base class constructor | diff --git a/ResourceManager.cpp b/ResourceManager.cpp index b76e825b..d06c4739 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -255,6 +255,12 @@ std::vector & ResourceManager::GetI2CBusses() void ResourceManager::RegisterRGBController(RGBController *rgb_controller) { + /*-------------------------------------------------*\ + | Mark this controller as locally owned | + \*-------------------------------------------------*/ + rgb_controller->flags &= ~CONTROLLER_FLAG_REMOTE; + rgb_controller->flags |= CONTROLLER_FLAG_LOCAL; + LOG_INFO("[%s] Registering RGB controller", rgb_controller->name.c_str()); rgb_controllers_hw.push_back(rgb_controller);