diff options
author | QMK Bot <hello@qmk.fm> | 2022-12-21 10:04:25 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2022-12-21 10:04:25 +0000 |
commit | 89b72017a014ca4810790831030c88054129f21c (patch) | |
tree | a3dbfeff5487f199af1eed59be7464c0fe49ffca /keyboards/teleport/native/rgb_matrix_kb.inc | |
parent | b2036a4c9f7838bfe7d8ede5e9335096a3767686 (diff) | |
parent | b8a9de206d38f0e047c2f07bca398d6fe53b76a9 (diff) |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'keyboards/teleport/native/rgb_matrix_kb.inc')
-rw-r--r-- | keyboards/teleport/native/rgb_matrix_kb.inc | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/keyboards/teleport/native/rgb_matrix_kb.inc b/keyboards/teleport/native/rgb_matrix_kb.inc new file mode 100644 index 0000000000..5df5312a42 --- /dev/null +++ b/keyboards/teleport/native/rgb_matrix_kb.inc @@ -0,0 +1,110 @@ +RGB_MATRIX_EFFECT(SINGLE_COLOR_RAINDROPS) +RGB_MATRIX_EFFECT(STATIC_GAME_MODE) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +/* This effect has been partially derived from quantum/rgb_matrix/animations/pixel_rain_anim.h and raindrops_anim.h +It sets random LEDs to matrix color (with very slight hue variation) but random intensity */ +static bool SINGLE_COLOR_RAINDROPS(effect_params_t* params) { + static uint32_t wait_timer = 0; + + // interval function and timing in general taken from pixel rain animation + inline uint32_t interval(void) { + return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); + } + + void single_color_raindrops_set_color(uint8_t i, effect_params_t * params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) { + return; + } + + // Take matrix color, add between -5 and +5 to hue, random brightness between 0 and val, set to 0 if val between 0 and 5, then write to LED + HSV hsv = rgb_matrix_get_hsv(); + hsv.h = rgb_matrix_get_hue() - 2 + random8() % 5; + hsv.v = random8() % rgb_matrix_get_val(); + if (hsv.v < 5) { + hsv.v = 0; + } + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + wait_timer = g_rgb_timer + interval(); + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + if (!params->init) { + if (g_rgb_timer > wait_timer) { + single_color_raindrops_set_color(mod8(random8(), RGB_MATRIX_LED_COUNT), params); + } + } else { + for (int i = led_min; i < led_max; i++) { + single_color_raindrops_set_color(i, params); + } + } + return rgb_matrix_check_finished_leds(led_max); +} + +/* This "effect" is a workaround to fix long matrix scan pauses caused by i2c communication. +When enabled, it writes all relevant LEDs once to static colors, then halts LED refreshes until a different animation is selcted. */ +bool STATIC_GAME_MODE(effect_params_t* params) { + + void game_mode_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) { + return; + } + + HSV hsv = rgb_matrix_get_hsv(); + + switch (i) { + case W_LED_INDEX: + case A_LED_INDEX: + case S_LED_INDEX: + case D_LED_INDEX: + + case M_LED_INDEX: + case K_LED_INDEX: + case O_LED_INDEX: + case P_LED_INDEX: + case NUM_0_LED_INDEX: + case SLSH_LED_INDEX: + break; + + case SCLN_LED_INDEX: + case ANV_A_LED_INDEX: + case ANV_N_LED_INDEX: + case ANV_V_LED_INDEX: + case ANV_I_LED_INDEX: + case ANV_L_LED_INDEX: + hsv.s = 255; + hsv.h = rgb_matrix_get_hue()+30; + break; + + case NUM_1_LED_INDEX: + case NUM_2_LED_INDEX: + case NUM_3_LED_INDEX: + case NUM_4_LED_INDEX: + case NUM_5_LED_INDEX: + hsv.s = 255; + hsv.h = rgb_matrix_get_hue()+30; + hsv.v = rgb_matrix_get_val()*2/3; + break; + + default: + hsv.v = 0; + break; + } + + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + if (!params->init) { + // Do not update LEDs after initial blanking + } else { + for (int i = led_min; i < led_max; i++) { + game_mode_set_color(i, params); + } + } + return rgb_matrix_check_finished_leds(led_max); +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS |