leds.rs 643 Bytes
Newer Older
Astro's avatar
Astro committed
1 2
//! Lights

Astro's avatar
Astro committed
3 4 5 6 7 8 9 10
use card10_sys::*;

#[derive(Clone, Copy)]
pub enum LEDColor {
    RGB(u8, u8, u8),
    HSV(f32, f32, f32),
}

Astro's avatar
Astro committed
11 12 13
/// Update all RGB LEDs
///
/// `f` must supply a `LEDColor` for `0..=10`.
Astro's avatar
Astro committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
pub fn update_rgb_leds<F>(f: F)
where
    F: Fn(i32) -> LEDColor,
{
    for index in 0..=10 {
        let color = f(index);
        match color {
            LEDColor::RGB(r, g, b) => unsafe {
                epic_leds_prep(index, r, g, b);
            }
            LEDColor::HSV(h, s, v) => unsafe {
                epic_leds_prep_hsv(index, h, s, v);
            }
        }
        unsafe {
            epic_leds_update();
        }
    }
}