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-09 20:34:43 -07:00
|
|
|
|
|
|
|
static int8_t fft_array_to_col[4][14] = {
|
|
|
|
// Each number represets a bin and a height:
|
|
|
|
// x % bin_height = height,
|
|
|
|
// x / bin_height = bin
|
|
|
|
//
|
|
|
|
// Indices are [col][row].
|
|
|
|
|
|
|
|
// Right side
|
|
|
|
{ 29, 34, 39, 44, 49,
|
|
|
|
28, 33, 38, 43, 48,
|
|
|
|
27, 32, 37, 42},{47,
|
|
|
|
26, 31, 36, 41, 46,
|
|
|
|
30, 35, 40, 45,
|
|
|
|
|
|
|
|
// Left side, mirrored
|
|
|
|
24, 19, 14, 9},{ 4,
|
|
|
|
23, 18, 13, 8, 3,
|
|
|
|
22, 17, 12, 7, 2,
|
|
|
|
21, 16, 11},{ 6, 1,
|
|
|
|
20, 15, 10, 5, 0,
|
|
|
|
|
|
|
|
// No keys here, fill array length
|
|
|
|
0, 0, 0, 0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2022-07-08 10:50:17 -07:00
|
|
|
static int8_t fft_col_to_array[10][5] = {
|
2022-07-07 17:12:13 -07:00
|
|
|
{ 47, 43, 38, 33, 28 },
|
|
|
|
{ 46, 42, 37, 32, 27 },
|
|
|
|
{ 45, 41, 36, 31, 26 },
|
|
|
|
{ 44, 40, 35, 30, 25 },
|
|
|
|
{ -1, 39, 34, 29, 24 },
|
|
|
|
{ -1, 15, 10, 5, 0 },
|
|
|
|
{ 20, 16, 11, 6, 1 },
|
|
|
|
{ 21, 17, 12, 7, 2 },
|
|
|
|
{ 22, 18, 13, 8, 3 },
|
|
|
|
{ 23, 19, 14, 9, 4 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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
|