aboutsummaryrefslogtreecommitdiff
path: root/users/drashna/rgb/rgb_matrix_stuff.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/rgb/rgb_matrix_stuff.c')
-rw-r--r--users/drashna/rgb/rgb_matrix_stuff.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/users/drashna/rgb/rgb_matrix_stuff.c b/users/drashna/rgb/rgb_matrix_stuff.c
new file mode 100644
index 000000000..97811092c
--- /dev/null
+++ b/users/drashna/rgb/rgb_matrix_stuff.c
@@ -0,0 +1,97 @@
1/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "drashna.h"
18#include "rgb_matrix.h"
19#include "lib/lib8tion/lib8tion.h"
20extern led_config_t g_led_config;
21
22static uint32_t hypno_timer;
23
24void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type, uint8_t led_min, uint8_t led_max) {
25 HSV hsv = {hue, sat, val};
26 if (hsv.v > rgb_matrix_get_val()) {
27 hsv.v = rgb_matrix_get_val();
28 }
29
30 switch (mode) {
31 case 1: // breathing
32 {
33 uint16_t time = scale16by8(g_rgb_timer, speed / 8);
34 hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
35 RGB rgb = hsv_to_rgb(hsv);
36 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
37 if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
38 RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
39 }
40 }
41 break;
42 }
43 default: // Solid Color
44 {
45 RGB rgb = hsv_to_rgb(hsv);
46 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
47 if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
48 RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
49 }
50 }
51 break;
52 }
53 }
54}
55
56__attribute__((weak)) void rgb_matrix_indicator_keymap(void) {}
57
58void matrix_scan_rgb_matrix(void) {
59#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
60 if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && sync_timer_elapsed32(hypno_timer) > 15000) {
61 rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
62 }
63#endif
64 rgb_matrix_indicator_keymap();
65}
66
67void keyboard_post_init_rgb_matrix(void) {
68#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
69 if (userspace_config.rgb_matrix_idle_anim) {
70 rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
71 }
72#endif
73}
74
75bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
76#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
77 hypno_timer = sync_timer_read32();
78 if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) {
79 rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
80 }
81#endif
82 switch (keycode) {
83 case RGB_IDL: // This allows me to use underglow as layer indication, or as normal
84#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
85 if (record->event.pressed) {
86 userspace_config.rgb_matrix_idle_anim ^= 1;
87 dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
88 eeconfig_update_user(userspace_config.raw);
89 if (userspace_config.rgb_matrix_idle_anim) {
90 rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
91 }
92 }
93#endif
94 break;
95 }
96 return true;
97}