mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 01:06:11 +00:00
Add support for device interface numbers when using hidapi
This commit is contained in:
parent
1c84af312a
commit
835aca7346
@ -163,7 +163,7 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
|
||||
|
||||
while (dev) {
|
||||
for (int i=0; i<(int)SupportedKeyboards.size(); i++) {
|
||||
if (dev->vendor_id == SupportedKeyboards[i][0] && dev->product_id == SupportedKeyboards[i][1]) {
|
||||
if (dev->vendor_id == SupportedKeyboards[i][0] && dev->product_id == SupportedKeyboards[i][1] && dev->interface_number == SupportedKeyboards[i][2]) {
|
||||
if (!serial.empty() && dev->serial_number != NULL && wideSerial.compare(dev->serial_number) != 0) break; //Serial didn't match
|
||||
|
||||
if (dev->serial_number != NULL) {
|
||||
@ -188,7 +188,8 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
|
||||
|
||||
currentDevice.vendorID = dev->vendor_id;
|
||||
currentDevice.productID = dev->product_id;
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][2];
|
||||
currentDevice.path = dev->path;
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][3];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -204,8 +205,7 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wideSerial.empty()) m_hidHandle = hid_open(currentDevice.vendorID, currentDevice.productID, NULL);
|
||||
else m_hidHandle = hid_open(currentDevice.vendorID, currentDevice.productID, wideSerial.c_str());
|
||||
m_hidHandle = hid_open_path(currentDevice.path.c_str());
|
||||
|
||||
if(m_hidHandle == 0) {
|
||||
hid_exit();
|
||||
@ -248,7 +248,7 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
|
||||
currentDevice.serialNumber = serial;
|
||||
currentDevice.vendorID = desc.idVendor;
|
||||
currentDevice.productID = desc.idProduct;
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][2];
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][3];
|
||||
|
||||
dev = device;
|
||||
libusb_close(m_hidHandle);
|
||||
@ -276,7 +276,7 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
|
||||
}
|
||||
currentDevice.vendorID = desc.idVendor;
|
||||
currentDevice.productID = desc.idProduct;
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][2];
|
||||
currentDevice.model = (KeyboardModel)SupportedKeyboards[i][3];
|
||||
if (libusb_get_string_descriptor_ascii(m_hidHandle, desc.iManufacturer, buf, 256) >= 1) currentDevice.manufacturer = string((char*)buf);
|
||||
if (libusb_get_string_descriptor_ascii(m_hidHandle, desc.iProduct, buf, 256) >= 1) currentDevice.product = string((char*)buf);
|
||||
if (libusb_get_string_descriptor_ascii(m_hidHandle, desc.iSerialNumber, buf, 256) >= 1) currentDevice.serialNumber = string((char*)buf);
|
||||
|
@ -45,20 +45,20 @@ class LedKeyboard {
|
||||
public:
|
||||
|
||||
std::vector<std::vector<uint16_t>> SupportedKeyboards = {
|
||||
{ 0x46d, 0xc336, (uint16_t)KeyboardModel::g213 },
|
||||
{ 0x46d, 0xc330, (uint16_t)KeyboardModel::g410 },
|
||||
{ 0x46d, 0xc33a, (uint16_t)KeyboardModel::g413 },
|
||||
{ 0x46d, 0xc342, (uint16_t)KeyboardModel::g512 },
|
||||
{ 0x46d, 0xc33c, (uint16_t)KeyboardModel::g513 },
|
||||
{ 0x46d, 0xc333, (uint16_t)KeyboardModel::g610 },
|
||||
{ 0x46d, 0xc338, (uint16_t)KeyboardModel::g610 },
|
||||
{ 0x46d, 0xc331, (uint16_t)KeyboardModel::g810 },
|
||||
{ 0x46d, 0xc337, (uint16_t)KeyboardModel::g810 },
|
||||
{ 0x46d, 0xc33f, (uint16_t)KeyboardModel::g815 },
|
||||
{ 0x46d, 0xc32b, (uint16_t)KeyboardModel::g910 },
|
||||
{ 0x46d, 0xc335, (uint16_t)KeyboardModel::g910 },
|
||||
{ 0x46d, 0xc541, (uint16_t)KeyboardModel::g915 },
|
||||
{ 0x46d, 0xc339, (uint16_t)KeyboardModel::gpro }
|
||||
{ 0x46d, 0xc336, 1, (uint16_t)KeyboardModel::g213 },
|
||||
{ 0x46d, 0xc330, 1, (uint16_t)KeyboardModel::g410 },
|
||||
{ 0x46d, 0xc33a, 1, (uint16_t)KeyboardModel::g413 },
|
||||
{ 0x46d, 0xc342, 1, (uint16_t)KeyboardModel::g512 },
|
||||
{ 0x46d, 0xc33c, 1, (uint16_t)KeyboardModel::g513 },
|
||||
{ 0x46d, 0xc333, 1, (uint16_t)KeyboardModel::g610 },
|
||||
{ 0x46d, 0xc338, 1, (uint16_t)KeyboardModel::g610 },
|
||||
{ 0x46d, 0xc331, 1, (uint16_t)KeyboardModel::g810 },
|
||||
{ 0x46d, 0xc337, 1, (uint16_t)KeyboardModel::g810 },
|
||||
{ 0x46d, 0xc33f, 1, (uint16_t)KeyboardModel::g815 },
|
||||
{ 0x46d, 0xc32b, 1, (uint16_t)KeyboardModel::g910 },
|
||||
{ 0x46d, 0xc335, 1, (uint16_t)KeyboardModel::g910 },
|
||||
{ 0x46d, 0xc541, 2, (uint16_t)KeyboardModel::g915 },
|
||||
{ 0x46d, 0xc339, 1, (uint16_t)KeyboardModel::gpro }
|
||||
};
|
||||
|
||||
enum class KeyboardModel : uint8_t {
|
||||
@ -167,6 +167,7 @@ class LedKeyboard {
|
||||
std::string manufacturer = "";
|
||||
std::string product = "";
|
||||
std::string serialNumber = "";
|
||||
std::string path = "";
|
||||
KeyboardModel model;
|
||||
} DeviceInfo;
|
||||
|
||||
|
@ -108,7 +108,8 @@ 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<<" -tuk\t\t\t\t\tTest unsupported keyboard with one of supported protocol (1-3) -dv and -dp are required"<<endl;
|
||||
cout<<" -di\t\t\t\t\tDevice interface number. Can be used with -tuk argument to specify non-default device interface number"<<endl;
|
||||
cout<<" -tuk\t\t\t\t\tTest unsupported keyboard with one of supported protocol (1-5) -dv and -dp are required"<<endl;
|
||||
cout<<endl;
|
||||
cout<<"Values:"<<endl;
|
||||
if((features | KeyboardFeatures::rgb) == features)
|
||||
|
32
src/main.cpp
32
src/main.cpp
@ -271,6 +271,7 @@ int main(int argc, char **argv) {
|
||||
std::string serial;
|
||||
uint16_t vendorID = 0x0;
|
||||
uint16_t productID = 0x0;
|
||||
uint8_t interfaceNumber = 0xff;
|
||||
|
||||
int argIndex = 1;
|
||||
while (argIndex < argc)
|
||||
@ -286,32 +287,49 @@ int main(int argc, char **argv) {
|
||||
if (! utils::parseUInt16(argv[argIndex + 1], vendorID)) return 1;
|
||||
argIndex += 2;
|
||||
continue;
|
||||
} else if (argc > (argIndex + 1) && arg == "-dp"){
|
||||
if (! utils::parseUInt16(argv[argIndex + 1], productID)) return 1;
|
||||
} 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 == "-di") {
|
||||
if (!utils::parseUInt8(argv[argIndex + 1], interfaceNumber)) 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;
|
||||
uint8_t ifNum;
|
||||
LedKeyboard::KeyboardModel model = LedKeyboard::KeyboardModel::unknown;
|
||||
switch(kbdProtocol) {
|
||||
case 1:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (uint16_t)LedKeyboard::KeyboardModel::g810 } };
|
||||
ifNum = 1;
|
||||
model = LedKeyboard::KeyboardModel::g810;
|
||||
break;
|
||||
case 2:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (uint16_t)LedKeyboard::KeyboardModel::g910 } };
|
||||
ifNum = 1;
|
||||
model = LedKeyboard::KeyboardModel::g910;
|
||||
break;
|
||||
case 3:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (uint16_t)LedKeyboard::KeyboardModel::g213 } };
|
||||
ifNum = 1;
|
||||
model = LedKeyboard::KeyboardModel::g213;
|
||||
break;
|
||||
case 4:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (uint16_t)LedKeyboard::KeyboardModel::g815 } };
|
||||
ifNum = 1;
|
||||
model = LedKeyboard::KeyboardModel::g815;
|
||||
break;
|
||||
case 5:
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, (uint16_t)LedKeyboard::KeyboardModel::g915 } };
|
||||
ifNum = 2;
|
||||
model = LedKeyboard::KeyboardModel::g915;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (model != LedKeyboard::KeyboardModel::unknown) {
|
||||
if (interfaceNumber != 0xff) ifNum = interfaceNumber;
|
||||
kbd.SupportedKeyboards = { { vendorID, productID, ifNum, (uint16_t)model } };
|
||||
}
|
||||
|
||||
argIndex += 2;
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user