Updated controller to use HIDAPI instead of LIBUSB
& added code to pass back info from the USB device
This commit is contained in:
parent
5fdea9d34f
commit
19ef8afe70
4 changed files with 49 additions and 47 deletions
|
|
@ -8,24 +8,21 @@
|
|||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "CMMP750Controller.h"
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
CMMP750Controller::CMMP750Controller(libusb_device_handle* dev_handle, unsigned int _inAddr, unsigned int _outAddr, int _interface)
|
||||
CMMP750Controller::CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path)
|
||||
{
|
||||
int tmp_size = wcslen(_vendor);
|
||||
|
||||
dev = dev_handle;
|
||||
inAddr = _inAddr;
|
||||
outAddr = _outAddr;
|
||||
interface = _interface;
|
||||
|
||||
libusb_device* device = libusb_get_device(dev);
|
||||
int bus = libusb_get_bus_number(device);
|
||||
int bus_addr = libusb_get_device_address(device);
|
||||
int port = libusb_get_port_number(device);
|
||||
location = "Bus: " + std::to_string(bus) + " Addr: " + std::to_string(bus_addr) + " Port: " + std::to_string(port);
|
||||
for (int i=0; ( i<tmp_size && i<CM_DEVICE_NAME_SIZE); i++)
|
||||
{
|
||||
device_name[i] = (char)_vendor[i];
|
||||
}
|
||||
for (int j=0; ( j<wcslen(_vendor) && tmp_size+j<CM_DEVICE_NAME_SIZE); j++)
|
||||
device_name[tmp_size+j] = (char)_device_name[j];
|
||||
|
||||
strcpy(device_name, "Cooler Master MP750");
|
||||
location = _path;
|
||||
|
||||
current_mode = MP750_MODE_STATIC;
|
||||
current_speed = MP750_SPEED_NORMAL;
|
||||
|
|
@ -33,8 +30,7 @@ CMMP750Controller::CMMP750Controller(libusb_device_handle* dev_handle, unsigned
|
|||
|
||||
CMMP750Controller::~CMMP750Controller()
|
||||
{
|
||||
libusb_release_interface(dev, interface);
|
||||
libusb_attach_kernel_driver(dev, interface);
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
char* CMMP750Controller::GetDeviceName()
|
||||
|
|
@ -71,7 +67,6 @@ void CMMP750Controller::SetColor(unsigned char red, unsigned char green, unsigne
|
|||
|
||||
void CMMP750Controller::SendUpdate()
|
||||
{
|
||||
int actual = 0;
|
||||
unsigned char buffer[0x40] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
|
||||
|
|
@ -94,7 +89,5 @@ void CMMP750Controller::SendUpdate()
|
|||
buffer[CM_SPEED_BYTE] = speed_mode_data[current_mode][current_speed];
|
||||
}
|
||||
|
||||
//Nothing will be done with the "actual" transfer length
|
||||
libusb_interrupt_transfer(dev, outAddr, buffer, buffer_size, nullptr, CM_INTERRUPT_TIMEOUT);
|
||||
}
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
}
|
||||
|
|
@ -16,12 +16,15 @@
|
|||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define CM_COLOUR_MODE_DATA_SIZE (sizeof(colour_mode_data) / sizeof(colour_mode_data[0]))
|
||||
#define CM_INTERRUPT_TIMEOUT 250
|
||||
#define CM_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
|
||||
#define CM_SERIAL_SIZE (sizeof(serial) / sizeof(serial[ 0 ]))
|
||||
#define HID_MAX_STR 255
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -53,10 +56,10 @@ static unsigned char colour_mode_data[][6] =
|
|||
static unsigned char speed_mode_data[][9] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },/* Static */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Blinking */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Breathing */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Colour Cycle */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF } /* Colour Breath */
|
||||
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Blinking */
|
||||
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Breathing */
|
||||
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 },/* Colour Cycle */
|
||||
{ 0xFF, 0xE0, 0xC0, 0xA0, 0x80, 0x60, 0x40, 0x20, 0x00 } /* Colour Breath */
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -75,7 +78,7 @@ enum
|
|||
class CMMP750Controller
|
||||
{
|
||||
public:
|
||||
CMMP750Controller(libusb_device_handle *dev_handle, unsigned int _inAddr, unsigned int _outAddr, int _interface);
|
||||
CMMP750Controller(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path);
|
||||
~CMMP750Controller();
|
||||
|
||||
char* GetDeviceName();
|
||||
|
|
@ -89,10 +92,7 @@ private:
|
|||
char device_name[32];
|
||||
char serial[32];
|
||||
std::string location;
|
||||
libusb_device_handle* dev;
|
||||
unsigned char inAddr;
|
||||
unsigned char outAddr;
|
||||
int interface;
|
||||
hid_device* dev;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#include "CMMP750Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CMMP750Controller.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define COOLERMASTER_VID 0x2516
|
||||
|
||||
|
|
@ -31,27 +30,37 @@ static const unsigned int cm_pids[][4] =
|
|||
|
||||
void DetectCoolerMasterControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
libusb_context * context;
|
||||
libusb_init(&context);
|
||||
hid_device_info* info;
|
||||
hid_device* dev = NULL;
|
||||
|
||||
for(int cm_pid_idx = 0; cm_pid_idx < COOLERMASTER_NUM_DEVICES; cm_pid_idx++)
|
||||
{
|
||||
//Look for the passed in cm_pids
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(context, COOLERMASTER_VID, cm_pids[cm_pid_idx][CM_PID]);
|
||||
hid_init();
|
||||
info = hid_enumerate(0x0, 0x0);
|
||||
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == COOLERMASTER_VID)
|
||||
&&(info->product_id == cm_pids[cm_pid_idx][CM_PID])
|
||||
&&(info->interface_number == cm_pids[cm_pid_idx][CM_INTERFACE]))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
|
||||
if(dev)
|
||||
{
|
||||
int status = libusb_detach_kernel_driver(dev, cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
status = libusb_claim_interface(dev, cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
|
||||
if(status == 0)
|
||||
{
|
||||
// Success: Device has been claimed
|
||||
CMMP750Controller* controller = new CMMP750Controller(dev, cm_pids[cm_pid_idx][CM_INADDR], cm_pids[cm_pid_idx][CM_OUTADDR], cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
RGBController_CMMP750Controller* rgb_controller = new RGBController_CMMP750Controller(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
CMMP750Controller* controller = new CMMP750Controller(dev, info->manufacturer_string, info->product_string, info->path);
|
||||
RGBController_CMMP750Controller* rgb_controller = new RGBController_CMMP750Controller(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
hid_free_enumeration(info);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ RGBController_CMMP750Controller::RGBController_CMMP750Controller(CMMP750Controll
|
|||
|
||||
name = cmmp750->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOUSEMAT;
|
||||
description = "Cooler Master Mousepad 750";
|
||||
description = cmmp750->GetDeviceName();
|
||||
version = "1.0";
|
||||
serial = "";
|
||||
location = cmmp750->GetLocation();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue