From 44e029c57dc0b37a45f01f0aa180ebd96c5bd1b5 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sun, 7 Aug 2016 19:40:48 +0200 Subject: [PATCH] Add G410 support --- src/classes/Keyboard.cpp | 4 ++-- src/classes/Keyboard.h | 2 +- src/main.cpp | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 687bf7c..bbf078f 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -12,12 +12,12 @@ bool Keyboard::isAttached() { return m_isAttached; } -bool Keyboard::attach() { +bool Keyboard::attach(int lg_pid) { if (m_isAttached == true) return false; int r; r = libusb_init(&ctx); if (r < 0) return false; - dev_handle = libusb_open_device_with_vid_pid(ctx, 0x046d, 0xc331); + dev_handle = libusb_open_device_with_vid_pid(ctx, 0x046d, lg_pid); if (dev_handle == NULL) { libusb_exit(ctx); ctx = NULL; diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index 5bd2e97..45cdefe 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -33,7 +33,7 @@ class Keyboard { struct KeyValue { KeyAddress key; KeyColors colors; }; bool isAttached(); - bool attach(); + bool attach(int lg_pid); bool detach(); bool commit(); bool getKeyAddress(Key key, KeyAddress &keyAddress); diff --git a/src/main.cpp b/src/main.cpp index 4540b6b..d77eabf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,13 +4,16 @@ #include #include #include +#include #include "classes/Keyboard.h" using namespace std; +int lg_pid = 0xc331; void usage() { - cout<<"g810-led Usages :\n"; + if (lg_pid == 0xc330) cout << "g410-led Usages :\n"; + else cout<<"g810-led Usages :\n"; cout<<"-----------------\n"; cout<<"\n"; cout<<" -s effect :\t\tSet keyboard startup effect\n"; @@ -44,7 +47,7 @@ void usage() { int commit() { Keyboard g810; - g810.attach(); + g810.attach(lg_pid); g810.commit(); g810.detach(); @@ -55,7 +58,7 @@ int setStartupEffect(string effect) { Keyboard g810; Keyboard::PowerOnEffect powerOnEffect; if (g810.parsePowerOnEffect(effect, powerOnEffect) == true) { - g810.attach(); + g810.attach(lg_pid); g810.setPowerOnEffect(powerOnEffect); g810.commit(); g810.detach(); @@ -73,7 +76,7 @@ int setKey(string key, string color, bool commit) { Keyboard::KeyValue keyValue; keyValue.key = keyAddress; keyValue.colors = colors; - g810.attach(); + g810.attach(lg_pid); g810.setKey(keyValue); if (commit == true) g810.commit(); g810.detach(); @@ -87,7 +90,7 @@ int setAllKeys(string color, bool commit) { Keyboard g810; Keyboard::KeyColors colors; if (g810.parseColor(color, colors) == true) { - g810.attach(); + g810.attach(lg_pid); g810.setAllKeys(colors); if (commit == true) g810.commit(); g810.detach(); @@ -102,7 +105,7 @@ int setGroupKeys(string groupKeys, string color, bool commit) { if (g810.parseKeyGroup(groupKeys, keyGroup) == true) { Keyboard::KeyColors colors; if (g810.parseColor(color, colors) == true) { - g810.attach(); + g810.attach(lg_pid); g810.setGroupKeys(keyGroup, colors); if (commit == true) g810.commit(); g810.detach(); @@ -131,7 +134,7 @@ int loadProfile(string profileFile) { map var; vector keys; - g810.attach(); + g810.attach(lg_pid); while (!file.eof()) { getline(file, line); @@ -204,6 +207,10 @@ int loadProfile(string profileFile) { int main(int argc, char *argv[]) { + string str = argv[0]; + size_t split = str.find_last_of("/\\"); + str = str.substr(split + 1); + if (str == "g410-led") lg_pid = 0xc330; if (argc > 1) { string argCmd = argv[1]; if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }