Skip to content

Commit

Permalink
change USBQuirks LEDs to B, N
Browse files Browse the repository at this point in the history
Also, add a method to override the indicators, and document.
  • Loading branch information
tlyu committed Dec 4, 2023
1 parent 36c54df commit 99f2e5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 9 additions & 0 deletions plugins/Kaleidoscope-USB-Quirks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ The plugin provides one object, `USBQuirks`, which provides the following method
> to detach and then re-attach to the host. (This re-attach is necessary to
> force re-enumeration with a different Report Descriptor.)
>
> Switching the toggle also lights up a key indicating the mode being
> switched to: by default, `B` for boot reports only, and `N` for extended
> reports enabled.
>
> The extended key report supports n-key rollover (NKRO), and is actually a
> hybrid, having a prefix containing the boot report, for compatibility
> with older hosts. The boot report only supports 6-key rollover (6KRO),
Expand All @@ -49,3 +53,8 @@ The plugin provides one object, `USBQuirks`, which provides the following method
> of the hybrid extended report should accommodate some of these hosts.
> This toggle helps to work with hosts that neither request boot protocol
> nor tolerate the longer hybrid report.
### `.setKeys(Key boot_led, Key nkro_led)`
> Set which keys to light up to indicate the target mode. Defaults to
> `(Key_B, Key_N)`.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
namespace kaleidoscope {
namespace plugin {

KeyAddr findKey(Key search_key) {
KeyAddr USBQuirks::key_boot_addr = KeyAddr::none();
KeyAddr USBQuirks::key_nkro_addr = KeyAddr::none();

static KeyAddr findKey(Key search_key) {
for (auto key_addr : KeyAddr::all()) {
Key k = Layer.lookupOnActiveLayer(key_addr);

Expand All @@ -40,9 +43,13 @@ KeyAddr findKey(Key search_key) {
return KeyAddr::none();
}

void USBQuirks::setKeys(Key boot_led, Key nkro_led) {
key_boot_addr = findKey(boot_led);
key_nkro_addr = findKey(nkro_led);
}

EventHandlerResult USBQuirks::onSetup() {
key_6_addr = findKey(Key_6);
key_n_addr = findKey(Key_N);
setKeys(Key_B, Key_N);
return EventHandlerResult::OK;
}

Expand All @@ -51,9 +58,9 @@ void USBQuirks::toggleKeyboardProtocol() {
uint8_t new_bootonly = !Runtime.hid().keyboard().getBootOnly();

if (new_bootonly) {
key_addr = key_6_addr;
key_addr = key_boot_addr;
} else {
key_addr = key_n_addr;
key_addr = key_nkro_addr;
}
::LEDControl.disable();
if (key_addr.isValid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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

namespace kaleidoscope {
Expand All @@ -27,10 +28,11 @@ class USBQuirks : public kaleidoscope::Plugin {
public:
void toggleKeyboardProtocol();
EventHandlerResult onSetup();
static void setKeys(Key boot_led, Key nkro_led);

private:
KeyAddr key_6_addr;
KeyAddr key_n_addr;
static KeyAddr key_boot_addr;
static KeyAddr key_nkro_addr;
};

} // namespace plugin
Expand Down

0 comments on commit 99f2e5c

Please sign in to comment.