QMK/keyboards/betalupi_ergodox/animations/fft.h

58 lines
1.3 KiB
C
Raw Normal View History

2022-07-09 20:34:43 -07:00
#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
2022-07-07 17:12:13 -07:00
#ifndef DISABLE_RGB_MATRIX_FFT_ANIM
RGB_MATRIX_EFFECT(FFT_ANIM)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
2022-07-11 10:39:06 -07:00
#include "extra_mappings.h"
2022-07-07 17:12:13 -07:00
// TODO:
// Dynamic color settings
bool FFT_ANIM(effect_params_t* params) {
2022-07-09 20:34:43 -07:00
uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter;
uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT;
if (led_max > sizeof(g_rgb_frame_buffer)) led_max = sizeof(g_rgb_frame_buffer);
2022-07-07 17:12:13 -07:00
if (params->init) {
2022-07-09 20:34:43 -07:00
rgb_matrix_set_color_all(0, 0, 0);
memset(g_rgb_frame_buffer, 0, sizeof g_rgb_frame_buffer);
}
2022-07-07 17:12:13 -07:00
2022-07-09 20:34:43 -07:00
// Render heatmap & decrease
for (int i = led_min; i < led_max; i++) {
uint8_t row = i % MATRIX_ROWS;
uint8_t col = i / MATRIX_ROWS;
uint8_t val = g_rgb_frame_buffer[row][col];
bool is_topmost = false;
int8_t height = fft_array_to_col[col][row] % 5;
int8_t bin = fft_array_to_col[col][row] / 5;
if (height == 5 - 1) {
is_topmost = true;
} else {
// Row and col of key above this one
if (
g_rgb_frame_buffer[
fft_col_to_array[bin][height + 1] % MATRIX_ROWS
][
fft_col_to_array[bin][height + 1] / MATRIX_ROWS
] == 0
) {
is_topmost = true;
2022-07-07 17:12:13 -07:00
}
2022-07-09 20:34:43 -07:00
}
2022-07-07 17:12:13 -07:00
2022-07-09 20:34:43 -07:00
if (is_topmost) {
rgb_matrix_set_color(i, val, 0x00, val);
} else {
rgb_matrix_set_color(i, 0x00, 0x00, val);
2022-07-07 17:12:13 -07:00
}
}
2022-07-09 20:34:43 -07:00
return led_max < sizeof(g_rgb_frame_buffer);
2022-07-07 17:12:13 -07:00
}
#endif
#endif
#endif