feature/gui-configuration:支持从 GUI 配置程序。 #4

Merged
Ivan merged 19 commits from feature/gui-configuration into master 2023-01-26 23:44:19 +08:00
Showing only changes of commit a55db2553b - Show all commits

View File

@ -116,7 +116,8 @@ impl CoreManager {
futs.push(fut); futs.push(fut);
} }
let total_colors_count = configs.iter() let total_colors_count = configs
.iter()
.flat_map(|c| { .flat_map(|c| {
vec![ vec![
c.led_strip_of_borders.top, c.led_strip_of_borders.top,
@ -136,36 +137,53 @@ impl CoreManager {
.collect::<HashSet<_>>() .collect::<HashSet<_>>()
.len(); .len();
tokio::spawn(async move { tokio::spawn(async move {
let mut global_colors = HashMap::new(); let mut global_sub_pixels = HashMap::new();
while let Some(screenshot) = rx.recv().await { while let Some(screenshot) = rx.recv().await {
let start_at = Instant::now(); let start_at = Instant::now();
let colors = screenshot.get_top_colors(); let colors = screenshot.get_colors();
let start = screenshot let config = screenshot.get_config();
.get_top_of_led_start_at() for (colors, config) in vec![
.min(screenshot.get_top_of_led_end_at()); (colors.top, config.led_strip_of_borders.top),
(colors.right, config.led_strip_of_borders.right),
(colors.bottom, config.led_strip_of_borders.bottom),
(colors.left, config.led_strip_of_borders.left),
] {
match config {
Some(config) => {
let (sign, start) = if config.global_start_position <= config.global_end_position
{
(1, config.global_start_position as isize * 3)
} else {
(-1, (config.global_start_position as isize + 1) * 3 - 1)
};
for (index, color) in colors.into_iter().enumerate() { for (index, color) in colors.into_iter().enumerate() {
global_colors.insert(index + start, color); global_sub_pixels
.insert((sign * index as isize + start) as usize, color);
}
}
None => {}
}
} }
info!( info!(
"led count: {}, spend: {:?}", "led count: {}, spend: {:?}",
global_colors.len(), global_sub_pixels.len(),
start_at.elapsed() start_at.elapsed()
); );
if global_colors.len() >= total_colors_count { if global_sub_pixels.len() >= total_colors_count * 3 {
let mut colors = vec![]; let mut colors = vec![];
for index in 0..global_colors.len() { for index in 0..global_sub_pixels.len() {
colors.push(*global_colors.get(&index).unwrap()); colors.push(*global_sub_pixels.get(&index).unwrap());
} }
global_colors = HashMap::new(); // info!("{:?}", colors);
global_sub_pixels = HashMap::new();
match rpc::manager::Manager::global() match rpc::manager::Manager::global()
.publish_led_colors(&colors) .publish_led_sub_pixels(colors)
.await .await
{ {
Ok(_) => { Ok(_) => {
info!("publish successful",); // info!("publish successful",);
} }
Err(error) => { Err(error) => {
warn!("publish led colors failed. {}", error); warn!("publish led colors failed. {}", error);