feat: 支持读取显示器配置。

This commit is contained in:
2023-05-07 09:56:00 +08:00
parent 800c0d3fc4
commit 3a430716d6
4 changed files with 82 additions and 12 deletions

View File

@ -0,0 +1,67 @@
use std::{sync::Arc, time::SystemTime};
use ddc_hi::{Ddc, Display};
use tokio::sync::RwLock;
use super::DisplayState;
pub struct DisplayHandler {
pub state: Arc<RwLock<DisplayState>>,
pub controller: Arc<RwLock<Display>>,
}
impl DisplayHandler {
pub async fn fetch_state(&self) {
let mut controller = self.controller.write().await;
let mut temp_state = DisplayState::default();
match controller.handle.get_vcp_feature(0x10) {
Ok(value) => {
temp_state.max_brightness = value.maximum();
temp_state.min_brightness = 0;
temp_state.brightness = value.value();
}
Err(_) => {}
};
match controller.handle.get_vcp_feature(0x12) {
Ok(value) => {
temp_state.max_contrast = value.maximum();
temp_state.min_contrast = 0;
temp_state.contrast = value.value();
}
Err(_) => {}
};
match controller.handle.get_vcp_feature(0xdc) {
Ok(value) => {
temp_state.max_mode = value.maximum();
temp_state.min_mode = 0;
temp_state.mode = value.value();
}
Err(_) => {}
};
temp_state.last_fetched_at = SystemTime::now();
let mut state = self.state.write().await;
*state = temp_state;
}
pub async fn set_brightness(&self, brightness: u16) {
let mut state = self.state.write().await;
state.brightness = brightness;
state.last_modified_at = SystemTime::now();
}
pub async fn set_contrast(&self, contrast: u16) {
let mut state = self.state.write().await;
state.contrast = contrast;
state.last_modified_at = SystemTime::now();
}
pub async fn set_mode(&self, mode: u16) {
let mut state = self.state.write().await;
state.mode = mode;
state.last_modified_at = SystemTime::now();
}
}