1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#[allow(unused_imports)]
use crate::PropertyType;
use serde::{Deserialize, Serialize};

/// Describes device-specific control options.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
pub enum DeviceCtrl {
    /// Query line or area scan type, usually [`PropertyType::EnumStr`]
    ScanType,
    /// Query device vendor ([`PropertyType::EnumStr`])
    VendorName,
    /// Query device model ([`PropertyType::EnumStr`])
    ModelName,
    /// Query device family ([`PropertyType::EnumStr`])
    FamilyName,
    /// Query manufacturer information ([`PropertyType::EnumStr`])
    MfgInfo,
    /// Query version ([`PropertyType::EnumStr`])
    Version,
    /// Query firmware version ([`PropertyType::EnumStr`])
    FwVersion,
    /// Query serial number ([`PropertyType::EnumStr`])
    SerialNumber,
    /// Query unique ID ([`PropertyType::EnumStr`])
    Id,
    /// Query user-set ID ([`PropertyType::EnumStr`])
    UserId,
    /// Query transport layer type ([`PropertyType::EnumStr`])
    TlType,
    /// Select device temperature source ([`PropertyType::EnumStr`])
    TemperatureSelector,
    /// Query selected temperature ([`PropertyType::Float`])
    Temperature,
}

/// Describes sensor-specific control options.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
pub enum SensorCtrl {
    /// Query pixel width ([`PropertyType::Float`])
    PixelWidth,
    /// Query pixel height ([`PropertyType::Float`])
    PixelHeight,
    /// Query sensor name ([`PropertyType::EnumStr`])
    Name,
    /// Query sensor shutter mode ([`PropertyType::EnumStr`])
    ShutterMode,
    /// Query sensor max width ([`PropertyType::Unsigned`])
    WidthMax,
    /// Query sensor max height ([`PropertyType::Unsigned`])
    HeightMax,
    /// Query the binning method ([`PropertyType::EnumStr`])
    BinningSelector,
    /// Query the horizontal binning mode ([`PropertyType::EnumStr`])
    BinningHorzlMode,
    /// Query the vertical binning mode ([`PropertyType::EnumStr`])
    BinningVertMode,
    /// Query the horizontal binning factor ([`PropertyType::Unsigned`] or [`PropertyType::EnumUnsigned`])
    BinningHorz,
    /// Query the vertical binning factor ([`PropertyType::Unsigned`] or [`PropertyType::EnumUnsigned`])
    BinningVert,
    /// Query the horizontal decimation method ([`PropertyType::EnumStr`])
    DecimationHorzMode,
    /// Query the horizontal decimation mode ([`PropertyType::EnumStr`])
    DecimationHorz,
    /// Query the vertical decimation method ([`PropertyType::EnumStr`])
    DecimationVertMode,
    /// Query the vertical decimation mode ([`PropertyType::EnumStr`])
    DecimationVert,
    /// Reverse the image about the X axis ([`PropertyType::Bool`])
    ReverseX,
    /// Reverse the image about the Y axis ([`PropertyType::Bool`])
    ReverseY,
    /// Query the pixel format ([`PropertyType::EnumStr`])
    PixelFormat,
    /// Apply a test pattern to the image ([`PropertyType::EnumStr`])
    TestPattern,
}

/// Describes trigger-specific control options.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
pub enum TriggerCtrl {
    /// Select trigger line ([`PropertyType::EnumStr`])
    Sel,
    /// Get or set trigger mode on the selected trigger line ([`PropertyType::EnumStr`])
    Mod,
    /// Get or set trigger source on the selected trigger line ([`PropertyType::EnumStr`])
    Src,
    /// Get or set the type trigger overlap permitted with the previous frame or line ([`PropertyType::EnumStr`])
    Overlap,
    /// Specifies the delay in microseconds (us) to apply after the trigger reception before activating it ([`PropertyType::Float`])
    Delay,
    /// Specifies a division factor for the incoming trigger pulses ([`PropertyType::Float`])
    Divider,
    /// Specifies a multiplication factor for the incoming trigger pulses ([`PropertyType::Float`])
    Multiplier,
}

/// Describes exposure control options.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
pub enum ExposureCtrl {
    /// Select exposure mode ([`PropertyType::EnumStr`])
    Mode,
    /// Select exposure time ([`PropertyType::Float`])
    ExposureTime,
    /// Select exposure auto mode ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    Auto,
    /// Select exposure auto target brightness ([`PropertyType::Float`])
    AutoTargetBrightness,
}

/// Describes frame rate control options.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
pub enum FrameTimeCtrl {
    /// Select frame time mode ([`PropertyType::EnumStr`])
    Mode,
    /// Select frame time ([`PropertyType::Duration`])
    FrameTime,
    /// Select frame time auto mode ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    Auto,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
/// Describes analog control options.
pub enum AnalogCtrl {
    /// Select which gain to control ([`PropertyType::EnumStr`])
    GainSelector,
    /// Select gain value ([`PropertyType::Float`])
    Gain,
    /// Select gain auto mode ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    GainAuto,
    /// Select gain auto balance ([`PropertyType::Float`])
    GainAutoBalance,
    /// Select which black level to control ([`PropertyType::EnumStr`])
    BlackLevelSel,
    /// Select black level value ([`PropertyType::Float`])
    BlackLevel,
    /// Select black level auto mode ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    BlackLevelAuto,
    /// Select black level auto balance ([`PropertyType::Float`])
    BlackLevelAutoBalance,
    /// Select which white clip to control ([`PropertyType::EnumStr`])
    WhiteClipSel,
    /// Select white clip value ([`PropertyType::Float`])
    WhiteClip,
    /// Select white balance ratio mode ([`PropertyType::EnumStr`])
    BalanceRatioSel,
    /// Configure white balance ratio value ([`PropertyType::Float`])
    BalanceRatio,
    /// Configure white balance ratio auto mode ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    BalanceWhiteAuto,
    /// Configure gamma value ([`PropertyType::Float`])
    Gamma,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
/// Describes digital I/O control options.
pub enum DigitalIoCtrl {
    /// Select which line to control ([`PropertyType::EnumStr`])
    LineSel,
    /// Select the line mode ([`PropertyType::EnumStr`])
    LineMod,
    /// Line I/O inversion ([`PropertyType::Bool`] or [`PropertyType::EnumStr`])
    LineInvert,
    /// Query line status ([`PropertyType::EnumStr`])
    LineStat,
    /// Configure the line signal source ([`PropertyType::EnumStr`])
    LineSrc,
    /// Configure as user output selector ([`PropertyType::EnumStr`] or [`PropertyType::Bool`])
    UserOutSel,
    /// Configure as user output value ([`PropertyType::Float`] or [`PropertyType::Bool`])
    UserOutVal,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
#[non_exhaustive]
/// Describes the general camera control zones.
pub enum GenCamCtrl {
    /// Device-specific control options.
    Device(DeviceCtrl),
    /// Sensor-specific control options.
    Sensor(SensorCtrl),
    /// Trigger-specific control options.
    Trigger(TriggerCtrl),
    /// Exposure-specific control options.
    Exposure(ExposureCtrl),
    /// Frame rate-specific control options.
    FrameTime(FrameTimeCtrl),
    /// Analog-specific control options.
    Analog(AnalogCtrl),
    /// Digital I/O-specific control options.
    DigitalIo(DigitalIoCtrl),
}

macro_rules! impl_from_ctrl {
    ($ctrl:ident, $variant:ident) => {
        impl From<$ctrl> for GenCamCtrl {
            fn from(ctrl: $ctrl) -> Self {
                GenCamCtrl::$variant(ctrl)
            }
        }
    };
}

impl_from_ctrl!(DeviceCtrl, Device);
impl_from_ctrl!(SensorCtrl, Sensor);
impl_from_ctrl!(TriggerCtrl, Trigger);
impl_from_ctrl!(ExposureCtrl, Exposure);
impl_from_ctrl!(FrameTimeCtrl, FrameTime);
impl_from_ctrl!(AnalogCtrl, Analog);
impl_from_ctrl!(DigitalIoCtrl, DigitalIo);