fix: 当配置反向时,颜色错误的问题。

This commit is contained in:
Ivan Li 2023-01-17 00:41:03 +08:00
parent a55db2553b
commit d3dfdb4d82

View File

@ -150,26 +150,34 @@ impl CoreManager {
] {
match config {
Some(config) => {
let (sign, start) = if config.global_start_position <= config.global_end_position
{
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() {
global_sub_pixels
.insert((sign * index as isize + start) as usize, color);
let pixel_index = index / 3;
let sub_pixel_index = index % 3;
let offset = if sign < 0 {
2 - sub_pixel_index
} else {
sub_pixel_index
};
let global_sub_pixel_index =
(sign * (pixel_index as isize * 3 + offset as isize) + start ) as usize;
global_sub_pixels.insert(global_sub_pixel_index, color);
}
}
None => {}
}
}
info!(
"led count: {}, spend: {:?}",
global_sub_pixels.len(),
start_at.elapsed()
);
// info!(
// "led count: {}, spend: {:?}",
// global_sub_pixels.len(),
// start_at.elapsed()
// );
if global_sub_pixels.len() >= total_colors_count * 3 {
let mut colors = vec![];