From 98751ffc9cae6b053f1fdf4b0a15a03f4ec8d9cb Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sat, 10 Sep 2022 17:43:38 +0800 Subject: [PATCH] style: clean up. --- src/dc_out_controller.rs | 7 +++---- src/main.rs | 20 ++++++-------------- src/time.rs | 3 +-- src/voltage_detection.rs | 6 ++---- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/dc_out_controller.rs b/src/dc_out_controller.rs index 3f14c06..8487490 100644 --- a/src/dc_out_controller.rs +++ b/src/dc_out_controller.rs @@ -12,7 +12,7 @@ use esp_idf_svc::eventloop::{ EspSubscription, EspTypedEventDeserializer, EspTypedEventSerializer, EspTypedEventSource, User, }; use esp_idf_sys::c_types; -use log::{info, warn}; +use log::{info, warn, debug}; use serde_json::json; use crate::voltage_detection::{VoltageDetectionWorker, VOLTAGE_EVENTLOOP}; @@ -22,7 +22,6 @@ const WAITING_OFF_SECONDS: u8 = 60; pub static mut DC_OUT_STATE_EVENT_LOOP: Option< EspEventLoop>, > = None; -static mut INSTANCE: Option = None; #[derive(Debug, Clone, Copy, PartialEq)] pub enum DcOutStatus { @@ -174,7 +173,7 @@ pub struct DcOutController { impl DcOutController { pub fn new() -> anyhow::Result { - let mut pin = unsafe { Gpio6::::new() } + let pin = unsafe { Gpio6::::new() } .into_output() .map_err(|err| anyhow::anyhow!("Make Gpio6 Into output Failed. {}", err))?; @@ -223,7 +222,7 @@ impl DcOutController { } else { warn!("DC_OUT_STATE_EVENT_LOOP is None"); } - info!("status: {:?}", state); + debug!("status: {:?}", state); }) .map_err(|err| anyhow::anyhow!("Subscribe Voltage Failed. {}", err))?; self.voltage_subscription = Some(voltage_subscription); diff --git a/src/main.rs b/src/main.rs index 40249ec..54de644 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,9 @@ -use embedded_svc::event_bus::{EventBus, Postbox}; -use esp_idf_svc::eventloop::{Background, EspBackgroundEventLoop, EspEventLoop}; +use embedded_svc::event_bus::{EventBus}; +use esp_idf_svc::eventloop::{EspBackgroundEventLoop}; use esp_idf_sys::{self as _}; use log::*; use std::{ - borrow::Borrow, env, - sync::{Arc, Mutex}, thread::{self, sleep}, time::Duration, }; @@ -105,11 +103,8 @@ fn main() { topic: "voltage".to_string(), message: json_str, }); - match result { - Ok(()) => { - warn!("send voltage to mq message failed.") - } - Err(err) => warn!("send voltage to mq message failed. {}", err), + if let Err(err) = result { + warn!("send voltage to mq message failed. {}", err) } } Err(err) => warn!("send voltage to mq message failed. {}", err), @@ -145,11 +140,8 @@ fn main() { message: message.to_json(), }); - match result { - Ok(_) => { - info!("send dc_out_state message success.") - } - Err(err) => warn!("send dc_out_state message failed. {}", err), + if let Err(err) = result { + warn!("send dc_out_state message failed. {}", err) } } Err(err) => warn!("send dc_out_state to mq message failed. {}", err), diff --git a/src/time.rs b/src/time.rs index 93a2d73..baf1a36 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,8 +1,7 @@ -use anyhow::bail; use embedded_svc::sys_time::SystemTime; use esp_idf_svc::sntp::{self, EspSntp}; use esp_idf_svc::systime::EspSystemTime; -use log::{warn, info}; +use log::{info}; use std::time::{Duration}; pub struct Time { diff --git a/src/voltage_detection.rs b/src/voltage_detection.rs index 3e2caad..44501c5 100644 --- a/src/voltage_detection.rs +++ b/src/voltage_detection.rs @@ -23,7 +23,7 @@ use esp_idf_svc::{ timer::{EspTimer, EspTimerService}, }; use esp_idf_sys::c_types; -use log::{info, warn}; +use log::{warn, debug}; use serde::{Deserialize, Serialize}; pub static mut VOLTAGE_EVENTLOOP: Option>> = None; @@ -64,7 +64,7 @@ impl VoltageDetection { if let Err(err) = worker.read_once() { warn!("Read Failed. {}", err); } - info!( + debug!( "Adapter: {},\tBattery: {},\t Output: {}", worker.adapter_voltage, worker.battery_voltage, worker.output_voltage ); @@ -78,8 +78,6 @@ impl VoltageDetection { None, ) { warn!("Post Result to Event Loop failed. {}", err); - } else { - info!("Event Loop Post"); } } else { warn!("EVENTLOOP IS NONE");