]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/rgb_matrix_animations/raindrops_anim.h
rgb_led struct conversion (aka: Per led (key) type rgb matrix effects - part 2) ...
[qmk_firmware.git] / quantum / rgb_matrix_animations / raindrops_anim.h
1 #pragma once
2 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
3 #include "rgb_matrix_types.h"
4
5 extern rgb_counters_t g_rgb_counters;
6 extern led_config_t g_led_config;
7 extern rgb_config_t rgb_matrix_config;
8
9 static void raindrops_set_color(int i, effect_params_t* params) {
10   if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
11   HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val };
12
13   // Take the shortest path between hues
14   int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4;
15   if (deltaH > 127) {
16     deltaH -= 256;
17   } else if (deltaH < -127) {
18     deltaH += 256;
19   }
20
21   hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03));
22   RGB rgb = hsv_to_rgb(hsv);
23   rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
24 }
25
26 bool rgb_matrix_raindrops(effect_params_t* params) {
27   if (!params->init) {
28     // Change one LED every tick, make sure speed is not 0
29     if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
30       raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
31     }
32     return false;
33   }
34
35   RGB_MATRIX_USE_LIMITS(led_min, led_max);
36   for (int i = led_min; i < led_max; i++) {
37     raindrops_set_color(i, params);
38   }
39   return led_max < DRIVER_LED_TOTAL;
40 }
41
42 #endif // DISABLE_RGB_MATRIX_RAINDROPS