logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

rgb_matrix_kb.inc (3710B)


  1. RGB_MATRIX_EFFECT(SINGLE_COLOR_RAINDROPS)
  2. RGB_MATRIX_EFFECT(STATIC_GAME_MODE)
  3. #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  4. /* This effect has been partially derived from quantum/rgb_matrix/animations/pixel_rain_anim.h and raindrops_anim.h
  5. It sets random LEDs to matrix color (with very slight hue variation) but random intensity */
  6. static bool SINGLE_COLOR_RAINDROPS(effect_params_t* params) {
  7. static uint32_t wait_timer = 0;
  8. // interval function and timing in general taken from pixel rain animation
  9. inline uint32_t interval(void) {
  10. return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
  11. }
  12. void single_color_raindrops_set_color(uint8_t i, effect_params_t * params) {
  13. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
  14. return;
  15. }
  16. // 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
  17. hsv_t hsv = rgb_matrix_get_hsv();
  18. hsv.h = rgb_matrix_get_hue() - 2 + random8() % 5;
  19. hsv.v = random8() % rgb_matrix_get_val();
  20. if (hsv.v < 5) {
  21. hsv.v = 0;
  22. }
  23. rgb_t rgb = rgb_matrix_hsv_to_rgb(hsv);
  24. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  25. wait_timer = g_rgb_timer + interval();
  26. }
  27. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  28. if (!params->init) {
  29. if (g_rgb_timer > wait_timer) {
  30. single_color_raindrops_set_color(mod8(random8(), RGB_MATRIX_LED_COUNT), params);
  31. }
  32. } else {
  33. for (int i = led_min; i < led_max; i++) {
  34. single_color_raindrops_set_color(i, params);
  35. }
  36. }
  37. return rgb_matrix_check_finished_leds(led_max);
  38. }
  39. /* This "effect" is a workaround to fix long matrix scan pauses caused by i2c communication.
  40. When enabled, it writes all relevant LEDs once to static colors, then halts LED refreshes until a different animation is selcted. */
  41. bool STATIC_GAME_MODE(effect_params_t* params) {
  42. void game_mode_set_color(int i, effect_params_t* params) {
  43. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
  44. return;
  45. }
  46. hsv_t hsv = rgb_matrix_get_hsv();
  47. switch (i) {
  48. case W_LED_INDEX:
  49. case A_LED_INDEX:
  50. case S_LED_INDEX:
  51. case D_LED_INDEX:
  52. case M_LED_INDEX:
  53. case K_LED_INDEX:
  54. case O_LED_INDEX:
  55. case P_LED_INDEX:
  56. case NUM_0_LED_INDEX:
  57. case SLSH_LED_INDEX:
  58. break;
  59. case SCLN_LED_INDEX:
  60. case ANV_A_LED_INDEX:
  61. case ANV_N_LED_INDEX:
  62. case ANV_V_LED_INDEX:
  63. case ANV_I_LED_INDEX:
  64. case ANV_L_LED_INDEX:
  65. hsv.s = 255;
  66. hsv.h = rgb_matrix_get_hue()+30;
  67. break;
  68. case NUM_1_LED_INDEX:
  69. case NUM_2_LED_INDEX:
  70. case NUM_3_LED_INDEX:
  71. case NUM_4_LED_INDEX:
  72. case NUM_5_LED_INDEX:
  73. hsv.s = 255;
  74. hsv.h = rgb_matrix_get_hue()+30;
  75. hsv.v = rgb_matrix_get_val()*2/3;
  76. break;
  77. default:
  78. hsv.v = 0;
  79. break;
  80. }
  81. rgb_t rgb = hsv_to_rgb(hsv);
  82. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  83. }
  84. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  85. if (!params->init) {
  86. // Do not update LEDs after initial blanking
  87. } else {
  88. for (int i = led_min; i < led_max; i++) {
  89. game_mode_set_color(i, params);
  90. }
  91. }
  92. return rgb_matrix_check_finished_leds(led_max);
  93. }
  94. #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS