Add sensors registry to global registries

This commit is contained in:
Gregor Reitzenstein 2020-09-17 11:46:05 +02:00
parent fc1480314f
commit 637490bd75
2 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,7 @@ mod actuators;
mod sensors;
pub use actuators::{Actuator, ActBox};
pub use sensors::{Sensor, SensBox};
#[derive(Clone)]
/// BFFH registries
@ -10,12 +11,14 @@ pub use actuators::{Actuator, ActBox};
/// reference, not clone the registries
pub struct Registries {
pub actuators: actuators::Actuators,
pub sensors: sensors::Sensors,
}
impl Registries {
pub fn new() -> Self {
Registries {
actuators: actuators::Actuators::new()
actuators: actuators::Actuators::new(),
sensors: sensors::Sensors::new(),
}
}
}

View File

@ -7,10 +7,19 @@ use std::sync::Arc;
use smol::lock::RwLock;
use std::collections::HashMap;
#[derive(Clone)]
pub struct Sensors {
inner: Arc<RwLock<Inner>>,
}
impl Sensors {
pub fn new() -> Self {
Sensors {
inner: Arc::new(RwLock::new(Inner::new())),
}
}
}
pub type SensBox<'a> = Box<dyn Sensor<'a>>;
type Inner = HashMap<String, SensBox<'static>>;