bump a lot of big changes I dont want to break down into individual commits

This commit is contained in:
2025-10-11 16:34:09 +02:00
parent 0e9e0c1b13
commit 8280f38185
48 changed files with 1275467 additions and 394056 deletions

View File

@@ -6,49 +6,27 @@ pub mod events;
pub mod tasks;
pub mod shaders;
pub mod ego;
pub mod animation;
pub mod idle;
pub mod logging;
extern crate alloc;
use rgb::Rgb;
use core::{iter::Sum, ops::{Div, Sub}, fmt::Debug};
/// Scales the requested brightness to stay within power consumption limits
pub fn brightness_for_mw(total_mw : u32, target : u8, max_power: u32) -> u8 {
let target32 = target as u32;
let requested_mw = (total_mw * target32) / 256;
if requested_mw > max_power {
((target32 * max_power) / requested_mw) as u8
} else {
target
}
}
/// Calculate the estimated power draw of a single pixel, in milliwatts
pub fn as_milliwatts(pixel: &Rgb<u8>) -> u32 {
// These values are copied from the original FastLED implementation
const RED_MW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
const GREEN_MW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
const BLUE_MW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
const DARK_MW : u32 = 5; //< 1mA @ 5v = 5mW
let red = (pixel.r as u32 * RED_MW).wrapping_shr(8);
let green = (pixel.g as u32 * GREEN_MW).wrapping_shr(8);
let blue = (pixel.b as u32 * BLUE_MW).wrapping_shr(8);
red + green + blue + DARK_MW
}
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub struct CircularBuffer<T, const SIZE: usize = 20> {
pub data: [T; SIZE],
next_index: usize
data: [T; SIZE],
next_index: usize,
filled: bool
}
impl<T: Default + Copy, const SIZE: usize> Default for CircularBuffer<T, SIZE> {
fn default() -> Self {
Self {
data: [Default::default(); SIZE],
next_index: 0
next_index: 0,
filled: false
}
}
}
@@ -59,6 +37,50 @@ impl<T, const SIZE: usize> CircularBuffer<T, SIZE> {
self.next_index += 1;
if self.next_index == self.data.len() {
self.next_index = 0;
self.filled = true;
}
}
pub fn data(&self) -> &[T; SIZE] {
&self.data
}
pub fn is_filled(&self) -> bool {
self.filled
}
pub fn mean(&self) -> T where T: for<'a> Sum<&'a T> + Div<f32, Output = T> {
self.data.iter().sum::<T>() / self.data.len() as f32
}
pub fn derivative(&self) -> T where for<'a> &'a T: Sub<&'a T, Output = T>, T: Sum<T> + Div<f32, Output = T> {
self.data.windows(2).map(|n| {
&n[0] - &n[1]
}).sum::<T>().div(self.data.len() as f32)
}
}
#[derive(Debug, Default)]
pub struct Breaker<T> {
tripped: bool,
value: T
}
impl<T: PartialEq + Copy + Debug> Breaker<T> {
pub fn set(&mut self, value: T) {
if self.value != value {
self.value = value;
self.tripped = true;
}
}
pub fn read_tripped(&mut self) -> Option<T> {
if self.tripped {
//info!("Tripped: {self:?}");
self.tripped = false;
Some(self.value)
} else {
None
}
}
}