diff --git a/RGBController/RGBController_HyperXAlloyOrigins.cpp b/RGBController/RGBController_HyperXAlloyOrigins.cpp index 2a07d863..2b1ed140 100644 --- a/RGBController/RGBController_HyperXAlloyOrigins.cpp +++ b/RGBController/RGBController_HyperXAlloyOrigins.cpp @@ -9,6 +9,32 @@ #include "RGBController_HyperXAlloyOrigins.h" +//Include thread libraries for Windows or Linux +#ifdef WIN32 +#include +#else +#include "pthread.h" +#include "unistd.h" +#endif + +//Thread functions have different types in Windows and Linux +#ifdef WIN32 +#define THREAD static void +#define THREADRETURN +#else +#define THREAD static void* +#define THREADRETURN return(NULL); +#endif + +using namespace std::chrono_literals; + +THREAD keepalive_thread(void *param) +{ + RGBController_HyperXAlloyOrigins* controller = static_cast(param); + controller->KeepaliveThread(); + THREADRETURN +} + //0xFFFFFFFF indicates an unused entry in matrix #define NA 0xFFFFFFFF @@ -36,6 +62,19 @@ RGBController_HyperXAlloyOrigins::RGBController_HyperXAlloyOrigins(HyperXAlloyOr modes.push_back(Custom); SetupZones(); + + /*-----------------------------------------------------*\ + | The Corsair Lighting Node Pro requires a packet within| + | 20 seconds of sending the lighting change in order | + | to not revert back into rainbow mode. Start a thread | + | to continuously send a keepalive packet every 5s | + \*-----------------------------------------------------*/ +#ifdef WIN32 + _beginthread(keepalive_thread, 0, this); +#else + pthread_t thread; + pthread_create(&thread, NULL, &keepalive_thread, this); +#endif } RGBController_HyperXAlloyOrigins::~RGBController_HyperXAlloyOrigins() @@ -100,4 +139,19 @@ void RGBController_HyperXAlloyOrigins::SetCustomMode() void RGBController_HyperXAlloyOrigins::UpdateMode() { +} + +void RGBController_HyperXAlloyOrigins::KeepaliveThread() +{ + while(1) + { + if(active_mode == 0) + { + if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50)) + { + UpdateLEDs(); + } + } + std::this_thread::sleep_for(10ms);; + } } \ No newline at end of file diff --git a/RGBController/RGBController_HyperXAlloyOrigins.h b/RGBController/RGBController_HyperXAlloyOrigins.h index aeec678a..debb1a3a 100644 --- a/RGBController/RGBController_HyperXAlloyOrigins.h +++ b/RGBController/RGBController_HyperXAlloyOrigins.h @@ -8,6 +8,7 @@ \*-----------------------------------------*/ #pragma once +#include #include "RGBController.h" #include "HyperXAlloyOriginsController.h" @@ -29,6 +30,10 @@ public: void SetCustomMode(); void UpdateMode(); + void KeepaliveThread(); + private: HyperXAlloyOriginsController* hyperx; + + std::chrono::time_point last_update_time; };