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