feat: 支持将色彩校准的值写入本地配置文件。
This commit is contained in:
@@ -5,7 +5,7 @@ use paris::{error, info};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::api::path::config_dir;
|
||||
|
||||
use crate::screenshot::{self, LedSamplePoints};
|
||||
use crate::screenshot::LedSamplePoints;
|
||||
|
||||
const CONFIG_FILE_NAME: &str = "cc.ivanli.ambient_light/led_strip_config.toml";
|
||||
|
||||
@@ -26,10 +26,18 @@ pub struct LedStripConfig {
|
||||
pub len: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||
pub struct ColorCalibration {
|
||||
r: f32,
|
||||
g: f32,
|
||||
b: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
pub struct LedStripConfigGroup {
|
||||
pub strips: Vec<LedStripConfig>,
|
||||
pub mappers: Vec<SamplePointMapper>,
|
||||
pub color_calibration: ColorCalibration,
|
||||
}
|
||||
|
||||
impl LedStripConfigGroup {
|
||||
@@ -115,7 +123,17 @@ impl LedStripConfigGroup {
|
||||
})
|
||||
}
|
||||
}
|
||||
Ok(Self { strips, mappers })
|
||||
let color_calibration = ColorCalibration {
|
||||
r: 1.0,
|
||||
g: 1.0,
|
||||
b: 1.0,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
strips,
|
||||
mappers,
|
||||
color_calibration,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@ use tokio::sync::OnceCell;
|
||||
|
||||
use crate::ambient_light::{config, LedStripConfigGroup};
|
||||
|
||||
use super::{Border, SamplePointMapper};
|
||||
use super::{Border, SamplePointMapper, ColorCalibration};
|
||||
|
||||
pub struct ConfigManager {
|
||||
config: Arc<RwLock<LedStripConfigGroup>>,
|
||||
@@ -223,4 +223,15 @@ impl ConfigManager {
|
||||
) -> tokio::sync::watch::Receiver<LedStripConfigGroup> {
|
||||
self.config_update_receiver.clone()
|
||||
}
|
||||
|
||||
pub async fn set_color_calibration(&self, color_calibration: ColorCalibration) -> anyhow::Result<()> {
|
||||
let config = self.config.write().await;
|
||||
|
||||
let mut cloned_config = config.clone();
|
||||
cloned_config.color_calibration = color_calibration;
|
||||
|
||||
drop(config);
|
||||
|
||||
self.update(&cloned_config).await
|
||||
}
|
||||
}
|
||||
|
@@ -192,7 +192,7 @@ impl LedColorsPublisher {
|
||||
warn!("Failed to send sorted colors: {}", err);
|
||||
}
|
||||
};
|
||||
log::info!("tick: {}ms", start.elapsed().as_millis());
|
||||
log::debug!("tick: {}ms", start.elapsed().as_millis());
|
||||
start = tokio::time::Instant::now();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user