chore: 更新。

This commit is contained in:
2023-03-16 20:13:08 +08:00
parent eeddff1dc1
commit 653729fcc2
6 changed files with 673 additions and 671 deletions

View File

@@ -52,11 +52,9 @@ impl Manager {
pub async fn publish_led_sub_pixels(&self, payload: Vec<u8>) -> anyhow::Result<()> {
self.client.publish_led_sub_pixels(payload).await
}
pub async fn publish_desktop_cmd<T>(&self, msg: &T) -> anyhow::Result<()>
where
T: ?Sized + serde::Serialize,
pub async fn publish_desktop_cmd(&self, field: &str, payload: Vec<u8>) -> anyhow::Result<()>
{
self.client.publish_desktop_cmd(msg).await
self.client.publish_desktop_cmd(field, payload).await
}
pub fn client(&self) -> &MqttRpc {

View File

@@ -12,7 +12,6 @@ const DISPLAY_TOPIC: &'static str = "display-ambient-light/display";
const DESKTOP_TOPIC: &'static str = "display-ambient-light/desktop";
const DISPLAY_BRIGHTNESS_TOPIC: &'static str = "display-ambient-light/board/brightness";
const BOARD_SEND_CMD: &'static str = "display-ambient-light/board/cmd";
const DESKTOP_SEND_CMD: &'static str = "display-ambient-light/desktop/cmd";
pub struct MqttRpc {
client: mqtt::AsyncClient,
@@ -227,16 +226,12 @@ impl MqttRpc {
) -> broadcast::Receiver<display::DisplayBrightness> {
self.change_display_brightness_tx.subscribe()
}
pub async fn publish_desktop_cmd<T>(&self, msg: &T) -> anyhow::Result<()>
where
T: ?Sized + serde::Serialize,
pub async fn publish_desktop_cmd(&self, field: &str, payload: Vec<u8>) -> anyhow::Result<()>
{
let str = serde_json::to_string(msg)
.map_err(|err| anyhow::anyhow!("can not serialize. {:?}", err))?;
self.client
.publish(mqtt::Message::new(
DESKTOP_SEND_CMD,
str.as_bytes(),
format!("{}/{}", DESKTOP_TOPIC, field),
payload,
mqtt::QOS_1,
))
.await