-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::error::Error; | ||
|
||
use tokio::sync::watch::Receiver; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
/// runs the mute/unmute functionality | ||
pub async fn audible_manager( | ||
cancel_token: CancellationToken, | ||
mut mute_stat_recv: Receiver<bool>, | ||
) -> Result<(), Box<dyn Error + Send + Sync>> { | ||
loop { | ||
tokio::select! { | ||
_ = cancel_token.cancelled() => { | ||
|
||
}, | ||
new = mute_stat_recv.changed() => { | ||
new?; | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,75 @@ | ||
use std::error::Error; | ||
|
||
use tokio::sync::watch::Receiver; | ||
use tokio::{process::Command, sync::watch::Receiver}; | ||
use tokio_util::sync::CancellationToken; | ||
use tracing::info; | ||
|
||
/// Run various HV on/off lockdowns | ||
pub async fn lockdown_runner( | ||
cancel_token: CancellationToken, | ||
mut hv_stat_recv: Receiver<bool>, | ||
) -> Result<(), Box<dyn Error + Send + Sync>> { | ||
let mut prev_state = false; | ||
|
||
loop { | ||
tokio::select! { | ||
_ = cancel_token.cancelled() => { | ||
hv_transition_disabled().await; | ||
break Ok(()); | ||
}, | ||
new = hv_stat_recv.changed() => { | ||
new?; | ||
info!("New HV state:{}", *hv_stat_recv.borrow_and_update()); | ||
let curr_state = *hv_stat_recv.borrow_and_update(); | ||
if prev_state == curr_state { continue } else{ | ||
prev_state = curr_state; | ||
} | ||
|
||
info!("New HV state: {}", curr_state); | ||
if curr_state { | ||
hv_transition_enabled().await; | ||
} else { | ||
hv_transition_disabled().await; | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
/// Transition to HV on | ||
pub async fn hv_transition_enabled() { | ||
let mut cmd_cerb_dis = Command::new("usbip") | ||
.args(["unbind", "--busid", "1-1.3"]) | ||
.spawn() | ||
.unwrap(); | ||
let mut cmd_shep_dis = Command::new("usbip") | ||
.args(["unbind", "--busid", "1-1.4"]) | ||
.spawn() | ||
.unwrap(); | ||
|
||
cmd_cerb_dis.wait().await.unwrap(); | ||
cmd_shep_dis.wait().await.unwrap(); | ||
|
||
// if !cmd_cerb_dis.wait().await.unwrap().success() && !cmd_shep_dis.wait().await.unwrap().success() { | ||
// info!("Failed to run USBIP command(s) to unbind"); | ||
// } | ||
} | ||
|
||
/// Transition to HV off | ||
pub async fn hv_transition_disabled() { | ||
let mut cmd_cerb_rec = Command::new("usbip") | ||
.args(["bind", "--busid", "1-1.3"]) | ||
.spawn() | ||
.unwrap(); | ||
let mut cmd_shep_rec = Command::new("usbip") | ||
.args(["bind", "--busid", "1-1.4"]) | ||
.spawn() | ||
.unwrap(); | ||
|
||
cmd_cerb_rec.wait().await.unwrap(); | ||
cmd_shep_rec.wait().await.unwrap(); | ||
|
||
// if !cmd_cerb_rec.wait().await.unwrap().success() && !cmd_shep_rec.wait().await.unwrap().success() { | ||
// println!("Failed to run USBIP command(s) to unbind"); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
use std::{error::Error, process::Stdio}; | ||
use std::{ | ||
error::Error, | ||
process::Stdio, | ||
time::{SystemTime, UNIX_EPOCH}, | ||
}; | ||
|
||
use tokio::process::Command; | ||
use tokio_util::sync::CancellationToken; | ||
|
@@ -16,6 +20,17 @@ pub async fn run_save_pipeline( | |
) -> Result<(), Box<dyn Error + Send + Sync>> { | ||
// ffmpeg -f video4linux2 -input_format mjpeg -s 1280x720 -i /dev/video0 -vf "drawtext=fontfile=FreeSerif.tff: \ | ||
//text='%{localtime\:%T}': [email protected]: x=7: y=700" -vcodec libx264 -preset veryfast -f mp4 -pix_fmt yuv420p -y output.mp4 | ||
|
||
// use the passed in folder | ||
let save_location = format!( | ||
"{}/frontcam-{}-ner24.avi", | ||
vid_opts.save_location, | ||
SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap() | ||
.as_millis() | ||
); | ||
|
||
info!("Creating and launching ffmpeg..."); | ||
let mut res = Command::new("ffmpeg").args([ | ||
"-f", | ||
|
@@ -37,20 +52,18 @@ pub async fn run_save_pipeline( | |
"-pix_fmt", | ||
"yuv420p", | ||
"-y", | ||
&vid_opts.save_location | ||
&save_location | ||
]).stdin(Stdio::null()).spawn()?; | ||
|
||
loop { | ||
tokio::select! { | ||
_ = cancel_token.cancelled() => { | ||
info!("Ffmpeg canceled"); | ||
res.wait().await.unwrap(); | ||
return Ok(()) | ||
}, | ||
_ = res.wait() => { | ||
warn!("Ffmpeg ended early!"); | ||
return Ok(()) | ||
} | ||
tokio::select! { | ||
_ = cancel_token.cancelled() => { | ||
info!("Ffmpeg canceled"); | ||
res.wait().await.unwrap(); | ||
Ok(()) | ||
}, | ||
_ = res.wait() => { | ||
warn!("Ffmpeg ended early!"); | ||
Ok(()) | ||
} | ||
} | ||
} |