feat: 发布灯条颜色到 MQTT。
This commit is contained in:
parent
0d47911355
commit
9ec030488a
@ -37,10 +37,10 @@ impl LedColorsPublisher {
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn start(&self) -> anyhow::Result<()> {
|
||||
pub fn start(&self) {
|
||||
let tx = self.tx.clone();
|
||||
|
||||
let handler = tokio::spawn(async move {
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
log::info!("colors update loop AAA");
|
||||
|
||||
@ -103,7 +103,31 @@ impl LedColorsPublisher {
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
|
||||
let rx = self.rx.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut rx = rx.read().await.clone();
|
||||
loop {
|
||||
if let Err(err) = rx.changed().await {
|
||||
warn!("rx changed error: {}", err);
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
continue;
|
||||
}
|
||||
|
||||
let colors = rx.borrow().clone();
|
||||
|
||||
let len = colors.len();
|
||||
|
||||
match Self::send_colors(colors).await {
|
||||
Ok(_) => {
|
||||
log::info!("colors sent. len: {}", len);
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("colors send failed: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn send_colors(payload: Vec<u8>) -> anyhow::Result<()> {
|
||||
|
@ -183,7 +183,7 @@ async fn main() {
|
||||
screenshot_manager.start().unwrap();
|
||||
|
||||
let led_color_publisher = ambient_light::LedColorsPublisher::global().await;
|
||||
led_color_publisher.start().unwrap();
|
||||
led_color_publisher.start();
|
||||
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
|
Loading…
Reference in New Issue
Block a user