factor chime play into separate function
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -49,17 +49,8 @@ async fn main() {
|
|||||||
let (tx, rx) = mpsc::channel(1);
|
let (tx, rx) = mpsc::channel(1);
|
||||||
events_clients.lock().unwrap().push(tx);
|
events_clients.lock().unwrap().push(tx);
|
||||||
let pushes = rx.for_each(|()| {
|
let pushes = rx.for_each(|()| {
|
||||||
if !audio_busy() {
|
if !audio_busy() { play_chime() }
|
||||||
trace!("Playing doorbell chime");
|
else { debug!("doorbell still ringing, not playing new 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"); }
|
|
||||||
futures_util::future::ready(())
|
futures_util::future::ready(())
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -118,3 +109,15 @@ fn audio_busy() -> bool {
|
|||||||
false
|
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)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user