1
0
mirror of https://github.com/MatMoul/g810-led.git synced 2024-12-23 01:06:11 +00:00

Add new arg -tuk for testing unsuported keyboard

This commit is contained in:
MatMoul 2017-05-06 22:41:08 +02:00
parent 11865ca560
commit ebb41b8037
5 changed files with 75 additions and 18 deletions

View File

@ -63,6 +63,19 @@ Linux led controller for Logitech G213, G410, G610, G810 and G910 Keyboards.</br
`g810-led -pp < profilefile # Load a profile`</br>
`echo -e "k w ff0000\nk a ff0000\nk s ff0000\nk d ff0000\nc" | g810-led -pp # Set multiple keys`</br>
## Testing unsuported keyboards :</br>
Start by retrieve the VendorID and the ProductID of your keyboard with lsusb.</br>
`lsusb`</br>
Sample return :<br>
`Bus 001 Device 001: ID 046d:c331 Logitech, Inc.`</br>
In this sample VendorID is 046d and ProductID is c331. Now test your keyboard with all supported protocol :</br>
`g810-led -dv 046d -dp c331 -tuk 1 -a 000000`</br>
If your keyboard set all key to off you have found the protocol (1), if not continue.</br>
`g810-led -dv 046d -dp c331 -tuk 2 -a 000000`</br>
If your keyboard set all key to off you have found the protocol (2), if not continue.</br>
`g810-led -dv 046d -dp c331 -tuk 3 -a 000000`</br>
If your keyboard set all key to off you have found the protocol (3), if not, need new dump.</br>
## Building and linking against the libg810-led library :</br>
Include in implementing source files.</br>
```cpp

View File

@ -21,6 +21,15 @@ LedKeyboard::~LedKeyboard() {
}
bool LedKeyboard::overrideKeyboard(uint16_t vendorID, uint16_t productID, KeyboardModel model) {
if(model==KeyboardModel::unknown) return false;
SupportedKeyboards = {
{ vendorID, productID, (u_int16_t)model }
};
return true;
}
vector<LedKeyboard::DeviceInfo> LedKeyboard::listKeyboards() {
vector<LedKeyboard::DeviceInfo> deviceList;

View File

@ -16,7 +16,7 @@ class LedKeyboard {
private:
const std::vector<std::vector<uint16_t>> SupportedKeyboards = {
std::vector<std::vector<uint16_t>> SupportedKeyboards = {
{ 0x46d, 0xc336, (u_int16_t)KeyboardModel::g213 },
{ 0x46d, 0xc330, (u_int16_t)KeyboardModel::g410 },
{ 0x46d, 0xc333, (u_int16_t)KeyboardModel::g610 },
@ -27,7 +27,6 @@ class LedKeyboard {
{ 0x46d, 0xc335, (u_int16_t)KeyboardModel::g910 }
};
enum class KeyAddressGroup : uint8_t {
logo = 0x00,
indicators,
@ -135,6 +134,8 @@ class LedKeyboard {
~LedKeyboard();
bool overrideKeyboard(uint16_t vendorID, uint16_t productID, KeyboardModel model);
std::vector<DeviceInfo> listKeyboards();
bool isOpen();

View File

@ -53,19 +53,21 @@ namespace help {
cout<<" -dv\t\t\t\t\tDevice vendor ID, such as 046d for Logitech. Can be omitted to match any vendor ID"<<endl;
cout<<" -dp\t\t\t\t\tDevice product ID, such as c337 for Logitech G810. Can be omitted to match any product ID"<<endl;
cout<<" -ds\t\t\t\t\tDevice serial number, Can be omitted to match the first device found"<<endl;
cout<<"--------"<<endl;
cout<<" -tuk\t\t\t\t\tTest unsuported keyboard with one of supported protocol (1-3) -dv and -dp are required"<<endl;
cout<<endl;
cout<<"Values:"<<endl;
if (cmdName == "g610-led")
cout<<"color formats :\t\t\t\tII (hex value for intensity)"<<endl;
cout<<" color formats :\t\t\tII (hex value for intensity)"<<endl;
else
cout<<"color formats :\t\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
cout<<" color formats :\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
if (cmdName == "g213-led") {
cout<<"region formats :\t\t\tRN (integer value for region, 1 to 5)"<<endl;
cout<<" region formats :\t\tRN (integer value for region, 1 to 5)"<<endl;
}
cout<<"speed formats :\t\t\t\tSS (hex value for speed 01 to ff)"<<endl;
cout<<""<<endl;
cout<<"key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl;
cout<<"group values :\t\t\t\tlogo, indicators, fkeys, ... (use --help-keys for more detail)"<<endl;
cout<<"startup mode :\t\t\t\twave, color"<<endl;
cout<<" speed formats :\t\t\tSS (hex value for speed 01 to ff)"<<endl;
cout<<endl;
cout<<" key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl;
cout<<" group values :\t\t\tlogo, indicators, fkeys, ... (use --help-keys for more detail)"<<endl;
cout<<" startup mode :\t\t\twave, color"<<endl;
cout<<endl;
}
@ -254,9 +256,21 @@ namespace help {
cout<<"g610-led -k logo ff # Set intensity of a key"<<endl;
cout<<"g610-led -g fkeys aa # Set intensity of a group of keys"<<endl;
cout<<endl;
cout<<"Samples for g213 :"<<endl;
cout<<"g213-led -a 00ff00 # Set color of all keys"<<endl;
cout<<"g213-led -r 1 ff0000 # Set region 1 red"<<endl;
cout<<endl;
cout<<"Samples with pipe (for effects) :"<<endl;
cout<<"g810-led -pp < profilefile # Load a profile"<<endl;
cout<<"echo -e \"k w ff0000\\nk a ff0000\\nk s ff0000\\nk d ff0000\\nc\" | g810-led -pp # Set multiple keys"<<endl;
cout<<endl;
cout<<"Testing an unsuported keyboard :"<<endl;
cout<<"lsusb"<<endl;
cout<<"#Sample result of lsusb : ID 046d:c331 Logitech, Inc. (dv=046d and dp=c331)"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 1 -a 000000"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 2 -a 000000"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 3 -a 000000"<<endl;
cout<<""<<endl;
}
}

View File

@ -24,7 +24,10 @@ void printDeviceInfo(LedKeyboard::DeviceInfo device) {
int listKeyboards(LedKeyboard &kbd) {
std::vector<LedKeyboard::DeviceInfo> deviceList = kbd.listKeyboards();
if (deviceList.empty()) return 1;
if (deviceList.empty()) {
std::cout<<"Matching or compatible device not found !"<<std::endl;
return 1;
}
std::vector<LedKeyboard::DeviceInfo>::iterator iterator;
for (iterator = deviceList.begin(); iterator != deviceList.end(); iterator++) {
@ -267,18 +270,35 @@ int main(int argc, char **argv) {
serial = argv[argIndex + 1];
argIndex += 2;
continue;
}
else if (argc > (argIndex + 1) && arg == "-dv"){
} else if (argc > (argIndex + 1) && arg == "-dv"){
if (! utils::parseUInt16(argv[argIndex + 1], vendorID)) return 1;
argIndex += 2;
continue;
}
else if (argc > (argIndex + 1) && arg == "-dp"){
} else if (argc > (argIndex + 1) && arg == "-dp"){
if (! utils::parseUInt16(argv[argIndex + 1], productID)) return 1;
argIndex += 2;
continue;
} else if (argc > (argIndex + 1) && arg == "-tuk"){
uint8_t kbdProtocol = 0;
if (! utils::parseUInt8(argv[argIndex + 1], kbdProtocol)) return 1;
switch(kbdProtocol) {
case 1:
kbd.overrideKeyboard(vendorID, productID, LedKeyboard::KeyboardModel::g810);
break;
case 2:
kbd.overrideKeyboard(vendorID, productID, LedKeyboard::KeyboardModel::g910);
break;
case 3:
kbd.overrideKeyboard(vendorID, productID, LedKeyboard::KeyboardModel::g213);
break;
default:
break;
}
argIndex += 2;
continue;
}
//Commands that do not need to initialize a specific device
if (arg == "--help" || arg == "-h") {help::usage(argv[0]); return 0;}
else if (arg == "--list-keyboards") return listKeyboards(kbd);
@ -288,7 +308,7 @@ int main(int argc, char **argv) {
//Initialize the device for use
if (!kbd.open(vendorID, productID, serial)) {
std::cout << "Matching or compatible device not found" << std::endl;
std::cout << "Matching or compatible device not found !" << std::endl;
return 2;
}