2019-03-09 05:02:49 -05:00
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
pub mod gamma;
|
|
|
|
pub mod rgb;
|
|
|
|
|
|
|
|
use core::borrow::Borrow;
|
|
|
|
|
2019-03-09 17:02:12 -05:00
|
|
|
/// An RGB value in physical color space, which should be passed on to an LED for display.
|
|
|
|
/// Not suitable for color operations, since its values won't be perceptually linear.
|
|
|
|
/// See the [rgb] module for the former, and the [gamma] module to convert into this.
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct HardwareRgb(pub u8, pub u8, pub u8);
|
|
|
|
|
2019-03-09 05:02:49 -05:00
|
|
|
pub trait Lights {
|
|
|
|
type Pixel;
|
|
|
|
|
|
|
|
fn render(&mut self, pixel: &Self::Pixel);
|
|
|
|
fn latch(&mut self);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait PixelIterator<T: Lights> {
|
|
|
|
fn render_to(&mut self, lights: &mut T);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Lights, I: Iterator> PixelIterator<T> for I
|
|
|
|
where I::Item: Borrow<T::Pixel>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn render_to(&mut self, lights: &mut T) {
|
|
|
|
self.for_each(|pixel| lights.render(pixel.borrow()));
|
|
|
|
}
|
|
|
|
}
|