logo

qmk_firmware

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

startup_swirl_anim.h (3609B)


  1. /* Copyright 2022 Jpe230 <https://github.com/Jpe230>
  2. * Copyright 2023 HorrorTroll <https://github.com/HorrorTroll>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <string.h>
  18. #include <math.h>
  19. #include <lib/lib8tion/lib8tion.h>
  20. #include "eeconfig.h"
  21. #define LED_TRAIL 10
  22. static int8_t top = 0;
  23. static int8_t bottom = MATRIX_ROWS - 1;
  24. static int8_t left = 0;
  25. static int8_t right = MATRIX_COLS - 1;
  26. static int8_t dir = 1;
  27. static int8_t i = 0;
  28. static int8_t j = 0;
  29. static bool traverse = true;
  30. static uint8_t v_values[RGB_MATRIX_LED_COUNT] = {0};
  31. static void traverse_matrix(void) {
  32. if (dir == 1) {
  33. // moving left->right
  34. i++;
  35. // Since we have traversed the whole first
  36. // row, move down to the next row.
  37. if (i > right) {
  38. ++top;
  39. dir = 2;
  40. j = top;
  41. i -= 1;
  42. }
  43. } else if (dir == 2) {
  44. // moving top->bottom
  45. j++;
  46. // Since we have traversed the whole last
  47. // column, move left to the previous column.
  48. if (j > bottom) {
  49. --right;
  50. dir = 3;
  51. i = right;
  52. j -= 1;
  53. }
  54. } else if (dir == 3) {
  55. // moving right->left
  56. i--;
  57. // Since we have traversed the whole last
  58. // row, move up to the previous row.
  59. if (i < left) {
  60. --bottom;
  61. dir = 4;
  62. j = bottom;
  63. i += 1;
  64. }
  65. } else if (dir == 4) {
  66. // moving bottom->up
  67. j--;
  68. // Since we have traversed the whole first
  69. // col, move right to the next column.
  70. if (j < top) {
  71. ++left;
  72. dir = 1;
  73. i = left;
  74. j += 1;
  75. }
  76. }
  77. }
  78. static void swirl_set_color(hsv_t hsv) {
  79. uint8_t index = g_led_config.matrix_co[j][i];
  80. if(index != NO_LED){
  81. v_values[index] = 75;
  82. }
  83. for(uint8_t v = 0; v < RGB_MATRIX_LED_COUNT; v++)
  84. {
  85. if(index != v) {
  86. if(v_values[v] >= 20)
  87. v_values[v] -= 20;
  88. else
  89. v_values[v] = 0;
  90. }
  91. hsv.v = v_values[v];
  92. rgb_t rgb = hsv_to_rgb(hsv);
  93. rgb_matrix_set_color(v, rgb.r, rgb.g, rgb.b);
  94. }
  95. traverse_matrix();
  96. if (!(top <= bottom && left <= right)) {
  97. eeconfig_read_rgb_matrix(&rgb_matrix_config);
  98. rgb_matrix_mode_noeeprom(rgb_matrix_config.mode);
  99. return;
  100. }
  101. }
  102. static bool STARTUP_SWIRL_ANIM(effect_params_t* params) {
  103. hsv_t hsv = rgb_matrix_config.hsv;
  104. uint8_t time = scale16by8(g_rgb_timer, qadd8(24, 1));
  105. hsv.h = time;
  106. rgb_t rgb = hsv_to_rgb(hsv);
  107. if (traverse) {
  108. swirl_set_color(hsv);
  109. }
  110. traverse = !traverse;
  111. return false;
  112. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  113. for (int i = led_min; i < led_max; i++) {
  114. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); // Clear matrix just in case
  115. }
  116. return rgb_matrix_check_finished_leds(led_max);
  117. }