diff options
Diffstat (limited to 'users/drashna/rgb/rgb_stuff.c')
-rw-r--r-- | users/drashna/rgb/rgb_stuff.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/users/drashna/rgb/rgb_stuff.c b/users/drashna/rgb/rgb_stuff.c new file mode 100644 index 000000000..15108bde0 --- /dev/null +++ b/users/drashna/rgb/rgb_stuff.c | |||
@@ -0,0 +1,132 @@ | |||
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 | #ifdef RGBLIGHT_ENABLE | ||
18 | |||
19 | # include "drashna.h" | ||
20 | # include "rgb_stuff.h" | ||
21 | # include "eeprom.h" | ||
22 | |||
23 | bool has_initialized; | ||
24 | |||
25 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), index); } | ||
26 | void rgblight_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode) { | ||
27 | rgblight_sethsv_noeeprom(hue, sat, val); | ||
28 | // wait_us(175); // Add a slight delay between color and mode to ensure it's processed correctly | ||
29 | rgblight_mode_noeeprom(mode); | ||
30 | } | ||
31 | |||
32 | bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record) { return true; } | ||
33 | |||
34 | # if defined(RGBLIGHT_STARTUP_ANIMATION) | ||
35 | static bool is_enabled; | ||
36 | static bool is_rgblight_startup; | ||
37 | static HSV old_hsv; | ||
38 | static uint8_t old_mode; | ||
39 | static uint16_t rgblight_startup_loop_timer; | ||
40 | # endif | ||
41 | |||
42 | void keyboard_post_init_rgb_light(void) { | ||
43 | # if defined(RGBLIGHT_STARTUP_ANIMATION) | ||
44 | is_enabled = rgblight_is_enabled(); | ||
45 | if (userspace_config.rgb_layer_change) { | ||
46 | layer_state_set_rgb_light(layer_state); | ||
47 | } | ||
48 | old_hsv = rgblight_get_hsv(); | ||
49 | old_mode = rgblight_get_mode(); | ||
50 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); | ||
51 | is_rgblight_startup = true; | ||
52 | # endif | ||
53 | if (userspace_config.rgb_layer_change) { | ||
54 | layer_state_set_rgb_light(layer_state); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | void matrix_scan_rgb_light(void) { | ||
59 | # if defined(RGBLIGHT_STARTUP_ANIMATION) | ||
60 | if (is_rgblight_startup && is_keyboard_master()) { | ||
61 | if (sync_timer_elapsed(rgblight_startup_loop_timer) > 10) { | ||
62 | static uint8_t counter; | ||
63 | counter++; | ||
64 | rgblight_sethsv_noeeprom((counter + old_hsv.h) % 255, 255, 255); | ||
65 | rgblight_startup_loop_timer = sync_timer_read(); | ||
66 | if (counter == 255) { | ||
67 | is_rgblight_startup = false; | ||
68 | if (userspace_config.rgb_layer_change) { | ||
69 | layer_state_set_rgb_light(layer_state); | ||
70 | } else { | ||
71 | rgblight_set_hsv_and_mode(old_hsv.h, old_hsv.s, old_hsv.v, old_mode); | ||
72 | } | ||
73 | if (!is_enabled) { | ||
74 | rgblight_disable_noeeprom(); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | # endif | ||
80 | } | ||
81 | |||
82 | layer_state_t layer_state_set_rgb_light(layer_state_t state) { | ||
83 | # ifdef RGBLIGHT_ENABLE | ||
84 | if (userspace_config.rgb_layer_change) { | ||
85 | switch (get_highest_layer(state | default_layer_state)) { | ||
86 | case _MOUSE: // mouse | ||
87 | if (!layer_state_cmp(state, _GAMEPAD) && !layer_state_cmp(state, _DIABLO)) { | ||
88 | # if defined(RGBLIGHT_EFFECT_TWINKLE) | ||
89 | rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_TWINKLE + 5); | ||
90 | # else | ||
91 | rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_BREATHING + 3); | ||
92 | # endif | ||
93 | } | ||
94 | break; | ||
95 | case _MEDIA: | ||
96 | rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_KNIGHT + 1); | ||
97 | break; | ||
98 | case _GAMEPAD: | ||
99 | rgblight_set_hsv_and_mode(HSV_ORANGE, RGBLIGHT_MODE_SNAKE + 2); | ||
100 | break; | ||
101 | case _DIABLO: | ||
102 | rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_BREATHING + 3); | ||
103 | break; | ||
104 | case _RAISE: | ||
105 | rgblight_set_hsv_and_mode(HSV_YELLOW, RGBLIGHT_MODE_BREATHING + 3); | ||
106 | break; | ||
107 | case _LOWER: | ||
108 | rgblight_set_hsv_and_mode(HSV_GREEN, RGBLIGHT_MODE_BREATHING + 3); | ||
109 | break; | ||
110 | case _ADJUST: | ||
111 | rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_KNIGHT + 2); | ||
112 | break; | ||
113 | case _DEFAULT_LAYER_1: | ||
114 | rgblight_set_hsv_and_mode(DEFAULT_LAYER_1_HSV, RGBLIGHT_MODE_STATIC_LIGHT); | ||
115 | break; | ||
116 | case _DEFAULT_LAYER_2: | ||
117 | rgblight_set_hsv_and_mode(DEFAULT_LAYER_2_HSV, RGBLIGHT_MODE_STATIC_LIGHT); | ||
118 | break; | ||
119 | case _DEFAULT_LAYER_3: | ||
120 | rgblight_set_hsv_and_mode(DEFAULT_LAYER_3_HSV, RGBLIGHT_MODE_STATIC_LIGHT); | ||
121 | break; | ||
122 | case _DEFAULT_LAYER_4: | ||
123 | rgblight_set_hsv_and_mode(DEFAULT_LAYER_4_HSV, RGBLIGHT_MODE_STATIC_LIGHT); | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | # endif // RGBLIGHT_ENABLE | ||
128 | |||
129 | return state; | ||
130 | } | ||
131 | |||
132 | #endif | ||