feat: progress

This commit is contained in:
2024-09-25 16:47:28 +02:00
parent 04e1b1f9ae
commit 3d7e506dd5
24 changed files with 2398 additions and 67 deletions

37
app/src/debouncer.rs Normal file
View File

@ -0,0 +1,37 @@
/// Basic debouncer that checks 16 samples, and only if all of them are on / off, it will return
/// the value.
#[derive(Debug)]
pub struct Debouncer(u16, bool);
impl Debouncer {
pub fn new() -> Self {
Self(0, false)
}
pub fn read(&self) -> bool {
self.1
}
/// Completely fill the debouncer, settng it "true".
pub fn fill(&mut self) {
self.0 = u16::MAX;
self.1 = true;
}
/// Completely empty the debouncer, settng it "false".
pub fn empty(&mut self) {
self.0 = 0;
self.1 = false;
}
pub fn update(&mut self, val: bool) -> bool {
self.0 = (self.0 << 1) | (val as u16);
if self.0 == u16::MAX {
self.1 = true;
} else if self.0 == 0 {
self.1 = false;
}
self.1
}
}