@@ -95,6 +95,60 @@ static bool CANDY_SPLASH(effect_params_t* params) {
9595#endif // ENABLE_RGB_MATRIX_CUSTOM_CANDY_SPLASH
9696
9797
98+ #ifdef ENABLE_RGB_MATRIX_CUSTOM_CANDY_PRESS
99+ RGB_MATRIX_EFFECT (CANDY_PRESS)
100+ # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
101+ # include " matrix.h"
102+
103+ // Store current brightness per LED (0 = dark, 255 = full)
104+ static uint8_t candy_press_v[RGB_MATRIX_LED_COUNT];
105+ static uint32_t candy_press_timer;
106+
107+ static bool CANDY_PRESS (effect_params_t * params) {
108+ if (params->iter == 0 ) {
109+ if (params->init ) memset (candy_press_v, 0 , sizeof (candy_press_v));
110+
111+ // On the first iteration, calculate brightness decay based on time scale since last update
112+ uint16_t delta = (uint16_t )MIN (g_rgb_timer - candy_press_timer, 0xFFFFu );
113+ uint8_t decay = (uint8_t )MIN (scale16by8 (delta, qadd8 (rgb_matrix_config.speed , 1 )), 255u );
114+ for (uint8_t i = 0 ; i < RGB_MATRIX_LED_COUNT; ++i) {
115+ if (candy_press_v[i]) candy_press_v[i] = qsub8 (candy_press_v[i], decay);
116+ }
117+ candy_press_timer = g_rgb_timer;
118+
119+ // Scan the key matrix and set brightness to 255 for currently pressed keys
120+ for (uint8_t row = 0 ; row < MATRIX_ROWS; row++) {
121+ matrix_row_t row_state = matrix_get_row (row);
122+ if (!row_state) continue ;
123+ for (uint8_t col = 0 ; col < MATRIX_COLS; col++) {
124+ if (!((row_state >> col) & 1 )) continue ;
125+ uint8_t led = g_led_config.matrix_co [row][col];
126+ if (led < RGB_MATRIX_LED_COUNT) candy_press_v[led] = 255 ;
127+ }
128+ }
129+ }
130+
131+ // Apply a triwave colour effect to all LEDs with brightness based on current
132+ // candy_press_v value, creating a pulsing effect that responds to key presses
133+ RGB_MATRIX_USE_LIMITS (led_min, led_max);
134+ for (uint8_t i = led_min; i < led_max; i++) {
135+ if (!candy_press_v[i]) continue ;
136+ RGB_MATRIX_TEST_LED_FLAGS ();
137+ uint8_t now = scale16by8 (g_rgb_timer, qadd8 (rgb_matrix_config.speed / 16 , 1 ));
138+ hsv_t hsv = rgb_matrix_config.hsv ;
139+ hsv.h = (triwave8 (now) / 4 ) + (g_rgb_timer / 1024 );
140+ hsv.v = scale8 (candy_press_v[i], hsv.v );
141+ rgb_t rgb = rgb_matrix_hsv_to_rgb (hsv);
142+ rgb_matrix_set_color (i, rgb.r , rgb.g , rgb.b );
143+ }
144+
145+ return rgb_matrix_check_finished_leds (led_max);
146+ }
147+
148+ # endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
149+ #endif // ENABLE_RGB_MATRIX_CUSTOM_CANDY_PRESS
150+
151+
98152#ifdef ENABLE_RGB_MATRIX_CUSTOM_CANDY_PULSE
99153RGB_MATRIX_EFFECT (CANDY_PULSE)
100154# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
0 commit comments