chore: clean code.
This commit is contained in:
parent
6e6160fc0a
commit
81d666557b
@ -16,7 +16,7 @@ use crate::{
|
|||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use super::{LedStripConfigGroup, SamplePointConfig, SamplePointMapper};
|
use super::{LedStripConfigGroup, SamplePointMapper};
|
||||||
|
|
||||||
pub struct LedColorsPublisher {
|
pub struct LedColorsPublisher {
|
||||||
sorted_colors_rx: Arc<RwLock<watch::Receiver<Vec<u8>>>>,
|
sorted_colors_rx: Arc<RwLock<watch::Receiver<Vec<u8>>>>,
|
||||||
@ -68,7 +68,6 @@ impl LedColorsPublisher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut start: tokio::time::Instant = tokio::time::Instant::now();
|
|
||||||
let mut interval = tokio::time::interval(Duration::from_millis(66));
|
let mut interval = tokio::time::interval(Duration::from_millis(66));
|
||||||
let init_version = internal_tasks_version.read().await.clone();
|
let init_version = internal_tasks_version.read().await.clone();
|
||||||
|
|
||||||
@ -88,8 +87,6 @@ impl LedColorsPublisher {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log::info!("tick: {}ms", start.elapsed().as_millis());
|
|
||||||
start = tokio::time::Instant::now();
|
|
||||||
let colors = screenshot_manager::get_display_colors(
|
let colors = screenshot_manager::get_display_colors(
|
||||||
display_id,
|
display_id,
|
||||||
&sample_points,
|
&sample_points,
|
||||||
@ -104,7 +101,7 @@ impl LedColorsPublisher {
|
|||||||
|
|
||||||
let colors = colors.unwrap();
|
let colors = colors.unwrap();
|
||||||
|
|
||||||
let color_len = colors.len();
|
// let color_len = colors.len();
|
||||||
|
|
||||||
match display_colors_tx.send((
|
match display_colors_tx.send((
|
||||||
display_id,
|
display_id,
|
||||||
@ -265,11 +262,8 @@ impl LedColorsPublisher {
|
|||||||
|
|
||||||
let colors = rx.borrow().clone();
|
let colors = rx.borrow().clone();
|
||||||
|
|
||||||
let len = colors.len();
|
|
||||||
|
|
||||||
match Self::send_colors(colors).await {
|
match Self::send_colors(colors).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// log::info!("colors sent. len: {}", len);
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("colors send failed: {}", err);
|
warn!("colors send failed: {}", err);
|
||||||
|
@ -8,12 +8,7 @@ mod rpc;
|
|||||||
pub mod screenshot;
|
pub mod screenshot;
|
||||||
mod screenshot_manager;
|
mod screenshot_manager;
|
||||||
|
|
||||||
use ambient_light::{
|
use ambient_light::{Border, ColorCalibration, LedStripConfig, LedStripConfigGroup};
|
||||||
Border, ColorCalibration, LedColorsPublisher, LedStripConfig, LedStripConfigGroup,
|
|
||||||
};
|
|
||||||
use core_graphics::display::{
|
|
||||||
kCGNullWindowID, kCGWindowImageDefault, kCGWindowListOptionOnScreenOnly, CGDisplay,
|
|
||||||
};
|
|
||||||
use display_info::DisplayInfo;
|
use display_info::DisplayInfo;
|
||||||
use paris::{error, info, warn};
|
use paris::{error, info, warn};
|
||||||
use screenshot::Screenshot;
|
use screenshot::Screenshot;
|
||||||
|
@ -10,11 +10,7 @@ use tokio::sync::{broadcast, watch, OnceCell};
|
|||||||
use tokio::time::{self, Duration};
|
use tokio::time::{self, Duration};
|
||||||
|
|
||||||
use crate::screenshot::LedSamplePoints;
|
use crate::screenshot::LedSamplePoints;
|
||||||
use crate::{
|
use crate::{ambient_light::SamplePointMapper, led_color::LedColor, screenshot::Screenshot};
|
||||||
ambient_light::SamplePointMapper,
|
|
||||||
led_color::LedColor,
|
|
||||||
screenshot::Screenshot,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Screenshot> {
|
pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Screenshot> {
|
||||||
log::debug!("take_screenshot");
|
log::debug!("take_screenshot");
|
||||||
@ -36,7 +32,6 @@ pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Scr
|
|||||||
|
|
||||||
let bytes = buffer.bytes().to_owned();
|
let bytes = buffer.bytes().to_owned();
|
||||||
|
|
||||||
|
|
||||||
let cg_display = CGDisplay::new(display_id);
|
let cg_display = CGDisplay::new(display_id);
|
||||||
let bound_scale_factor = (cg_display.bounds().size.width / width as f64) as f32;
|
let bound_scale_factor = (cg_display.bounds().size.width / width as f64) as f32;
|
||||||
|
|
||||||
@ -47,7 +42,7 @@ pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Scr
|
|||||||
bytes_per_row,
|
bytes_per_row,
|
||||||
bytes,
|
bytes,
|
||||||
scale_factor,
|
scale_factor,
|
||||||
bound_scale_factor
|
bound_scale_factor,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +55,6 @@ pub fn get_display_colors(
|
|||||||
let cg_display = CGDisplay::new(display_id);
|
let cg_display = CGDisplay::new(display_id);
|
||||||
|
|
||||||
let mut colors = vec![];
|
let mut colors = vec![];
|
||||||
let start_at = std::time::Instant::now();
|
|
||||||
for points in sample_points {
|
for points in sample_points {
|
||||||
if points.len() == 0 {
|
if points.len() == 0 {
|
||||||
continue;
|
continue;
|
||||||
@ -116,13 +110,6 @@ pub fn get_display_colors(
|
|||||||
colors.append(&mut part_colors);
|
colors.append(&mut part_colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if display_id == 4849664 {
|
|
||||||
// log::info!(
|
|
||||||
// "======= get_display_colors {} took {}ms",
|
|
||||||
// display_id,
|
|
||||||
// start_at.elapsed().as_millis()
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
Ok(colors)
|
Ok(colors)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +153,6 @@ impl ScreenshotManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut interval = time::interval(Duration::from_millis(1000));
|
let mut interval = time::interval(Duration::from_millis(1000));
|
||||||
let mut start = tokio::time::Instant::now();
|
|
||||||
|
|
||||||
let screenshot = screenshot.unwrap();
|
let screenshot = screenshot.unwrap();
|
||||||
let (screenshot_tx, screenshot_rx) = watch::channel(screenshot);
|
let (screenshot_tx, screenshot_rx) = watch::channel(screenshot);
|
||||||
@ -179,7 +165,6 @@ impl ScreenshotManager {
|
|||||||
let merged_screenshot_tx = merged_screenshot_tx.read().await.clone();
|
let merged_screenshot_tx = merged_screenshot_tx.read().await.clone();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
start = tokio::time::Instant::now();
|
|
||||||
Self::take_screenshot_loop(
|
Self::take_screenshot_loop(
|
||||||
display_id,
|
display_id,
|
||||||
scale_factor,
|
scale_factor,
|
||||||
@ -205,10 +190,12 @@ impl ScreenshotManager {
|
|||||||
if let Ok(screenshot) = screenshot {
|
if let Ok(screenshot) = screenshot {
|
||||||
match merged_screenshot_tx.send(screenshot.clone()) {
|
match merged_screenshot_tx.send(screenshot.clone()) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
log::info!("take_screenshot_loop: merged_screenshot_tx.send success. display#{}", display_id);
|
log::info!(
|
||||||
|
"take_screenshot_loop: merged_screenshot_tx.send success. display#{}",
|
||||||
|
display_id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(_) => {
|
||||||
// warn!("take_screenshot_loop: merged_screenshot_tx.send failed. display#{}. err: {}", display_id, err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
screenshot_tx.send(screenshot).unwrap();
|
screenshot_tx.send(screenshot).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user