Skip to content

Commit

Permalink
Merge pull request #178 from namana-mecha/save-snapshot-to-pictures
Browse files Browse the repository at this point in the history
feat(camera-app): Snapshot will get saved in the `~/Pictures` directory.
  • Loading branch information
akshayr-mecha authored Feb 6, 2025
2 parents 6e6b565 + cc34205 commit 4d4547d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ members = [
default-members = ["settings-app", "camera", "files"]

[workspace.package]
version = "0.1.15"
version = "0.1.16"
authors = [
"Sweta <[email protected]>",
"Naman <namana-mecha@mechasystems.com>",
"Naman <[email protected]>",
"Minesh <[email protected]>",
]
edition = "2021"
Expand Down Expand Up @@ -38,4 +38,4 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"]}
anyhow = { version = "1.0.75", features = ["backtrace"]}
tokio = { version = "1.33", features = ["full"] }
networkmanager = { path = "../commons/networkmanager"}
networkmanager = { path = "../commons/networkmanager"}
1 change: 1 addition & 0 deletions apps/camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ serde = "1.0.217"
serde_yaml = "0.9.34"
dirs = "5.0.1"
const_format = "0.2.34"
chrono = "0.4.39"

[package.metadata.deb]
name = "mechanix-camera"
Expand Down
21 changes: 17 additions & 4 deletions apps/camera/src/contexts/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ impl Camera {
}

pub fn save_frame() {
let frame = Self::get().frame_buffer.get();
frame.save("frame.jpg").unwrap();

RUNTIME.spawn(async {
GST_CAMERA
.lock()
Expand Down Expand Up @@ -173,7 +170,23 @@ impl Camera {
let buffer = yuyv422_to_rgb(frame.as_raw(), true).unwrap();
let frame: ImageBuffer<image::Rgba<u8>, Vec<u8>> =
ImageBuffer::from_raw(width, height, buffer).unwrap();
frame.save("frame2.jpg").unwrap();

let now = chrono::Local::now();
let formatted_time = now.format("%Y%m%d_%H%M%S").to_string();
let mut pictures_dir = std::path::PathBuf::from(
std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()),
);
pictures_dir.push("Pictures");

if !pictures_dir.exists() {
std::fs::create_dir_all(&pictures_dir)
.expect("Couldn't create directory `Pictures`");
}

let filename = format!("Snapshot_{}.jpg", formatted_time);
let filepath = pictures_dir.join(&filename);
frame.save(filepath).unwrap();

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Component for SettingsScreen {
);

list_items = list_items.push(network_div);
list_items = list_items.push(bluetooth_div);
// list_items = list_items.push(bluetooth_div);
list_items = list_items.push(display_div);
// list_items = list_items.push(appearance_div);
list_items = list_items.push(battery_div);
Expand Down

0 comments on commit 4d4547d

Please sign in to comment.