Add support for Holtek USB Gaming Mouse

This commit is contained in:
santeri3700
2020-08-01 21:19:13 +03:00
committed by Adam Honse
parent f1d42d27ce
commit 92f7fe7dc4
5 changed files with 337 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
/*-----------------------------------------------*\
| HoltekA070Controller.cpp |
| |
| Driver for Holtek USB Gaming Mouse [04d9:a070] |
| |
| Santeri Pikarinen (santeri3700) 8/01/2020 |
\*-----------------------------------------------*/
#include "HoltekA070Controller.h"
#include <cstring>
HoltekA070Controller::HoltekA070Controller(hid_device* dev_handle)
{
dev = dev_handle;
}
/*-------------------------------------------------------------------------------------------------*\
| Private packet sending functions. |
\*-------------------------------------------------------------------------------------------------*/
void HoltekA070Controller::SendCustomColor
(
unsigned char red,
unsigned char green,
unsigned char blue
)
{
char usb_buf[8];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up RGB Control packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x07; // PACKET SIZE?
usb_buf[0x01] = 0x0a; // SET RGB
usb_buf[0x02] = 0x00; // SAVE (does not work with SET RGB)
usb_buf[0x03] = red; // RED
usb_buf[0x04] = green; // GREEN
usb_buf[0x05] = blue; // BLUE
usb_buf[0x06] = 0x00; // PADDING?
usb_buf[0x07] = 0x00; // PADDING?
// So far no saving function has been discovered for the "SET RGB" command.
// Such functionality might not even exist for the A070 series.
// The chosen RGB color will therefore reset after a power cycle.
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_send_feature_report(dev, (unsigned char *)usb_buf, sizeof(usb_buf));
}
void HoltekA070Controller::SendMode
(
unsigned char mode
)
{
char usb_buf[8];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up lighting mode control packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x07; // PACKET SIZE?
usb_buf[0x01] = 0x0b; // SET LIGHTING MODE
usb_buf[0x02] = 0x01; // SAVE
usb_buf[0x03] = mode; // MODE 01-04
usb_buf[0x04] = 0x00; // PADDING?
usb_buf[0x05] = 0x00; // PADDING?
usb_buf[0x06] = 0x00; // PADDING?
usb_buf[0x07] = 0x00; // PADDING?
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_send_feature_report(dev, (unsigned char *)usb_buf, sizeof(usb_buf));
}

View File

@@ -0,0 +1,44 @@
/*---------------------------------------------------------------*\
| HoltekA070Controller.h |
| |
| Definitions and types for Holtek USB Gaming Mouse [04d9:a070] |
| |
| Santeri Pikarinen (santeri3700) 8/01/2020 |
\*---------------------------------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
HOLTEK_A070_MODE_STATIC = 0x01,
HOLTEK_A070_MODE_BREATHING_SLOW = 0x02,
HOLTEK_A070_MODE_BREATHING_MEDIUM = 0x03,
HOLTEK_A070_MODE_BREATHING_FAST = 0x04
};
class HoltekA070Controller
{
public:
HoltekA070Controller(hid_device* dev_handle);
~HoltekA070Controller();
void SendCustomColor
(
unsigned char red,
unsigned char green,
unsigned char blue
);
void SendMode
(
unsigned char mode
);
private:
hid_device* dev;
};

View File

@@ -0,0 +1,86 @@
#include "HoltekA070Controller.h"
#include "RGBController.h"
#include "RGBController_HoltekA070.h"
#include <vector>
#include <hidapi/hidapi.h>
/*-----------------------------------------------------*\
| Holtek Semiconductor Inc. vendor ID |
\*-----------------------------------------------------*/
#define HOLTEK_VID 0x04D9
/*-----------------------------------------------------*\
| Mouse product IDs |
\*-----------------------------------------------------*/
#define HOLTEK_A070_PID 0xA070
typedef struct
{
unsigned short usb_vid;
unsigned short usb_pid;
unsigned char usb_interface;
device_type type;
const char * name;
} holtek_device;
#define HOLTEK_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
static const holtek_device device_list[] =
{
/*-------------------------------------------------------------------------------------------------------------*\
| Mice |
\*-------------------------------------------------------------------------------------------------------------*/
{ HOLTEK_VID, HOLTEK_A070_PID, 1, DEVICE_TYPE_MOUSE, "Holtek USB Gaming Mouse" },
};
void DetectHoltekControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_init();
for(int device_idx = 0; device_idx < HOLTEK_NUM_DEVICES; device_idx++)
{
switch(device_list[device_idx].type)
{
case DEVICE_TYPE_MOUSE:
{
hid_device_info* info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
while(info)
{
if((info->vendor_id == device_list[device_idx].usb_vid)
&&(info->product_id == device_list[device_idx].usb_pid)
#ifdef USE_HID_USAGE
&&(info->interface_number == device_list[device_idx].usb_interface)
&&(info->usage_page == 0xFF00)
&&(info->usage == 2))
#else
&&(info->interface_number == device_list[device_idx].usb_interface))
#endif
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
switch(device_list[device_idx].usb_pid)
{
case HOLTEK_A070_PID:
{
HoltekA070Controller* controller = new HoltekA070Controller(dev);
RGBController_HoltekA070* rgb_controller = new RGBController_HoltekA070(controller);
rgb_controller->name = device_list[device_idx].name;
rgb_controllers.push_back(rgb_controller);
}
break;
}
}
}
info = info->next;
}
hid_free_enumeration(info);
}
break;
}
}
}