BuzzerEngine

Struct BuzzerEngine 

Source
pub struct BuzzerEngine { /* private fields */ }
Expand description

Buzzer melody engine.

Implementations§

Source§

impl BuzzerEngine

Source

pub const fn new() -> Self

Source

pub fn is_silenced(&self) -> bool

Returns true if the buzzer is currently silenced.

Source

pub fn set_silenced(&mut self, silenced: bool)

Toggle silence. Engaging silence stops any in-flight melody so the user’s request is honored without waiting for the sequence to finish — except a locate alert, which outranks it.

Source

pub fn alert_active(&self) -> bool

Whether a silence-overriding locate alert is playing.

Source

pub fn toggle_silenced(&mut self) -> bool

Toggle silence on/off and return the new state. Convenience for the double-press handler.

Source

pub fn restart_active(&mut self, now_ms: u64)

Rewind the active melody so its first note plays from now_ms. No-op if no melody is active.

Buzzer drivers that need an inaudible warmup period (e.g. the T1000-E’s piezo driver chip needs ~20 ms of PWM activity before it starts emitting) should run that warmup with the engine already loaded, then call this to drop the warmup interval out of the engine’s perceived clock so the first note gets its full declared duration.

Source

pub fn play(&mut self, melody: &'static Melody, now_ms: u64)

Start a melody. No-op if silenced, and no-op while a locate alert is running — an ordinary notification must not displace the alarm someone is currently homing in on.

Source

pub fn play_alert( &mut self, melody: &'static Melody, now_ms: u64, period_ms: u64, )

Start the locate alert: melody on repeat every period_ms, playing through silence, until Self::stop_alert.

Intermittent by construction rather than a continuous tone — a lost radio is usually a nearly-flat radio, and a periodic chirp is easier to home in on than a constant one.

Source

pub fn stop_alert(&mut self)

Stop a locate alert. Leaves an ordinary melody alone, so this is safe to call unconditionally when the alert clears.

Source

pub fn next_deadline_ms(&self, now_ms: u64) -> Option<u64>

When the engine next changes state, if it will.

BuzzerDecision::Silent carries no deadline, but a repeating alert is silent between passes and must be woken for the next one — a driver that only re-ticks on Tone deadlines would play the alert once and stop. Drivers arm a timer on this whenever the decision is Silent.

Source

pub fn tick(&mut self, now_ms: u64) -> BuzzerDecision

Compute the buzzer state to apply at now_ms.

Trait Implementations§

Source§

impl Debug for BuzzerEngine

Source§

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

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

impl Default for BuzzerEngine

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.