Skip to content

Commit

Permalink
✨♻️ disable webcam
Browse files Browse the repository at this point in the history
  • Loading branch information
chriamue committed Oct 13, 2023
1 parent 492f013 commit 7c1bc0e
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 116 deletions.
195 changes: 99 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build = "build.rs"
default = ["server", "camera", "yolo"]
full = ["bluetooth", "camera", "detect", "hotspot", "server"]
pi = ["bluetooth", "camera", "detect", "server"]
bluetooth = ["bluer"]
bluetooth = ["base64", "bluer"]
camera = ["nokhwa/input-native"]
hotspot = ["wifi-rs"]
server = ["axum", "base64", "tower", "tower-http"]
Expand Down Expand Up @@ -49,7 +49,7 @@ lenna_birds_plugin = { git = "https://github.com/lenna-project/birds-plugin", br
lenna_yolo_plugin = { git = "https://github.com/lenna-project/yolo-plugin", branch = "main", default-features = false, optional = true }
log = "0.4"
mime = "0.3.17"
nokhwa = { version = "0.10.4", features = ["output-threaded"] }
nokhwa = { version = "0.10.4", features = ["output-threaded"], optional = true}

rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
Expand Down
19 changes: 9 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ use std::path::Path;
use std::process::Command;

fn main() {
#[cfg(feature = "server")]
{
let app_dir = format!("{}/app", env::var("CARGO_MANIFEST_DIR").unwrap());
let app_dir = format!("{}/app", env::var("CARGO_MANIFEST_DIR").unwrap());

Command::new("trunk")
.args(&["build --release"])
.current_dir(&Path::new(&app_dir))
.status()
.unwrap();
let status = Command::new("trunk")
.args(&["build", "--release"])
.current_dir(&Path::new(&app_dir))
.status();

println!("building {}", app_dir);
match status {
Ok(status) if status.success() => println!("Successfully built {}", app_dir),
Ok(status) => eprintln!("Failed to build {}: exit code {}", app_dir, status),
Err(err) => eprintln!("Failed to run trunk command: {}", err),
}

println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 1 addition & 1 deletion docs/RaspberryPi.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ If you have a monitor and keyboard connected to your Raspberry Pi, you can find
3. Install prerequisites:
```sh
sudo apt install git build-essential clang
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev v4l-utils libssl-dev
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev v4l-utils libssl-dev libdbus-1-dev
curl https://sh.rustup.rs -sSf | sh
cargo install --locked trunk
cargo install --locked wasm-bindgen-cli
Expand Down
2 changes: 2 additions & 0 deletions examples/bt_rfcomm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ async fn main() {
let target_address: Address = "B8:27:EB:4C:40:D5".parse().expect("invalid address");
let target_address: Address = "00:15:83:0C:BF:EB".parse().expect("invalid address");

let target_address: Address = "DC:A6:32:84:72:93".parse().expect("invalid address");

perform(target_address, CHANNEL).await.unwrap();
}
7 changes: 7 additions & 0 deletions examples/raspicam.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[cfg(feature = "webcam")]
use nokhwa::{
pixel_format::RgbFormat,
utils::{CameraFormat, CameraIndex, FrameFormat, RequestedFormat, RequestedFormatType},
Camera,
};

#[cfg(feature = "webcam")]
fn main() {
let index = CameraIndex::Index(0);
// request the absolute highest resolution CameraFormat that can be decoded to RGB.
Expand All @@ -28,3 +30,8 @@ fn main() {
println!("{}, {}", decoded.width(), decoded.height());
decoded.save("frame.jpg").unwrap();
}

#[cfg(not(feature = "webcam"))]
fn main() {
println!("Webcam feature not enabled");
}
10 changes: 8 additions & 2 deletions examples/webcam.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use ornithology_pi::{Capture, WebCam};
use ornithology_pi::Capture;

#[cfg(feature = "webcam")]
fn main() {
let mut capture = WebCam::default();
let mut capture = ornithology_pi::WebCam::default();
let frame = capture.frame().unwrap();
println!("{}, {}", frame.width(), frame.height());
frame.save("frame.jpg").unwrap();
}

#[cfg(not(feature = "webcam"))]
fn main() {
println!("Webcam feature not enabled");
}
9 changes: 7 additions & 2 deletions src/bluetooth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ pub mod rfcomm_srv;

pub const MANUFACTURER_ID: u16 = 0xf00d;

pub async fn run_bluetooth(sightings: Arc<Mutex<Vec<Sighting>>>) -> bluer::Result<()> {
let session = bluer::Session::new().await?;
pub async fn setup_session(session: &bluer::Session) -> bluer::Result<()> {
let adapter_names = session.adapter_names().await?;
let adapter_name = adapter_names.first().expect("No Bluetooth adapter present");
let adapter = session.adapter(adapter_name)?;
Expand All @@ -25,6 +24,12 @@ pub async fn run_bluetooth(sightings: Arc<Mutex<Vec<Sighting>>>) -> bluer::Resul
&adapter_name,
adapter.address().await?
);
Ok(())
}

pub async fn run_bluetooth(sightings: Arc<Mutex<Vec<Sighting>>>) -> bluer::Result<()> {
let mut session = bluer::Session::new().await?;
setup_session(&session).await?;
/*let gatt_handle = gatt_srv::run_advertise(&adapter, sightings.clone())
.await
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ pub trait Capture: Stream {
}
}

#[cfg(feature = "webcam")]
mod webcam;
#[cfg(feature = "webcam")]
pub use webcam::WebCam;
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Publicly re-exporting types for external use.
pub use self::{
capture::{Capture, WebCam},
capture::Capture,
config::Config,
mjpeg::MJpeg,
sighting::{DataSighting, Sighting},
};

#[cfg(feature = "webcam")]
pub use self::{capture::WebCam, mjpeg::MJpeg};

// Type aliases for convenience.
pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub type Result<T> = std::result::Result<T, Error>;
Expand All @@ -15,6 +17,8 @@ pub mod capture;
pub mod cli;
pub mod config;
pub mod logger;

#[cfg(feature = "webcam")]
pub mod mjpeg;
pub mod sighting;

Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use ornithology_pi::hotspot::Hotspot;
use ornithology_pi::logger::init_logger;
#[cfg(feature = "server")]
use ornithology_pi::server::server;
use ornithology_pi::{Sighting, WebCam};
use ornithology_pi::Sighting;
#[cfg(feature = "webcam")]
use ornithology_pi::WebCam;
use std::sync::{Arc, Mutex};

#[tokio::main]
Expand All @@ -25,6 +27,8 @@ async fn main() {
let sightings: Arc<Mutex<Vec<Sighting>>> = Arc::new(Mutex::new(
ornithology_pi::sighting::load_from_file("sightings/sightings.db").unwrap_or_default(),
));

#[cfg(feature = "webcam")]
let capture: Arc<Mutex<WebCam>> = Arc::new(Mutex::new(
WebCam::new(config.camera.width, config.camera.height, config.camera.fps).unwrap(),
));
Expand Down

0 comments on commit 7c1bc0e

Please sign in to comment.