Compare commits
No commits in common. "a55db2553bb3f2e68efd1971ef32721d7b8d3a0a" and "af03b22d05dc44ac41c93039ae14ec761c6fc0f7" have entirely different histories.
a55db2553b
...
af03b22d05
@ -116,8 +116,7 @@ impl CoreManager {
|
|||||||
futs.push(fut);
|
futs.push(fut);
|
||||||
}
|
}
|
||||||
|
|
||||||
let total_colors_count = configs
|
let total_colors_count = configs.iter()
|
||||||
.iter()
|
|
||||||
.flat_map(|c| {
|
.flat_map(|c| {
|
||||||
vec![
|
vec![
|
||||||
c.led_strip_of_borders.top,
|
c.led_strip_of_borders.top,
|
||||||
@ -137,53 +136,36 @@ impl CoreManager {
|
|||||||
.collect::<HashSet<_>>()
|
.collect::<HashSet<_>>()
|
||||||
.len();
|
.len();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut global_sub_pixels = HashMap::new();
|
let mut global_colors = 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_colors();
|
let colors = screenshot.get_top_colors();
|
||||||
let config = screenshot.get_config();
|
let start = screenshot
|
||||||
for (colors, config) in vec![
|
.get_top_of_led_start_at()
|
||||||
(colors.top, config.led_strip_of_borders.top),
|
.min(screenshot.get_top_of_led_end_at());
|
||||||
(colors.right, config.led_strip_of_borders.right),
|
|
||||||
(colors.bottom, config.led_strip_of_borders.bottom),
|
for (index, color) in colors.into_iter().enumerate() {
|
||||||
(colors.left, config.led_strip_of_borders.left),
|
global_colors.insert(index + start, color);
|
||||||
] {
|
|
||||||
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() {
|
|
||||||
global_sub_pixels
|
|
||||||
.insert((sign * index as isize + start) as usize, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"led count: {}, spend: {:?}",
|
"led count: {}, spend: {:?}",
|
||||||
global_sub_pixels.len(),
|
global_colors.len(),
|
||||||
start_at.elapsed()
|
start_at.elapsed()
|
||||||
);
|
);
|
||||||
|
|
||||||
if global_sub_pixels.len() >= total_colors_count * 3 {
|
if global_colors.len() >= total_colors_count {
|
||||||
let mut colors = vec![];
|
let mut colors = vec![];
|
||||||
for index in 0..global_sub_pixels.len() {
|
for index in 0..global_colors.len() {
|
||||||
colors.push(*global_sub_pixels.get(&index).unwrap());
|
colors.push(*global_colors.get(&index).unwrap());
|
||||||
}
|
}
|
||||||
// info!("{:?}", colors);
|
global_colors = HashMap::new();
|
||||||
global_sub_pixels = HashMap::new();
|
|
||||||
match rpc::manager::Manager::global()
|
match rpc::manager::Manager::global()
|
||||||
.publish_led_sub_pixels(colors)
|
.publish_led_colors(&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);
|
||||||
|
@ -41,7 +41,7 @@ impl Screenshot {
|
|||||||
config.display_width,
|
config.display_width,
|
||||||
led_strip_config
|
led_strip_config
|
||||||
.global_start_position
|
.global_start_position
|
||||||
.abs_diff(led_strip_config.global_end_position) + 1,
|
.abs_diff(led_strip_config.global_end_position),
|
||||||
5,
|
5,
|
||||||
),
|
),
|
||||||
None => {
|
None => {
|
||||||
@ -56,7 +56,7 @@ impl Screenshot {
|
|||||||
config.display_width,
|
config.display_width,
|
||||||
led_strip_config
|
led_strip_config
|
||||||
.global_start_position
|
.global_start_position
|
||||||
.abs_diff(led_strip_config.global_end_position) + 1,
|
.abs_diff(led_strip_config.global_end_position),
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
points
|
points
|
||||||
@ -81,7 +81,7 @@ impl Screenshot {
|
|||||||
config.display_height,
|
config.display_height,
|
||||||
led_strip_config
|
led_strip_config
|
||||||
.global_start_position
|
.global_start_position
|
||||||
.abs_diff(led_strip_config.global_end_position) + 1,
|
.abs_diff(led_strip_config.global_end_position),
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
points
|
points
|
||||||
@ -103,7 +103,7 @@ impl Screenshot {
|
|||||||
config.display_height,
|
config.display_height,
|
||||||
led_strip_config
|
led_strip_config
|
||||||
.global_start_position
|
.global_start_position
|
||||||
.abs_diff(led_strip_config.global_end_position) + 1,
|
.abs_diff(led_strip_config.global_end_position),
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
points
|
points
|
||||||
@ -212,6 +212,23 @@ impl Screenshot {
|
|||||||
colors
|
colors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_top_colors(&self) -> Vec<LedColor> {
|
||||||
|
self.get_one_edge_colors(&self.sample_points.top)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_top_of_led_start_at(&self) -> usize {
|
||||||
|
self.config
|
||||||
|
.led_strip_of_borders.top
|
||||||
|
.and_then(|c| Some(c.global_start_position))
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
pub fn get_top_of_led_end_at(&self) -> usize {
|
||||||
|
self.config
|
||||||
|
.led_strip_of_borders.top
|
||||||
|
.and_then(|c| Some(c.global_end_position))
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn to_webp_base64(&self) -> String {
|
pub async fn to_webp_base64(&self) -> String {
|
||||||
let bitmap = &self.bitmap;
|
let bitmap = &self.bitmap;
|
||||||
let stride = bitmap.len() / self.config.display_height;
|
let stride = bitmap.len() / self.config.display_height;
|
||||||
@ -263,11 +280,6 @@ impl Screenshot {
|
|||||||
colors,
|
colors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_config(&self) -> DisplayConfig {
|
|
||||||
self.config
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
|
@ -38,18 +38,4 @@ impl Manager {
|
|||||||
.await
|
.await
|
||||||
.map_err(|error| anyhow::anyhow!("mqtt publish failed. {}", error))
|
.map_err(|error| anyhow::anyhow!("mqtt publish failed. {}", error))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn publish_led_sub_pixels(&self, payload: Vec<u8>) -> anyhow::Result<()> {
|
|
||||||
|
|
||||||
self.mqtt
|
|
||||||
.client
|
|
||||||
.publish(
|
|
||||||
"display-ambient-light/desktop/colors",
|
|
||||||
rumqttc::QoS::AtLeastOnce,
|
|
||||||
false,
|
|
||||||
payload,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|error| anyhow::anyhow!("mqtt publish failed. {}", error))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -183,11 +183,8 @@ export const DraggableStrip: FC<DraggableStripProp> = ({
|
|||||||
<div
|
<div
|
||||||
tw="border border-gray-700 h-3 w-full rounded-full"
|
tw="border border-gray-700 h-3 w-full rounded-full"
|
||||||
css={css`
|
css={css`
|
||||||
grid-column: ${Math.min(
|
grid-column-start: ${(config?.global_start_position ?? 0) + 1};
|
||||||
config?.global_start_position ?? 0,
|
grid-column-end: ${(config?.global_end_position ?? 0) + 1};
|
||||||
config?.global_end_position ?? 0,
|
|
||||||
) + 1} / span
|
|
||||||
${Math.abs(config?.global_start_position - config?.global_end_position) + 1};
|
|
||||||
grid-row-start: ${index + 1};
|
grid-row-start: ${index + 1};
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
transform: translateX(${boxTranslateX}px);
|
transform: translateX(${boxTranslateX}px);
|
||||||
|
@ -37,7 +37,7 @@ export const LedStripEditor: FC<LedStripEditorProps> = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onChange?.(new LedStripConfig(0, 0, 0));
|
onChange?.(new LedStripConfig(0, 0, 1));
|
||||||
}
|
}
|
||||||
}, [config, onChange]);
|
}, [config, onChange]);
|
||||||
const removeLed = useCallback(() => {
|
const removeLed = useCallback(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user