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

Issue #157: -fx-store sets user-stored lighting on G Pro

This commit is contained in:
Daniel Eble 2019-01-01 22:14:39 -05:00
parent 79aa3b278c
commit af802446fb
5 changed files with 64 additions and 26 deletions

View File

@ -568,7 +568,8 @@ bool LedKeyboard::setAllKeys(LedKeyboard::Color color) {
for (uint8_t rIndex=0x01; rIndex <= 0x05; rIndex++) if (! setRegion(rIndex, color)) return false; for (uint8_t rIndex=0x01; rIndex <= 0x05; rIndex++) if (! setRegion(rIndex, color)) return false;
return true; return true;
case KeyboardModel::g413: case KeyboardModel::g413:
setNativeEffect(NativeEffect::color, NativeEffectPart::keys, std::chrono::seconds(0), color); setNativeEffect(NativeEffect::color, NativeEffectPart::keys, std::chrono::seconds(0), color,
NativeEffectStorage::none);
return true; return true;
case KeyboardModel::g410: case KeyboardModel::g410:
case KeyboardModel::g513: case KeyboardModel::g513:
@ -697,7 +698,9 @@ bool LedKeyboard::setStartupMode(StartupMode startupMode) {
} }
bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, std::chrono::duration<uint16_t, std::milli> period, Color color) { bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part,
std::chrono::duration<uint16_t, std::milli> period, Color color,
NativeEffectStorage storage) {
uint8_t protocolByte = 0; uint8_t protocolByte = 0;
NativeEffectGroup effectGroup = static_cast<NativeEffectGroup>(static_cast<uint16_t>(effect) >> 8); NativeEffectGroup effectGroup = static_cast<NativeEffectGroup>(static_cast<uint16_t>(effect) >> 8);
@ -722,8 +725,8 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
break; break;
} }
return ( return (
setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, period, color) && setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, period, color, storage) &&
setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, period, color)); setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, period, color, storage));
} }
switch (currentDevice.model) { switch (currentDevice.model) {
@ -747,7 +750,7 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
} }
if ((effectGroup == NativeEffectGroup::waves) && (part == NativeEffectPart::logo)) { if ((effectGroup == NativeEffectGroup::waves) && (part == NativeEffectPart::logo)) {
return setNativeEffect(NativeEffect::color, part, std::chrono::seconds(0), Color({0x00, 0xff, 0xff})); return setNativeEffect(NativeEffect::color, part, std::chrono::seconds(0), Color({0x00, 0xff, 0xff}), storage);
} }
byte_buffer_t data = { byte_buffer_t data = {
@ -763,7 +766,7 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
0x64, // unused? 0x64, // unused?
// period of wave effect (ms) // period of wave effect (ms)
static_cast<uint8_t>(period.count() >> 8), // LSB is shared with cycle effect above static_cast<uint8_t>(period.count() >> 8), // LSB is shared with cycle effect above
0, // change to 1 to store this effect as the user effect (issue #157) static_cast<uint8_t>(storage),
0, // unused? 0, // unused?
0, // unused? 0, // unused?
0, // unused? 0, // unused?

View File

@ -54,6 +54,9 @@ class LedKeyboard {
gpro gpro
}; };
enum class StartupMode : uint8_t { enum class StartupMode : uint8_t {
// TODO: On the G Pro, the value 1 selects the
// user-stored lighting effect, which is not
// necessarily wave.
wave = 0x01, wave = 0x01,
color color
}; };
@ -77,6 +80,11 @@ class LedKeyboard {
keys = 0x00, keys = 0x00,
logo logo
}; };
enum class NativeEffectStorage : uint8_t {
none = 0x00,
// "user-stored lighting" can be recalled with backlight+7
user,
};
enum class KeyGroup : uint8_t { enum class KeyGroup : uint8_t {
logo = 0x00, logo = 0x00,
indicators, indicators,
@ -173,7 +181,8 @@ class LedKeyboard {
bool setStartupMode(StartupMode startupMode); bool setStartupMode(StartupMode startupMode);
bool setNativeEffect(NativeEffect effect, NativeEffectPart part, bool setNativeEffect(NativeEffect effect, NativeEffectPart part,
std::chrono::duration<uint16_t, std::milli> period, Color color); std::chrono::duration<uint16_t, std::milli> period, Color color,
NativeEffectStorage storage);
private: private:

View File

@ -59,7 +59,10 @@ namespace help {
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\tActivate an on-board lighting effect"<<endl;
if((features | KeyboardFeatures::userstoredlighting) == features)
cout<<" -fx-store ...\t\t\t\tSet an on-board effect as user-stored lighting"<<endl;
cout<<" \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;
@ -245,15 +248,22 @@ namespace help {
cout<<endl; cout<<endl;
cout<<"At this time, FX are only tested on g512, g810, and gpro !"<<endl; cout<<"At this time, FX are only tested on g512, g810, and gpro !"<<endl;
cout<<endl; cout<<endl;
cout<<" -fx {effect} {target}"<<endl; cout<<" -fx ... \t\t\t\tActivate an on-board lighting effect"<<endl;
string optionalStore;
if((features | KeyboardFeatures::userstoredlighting) == features) {
cout<<" -fx-store ...\t\t\t\tSet an on-board effect as user-stored lighting"<<endl;
optionalStore = "[-store]";
}
cout<<endl; cout<<endl;
cout<<" -fx color {target} {color}"<<endl; cout<<" -fx" << optionalStore << " {effect} {target}"<<endl;
cout<<" -fx breathing {target} {color} {period}"<<endl; cout<<endl;
cout<<" -fx cycle {target} {period}"<<endl; cout<<" -fx" << optionalStore << " color {target} {color}"<<endl;
cout<<" -fx waves {target} {period}"<<endl; cout<<" -fx" << optionalStore << " breathing {target} {color} {period}"<<endl;
cout<<" -fx hwave {target} {period}"<<endl; cout<<" -fx" << optionalStore << " cycle {target} {period}"<<endl;
cout<<" -fx vwave {target} {period}"<<endl; cout<<" -fx" << optionalStore << " waves {target} {period}"<<endl;
cout<<" -fx cwave {target} {period}"<<endl; cout<<" -fx" << optionalStore << " hwave {target} {period}"<<endl;
cout<<" -fx" << optionalStore << " vwave {target} {period}"<<endl;
cout<<" -fx" << optionalStore << " cwave {target} {period}"<<endl;
cout<<endl; cout<<endl;
if((features | KeyboardFeatures::logo1) == features) if((features | KeyboardFeatures::logo1) == features)
cout<<"target value :\t\t\t\tall, keys, logo"<<endl; cout<<"target value :\t\t\t\tall, keys, logo"<<endl;

View File

@ -21,19 +21,21 @@ namespace help {
setregion = 2048, setregion = 2048,
setindicators = 4096, setindicators = 4096,
poweronfx = 8192, poweronfx = 8192,
// "user-stored lighting" can be recalled with backlight+7 on the G Pro
userstoredlighting = 16384,
// fx features // fx features
all = rgb | intensity | commit | logo1 | logo2 | numpad | multimedia | gkeys | all = rgb | intensity | commit | logo1 | logo2 | numpad | multimedia | gkeys |
setall | setgroup | setkey | setregion | setindicators | poweronfx, setall | setgroup | setkey | setregion | setindicators | poweronfx | userstoredlighting,
g213 = rgb | logo1 | numpad | multimedia | setall | setregion | setindicators | poweronfx, g213 = rgb | logo1 | numpad | multimedia | setall | setregion | setindicators | poweronfx | userstoredlighting,
g410 = rgb | commit | setall | setgroup | setkey | poweronfx, g410 = rgb | commit | setall | setgroup | setkey | poweronfx | userstoredlighting,
g413 = intensity | setall, g413 = intensity | setall | userstoredlighting,
g513 = rgb | commit | numpad | setall | setgroup | setkey | setindicators | poweronfx, g513 = rgb | commit | numpad | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting,
g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx, g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting,
g810 = rgb | 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, g910 = rgb | commit | logo1 | logo2 | numpad | multimedia | gkeys | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting,
gpro = rgb | commit | logo1 | setall | setgroup | setkey | setindicators | poweronfx gpro = rgb | commit | logo1 | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting
}; };
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b); inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b);

View File

@ -103,7 +103,8 @@ int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3) {
return 1; return 1;
} }
int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = "") { int setFX(LedKeyboard &kbd, LedKeyboard::NativeEffectStorage storage,
const std::string &arg2, const std::string &arg3, const std::string &arg4, const std::string &arg5) {
LedKeyboard::NativeEffect effect; LedKeyboard::NativeEffect effect;
LedKeyboard::NativeEffectPart effectPart; LedKeyboard::NativeEffectPart effectPart;
std::chrono::duration<uint16_t, std::milli> period(0); std::chrono::duration<uint16_t, std::milli> period(0);
@ -131,11 +132,20 @@ int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4
if (! kbd.open()) return 1; if (! kbd.open()) return 1;
if (! kbd.setNativeEffect(effect, effectPart, period, color)) return 1; if (! kbd.setNativeEffect(effect, effectPart, period, color, storage)) return 1;
return 0; return 0;
} }
int setFX(LedKeyboard &kbd, const std::string &arg2, const std::string &arg3, const std::string &arg4 = std::string(),
const std::string &arg5 = std::string()) {
return setFX(kbd, LedKeyboard::NativeEffectStorage::none, arg2, arg3, arg4, arg5);
}
int storeFX(LedKeyboard &kbd, const std::string &arg2, const std::string &arg3, const std::string &arg4 = std::string(),
const std::string &arg5 = std::string()) {
return setFX(kbd, LedKeyboard::NativeEffectStorage::user, arg2, arg3, arg4, arg5);
}
int setStartupMode(LedKeyboard &kbd, std::string arg2) { int setStartupMode(LedKeyboard &kbd, std::string arg2) {
LedKeyboard::StartupMode startupMode; LedKeyboard::StartupMode startupMode;
@ -303,6 +313,10 @@ int main(int argc, char **argv) {
return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3], argv[argIndex + 4]); return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3], argv[argIndex + 4]);
else if (argc > (argIndex + 3) && arg == "-fx") else if (argc > (argIndex + 3) && arg == "-fx")
return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3]); return setFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3]);
else if (argc > (argIndex + 4) && arg == "-fx-store")
return storeFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3], argv[argIndex + 4]);
else if (argc > (argIndex + 3) && arg == "-fx-store")
return storeFX(kbd, argv[argIndex + 1], argv[argIndex + 2], argv[argIndex + 3]);
else if (argc > (argIndex + 1) && arg == "--startup-mode") return setStartupMode(kbd, argv[argIndex + 1]); else if (argc > (argIndex + 1) && arg == "--startup-mode") return setStartupMode(kbd, argv[argIndex + 1]);
else { help::usage(argv[0]); return 1; } else { help::usage(argv[0]); return 1; }
} }