Skip to main content

autocore_std/fb/
mod.rs

1//! # Function Blocks
2//!
3//! Reusable function blocks for control program development, inspired by the
4//! IEC 61131-3 standard. Each block is a stateful struct that you call
5//! cyclically (once per scan) from your [`ControlProgram::process_tick`](crate::ControlProgram::process_tick)
6//! implementation.
7//!
8//! ## Available Blocks
9//!
10//! | Block | Description |
11//! |-------|-------------|
12//! | [`RTrig`](crate::fb::RTrig) | Rising edge detector (false → true) |
13//! | [`FTrig`](crate::fb::FTrig) | Falling edge detector (true → false) |
14//! | [`Ton`](crate::fb::Ton) | Timer On Delay — output activates after a duration |
15//! | [`SimpleTimer`](crate::fb::SimpleTimer) | One-shot timer for imperative start/check patterns |
16//! | [`StateMachine`](crate::fb::StateMachine) | State machine helper with automatic timer management |
17//! | [`BitResetOnDelay`](crate::fb::BitResetOnDelay) | Resets a boolean after it has been true for a duration |
18//! | [`RunningAverage`](crate::fb::RunningAverage) | Accumulates values and computes their arithmetic mean |
19//! | [`Beeper`](crate::fb::Beeper) | Audible beeper controller with configurable beep sequences |
20//! | [`Heartbeat`](crate::fb::Heartbeat) | Monitors a remote heartbeat counter for connection loss |
21//! | [`Shutdown`](crate::fb::Shutdown) | Non-blocking system shutdown initiation and cancellation via IPC |
22//! | [`ni::DaqCapture`](crate::fb::ni::DaqCapture) | NI DAQ triggered capture: arm, wait, read data via IPC |
23//!
24//! ## Usage Pattern
25//!
26//! All function blocks follow the same pattern:
27//!
28//! 1. **Create** the block once (typically in your program struct)
29//! 2. **Call** it every scan cycle with the current inputs
30//! 3. **Read** its outputs to drive your logic
31//!
32//! ```ignore
33//! use autocore_std::fb::{RTrig, Ton};
34//! use std::time::Duration;
35//!
36//! struct MyProgram {
37//!     start_trigger: RTrig,
38//!     start_delay: Ton,
39//! }
40//!
41//! impl MyProgram {
42//!     fn new() -> Self {
43//!         Self {
44//!             start_trigger: RTrig::new(),
45//!             start_delay: Ton::new(),
46//!         }
47//!     }
48//! }
49//! ```
50//!
51//! ## IEC 61131-3 Naming
52//!
53//! | IEC 61131-3 Name | Rust Name |
54//! |------------------|-----------|
55//! | `R_TRIG` | [`RTrig`](crate::fb::RTrig) |
56//! | `F_TRIG` | [`FTrig`](crate::fb::FTrig) |
57//! | `TON` | [`Ton`](crate::fb::Ton) |
58//! | `FB_StateMachine` | [`StateMachine`](crate::fb::StateMachine) |
59//! | `FB_BitResetOnDelay` | [`BitResetOnDelay`](crate::fb::BitResetOnDelay) |
60//! | `FB_RunningAverage` | [`RunningAverage`](crate::fb::RunningAverage) |
61//! | `FB_Beeper` | [`Beeper`](crate::fb::Beeper) |
62//! | `FB_Heartbeat` | [`Heartbeat`](crate::fb::Heartbeat) |
63//! | `FB_Shutdown` | [`Shutdown`](crate::fb::Shutdown) |
64
65mod r_trig;
66mod f_trig;
67mod ton;
68mod simple_timer;
69mod state_machine;
70mod bit_reset_on_delay;
71mod running_average;
72mod beeper;
73mod heartbeat;
74mod shutdown;
75pub mod ni;
76pub use r_trig::RTrig;
77pub use f_trig::FTrig;
78pub use ton::Ton;
79pub use simple_timer::SimpleTimer;
80pub use state_machine::StateMachine;
81pub use bit_reset_on_delay::BitResetOnDelay;
82pub use running_average::{RunningAverage, Averageable};
83pub use beeper::Beeper;
84pub use heartbeat::Heartbeat;
85pub use shutdown::Shutdown;