-
-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
RGB Matrix: Ability to define custom effects from keymaps #5329
Comments
Hi, I have read through your proposal and there is one part i think should be adjusted to male it easier for a user to add RGB effects, this is the overrides in keymap.c, would there be a way where we could automatically do this say by the use of an ifdef or just an if/else statement so that when the user has rgb_matrix_custom_mode_f_custom_modes[] it automatically overides. Im also not sure whether that name is quite suitable or should be more like rgb_matrix_custom_user and also therefore possibly should have a rgb_matrix_custom_kb to follow the naming scheme for kb/user. Other than those two aspects this is a feature that i personally see good use for however also needs to be made simpler for all drivers similar to what was said in your original PR |
Thanks for the feedback!
I'm a bit confused by what you mean when you say you want overrides to be done "automatically," or how a ifdef-based system might work. With the current proposal, things are already pretty automatic, since once the user defines the two variables (the array, and the length), things would "just work." Could you elaborate on what you had in mind? |
Hi, apologies, when i was on mobile it looked like there where 4/5 different varibles a user had to define however as its only two ignore me about that as 2 variables are fine. |
@daniel5151 I really like where you are going with this approach and think we should also apply a similar array / function pointer system to rgb matrix for the base effects eventually. I have a few thoughts on the approach:
|
Glad to hear! I definitely think that an array of effect pointers would be nicer than the current switch-statement based system (I hate the sea of ifdef-endifs the current system requires haha)
|
|
static void my_effect(bool init) { /**/ }
static void another_effect(bool init) { /**/ }
void rgb_matrix_init_user(rgb_matrix_anims* anims, uint8_t size) {
anims[0] = my_effect;
anims[1] = another_effect;
} If that's the case, then it might make sense to just stick with defining an array. As for the double-duty thing, I just reread my comment, and I realize I go tripped up on rgb_matrix subsystem instantiation, and rgb_matrix effect instantiation, so disregard my comments
static inline void my_complex_effect_init() { /**/ }
static inline void my_complex_effect_tick() { /**/ }
void my_complex_effect(bool init) {
if (init) my_complex_effect_init();
my_complex_effect_tick();
} Which the compiler should properly inline. Your void* scratchpad idea intrigues me... |
Ahh, I remember why I was running into issues when using the weakly-linked arrays! Consider this (super simplified) scenario: // somewhere in rgb_matrix.c
if (rgb_matrix_effects_user_count > 0) rgb_matrix_effects_user[i]();
// but later on, in the same file
__attribute__ ((weak))
const rgb_matrix_custom_effect_f rgb_matrix_effects_user[] = {};
__attribute__ ((weak))
const uint8_t rgb_matrix_effects_user_count[] = 0; Even if the symbol is redefined to a non-empty array, the compiler will still emit the following warning (warnings = errors in QMK): warning: array subscript is above array bounds [-Warray-bounds]
if (rgb_matrix_effects_user_count > 0) rgb_matrix_effects_user[i]();
~~~~~~~~~~~~~~~~~~~~~~~^~~ It's not smart enough to recognize the check / see the weak linking, and prevents things from compiling. After playing around with it a bit more, it looks a workaround for this issue would be to move those default weak instantiations into a separate compilation unit (something like |
I think this can be closed. |
The current method of creating custom lighting effects through RGB Matrix from user keymaps is by calling
rgb_matrix_set_color
from methods such asprocess_user
,matrix_scan_user
, orrgb_matrix_indicators_user
. While this works fine for overriding a few LEDs here-and-there (to indicate caps-lock, or indicating the current layer), it's quite inefficient when overriding all LEDs, since RGB Matrix is still running it's own effects in the background.For example, my preferred lighting setup is a smooth red-orange gradient, with a on-keypress fade effect from green to the underlying color. Since there is no built-in RGB Matrix effect that can do this, I would have to write my own. This leaves me with 2 options:
Instead, it would be nice if there was a way to extend the built-in effects provided by RGB Matrix with new ones, and do so in a efficient and ergonomic manner.
I've actually taken a stab at this already (in the ill-fated PR #5096), and I'd like to reintroduce the feature in it's own standalone PR.
My proposed interface would be something akin to the following:
Users could then write their own effects, export those symbols, and have them show up in RGB Matrix like any other effect. i.e: RGB_TOG would cycle through the built-in effects, and once it reaches the end of the built-in effects, it would continue cycling through any custom-defined effects.
A simple example of how one might use this interface in a keymap:
I'll be putting up a PR soon-ish with the actual implementation, but I just wanted to throw up an issue first (to reference in the PR)
The text was updated successfully, but these errors were encountered: