chore: 清理代码。
This commit is contained in:
parent
d9d73f01d7
commit
9109518822
@ -71,14 +71,10 @@ impl DisplayManager {
|
|||||||
fn subscribe_setting_request(&mut self) {
|
fn subscribe_setting_request(&mut self) {
|
||||||
let displays = self.displays.clone();
|
let displays = self.displays.clone();
|
||||||
let displays_changed_sender = self.displays_changed_sender.clone();
|
let displays_changed_sender = self.displays_changed_sender.clone();
|
||||||
log::info!("start display setting request handler");
|
|
||||||
let handler = tokio::spawn(async move {
|
let handler = tokio::spawn(async move {
|
||||||
let channels = BoardMessageChannels::global().await;
|
let channels = BoardMessageChannels::global().await;
|
||||||
|
|
||||||
let mut request_rx = channels.display_setting_request_sender.subscribe();
|
let mut request_rx = channels.display_setting_request_sender.subscribe();
|
||||||
|
|
||||||
log::info!("display setting request handler started");
|
|
||||||
|
|
||||||
while let Ok(message) = request_rx.recv().await {
|
while let Ok(message) = request_rx.recv().await {
|
||||||
let displays = displays.write().await;
|
let displays = displays.write().await;
|
||||||
|
|
||||||
@ -88,7 +84,6 @@ impl DisplayManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("display setting request received. {:?}", message);
|
|
||||||
|
|
||||||
let display = display.unwrap().write().await;
|
let display = display.unwrap().write().await;
|
||||||
let result = match message.setting {
|
let result = match message.setting {
|
||||||
@ -104,8 +99,6 @@ impl DisplayManager {
|
|||||||
|
|
||||||
drop(display);
|
drop(display);
|
||||||
|
|
||||||
log::info!("display setting request handled. {:?}", message);
|
|
||||||
|
|
||||||
let mut states = Vec::new();
|
let mut states = Vec::new();
|
||||||
for display in displays.iter() {
|
for display in displays.iter() {
|
||||||
let state = display.read().await.state.read().await.clone();
|
let state = display.read().await.state.read().await.clone();
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use paris::{error, info, warn};
|
use paris::{error, info, warn};
|
||||||
use tokio::{io, net::UdpSocket, sync::RwLock, time::timeout, task::yield_now};
|
use tokio::{io, net::UdpSocket, sync::RwLock, task::yield_now, time::timeout};
|
||||||
|
|
||||||
use crate::rpc::DisplaySettingRequest;
|
use crate::rpc::DisplaySettingRequest;
|
||||||
|
|
||||||
use super::{BoardConnectStatus, BoardInfo, UdpRpc};
|
use super::{BoardConnectStatus, BoardInfo};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Board {
|
pub struct Board {
|
||||||
@ -42,27 +42,28 @@ impl Board {
|
|||||||
|
|
||||||
let board_message_channels = crate::rpc::channels::BoardMessageChannels::global().await;
|
let board_message_channels = crate::rpc::channels::BoardMessageChannels::global().await;
|
||||||
|
|
||||||
let display_setting_request_sender = board_message_channels.display_setting_request_sender.clone();
|
let display_setting_request_sender = board_message_channels
|
||||||
|
.display_setting_request_sender
|
||||||
|
.clone();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match socket.try_recv(&mut buf) {
|
match socket.try_recv(&mut buf) {
|
||||||
Ok(len) => {
|
Ok(len) => {
|
||||||
log::info!("recv: {:?}", &buf[..len]);
|
log::info!("recv: {:?}", &buf[..len]);
|
||||||
if buf[0] == 3 {
|
if buf[0] == 3 {
|
||||||
let result = display_setting_request_sender.send(DisplaySettingRequest {
|
let result =
|
||||||
display_index: buf[1] as usize,
|
display_setting_request_sender.send(DisplaySettingRequest {
|
||||||
setting: crate::rpc::DisplaySetting::Brightness(buf[2]),
|
display_index: buf[1] as usize,
|
||||||
});
|
setting: crate::rpc::DisplaySetting::Brightness(buf[2]),
|
||||||
|
});
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
error!("send display setting request to channel failed: {:?}", err);
|
error!("send display setting request to channel failed: {:?}", err);
|
||||||
} else {
|
|
||||||
info!("send display setting request to channel success");
|
|
||||||
yield_now().await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
|
yield_now().await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user