-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(thermal-cam-ctrl): add cleanup command (#311)
- Loading branch information
Showing
9 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use clap::Parser; | ||
use color_eyre::Result; | ||
use eyre::{OptionExt as _, WrapErr as _}; | ||
use seek_camera::{ | ||
manager::{CameraHandle, Event, Manager}, | ||
ChipId, ErrorCode, | ||
}; | ||
|
||
use crate::{start_manager, Flow}; | ||
|
||
/// Manages pairing of the camera | ||
#[derive(Debug, Parser)] | ||
pub struct Cleanup {} | ||
|
||
impl Cleanup { | ||
pub fn run(self) -> Result<()> { | ||
start_manager(Box::new(on_cam)) | ||
} | ||
} | ||
|
||
fn on_cam( | ||
mngr: &mut Manager, | ||
cam_h: CameraHandle, | ||
evt: Event, | ||
_err_code: Option<ErrorCode>, | ||
) -> Result<Flow> { | ||
match evt { | ||
Event::Connect | Event::ReadyToPair => (), | ||
_ => return Ok(Flow::Finish), | ||
} | ||
let cid = mngr | ||
.cameras() | ||
.wrap_err("failed to get cameras")? | ||
.get_mut(&cam_h) | ||
.ok_or_eyre("failed to access camera from handle")? | ||
.chip_id() | ||
.wrap_err("failed to get camera chip_id")?; | ||
delete_other_cams(&cid)?; | ||
Ok(Flow::Finish) | ||
} | ||
|
||
fn delete_other_cams(cid_to_keep: &ChipId) -> Result<()> { | ||
let calib_dir = crate::get_seek_dir().join("cal"); | ||
for entry in calib_dir | ||
.read_dir() | ||
.wrap_err("failed to access SEEKTHERMAL_ROOT/.seekthermal/cal")? | ||
{ | ||
let entry = entry?; | ||
if cid_to_keep.as_str() == entry.file_name() { | ||
continue; // skips matching dir | ||
} | ||
tracing::info!("removing {}", entry.path().display()); | ||
std::fs::remove_dir_all(entry.path()).wrap_err_with(|| { | ||
format!( | ||
"failed to delete directory contents at {}", | ||
entry.path().display() | ||
) | ||
})? | ||
} | ||
Ok(()) | ||
} |
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