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

Clean code

This commit is contained in:
MatMoul 2017-01-06 06:31:42 +01:00
parent 3596a85315
commit c8a579a8f2

View File

@ -2,144 +2,149 @@
#include <vector>
#include <fstream>
#include <istream>
#include "classes/Keyboard.h"
#include <unistd.h>
#include "classes/Keyboard.h"
using namespace std;
string appname = "g810-led";
void usage() {
string appname = "g810-led";
cout<<appname<<" Usages :\n";
cout<<"-----------------\n";
cout<<"\n";
cout<<" -s effect :\t\t\tSet keyboard startup effect\n";
cout<<"\n";
cout<<" -a color :\t\t\tSet all keys\n";
cout<<" -g group, color :\t\tSet a group of keys\n";
cout<<" -k key, color :\t\tSet a key\n";
cout<<"\n";
cout<<" -an color :\t\t\tSet all keys without commit\n";
cout<<" -gn group, color :\t\tSet a group of keys without commit\n";
cout<<" -kn key, color :\t\tSet a key without commit\n";
cout<<"\n";
cout<<" -c :\t\t\t\tCommit changes\n";
cout<<"\n";
cout<<" -fx-color color :\t\tSet static color effect\n";
cout<<" -fx-breathing color, speed :\tSet breathing effect\n";
cout<<" -fx-cycle speed :\t\tSet color cycle effect\n";
cout<<" -fx-hwave speed :\t\tSet horizontal color wave effect\n";
cout<<" -fx-vwave speed :\t\tSet vertical color wave effect\n";
cout<<" -fx-cwave speed :\t\tSet center color wave effect\n";
cout<<"\n";
cout<<" -p profilefile :\t\tLoad a profile from a file\n";
cout<<" -pp profilepipe :\t\tLoad a profile from stdin\n";
cout<<"\n";
cout<<" -h | --help :\t\t\tthis help message\n";
cout<<" -lk | --list-keys :\t\tList keys in groups\n";
cout<<"\n";
cout<<"color formats :\t\t\tRRGGBB (hex value for red, green and blue)\n";
cout<<"speed formats :\t\t\tSS (hex value for speed)\n";
cout<<"\n";
cout<<"effect values :\t\t\trainbow, color\n";
cout<<"key values :\t\t\tabc... 123... and other\n";
cout<<"group values :\t\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys, gkeys\n";
cout<<"\n";
cout<<"sample :\n";
cout<<appname<<" -k logo ff0000\n";
cout<<appname<<" -a 00ff00\n";
cout<<appname<<" -g fkeys ff00ff\n";
cout<<appname<<" -s color\n";
cout<<appname<<" -fx-cycle 10\n";
cout<<appname<<" Usages :"<<endl;
cout<<"-----------------"<<endl;
cout<<""<<endl;
cout<<" -s effect :\t\t\tSet keyboard startup effect"<<endl;
cout<<""<<endl;
cout<<" -a color :\t\t\tSet all keys"<<endl;
cout<<" -g group, color :\t\tSet a group of keys"<<endl;
cout<<" -k key, color :\t\tSet a key"<<endl;
cout<<""<<endl;
cout<<" -an color :\t\t\tSet all keys without commit"<<endl;
cout<<" -gn group, color :\t\tSet a group of keys without commit"<<endl;
cout<<" -kn key, color :\t\tSet a key without commit"<<endl;
cout<<""<<endl;
cout<<" -c :\t\t\t\tCommit changes"<<endl;
cout<<""<<endl;
cout<<" -fx-color color :\t\tSet static color effect"<<endl;
cout<<" -fx-breathing color, speed :\tSet breathing effect"<<endl;
cout<<" -fx-cycle speed :\t\tSet color cycle effect"<<endl;
cout<<" -fx-hwave speed :\t\tSet horizontal color wave effect"<<endl;
cout<<" -fx-vwave speed :\t\tSet vertical color wave effect"<<endl;
cout<<" -fx-cwave speed :\t\tSet center color wave effect"<<endl;
cout<<""<<endl;
cout<<" -p profilefile :\t\tLoad a profile from a file"<<endl;
cout<<" -pp profilepipe :\t\tLoad a profile from stdin"<<endl;
cout<<""<<endl;
cout<<" -h | --help :\t\t\tthis help message"<<endl;
cout<<" -lk | --list-keys :\t\tList keys in groups"<<endl;
cout<<""<<endl;
cout<<"color formats :\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
cout<<"speed formats :\t\t\tSS (hex value for speed)"<<endl;
cout<<""<<endl;
cout<<"effect values :\t\t\trainbow, color"<<endl;
cout<<"key values :\t\t\tabc... 123... and other (use -lk for more detail)"<<endl;
cout<<"group values :\t\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys, gkeys"<<endl;
cout<<""<<endl;
cout<<"samples :"<<endl;
cout<<appname<<" -k logo ff0000"<<endl;
cout<<appname<<" -a 00ff00"<<endl;
cout<<appname<<" -g fkeys ff00ff"<<endl;
cout<<appname<<" -s color"<<endl;
cout<<appname<<" -fx-cycle 10"<<endl;
cout<<appname<<" -p profilefile"<<endl;
cout<<""<<endl;
cout<<"samples with pipe:"<<endl;
cout<<appname<<" -pp < profilefile"<<endl;
cout<<"echo -e \"k w ff0000\\nk a ff0000\\nk s ff0000\\nk d ff0000\\nc\" | "<<appname<<" -pp"<<endl;
}
void listkeys() {
string appname = "g810-led";
cout<<appname<<" Keys in groups :\n";
cout<<"-------------------------\n";
cout<<"\n";
cout<<"Group logo :\n";
cout<<" logo\n";
cout<<" logo2\n";
cout<<"\n";
cout<<"Group indicators :\n";
cout<<" num_indicator, numindicator, num\n";
cout<<" caps_indicator, capsindicator, caps\n";
cout<<" scroll_indicator, scrollindicator, scroll\n";
cout<<" game_mode, gamemode, game\n";
cout<<" back_light, backlight, light\n";
cout<<"\n";
cout<<"Group fkeys :\n";
cout<<" f1 - f12\n";
cout<<"\n";
cout<<"Group modifiers :\n";
cout<<" shift_left, shiftleft, shiftl\n";
cout<<" ctrl_left, ctrlleft, ctrll\n";
cout<<" win_left, winleft, win_left\n";
cout<<" alt_left, altleft, altl\n";
cout<<" alt_right, altright, altr, altgr\n";
cout<<" win_right, winright, winr\n";
cout<<" menu\n";
cout<<" ctrl_right, ctrlright, ctrlr\n";
cout<<" shift_right, shiftright, shiftr\n";
cout<<"\n";
cout<<"Group multimedia :\n";
cout<<" mute\n";
cout<<" play_pause, playpause, play\n";
cout<<" stop\n";
cout<<" previous, prev\n";
cout<<" next\n";
cout<<"\n";
cout<<"Group arrows :\n";
cout<<" arrow_top, arrowtop, top\n";
cout<<" arrow_left, arrowleft, left\n";
cout<<" arrow_bottom, arrowbottom, bottom\n";
cout<<" arrow_right, arrowright, right\n";
cout<<"\n";
cout<<"Group numeric :\n";
cout<<" num_lock, numlock\n";
cout<<" num_slash, numslash, num/\n";
cout<<" num_asterisk, numasterisk, num*\n";
cout<<" num_minus, numminus, num-\n";
cout<<" num_plus, numplus, num+\n";
cout<<" numenter\n";
cout<<" num0 - num9\n";
cout<<" num_dot, numdot, num.\n";
cout<<"\n";
cout<<"Group functions :\n";
cout<<" escape, esc\n";
cout<<" print_screen, printscreen, printscr\n";
cout<<" scroll_lock, scrolllock\n";
cout<<" pause_break, pausebreak\n";
cout<<" insert, ins\n";
cout<<" home\n";
cout<<" page_up, pageup\n";
cout<<" delete, del\n";
cout<<" end\n";
cout<<" page_down, pagedown\n";
cout<<"\n";
cout<<"Group keys :\n";
cout<<" 0 - 9\n";
cout<<" a - z\n";
cout<<" tab\n";
cout<<" caps_lock, capslock\n";
cout<<" space\n";
cout<<" backspace, back\n";
cout<<" enter\n";
cout<<" tilde\n";
cout<<" minus\n";
cout<<" equal\n";
cout<<" open_bracket\n";
cout<<" close_bracket\n";
cout<<" backslash\n";
cout<<" semicolon\n";
cout<<" dollar\n";
cout<<" quote\n";
cout<<" intl_backslash\n";
cout<<" comma\n";
cout<<" period\n";
cout<<" slash\n";
cout<<"Group gkeys :\n";
cout<<" g1 - g9\n";
cout<<appname<<" Keys in groups :"<<endl;
cout<<"-------------------------"<<endl;
cout<<""<<endl;
cout<<"Group logo :"<<endl;
cout<<" logo"<<endl;
cout<<" logo2"<<endl;
cout<<""<<endl;
cout<<"Group indicators :"<<endl;
cout<<" num_indicator, numindicator, num"<<endl;
cout<<" caps_indicator, capsindicator, caps"<<endl;
cout<<" scroll_indicator, scrollindicator, scroll"<<endl;
cout<<" game_mode, gamemode, game"<<endl;
cout<<" back_light, backlight, light"<<endl;
cout<<""<<endl;
cout<<"Group fkeys :"<<endl;
cout<<" f1 - f12"<<endl;
cout<<""<<endl;
cout<<"Group modifiers :"<<endl;
cout<<" shift_left, shiftleft, shiftl"<<endl;
cout<<" ctrl_left, ctrlleft, ctrll"<<endl;
cout<<" win_left, winleft, win_left"<<endl;
cout<<" alt_left, altleft, altl"<<endl;
cout<<" alt_right, altright, altr, altgr"<<endl;
cout<<" win_right, winright, winr"<<endl;
cout<<" menu"<<endl;
cout<<" ctrl_right, ctrlright, ctrlr"<<endl;
cout<<" shift_right, shiftright, shiftr"<<endl;
cout<<""<<endl;
cout<<"Group multimedia :"<<endl;
cout<<" mute"<<endl;
cout<<" play_pause, playpause, play"<<endl;
cout<<" stop"<<endl;
cout<<" previous, prev"<<endl;
cout<<" next"<<endl;
cout<<""<<endl;
cout<<"Group arrows :"<<endl;
cout<<" arrow_top, arrowtop, top"<<endl;
cout<<" arrow_left, arrowleft, left"<<endl;
cout<<" arrow_bottom, arrowbottom, bottom"<<endl;
cout<<" arrow_right, arrowright, right"<<endl;
cout<<""<<endl;
cout<<"Group numeric :"<<endl;
cout<<" num_lock, numlock"<<endl;
cout<<" num_slash, numslash, num/"<<endl;
cout<<" num_asterisk, numasterisk, num*"<<endl;
cout<<" num_minus, numminus, num-"<<endl;
cout<<" num_plus, numplus, num+"<<endl;
cout<<" numenter"<<endl;
cout<<" num0 - num9"<<endl;
cout<<" num_dot, numdot, num."<<endl;
cout<<""<<endl;
cout<<"Group functions :"<<endl;
cout<<" escape, esc"<<endl;
cout<<" print_screen, printscreen, printscr"<<endl;
cout<<" scroll_lock, scrolllock"<<endl;
cout<<" pause_break, pausebreak"<<endl;
cout<<" insert, ins"<<endl;
cout<<" home"<<endl;
cout<<" page_up, pageup"<<endl;
cout<<" delete, del"<<endl;
cout<<" end"<<endl;
cout<<" page_down, pagedown"<<endl;
cout<<""<<endl;
cout<<"Group keys :"<<endl;
cout<<" 0 - 9"<<endl;
cout<<" a - z"<<endl;
cout<<" tab"<<endl;
cout<<" caps_lock, capslock"<<endl;
cout<<" space"<<endl;
cout<<" backspace, back"<<endl;
cout<<" enter"<<endl;
cout<<" tilde"<<endl;
cout<<" minus"<<endl;
cout<<" equal"<<endl;
cout<<" open_bracket"<<endl;
cout<<" close_bracket"<<endl;
cout<<" backslash"<<endl;
cout<<" semicolon"<<endl;
cout<<" dollar"<<endl;
cout<<" quote"<<endl;
cout<<" intl_backslash"<<endl;
cout<<" comma"<<endl;
cout<<" period"<<endl;
cout<<" slash"<<endl;
cout<<"Group gkeys :"<<endl;
cout<<" g1 - g9"<<endl;
}
int commit() {
@ -325,7 +330,6 @@ int setFXCWave(string speed) {
return 0;
}
return 1;
return 1;
}
int parseProfile(istream &is) {
@ -527,6 +531,7 @@ int main(int argc, char *argv[]) {
string str = argv[0];
size_t split = str.find_last_of("/\\");
str = str.substr(split + 1);
appname = str;
if (argc > 1) {
string argCmd = argv[1];
if (argCmd == "-h" || argCmd == "--help") { usage(); return 0; }