hacam_lib_rs/lib.rs
1//! A Rust cross-platform userspace driver for interacting with the Huawei EnVizion 360° Camera (Huawei CV60).
2//!
3//! Tested on Windows and macOS. Should work on Linux as well.
4//! This library uses the [nusb] library.
5//! The camera itself uses a standard LibUSB driver, so it works out of the box on macOS, but you need to select the driver manually on Windows (WinUSB).
6//!
7//! [nusb]: https://github.com/kevinmehall/nusb
8//!
9//! ## Example
10//!
11//! More examples are provided in the `examples/` folder.
12//!
13//! ```no_run
14//! use hacam_lib_rs::{cam::HaCam, settings::PictureOrientation, util::CamUtil};
15//!
16//! #[tokio::main]
17//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
18//! let mut cam = HaCam::new()?;
19//!
20//! cam.initialize_comm().await?;
21//!
22//! println!("Camera info: {:#?}", cam.get_camera_info().await?);
23//!
24//! cam.power_off().await?;
25//!
26//! Ok(())
27//! }
28//! ```
29
30/// Contains definitions of camera commands and some default values.
31pub mod consts;
32
33/// Contains enums and structs for the camera settings.
34pub mod settings;
35
36/// Contains various convenience methods for interacting with the camera.
37pub mod util;
38
39/// Contains the main camera struct.
40pub mod cam;
41
42/// Crate-specific error enum.
43/// Every function interacting with the camera returns a Result enum with this error type.
44#[derive(thiserror::Error, Debug)]
45pub enum CamError {
46 #[error("Error while transfering USB data")]
47 UsbTransfer(#[from] nusb::transfer::TransferError),
48
49 #[error("Internal I/O error occured")]
50 Io(#[from] std::io::Error),
51
52 #[error("Timeout occured during I/O operation")]
53 Timeout(#[from] tokio::time::error::Elapsed),
54
55 #[error("Invalid response format")]
56 InvalidFormat,
57
58 #[error("Invalid response length (expected: {expected}, received: {received})")]
59 InvalidLength { expected: usize, received: usize },
60
61 #[error("Unable to initialize connection, attempts: {tries}, status code: {status_code}")]
62 ConnInit { tries: u32, status_code: u32 },
63
64 #[error("Unable to send command, attempts: {tries}, status code: {status_code}")]
65 SendCommand { tries: u32, status_code: u32 },
66
67 #[error("Error while sending the keepalive command, status code: {status_code}")]
68 Keepalive { status_code: u32 },
69
70 #[error("Error while writing data")]
71 Write,
72
73 #[error("Couldn't find a device with given VID/PID: {vid:#06X}:{pid:#06X}")]
74 NoDeviceFound { vid: u16, pid: u16 },
75}
76
77type CamResult<T> = Result<T, CamError>;