factor chime play into separate function

This commit is contained in:
2020-10-29 06:40:51 -07:00
parent ab961382ba
commit 85a69b2420

View File

@@ -49,17 +49,8 @@ async fn main() {
let (tx, rx) = mpsc::channel(1);
events_clients.lock().unwrap().push(tx);
let pushes = rx.for_each(|()| {
if !audio_busy() {
trace!("Playing doorbell chime");
match process::Command::new("mplayer")
.arg(OUTDOOR_CHIME_FILE)
.stdout(process::Stdio::null())
.stderr(process::Stdio::null())
.spawn() {
Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); },
Err(err) => error!("Error playing outdoor chime: {}", err)
};
} else { debug!("doorbell still ringing, not playing new chime"); }
if !audio_busy() { play_chime() }
else { debug!("doorbell still ringing, not playing new chime"); }
futures_util::future::ready(())
});
@@ -118,3 +109,15 @@ fn audio_busy() -> bool {
false
})
}
fn play_chime() {
trace!("Playing doorbell chime");
match process::Command::new("mplayer")
.arg(OUTDOOR_CHIME_FILE)
.stdout(process::Stdio::null())
.stderr(process::Stdio::null())
.spawn() {
Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); },
Err(err) => error!("Error playing outdoor chime: {}", err)
};
}