1use core::fmt;
7
8use crate::wire::{BayStatus, BayUid, FirmwareType, MxrSignalType};
9
10#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub enum DeviceStatus {
13 #[default]
15 Online,
16 Offline,
18 Rebooting,
20 Booting,
22 Inactive,
24}
25
26impl fmt::Display for DeviceStatus {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.write_str(match self {
29 Self::Online => "Online",
30 Self::Offline => "Offline",
31 Self::Rebooting => "Rebooting",
32 Self::Booting => "Booting",
33 Self::Inactive => "Inactive",
34 })
35 }
36}
37
38#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
40pub enum PowerStatus {
41 #[default]
43 Unknown,
44 On,
46 Off,
48}
49
50impl fmt::Display for PowerStatus {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 f.write_str(match self {
53 Self::On => "on",
54 Self::Off => "off",
55 Self::Unknown => "unknown",
56 })
57 }
58}
59
60#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
62pub enum ConnectStatus {
63 #[default]
65 Unknown,
66 Connected,
68 Disconnected,
70}
71
72impl fmt::Display for ConnectStatus {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 f.write_str(match self {
75 Self::Connected => "connected",
76 Self::Disconnected => "disconnected",
77 Self::Unknown => "unknown",
78 })
79 }
80}
81
82#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
84pub enum HiddenStatus {
85 #[default]
87 Unknown,
88 Hidden,
90 Visible,
92}
93
94impl fmt::Display for HiddenStatus {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 f.write_str(match self {
97 Self::Hidden => "hidden",
98 Self::Visible => "visible",
99 Self::Unknown => "unknown",
100 })
101 }
102}
103
104#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
106pub struct MuteStatus(u8);
107
108impl MuteStatus {
109 pub const fn from_wire(value: u8) -> Self {
111 Self(value)
112 }
113
114 pub const fn to_wire(self) -> u8 {
116 self.0
117 }
118
119 pub const fn left(self) -> bool {
121 self.0 & (1 << 0) != 0
122 }
123
124 pub const fn right(self) -> bool {
126 self.0 & (1 << 1) != 0
127 }
128
129 pub const fn muted(self) -> bool {
131 self.0 != 0
132 }
133}
134
135#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
140pub struct VolumeMuteStatus {
141 pub volume_left: Option<u8>,
143 pub volume_right: Option<u8>,
145 pub muted_left: Option<bool>,
147 pub muted_right: Option<bool>,
149}
150
151impl VolumeMuteStatus {
152 pub fn volume(&self) -> u8 {
155 match (self.volume_left, self.volume_right) {
156 (Some(l), Some(r)) => ((u16::from(l) + u16::from(r)) / 2) as u8,
157 (Some(l), None) => l,
158 (None, Some(r)) => r,
159 (None, None) => 0,
160 }
161 }
162
163 pub fn muted(&self) -> Option<bool> {
165 match (self.muted_left, self.muted_right) {
166 (None, None) => None,
167 (l, r) => Some(l.unwrap_or(false) || r.unwrap_or(false)),
168 }
169 }
170
171 pub(crate) fn wire(&self) -> [u8; 3] {
174 [
175 self.volume_left.unwrap_or_else(|| self.volume()),
176 self.volume_right.unwrap_or_else(|| self.volume()),
177 self.muted_value(),
178 ]
179 }
180
181 fn muted_value(&self) -> u8 {
183 if self.muted() != Some(true) {
184 return 0;
185 }
186 match (
187 self.muted_left.unwrap_or(false),
188 self.muted_right.unwrap_or(false),
189 ) {
190 (true, true) => 3,
191 (true, false) => 1,
192 _ => 2,
193 }
194 }
195}
196
197#[derive(Clone, Copy, Debug, Default, PartialEq)]
200pub struct BaySignalDetails {
201 pub frame_rate: f64,
203 pub tmds_clock: u32,
205 pub status: BayStatus,
207 pub scaling: MxrSignalType,
209 pub clock_rate: u32,
211}
212
213#[derive(Clone, Debug, Default, PartialEq, Eq)]
215pub struct FirmwareVersion {
216 pub firmware_type: FirmwareType,
218 pub timestamp: u32,
220 pub version: String,
222 pub hash: u32,
224}
225
226impl fmt::Display for FirmwareVersion {
227 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
228 write!(
229 f,
230 "firmware {} version {} hash {}",
231 self.firmware_type, self.version, self.hash
232 )
233 }
234}
235
236#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
240pub struct BayMirrorStatus {
241 pub target: Option<BayUid>,
243}
244
245impl BayMirrorStatus {
246 pub const fn is_mirroring(&self) -> bool {
248 self.target.is_some()
249 }
250}
251
252#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
254pub struct TopologyEntry {
255 pub uid: crate::wire::DeviceUid,
257 pub mask: u32,
259}
260
261#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
263pub enum ArcStatus {
264 #[default]
266 Inactive,
267 Hdmi,
269 Optical,
271 Analog,
273}
274
275impl fmt::Display for ArcStatus {
276 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
277 f.write_str(match self {
278 Self::Inactive => "Inactive",
279 Self::Hdmi => "HDMI",
280 Self::Optical => "optical",
281 Self::Analog => "analog",
282 })
283 }
284}