diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 47ec2e0..c342262 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -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 period, Color color) { +bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, + std::chrono::duration period, Color color, + NativeEffectStorage storage) { uint8_t protocolByte = 0; NativeEffectGroup effectGroup = static_cast(static_cast(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(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(storage), 0, // unused? 0, // unused? 0, // unused? diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index b7266d3..ea2521e 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -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 period, Color color); + std::chrono::duration period, Color color, + NativeEffectStorage storage); private: diff --git a/src/helpers/help.cpp b/src/helpers/help.cpp index e1e7b53..850442d 100644 --- a/src/helpers/help.cpp +++ b/src/helpers/help.cpp @@ -59,7 +59,10 @@ namespace help { cout<<" -c\t\t\t\t\tCommit change"< 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; } }