|
|
|
|
@ -10,17 +10,104 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
//Include thread libraries for Windows or Linux
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <process.h>
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
static void Sleep(unsigned int milliseconds)
|
|
|
|
|
{
|
|
|
|
|
usleep(1000 * milliseconds);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
THREAD keepalive_thread(void *param)
|
|
|
|
|
{
|
|
|
|
|
CorsairNodeProController* corsair = static_cast<CorsairNodeProController*>(param);
|
|
|
|
|
corsair->KeepaliveThread();
|
|
|
|
|
THREADRETURN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CorsairNodeProController::CorsairNodeProController(libusb_device_handle* dev_handle)
|
|
|
|
|
{
|
|
|
|
|
dev = dev_handle;
|
|
|
|
|
channel_leds[0] = 60;
|
|
|
|
|
channel_leds[1] = 60;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CorsairNodeProController::~CorsairNodeProController()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CorsairNodeProController::SendKeepalive()
|
|
|
|
|
{
|
|
|
|
|
unsigned char usb_apply[] =
|
|
|
|
|
{
|
|
|
|
|
0x33, 0xFF, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x80, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
|
};
|
|
|
|
|
int actual;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Send apply packet |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
libusb_interrupt_transfer(dev, 0x01, usb_apply, 64, &actual, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CorsairNodeProController::KeepaliveThread()
|
|
|
|
|
{
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
SendKeepalive();
|
|
|
|
|
|
|
|
|
|
Sleep(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CorsairNodeProController::SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors)
|
|
|
|
|
{
|
|
|
|
|
unsigned char usb_start[] =
|
|
|
|
|
|