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; mod sensors;
pub use actuators::{Actuator, ActBox}; pub use actuators::{Actuator, ActBox};
pub use sensors::{Sensor, SensBox};
#[derive(Clone)] #[derive(Clone)]
/// BFFH registries /// BFFH registries
@ -10,12 +11,14 @@ pub use actuators::{Actuator, ActBox};
/// reference, not clone the registries /// reference, not clone the registries
pub struct Registries { pub struct Registries {
pub actuators: actuators::Actuators, pub actuators: actuators::Actuators,
pub sensors: sensors::Sensors,
} }
impl Registries { impl Registries {
pub fn new() -> Self { pub fn new() -> Self {
Registries { 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 smol::lock::RwLock;
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Clone)]
pub struct Sensors { pub struct Sensors {
inner: Arc<RwLock<Inner>>, 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>>; pub type SensBox<'a> = Box<dyn Sensor<'a>>;
type Inner = HashMap<String, SensBox<'static>>; type Inner = HashMap<String, SensBox<'static>>;