Merge pull request #31 from Kirili4ik/master

Add support of 4 devices + instructions + logging from other PRs
This commit is contained in:
Mateusz Nowotyński
2021-09-15 19:13:48 +02:00
committed by GitHub
3 changed files with 67 additions and 11 deletions

View File

@@ -33,8 +33,22 @@ void Mouse::discoverDevices() {
libusb_device_descriptor desc;
libusb_get_device_descriptor(devs[i], &desc);
if (isCompatibleDevice(desc)) {
if(libusb_open(devs[i], &currentDevice) != 0)
continue;
switch (int status = libusb_open(devs[i], &currentDevice)) {
case 0:
break;
case LIBUSB_ERROR_NO_MEM:
cout << "LIBUSB_ERROR_NO_MEM" << endl;
continue;
case LIBUSB_ERROR_ACCESS:
cout << "LIBUSB_ERROR_ACCESS" << endl;
continue;
case LIBUSB_ERROR_NO_DEVICE:
cout << "LIBUSB_ERROR_NO_DEVICE" << endl;
continue;
default:
cout << "Status: " << status << endl;
continue;
}
if(libusb_kernel_driver_active(currentDevice, 2) == 1)
if(libusb_detach_kernel_driver(currentDevice, 2) != 0) {
@@ -90,14 +104,26 @@ int Mouse::setBackLightLevel(uint8_t level) {
}
int Mouse::writeToMouse(uint8_t data[], size_t size) {
int res = libusb_control_transfer(currentDevice,0x21,9,
0x0307,2,data,size,10000);
if(res < 0){
cout<<"Unnable to send command"<<endl;
return -1;
int res = libusb_control_transfer(currentDevice, 0x21, 9,
0x0307, 2, data, size, 10000);
switch (res){
case LIBUSB_ERROR_TIMEOUT:
cout << "LIBUSB_ERROR_TIMEOUT" << endl;
return -1;
case LIBUSB_ERROR_PIPE:
cout << "LIBUSB_ERROR_PIPE" << endl;
return -1;
case LIBUSB_ERROR_NO_DEVICE:
cout << "LIBUSB_ERROR_NO_DEVICE" << endl;
return -1;
case LIBUSB_ERROR_BUSY:
cout << "LIBUSB_ERROR_BUSY" << endl;
return -1;
case LIBUSB_ERROR_INVALID_PARAM:
cout << "LIBUSB_ERROR_INVALID_PARAM" << endl;
default:
return 0;
}
return 0;
}
int Mouse::readFromMouse(uint8_t *request, size_t requestSize, uint8_t *response, size_t responseSize) {
@@ -166,6 +192,18 @@ void Mouse::listDevices() {
case BLOODY_A9_PID:
name = "Bloody A9";
break;
case BLOODY_RT5_PID:
name = "Bloody RT5";
break;
case BLOODY_V8M_PID:
name = "Bloody V8M";
break;
case BLOODY_R8_PID:
name = "Bloody R8";
break;
case BLOODY_J95S_PID:
name = "Bloody J95S";
break;
default:
name = "Unknown";
}

View File

@@ -9,6 +9,10 @@
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;
@@ -20,7 +24,7 @@ static const int BLOODY_R70_PID = 0xf643;
static const int BLOODY_A7_PID = 0x7e36;
static const int BLOODY_A9_PID = 0x1003;
static const int COMPATIBLE_PIDS[] = {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};
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};
static const size_t COMPATIBLE_PIDS_SIZE = sizeof(COMPATIBLE_PIDS)/sizeof(COMPATIBLE_PIDS[0]);
static const int A4TECH_MAGIC = 0x07;

View File

@@ -14,7 +14,21 @@ cmake .
make
```
# Usage
## Add new bloody devices
1. Get USB PID of device:
```
~$ lsusb -d 09da: | cut -d ' ' -f6 | cut -d ':' -f2
```
2. Add that PID to Mouce.h & Mouce.cpp
Mouse.h: add line with PID and add name to COMPATIBLE_PIDS variable as all the other mouses.
Mouse.cpp: add 3 lines: case, name and break; as all the other mouses.
## Run
```
sudo ./bloody
Available devices: