about summary refs log tree commit diff
path: root/src/facility.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-21 21:05:57 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-21 21:05:57 -0700
commitefa17e7eb566d81ce821bde459e900d7398a9977 (patch)
tree623059a8ef212b9e340737fa492812d0827fdcf5 /src/facility.rs
parent62d218ed210a5c5f6686e80edb38fedd0c952de1 (diff)
facilities now get an update ping at the start of each frame
with that done, battery status now updates live! wooooo

Force-Push: yes
Change-Id: If7f2343f6d7762e8f65a4735deadc1b871e26f9d
Diffstat (limited to 'src/facility.rs')
-rw-r--r--src/facility.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/facility.rs b/src/facility.rs
index c156570..dcc252c 100644
--- a/src/facility.rs
+++ b/src/facility.rs
@@ -21,6 +21,11 @@ pub trait Facility: Any {
    */
   #[allow(dead_code)]
   fn as_any_mut(&mut self) -> &mut dyn Any;
+
+  /*   Frustratingly, this can't be async because that wouldn't be
+   * dyn-compatible.
+   */
+  fn update(&mut self) -> Result<()>;
 }
 
 /*   In order to keep Facility dyn-compatible, we put everything that isn't in
@@ -106,5 +111,48 @@ impl FacilityMap {
       (*facility).as_mut().as_any_mut().downcast_mut()
     } else { None }
   }
+
+  pub fn iter(&self) -> impl Iterator<Item=&Box<dyn Facility>> {
+    let btree_iterator = self.facilities.iter();
+
+    Iter { btree_iterator }
+  }
+
+  pub fn iter_mut(&mut self) -> impl Iterator<Item=&mut Box<dyn Facility>> {
+    let btree_iterator = self.facilities.iter_mut();
+
+    IterMut { btree_iterator }
+  }
+}
+
+
+struct Iter<'a> {
+  btree_iterator: std::collections::btree_map
+      ::Iter<'a, FacilityType, Box<dyn Facility>>,
+}
+
+impl<'a> Iterator for Iter<'a> {
+  type Item = &'a Box<dyn Facility>;
+
+  fn next(&mut self) -> Option<Self::Item> {
+    if let Some((_, value)) = self.btree_iterator.next() {
+      Some(value)
+    } else { None }
+  }
+}
+
+struct IterMut<'a> {
+  btree_iterator: std::collections::btree_map
+      ::IterMut<'a, FacilityType, Box<dyn Facility>>,
+}
+
+impl<'a> Iterator for IterMut<'a> {
+  type Item = &'a mut Box<dyn Facility>;
+
+  fn next(&mut self) -> Option<Self::Item> {
+    if let Some((_, value)) = self.btree_iterator.next() {
+      Some(value)
+    } else { None }
+  }
 }