use core::fmt;
use crate::wire::{BayStatus, BayUid, FirmwareType, MxrSignalType};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DeviceStatus {
#[default]
Online,
Offline,
Rebooting,
Booting,
Inactive,
}
impl fmt::Display for DeviceStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Online => "Online",
Self::Offline => "Offline",
Self::Rebooting => "Rebooting",
Self::Booting => "Booting",
Self::Inactive => "Inactive",
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PowerStatus {
#[default]
Unknown,
On,
Off,
}
impl fmt::Display for PowerStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::On => "on",
Self::Off => "off",
Self::Unknown => "unknown",
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ConnectStatus {
#[default]
Unknown,
Connected,
Disconnected,
}
impl fmt::Display for ConnectStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Connected => "connected",
Self::Disconnected => "disconnected",
Self::Unknown => "unknown",
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum HiddenStatus {
#[default]
Unknown,
Hidden,
Visible,
}
impl fmt::Display for HiddenStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Hidden => "hidden",
Self::Visible => "visible",
Self::Unknown => "unknown",
})
}
}
pub const VOLUME_UNCHANGED: u8 = 0xFF;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MuteStatus(u8);
impl MuteStatus {
pub const fn from_wire(value: u8) -> Self {
Self(value)
}
pub const fn to_wire(self) -> u8 {
self.0
}
pub const fn left(self) -> bool {
self.0 & (1 << 0) != 0
}
pub const fn right(self) -> bool {
self.0 & (1 << 1) != 0
}
pub const fn muted(self) -> bool {
self.0 != 0
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct VolumeMuteStatus {
pub volume_left: Option<u8>,
pub volume_right: Option<u8>,
pub muted_left: Option<bool>,
pub muted_right: Option<bool>,
}
impl VolumeMuteStatus {
pub fn volume(&self) -> u8 {
match (self.volume_left, self.volume_right) {
(Some(l), Some(r)) => ((u16::from(l) + u16::from(r)) / 2) as u8,
(Some(l), None) => l,
(None, Some(r)) => r,
(None, None) => 0,
}
}
pub fn muted(&self) -> Option<bool> {
match (self.muted_left, self.muted_right) {
(None, None) => None,
(l, r) => Some(l.unwrap_or(false) || r.unwrap_or(false)),
}
}
pub(crate) fn wire(&self) -> [u8; 3] {
[
self.volume_left.unwrap_or_else(|| self.volume()),
self.volume_right.unwrap_or_else(|| self.volume()),
self.muted_value(),
]
}
fn muted_value(&self) -> u8 {
match self.muted() {
None => VOLUME_UNCHANGED,
Some(false) => 0,
Some(true) => match (
self.muted_left.unwrap_or(false),
self.muted_right.unwrap_or(false),
) {
(true, true) => 3,
(true, false) => 1,
_ => 2,
},
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct BaySignalDetails {
pub frame_rate: f64,
pub tmds_clock: u32,
pub status: BayStatus,
pub scaling: MxrSignalType,
pub clock_rate: u32,
pub audio: Option<BayAudioDetails>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct BayAudioDetails {
pub format: u8,
pub channels: u8,
pub sample_rate: u32,
pub coding: Option<u8>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct FirmwareVersion {
pub firmware_type: FirmwareType,
pub timestamp: u32,
pub version: String,
pub hash: u32,
}
impl fmt::Display for FirmwareVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"firmware {} version {} hash {}",
self.firmware_type, self.version, self.hash
)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct BayMirrorStatus {
pub target: Option<BayUid>,
}
impl BayMirrorStatus {
pub const fn is_mirroring(&self) -> bool {
self.target.is_some()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct TopologyEntry {
pub uid: crate::wire::DeviceUid,
pub mask: u32,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ArcStatus {
#[default]
Inactive,
Hdmi,
Optical,
Analog,
}
impl fmt::Display for ArcStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Inactive => "Inactive",
Self::Hdmi => "HDMI",
Self::Optical => "optical",
Self::Analog => "analog",
})
}
}