mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-29 09:33:04 +00:00
linux-rust: add skeleton for other devices
This commit is contained in:
107
linux-rust/src/devices/enums.rs
Normal file
107
linux-rust/src/devices/enums.rs
Normal file
@@ -0,0 +1,107 @@
|
||||
use std::fmt::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::devices::airpods::AirPodsInformation;
|
||||
use crate::devices::nothing::NothingInformation;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(PartialEq)]
|
||||
pub enum DeviceType {
|
||||
AirPods,
|
||||
Nothing
|
||||
}
|
||||
|
||||
impl Display for DeviceType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
DeviceType::AirPods => write!(f, "AirPods"),
|
||||
DeviceType::Nothing => write!(f, "Nothing"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", content = "data")]
|
||||
pub enum DeviceInformation {
|
||||
AirPods(AirPodsInformation),
|
||||
Nothing(NothingInformation)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DeviceData {
|
||||
pub name: String,
|
||||
pub type_: DeviceType,
|
||||
pub information: Option<DeviceInformation>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum DeviceState {
|
||||
AirPods(AirPodsState),
|
||||
Nothing(NothingState),
|
||||
}
|
||||
|
||||
impl Display for DeviceState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
DeviceState::AirPods(_) => write!(f, "AirPods State"),
|
||||
DeviceState::Nothing(_) => write!(f, "Nothing State"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AirPodsState {
|
||||
pub conversation_awareness_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NothingState {
|
||||
pub anc_mode: NothingAncMode,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum NothingAncMode {
|
||||
Off,
|
||||
LowNoiseCancellation,
|
||||
MidNoiseCancellation,
|
||||
HighNoiseCancellation,
|
||||
AdaptiveNoiseCancellation,
|
||||
Transparency
|
||||
}
|
||||
|
||||
impl Display for NothingAncMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
NothingAncMode::Off => write!(f, "Off"),
|
||||
NothingAncMode::LowNoiseCancellation => write!(f, "Low Noise Cancellation"),
|
||||
NothingAncMode::MidNoiseCancellation => write!(f, "Mid Noise Cancellation"),
|
||||
NothingAncMode::HighNoiseCancellation => write!(f, "High Noise Cancellation"),
|
||||
NothingAncMode::AdaptiveNoiseCancellation => write!(f, "Adaptive Noise Cancellation"),
|
||||
NothingAncMode::Transparency => write!(f, "Transparency"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl NothingAncMode {
|
||||
pub fn from_byte(value: u8) -> Self {
|
||||
match value {
|
||||
0x03 => NothingAncMode::LowNoiseCancellation,
|
||||
0x02 => NothingAncMode::MidNoiseCancellation,
|
||||
0x01 => NothingAncMode::HighNoiseCancellation,
|
||||
0x04 => NothingAncMode::AdaptiveNoiseCancellation,
|
||||
0x07 => NothingAncMode::Transparency,
|
||||
0x05 => NothingAncMode::Off,
|
||||
_ => NothingAncMode::Off,
|
||||
}
|
||||
}
|
||||
pub fn to_byte(&self) -> u8 {
|
||||
match self {
|
||||
NothingAncMode::LowNoiseCancellation => 0x03,
|
||||
NothingAncMode::MidNoiseCancellation => 0x02,
|
||||
NothingAncMode::HighNoiseCancellation => 0x01,
|
||||
NothingAncMode::AdaptiveNoiseCancellation => 0x04,
|
||||
NothingAncMode::Transparency => 0x07,
|
||||
NothingAncMode::Off => 0x05,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user