1use crate::builder::CameraConfig;
2use crate::error::Result;
3use crate::frame::Frame;
4use async_trait::async_trait;
5
6#[derive(Debug, Clone, PartialEq)]
10pub struct DeviceInfo {
11 pub name: String,
13
14 pub id: String,
17
18 pub backend: String,
20
21 pub bus_info: Option<String>,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub struct TriggerConfig {
29 pub mode: TriggerMode,
31
32 pub source: TriggerSource,
34
35 pub polarity: TriggerPolarity,
37
38 pub delay_us: u32,
40}
41
42impl Default for TriggerConfig {
43 fn default() -> Self {
44 Self {
45 mode: TriggerMode::Off,
46 source: TriggerSource::Software,
47 polarity: TriggerPolarity::RisingEdge,
48 delay_us: 0,
49 }
50 }
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum TriggerMode {
56 Off,
58 Standard,
60 Bulb,
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum TriggerSource {
67 Software,
69 Line0,
71 Line1,
73 Line2,
75 Line3,
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq)]
81pub enum TriggerPolarity {
82 RisingEdge,
84 FallingEdge,
86 HighLevel,
88 LowLevel,
90}
91
92pub trait Driver: Send + Sync {
96 fn list_devices(&self) -> Result<Vec<DeviceInfo>>;
98
99 fn open(&self, id: &str, config: CameraConfig) -> Result<(Box<dyn Stream>, DeviceControls)>;
102}
103
104#[async_trait]
107pub trait Stream: Send {
108 async fn start(&mut self) -> Result<()>;
110
111 async fn stop(&mut self) -> Result<()>;
113
114 async fn next_frame(&mut self) -> Result<Frame<'_>>;
118
119 #[cfg(feature = "simulation")]
121 async fn inject_frame(&mut self, frame: Frame<'_>) -> Result<()>;
122}
123
124#[allow(missing_debug_implementations)]
126pub struct DeviceControls {
127 pub sensor: Box<dyn SensorControl>, pub lens: Box<dyn LensControl>, pub system: Box<dyn SystemControl>, }
131
132pub trait SensorControl: Send + Sync {
134 fn set_exposure(&self, value_us: u32) -> Result<()>;
135 fn get_exposure(&self) -> Result<u32>;
136 }
138
139pub trait LensControl: Send + Sync {
141 fn set_zoom(&self, zoom: u32) -> Result<()>;
142 fn set_focus(&self, focus: u32) -> Result<()>;
143}
144
145pub trait SystemControl: Send + Sync {
147 unsafe fn force_reset(&self) -> Result<()>;
151
152 fn set_trigger(&self, config: TriggerConfig) -> Result<()>;
154
155 #[cfg(feature = "serialize")]
158 fn export_state(&self) -> Result<serde_json::Value>;
159}
160
161#[async_trait]
163impl<S: Stream + ?Sized + Send> Stream for Box<S> {
164 async fn start(&mut self) -> Result<()> {
165 (**self).start().await
166 }
167
168 async fn stop(&mut self) -> Result<()> {
169 (**self).stop().await
170 }
171
172 async fn next_frame(&mut self) -> Result<Frame<'_>> {
173 (**self).next_frame().await
174 }
175
176 #[cfg(feature = "simulation")]
177 async fn inject_frame(&mut self, frame: Frame<'_>) -> Result<()> {
178 (**self).inject_frame(frame).await
179 }
180}