59 lines
2.6 KiB
C++
59 lines
2.6 KiB
C++
//
|
|
// Created by maxmati on 4/18/15.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
#include <libusb.h>
|
|
|
|
static const int A4TECH_VID = 0x09da;
|
|
|
|
static const int BLOODY_J95S_PID = 0xfee3;
|
|
static const int BLOODY_RT5_PID = 0x7f1b;
|
|
static const int BLOODY_V8M_PID = 0x1094;
|
|
static const int BLOODY_R8_PID = 0x7c10;
|
|
static const int BLOODY_V5_PID = 0x172A;
|
|
static const int BLOODY_V7_PID = 0xF613;
|
|
static const int BLOODY_V8_PID = 0x11F5;
|
|
static const int BLOODY_R7_PID = 0x1485;
|
|
static const int BLOODY_R8_1_PID = 0x14ee;
|
|
static const int BLOODY_R3_PID = 0x1a5a;
|
|
static const int BLOODY_AL9_PID = 0xf633;
|
|
static const int BLOODY_R70_PID = 0xf643;
|
|
static const int BLOODY_A7_PID = 0x7e36;
|
|
static const int BLOODY_A9_PID = 0x1003;
|
|
static const int BLOODY_RT7_PID = 0x144d;
|
|
|
|
static const int COMPATIBLE_PIDS[] = {BLOODY_J95S_PID, BLOODY_RT5_PID, BLOODY_V8M_PID, BLOODY_R8_PID, BLOODY_V5_PID, BLOODY_V7_PID, BLOODY_V8_PID, BLOODY_R7_PID, BLOODY_R8_1_PID, BLOODY_R3_PID, BLOODY_AL9_PID, BLOODY_R70_PID, BLOODY_A7_PID, BLOODY_A9_PID, BLOODY_RT7_PID};
|
|
static const size_t COMPATIBLE_PIDS_SIZE = sizeof(COMPATIBLE_PIDS)/sizeof(COMPATIBLE_PIDS[0]);
|
|
|
|
static const int A4TECH_MAGIC = 0x07;
|
|
|
|
static const int BACKLIGHT_OPCODE = 0x11;
|
|
static const int BACKLIGHT_WRITE = 0x80;
|
|
static const int BACKLIGHT_READ = 0x00;
|
|
|
|
static const int DPI_SET_OPCODE = 0x0d;
|
|
static const uint8_t dpi_binary[120] = {0x07,0x07,0x81,0x10,0x10,0x81,0x10,0x10,0x81,0x0d,0x0d,0x82,0x10,0x10,0x82,0x0d,0x0d,0x83,0x10,0x10,0x83,0x10,0x10,0x83,0x0f,0x0f,0x84,0x10,0x10,0x84,0x0e,0x0e,0x85,0x10,0x10,0x85,0x10,0x10,0x85,0x0f,0x0f,0x86,0x10,0x10,0x86,0x0f,0x0f,0x87,0x10,0x10,0x87,0x10,0x10,0x87,0x0f,0x0f,0x88,0x10,0x10,0x88,0x11,0x11,0x88,0x12,0x12,0x88,0x13,0x13,0x88,0x14,0x14,0x88,0x15,0x15,0x88,0x16,0x16,0x88,0x17,0x17,0x88,0x18,0x18,0x88,0x19,0x19,0x88,0x1a,0x1a,0x88,0x1b,0x1b,0x88,0x1c,0x1c,0x88,0x1d,0x1d,0x88,0x1e,0x1e,0x88,0x1e,0x1e,0x88,0x1f,0x1f,0x88,0x1f,0x1f,0x88};
|
|
static const uint8_t rate_binary[4] = {0x08,0x04,0x02,0x02}; //4 entryes because 500/125-1 produces 3, not 2
|
|
|
|
class Mouse {
|
|
public:
|
|
~Mouse();
|
|
void init();
|
|
void listDevices();
|
|
bool selectDevice(int address);
|
|
int setBackLightLevel(uint8_t level);
|
|
uint8_t getBackLightLevel();
|
|
int readFromMouse(uint8_t *request, size_t requestSize, uint8_t *response, size_t responseSize);
|
|
int writeToMouse(uint8_t data[], size_t size);
|
|
uint8_t setDPI(uint8_t rate, uint8_t dpi);
|
|
private:
|
|
std::map<int, libusb_device_handle*> devices;
|
|
libusb_device_handle* currentDevice = nullptr;
|
|
libusb_context* context = nullptr;
|
|
void discoverDevices();
|
|
bool isCompatibleDevice(libusb_device_descriptor &desc);
|
|
};
|