pub struct Beeper {
pub q: bool,
pub count: u16,
pub done: bool,
/* private fields */
}Expand description
Audible Beeper Controller (FB_Beeper)
Controls an audible beeper through a single boolean output. On the rising
edge of execute, emits exactly preset beeps with configurable on/off
durations. Call cyclically (once per scan).
§Behavior
- Idle until a rising edge is detected on
execute - On trigger: emits
presetbeeps, alternatingqon fort_onthen off fort_off - When all beeps are emitted,
donebecomestrueandqstaysfalse - Setting
executetofalseat any time resets the FB and silences output t_on/t_offvalues below 50 ms are clamped to 750 ms / 500 ms
§Example
use autocore_std::fb::Beeper;
use std::time::Duration;
let mut beeper = Beeper::new();
// Idle — not yet triggered
beeper.call(false, 3, Duration::from_millis(100), Duration::from_millis(100));
assert_eq!(beeper.q, false);
assert_eq!(beeper.done, false);
// Rising edge triggers 3 beeps
beeper.call(true, 3, Duration::from_millis(100), Duration::from_millis(100));
// One more call enters the beeping state
beeper.call(true, 3, Duration::from_millis(100), Duration::from_millis(100));
assert_eq!(beeper.q, true); // First beep started§Timing Diagram (preset = 2)
execute: ___|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
q: ____|‾‾‾‾‾|_____|‾‾‾‾‾|____________________
count: 0 0 1 1 2
done: ________________________|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
←t_on→←t_off→←t_on→←t_off→§Use Cases
- Audible alarms with a fixed number of beeps
- Confirmation tones (single short beep)
- Warning patterns (rapid multi-beep)
Fields§
§q: boolOutput: beeper pulse. Connect to the output controlling the beeper.
count: u16Output: number of beeps emitted so far.
done: boolOutput: true when the preset number of beeps has been emitted.
Implementations§
Source§impl Beeper
impl Beeper
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new beeper in the idle state.
§Example
use autocore_std::fb::Beeper;
let beeper = Beeper::new();
assert_eq!(beeper.q, false);
assert_eq!(beeper.count, 0);
assert_eq!(beeper.done, false);Sourcepub fn call(
&mut self,
execute: bool,
preset: u16,
t_on: Duration,
t_off: Duration,
)
pub fn call( &mut self, execute: bool, preset: u16, t_on: Duration, t_off: Duration, )
Executes one scan cycle of the beeper logic.
Call this once per control cycle. On the rising edge of execute,
the beeper begins emitting preset beeps. Setting execute to
false resets the FB immediately (silences output).
§Arguments
execute- Enable; rising edge triggers the beep sequencepreset- Number of beeps to emitt_on- Duration the beeper stays on per beep (min 50 ms, clamped to 750 ms)t_off- Duration the beeper stays off between beeps (min 50 ms, clamped to 500 ms)
§Example
use autocore_std::fb::Beeper;
use std::time::Duration;
let mut beeper = Beeper::new();
let t_on = Duration::from_millis(750);
let t_off = Duration::from_millis(750);
// Call cyclically in your control loop
beeper.call(some_trigger_condition, 2, t_on, t_off);
// Read beeper.q to drive the physical outputTrait Implementations§
Auto Trait Implementations§
impl Freeze for Beeper
impl RefUnwindSafe for Beeper
impl Send for Beeper
impl Sync for Beeper
impl Unpin for Beeper
impl UnsafeUnpin for Beeper
impl UnwindSafe for Beeper
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