aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorM-AS <matthewtransformer@hotmail.com>2019-04-22 11:37:40 -0400
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-22 08:37:40 -0700
commitbb52119a6dfe9c6f0314d1bcd948efda59626a70 (patch)
treea385f30d3eee0bf585e1089f0907c24fa64523dc /quantum
parentb61baf4281bde34bfe28aaa1109bd5d5c6471116 (diff)
downloadqmk_firmware-bb52119a6dfe9c6f0314d1bcd948efda59626a70.tar.gz
qmk_firmware-bb52119a6dfe9c6f0314d1bcd948efda59626a70.zip
RGB Matrix Animations: Three/six new reactive effects (wide, cross, nexus) (#5602)
* added 3 new RGB_Matrix effects * made cross effect behavior smoother * removed dead code * added effect descriptions
Diffstat (limited to 'quantum')
-rw-r--r--quantum/rgb_matrix.c33
-rw-r--r--quantum/rgb_matrix.h18
-rw-r--r--quantum/rgb_matrix_animations/solid_reactive_cross.h50
-rw-r--r--quantum/rgb_matrix_animations/solid_reactive_nexus.h48
-rw-r--r--quantum/rgb_matrix_animations/solid_reactive_wide.h42
5 files changed, 191 insertions, 0 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index a1193d4c0..41ed8983e 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -41,6 +41,9 @@
41#include "rgb_matrix_animations/digital_rain_anim.h" 41#include "rgb_matrix_animations/digital_rain_anim.h"
42#include "rgb_matrix_animations/solid_reactive_simple_anim.h" 42#include "rgb_matrix_animations/solid_reactive_simple_anim.h"
43#include "rgb_matrix_animations/solid_reactive_anim.h" 43#include "rgb_matrix_animations/solid_reactive_anim.h"
44#include "rgb_matrix_animations/solid_reactive_wide.h"
45#include "rgb_matrix_animations/solid_reactive_cross.h"
46#include "rgb_matrix_animations/solid_reactive_nexus.h"
44#include "rgb_matrix_animations/splash_anim.h" 47#include "rgb_matrix_animations/splash_anim.h"
45#include "rgb_matrix_animations/solid_splash_anim.h" 48#include "rgb_matrix_animations/solid_splash_anim.h"
46#include "rgb_matrix_animations/breathing_anim.h" 49#include "rgb_matrix_animations/breathing_anim.h"
@@ -380,6 +383,36 @@ static void rgb_task_render(uint8_t effect) {
380 rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms 383 rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
381 break; 384 break;
382#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE 385#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
386#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
387 case RGB_MATRIX_SOLID_REACTIVE_WIDE:
388 rendering = rgb_matrix_solid_reactive_wide(&rgb_effect_params); // Max ?? ms Avg ?? ms
389 break;
390#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
391#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
392 case RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE:
393 rendering = rgb_matrix_solid_reactive_multiwide(&rgb_effect_params); // Max ?? ms Avg ?? ms
394 break;
395#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
396#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
397 case RGB_MATRIX_SOLID_REACTIVE_CROSS:
398 rendering = rgb_matrix_solid_reactive_cross(&rgb_effect_params); // Max ?? ms Avg ?? ms
399 break;
400#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
401#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
402 case RGB_MATRIX_SOLID_REACTIVE_MULTICROSS:
403 rendering = rgb_matrix_solid_reactive_multicross(&rgb_effect_params); // Max ?? ms Avg ?? ms
404 break;
405#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
406#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
407 case RGB_MATRIX_SOLID_REACTIVE_NEXUS:
408 rendering = rgb_matrix_solid_reactive_nexus(&rgb_effect_params); // Max ?? ms Avg ?? ms
409 break;
410#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
411#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
412 case RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS:
413 rendering = rgb_matrix_solid_reactive_multinexus(&rgb_effect_params); // Max ?? ms Avg ?? ms
414 break;
415#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
383#ifndef DISABLE_RGB_MATRIX_SPLASH 416#ifndef DISABLE_RGB_MATRIX_SPLASH
384 case RGB_MATRIX_SPLASH: 417 case RGB_MATRIX_SPLASH:
385 rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms 418 rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index f5be49435..5fdc854f0 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -111,6 +111,24 @@ enum rgb_matrix_effects {
111#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE 111#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
112 RGB_MATRIX_SOLID_REACTIVE, 112 RGB_MATRIX_SOLID_REACTIVE,
113#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE 113#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
114#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
115 RGB_MATRIX_SOLID_REACTIVE_WIDE,
116#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
117#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
118 RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE,
119#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
120#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
121 RGB_MATRIX_SOLID_REACTIVE_CROSS,
122#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
123#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
124 RGB_MATRIX_SOLID_REACTIVE_MULTICROSS,
125#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
126#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
127 RGB_MATRIX_SOLID_REACTIVE_NEXUS,
128#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
129#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
130 RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS,
131#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
114#ifndef DISABLE_RGB_MATRIX_SPLASH 132#ifndef DISABLE_RGB_MATRIX_SPLASH
115 RGB_MATRIX_SPLASH, 133 RGB_MATRIX_SPLASH,
116#endif // DISABLE_RGB_MATRIX_SPLASH 134#endif // DISABLE_RGB_MATRIX_SPLASH
diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h
new file mode 100644
index 000000000..af602cba1
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h
@@ -0,0 +1,50 @@
1#pragma once
2#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
3#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
4
5extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
6extern rgb_config_t rgb_matrix_config;
7extern last_hit_t g_last_hit_tracker;
8
9static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_params_t* params) {
10 RGB_MATRIX_USE_LIMITS(led_min, led_max);
11
12 HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
13 uint8_t count = g_last_hit_tracker.count;
14 for (uint8_t i = led_min; i < led_max; i++) {
15 hsv.v = 0;
16 point_t point = g_rgb_leds[i].point;
17 for (uint8_t j = start; j < count; j++) {
18 int16_t dx = point.x - g_last_hit_tracker.x[j];
19 int16_t dy = point.y - g_last_hit_tracker.y[j];
20 uint8_t dist = sqrt16(dx * dx + dy * dy);
21 int16_t dist2 = 16;
22 uint8_t dist3;
23 uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist;
24 dx = dx < 0 ? dx * -1 : dx;
25 dy = dy < 0 ? dy * -1 : dy;
26 dx = dx * dist2 > 255 ? 255 : dx * dist2;
27 dy = dy * dist2 > 255 ? 255 : dy * dist2;
28 dist3 = dx > dy ? dy : dx;
29 effect += dist3;
30 if (effect > 255)
31 effect = 255;
32 hsv.v = qadd8(hsv.v, 255 - effect);
33 }
34 hsv.v = scale8(hsv.v, rgb_matrix_config.val);
35 RGB rgb = hsv_to_rgb(hsv);
36 rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
37 }
38 return led_max < DRIVER_LED_TOTAL;
39}
40
41bool rgb_matrix_solid_reactive_multicross(effect_params_t* params) {
42 return rgb_matrix_solid_reactive_multicross_range(0, params);
43}
44
45bool rgb_matrix_solid_reactive_cross(effect_params_t* params) {
46 return rgb_matrix_solid_reactive_multicross_range(qsub8(g_last_hit_tracker.count, 1), params);
47}
48
49#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
50#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_animations/solid_reactive_nexus.h b/quantum/rgb_matrix_animations/solid_reactive_nexus.h
new file mode 100644
index 000000000..8b4a139dc
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h
@@ -0,0 +1,48 @@
1#pragma once
2#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
3#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
4
5extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
6extern rgb_config_t rgb_matrix_config;
7extern last_hit_t g_last_hit_tracker;
8
9static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_params_t* params) {
10 RGB_MATRIX_USE_LIMITS(led_min, led_max);
11
12 HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
13 uint8_t count = g_last_hit_tracker.count;
14 for (uint8_t i = led_min; i < led_max; i++) {
15 hsv.v = 0;
16 point_t point = g_rgb_leds[i].point;
17 for (uint8_t j = start; j < count; j++) {
18 int16_t dx = point.x - g_last_hit_tracker.x[j];
19 int16_t dy = point.y - g_last_hit_tracker.y[j];
20 uint8_t dist = sqrt16(dx * dx + dy * dy);
21 int16_t dist2 = 8;
22 uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
23 if (effect > 255)
24 effect = 255;
25 if (dist > 72)
26 effect = 255;
27 if ((dx > dist2 || dx < -dist2) && (dy > dist2 || dy < -dist2))
28 effect = 255;
29 hsv.v = qadd8(hsv.v, 255 - effect);
30 hsv.h = rgb_matrix_config.hue + dy / 4;
31 }
32 hsv.v = scale8(hsv.v, rgb_matrix_config.val);
33 RGB rgb = hsv_to_rgb(hsv);
34 rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
35 }
36 return led_max < DRIVER_LED_TOTAL;
37}
38
39bool rgb_matrix_solid_reactive_multinexus(effect_params_t* params) {
40 return rgb_matrix_solid_reactive_multinexus_range(0, params);
41}
42
43bool rgb_matrix_solid_reactive_nexus(effect_params_t* params) {
44 return rgb_matrix_solid_reactive_multinexus_range(qsub8(g_last_hit_tracker.count, 1), params);
45}
46
47#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
48#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_animations/solid_reactive_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h
new file mode 100644
index 000000000..abb01892e
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h
@@ -0,0 +1,42 @@
1#pragma once
2#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
3#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
4
5extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
6extern rgb_config_t rgb_matrix_config;
7extern last_hit_t g_last_hit_tracker;
8
9static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_params_t* params) {
10 RGB_MATRIX_USE_LIMITS(led_min, led_max);
11
12 HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
13 uint8_t count = g_last_hit_tracker.count;
14 for (uint8_t i = led_min; i < led_max; i++) {
15 hsv.v = 0;
16 point_t point = g_rgb_leds[i].point;
17 for (uint8_t j = start; j < count; j++) {
18 int16_t dx = point.x - g_last_hit_tracker.x[j];
19 int16_t dy = point.y - g_last_hit_tracker.y[j];
20 uint8_t dist = sqrt16(dx * dx + dy * dy);
21 uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist * 5;
22 if (effect > 255)
23 effect = 255;
24 hsv.v = qadd8(hsv.v, 255 - effect);
25 }
26 hsv.v = scale8(hsv.v, rgb_matrix_config.val);
27 RGB rgb = hsv_to_rgb(hsv);
28 rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
29 }
30 return led_max < DRIVER_LED_TOTAL;
31}
32
33bool rgb_matrix_solid_reactive_multiwide(effect_params_t* params) {
34 return rgb_matrix_solid_reactive_multiwide_range(0, params);
35}
36
37bool rgb_matrix_solid_reactive_wide(effect_params_t* params) {
38 return rgb_matrix_solid_reactive_multiwide_range(qsub8(g_last_hit_tracker.count, 1), params);
39}
40
41#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
42#endif // RGB_MATRIX_KEYREACTIVE_ENABLED