openlogi_camera/
controls.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum CameraControl {
7 Zoom,
8 Focus,
9 Exposure,
10 Brightness,
11 Contrast,
12 Saturation,
13 Sharpness,
14 WhiteBalance,
15 Tint,
16}
17
18impl CameraControl {
19 pub const ALL: [Self; 9] = [
21 Self::Zoom,
22 Self::Focus,
23 Self::Exposure,
24 Self::Brightness,
25 Self::Contrast,
26 Self::Saturation,
27 Self::Sharpness,
28 Self::WhiteBalance,
29 Self::Tint,
30 ];
31
32 #[must_use]
34 pub fn name(self) -> &'static str {
35 match self {
36 Self::Zoom => "zoom",
37 Self::Focus => "focus",
38 Self::Exposure => "exposure",
39 Self::Brightness => "brightness",
40 Self::Contrast => "contrast",
41 Self::Saturation => "saturation",
42 Self::Sharpness => "sharpness",
43 Self::WhiteBalance => "white_balance",
44 Self::Tint => "tint",
45 }
46 }
47
48 #[must_use]
50 pub fn auto_toggle(self) -> Option<AutoToggle> {
51 match self {
52 Self::Focus => Some(AutoToggle::Focus),
53 Self::Exposure => Some(AutoToggle::Exposure),
54 Self::WhiteBalance => Some(AutoToggle::WhiteBalance),
55 _ => None,
56 }
57 }
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub enum AutoToggle {
64 Focus,
65 Exposure,
66 WhiteBalance,
67}
68
69impl AutoToggle {
70 pub const ALL: [Self; 3] = [Self::Focus, Self::Exposure, Self::WhiteBalance];
72
73 #[must_use]
75 pub fn name(self) -> &'static str {
76 match self {
77 Self::Focus => "focus_auto",
78 Self::Exposure => "exposure_auto",
79 Self::WhiteBalance => "white_balance_auto",
80 }
81 }
82}
83
84#[derive(Debug, Clone, Copy, PartialEq, Eq)]
86pub struct AutoState {
87 pub current: bool,
88 pub default: bool,
89}
90
91#[derive(Debug, Clone, Default)]
94pub struct CameraState {
95 pub controls: Vec<(CameraControl, ControlRange)>,
96 pub autos: Vec<(AutoToggle, AutoState)>,
97}
98
99#[derive(Debug, Clone, Copy, PartialEq, Eq)]
101pub struct ControlRange {
102 pub min: i32,
103 pub max: i32,
104 pub default: i32,
105 pub current: i32,
106}
107
108#[derive(Debug, Clone)]
110pub enum ControlError {
111 NotFound,
113 Ambiguous,
117 Unsupported,
120 Io(String),
122}
123
124impl std::fmt::Display for ControlError {
125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126 match self {
127 Self::NotFound => write!(f, "no matching UVC device"),
128 Self::Ambiguous => write!(f, "camera could not be uniquely identified"),
129 Self::Unsupported => write!(f, "camera does not support that control"),
130 Self::Io(s) => write!(f, "platform error: {s}"),
131 }
132 }
133}
134
135impl std::error::Error for ControlError {}