From a5acdf411311004cfdba046744d4c683a55179cb Mon Sep 17 00:00:00 2001 From: cornernote Date: Tue, 14 Jan 2020 08:40:45 +1030 Subject: [PATCH] add support for g815 on-board-mode --- src/classes/Keyboard.cpp | 27 ++++++++++++++++++++++++--- src/classes/Keyboard.h | 5 +++++ src/helpers/help.cpp | 8 ++++++++ src/helpers/help.h | 5 +++-- src/helpers/utils.cpp | 13 ++++++++++--- src/helpers/utils.h | 3 ++- src/main.cpp | 11 +++++++++++ 7 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 7da2cfe..1c3b286 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -755,9 +755,6 @@ bool LedKeyboard::setStartupMode(StartupMode startupMode) { case KeyboardModel::gpro: data = { 0x11, 0xff, 0x0d, 0x5a, 0x00, 0x01 }; break; - case KeyboardModel::g815: - data = { 0x11, 0xff, 0x11, 0x1b, 0x02 }; - break; case KeyboardModel::g910: data = { 0x11, 0xff, 0x10, 0x5e, 0x00, 0x01 }; break; @@ -769,6 +766,30 @@ bool LedKeyboard::setStartupMode(StartupMode startupMode) { return sendDataInternal(data); } +bool LedKeyboard::setOnBoardMode(OnBoardMode onBoardMode) { + byte_buffer_t data; + switch (currentDevice.model) { + case KeyboardModel::g815: + switch (onBoardMode) { + case LedKeyboard::OnBoardMode::board: + data = { 0x11, 0xff, 0x11, 0x1a, 0x01 }; + data.resize(20, 0x00); + return sendDataInternal(data); + case LedKeyboard::OnBoardMode::software: + data = { 0x11, 0xff, 0x11, 0x1b, 0x02 }; + data.resize(20, 0x00); + return sendDataInternal(data); + default: + break; + } + break; + default: + return false; + } + data.push_back((unsigned char)onBoardMode); + data.resize(20, 0x00); + return sendDataInternal(data); +} bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, std::chrono::duration period, Color color, diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index 74505e2..41dca80 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -78,6 +78,10 @@ class LedKeyboard { wave = 0x01, color }; + enum class OnBoardMode : uint8_t { + board = 0x01, + software + }; enum class NativeEffectGroup : uint8_t { off, color, @@ -201,6 +205,7 @@ class LedKeyboard { bool setRegion(uint8_t region, Color color); bool setStartupMode(StartupMode startupMode); + bool setOnBoardMode(OnBoardMode onBoardMode); bool setNativeEffect(NativeEffect effect, NativeEffectPart part, std::chrono::duration period, Color color, diff --git a/src/helpers/help.cpp b/src/helpers/help.cpp index 30a7f45..f53a322 100644 --- a/src/helpers/help.cpp +++ b/src/helpers/help.cpp @@ -90,6 +90,10 @@ namespace help { cout<<" --startup-mode {startup mode}\t\tSet startup mode"< 1) { if (setStartupMode(kbd, args[1]) == 1) retval = 1; + } else if (args[0] == "obm" && args.size() > 1) { + if (setOnBoardMode(kbd, args[1]) == 1) retval = 1; } else if (args[0] == "fx" && args.size() > 4) { if (setFX(kbd, args[1], args[2], args[3], args[4]) == 1) retval = 1; } else if (args[0] == "fx" && args.size() > 3) { @@ -336,6 +346,7 @@ int main(int argc, char **argv) { 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 == "--on-board-mode") return setOnBoardMode(kbd, argv[argIndex + 1]); else { help::usage(argv[0]); return 1; } }