Convert AMD Wraith Prism driver to use hidapi instead of libusb
This commit is contained in:
parent
8827d0e0c2
commit
1d426f109a
3 changed files with 37 additions and 35 deletions
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
AMDWraithPrismController::AMDWraithPrismController(libusb_device_handle* dev_handle)
|
||||
AMDWraithPrismController::AMDWraithPrismController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
|
|
@ -67,12 +67,10 @@ std::string AMDWraithPrismController::GetEffectChannelString(unsigned char chann
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
int actual;
|
||||
|
||||
usb_buf[0x02] = channel;
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
|
||||
ret_string.append((char *)&usb_buf[0x08]);
|
||||
|
||||
|
|
@ -103,11 +101,10 @@ std::string AMDWraithPrismController::GetFirmwareVersionString()
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
int actual;
|
||||
unsigned char fw_buf[16] = {0x00};
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
|
||||
for(int char_idx = 0; char_idx < 16; char_idx+=2)
|
||||
{
|
||||
|
|
@ -227,10 +224,8 @@ void AMDWraithPrismController::SendEnableCommand()
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
int actual;
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
}
|
||||
|
||||
void AMDWraithPrismController::SendApplyCommand()
|
||||
|
|
@ -255,10 +250,8 @@ void AMDWraithPrismController::SendApplyCommand()
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
int actual;
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
}
|
||||
|
||||
void AMDWraithPrismController::SendEffectChannelUpdate
|
||||
|
|
@ -294,8 +287,6 @@ void AMDWraithPrismController::SendEffectChannelUpdate
|
|||
0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
int actual;
|
||||
|
||||
usb_buf[0x04] = effect_channel;
|
||||
usb_buf[0x05] = speed;
|
||||
usb_buf[0x06] = (direction ? 0x01 : 0x00) | (random_color ? 0x80 : 0x00);
|
||||
|
|
@ -307,8 +298,8 @@ void AMDWraithPrismController::SendEffectChannelUpdate
|
|||
usb_buf[0x0B] = green;
|
||||
usb_buf[0x0C] = blue;
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
}
|
||||
|
||||
void AMDWraithPrismController::SendChannelRemap(unsigned char ring_channel, unsigned char logo_channel, unsigned char fan_channel)
|
||||
|
|
@ -333,8 +324,6 @@ void AMDWraithPrismController::SendChannelRemap(unsigned char ring_channel, unsi
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
int actual;
|
||||
|
||||
usb_buf[0x08] = logo_channel;
|
||||
usb_buf[0x09] = fan_channel;
|
||||
|
||||
|
|
@ -343,6 +332,6 @@ void AMDWraithPrismController::SendChannelRemap(unsigned char ring_channel, unsi
|
|||
usb_buf[led] = ring_channel;
|
||||
}
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
|
||||
hid_write(dev, usb_buf, 64);
|
||||
hid_read(dev, usb_buf, 64);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ enum
|
|||
class AMDWraithPrismController
|
||||
{
|
||||
public:
|
||||
AMDWraithPrismController(libusb_device_handle* dev_handle);
|
||||
AMDWraithPrismController(hid_device* dev_handle);
|
||||
~AMDWraithPrismController();
|
||||
|
||||
char* GetDeviceName();
|
||||
|
|
@ -130,7 +130,7 @@ public:
|
|||
|
||||
private:
|
||||
char device_name[32];
|
||||
libusb_device_handle* dev;
|
||||
hid_device* dev;
|
||||
|
||||
unsigned char current_fan_mode;
|
||||
unsigned char current_fan_speed;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
#include "RGBController.h"
|
||||
#include "RGBController_AMDWraithPrism.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
#define AMD_WRAITH_PRISM_VID 0x2516
|
||||
#define AMD_WRAITH_PRISM_PID 0x0051
|
||||
|
||||
|
|
@ -17,17 +16,31 @@
|
|||
|
||||
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
libusb_context * ctx;
|
||||
libusb_init(&ctx);
|
||||
hid_device_info* info;
|
||||
hid_device* dev = NULL;
|
||||
|
||||
hid_init();
|
||||
|
||||
info = hid_enumerate(AMD_WRAITH_PRISM_VID, AMD_WRAITH_PRISM_PID);
|
||||
|
||||
//Look for AMD Wraith Prism
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, AMD_WRAITH_PRISM_VID, AMD_WRAITH_PRISM_PID);
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == AMD_WRAITH_PRISM_VID)
|
||||
&&(info->product_id == AMD_WRAITH_PRISM_PID)
|
||||
&&(info->interface_number == 1))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
|
||||
if( dev )
|
||||
{
|
||||
libusb_detach_kernel_driver(dev, 1);
|
||||
libusb_claim_interface(dev, 1);
|
||||
|
||||
AMDWraithPrismController* controller = new AMDWraithPrismController(dev);
|
||||
|
||||
RGBController_AMDWraithPrism* rgb_controller = new RGBController_AMDWraithPrism(controller);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue