driver: g-wolves full refactor
This commit is contained in:
		@@ -1,7 +1,14 @@
 | 
			
		||||
SUBDIRS := $(wildcard */.)
 | 
			
		||||
CC=gcc
 | 
			
		||||
CFLAGS=$(shell pkg-config --cflags libusb-1.0) -O3 -Wall -shared
 | 
			
		||||
LDFLAGS=$(shell pkg-config --libs libusb-1.0)
 | 
			
		||||
 | 
			
		||||
all: $(SUBDIRS)
 | 
			
		||||
$(SUBDIRS):
 | 
			
		||||
		$(MAKE) -C $@
 | 
			
		||||
ASSETS=$(shell find devices/ -name '*.png')
 | 
			
		||||
FINAL_ASSETS=$(BUILD_DIR)/drivers/assets/gwolves-htx.png
 | 
			
		||||
BUILD_DIR=../../build/
 | 
			
		||||
 | 
			
		||||
.PHONY: all $(SUBDIRS)
 | 
			
		||||
all: $(BUILD_DIR)/drivers/g-wolves.so
 | 
			
		||||
 | 
			
		||||
$(BUILD_DIR)/drivers/g-wolves.so: g-wolves.c | $(BUILD_DIR)/drivers/
 | 
			
		||||
	$(CC) $(CFLAGS) -o $@ $^
 | 
			
		||||
$(BUILD_DIR)/drivers/assets/%.png: devices/%.png | $(BUILD_DIR)/drivers/assets
 | 
			
		||||
	cp $^ $@
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,15 @@
 | 
			
		||||
# G-Wolves HTX driver
 | 
			
		||||
# G-Wolves driver
 | 
			
		||||
 | 
			
		||||
G-Wolves USB Vendor ID: 0x33e4
 | 
			
		||||
 | 
			
		||||
Product IDs:
 | 
			
		||||
- G-Wolves HTS+ 4K Wired: 0x5408
 | 
			
		||||
- G-Wolves HTS+ 4K Wireless: 0x5407
 | 
			
		||||
- G-Wolves HTX 4K Wired: 0x5708
 | 
			
		||||
- G-Wolves HTX 4K Wireless: 0x5707
 | 
			
		||||
 | 
			
		||||
All of the G-Wolves devices use the same protocol.
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
 | 
			
		||||
The device works using USB HID feature reports.
 | 
			
		||||
@@ -15,4 +19,3 @@ The SET_REPORT command can be used, setting a command byte to the desired comman
 | 
			
		||||
to get an output (for example, you set report with COMMAND_DPI_SETTINGS, and
 | 
			
		||||
then get report to obtain a DPI_SETTINGS_REPORT structure).
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								drivers/g-wolves/devices/gwolves-hts_plus.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								drivers/g-wolves/devices/gwolves-hts_plus.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
							
								
								
									
										11
									
								
								drivers/g-wolves/devices/hts_plus.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								drivers/g-wolves/devices/hts_plus.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
#ifndef HTS_PLUS_H
 | 
			
		||||
#define HTS_PLUS_H
 | 
			
		||||
 | 
			
		||||
#define HTS_PLUS_4K_PRODUCT_ID_WIRED 0x5408
 | 
			
		||||
#define HTS_PLUS_4K_PRODUCT_ID_WIRELESS 0x5407
 | 
			
		||||
#define HTS_PLUS_4K_PRODUCT_NAME "HTS+ 4K"
 | 
			
		||||
 | 
			
		||||
#define HTS_DPI_MAX_VALUE 26000
 | 
			
		||||
#define HTS_DPI_MAX_LEVEL_COUNT 5
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										11
									
								
								drivers/g-wolves/devices/htx.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								drivers/g-wolves/devices/htx.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
#ifndef HTX_H
 | 
			
		||||
#define HTX_H
 | 
			
		||||
 | 
			
		||||
#define HTX_4K_PRODUCT_ID_WIRED 0x5708
 | 
			
		||||
#define HTX_4K_PRODUCT_ID_WIRELESS 0x5707
 | 
			
		||||
#define HTX_4K_PRODUCT_NAME "HTX 4K"
 | 
			
		||||
 | 
			
		||||
#define HTX_DPI_MAX_VALUE 26000
 | 
			
		||||
#define HTX_DPI_MAX_LEVEL_COUNT 5
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -1,19 +1,19 @@
 | 
			
		||||
#include "htx.h"
 | 
			
		||||
#include "g-wolves.h"
 | 
			
		||||
 | 
			
		||||
static int htx_send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
			
		||||
static int send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
			
		||||
{
 | 
			
		||||
    if(wireless)
 | 
			
		||||
    {
 | 
			
		||||
        // If wireless, ask receiver for mouse command first
 | 
			
		||||
        struct HTX_REPORT_WIRELESS w_report = {0};
 | 
			
		||||
        int res = htx_send_command(hand, COMMAND_WIRELESS_MOUSE, REPORT_WIRELESS_MOUSE_SIZE, &w_report, false);
 | 
			
		||||
        struct REPORT_WIRELESS w_report = {0};
 | 
			
		||||
        int res = send_command(hand, COMMAND_WIRELESS_MOUSE, REPORT_WIRELESS_MOUSE_SIZE, &w_report, false);
 | 
			
		||||
        if(res <= 0) return res;
 | 
			
		||||
 | 
			
		||||
        if(!w_report.mouse_connected)
 | 
			
		||||
            return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    htx_report_header_t* head = report;
 | 
			
		||||
    report_header_t* head = report;
 | 
			
		||||
    head->report_size = size;
 | 
			
		||||
    head->command = command;
 | 
			
		||||
    if(wireless)
 | 
			
		||||
@@ -51,12 +51,28 @@ uint32_t driver_getkey(void)
 | 
			
		||||
    static int count = 0;
 | 
			
		||||
    count++;
 | 
			
		||||
 | 
			
		||||
    if(count == 1)
 | 
			
		||||
        return (DEVICE_VENDOR_ID << 16) | DEVICE_PRODUCT_ID_WIRED;
 | 
			
		||||
    else if(count == 2)
 | 
			
		||||
        return (DEVICE_VENDOR_ID << 16) | DEVICE_PRODUCT_ID_WIRELESS;
 | 
			
		||||
    // Register ALL G-Wolves compatible devices
 | 
			
		||||
    uint16_t id = 0;
 | 
			
		||||
    switch(count)
 | 
			
		||||
    {
 | 
			
		||||
        case 1:
 | 
			
		||||
            id = HTX_4K_PRODUCT_ID_WIRED;
 | 
			
		||||
            break;
 | 
			
		||||
        case 2:
 | 
			
		||||
            id = HTX_4K_PRODUCT_ID_WIRELESS;
 | 
			
		||||
            break;
 | 
			
		||||
        case 3:
 | 
			
		||||
            id = HTS_PLUS_4K_PRODUCT_ID_WIRED;
 | 
			
		||||
            break;
 | 
			
		||||
        case 4:
 | 
			
		||||
            id = HTS_PLUS_4K_PRODUCT_ID_WIRELESS;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            id = 0;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
    if(id == 0) return 0;
 | 
			
		||||
    return (VENDOR_ID << 16) | id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char* driver_get_name(void* handle)
 | 
			
		||||
@@ -68,11 +84,14 @@ char* driver_get_name(void* handle)
 | 
			
		||||
 | 
			
		||||
    switch(desc.idProduct)
 | 
			
		||||
    {
 | 
			
		||||
        case 0x5708:
 | 
			
		||||
        case 0x5707:
 | 
			
		||||
            return "HTX 4K";
 | 
			
		||||
        case HTX_4K_PRODUCT_ID_WIRED:
 | 
			
		||||
        case HTX_4K_PRODUCT_ID_WIRELESS:
 | 
			
		||||
            return HTX_4K_PRODUCT_NAME;
 | 
			
		||||
        case HTS_PLUS_4K_PRODUCT_ID_WIRED:
 | 
			
		||||
        case HTS_PLUS_4K_PRODUCT_ID_WIRELESS:
 | 
			
		||||
            return HTS_PLUS_4K_PRODUCT_NAME;
 | 
			
		||||
        default:
 | 
			
		||||
            return "HTX ACE";
 | 
			
		||||
            return "Unknown G-Wolves mice";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -7,12 +7,10 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
#define DEVICE_VENDOR_ID 0x33e4
 | 
			
		||||
#define DEVICE_PRODUCT_ID_WIRED 0x5708
 | 
			
		||||
#define DEVICE_PRODUCT_ID_WIRELESS 0x5707
 | 
			
		||||
#include "devices/htx.h"
 | 
			
		||||
#include "devices/hts_plus.h"
 | 
			
		||||
 | 
			
		||||
#define DPI_MAX_VALUE 26000
 | 
			
		||||
#define DPI_MAX_LEVEL_COUNT 5
 | 
			
		||||
#define VENDOR_ID 0x33e4
 | 
			
		||||
 | 
			
		||||
#define REPORT_MAX_SIZE 0x40 // 64 Bytes
 | 
			
		||||
 | 
			
		||||
@@ -40,7 +38,7 @@
 | 
			
		||||
#define COMMAND_BATTERY 0x8F
 | 
			
		||||
#define COMMAND_WIRELESS_MOUSE 0x90 // -> send the next report to mouse, checking if mouse is connected
 | 
			
		||||
 | 
			
		||||
typedef struct HTX_DPI_LEVEL
 | 
			
		||||
typedef struct DPI_LEVEL
 | 
			
		||||
{
 | 
			
		||||
    uint8_t dpi_x_high;
 | 
			
		||||
    uint8_t dpi_x_low;
 | 
			
		||||
@@ -52,51 +50,51 @@ typedef struct HTX_DPI_LEVEL
 | 
			
		||||
    uint8_t led_r;
 | 
			
		||||
    uint8_t led_g;
 | 
			
		||||
    uint8_t led_b;
 | 
			
		||||
} __attribute__((packed)) htx_dpi_level_t;
 | 
			
		||||
} __attribute__((packed)) dpi_level_t;
 | 
			
		||||
 | 
			
		||||
typedef struct HTX_REPORT_HEADER
 | 
			
		||||
typedef struct REPORT_HEADER
 | 
			
		||||
{
 | 
			
		||||
    uint8_t a1; // 0xa1: request_type on receive, 0x00 on set
 | 
			
		||||
 | 
			
		||||
    uint8_t report_size; // report size, after header
 | 
			
		||||
    uint8_t command; // COMMAND
 | 
			
		||||
    uint8_t wireless; // 0 on wired, 1 on wireless
 | 
			
		||||
} __attribute__((packed)) htx_report_header_t;
 | 
			
		||||
} __attribute__((packed)) report_header_t;
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_DPI_SETTINGS
 | 
			
		||||
struct REPORT_DPI_SETTINGS
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t level_current; // current dpi level
 | 
			
		||||
    uint8_t level_count; // count of dpi levels
 | 
			
		||||
 | 
			
		||||
    htx_dpi_level_t levels[5];
 | 
			
		||||
    dpi_level_t levels[5];
 | 
			
		||||
    uint8_t zeros[23];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_UNKNOWN_0
 | 
			
		||||
struct REPORT_UNKNOWN_0
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t value0;
 | 
			
		||||
    uint8_t value1;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 2];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 2];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_UNKNOWN_1
 | 
			
		||||
struct REPORT_UNKNOWN_1
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t value0;
 | 
			
		||||
    uint8_t value1;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 2];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 2];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_CLICK_DEBOUNCE_SETTINGS
 | 
			
		||||
struct REPORT_CLICK_DEBOUNCE_SETTINGS
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    // A = 0ms B = 1 ms C = 2 ms D = 3 ms E = 4 ms
 | 
			
		||||
    uint8_t debounce_preset; // 0x00 = A, 0x01 = B, 0x02 = C, 0x03 = D, 0x04 = E, AUTO = 0x00
 | 
			
		||||
@@ -107,38 +105,38 @@ struct HTX_REPORT_CLICK_DEBOUNCE_SETTINGS
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - 8];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_LIFT_OFF
 | 
			
		||||
struct REPORT_LIFT_OFF
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    // 1 = Low, 2 = High
 | 
			
		||||
    uint8_t lift_off;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 1];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 1];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_ANGLE_SNAP
 | 
			
		||||
struct REPORT_ANGLE_SNAP
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    // 0 = disabled, 1 = enabled
 | 
			
		||||
    uint8_t angle_snap;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 1];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 1];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_MOTION_SYNC
 | 
			
		||||
struct REPORT_MOTION_SYNC
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t motion_sync;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 1];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 1];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_UNKNOWN_6
 | 
			
		||||
struct REPORT_UNKNOWN_6
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
    
 | 
			
		||||
    uint8_t value0;
 | 
			
		||||
    uint8_t value1;
 | 
			
		||||
@@ -147,23 +145,23 @@ struct HTX_REPORT_UNKNOWN_6
 | 
			
		||||
    uint8_t value4;
 | 
			
		||||
    uint8_t value5;
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 5];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 5];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_BATTERY
 | 
			
		||||
struct REPORT_BATTERY
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t battery_status; // 0 : not charging, 1 : charging
 | 
			
		||||
    uint8_t battery_level; // in %
 | 
			
		||||
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 2];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 2];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
struct HTX_REPORT_WIRELESS
 | 
			
		||||
struct REPORT_WIRELESS
 | 
			
		||||
{
 | 
			
		||||
    htx_report_header_t header;
 | 
			
		||||
    report_header_t header;
 | 
			
		||||
 | 
			
		||||
    uint8_t mouse_connected; // 0 if disconnected, else 1
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(htx_report_header_t) - 1];
 | 
			
		||||
    uint8_t zeros[REPORT_MAX_SIZE - sizeof(report_header_t) - 1];
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
CC=gcc
 | 
			
		||||
CFLAGS=$(shell pkg-config --cflags libusb-1.0) -O3 -Wall -shared
 | 
			
		||||
LDFLAGS=$(shell pkg-config --libs libusb-1.0)
 | 
			
		||||
 | 
			
		||||
BUILD_DIR=../../../build/
 | 
			
		||||
 | 
			
		||||
all: $(BUILD_DIR)/drivers/gwolves-htx.so
 | 
			
		||||
 | 
			
		||||
$(BUILD_DIR)/drivers/gwolves-htx.so: htx.c | $(BUILD_DIR)/drivers/
 | 
			
		||||
	$(CC) $(CFLAGS) -o $@ $^
 | 
			
		||||
$(BUILD_DIR)/drivers/assets/gwolves-htx.png: htx_0.png | $(BUILD_DIR)/drivers/assets
 | 
			
		||||
	cp $^ $@
 | 
			
		||||
		Reference in New Issue
	
	Block a user