TeXitoi / keyberon

A rust crate to create a pure rust keyboard firmware.
MIT License
1.08k stars 79 forks source link

Add a way to fire an Event without requiring a specific coordinate in a layout/Layers #101

Open riskable opened 2 years ago

riskable commented 2 years ago

I've got an absolute rotary selection knob in my latest prototype and I want to fire a Keyberon Event when the user changes modes (i.e. rotates the knob to a different position). However, to do something like that I need to have said event defined somewhere inside of Layers with a matching coordinate. My absolute rotary encoder has nothing to do with the keyboard's normal layout but I still want to be able to send a keystroke to the PC when it changes (just an example).

Right now I've got some code that defines one set of Layers for each encoder position (all 8 of them!) and swaps them out whenever the user changes its position. I went to add CustomEvents for each mode and realized there's no way to actually fire off a Keyberon Event without having an associated coordinate in a pre-existing Layers/layout. I could just add yet another virtual row/column to the Layers (like I'm doing with the infrared remote stuff) but if I do that it means my Layers will grow from A columns/rows times B defined layers times 8 (number of encoder positions/modes) which is a lot of duplicated code inside of my layers.rs. It's getting out of hand already with everything duplicated 8 times (it's already over 5000 lines!).

It would be so much easier if I could do something like:

// This wouldn't be associated with any given row/column:
layout.new_virtual_event(CustomEvent::Whatever, k(A));
layout.virtual_event(CustomEvent::Whatever::Press());

...or provide a mechanism to attach arbitrary custom events like that to Layers when setting it up.

As a (really rough) alternative I could work around this if there were some way to use multiple Layers variables at once and combine them into a single keyboard report when needed.