42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use esp_idf_svc::hal::units::{MilliSeconds,FromValueType};
|
|
|
|
use crate::audio::AudioProcessor;
|
|
use crate::effects::led_effect::{LedColors, LedEffect, Rgbv};
|
|
use crate::helpers::random_at_most;
|
|
use crate::LED_COUNT;
|
|
|
|
pub struct LedEffectBassSparks {
|
|
bass_color: Rgbv,
|
|
}
|
|
impl LedEffectBassSparks {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
bass_color: Rgbv::black(0),
|
|
}
|
|
}
|
|
}
|
|
impl LedEffect for LedEffectBassSparks {
|
|
fn render(&mut self, processed: &AudioProcessor, _fft_buf: usize, leds: &mut LedColors) -> MilliSeconds {
|
|
if processed.floating_max > 10100000
|
|
&& (processed.current_powers[0] > 1.25 * processed.avg_powers[0])
|
|
{
|
|
self.bass_color = Rgbv::new(127, 0, 255, 4)
|
|
}
|
|
|
|
leds.fill(self.bass_color);
|
|
|
|
self.bass_color.decrease(3, 5, 5, 0);
|
|
|
|
if processed.floating_max > 10100000
|
|
&& (processed.current_powers[1] > 1.35 * processed.avg_powers[1])
|
|
&& (processed.current_powers[2] > 1.35 * processed.avg_powers[2])
|
|
{
|
|
for _ in 0..10 {
|
|
let led_index = random_at_most(LED_COUNT as u32 - 1) as usize;
|
|
leds[led_index] = Rgbv::white(31);
|
|
}
|
|
}
|
|
|
|
10.ms()
|
|
}
|
|
}
|