Skip to content

Commit

Permalink
fix clock
Browse files Browse the repository at this point in the history
  • Loading branch information
Ved-s committed Jan 13, 2024
1 parent 52bf1a3 commit cb0d01d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/circuits/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ impl Clock {

#[track_caller]
fn schedule_next_update(frequency: f32, pwm: f32, state: &mut ClockState) -> Option<Duration> {
if frequency <= 0.0 {
return None;
}
if pwm <= 0.0 || pwm >= 1.0 {
return Some(Duration::ZERO);
}
Expand Down Expand Up @@ -216,7 +219,7 @@ impl Clock {

impl CircuitImpl for Clock {
fn draw(&self, state_ctx: &CircuitStateContext, paint_ctx: &PaintContext) {
let enabled = state_ctx
let enabled = self.frequency > 0.0 && state_ctx
.read_circuit_internal_state(|s: &ClockState| s.enabled || s.state)
.unwrap_or_default();
Clock::draw(self.pwm, enabled, paint_ctx, false);
Expand Down Expand Up @@ -362,7 +365,10 @@ impl CircuitPreviewImpl for Preview {
}

fn description(&self) -> DynStaticStr {
"TODO".into()
"Clock pulses its output with set frequency specified in its parameters.\n\
% of the time signal stays on during the clock cycle can be set with PWM Fill property.\n\
Control pin can be enabled to turn the clock on or off.\
".into()
}

fn draw_preview(&self, props: &CircuitPropertyStore, ctx: &PaintContext, in_world: bool) {
Expand Down
8 changes: 8 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@ impl State {

fn schedule_update(self: &Arc<Self>, task: UpdateTask) {
let mut queue = self.queue.lock();

if queue.len() > 10_000_000 {
println!("warning! queue contains too many elements! draining...");
for _ in 0..1_000_000 {
queue.dequeue();
}
}

queue.enqueue(task);

#[cfg(not(feature = "single_thread"))]
Expand Down
3 changes: 2 additions & 1 deletion src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ impl CircuitBoardEditor {
_ => (),
}

let queue_len = self.board.state.queue_len();
let states = self.board.board.states.states.read().iter().count();
let frozen_states = self
.board
Expand All @@ -631,7 +632,7 @@ impl CircuitBoardEditor {
.filter(|s| !s.is_being_used())
.count();

let text = format!("This board has {states} state(s), {frozen_states} are frozen, {unused_states} will be removed");
let text = format!("This board has {states} state(s), {frozen_states} are frozen, {unused_states} will be removed\nCurrent queue length: {queue_len}");

ui.monospace(text);
}
Expand Down

0 comments on commit cb0d01d

Please sign in to comment.