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..bec183e52b 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/plugin/LEDControl.h" +#include "kaleidoscope/key_defs.h" 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..e10eb196b0 100644 --- a/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h +++ b/plugins/Kaleidoscope-USB-Quirks/src/kaleidoscope/plugin/USB-Quirks.h @@ -18,12 +18,18 @@ #pragma once #include "kaleidoscope/plugin.h" // for Plugin +#include "kaleidoscope/KeyAddr.h" +#include "kaleidoscope/event_handler_result.h" namespace kaleidoscope { namespace plugin { class USBQuirks : public kaleidoscope::Plugin { public: void toggleKeyboardProtocol(); + EventHandlerResult onSetup(); + private: + KeyAddr key_6_addr; + KeyAddr key_n_addr; }; } // namespace plugin