Add pin registry
This commit is contained in:
parent
7dd09c730d
commit
2a78581a2d
1 changed files with 10 additions and 0 deletions
|
|
@ -4,16 +4,26 @@ use crate::pin::Pin;
|
||||||
|
|
||||||
/// Manages electrical connections between pins
|
/// Manages electrical connections between pins
|
||||||
pub struct ConnectionManager {
|
pub struct ConnectionManager {
|
||||||
|
pin_registry: HashMap<String, Arc<Mutex<Pin>>>,
|
||||||
connections: HashMap<String, Vec<String>>, // pin_name -> connected_pin_names
|
connections: HashMap<String, Vec<String>>, // pin_name -> connected_pin_names
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectionManager {
|
impl ConnectionManager {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ConnectionManager {
|
ConnectionManager {
|
||||||
|
pin_registry: HashMap::new(),
|
||||||
connections: HashMap::new(),
|
connections: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn register_pin(&mut self, name: String, pin: Arc<Mutex<Pin>>) {
|
||||||
|
self.pin_registry.insert(name, pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pin(&self, name: &str) -> Option<Arc<Mutex<Pin>>> {
|
||||||
|
self.pin_registry.get(name).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
/// Connect two pins bidirectionally
|
/// Connect two pins bidirectionally
|
||||||
pub fn connect_pins(&mut self, pin1: Arc<Mutex<Pin>>, pin2: Arc<Mutex<Pin>>) -> Result<(), String> {
|
pub fn connect_pins(&mut self, pin1: Arc<Mutex<Pin>>, pin2: Arc<Mutex<Pin>>) -> Result<(), String> {
|
||||||
let pin1_name = {
|
let pin1_name = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue