src: implement simulation data sources
This commit is contained in:
26
src/lib.rs
26
src/lib.rs
@@ -35,4 +35,30 @@ pub fn as_milliwatts(pixel: &Rgb<u8>) -> u32 {
|
||||
let blue = (pixel.b as u32 * BLUE_MW).wrapping_shr(8);
|
||||
|
||||
red + green + blue + DARK_MW
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CircularBuffer<T, const SIZE: usize = 20> {
|
||||
pub data: [T; SIZE],
|
||||
next_index: usize
|
||||
}
|
||||
|
||||
impl<T: Default + Copy, const SIZE: usize> Default for CircularBuffer<T, SIZE> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
data: [Default::default(); SIZE],
|
||||
next_index: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, const SIZE: usize> CircularBuffer<T, SIZE> {
|
||||
pub fn insert(&mut self, value: T) {
|
||||
self.data[self.next_index] = value;
|
||||
self.next_index += 1;
|
||||
if self.next_index == self.data.len() {
|
||||
self.next_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user