#[allow(unused_imports)]
use crate::PropertyType;
use documented::{Documented, DocumentedVariants};
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq)]
pub struct CustomName([u8; 16]);
impl CustomName {
fn new(name: &str) -> Self {
let mut bytes = [0; 16];
let len = name.len().min(16);
bytes[..len].copy_from_slice(&name.as_bytes()[..len]);
Self(bytes)
}
pub fn as_str(&self) -> &str {
std::str::from_utf8(&self.0)
.unwrap() .trim_end_matches(char::from(0))
}
}
impl<'a, T: Into<&'a str>> From<T> for CustomName {
fn from(name: T) -> Self {
Self::new(name.into())
}
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum DeviceCtrl {
ScanType,
VendorName,
ModelName,
FamilyName,
MfgInfo,
Version,
FwVersion,
SerialNumber,
Id,
UserId,
TlType,
TemperatureSelector,
Temperature,
Reset,
CoolerTemp,
CoolerPower,
CoolerEnable,
HighSpeedMode,
FanToggle,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum SensorCtrl {
PixelWidth,
PixelHeight,
Name,
ShutterMode,
WidthMax,
HeightMax,
BinningSelector,
BinningBoth,
BinningHorzlMode,
BinningVertMode,
BinningHorz,
BinningVert,
DecimationHorzMode,
DecimationHorz,
DecimationVertMode,
DecimationVert,
ReverseX,
ReverseY,
PixelFormat,
TestPattern,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum TriggerCtrl {
Sel,
Mod,
Src,
Overlap,
Delay,
Divider,
Multiplier,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum ExposureCtrl {
Mode,
ExposureTime,
Auto,
AutoMaxExposure,
AutoTargetBrightness,
AutoMaxGain,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum FrameTimeCtrl {
Mode,
FrameTime,
Auto,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum AnalogCtrl {
GainSelector,
Gain,
GainAuto,
GainAutoBalance,
BlackLevelSel,
BlackLevel,
BlackLevelAuto,
BlackLevelAutoBalance,
WhiteClipSel,
WhiteClip,
BalanceRatioSel,
BalanceRatio,
BalanceWhiteAuto,
Gamma,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum DigitalIoCtrl {
LineSel,
LineMod,
LineInvert,
LineStat,
LineSrc,
UserOutSel,
UserOutVal,
Custom(CustomName),
}
#[derive(
Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Documented, DocumentedVariants,
)]
#[non_exhaustive]
pub enum GenCamCtrl {
Device(DeviceCtrl),
Sensor(SensorCtrl),
Trigger(TriggerCtrl),
Exposure(ExposureCtrl),
FrameTime(FrameTimeCtrl),
Analog(AnalogCtrl),
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);
pub trait ToolTip {
fn tooltip(&self) -> &'static str;
}
macro_rules! impl_tooltip {
($ctrl:ident) => {
impl ToolTip for $ctrl {
fn tooltip(&self) -> &'static str {
self.get_variant_docs().unwrap()
}
}
};
}
impl_tooltip!(DeviceCtrl);
impl_tooltip!(SensorCtrl);
impl_tooltip!(TriggerCtrl);
impl_tooltip!(ExposureCtrl);
impl_tooltip!(FrameTimeCtrl);
impl_tooltip!(AnalogCtrl);
impl_tooltip!(DigitalIoCtrl);
impl_tooltip!(GenCamCtrl);