Skip to content

Commit

Permalink
make USBQuirks show new mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tlyu committed Dec 2, 2023
1 parent f205851 commit 0685e00
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@

#pragma once

#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin

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
Expand Down

0 comments on commit 0685e00

Please sign in to comment.