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