feat: 使用左开右闭区间定义每边的 LEDs。
This commit is contained in:
parent
af03b22d05
commit
1882b8ccdc
@ -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),
|
.abs_diff(led_strip_config.global_end_position) + 1,
|
||||||
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),
|
.abs_diff(led_strip_config.global_end_position) + 1,
|
||||||
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),
|
.abs_diff(led_strip_config.global_end_position) + 1,
|
||||||
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),
|
.abs_diff(led_strip_config.global_end_position) + 1,
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
points
|
points
|
||||||
@ -212,23 +212,6 @@ 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;
|
||||||
@ -280,6 +263,11 @@ impl Screenshot {
|
|||||||
colors,
|
colors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_config(&self) -> DisplayConfig {
|
||||||
|
self.config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
|
@ -38,4 +38,18 @@ 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,8 +183,11 @@ 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-start: ${(config?.global_start_position ?? 0) + 1};
|
grid-column: ${Math.min(
|
||||||
grid-column-end: ${(config?.global_end_position ?? 0) + 1};
|
config?.global_start_position ?? 0,
|
||||||
|
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, 1));
|
onChange?.(new LedStripConfig(0, 0, 0));
|
||||||
}
|
}
|
||||||
}, [config, onChange]);
|
}, [config, onChange]);
|
||||||
const removeLed = useCallback(() => {
|
const removeLed = useCallback(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user