pub struct BuzzerEngine { /* private fields */ }Expand description
Buzzer melody engine.
Implementations§
Source§impl BuzzerEngine
impl BuzzerEngine
pub const fn new() -> Self
Sourcepub fn is_silenced(&self) -> bool
pub fn is_silenced(&self) -> bool
Returns true if the buzzer is currently silenced.
Sourcepub fn set_silenced(&mut self, silenced: bool)
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.
Sourcepub fn alert_active(&self) -> bool
pub fn alert_active(&self) -> bool
Whether a silence-overriding locate alert is playing.
Sourcepub fn toggle_silenced(&mut self) -> bool
pub fn toggle_silenced(&mut self) -> bool
Toggle silence on/off and return the new state. Convenience for the double-press handler.
Sourcepub fn restart_active(&mut self, now_ms: u64)
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.
Sourcepub fn play(&mut self, melody: &'static Melody, now_ms: u64)
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.
Sourcepub fn play_alert(
&mut self,
melody: &'static Melody,
now_ms: u64,
period_ms: u64,
)
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.
Sourcepub fn stop_alert(&mut self)
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.
Sourcepub fn next_deadline_ms(&self, now_ms: u64) -> Option<u64>
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.
Sourcepub fn tick(&mut self, now_ms: u64) -> BuzzerDecision
pub fn tick(&mut self, now_ms: u64) -> BuzzerDecision
Compute the buzzer state to apply at now_ms.