diff options
author | Jacob Jerrell <jacob.jerrell@gmail.com> | 2020-12-06 00:30:27 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-06 17:30:27 +1100 |
commit | 3076f86dc11d346d07c63e5fb11702817d7034e7 (patch) | |
tree | ebf9b4f3dd89366069f2123a0c984692c3d98e52 /users/bocaj/rgb_matrix_stuff.c | |
parent | 6b1f96dca8b1218c0e3de6ef23dbde107f8c4588 (diff) |
Bocaj - Third Annual Refactor (Redux) (#10295)
* Reset everything to upstream, reapply Bocaj changes
* Bocaj - address PR comments
* Just in time changes
* Bocaj - Several adjustments after using the layout for a while
Diffstat (limited to 'users/bocaj/rgb_matrix_stuff.c')
-rw-r--r-- | users/bocaj/rgb_matrix_stuff.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/users/bocaj/rgb_matrix_stuff.c b/users/bocaj/rgb_matrix_stuff.c new file mode 100644 index 0000000000..bc50349d23 --- /dev/null +++ b/users/bocaj/rgb_matrix_stuff.c @@ -0,0 +1,106 @@ +#include "bocaj.h" + +#include "lib/lib8tion/lib8tion.h" +extern led_config_t g_led_config; + +static uint32_t hypno_timer; +#if defined(SPLIT_KEYBOARD) || defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_crkbd) +# define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN_DUAL +#else +# define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN +#endif + +void rgb_matrix_set_color_row(uint8_t row, uint8_t red, uint8_t green, uint8_t blue) { +#ifdef KEYBOARD_planck_ez + if (row > 2) { + row = 0; + } + uint8_t row_multiplier = row * 12; + + rgb_matrix_set_color(1 + row_multiplier, red, green, blue); + rgb_matrix_set_color(2 + row_multiplier, red, green, blue); + rgb_matrix_set_color(3 + row_multiplier, red, green, blue); + rgb_matrix_set_color(4 + row_multiplier, red, green, blue); + rgb_matrix_set_color(5 + row_multiplier, red, green, blue); + rgb_matrix_set_color(6 + row_multiplier, red, green, blue); + rgb_matrix_set_color(7 + row_multiplier, red, green, blue); + rgb_matrix_set_color(8 + row_multiplier, red, green, blue); + rgb_matrix_set_color(9 + row_multiplier, red, green, blue); + rgb_matrix_set_color(10 + row_multiplier, red, green, blue); +#endif +} + +void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type) { + HSV hsv = {hue, sat, val}; + if (hsv.v > rgb_matrix_get_val()) { + hsv.v = rgb_matrix_get_val(); + } + + switch (mode) { + case 1: // breathing + { + uint16_t time = scale16by8(g_rgb_timer, speed / 8); + hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + } + break; + } + default: // Solid Color + { + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + } + break; + } + } +} + +__attribute__((weak)) void rgb_matrix_indicator_keymap(void) {} + +void matrix_scan_rgb_matrix(void) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && timer_elapsed32(hypno_timer) > 15000) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); + } +#endif + rgb_matrix_indicator_keymap(); +} + +void keyboard_post_init_rgb_matrix(void) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + if (userspace_config.rgb_matrix_idle_anim) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); + } +#endif +} + +bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + hypno_timer = timer_read32(); + if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); + } +#endif + switch (keycode) { + case RGB_IDL: +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + if (record->event.pressed) { + userspace_config.rgb_matrix_idle_anim ^= 1; + dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim); + eeconfig_update_user(userspace_config.raw); + if (userspace_config.rgb_matrix_idle_anim) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); + } + } +#endif + break; + } + return true; +} |