use crate::ddc_trait::DdcControl;
use crate::ddc_types::VcpCode;
use crate::error::DdcError;
use std::collections::HashMap;
use std::sync::Mutex;
pub struct DebugBackend {
vcp_values: Mutex<HashMap<u8, u32>>,
}
impl Default for DebugBackend {
fn default() -> Self {
Self::new()
}
}
impl DebugBackend {
pub fn new() -> Self {
let mut initial_values = HashMap::new();
initial_values.insert(VcpCode::Brightness as u8, 50);
initial_values.insert(VcpCode::Contrast as u8, 80);
initial_values.insert(VcpCode::PowerMode as u8, 0x01);
Self {
vcp_values: Mutex::new(initial_values),
}
}
}
impl DdcControl for DebugBackend {
fn get_vcp_feature(&self, code: u8) -> Result<(u32, u32), DdcError> {
let values = self
.vcp_values
.lock()
.map_err(|_| DdcError::CommunicationFailed {
reason: "Mutex lock poisoned in debug backend (get_vcp_feature)".to_string(),
})?;
let current = values.get(&code).cloned().unwrap_or(0);
println!("[DEBUG BUS] Read Code {:#04x}: Value {}", code, current);
Ok((current, 100))
}
fn set_vcp_feature(&self, code: u8, value: u32) -> Result<(), DdcError> {
let mut values = self
.vcp_values
.lock()
.map_err(|_| DdcError::CommunicationFailed {
reason: "Mutex lock poisoned in debug backend (set_vcp_feature)".to_string(),
})?;
println!("[DEBUG BUS] Write Code {:#04x}: Set to {}", code, value);
values.insert(code, value);
Ok(())
}
}