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//!
23//! ## Usage Pattern
24//!
25//! All function blocks follow the same pattern:
26//!
27//! 1. **Create** the block once (typically in your program struct)
28//! 2. **Call** it every scan cycle with the current inputs
29//! 3. **Read** its outputs to drive your logic
30//!
31//! ```ignore
32//! use autocore_std::fb::{RTrig, Ton};
33//! use std::time::Duration;
34//!
35//! struct MyProgram {
36//!     start_trigger: RTrig,
37//!     start_delay: Ton,
38//! }
39//!
40//! impl MyProgram {
41//!     fn new() -> Self {
42//!         Self {
43//!             start_trigger: RTrig::new(),
44//!             start_delay: Ton::new(),
45//!         }
46//!     }
47//! }
48//! ```
49//!
50//! ## IEC 61131-3 Naming
51//!
52//! | IEC 61131-3 Name | Rust Name |
53//! |------------------|-----------|
54//! | `R_TRIG` | [`RTrig`](crate::fb::RTrig) |
55//! | `F_TRIG` | [`FTrig`](crate::fb::FTrig) |
56//! | `TON` | [`Ton`](crate::fb::Ton) |
57//! | `FB_StateMachine` | [`StateMachine`](crate::fb::StateMachine) |
58//! | `FB_BitResetOnDelay` | [`BitResetOnDelay`](crate::fb::BitResetOnDelay) |
59//! | `FB_RunningAverage` | [`RunningAverage`](crate::fb::RunningAverage) |
60//! | `FB_Beeper` | [`Beeper`](crate::fb::Beeper) |
61//! | `FB_Heartbeat` | [`Heartbeat`](crate::fb::Heartbeat) |
62//! | `FB_Shutdown` | [`Shutdown`](crate::fb::Shutdown) |
63
64mod r_trig;
65mod f_trig;
66mod ton;
67mod simple_timer;
68mod state_machine;
69mod bit_reset_on_delay;
70mod running_average;
71mod beeper;
72mod heartbeat;
73mod shutdown;
74pub use r_trig::RTrig;
75pub use f_trig::FTrig;
76pub use ton::Ton;
77pub use simple_timer::SimpleTimer;
78pub use state_machine::StateMachine;
79pub use bit_reset_on_delay::BitResetOnDelay;
80pub use running_average::{RunningAverage, Averageable};
81pub use beeper::Beeper;
82pub use heartbeat::Heartbeat;
83pub use shutdown::Shutdown;