add vu effect
This commit is contained in:
parent
36f896db35
commit
de110d8120
1 changed files with 58 additions and 1 deletions
|
@ -83,6 +83,12 @@ treb: 43-255
|
|||
} \
|
||||
current_powers[IDX] /= (END + 1 - START);
|
||||
|
||||
#define MIRROR_LED(start, end, second_start) \
|
||||
for (uint32_t *src = start, *dst = second_start; src < end; src++, dst--) \
|
||||
{ \
|
||||
*dst = *src; \
|
||||
}
|
||||
|
||||
#define RGB(R, G, B, V) ((uint32_t)(0xe0) | (V) | (B << 8) | (G << 16) | (R << 24))
|
||||
#define SET_RGB(old, R, G, B) ((old&0x000000E0) | (uint32_t)(0xe0) | (V) | (B << 8) | (G << 16) | (R << 24)))
|
||||
#define SET_R(old, R) ((old & 0x00FFFFFF) | (R << 24))
|
||||
|
@ -412,6 +418,56 @@ static inline TickType_t app_effect_fft_colors()
|
|||
return pdMS_TO_TICKS(10);
|
||||
}
|
||||
|
||||
static inline TickType_t app_effect_vu_meter()
|
||||
{
|
||||
// if (xTaskNotifyWait(0, 0, &in_fft_buf_idx, pdMS_TO_TICKS(100)) == pdPASS)
|
||||
// {
|
||||
// if (in_fft_buf_idx >= BUF_COUNT)
|
||||
// {
|
||||
// printf("output buf count wrong: %ld", in_fft_buf_idx);
|
||||
// return pdMS_TO_TICKS(10);
|
||||
// }
|
||||
// }
|
||||
|
||||
xSemaphoreTake(output_mutex, portMAX_DELAY);
|
||||
// float current_level = 0;
|
||||
float max_level = ((float)floating_max) / INT32_MAX;
|
||||
xSemaphoreGive(output_mutex);
|
||||
|
||||
uint32_t max_level_led = MIN(LEDS_COUNT / 2 - 1, MAX(0, LEDS_COUNT / 2 * max_level));
|
||||
|
||||
for (int i = 0; i < LEDS_COUNT / 2; i++)
|
||||
{
|
||||
if (i < max_level_led)
|
||||
{
|
||||
if (i < 0.5 * LEDS_COUNT / 2)
|
||||
{
|
||||
leds.buffer[i] = RGB(0, 255, 0, 4);
|
||||
}
|
||||
else if (i < 0.8 * LEDS_COUNT / 2)
|
||||
{
|
||||
leds.buffer[i] = RGB(255, 192, 0, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
leds.buffer[i] = RGB(255, 0, 0, 8);
|
||||
}
|
||||
}
|
||||
else if (i == max_level_led)
|
||||
{
|
||||
leds.buffer[i] = RGB(0, 0, 255, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
leds.buffer[i] = RGB(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
MIRROR_LED(&leds.buffer[0], &leds.buffer[LEDS_COUNT / 2], &leds.buffer[LEDS_COUNT - 1]);
|
||||
|
||||
return pdMS_TO_TICKS(10);
|
||||
}
|
||||
|
||||
static void app_output_task(void *args)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
@ -431,7 +487,8 @@ static void app_output_task(void *args)
|
|||
|
||||
// TickType_t next_ticks = app_effect_blob_run();
|
||||
// TickType_t next_ticks = app_effect_fft_colors();
|
||||
TickType_t next_ticks = app_effect_bass_sparks();
|
||||
// TickType_t next_ticks = app_effect_bass_sparks();
|
||||
TickType_t next_ticks = app_effect_vu_meter();
|
||||
|
||||
ret = spi_device_transmit(led_spi_dev, &trans);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue