From ebb41b80374f07f4e1aee147b17a26dd6d995d6c Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sat, 6 May 2017 22:41:08 +0200 Subject: [PATCH] Add new arg -tuk for testing unsuported keyboard --- README.md | 13 +++++++++++++ src/classes/Keyboard.cpp | 9 +++++++++ src/classes/Keyboard.h | 5 +++-- src/helpers/help.cpp | 32 +++++++++++++++++++++++--------- src/main.cpp | 34 +++++++++++++++++++++++++++------- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6bffe8f..7094223 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,19 @@ Linux led controller for Logitech G213, G410, G610, G810 and G910 Keyboards.
`echo -e "k w ff0000\nk a ff0000\nk s ff0000\nk d ff0000\nc" | g810-led -pp # Set multiple keys`
+## Testing unsuported keyboards :
+Start by retrieve the VendorID and the ProductID of your keyboard with lsusb.
+`lsusb`
+Sample return :
+`Bus 001 Device 001: ID 046d:c331 Logitech, Inc.`
+In this sample VendorID is 046d and ProductID is c331. Now test your keyboard with all supported protocol :
+`g810-led -dv 046d -dp c331 -tuk 1 -a 000000`
+If your keyboard set all key to off you have found the protocol (1), if not continue.
+`g810-led -dv 046d -dp c331 -tuk 2 -a 000000`
+If your keyboard set all key to off you have found the protocol (2), if not continue.
+`g810-led -dv 046d -dp c331 -tuk 3 -a 000000`
+If your keyboard set all key to off you have found the protocol (3), if not, need new dump.
+ ## Building and linking against the libg810-led library :
Include in implementing source files.
```cpp diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 2ecaceb..bb13e7c 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -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::listKeyboards() { vector deviceList; diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index b87698d..b98e969 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -16,7 +16,7 @@ class LedKeyboard { private: - const std::vector> SupportedKeyboards = { + std::vector> 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 listKeyboards(); bool isOpen(); diff --git a/src/helpers/help.cpp b/src/helpers/help.cpp index 573b188..404fd0e 100644 --- a/src/helpers/help.cpp +++ b/src/helpers/help.cpp @@ -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"< deviceList = kbd.listKeyboards(); - if (deviceList.empty()) return 1; + if (deviceList.empty()) { + std::cout<<"Matching or compatible device not found !"<::iterator iterator; for (iterator = deviceList.begin(); iterator != deviceList.end(); iterator++) { @@ -267,17 +270,34 @@ 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;} @@ -288,10 +308,10 @@ 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; } - + // Command arguments, these will cause parsing to ignore anything beyond the command and its arguments if (arg == "-c") return commit(kbd); else if (arg == "--print-device") {printDeviceInfo(kbd.getCurrentDevice()); return 0;}