Convert Corsair Lighting Node driver to use hidapi instead of libusb

This commit is contained in:
Adam Honse 2020-05-30 23:48:59 -05:00
parent a75a2bbf8b
commit 8d29a40954
3 changed files with 48 additions and 41 deletions

View file

@ -46,10 +46,9 @@ THREAD keepalive_thread(void *param)
THREADRETURN
}
CorsairLightingNodeController::CorsairLightingNodeController(libusb_device_handle* dev_handle, unsigned int dev_endpoint)
CorsairLightingNodeController::CorsairLightingNodeController(hid_device* dev_handle)
{
dev = dev_handle;
endpoint = dev_endpoint;
SendFirmwareRequest();
@ -220,8 +219,8 @@ void CorsairLightingNodeController::SendFirmwareRequest()
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x80 + endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
actual = hid_read(dev, usb_buf, 64);
if(actual > 0)
{
@ -238,7 +237,6 @@ void CorsairLightingNodeController::SendDirect
unsigned char* color_data
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -263,12 +261,11 @@ void CorsairLightingNodeController::SendDirect
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendCommit()
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -285,7 +282,7 @@ void CorsairLightingNodeController::SendCommit()
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendBegin
@ -293,7 +290,6 @@ void CorsairLightingNodeController::SendBegin
unsigned char channel
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -310,7 +306,7 @@ void CorsairLightingNodeController::SendBegin
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendEffectConfig
@ -336,7 +332,6 @@ void CorsairLightingNodeController::SendEffectConfig
unsigned short temperature_2
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -387,7 +382,7 @@ void CorsairLightingNodeController::SendEffectConfig
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendTemperature()
@ -400,7 +395,6 @@ void CorsairLightingNodeController::SendReset
unsigned char channel
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -417,7 +411,7 @@ void CorsairLightingNodeController::SendReset
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendPortState
@ -426,7 +420,6 @@ void CorsairLightingNodeController::SendPortState
unsigned char state
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
@ -444,7 +437,7 @@ void CorsairLightingNodeController::SendPortState
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
hid_write(dev, usb_buf, 64);
}
void CorsairLightingNodeController::SendBrightness()

View file

@ -6,7 +6,7 @@
#include "RGBController.h"
#include <vector>
#include <libusb-1.0/libusb.h>
#include <hidapi/hidapi.h>
#pragma once
@ -78,7 +78,7 @@ enum
class CorsairLightingNodeController
{
public:
CorsairLightingNodeController(libusb_device_handle* dev_handle, unsigned int dev_endpoint);
CorsairLightingNodeController(hid_device* dev_handle);
~CorsairLightingNodeController();
std::string GetFirmwareString();
@ -107,8 +107,7 @@ public:
void KeepaliveThread();
private:
libusb_device_handle* dev;
unsigned int endpoint;
hid_device* dev;
std::string firmware_version;
void SendFirmwareRequest();

View file

@ -2,7 +2,7 @@
#include "RGBController.h"
#include "RGBController_CorsairLightingNode.h"
#include <vector>
#include <libusb-1.0/libusb.h>
#include <hidapi/hidapi.h>
#define CORSAIR_VID 0x1B1C
#define CORSAIR_LIGHTING_NODE_CORE_PID 0x0C1A
@ -16,20 +16,20 @@ typedef struct
{
unsigned short usb_vid;
unsigned short usb_pid;
unsigned char usb_endpoint;
unsigned char channel_count;
const char * name;
} corsair_node_device;
static const corsair_node_device device_list[6] =
{
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_CORE_PID, 1, 1, "Corsair Lighting Node Core" },
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_PRO_PID, 1, 2, "Corsair Lighting Node Pro" },
{ CORSAIR_VID, CORSAIR_COMMANDER_PRO_PID, 2, 2, "Corsair Commander Pro" },
{ CORSAIR_VID, CORSAIR_LS100_PID, 1, 1, "Corsair LS100 Lighting Kit" },
{ CORSAIR_VID, CORSAIR_1000D_OBSIDIAN_PID, 2, 2, "Corsair 1000D Obsidian" },
{ CORSAIR_VID, CORSAIR_SPEC_OMEGA_RGB_PID, 1, 2, "Corsair SPEC OMEGA RGB" }
#define CORSAIR_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
static const corsair_node_device device_list[] =
{
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_CORE_PID, 1, "Corsair Lighting Node Core" },
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_PRO_PID, 2, "Corsair Lighting Node Pro" },
{ CORSAIR_VID, CORSAIR_COMMANDER_PRO_PID, 2, "Corsair Commander Pro" },
{ CORSAIR_VID, CORSAIR_LS100_PID, 1, "Corsair LS100 Lighting Kit" },
{ CORSAIR_VID, CORSAIR_1000D_OBSIDIAN_PID, 2, "Corsair 1000D Obsidian" },
{ CORSAIR_VID, CORSAIR_SPEC_OMEGA_RGB_PID, 2, "Corsair SPEC OMEGA RGB" }
};
/******************************************************************************************\
@ -37,30 +37,45 @@ static const corsair_node_device device_list[6] =
* DetectCorsairLightingNodeControllers *
* *
* Detect devices supported by the Corsair Lighting Node Pro driver *
* * *
* *
\******************************************************************************************/
void DetectCorsairLightingNodeControllers(std::vector<RGBController*> &rgb_controllers)
{
libusb_context * ctx;
libusb_init(&ctx);
hid_device_info* info;
hid_device* dev;
for(int device_idx = 0; device_idx < 6; device_idx++)
hid_init();
for(std::size_t device_idx = 0; device_idx < CORSAIR_NUM_DEVICES; device_idx++)
{
//Look for Corsair Lighting Node Device
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
dev = NULL;
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
//Look for Corsair Lighting Node Devices
while(info)
{
if((info->vendor_id == device_list[device_idx].usb_vid)
&&(info->product_id == device_list[device_idx].usb_pid))
{
dev = hid_open_path(info->path);
break;
}
else
{
info = info->next;
}
}
if( dev )
{
libusb_detach_kernel_driver(dev, 0);
libusb_claim_interface(dev, 0);
CorsairLightingNodeController* controller = new CorsairLightingNodeController(dev, device_list[device_idx].usb_endpoint);
CorsairLightingNodeController* controller = new CorsairLightingNodeController(dev);
RGBController_CorsairLightingNode* rgb_controller = new RGBController_CorsairLightingNode(controller);
rgb_controller->name = device_list[device_idx].name;
rgb_controllers.push_back(rgb_controller);
}
}