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§
Sourcefn buzz(&self, frequency_hz: usize, duration_ms: usize) -> Result<(), ErrorCode>
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.
Sourcefn stop(&self) -> Result<(), ErrorCode>
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.
Sourcefn set_client(&self, client: &'a dyn BuzzerClient)
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".