pub struct BitResetOnDelay { /* private fields */ }Expand description
Resets a boolean value after it has been true for a specified duration.
This function block monitors a boolean value and, once it has been
continuously true for the preset time pt, resets it to false.
It uses a Ton timer internally.
IEC 61131-3 equivalent:
tonValue(IN := Value^, PT := PT);
IF tonValue.Q THEN
Value^ := FALSE;
END_IF§Example
use autocore_std::fb::BitResetOnDelay;
use std::time::Duration;
let mut reset_delay = BitResetOnDelay::new();
let mut flag = true;
// Flag is true, timer starts counting
reset_delay.call(&mut flag, Duration::from_millis(50));
assert_eq!(flag, true); // Not yet reset
// After delay elapses, flag is reset to false
std::thread::sleep(Duration::from_millis(60));
reset_delay.call(&mut flag, Duration::from_millis(50));
assert_eq!(flag, false);§Use Cases
- Auto-clearing acknowledgment flags
- Resetting one-shot signals after a hold time
- Automatically turning off indicators after a display period
Implementations§
Source§impl BitResetOnDelay
impl BitResetOnDelay
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new BitResetOnDelay with the internal timer in its default state.
§Example
use autocore_std::fb::BitResetOnDelay;
let reset_delay = BitResetOnDelay::new();Sourcepub fn call(&mut self, value: &mut bool, pt: Duration)
pub fn call(&mut self, value: &mut bool, pt: Duration)
Call cyclically. Resets value to false after it has been
true for the duration pt.
When value is false, the internal timer resets. When value
is true, the timer counts up. Once the timer reaches pt,
value is set to false.
§Arguments
value- Mutable reference to the boolean to monitor and resetpt- Duration thatvaluemust betruebefore it is reset
§Example
use autocore_std::fb::BitResetOnDelay;
use std::time::Duration;
let mut reset_delay = BitResetOnDelay::new();
let mut alarm_ack = false;
// No effect when value is false
reset_delay.call(&mut alarm_ack, Duration::from_millis(100));
assert_eq!(alarm_ack, false);
// Set the flag
alarm_ack = true;
reset_delay.call(&mut alarm_ack, Duration::from_millis(100));
assert_eq!(alarm_ack, true); // Still true, timer just startedTrait Implementations§
Source§impl Clone for BitResetOnDelay
impl Clone for BitResetOnDelay
Source§fn clone(&self) -> BitResetOnDelay
fn clone(&self) -> BitResetOnDelay
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BitResetOnDelay
impl Debug for BitResetOnDelay
Auto Trait Implementations§
impl Freeze for BitResetOnDelay
impl RefUnwindSafe for BitResetOnDelay
impl Send for BitResetOnDelay
impl Sync for BitResetOnDelay
impl Unpin for BitResetOnDelay
impl UnwindSafe for BitResetOnDelay
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more