bnr_xfs/status/
shutter.rs

1use std::fmt;
2
3use super::HardwareStatus;
4
5pub const SHT_CLOSED: u32 = 6198;
6pub const SHT_OPEN: u32 = 6199;
7pub const SHT_NOT_SUPPORTED: u32 = 6201;
8pub const SHT_UNKNOWN: u32 = 6202;
9
10/// Represents shutter status values.
11#[repr(u32)]
12#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
13pub enum ShutterStatus {
14    /// Indicates the shutter is closed
15    Closed = SHT_CLOSED,
16    /// Indicates the shutter status is not supported
17    NotSupported = SHT_NOT_SUPPORTED,
18    /// Indicates the shutter is open
19    Open = SHT_OPEN,
20    /// Indicates the shutter status is unknown
21    #[default]
22    Unknown = SHT_UNKNOWN,
23}
24
25impl ShutterStatus {
26    /// Creates a new [ShutterStatus].
27    pub const fn new() -> Self {
28        Self::Unknown
29    }
30
31    /// Creates a new [ShutterStatus] from the provided parameter.
32    pub const fn create(val: u32) -> Self {
33        match val {
34            SHT_CLOSED => Self::Closed,
35            SHT_NOT_SUPPORTED => Self::NotSupported,
36            SHT_OPEN => Self::Open,
37            SHT_UNKNOWN => Self::Unknown,
38            _ => Self::Unknown,
39        }
40    }
41}
42
43impl From<ShutterStatus> for HardwareStatus {
44    fn from(val: ShutterStatus) -> Self {
45        match val {
46            ShutterStatus::Closed | ShutterStatus::Open => Self::Notification,
47            ShutterStatus::NotSupported => Self::Missing,
48            ShutterStatus::Unknown => Self::Warning,
49        }
50    }
51}
52
53impl From<ShutterStatus> for &'static str {
54    fn from(val: ShutterStatus) -> Self {
55        match val {
56            ShutterStatus::Closed => "closed",
57            ShutterStatus::Open => "open",
58            ShutterStatus::NotSupported => "not supported",
59            ShutterStatus::Unknown => "unknown",
60        }
61    }
62}
63
64impl From<&ShutterStatus> for &'static str {
65    fn from(val: &ShutterStatus) -> Self {
66        (*val).into()
67    }
68}
69
70impl fmt::Display for ShutterStatus {
71    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72        write!(f, r#""{}""#, <&str>::from(self))
73    }
74}
75
76impl_xfs_enum!(ShutterStatus, "shutterStatus");