#[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)]
pub enum ControlError {
NotFound,
Ambiguous,
Unsupported,
Io(String),
}
impl std::fmt::Display for ControlError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound => write!(f, "no matching UVC device"),
Self::Ambiguous => write!(f, "camera could not be uniquely identified"),
Self::Unsupported => write!(f, "camera does not support that control"),
Self::Io(s) => write!(f, "platform error: {s}"),
}
}
}
impl std::error::Error for ControlError {}