[CLEAN] Cleaned dpi code
Cleaned, moved it to Mouse.cpp and Mouse.h files, optimised using array with binary args.
This commit is contained in:
12
Mouse.cpp
12
Mouse.cpp
@@ -2,8 +2,11 @@
|
||||
// Created by maxmati on 4/18/15.
|
||||
//
|
||||
|
||||
#include "Mouse.h"
|
||||
// DPI change support added by SouceCalve on 27/11/25.
|
||||
|
||||
|
||||
#include "Mouse.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using std::cout; using std::endl;
|
||||
@@ -151,7 +154,12 @@ uint8_t Mouse::getBackLightLevel() {
|
||||
return response[8];
|
||||
}
|
||||
|
||||
|
||||
uint8_t Mouse::setDPI(uint8_t dpi){
|
||||
if(dpi < 0 || dpi > 40) dpi=32;
|
||||
uint8_t data[72] = {A4TECH_MAGIC, DPI_SET_OPCODE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x1a,0x88,0x02,0x00, };
|
||||
memcpy(data + 10, dpi_binary+dpi*3, 3);
|
||||
return writeToMouse(data, sizeof(data));
|
||||
}
|
||||
|
||||
void Mouse::listDevices() {
|
||||
std::cout<<"Available devices:"<<endl;
|
||||
|
||||
8
Mouse.h
8
Mouse.h
@@ -35,7 +35,7 @@ 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};
|
||||
|
||||
class Mouse {
|
||||
public:
|
||||
@@ -47,15 +47,11 @@ public:
|
||||
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 dpi);
|
||||
private:
|
||||
std::map<int, libusb_device_handle*> devices;
|
||||
libusb_device_handle* currentDevice = nullptr;
|
||||
libusb_context* context = nullptr;
|
||||
|
||||
|
||||
//int readFromMouse(uint8_t* request, size_t requestSize, uint8_t* response, size_t responseSize);
|
||||
|
||||
void discoverDevices();
|
||||
|
||||
bool isCompatibleDevice(libusb_device_descriptor &desc);
|
||||
};
|
||||
|
||||
196
main.cpp
196
main.cpp
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include "Mouse.h"
|
||||
#include <cstring>
|
||||
|
||||
int main() {
|
||||
Mouse m;
|
||||
int address, level, DPI_level;
|
||||
@@ -15,199 +15,21 @@ int main() {
|
||||
std::cout<<"Current backlight level: "<<(int)m.getBackLightLevel()<<std::endl;
|
||||
|
||||
do {
|
||||
std::cout << "Select backlight level(0-3):";
|
||||
std::cout << "Select backlight level(0-3): ";
|
||||
std::cin >> level;
|
||||
}while(m.setBackLightLevel(level) < 0);
|
||||
|
||||
uint8_t data[72] = {A4TECH_MAGIC, DPI_SET_OPCODE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x1a,0x88,0x02,0x00, };
|
||||
|
||||
do {
|
||||
std::cout << "Select DPI(100-4000):";
|
||||
std::cout << "Select DPI(100-4000): ";
|
||||
std::cin >> DPI_level;
|
||||
}while(DPI_level < 0 || DPI_level > 4000);
|
||||
|
||||
switch(DPI_level){
|
||||
case 100:
|
||||
printf("Setting it to 100, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 200:
|
||||
printf("Setting it to 200, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x10, 0x10, 0x81}, 3);
|
||||
break;
|
||||
case 300:
|
||||
printf("Setting it to 300, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x10, 0x10, 0x81}, 3);
|
||||
break;
|
||||
case 400:
|
||||
printf("Setting it to 400, boss\n"); //остановился здесь(3200 тоже прописал)
|
||||
memcpy(data + 10, (uint8_t[]){0x0d, 0x0d, 0x82}, 3);
|
||||
break;
|
||||
case 500:
|
||||
printf("Setting it to 500, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x10, 0x10, 0x82}, 3);
|
||||
break;
|
||||
case 600:
|
||||
printf("Setting it to 600, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 700:
|
||||
printf("Setting it to 700, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 800:
|
||||
printf("Setting it to 800, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 900:
|
||||
printf("Setting it to 900, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1000:
|
||||
printf("Setting it to 1000, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1100:
|
||||
printf("Setting it to 1100, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1200:
|
||||
printf("Setting it to 1200, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1300:
|
||||
printf("Setting it to 1300, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1400:
|
||||
printf("Setting it to 1400, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1500:
|
||||
printf("Setting it to 1500, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1600:
|
||||
printf("Setting it to 1600, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1700:
|
||||
printf("Setting it to 1700, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1800:
|
||||
printf("Setting it to 1800, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 1900:
|
||||
printf("Setting it to 1900, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2000:
|
||||
printf("Setting it to 2000, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2100:
|
||||
printf("Setting it to 2100, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2200:
|
||||
printf("Setting it to 2200, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2300:
|
||||
printf("Setting it to 2300, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2400:
|
||||
printf("Setting it to 2400, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2500:
|
||||
printf("Setting it to 2500, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2600:
|
||||
printf("Setting it to 2600, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2700:
|
||||
printf("Setting it to 2700, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2800:
|
||||
printf("Setting it to 2800, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 2900:
|
||||
printf("Setting it to 2900, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3000:
|
||||
printf("Setting it to 3000, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3100:
|
||||
printf("Setting it to 3100, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3200:
|
||||
printf("Setting it to 3200, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x1a, 0x1a, 0x88}, 3);
|
||||
break;
|
||||
case 3300:
|
||||
printf("Setting it to 3300, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3400:
|
||||
printf("Setting it to 3400, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3500:
|
||||
printf("Setting it to 3500, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3600:
|
||||
printf("Setting it to 3600, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3700:
|
||||
printf("Setting it to 3700, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3800:
|
||||
printf("Setting it to 3800, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 3900:
|
||||
printf("Setting it to 3900, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
case 4000:
|
||||
printf("Setting it to 4000, boss\n");
|
||||
memcpy(data + 10, (uint8_t[]){0x07, 0x07, 0x81}, 3);
|
||||
break;
|
||||
default:
|
||||
printf("Setting it to %d, boss\n", default_dpi);
|
||||
break;
|
||||
if(DPI_level < 100 || DPI_level > 4000) std::cout<<"Bad number. Try again!\n"<<std::endl;
|
||||
}while(DPI_level < 100 || DPI_level > 4000);
|
||||
|
||||
printf("Setting it to %d, boss!\n", DPI_level);
|
||||
int error = m.setDPI(DPI_level/100-1);
|
||||
if(error != 0){
|
||||
std::cout<<"Sorry boss, i cant... err: "<<(int)error<<std::endl;
|
||||
}
|
||||
|
||||
//uint8_t data[72] = {A4TECH_MAGIC, DPI_SET_OPCODE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x1a,0x88,0x02,0x00, };
|
||||
|
||||
int error = m.writeToMouse(data, sizeof(data));
|
||||
printf("Code: %d\n", error);
|
||||
/*for(int x = 0; x<71; x++){
|
||||
std::cout<<(int)data[x]<<std::endl;
|
||||
}*/
|
||||
//uint8_t request[72] = {A4TECH_MAGIC, DPI_SET_OPCODE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1a,0x1a,0x88,0x02,0x00};
|
||||
//uint8_t response[72];
|
||||
|
||||
//m.readFromMouse(request, sizeof(request), response, sizeof(response));
|
||||
//for(int x = 0; x < 71; x++){
|
||||
// std::cout<<(int)response[x]<<std::endl;
|
||||
//}
|
||||
//std::cout<<"Current backlight level: "<<(int)m.getBackLightLevel()<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user