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

Add MKeys led control

This commit is contained in:
MatMoul 2017-03-11 17:56:40 +01:00
parent 619e6af72c
commit be7d367079
6 changed files with 89 additions and 1 deletions

View File

@ -446,6 +446,53 @@ bool LedKeyboard::setAllKeys(LedKeyboard::Color color) {
} }
bool LedKeyboard::setMRKey(uint8_t value) {
LedKeyboard::byte_buffer_t data;
switch (m_keyboardModel) {
case KeyboardModel::g910:
switch (value) {
case 0x00:
case 0x01:
data = { 0x11, 0xff, 0x0a, 0x0e, value };
data.resize(20, 0x00);
return sendDataInternal(data);
default:
break;
}
break;
default:
break;
}
return false;
}
bool LedKeyboard::setMNKey(uint8_t value) {
LedKeyboard::byte_buffer_t data;
switch (m_keyboardModel) {
case KeyboardModel::g910:
switch (value) {
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
data = { 0x11, 0xff, 0x09, 0x1e, value };
data.resize(20, 0x00);
return sendDataInternal(data);
default:
break;
}
break;
default:
break;
}
return false;
}
bool LedKeyboard::setStartupMode(StartupMode startupMode) { bool LedKeyboard::setStartupMode(StartupMode startupMode) {
byte_buffer_t data; byte_buffer_t data;
switch (m_keyboardModel) { switch (m_keyboardModel) {

View File

@ -140,6 +140,9 @@ class LedKeyboard {
bool setGroupKeys(KeyGroup keyGroup, Color color); bool setGroupKeys(KeyGroup keyGroup, Color color);
bool setAllKeys(Color color); bool setAllKeys(Color color);
bool setMRKey(uint8_t value);
bool setMNKey(uint8_t value);
bool setStartupMode(StartupMode startupMode); bool setStartupMode(StartupMode startupMode);
bool setNativeEffect(NativeEffect effect, NativeEffectPart part, uint8_t speed, Color color); bool setNativeEffect(NativeEffect effect, NativeEffectPart part, uint8_t speed, Color color);

View File

@ -8,7 +8,7 @@ using namespace std;
namespace help { namespace help {
string version = "0.1.0"; string version = "0.1.1";
void usage(char *arg0) { void usage(char *arg0) {
string cmdName = utils::getCmdName(arg0); string cmdName = utils::getCmdName(arg0);
@ -19,10 +19,18 @@ namespace help {
cout<<" -a {color}\t\t\t\tSet all keys color"<<endl; cout<<" -a {color}\t\t\t\tSet all keys color"<<endl;
cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl; cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl;
cout<<" -k {key} {color}\t\t\tSet key color"<<endl; cout<<" -k {key} {color}\t\t\tSet key color"<<endl;
if (cmdName == "g910-led") {
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<<endl; cout<<endl;
cout<<" -an {color}\t\t\t\tSet all keys color without commit"<<endl; cout<<" -an {color}\t\t\t\tSet all keys color without commit"<<endl;
cout<<" -gn {keygroup} {color}\t\tSet key group color without commit"<<endl; cout<<" -gn {keygroup} {color}\t\tSet key group color without commit"<<endl;
cout<<" -kn {key} {color}\t\t\tSet key color without commit"<<endl; cout<<" -kn {key} {color}\t\t\tSet key color without commit"<<endl;
if (cmdName == "g910-led") {
cout<<" -mrn {value}\t\t\t\tSet MR key without commit"<<endl;
cout<<" -mnn {value}\t\t\t\tSet MN key without commit"<<endl;
}
cout<<" -c\t\t\t\t\tCommit change"<<endl; cout<<" -c\t\t\t\t\tCommit change"<<endl;
cout<<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;

View File

@ -209,4 +209,11 @@ namespace utils {
return true; return true;
} }
bool parseUInt8(std::string val, uint8_t &uint8) {
if (val.length() == 1) val = "0" + val;
if (val.length() != 2) return false;
uint8 = std::stoul("0x" + val, nullptr, 16);
return true;
}
} }

View File

@ -15,6 +15,7 @@ namespace utils {
bool parseKeyGroup(std::string val, LedKeyboard::KeyGroup &keyGroup); bool parseKeyGroup(std::string val, LedKeyboard::KeyGroup &keyGroup);
bool parseColor(std::string val, LedKeyboard::Color &color); bool parseColor(std::string val, LedKeyboard::Color &color);
bool parseSpeed(std::string val, uint8_t &speed); bool parseSpeed(std::string val, uint8_t &speed);
bool parseUInt8(std::string val, uint8_t &uint8);
} }

View File

@ -46,6 +46,24 @@ int setKey(LedKeyboard &kbd, std::string arg2, std::string arg3, bool commit = t
return 0; return 0;
} }
int setMRKey(LedKeyboard &kbd, std::string arg2, bool commit = true) {
uint8_t value;
if (! utils::parseUInt8(arg2, value)) return 1;
if (! kbd.open()) return 1;
if (! kbd.setMRKey(value)) return 1;
if (commit) if(! kbd.commit()) return 1;
return 0;
}
int setMNKey(LedKeyboard &kbd, std::string arg2, bool commit = true) {
uint8_t value;
if (! utils::parseUInt8(arg2, value)) return 1;
if (! kbd.open()) return 1;
if (! kbd.setMNKey(value)) return 1;
if (commit) if(! kbd.commit()) return 1;
return 0;
}
int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = "") { int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = "") {
LedKeyboard::NativeEffect effect; LedKeyboard::NativeEffect effect;
@ -203,9 +221,13 @@ int main(int argc, char **argv) {
else if (argc > 2 && arg == "-a") return setAllKeys(kbd, argv[2]); else if (argc > 2 && arg == "-a") return setAllKeys(kbd, argv[2]);
else if (argc > 3 && arg == "-g") return setGroupKeys(kbd, argv[2], argv[3]); else if (argc > 3 && arg == "-g") return setGroupKeys(kbd, argv[2], argv[3]);
else if (argc > 3 && arg == "-k") return setKey(kbd, argv[2], argv[3]); else if (argc > 3 && arg == "-k") return setKey(kbd, argv[2], argv[3]);
else if (argc > 2 && arg == "-mr") return setMRKey(kbd, argv[2]);
else if (argc > 2 && arg == "-mn") return setMNKey(kbd, argv[2]);
else if (argc > 2 && arg == "-an") return setAllKeys(kbd, argv[2], false); else if (argc > 2 && arg == "-an") return setAllKeys(kbd, argv[2], false);
else if (argc > 3 && arg == "-gn") return setGroupKeys(kbd, argv[2], argv[3], false); else if (argc > 3 && arg == "-gn") return setGroupKeys(kbd, argv[2], argv[3], false);
else if (argc > 3 && arg == "-kn") return setKey(kbd, argv[2], argv[3], false); else if (argc > 3 && arg == "-kn") return setKey(kbd, argv[2], argv[3], false);
else if (argc > 2 && arg == "-mrn") return setMRKey(kbd, argv[2], false);
else if (argc > 2 && arg == "-mnn") return setMNKey(kbd, argv[2], false);
else if (argc > 2 && arg == "-p") return loadProfile(kbd, argv[2]); else if (argc > 2 && arg == "-p") return loadProfile(kbd, argv[2]);
else if (argc > 1 && arg == "-pp") return pipeProfile(kbd); else if (argc > 1 && arg == "-pp") return pipeProfile(kbd);