-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enables use of custom keycodes on Torn encoders #12887
Conversation
keyboards/torn/torn_encoder.c
Outdated
@@ -32,6 +32,7 @@ static uint8_t encoder_state = 0; | |||
static int8_t encoder_pulses = 0; | |||
|
|||
__attribute__((weak)) extern const uint16_t PROGMEM encoder_keymaps[][2][2]; | |||
bool encoder_update_user(uint16_t keycode, bool clockwise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have little-to-no experience with C, so I'm not sure if this is the right way to define this function that can be overridden by the keymap.
Is there a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work right now, because it's a different type for the function. However, I do have a PR that changes the encoder code to support this. #12805 specifically.
For now...
bool encoder_update_user(uint16_t keycode, bool clockwise); | |
__attribute__((weak)) encoder_update_user(uint16_t keycode, bool clockwise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for me, but I'm sure you mean some other kind of "works". Can I use is with the bool
return type for now? I need to know if the keymap overrode the given key code so that torn_encoder.c
knows to not send a keycode itself.
It looks like your merged PR does this? Is there a proper way I can fall in line with those changes that you made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you target develop instead, yes. Otherwise, it's wait for the breaking changes process, and update this in june.
Also, you may be interested in:
#12982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Missed that this repo is using gitflow.
#12982 is confusing me a bit. How would it look like to set the keycodes triggered on encoder rotation in the LAYOUT? And when you do, are custom keycodes that are set for encoder rotations in this way handled in the same ..._kb
macro function for the keymap level?
I'll look at rebasing onto develop and updating this PR, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drashna done, how does it look now?
I noticed that encoder_update_user()
passes an index develop
, but with the keymap is passes a keycode to the user's keymap. Am I using it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the PR in question changes how the encoder code works. It points to a location in the switch matrix, and then calls that via "action_exec", which is the lowest level event for a switch being triggered. This allows non-basic keycodes (including macros) to be used for the encoder, which also adds VIA support for encoders, since the keycode for them is set in the keymap.
Which is why I mentioned it. And it is most likely the way we're headed rather than the encoder_keymap
type method.
As for the callback, I mistyped above. The main difference between master and develop is that the callbacks are now boolean, which allows for them to be over-ridden, if/when needed. I'm just ... very used to typing out the process_record_*
function...
eg:
bool encoder_update_user(uint16_t keycode, bool clockwise); | |
bool encoder_update_user(uint8_t index, bool clockwise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh just noticed that it's a uint8_t
instead of a uint16_t
, so it can't take custom passed key bodes like the keyboard switch press custom function can:
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
Would be nice if the new encoder function that returns a bool could have the first argument be the key code, rather than the index so the keymap doesn't have to lookup the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drashna whoops! I hadn't realised you'd replied for sending my last comment.
So does that mean that the keycodes that encores send on rotate also need to be assigned to a switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I've crudely made a torn
version of the method until I get this working with the new approach you've made @drashna.
I'm still not sure how clear it is for encoder rotation keycodes to be in the switch layout. I think it makes it harder to read the layout, rather than separating them.
f068e69
to
6383d63
Compare
Thank you for your contribution! |
@@ -52,7 +50,9 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { | |||
code = encoder_default[index][clockwise]; | |||
} | |||
|
|||
tap_code16(code); | |||
if (encoder_update_user(code, clockwise) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic is inverted. False is that the kb code should NOT be respected.
if (encoder_update_user(code, clockwise) == false) { | |
if (encoder_update_user(code, clockwise)) { |
Thank you for your contribution! |
Thank you for your contribution! |
Description
I noticed that custom key codes were not working via the encoders on my Torn kb.
It seems that the
keymap.c
isn't called to check if it wants to override a given keycode on encoder rotation. This PR attempts to fix that.I've notified the keyboard designer (@rtitmuss) that I will be trying to make this fix.
Types of Changes
Checklist