From 0685e0001222071d31b9992a88d4d205e26693da Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sat, 2 Dec 2023 14:43:55 -0600 Subject: [PATCH] make USBQuirks show new mode --- .../src/kaleidoscope/plugin/USB-Quirks.cpp | 32 +++++++++++++++++++ .../src/kaleidoscope/plugin/USB-Quirks.h | 7 ++++ 2 files changed, 39 insertions(+) diff --git a/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.cpp b/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.cpp index 98ed0eef84..334e854410 100644 --- a/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.cpp +++ b/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.cpp @@ -23,16 +23,48 @@ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/device/device.h" // for Base<>::HID, VirtualProps::HID #include "kaleidoscope/driver/hid/keyboardio/Keyboard.h" // for Keyboard +#include "kaleidoscope/key_defs.h" // for Key +#include "kaleidoscope/plugin/LEDControl.h" // for LEDControl namespace kaleidoscope { namespace plugin { +KeyAddr findKey(Key search_key) { + for (auto key_addr : KeyAddr::all()) { + Key k = Layer.lookupOnActiveLayer(key_addr); + + if (k == search_key) { + return key_addr; + } + } + return KeyAddr::none(); +} + +EventHandlerResult USBQuirks::onSetup() { + key_6_addr = findKey(Key_6); + key_n_addr = findKey(Key_N); + return EventHandlerResult::OK; +} + void USBQuirks::toggleKeyboardProtocol() { + KeyAddr key_addr; uint8_t new_bootonly = !Runtime.hid().keyboard().getBootOnly(); + if (new_bootonly) { + key_addr = key_6_addr; + } else { + key_addr = key_n_addr; + } + ::LEDControl.disable(); + if (key_addr.isValid()) { + ::LEDControl.setCrgbAt(key_addr, CRGB(0, 0, 255)); + } + Runtime.device().syncLeds(); Runtime.detachFromHost(); Runtime.hid().keyboard().setBootOnly(new_bootonly); delay(1000); + ::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); + ::LEDControl.enable(); Runtime.attachToHost(); } diff --git a/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h b/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h index c8b5d4c99d..834850ec21 100644 --- a/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h +++ b/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h @@ -17,6 +17,8 @@ #pragma once +#include "kaleidoscope/KeyAddr.h" // for KeyAddr +#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/plugin.h" // for Plugin namespace kaleidoscope { @@ -24,6 +26,11 @@ namespace plugin { class USBQuirks : public kaleidoscope::Plugin { public: void toggleKeyboardProtocol(); + EventHandlerResult onSetup(); + + private: + KeyAddr key_6_addr; + KeyAddr key_n_addr; }; } // namespace plugin