use thiserror::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CameraControl {
Zoom,
Focus,
Exposure,
Brightness,
Contrast,
Saturation,
Sharpness,
WhiteBalance,
Tint,
}
impl CameraControl {
pub const ALL: [Self; 9] = [
Self::Zoom,
Self::Focus,
Self::Exposure,
Self::Brightness,
Self::Contrast,
Self::Saturation,
Self::Sharpness,
Self::WhiteBalance,
Self::Tint,
];
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Zoom => "zoom",
Self::Focus => "focus",
Self::Exposure => "exposure",
Self::Brightness => "brightness",
Self::Contrast => "contrast",
Self::Saturation => "saturation",
Self::Sharpness => "sharpness",
Self::WhiteBalance => "white_balance",
Self::Tint => "tint",
}
}
#[must_use]
pub fn auto_toggle(self) -> Option<AutoToggle> {
match self {
Self::Focus => Some(AutoToggle::Focus),
Self::Exposure => Some(AutoToggle::Exposure),
Self::WhiteBalance => Some(AutoToggle::WhiteBalance),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AutoToggle {
Focus,
Exposure,
WhiteBalance,
}
impl AutoToggle {
pub const ALL: [Self; 3] = [Self::Focus, Self::Exposure, Self::WhiteBalance];
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Focus => "focus_auto",
Self::Exposure => "exposure_auto",
Self::WhiteBalance => "white_balance_auto",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AutoState {
pub current: bool,
pub default: bool,
}
#[derive(Debug, Clone, Default)]
pub struct CameraState {
pub controls: Vec<(CameraControl, ControlRange)>,
pub autos: Vec<(AutoToggle, AutoState)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ControlRange {
pub min: i32,
pub max: i32,
pub default: i32,
pub current: i32,
}
#[derive(Debug, Clone, Error)]
pub enum ControlError {
#[error("no matching UVC device")]
NotFound,
#[error("camera could not be uniquely identified")]
Ambiguous,
#[error("camera does not support that control")]
Unsupported,
#[error("platform error: {0}")]
Io(String),
}