From 1173f3125fff2cac2ff854e089a87c4030f67ceb Mon Sep 17 00:00:00 2001 From: KoenGoe Date: Wed, 23 Mar 2022 21:01:38 +0100 Subject: [PATCH 1/4] digital rain follows val rgb matrix digital rain animation adjust to listen to currently set rgb val. This also prevents it from dangerously ignoring `RGB_MATRIX_MAXIMUM_BRIGHTNESS`. Speed of decay is dynamically adjusted as well to keep time from full brightness to 0 roughly constant --- .../rgb_matrix/animations/digital_rain_anim.h | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h index 4633145ff6bd..b19b261cc25c 100644 --- a/quantum/rgb_matrix/animations/digital_rain_anim.h +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -10,11 +10,13 @@ RGB_MATRIX_EFFECT(DIGITAL_RAIN) bool DIGITAL_RAIN(effect_params_t* params) { // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain const uint8_t drop_ticks = 28; - const uint8_t pure_green_intensity = 0xd0; - const uint8_t max_brightness_boost = 0xc0; - const uint8_t max_intensity = 0xff; + const uint8_t pure_green_intensity = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; + const uint8_t max_brightness_boost = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; + const uint8_t max_intensity = rgb_matrix_config.hsv.v; + const uint8_t decay_ticks = 0xff / max_intensity; static uint8_t drop = 0; + static uint8_t decay = 0; if (params->init) { rgb_matrix_set_color_all(0, 0, 0); @@ -22,6 +24,7 @@ bool DIGITAL_RAIN(effect_params_t* params) { drop = 0; } + decay++; for (uint8_t col = 0; col < MATRIX_COLS; col++) { for (uint8_t row = 0; row < MATRIX_ROWS; row++) { if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { @@ -30,7 +33,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { g_rgb_frame_buffer[row][col] = max_intensity; } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { // neither fully bright nor dark, decay it - g_rgb_frame_buffer[row][col]--; + if(decay == decay_ticks){ + g_rgb_frame_buffer[row][col]--; + } } // set the pixel colour uint8_t led[LED_HITS_TO_REMEMBER]; @@ -48,6 +53,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { } } } + if(decay == decay_ticks){ + decay = 0; + } if (++drop > drop_ticks) { // reset drop timer @@ -59,9 +67,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { g_rgb_frame_buffer[row][col]--; } // check if the pixel above is bright - if (g_rgb_frame_buffer[row - 1][col] == max_intensity) { + if (g_rgb_frame_buffer[row - 1][col] >= max_intensity) { //Note: can be larger than max_intensity if val was recently decreased // allow old bright pixel to decay - g_rgb_frame_buffer[row - 1][col]--; + g_rgb_frame_buffer[row - 1][col] = max_intensity-1; // make this pixel bright g_rgb_frame_buffer[row][col] = max_intensity; } @@ -71,5 +79,5 @@ bool DIGITAL_RAIN(effect_params_t* params) { return false; } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) From 9441a7ce756e21ddab25d2deaa55a1b84643f41d Mon Sep 17 00:00:00 2001 From: KoenGoe Date: Wed, 23 Mar 2022 21:42:40 +0100 Subject: [PATCH 2/4] tab indent to 4 space indent formatting fix --- .../rgb_matrix/animations/digital_rain_anim.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h index b19b261cc25c..1bbbd86a3047 100644 --- a/quantum/rgb_matrix/animations/digital_rain_anim.h +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -13,10 +13,10 @@ bool DIGITAL_RAIN(effect_params_t* params) { const uint8_t pure_green_intensity = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; const uint8_t max_brightness_boost = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; const uint8_t max_intensity = rgb_matrix_config.hsv.v; - const uint8_t decay_ticks = 0xff / max_intensity; + const uint8_t decay_ticks = 0xff / max_intensity; static uint8_t drop = 0; - static uint8_t decay = 0; + static uint8_t decay = 0; if (params->init) { rgb_matrix_set_color_all(0, 0, 0); @@ -24,7 +24,7 @@ bool DIGITAL_RAIN(effect_params_t* params) { drop = 0; } - decay++; + decay++; for (uint8_t col = 0; col < MATRIX_COLS; col++) { for (uint8_t row = 0; row < MATRIX_ROWS; row++) { if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { @@ -33,9 +33,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { g_rgb_frame_buffer[row][col] = max_intensity; } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { // neither fully bright nor dark, decay it - if(decay == decay_ticks){ - g_rgb_frame_buffer[row][col]--; - } + if(decay == decay_ticks){ + g_rgb_frame_buffer[row][col]--; + } } // set the pixel colour uint8_t led[LED_HITS_TO_REMEMBER]; @@ -53,9 +53,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { } } } - if(decay == decay_ticks){ - decay = 0; - } + if(decay == decay_ticks){ + decay = 0; + } if (++drop > drop_ticks) { // reset drop timer From fc8b2a3bde68f506a6051fa69a320ca004e8f10d Mon Sep 17 00:00:00 2001 From: KoenGoe Date: Wed, 23 Mar 2022 21:57:18 +0100 Subject: [PATCH 3/4] reformatting of spacing --- .../rgb_matrix/animations/digital_rain_anim.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h index 1bbbd86a3047..b5dfaeaae398 100644 --- a/quantum/rgb_matrix/animations/digital_rain_anim.h +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -10,12 +10,12 @@ RGB_MATRIX_EFFECT(DIGITAL_RAIN) bool DIGITAL_RAIN(effect_params_t* params) { // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain const uint8_t drop_ticks = 28; - const uint8_t pure_green_intensity = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; - const uint8_t max_brightness_boost = (((uint16_t) rgb_matrix_config.hsv.v)*3)>>2; + const uint8_t pure_green_intensity = (((uint16_t) rgb_matrix_config.hsv.v) * 3) >> 2; + const uint8_t max_brightness_boost = (((uint16_t) rgb_matrix_config.hsv.v) * 3) >> 2; const uint8_t max_intensity = rgb_matrix_config.hsv.v; - const uint8_t decay_ticks = 0xff / max_intensity; + const uint8_t decay_ticks = 0xff / max_intensity; - static uint8_t drop = 0; + static uint8_t drop = 0; static uint8_t decay = 0; if (params->init) { @@ -33,7 +33,7 @@ bool DIGITAL_RAIN(effect_params_t* params) { g_rgb_frame_buffer[row][col] = max_intensity; } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { // neither fully bright nor dark, decay it - if(decay == decay_ticks){ + if (decay == decay_ticks) { g_rgb_frame_buffer[row][col]--; } } @@ -53,7 +53,7 @@ bool DIGITAL_RAIN(effect_params_t* params) { } } } - if(decay == decay_ticks){ + if (decay == decay_ticks) { decay = 0; } @@ -67,9 +67,9 @@ bool DIGITAL_RAIN(effect_params_t* params) { g_rgb_frame_buffer[row][col]--; } // check if the pixel above is bright - if (g_rgb_frame_buffer[row - 1][col] >= max_intensity) { //Note: can be larger than max_intensity if val was recently decreased + if (g_rgb_frame_buffer[row - 1][col] >= max_intensity) { // Note: can be larger than max_intensity if val was recently decreased // allow old bright pixel to decay - g_rgb_frame_buffer[row - 1][col] = max_intensity-1; + g_rgb_frame_buffer[row - 1][col] = max_intensity - 1; // make this pixel bright g_rgb_frame_buffer[row][col] = max_intensity; } @@ -79,5 +79,5 @@ bool DIGITAL_RAIN(effect_params_t* params) { return false; } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) From 8c39304197821a1902bbf23dc2f622627cdcef96 Mon Sep 17 00:00:00 2001 From: KoenGoe Date: Thu, 24 Mar 2022 10:06:01 +0100 Subject: [PATCH 4/4] Update format quantum/rgb_matrix/animations/digital_rain_anim.h Co-authored-by: Drashna Jaelre --- quantum/rgb_matrix/animations/digital_rain_anim.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h index b5dfaeaae398..7d3b22f697a1 100644 --- a/quantum/rgb_matrix/animations/digital_rain_anim.h +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -10,8 +10,8 @@ RGB_MATRIX_EFFECT(DIGITAL_RAIN) bool DIGITAL_RAIN(effect_params_t* params) { // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain const uint8_t drop_ticks = 28; - const uint8_t pure_green_intensity = (((uint16_t) rgb_matrix_config.hsv.v) * 3) >> 2; - const uint8_t max_brightness_boost = (((uint16_t) rgb_matrix_config.hsv.v) * 3) >> 2; + const uint8_t pure_green_intensity = (((uint16_t)rgb_matrix_config.hsv.v) * 3) >> 2; + const uint8_t max_brightness_boost = (((uint16_t)rgb_matrix_config.hsv.v) * 3) >> 2; const uint8_t max_intensity = rgb_matrix_config.hsv.v; const uint8_t decay_ticks = 0xff / max_intensity;