2022-07-07 17:12:13 -07:00
|
|
|
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
|
|
|
#ifndef DISABLE_RGB_MATRIX_FFT_ANIM
|
|
|
|
RGB_MATRIX_EFFECT(FFT_ANIM)
|
|
|
|
|
|
|
|
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
|
|
|
|
|
|
|
// Maps fft columns to leds.
|
2022-07-08 10:50:17 -07:00
|
|
|
// fft_col_to_array[i] returns an array of leds in the ith bin of the fft.
|
2022-07-07 17:12:13 -07:00
|
|
|
// Negative indices are "invisible" leds.
|
|
|
|
// Use them when your keyboard has gaps.
|
|
|
|
//
|
|
|
|
// This layout is for the Ergodox EZ.
|
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) {
|
|
|
|
RGB_MATRIX_USE_LIMITS(led_min, led_max);
|
|
|
|
|
|
|
|
// REQUIRED for any animation that uses this pointer.
|
|
|
|
// Clears any previous data.
|
|
|
|
if (params->init) {
|
|
|
|
rgb_matrix_anim_data = NULL;
|
|
|
|
return led_max < DRIVER_LED_TOTAL;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (rgb_matrix_anim_data == NULL) {
|
|
|
|
// If animation data is empty, turn off all leds and exit.
|
|
|
|
for (uint8_t i = led_min; i < led_max; i++) {
|
|
|
|
rgb_matrix_set_color(
|
|
|
|
i,
|
|
|
|
0x00, 0x00, 0x00
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Data should be a pointer to 10 uint8_ts, each representing
|
|
|
|
// the height of a bar on the display.
|
|
|
|
uint8_t* data = (uint8_t*) rgb_matrix_anim_data;
|
|
|
|
|
|
|
|
for (uint8_t bin = 0; bin < 10; bin++) {
|
|
|
|
// Scale data values
|
|
|
|
uint8_t d = data[bin];
|
|
|
|
uint8_t bin_height = d / 50;
|
|
|
|
// Brightness of topmost key
|
|
|
|
uint8_t last_brightness = ((d % 50)/50.0) * 0xFF;
|
|
|
|
|
|
|
|
|
|
|
|
// Turn off leds that should be off.
|
|
|
|
// There are 5 keys in each column.
|
|
|
|
for (uint8_t i = bin_height; i < 6; i++) {
|
|
|
|
// Ignore negative indices.
|
2022-07-08 10:50:17 -07:00
|
|
|
// See fft_col_to_array definition.
|
|
|
|
if (fft_col_to_array[bin][i] < 0) {
|
2022-07-07 17:12:13 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rgb_matrix_set_color(
|
2022-07-08 10:50:17 -07:00
|
|
|
fft_col_to_array[bin][i],
|
2022-07-07 17:12:13 -07:00
|
|
|
0x00, 0x00, 0x00
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Turn on leds that should be on.
|
|
|
|
for (uint8_t i = 0; i < bin_height; i++) {
|
|
|
|
// Ignore negative indices.
|
2022-07-08 10:50:17 -07:00
|
|
|
// See fft_col_to_array definition.
|
|
|
|
if (fft_col_to_array[bin][i] < 0) {
|
2022-07-07 17:12:13 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the topmost lit key, its
|
|
|
|
// brightness depends on the height of the bar.
|
|
|
|
if (i == bin_height - 1) {
|
|
|
|
rgb_matrix_set_color(
|
2022-07-08 10:50:17 -07:00
|
|
|
fft_col_to_array[bin][i],
|
2022-07-07 17:12:13 -07:00
|
|
|
last_brightness, 0x00, last_brightness
|
|
|
|
);
|
|
|
|
|
|
|
|
// If this isn't the topmost key,
|
|
|
|
// it has a plain full-brightness color.
|
|
|
|
} else {
|
|
|
|
rgb_matrix_set_color(
|
2022-07-08 10:50:17 -07:00
|
|
|
fft_col_to_array[bin][i],
|
2022-07-07 17:12:13 -07:00
|
|
|
0x00, 0x00, 0xFF
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return led_max < DRIVER_LED_TOTAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|