Skip to main content

Buzzer

Trait Buzzer 

Source
pub trait Buzzer<'a> {
    // Required methods
    fn buzz(
        &self,
        frequency_hz: usize,
        duration_ms: usize,
    ) -> Result<(), ErrorCode>;
    fn stop(&self) -> Result<(), ErrorCode>;
    fn set_client(&self, client: &'a dyn BuzzerClient);
}
Expand description

The Buzzer HIL is used to play a sound on a buzzer at a fixed frequency and for a certain duration.

Required Methods§

Source

fn buzz(&self, frequency_hz: usize, duration_ms: usize) -> Result<(), ErrorCode>

Play a sound at a chosen frequency and for a chosen duration. Once the buzzer finishes buzzing, the buzzer_done() callback is called. If it is called while the buzzer is playing, the buzzer command will be overridden with the new frequency and duration values.

Return values:

  • Ok(()): The attempt at starting the buzzer was successful.
  • FAIL: Cannot start the buzzer.
Source

fn stop(&self) -> Result<(), ErrorCode>

Stop the sound currently playing. After the buzzer is successfully stopped, the buzzer_done() callback is called.

Return values:

  • Ok(()): The attempt at stopping the buzzer was successful.
  • FAIL: Cannot stop the buzzer.
  • OFF: The buzzer wasn’t playing a sound when the stop command was called.
Source

fn set_client(&self, client: &'a dyn BuzzerClient)

Set the client to be used for callbacks of the Buzzer implementation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§