mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Reindent with tab
This commit is contained in:
parent
4f9b5f381b
commit
3af149101e
File diff suppressed because it is too large
Load Diff
@ -6,65 +6,65 @@
|
|||||||
|
|
||||||
class Keyboard {
|
class Keyboard {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum class KeyboardProtocol { generic, g910 };
|
enum class KeyboardProtocol { generic, g910 };
|
||||||
enum class PowerOnEffect { rainbow, color };
|
enum class PowerOnEffect { rainbow, color };
|
||||||
enum class KeyAddressGroup { logo, indicators, multimedia, keys, gkeys };
|
enum class KeyAddressGroup { logo, indicators, multimedia, keys, gkeys };
|
||||||
enum class Key { // 127 items
|
enum class Key { // 127 items
|
||||||
logo, logo2,
|
logo, logo2,
|
||||||
caps, num, scroll, game, backlight,
|
caps, num, scroll, game, backlight,
|
||||||
mute, play, stop, prev, next,
|
mute, play, stop, prev, next,
|
||||||
f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
|
f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
|
||||||
shift_left, ctrl_left, win_left, alt_left, alt_right, win_right, ctrl_right, shift_right, menu,
|
shift_left, ctrl_left, win_left, alt_left, alt_right, win_right, ctrl_right, shift_right, menu,
|
||||||
arrow_top, arrow_left, arrow_bottom, arrow_right,
|
arrow_top, arrow_left, arrow_bottom, arrow_right,
|
||||||
num_1, num_2, num_3, num_4, num_5, num_6, num_7, num_8, num_9, num_0, num_dot, num_enter, num_plus, num_minus, num_asterisk, num_slash, num_lock,
|
num_1, num_2, num_3, num_4, num_5, num_6, num_7, num_8, num_9, num_0, num_dot, num_enter, num_plus, num_minus, num_asterisk, num_slash, num_lock,
|
||||||
esc, scroll_lock,
|
esc, scroll_lock,
|
||||||
insert, del, home, end, page_up, page_down, print_screen, pause_break,
|
insert, del, home, end, page_up, page_down, print_screen, pause_break,
|
||||||
n1, n2, n3, n4, n5, n6, n7, n8, n9, n0,
|
n1, n2, n3, n4, n5, n6, n7, n8, n9, n0,
|
||||||
tab, caps_lock, space, backspace, enter,
|
tab, caps_lock, space, backspace, enter,
|
||||||
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
|
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
|
||||||
tilde, minus, equal,
|
tilde, minus, equal,
|
||||||
open_bracket, close_bracket, backslash,
|
open_bracket, close_bracket, backslash,
|
||||||
semicolon, quote, dollar,
|
semicolon, quote, dollar,
|
||||||
intl_backslash, comma, period, slash,
|
intl_backslash, comma, period, slash,
|
||||||
g1, g2, g3, g4, g5, g6, g7, g8, g9
|
g1, g2, g3, g4, g5, g6, g7, g8, g9
|
||||||
};
|
};
|
||||||
enum class KeyGroup { logo, indicators, multimedia, fkeys, modifiers, arrows, numeric, functions, keys, gkeys};
|
enum class KeyGroup { logo, indicators, multimedia, fkeys, modifiers, arrows, numeric, functions, keys, gkeys};
|
||||||
|
|
||||||
struct KeyColors { char red; char green; char blue; };
|
struct KeyColors { char red; char green; char blue; };
|
||||||
struct KeyAddress { KeyAddressGroup addressGroup; char id; };
|
struct KeyAddress { KeyAddressGroup addressGroup; char id; };
|
||||||
struct KeyValue { KeyAddress key; KeyColors colors; };
|
struct KeyValue { KeyAddress key; KeyColors colors; };
|
||||||
|
|
||||||
bool isAttached();
|
bool isAttached();
|
||||||
bool attach();
|
bool attach();
|
||||||
bool detach();
|
bool detach();
|
||||||
bool commit();
|
bool commit();
|
||||||
bool getKeyAddress(Key key, KeyAddress &keyAddress);
|
bool getKeyAddress(Key key, KeyAddress &keyAddress);
|
||||||
bool parsePowerOnEffect(std::string effect, PowerOnEffect &powerOnEffect);
|
bool parsePowerOnEffect(std::string effect, PowerOnEffect &powerOnEffect);
|
||||||
bool parseKey(std::string key, KeyAddress &keyAddress);
|
bool parseKey(std::string key, KeyAddress &keyAddress);
|
||||||
bool parseKeyGroup(std::string key, KeyGroup &keyGroup);
|
bool parseKeyGroup(std::string key, KeyGroup &keyGroup);
|
||||||
bool parseColor(std::string color, KeyColors &colors);
|
bool parseColor(std::string color, KeyColors &colors);
|
||||||
bool setPowerOnEffect(PowerOnEffect powerOnEffect);
|
bool setPowerOnEffect(PowerOnEffect powerOnEffect);
|
||||||
bool setKey(KeyValue keyValue);
|
bool setKey(KeyValue keyValue);
|
||||||
bool setKey(Key key, KeyColors colors);
|
bool setKey(Key key, KeyColors colors);
|
||||||
bool setKeys(KeyValue keyValue[], int keyValueCount);
|
bool setKeys(KeyValue keyValue[], int keyValueCount);
|
||||||
bool setAllKeys(KeyColors colors);
|
bool setAllKeys(KeyColors colors);
|
||||||
bool setGroupKeys(KeyGroup keyGroup, KeyColors colors);
|
bool setGroupKeys(KeyGroup keyGroup, KeyColors colors);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool m_isAttached = false;
|
bool m_isAttached = false;
|
||||||
bool m_isKernellDetached = false;
|
bool m_isKernellDetached = false;
|
||||||
KeyboardProtocol kbdProtocol = KeyboardProtocol::generic;
|
KeyboardProtocol kbdProtocol = KeyboardProtocol::generic;
|
||||||
libusb_device **devs;
|
libusb_device **devs;
|
||||||
libusb_device_handle *dev_handle;
|
libusb_device_handle *dev_handle;
|
||||||
libusb_context *ctx = NULL;
|
libusb_context *ctx = NULL;
|
||||||
|
|
||||||
bool populateAddressGroupInternal(KeyAddressGroup addressGroup, unsigned char *data);
|
bool populateAddressGroupInternal(KeyAddressGroup addressGroup, unsigned char *data);
|
||||||
bool sendDataInternal(unsigned char *data, int data_size);
|
bool sendDataInternal(unsigned char *data, int data_size);
|
||||||
bool setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], int keyValueCount);
|
bool setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], int keyValueCount);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
530
src/main.cpp
530
src/main.cpp
@ -6,305 +6,305 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
string appname = "g810-led";
|
string appname = "g810-led";
|
||||||
cout<<appname<<" Usages :\n";
|
cout<<appname<<" Usages :\n";
|
||||||
cout<<"-----------------\n";
|
cout<<"-----------------\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -s effect :\t\tSet keyboard startup effect\n";
|
cout<<" -s effect :\t\tSet keyboard startup effect\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -a color :\t\tSet all keys\n";
|
cout<<" -a color :\t\tSet all keys\n";
|
||||||
cout<<" -g group, color :\tSet a group of keys\n";
|
cout<<" -g group, color :\tSet a group of keys\n";
|
||||||
cout<<" -k key, color :\tSet a key\n";
|
cout<<" -k key, color :\tSet a key\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -an color :\t\tSet all keys without commit\n";
|
cout<<" -an color :\t\tSet all keys without commit\n";
|
||||||
cout<<" -gn group, color :\tSet a group of keys without commit\n";
|
cout<<" -gn group, color :\tSet a group of keys without commit\n";
|
||||||
cout<<" -kn key, color :\tSet a key without commit\n";
|
cout<<" -kn key, color :\tSet a key without commit\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -c :\t\t\tCommit changes\n";
|
cout<<" -c :\t\t\tCommit changes\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -p profilefile :\tLoad a profile\n";
|
cout<<" -p profilefile :\tLoad a profile\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<" -h | --help :\t\tthis help message\n";
|
cout<<" -h | --help :\t\tthis help message\n";
|
||||||
cout<<" -lk | --list-keys :\tList keys in groups\n";
|
cout<<" -lk | --list-keys :\tList keys in groups\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"color formats :\t\tRRGGBB (hex value for red, green and blue)\n";
|
cout<<"color formats :\t\tRRGGBB (hex value for red, green and blue)\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"effect values :\t\trainbow, color\n";
|
cout<<"effect values :\t\trainbow, color\n";
|
||||||
cout<<"key values :\t\tabc... 123... and other\n";
|
cout<<"key values :\t\tabc... 123... and other\n";
|
||||||
cout<<"group values :\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys\n";
|
cout<<"group values :\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"sample :\n";
|
cout<<"sample :\n";
|
||||||
cout<<appname<<" -k logo ff0000\n";
|
cout<<appname<<" -k logo ff0000\n";
|
||||||
cout<<appname<<" -a 00ff00\n";
|
cout<<appname<<" -a 00ff00\n";
|
||||||
cout<<appname<<" -g fkeys ff00ff\n";
|
cout<<appname<<" -g fkeys ff00ff\n";
|
||||||
cout<<appname<<" -s color\n";
|
cout<<appname<<" -s color\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void listkeys() {
|
void listkeys() {
|
||||||
string appname = "g810-led";
|
string appname = "g810-led";
|
||||||
cout<<appname<<" Keys in groups :\n";
|
cout<<appname<<" Keys in groups :\n";
|
||||||
cout<<"-------------------------\n";
|
cout<<"-------------------------\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group logo :\n";
|
cout<<"Group logo :\n";
|
||||||
cout<<" logo\n";
|
cout<<" logo\n";
|
||||||
cout<<" logo2\n";
|
cout<<" logo2\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group indicators :\n";
|
cout<<"Group indicators :\n";
|
||||||
cout<<" num_indicator, numindicator, num\n";
|
cout<<" num_indicator, numindicator, num\n";
|
||||||
cout<<" caps_indicator, capsindicator, caps\n";
|
cout<<" caps_indicator, capsindicator, caps\n";
|
||||||
cout<<" scroll_indicator, scrollindicator, scroll\n";
|
cout<<" scroll_indicator, scrollindicator, scroll\n";
|
||||||
cout<<" game_mode, gamemode, game\n";
|
cout<<" game_mode, gamemode, game\n";
|
||||||
cout<<" back_light, backlight, light\n";
|
cout<<" back_light, backlight, light\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group fkeys :\n";
|
cout<<"Group fkeys :\n";
|
||||||
cout<<" f1 - f12\n";
|
cout<<" f1 - f12\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group modifiers :\n";
|
cout<<"Group modifiers :\n";
|
||||||
cout<<" shift_left, shiftleft, shiftl\n";
|
cout<<" shift_left, shiftleft, shiftl\n";
|
||||||
cout<<" ctrl_left, ctrlleft, ctrll\n";
|
cout<<" ctrl_left, ctrlleft, ctrll\n";
|
||||||
cout<<" win_left, winleft, win_left\n";
|
cout<<" win_left, winleft, win_left\n";
|
||||||
cout<<" alt_left, altleft, altl\n";
|
cout<<" alt_left, altleft, altl\n";
|
||||||
cout<<" alt_right, altright, altr, altgr\n";
|
cout<<" alt_right, altright, altr, altgr\n";
|
||||||
cout<<" win_right, winright, winr\n";
|
cout<<" win_right, winright, winr\n";
|
||||||
cout<<" menu\n";
|
cout<<" menu\n";
|
||||||
cout<<" ctrl_right, ctrlright, ctrlr\n";
|
cout<<" ctrl_right, ctrlright, ctrlr\n";
|
||||||
cout<<" shift_right, shiftright, shiftr\n";
|
cout<<" shift_right, shiftright, shiftr\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group multimedia :\n";
|
cout<<"Group multimedia :\n";
|
||||||
cout<<" mute\n";
|
cout<<" mute\n";
|
||||||
cout<<" play_pause, playpause, play\n";
|
cout<<" play_pause, playpause, play\n";
|
||||||
cout<<" stop\n";
|
cout<<" stop\n";
|
||||||
cout<<" previous, prev\n";
|
cout<<" previous, prev\n";
|
||||||
cout<<" next\n";
|
cout<<" next\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group arrows :\n";
|
cout<<"Group arrows :\n";
|
||||||
cout<<" arrow_top, arrowtop, top\n";
|
cout<<" arrow_top, arrowtop, top\n";
|
||||||
cout<<" arrow_left, arrowleft, left\n";
|
cout<<" arrow_left, arrowleft, left\n";
|
||||||
cout<<" arrow_bottom, arrowbottom, bottom\n";
|
cout<<" arrow_bottom, arrowbottom, bottom\n";
|
||||||
cout<<" arrow_right, arrowright, right\n";
|
cout<<" arrow_right, arrowright, right\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group numeric :\n";
|
cout<<"Group numeric :\n";
|
||||||
cout<<" num_lock, numlock\n";
|
cout<<" num_lock, numlock\n";
|
||||||
cout<<" num_slash, numslash, num/\n";
|
cout<<" num_slash, numslash, num/\n";
|
||||||
cout<<" num_asterisk, numasterisk, num*\n";
|
cout<<" num_asterisk, numasterisk, num*\n";
|
||||||
cout<<" num_minus, numminus, num-\n";
|
cout<<" num_minus, numminus, num-\n";
|
||||||
cout<<" num_plus, numplus, num+\n";
|
cout<<" num_plus, numplus, num+\n";
|
||||||
cout<<" numenter\n";
|
cout<<" numenter\n";
|
||||||
cout<<" num0 - num9\n";
|
cout<<" num0 - num9\n";
|
||||||
cout<<" num_dot, numdot, num.\n";
|
cout<<" num_dot, numdot, num.\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group functions :\n";
|
cout<<"Group functions :\n";
|
||||||
cout<<" escape, esc\n";
|
cout<<" escape, esc\n";
|
||||||
cout<<" print_screen, printscreen, printscr\n";
|
cout<<" print_screen, printscreen, printscr\n";
|
||||||
cout<<" scroll_lock, scrolllock\n";
|
cout<<" scroll_lock, scrolllock\n";
|
||||||
cout<<" pause_break, pausebreak\n";
|
cout<<" pause_break, pausebreak\n";
|
||||||
cout<<" insert, ins\n";
|
cout<<" insert, ins\n";
|
||||||
cout<<" home\n";
|
cout<<" home\n";
|
||||||
cout<<" page_up, pageup\n";
|
cout<<" page_up, pageup\n";
|
||||||
cout<<" delete, del\n";
|
cout<<" delete, del\n";
|
||||||
cout<<" end\n";
|
cout<<" end\n";
|
||||||
cout<<" page_down, pagedown\n";
|
cout<<" page_down, pagedown\n";
|
||||||
cout<<"\n";
|
cout<<"\n";
|
||||||
cout<<"Group keys :\n";
|
cout<<"Group keys :\n";
|
||||||
cout<<" 0 - 9\n";
|
cout<<" 0 - 9\n";
|
||||||
cout<<" a - z\n";
|
cout<<" a - z\n";
|
||||||
cout<<" tab\n";
|
cout<<" tab\n";
|
||||||
cout<<" caps_lock, capslock\n";
|
cout<<" caps_lock, capslock\n";
|
||||||
cout<<" space\n";
|
cout<<" space\n";
|
||||||
cout<<" backspace, back\n";
|
cout<<" backspace, back\n";
|
||||||
cout<<" enter\n";
|
cout<<" enter\n";
|
||||||
cout<<" tilde\n";
|
cout<<" tilde\n";
|
||||||
cout<<" minus\n";
|
cout<<" minus\n";
|
||||||
cout<<" equal\n";
|
cout<<" equal\n";
|
||||||
cout<<" open_bracket\n";
|
cout<<" open_bracket\n";
|
||||||
cout<<" close_bracket\n";
|
cout<<" close_bracket\n";
|
||||||
cout<<" backslash\n";
|
cout<<" backslash\n";
|
||||||
cout<<" semicolon\n";
|
cout<<" semicolon\n";
|
||||||
cout<<" dollar\n";
|
cout<<" dollar\n";
|
||||||
cout<<" quote\n";
|
cout<<" quote\n";
|
||||||
cout<<" intl_backslash\n";
|
cout<<" intl_backslash\n";
|
||||||
cout<<" comma\n";
|
cout<<" comma\n";
|
||||||
cout<<" period\n";
|
cout<<" period\n";
|
||||||
cout<<" slash\n";
|
cout<<" slash\n";
|
||||||
cout<<"Group gkeys :\n";
|
cout<<"Group gkeys :\n";
|
||||||
cout<<" g1 - g9\n";
|
cout<<" g1 - g9\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int commit() {
|
int commit() {
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
lg_kbd.commit();
|
lg_kbd.commit();
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setStartupEffect(string effect) {
|
int setStartupEffect(string effect) {
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
Keyboard::PowerOnEffect powerOnEffect;
|
Keyboard::PowerOnEffect powerOnEffect;
|
||||||
if (lg_kbd.parsePowerOnEffect(effect, powerOnEffect) == true) {
|
if (lg_kbd.parsePowerOnEffect(effect, powerOnEffect) == true) {
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
lg_kbd.setPowerOnEffect(powerOnEffect);
|
lg_kbd.setPowerOnEffect(powerOnEffect);
|
||||||
lg_kbd.commit();
|
lg_kbd.commit();
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setKey(string key, string color, bool commit) {
|
int setKey(string key, string color, bool commit) {
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
Keyboard::KeyAddress keyAddress;
|
Keyboard::KeyAddress keyAddress;
|
||||||
if (lg_kbd.parseKey(key, keyAddress) == true) {
|
if (lg_kbd.parseKey(key, keyAddress) == true) {
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
if (lg_kbd.parseColor(color, colors) == true) {
|
if (lg_kbd.parseColor(color, colors) == true) {
|
||||||
Keyboard::KeyValue keyValue;
|
Keyboard::KeyValue keyValue;
|
||||||
keyValue.key = keyAddress;
|
keyValue.key = keyAddress;
|
||||||
keyValue.colors = colors;
|
keyValue.colors = colors;
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
lg_kbd.setKey(keyValue);
|
lg_kbd.setKey(keyValue);
|
||||||
if (commit == true) lg_kbd.commit();
|
if (commit == true) lg_kbd.commit();
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setAllKeys(string color, bool commit) {
|
int setAllKeys(string color, bool commit) {
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
if (lg_kbd.parseColor(color, colors) == true) {
|
if (lg_kbd.parseColor(color, colors) == true) {
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
lg_kbd.setAllKeys(colors);
|
lg_kbd.setAllKeys(colors);
|
||||||
if (commit == true) lg_kbd.commit();
|
if (commit == true) lg_kbd.commit();
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setGroupKeys(string groupKeys, string color, bool commit) {
|
int setGroupKeys(string groupKeys, string color, bool commit) {
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
Keyboard::KeyGroup keyGroup;
|
Keyboard::KeyGroup keyGroup;
|
||||||
if (lg_kbd.parseKeyGroup(groupKeys, keyGroup) == true) {
|
if (lg_kbd.parseKeyGroup(groupKeys, keyGroup) == true) {
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
if (lg_kbd.parseColor(color, colors) == true) {
|
if (lg_kbd.parseColor(color, colors) == true) {
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
lg_kbd.setGroupKeys(keyGroup, colors);
|
lg_kbd.setGroupKeys(keyGroup, colors);
|
||||||
if (commit == true) lg_kbd.commit();
|
if (commit == true) lg_kbd.commit();
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadProfile(string profileFile) {
|
int loadProfile(string profileFile) {
|
||||||
ifstream file;
|
ifstream file;
|
||||||
|
|
||||||
file.open(profileFile);
|
file.open(profileFile);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
int lineCount = 1;
|
int lineCount = 1;
|
||||||
int ind;
|
int ind;
|
||||||
|
|
||||||
Keyboard lg_kbd;
|
Keyboard lg_kbd;
|
||||||
Keyboard::KeyGroup keyGroup;
|
Keyboard::KeyGroup keyGroup;
|
||||||
Keyboard::KeyAddress keyAddress;
|
Keyboard::KeyAddress keyAddress;
|
||||||
Keyboard::KeyValue keyValue;
|
Keyboard::KeyValue keyValue;
|
||||||
Keyboard::KeyColors colors;
|
Keyboard::KeyColors colors;
|
||||||
|
|
||||||
map<string, string> var;
|
map<string, string> var;
|
||||||
vector<Keyboard::KeyValue> keys;
|
vector<Keyboard::KeyValue> keys;
|
||||||
|
|
||||||
lg_kbd.attach();
|
lg_kbd.attach();
|
||||||
|
|
||||||
while (!file.eof()) {
|
while (!file.eof()) {
|
||||||
getline(file, line);
|
getline(file, line);
|
||||||
|
|
||||||
if (line.substr(0, 3) == "var") {
|
if (line.substr(0, 3) == "var") {
|
||||||
line = line.substr(4);
|
line = line.substr(4);
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
var[line.substr(0, ind)] = line.substr(ind + 1, 6);
|
var[line.substr(0, ind)] = line.substr(ind + 1, 6);
|
||||||
} else if (line.substr(0, 1) == "a") {
|
} else if (line.substr(0, 1) == "a") {
|
||||||
line = line.substr(2);
|
line = line.substr(2);
|
||||||
if (line.substr(0, 1) == "$") {
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
line = var[line.substr(1, ind - 1)];
|
line = var[line.substr(1, ind - 1)];
|
||||||
} else line = line.substr(0, 6);
|
} else line = line.substr(0, 6);
|
||||||
if (lg_kbd.parseColor(line, colors) == true) {
|
if (lg_kbd.parseColor(line, colors) == true) {
|
||||||
keys.clear();
|
keys.clear();
|
||||||
lg_kbd.setAllKeys(colors);
|
lg_kbd.setAllKeys(colors);
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else if (line.substr(0,1) == "g") {
|
} else if (line.substr(0,1) == "g") {
|
||||||
line = line.substr(2);
|
line = line.substr(2);
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
if (lg_kbd.parseKeyGroup(line.substr(0, ind), keyGroup) == true) {
|
if (lg_kbd.parseKeyGroup(line.substr(0, ind), keyGroup) == true) {
|
||||||
line = line.substr(ind + 1);
|
line = line.substr(ind + 1);
|
||||||
if (line.substr(0, 1) == "$") {
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
line = var[line.substr(1, ind - 1)];
|
line = var[line.substr(1, ind - 1)];
|
||||||
};
|
};
|
||||||
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
||||||
lg_kbd.setGroupKeys(keyGroup, colors);
|
lg_kbd.setGroupKeys(keyGroup, colors);
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else if (line.substr(0,1) == "k") {
|
} else if (line.substr(0,1) == "k") {
|
||||||
line = line.substr(2);
|
line = line.substr(2);
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
if (lg_kbd.parseKey(line.substr(0, ind), keyAddress) == true) {
|
if (lg_kbd.parseKey(line.substr(0, ind), keyAddress) == true) {
|
||||||
line = line.substr(ind + 1);
|
line = line.substr(ind + 1);
|
||||||
if (line.substr(0, 1) == "$") {
|
if (line.substr(0, 1) == "$") {
|
||||||
ind = line.find(" ");
|
ind = line.find(" ");
|
||||||
line = var[line.substr(1, ind - 1)];
|
line = var[line.substr(1, ind - 1)];
|
||||||
}
|
}
|
||||||
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
if (lg_kbd.parseColor(line.substr(0, 6), colors) == true) {
|
||||||
keyValue.key = keyAddress;
|
keyValue.key = keyAddress;
|
||||||
keyValue.colors = colors;
|
keyValue.colors = colors;
|
||||||
keys.push_back(keyValue);
|
keys.push_back(keyValue);
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
} else cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
} else if (line.substr(0,1) == "c") {
|
} else if (line.substr(0,1) == "c") {
|
||||||
lg_kbd.commit();
|
lg_kbd.commit();
|
||||||
lg_kbd.setKeys(&keys[0], keys.size());
|
lg_kbd.setKeys(&keys[0], keys.size());
|
||||||
keys.clear();
|
keys.clear();
|
||||||
lg_kbd.commit();
|
lg_kbd.commit();
|
||||||
} else if ((line.substr(0, 1) != "#") && (line.substr(0, 1) != "")) {
|
} else if ((line.substr(0, 1) != "#") && (line.substr(0, 1) != "")) {
|
||||||
cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
cout<<"Error on line "<<lineCount<<" : "<<line<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
lineCount++;
|
lineCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
lg_kbd.detach();
|
lg_kbd.detach();
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
string str = argv[0];
|
string str = argv[0];
|
||||||
size_t split = str.find_last_of("/\\");
|
size_t split = str.find_last_of("/\\");
|
||||||
str = str.substr(split + 1);
|
str = str.substr(split + 1);
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
string argCmd = argv[1];
|
string argCmd = argv[1];
|
||||||
if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }
|
if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }
|
||||||
else if (argCmd == "-lk" || argCmd == "--list-keys") { listkeys(); return 0; }
|
else if (argCmd == "-lk" || argCmd == "--list-keys") { listkeys(); return 0; }
|
||||||
else if (argCmd == "-s" && argc == 3) return setStartupEffect(argv[2]);
|
else if (argCmd == "-s" && argc == 3) return setStartupEffect(argv[2]);
|
||||||
else if (argCmd == "-a" && argc == 3) return setAllKeys(argv[2], true);
|
else if (argCmd == "-a" && argc == 3) return setAllKeys(argv[2], true);
|
||||||
else if (argCmd == "-an" && argc == 3) return setAllKeys(argv[2], false);
|
else if (argCmd == "-an" && argc == 3) return setAllKeys(argv[2], false);
|
||||||
else if (argCmd == "-g" && argc == 4) return setGroupKeys(argv[2], argv[3], true);
|
else if (argCmd == "-g" && argc == 4) return setGroupKeys(argv[2], argv[3], true);
|
||||||
else if (argCmd == "-gn" && argc == 4) return setGroupKeys(argv[2], argv[3], false);
|
else if (argCmd == "-gn" && argc == 4) return setGroupKeys(argv[2], argv[3], false);
|
||||||
else if (argCmd == "-k" && argc == 4) return setKey(argv[2], argv[3], true);
|
else if (argCmd == "-k" && argc == 4) return setKey(argv[2], argv[3], true);
|
||||||
else if (argCmd == "-kn" && argc == 4) return setKey(argv[2], argv[3], false);
|
else if (argCmd == "-kn" && argc == 4) return setKey(argv[2], argv[3], false);
|
||||||
else if (argCmd == "-c" && argc == 2) return commit();
|
else if (argCmd == "-c" && argc == 2) return commit();
|
||||||
else if (argCmd == "-p" && argc == 3) return loadProfile(argv[2]);
|
else if (argCmd == "-p" && argc == 3) return loadProfile(argv[2]);
|
||||||
}
|
}
|
||||||
usage();
|
usage();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user