New implementation with threads per component
This commit is contained in:
parent
ac8ebbafe9
commit
bfbddda58c
15 changed files with 170 additions and 265 deletions
|
|
@ -1,8 +1,10 @@
|
|||
use std::collections::HashMap;
|
||||
use crate::{PinValue, BaseComponent, Component, Pin};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use crate::component::{BaseComponent, Component};
|
||||
use crate::pin::{Pin, PinValue};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GenericClock {
|
||||
base: BaseComponent,
|
||||
|
|
@ -13,7 +15,7 @@ pub struct GenericClock {
|
|||
impl GenericClock {
|
||||
pub fn new(name: String, frequency_hz: u64) -> Self {
|
||||
let mut base = BaseComponent::new(name);
|
||||
let out_pin = base.add_pin("out".to_string(), PinValue::Low, true);
|
||||
let _out_pin = base.add_pin("out".to_string(), PinValue::Low, true);
|
||||
|
||||
let half_period_ms = 500 / frequency_hz; // Convert to milliseconds
|
||||
|
||||
|
|
@ -24,29 +26,20 @@ impl GenericClock {
|
|||
last_state: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn out(&self) -> Option<Arc<Pin>> {
|
||||
self.base.get_pin("out")
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for GenericClock {
|
||||
fn name(&self) -> &str {
|
||||
self.base.name()
|
||||
}
|
||||
|
||||
fn pins(&self) -> &HashMap<String, Arc<Pin>> {
|
||||
self.base.pins()
|
||||
}
|
||||
|
||||
fn get_pin(&self, name: &str) -> Option<Arc<Pin>> {
|
||||
self.base.get_pin(name)
|
||||
}
|
||||
|
||||
fn connect_pin(&mut self, pin_name: &str, other_pin: Arc<Pin>) -> Result<(), String> {
|
||||
self.base.connect_pin(pin_name, other_pin)
|
||||
}
|
||||
|
||||
fn update(&mut self) -> Result<(), String> {
|
||||
let out_pin = self.base.pins.get("out").unwrap();
|
||||
|
||||
|
|
@ -59,11 +52,9 @@ impl Component for GenericClock {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run(&mut self) {
|
||||
self.base.run();
|
||||
}
|
||||
|
||||
fn stop(&mut self) {
|
||||
self.base.stop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue