mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 01:06:11 +00:00
Merge pull request #161 from DanEble/issue-157-store-effect
Issue #157: -fx-store sets user-stored lighting
This commit is contained in:
commit
0fd4801c7c
@ -568,7 +568,8 @@ bool LedKeyboard::setAllKeys(LedKeyboard::Color color) {
|
||||
for (uint8_t rIndex=0x01; rIndex <= 0x05; rIndex++) if (! setRegion(rIndex, color)) return false;
|
||||
return true;
|
||||
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;
|
||||
case KeyboardModel::g410:
|
||||
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;
|
||||
NativeEffectGroup effectGroup = static_cast<NativeEffectGroup>(static_cast<uint16_t>(effect) >> 8);
|
||||
|
||||
@ -722,8 +725,8 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
|
||||
break;
|
||||
}
|
||||
return (
|
||||
setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, period, color) &&
|
||||
setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, period, color));
|
||||
setNativeEffect(effect, LedKeyboard::NativeEffectPart::keys, period, color, storage) &&
|
||||
setNativeEffect(effect, LedKeyboard::NativeEffectPart::logo, period, color, storage));
|
||||
}
|
||||
|
||||
switch (currentDevice.model) {
|
||||
@ -747,7 +750,7 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
|
||||
}
|
||||
|
||||
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 = {
|
||||
@ -763,7 +766,7 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, st
|
||||
0x64, // unused?
|
||||
// period of wave effect (ms)
|
||||
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?
|
||||
|
@ -54,6 +54,9 @@ class LedKeyboard {
|
||||
gpro
|
||||
};
|
||||
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,
|
||||
color
|
||||
};
|
||||
@ -77,6 +80,11 @@ class LedKeyboard {
|
||||
keys = 0x00,
|
||||
logo
|
||||
};
|
||||
enum class NativeEffectStorage : uint8_t {
|
||||
none = 0x00,
|
||||
// "user-stored lighting" can be recalled with backlight+7
|
||||
user,
|
||||
};
|
||||
enum class KeyGroup : uint8_t {
|
||||
logo = 0x00,
|
||||
indicators,
|
||||
@ -173,7 +181,8 @@ class LedKeyboard {
|
||||
bool setStartupMode(StartupMode startupMode);
|
||||
|
||||
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:
|
||||
|
@ -59,7 +59,10 @@ namespace help {
|
||||
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\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<<" < {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;
|
||||
@ -245,15 +248,22 @@ namespace help {
|
||||
cout<<endl;
|
||||
cout<<"At this time, FX are only tested on g512, g810, and gpro !"<<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<<" -fx color {target} {color}"<<endl;
|
||||
cout<<" -fx breathing {target} {color} {period}"<<endl;
|
||||
cout<<" -fx cycle {target} {period}"<<endl;
|
||||
cout<<" -fx waves {target} {period}"<<endl;
|
||||
cout<<" -fx hwave {target} {period}"<<endl;
|
||||
cout<<" -fx vwave {target} {period}"<<endl;
|
||||
cout<<" -fx cwave {target} {period}"<<endl;
|
||||
cout<<" -fx" << optionalStore << " {effect} {target}"<<endl;
|
||||
cout<<endl;
|
||||
cout<<" -fx" << optionalStore << " color {target} {color}"<<endl;
|
||||
cout<<" -fx" << optionalStore << " breathing {target} {color} {period}"<<endl;
|
||||
cout<<" -fx" << optionalStore << " cycle {target} {period}"<<endl;
|
||||
cout<<" -fx" << optionalStore << " waves {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;
|
||||
if((features | KeyboardFeatures::logo1) == features)
|
||||
cout<<"target value :\t\t\t\tall, keys, logo"<<endl;
|
||||
|
@ -21,19 +21,21 @@ namespace help {
|
||||
setregion = 2048,
|
||||
setindicators = 4096,
|
||||
poweronfx = 8192,
|
||||
// "user-stored lighting" can be recalled with backlight+7 on the G Pro
|
||||
userstoredlighting = 16384,
|
||||
// fx features
|
||||
|
||||
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,
|
||||
g410 = rgb | commit | setall | setgroup | setkey | poweronfx,
|
||||
g413 = intensity | setall,
|
||||
g513 = rgb | commit | numpad | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
g213 = rgb | logo1 | numpad | multimedia | setall | setregion | setindicators | poweronfx | userstoredlighting,
|
||||
g410 = rgb | commit | setall | setgroup | setkey | poweronfx | userstoredlighting,
|
||||
g413 = intensity | setall | userstoredlighting,
|
||||
g513 = rgb | commit | numpad | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting,
|
||||
g610 = intensity | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx | userstoredlighting,
|
||||
g810 = rgb | commit | logo1 | numpad | multimedia | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
g910 = rgb | commit | logo1 | logo2 | numpad | multimedia | gkeys | setall | setgroup | setkey | setindicators | poweronfx,
|
||||
gpro = rgb | commit | logo1 | 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 | userstoredlighting
|
||||
};
|
||||
inline KeyboardFeatures operator|(KeyboardFeatures a, KeyboardFeatures b);
|
||||
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -103,7 +103,8 @@ int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3) {
|
||||
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::NativeEffectPart effectPart;
|
||||
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.setNativeEffect(effect, effectPart, period, color)) return 1;
|
||||
if (! kbd.setNativeEffect(effect, effectPart, period, color, storage)) return 1;
|
||||
|
||||
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) {
|
||||
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]);
|
||||
else if (argc > (argIndex + 3) && arg == "-fx")
|
||||
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 { help::usage(argv[0]); return 1; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user