linux-rust: add skeleton for other devices

This commit is contained in:
Kavish Devar
2025-11-07 01:57:14 +05:30
parent 934df2419a
commit a2cda688d4
20 changed files with 1449 additions and 338 deletions

View 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,
}
}
}