diff --git a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.cpp index 170ccc68c..5bd83c205 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.cpp @@ -39,13 +39,44 @@ void HyperXPulsefireSurgeController::SendWakeup() /*-----------------------------------------------------*\ | Set up Wakeup packet | \*-----------------------------------------------------*/ - buf[0x00] = 0x07; - buf[0x01] = 0x03; - buf[0x02] = 0x04; - buf[0x03] = 0x01; - buf[0x04] = 0x01; - buf[0x05] = 0x01; - buf[0x06] = 0x03; + buf[0x00] = 0x07; + buf[0x01] = 0x07; + buf[0x02] = 0x01; +// buf[0x00] = 0x07; +// buf[0x01] = 0x03; +// buf[0x02] = 0x04; +// buf[0x03] = 0x01; +// buf[0x04] = 0x01; +// buf[0x05] = 0x01; +// buf[0x06] = 0x03; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Wakeup packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = 0x03; + buf[0x02] = 0x01; + buf[0x03] = 0x01; + buf[0x04] = 0x01; + buf[0x05] = 0x01; + buf[0x06] = 0x64; +// buf[0x00] = 0x07; +// buf[0x01] = 0x03; +// buf[0x02] = 0x04; +// buf[0x03] = 0x01; +// buf[0x04] = 0x01; +// buf[0x05] = 0x01; +// buf[0x06] = 0x03; /*-----------------------------------------------------*\ | Send packet | @@ -144,7 +175,7 @@ void HyperXPulsefireSurgeController::SendWakeup() /*-----------------------------------------------------*\ | Send packet | \*-----------------------------------------------------*/ - hid_send_feature_report(dev, buf, 264); + //hid_send_feature_report(dev, buf, 264); } void HyperXPulsefireSurgeController::SendData @@ -178,11 +209,11 @@ void HyperXPulsefireSurgeController::SendData memset(buf, 0x00, sizeof(buf)); /*-----------------------------------------------------*\ - | Set up Select Profile packet | + | Set up Set Configuration packet | \*-----------------------------------------------------*/ buf[0x00] = 0x07; - buf[0x01] = 0x01; - buf[0x02] = 0x04; + buf[0x01] = HYPERX_PULSEFIRE_SURGE_PACKET_ID_SET_CONFIGURATION; + buf[0x02] = 0x01; /*-----------------------------------------------------*\ | DPI settings | @@ -285,3 +316,47 @@ void HyperXPulsefireSurgeController::SendData \*-----------------------------------------------------*/ hid_send_feature_report(dev, buf, 264); } + +void HyperXPulsefireSurgeController::SendDirect + ( + RGBColor* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Select Profile packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PULSEFIRE_SURGE_PACKET_ID_DIRECT; + buf[0x03] = 0xA0; + + for(int red_idx = 0; red_idx < 32; red_idx++) + { + buf[0x08 + red_idx] = RGBGetRValue(color_data[red_idx]); + } + + for(int grn_idx = 0; grn_idx < 32; grn_idx++) + { + buf[0x28 + grn_idx] = RGBGetGValue(color_data[grn_idx]); + } + + for(int blu_idx = 0; blu_idx < 32; blu_idx++) + { + buf[0x48 + blu_idx] = RGBGetBValue(color_data[blu_idx]); + } + + buf[0x6C] = RGBGetRValue(color_data[32]); + buf[0x6D] = RGBGetGValue(color_data[32]); + buf[0x6E] = RGBGetBValue(color_data[32]); + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} diff --git a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.h b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.h index 250540e54..ad48cc3ee 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.h +++ b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController.h @@ -16,11 +16,17 @@ enum { - HYPERX_PULSEFIRE_SURGE_MODE_SOLID = 0x00, /* Solid color mode */ - HYPERX_PULSEFIRE_SURGE_MODE_CYCLE = 0x01, /* Spectrum cycle mode */ - HYPERX_PULSEFIRE_SURGE_MODE_BREATHING = 0x02, /* Breathing mode */ - HYPERX_PULSEFIRE_SURGE_MODE_WAVE = 0x03, /* Wave mode */ - HYPERX_PULSEFIRE_SURGE_MODE_TRIGGER = 0x04, /* Trigger mode */ + HYPERX_PULSEFIRE_SURGE_PACKET_ID_SET_CONFIGURATION = 0x01, /* Set profile configuration packet */ + HYPERX_PULSEFIRE_SURGE_PACKET_ID_DIRECT = 0x14, /* Direct control packet */ +}; + +enum +{ + HYPERX_PULSEFIRE_SURGE_MODE_SOLID = 0x00, /* Solid color mode */ + HYPERX_PULSEFIRE_SURGE_MODE_CYCLE = 0x01, /* Spectrum cycle mode */ + HYPERX_PULSEFIRE_SURGE_MODE_BREATHING = 0x02, /* Breathing mode */ + HYPERX_PULSEFIRE_SURGE_MODE_WAVE = 0x03, /* Wave mode */ + HYPERX_PULSEFIRE_SURGE_MODE_TRIGGER = 0x04, /* Trigger mode */ }; class HyperXPulsefireSurgeController @@ -35,6 +41,11 @@ public: RGBColor* color_data ); + void SendDirect + ( + RGBColor* color_data + ); + private: hid_device* dev; diff --git a/RGBController/RGBController_HyperXPulsefireSurge.cpp b/RGBController/RGBController_HyperXPulsefireSurge.cpp index 8075c0fca..2d68fd5f9 100644 --- a/RGBController/RGBController_HyperXPulsefireSurge.cpp +++ b/RGBController/RGBController_HyperXPulsefireSurge.cpp @@ -9,6 +9,32 @@ #include "RGBController_HyperXPulsefireSurge.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_HyperXPulsefireSurge* controller = static_cast(param); + controller->KeepaliveThread(); + THREADRETURN +} + RGBController_HyperXPulsefireSurge::RGBController_HyperXPulsefireSurge(HyperXPulsefireSurgeController* hyperx_ptr) { hyperx = hyperx_ptr; @@ -19,11 +45,18 @@ RGBController_HyperXPulsefireSurge::RGBController_HyperXPulsefireSurge(HyperXPul mode Direct; Direct.name = "Direct"; - Direct.value = HYPERX_PULSEFIRE_SURGE_MODE_SOLID; + Direct.value = 0xFFFF; Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); + mode Custom; + Custom.name = "Custom"; + Custom.value = HYPERX_PULSEFIRE_SURGE_MODE_SOLID; + Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Custom.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Custom); + mode Cycle; Cycle.name = "Cycle"; Cycle.value = HYPERX_PULSEFIRE_SURGE_MODE_CYCLE; @@ -46,6 +79,19 @@ RGBController_HyperXPulsefireSurge::RGBController_HyperXPulsefireSurge(HyperXPul modes.push_back(Wave); 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_HyperXPulsefireSurge::~RGBController_HyperXPulsefireSurge() @@ -58,9 +104,9 @@ void RGBController_HyperXPulsefireSurge::SetupZones() zone led_strip; led_strip.name = "LED Strip"; led_strip.type = ZONE_TYPE_LINEAR; - led_strip.leds_min = 31; - led_strip.leds_max = 31; - led_strip.leds_count = 31; + led_strip.leds_min = 32; + led_strip.leds_max = 32; + led_strip.leds_count = 32; led_strip.matrix_map = NULL; zones.push_back(led_strip); @@ -95,7 +141,17 @@ void RGBController_HyperXPulsefireSurge::ResizeZone(int /*zone*/, int /*new_size void RGBController_HyperXPulsefireSurge::DeviceUpdateLEDs() { - hyperx->SendData(active_mode, &colors[0]); + last_update_time = std::chrono::steady_clock::now(); + + if(active_mode == 0) + { + hyperx->SendDirect(&colors[0]); + } + else + { + hyperx->SendData(active_mode, &colors[0]); + } + } void RGBController_HyperXPulsefireSurge::UpdateZoneLEDs(int /*zone*/) @@ -120,5 +176,15 @@ void RGBController_HyperXPulsefireSurge::DeviceUpdateMode() void RGBController_HyperXPulsefireSurge::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); + } } diff --git a/RGBController/RGBController_HyperXPulsefireSurge.h b/RGBController/RGBController_HyperXPulsefireSurge.h index e344c2a6e..e6cc9ec9d 100644 --- a/RGBController/RGBController_HyperXPulsefireSurge.h +++ b/RGBController/RGBController_HyperXPulsefireSurge.h @@ -34,4 +34,6 @@ public: private: HyperXPulsefireSurgeController* hyperx; + + std::chrono::time_point last_update_time; };