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

Add feature flags to filter help messages

This commit is contained in:
MatMoul 2017-05-07 01:32:31 +02:00
parent 2e20286a07
commit b88e839978
2 changed files with 183 additions and 99 deletions

View File

@ -8,39 +8,63 @@ using namespace std;
namespace help { namespace help {
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b) {
return static_cast<KeyboardFeatures>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b));
}
KeyboardFeatures getKeyboardFeatures(string cmdName) {
if(cmdName == "g213-led") return KeyboardFeatures::g213;
else if(cmdName == "g410-led") return KeyboardFeatures::g410;
else if(cmdName == "g610-led") return KeyboardFeatures::g610;
else if(cmdName == "g810-led") return KeyboardFeatures::g810;
else if(cmdName == "g910-led") return KeyboardFeatures::g910;
return KeyboardFeatures::all;
}
void usage(char *arg0) { void usage(char *arg0) {
string cmdName = utils::getCmdName(arg0); string cmdName = utils::getCmdName(arg0);
KeyboardFeatures features = getKeyboardFeatures(cmdName);
cout<<cmdName<<endl; cout<<cmdName<<endl;
cout<<"--------"<<endl; cout<<"--------"<<endl;
cout<<"Version : "<<VERSION<<endl; cout<<"Version : "<<VERSION<<endl;
cout<<endl; cout<<endl;
cout<<"Usage: "<<cmdName<<" [OPTIONS...] [command] (command arguments)"<<endl; cout<<"Usage: "<<cmdName<<" [OPTIONS...] [command] (command arguments)"<<endl;
cout<<"Commands:"<<endl; cout<<"Commands:"<<endl;
cout<<" -a {color}\t\t\t\tSet all keys color"<<endl; if((features | KeyboardFeatures::setall) == features)
cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl; cout<<" -a {color}\t\t\t\tSet all keys color"<<endl;
cout<<" -k {key} {color}\t\t\tSet key color"<<endl; if((features | KeyboardFeatures::setgroup) == features)
if (cmdName == "g213-led") { cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl;
if((features | KeyboardFeatures::setkey) == features)
cout<<" -k {key} {color}\t\t\tSet key color"<<endl;
if((features | KeyboardFeatures::setregion) == features)
cout<<" -r {region} {color}\t\t\tSet the color of a region for a region-based keyboard"<<endl; cout<<" -r {region} {color}\t\t\tSet the color of a region for a region-based keyboard"<<endl;
} if((features | KeyboardFeatures::gkeys) == features) {
if (cmdName == "g910-led") {
cout<<" -mr {value}\t\t\t\tSet MR key (0-1)"<<endl; cout<<" -mr {value}\t\t\t\tSet MR key (0-1)"<<endl;
cout<<" -mn {value}\t\t\t\tSet MN key (0-7) (M1=1, M2=2, M3=4) (M1+M2=3, M1+M3=5, ...)"<<endl; cout<<" -mn {value}\t\t\t\tSet MN key (0-7) (M1=1, M2=2, M3=4) (M1+M2=3, M1+M3=5, ...)"<<endl;
cout<<endl; cout<<endl;
cout<<" -gkm {value}\t\t\t\tSet GKeys mode (0=Mapped to FKeys, 1=Independent)"<<endl; cout<<" -gkm {value}\t\t\t\tSet GKeys mode (0=Mapped to FKeys, 1=Independent)"<<endl;
} }
cout<<endl; cout<<endl;
cout<<" -an {color}\t\t\t\tSet all keys color without commit"<<endl; if((features | KeyboardFeatures::commit) == features) {
cout<<" -gn {keygroup} {color}\t\tSet key group color without commit"<<endl; if((features | KeyboardFeatures::setall) == features)
cout<<" -kn {key} {color}\t\t\tSet key color without commit"<<endl; cout<<" -an {color}\t\t\t\tSet all keys color without commit"<<endl;
cout<<" -c\t\t\t\t\tCommit change"<<endl; if((features | KeyboardFeatures::setgroup) == features)
cout<<endl; cout<<" -gn {keygroup} {color}\t\tSet key group color without commit"<<endl;
if((features | KeyboardFeatures::setkey) == features)
cout<<" -kn {key} {color}\t\t\tSet key color without commit"<<endl;
cout<<" -c\t\t\t\t\tCommit change"<<endl;
cout<<endl;
}
cout<<" -fx ...\t\t\t\tUse --help-effects for more detail"<<endl; cout<<" -fx ...\t\t\t\tUse --help-effects for more detail"<<endl;
cout<<endl; cout<<endl;
cout<<" < {profile}\t\t\t\tSet a profile from a file (use --help-samples for more detail)"<<endl; cout<<" < {profile}\t\t\t\tSet a profile from a file (use --help-samples for more detail)"<<endl;
cout<<" |\t\t\t\t\tSet a profile from stdin (for scripting) (use --help-samples for more detail)"<<endl; cout<<" |\t\t\t\t\tSet a profile from stdin (for scripting) (use --help-samples for more detail)"<<endl;
cout<<endl; cout<<endl;
cout<<" --startup-mode {startup mode}\t\tSet startup mode"<<endl; if((features | KeyboardFeatures::poweronfx) == features) {
cout<<endl; cout<<" --startup-mode {startup mode}\t\tSet startup mode"<<endl;
cout<<endl;
}
cout<<" --list-keyboards \t\t\tList connected keyboards"<<endl; cout<<" --list-keyboards \t\t\tList connected keyboards"<<endl;
cout<<" --print-device\t\t\tPrint device information for the keyboard"<<endl; cout<<" --print-device\t\t\tPrint device information for the keyboard"<<endl;
cout<<endl; cout<<endl;
@ -56,52 +80,59 @@ namespace help {
cout<<" -tuk\t\t\t\t\tTest unsuported keyboard with one of supported protocol (1-3) -dv and -dp are required"<<endl; cout<<" -tuk\t\t\t\t\tTest unsuported keyboard with one of supported protocol (1-3) -dv and -dp are required"<<endl;
cout<<endl; cout<<endl;
cout<<"Values:"<<endl; cout<<"Values:"<<endl;
if (cmdName == "g610-led") if((features | KeyboardFeatures::rgb) == features)
cout<<" color formats :\t\t\tII (hex value for intensity)"<<endl;
else
cout<<" color formats :\t\t\tRRGGBB (hex value for red, green and blue)"<<endl; cout<<" color formats :\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
if (cmdName == "g213-led") { if((features | KeyboardFeatures::intensity) == features)
cout<<" region formats :\t\tRN (integer value for region, 1 to 5)"<<endl; cout<<" color formats :\t\t\tII (hex value for intensity)"<<endl;
} if((features | KeyboardFeatures::setregion) == features)
cout<<" region formats :\t\t\tRN (integer value for region, 1 to 5)"<<endl;
cout<<" speed formats :\t\t\tSS (hex value for speed 01 to ff)"<<endl; cout<<" speed formats :\t\t\tSS (hex value for speed 01 to ff)"<<endl;
cout<<endl; cout<<endl;
cout<<" key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl; if((features | KeyboardFeatures::setkey) == features)
cout<<" group values :\t\t\tlogo, indicators, fkeys, ... (use --help-keys for more detail)"<<endl; cout<<" key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl;
if((features | KeyboardFeatures::setgroup) == features)
cout<<" group values :\t\t\tlogo, indicators, fkeys, ... (use --help-keys for more detail)"<<endl;
cout<<" startup mode :\t\t\twave, color"<<endl; cout<<" startup mode :\t\t\twave, color"<<endl;
cout<<endl; cout<<endl;
} }
// Need to check rgb and intesity
void keys(char *arg0) { void keys(char *arg0) {
string cmdName = utils::getCmdName(arg0); string cmdName = utils::getCmdName(arg0);
KeyboardFeatures features = getKeyboardFeatures(cmdName);
cout<<cmdName<<" Keys"<<endl; cout<<cmdName<<" Keys"<<endl;
cout<<"-------------"<<endl; cout<<"-------------"<<endl;
cout<<endl; cout<<endl;
cout<<"Group List :"<<endl; cout<<"Group List :"<<endl;
if (cmdName != "g410-led") cout<<" logo"<<endl; if((features | KeyboardFeatures::logo1) == features)
if (cmdName != "g410-led") cout<<" indicators"<<endl; cout<<" logo"<<endl;
if (cmdName == "g910-led") cout<<" gkeys"<<endl; if((features | KeyboardFeatures::setindicators) == features)
cout<<" indicators"<<endl;
if((features | KeyboardFeatures::gkeys) == features)
cout<<" gkeys"<<endl;
cout<<" fkeys"<<endl; cout<<" fkeys"<<endl;
cout<<" modifiers"<<endl; cout<<" modifiers"<<endl;
if (cmdName != "g410-led" && cmdName != "g910-led") cout<<" multimedia"<<endl; if((features | KeyboardFeatures::multimedia) == features)
cout<<" multimedia"<<endl;
cout<<" arrows"<<endl; cout<<" arrows"<<endl;
if (cmdName != "g410-led") cout<<" numeric"<<endl; if((features | KeyboardFeatures::numpad) == features)
cout<<" numeric"<<endl;
cout<<" functions"<<endl; cout<<" functions"<<endl;
cout<<" keys"<<endl; cout<<" keys"<<endl;
cout<<endl; cout<<endl;
cout<<endl; cout<<endl;
if (cmdName == "g910-led") { if((features | KeyboardFeatures::logo1) == features) {
cout<<"Group logo :"<<endl; cout<<"Group Logo :"<<endl;
cout<<" logo"<<endl;
cout<<" logo2"<<endl;
} else if (cmdName != "g410-led") {
cout<<"Group logo :"<<endl;
cout<<" logo"<<endl; cout<<" logo"<<endl;
if((features | KeyboardFeatures::logo2) == features)
cout<<" logo2"<<endl;
cout<<""<<endl;
} }
cout<<""<<endl;
if (cmdName != "g410-led") { if((features | KeyboardFeatures::setindicators) == features) {
cout<<"Group indicators :"<<endl; cout<<"Group indicators :"<<endl;
cout<<" num_indicator, numindicator, num"<<endl; cout<<" num_indicator, numindicator, num"<<endl;
cout<<" caps_indicator, capsindicator, caps"<<endl; cout<<" caps_indicator, capsindicator, caps"<<endl;
@ -111,7 +142,7 @@ namespace help {
cout<<""<<endl; cout<<""<<endl;
} }
if (cmdName == "g910-led") { if((features | KeyboardFeatures::gkeys) == features) {
cout<<"Group gkeys :"<<endl; cout<<"Group gkeys :"<<endl;
cout<<" g1 - g9"<<endl; cout<<" g1 - g9"<<endl;
cout<<""<<endl; cout<<""<<endl;
@ -133,7 +164,7 @@ namespace help {
cout<<" shift_right, shiftright, shiftr"<<endl; cout<<" shift_right, shiftright, shiftr"<<endl;
cout<<""<<endl; cout<<""<<endl;
if (cmdName != "g410-led" && cmdName != "g910-led") { if((features | KeyboardFeatures::multimedia) == features) {
cout<<"Group multimedia :"<<endl; cout<<"Group multimedia :"<<endl;
cout<<" mute"<<endl; cout<<" mute"<<endl;
cout<<" play_pause, playpause, play"<<endl; cout<<" play_pause, playpause, play"<<endl;
@ -150,7 +181,7 @@ namespace help {
cout<<" arrow_right, arrowright, right"<<endl; cout<<" arrow_right, arrowright, right"<<endl;
cout<<""<<endl; cout<<""<<endl;
if (cmdName != "g410-led") { if((features | KeyboardFeatures::numpad) == features) {
cout<<"Group numeric :"<<endl; cout<<"Group numeric :"<<endl;
cout<<" num_lock, numlock"<<endl; cout<<" num_lock, numlock"<<endl;
cout<<" num_slash, numslash, num/"<<endl; cout<<" num_slash, numslash, num/"<<endl;
@ -175,31 +206,35 @@ namespace help {
cout<<" end"<<endl; cout<<" end"<<endl;
cout<<" page_down, pagedown"<<endl; cout<<" page_down, pagedown"<<endl;
cout<<""<<endl; cout<<""<<endl;
cout<<"Group keys :"<<endl;
cout<<" 0 - 9"<<endl; if((features | KeyboardFeatures::setkey) == features) {
cout<<" a - z"<<endl; cout<<"Group keys :"<<endl;
cout<<" tab"<<endl; cout<<" 0 - 9"<<endl;
cout<<" caps_lock, capslock"<<endl; cout<<" a - z"<<endl;
cout<<" space"<<endl; cout<<" tab"<<endl;
cout<<" backspace, back"<<endl; cout<<" caps_lock, capslock"<<endl;
cout<<" enter"<<endl; cout<<" space"<<endl;
cout<<" tilde"<<endl; cout<<" backspace, back"<<endl;
cout<<" minus"<<endl; cout<<" enter"<<endl;
cout<<" equal"<<endl; cout<<" tilde"<<endl;
cout<<" open_bracket"<<endl; cout<<" minus"<<endl;
cout<<" close_bracket"<<endl; cout<<" equal"<<endl;
cout<<" backslash"<<endl; cout<<" open_bracket"<<endl;
cout<<" semicolon"<<endl; cout<<" close_bracket"<<endl;
cout<<" dollar"<<endl; cout<<" backslash"<<endl;
cout<<" quote"<<endl; cout<<" semicolon"<<endl;
cout<<" intl_backslash"<<endl; cout<<" dollar"<<endl;
cout<<" comma"<<endl; cout<<" quote"<<endl;
cout<<" period"<<endl; cout<<" intl_backslash"<<endl;
cout<<" slash"<<endl; cout<<" comma"<<endl;
cout<<" period"<<endl;
cout<<" slash"<<endl;
}
} }
void effects(char *arg0) { void effects(char *arg0) {
string cmdName = utils::getCmdName(arg0); string cmdName = utils::getCmdName(arg0);
KeyboardFeatures features = getKeyboardFeatures(cmdName);
cout<<cmdName<<" Effects"<<endl; cout<<cmdName<<" Effects"<<endl;
cout<<"----------------"<<endl; cout<<"----------------"<<endl;
cout<<endl; cout<<endl;
@ -214,62 +249,79 @@ namespace help {
cout<<" -fx vwave {target} {speed}"<<endl; cout<<" -fx vwave {target} {speed}"<<endl;
cout<<" -fx cwave {target} {speed}"<<endl; cout<<" -fx cwave {target} {speed}"<<endl;
cout<<endl; cout<<endl;
if (cmdName == "g410-led") { if((features | KeyboardFeatures::logo1) == features)
cout<<"target value :\t\t\t\tall, keys (all is for compatibility with other keyboard models)"<<endl;
} else {
cout<<"target value :\t\t\t\tall, keys, logo"<<endl; cout<<"target value :\t\t\t\tall, keys, logo"<<endl;
} else
cout<<"color formats :\t\t\t\tRRGGBB (hex value for red, green and blue)"<<endl; cout<<"target value :\t\t\t\tall, keys (all is for compatibility with other keyboard models)"<<endl;
if((features | KeyboardFeatures::rgb) == features)
cout<<"color formats :\t\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
else if((features | KeyboardFeatures::rgb) == features)
cout<<"color formats :\t\t\t\tII (hex value for intensity)"<<endl;
cout<<"speed formats :\t\t\t\tSS (hex value for speed 01 to ff)"<<endl; cout<<"speed formats :\t\t\t\tSS (hex value for speed 01 to ff)"<<endl;
cout<<endl; cout<<endl;
} }
// Need to check rgb and intesity
void samples(char *arg0) { void samples(char *arg0) {
string cmdName = utils::getCmdName(arg0); string cmdName = utils::getCmdName(arg0);
KeyboardFeatures features = getKeyboardFeatures(cmdName);
cout<<cmdName<<" Samples"<<endl; cout<<cmdName<<" Samples"<<endl;
cout<<"----------------"<<endl; cout<<"----------------"<<endl;
cout<<endl; cout<<endl;
cout<<"Samples :"<<endl; cout<<"Samples :"<<endl;
cout<<"g810-led -p /etc/g810/profile # Load a profile"<<endl; cout<<cmdName<<" -p /etc/g810/profile # Load a profile"<<endl;
cout<<"g810-led -k logo ff0000 # Set color of a key"<<endl; if((features | KeyboardFeatures::setkey) == features)
cout<<"g810-led -a 00ff00 # Set color of all keys"<<endl; cout<<cmdName<<" -k logo ff0000 # Set color of a key"<<endl;
cout<<"g810-led -g fkeys ff00ff # Set color of a group of keys"<<endl; if((features | KeyboardFeatures::setall) == features)
cout<<"g810-led -s color # Set keyboard power on effect"<<endl; cout<<cmdName<<" -a 00ff00 # Set color of all keys"<<endl;
cout<<"g810-led -fx color keys 00ff00 # Set fixed color effect"<<endl; if((features | KeyboardFeatures::setgroup) == features)
cout<<"g810-led -fx breathing logo 00ff00 0a # Set breathing effect"<<endl; cout<<cmdName<<" -g fkeys ff00ff # Set color of a group of keys"<<endl;
cout<<"g810-led -fx cycle all 0a # Set color cycle effect"<<endl; if((features | KeyboardFeatures::setregion) == features)
cout<<"g810-led -fx hwave keys 0a # Set horizontal wave effect"<<endl; cout<<cmdName<<" -r 1 ff0000 # Set region 1 red"<<endl;
cout<<"g810-led -fx vwave keys 0a # Set vertical wave effect"<<endl; cout<<cmdName<<" -fx color keys 00ff00 # Set fixed color effect"<<endl;
cout<<"g810-led -fx cwave keys 0a # Set center wave effect"<<endl; cout<<cmdName<<" -fx breathing logo 00ff00 0a # Set breathing effect"<<endl;
cout<<endl; cout<<cmdName<<" -fx cycle all 0a # Set color cycle effect"<<endl;
cout<<"Samples with no commit :"<<endl; cout<<cmdName<<" -fx hwave keys 0a # Set horizontal wave effect"<<endl;
cout<<"g810-led -an 000000 # Set color of all key with no action"<<endl; cout<<cmdName<<" -fx vwave keys 0a # Set vertical wave effect"<<endl;
cout<<"g810-led -gn modifiers ff0000 # Set color of a group with no action"<<endl; cout<<cmdName<<" -fx cwave keys 0a # Set center wave effect"<<endl;
cout<<"g810-led -kn w ff0000 # Set color of a key with no action"<<endl; if((features | KeyboardFeatures::poweronfx) == features)
cout<<"g810-led -kn a ff0000 # Set color of a key with no action"<<endl; cout<<cmdName<<" --startup-mode color # Set keyboard power on effect"<<endl;
cout<<"g810-led -kn s ff0000 # Set color of a key with no action"<<endl;
cout<<"g810-led -kn d ff0000 # Set color of a key with no action"<<endl;
cout<<"g810-led -c # Commit all changes"<<endl;
cout<<endl;
cout<<"Samples for g610 :"<<endl;
cout<<"g610-led -a 60 # Set intensity of all keys"<<endl;
cout<<"g610-led -k logo ff # Set intensity of a key"<<endl;
cout<<"g610-led -g fkeys aa # Set intensity of a group of keys"<<endl;
cout<<endl;
cout<<"Samples for g213 :"<<endl;
cout<<"g213-led -a 00ff00 # Set color of all keys"<<endl;
cout<<"g213-led -r 1 ff0000 # Set region 1 red"<<endl;
cout<<endl;
cout<<"Samples with pipe (for effects) :"<<endl;
cout<<"g810-led -pp < profilefile # Load a profile"<<endl;
cout<<"echo -e \"k w ff0000\\nk a ff0000\\nk s ff0000\\nk d ff0000\\nc\" | g810-led -pp # Set multiple keys"<<endl;
cout<<endl; cout<<endl;
if((features | KeyboardFeatures::commit) == features) {
cout<<"Samples with no commit :"<<endl;
if((features | KeyboardFeatures::setall) == features)
cout<<cmdName<<" -an 000000 # Set color of all key with no action"<<endl;
if((features | KeyboardFeatures::setgroup) == features)
cout<<cmdName<<" -gn modifiers ff0000 # Set color of a group with no action"<<endl;
if((features | KeyboardFeatures::setkey) == features) {
cout<<cmdName<<" -kn w ff0000 # Set color of a key with no action"<<endl;
cout<<cmdName<<" -kn a ff0000 # Set color of a key with no action"<<endl;
cout<<cmdName<<" -kn s ff0000 # Set color of a key with no action"<<endl;
cout<<cmdName<<" -kn d ff0000 # Set color of a key with no action"<<endl;
}
cout<<cmdName<<" -c # Commit all changes"<<endl;
cout<<endl;
}
// Need to be merged with Samples
if((features | KeyboardFeatures::intensity) == features) {
cout<<"Samples with intensity :"<<endl;
cout<<cmdName<<" -a 60 # Set intensity of all keys"<<endl;
cout<<cmdName<<" -k logo ff # Set intensity of a key"<<endl;
cout<<cmdName<<" -g fkeys aa # Set intensity of a group of keys"<<endl;
cout<<endl;
}
if((features | KeyboardFeatures::setkey) == features) {
cout<<"Samples with pipe (for effects) :"<<endl;
cout<<cmdName<<" -pp < profilefile # Load a profile"<<endl;
cout<<"echo -e \"k w ff0000\\nk a ff0000\\nk s ff0000\\nk d ff0000\\nc\" | g810-led -pp # Set multiple keys"<<endl;
cout<<endl;
}
cout<<"Testing an unsuported keyboard :"<<endl; cout<<"Testing an unsuported keyboard :"<<endl;
cout<<"lsusb"<<endl; cout<<"lsusb"<<endl;
cout<<"#Sample result of lsusb : ID 046d:c331 Logitech, Inc. (dv=046d and dp=c331)"<<endl; cout<<"#Sample result of lsusb : ID 046d:c331 Logitech, Inc. (dv=046d and dp=c331)"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 1 -a 000000"<<endl; cout<<cmdName<<" -dv 046d -dp c331 -tuk 1 -a 000000"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 2 -a 000000"<<endl; cout<<cmdName<<" -dv 046d -dp c331 -tuk 2 -a 000000"<<endl;
cout<<"g810-led -dv 046d -dp c331 -tuk 3 -a 000000"<<endl; cout<<cmdName<<" -dv 046d -dp c331 -tuk 3 -a 000000"<<endl;
cout<<""<<endl; cout<<""<<endl;
} }

View File

@ -5,6 +5,38 @@
namespace help { namespace help {
enum class KeyboardFeatures : uint16_t {
none = 0,
rgb = 1,
intensity = 2,
commit = 4,
logo1 = 8,
logo2 = 16,
numpad = 32,
multimedia = 64,
gkeys = 128,
setall = 256,
setgroup = 512,
setkey = 1024,
setregion = 2048,
setindicators = 4096,
poweronfx = 8192,
// fx features
all = rgb | intensity | commit | logo1 | logo2 | numpad | multimedia | gkeys |
setall | setgroup | setkey | setregion | setindicators | poweronfx,
g213 = rgb | logo1 | numpad | multimedia | setall | setregion | setindicators | poweronfx,
g410 = rgb | commit | setall | setgroup | setkey | poweronfx,
g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
g810 = rgb | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
g910 = rgb | commit | logo1 | logo2 | numpad | multimedia | gkeys | setall | setgroup | setkey | setindicators | poweronfx
};
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b);
KeyboardFeatures getKeyboardFeatures(std::string cmdName);
void usage(char *arg0); void usage(char *arg0);
void keys(char *arg0); void keys(char *arg0);
void effects(char *arg0); void effects(char *arg0);