Skip to main content

Beeper

Struct Beeper 

Source
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 preset beeps, alternating q on for t_on then off for t_off
  • When all beeps are emitted, done becomes true and q stays false
  • Setting execute to false at any time resets the FB and silences output
  • t_on / t_off values 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: bool

Output: beeper pulse. Connect to the output controlling the beeper.

§count: u16

Output: number of beeps emitted so far.

§done: bool

Output: true when the preset number of beeps has been emitted.

Implementations§

Source§

impl Beeper

Source

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);
Source

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 sequence
  • preset - Number of beeps to emit
  • t_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 output

Trait Implementations§

Source§

impl Clone for Beeper

Source§

fn clone(&self) -> Beeper

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Beeper

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Beeper

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Beeper

§

impl RefUnwindSafe for Beeper

§

impl Send for Beeper

§

impl Sync for Beeper

§

impl Unpin for Beeper

§

impl UnwindSafe for Beeper

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V