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 18 #include <string.h> 19 #include <math.h> 20 #include <lib/lib8tion/lib8tion.h> 21 #include "eeconfig.h" 22 23 #define LED_TRAIL 10 24 25 static int8_t top = 0; 26 static int8_t bottom = MATRIX_ROWS - 1; 27 static int8_t left = 0; 28 static int8_t right = MATRIX_COLS - 1; 29 static int8_t dir = 1; 30 31 static int8_t i = 0; 32 static int8_t j = 0; 33 34 static bool traverse = true; 35 36 static uint8_t v_values[RGB_MATRIX_LED_COUNT] = {0}; 37 38 static void traverse_matrix(void) { 39 if (dir == 1) { 40 // moving left->right 41 i++; 42 // Since we have traversed the whole first 43 // row, move down to the next row. 44 if (i > right) { 45 ++top; 46 dir = 2; 47 j = top; 48 i -= 1; 49 } 50 } else if (dir == 2) { 51 // moving top->bottom 52 j++; 53 // Since we have traversed the whole last 54 // column, move left to the previous column. 55 if (j > bottom) { 56 --right; 57 dir = 3; 58 i = right; 59 j -= 1; 60 } 61 } else if (dir == 3) { 62 // moving right->left 63 i--; 64 // Since we have traversed the whole last 65 // row, move up to the previous row. 66 if (i < left) { 67 --bottom; 68 dir = 4; 69 j = bottom; 70 i += 1; 71 } 72 } else if (dir == 4) { 73 // moving bottom->up 74 j--; 75 // Since we have traversed the whole first 76 // col, move right to the next column. 77 if (j < top) { 78 ++left; 79 dir = 1; 80 i = left; 81 j += 1; 82 } 83 } 84 } 85 86 static void swirl_set_color(hsv_t hsv) { 87 uint8_t index = g_led_config.matrix_co[j][i]; 88 89 if(index != NO_LED){ 90 v_values[index] = 75; 91 } 92 93 for(uint8_t v = 0; v < RGB_MATRIX_LED_COUNT; v++) 94 { 95 if(index != v) { 96 if(v_values[v] >= 20) 97 v_values[v] -= 20; 98 else 99 v_values[v] = 0; 100 } 101 hsv.v = v_values[v]; 102 rgb_t rgb = hsv_to_rgb(hsv); 103 rgb_matrix_set_color(v, rgb.r, rgb.g, rgb.b); 104 } 105 106 traverse_matrix(); 107 108 if (!(top <= bottom && left <= right)) { 109 eeconfig_read_rgb_matrix(&rgb_matrix_config); 110 rgb_matrix_mode_noeeprom(rgb_matrix_config.mode); 111 return; 112 } 113 } 114 115 static bool STARTUP_SWIRL_ANIM(effect_params_t* params) { 116 hsv_t hsv = rgb_matrix_config.hsv; 117 uint8_t time = scale16by8(g_rgb_timer, qadd8(24, 1)); 118 hsv.h = time; 119 rgb_t rgb = hsv_to_rgb(hsv); 120 121 if (traverse) { 122 swirl_set_color(hsv); 123 } 124 traverse = !traverse; 125 return false; 126 127 RGB_MATRIX_USE_LIMITS(led_min, led_max); 128 129 for (int i = led_min; i < led_max; i++) { 130 rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); // Clear matrix just in case 131 } 132 133 return rgb_matrix_check_finished_leds(led_max); 134 }