style: clean up.
This commit is contained in:
parent
7d7048b671
commit
98751ffc9c
@ -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<esp_idf_svc::eventloop::User<Background>>,
|
||||
> = None;
|
||||
static mut INSTANCE: Option<DcOutController> = None;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum DcOutStatus {
|
||||
@ -174,7 +173,7 @@ pub struct DcOutController {
|
||||
|
||||
impl DcOutController {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let mut pin = unsafe { Gpio6::<Output>::new() }
|
||||
let pin = unsafe { Gpio6::<Output>::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);
|
||||
|
20
src/main.rs
20
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),
|
||||
|
@ -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 {
|
||||
|
@ -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<EspEventLoop<esp_idf_svc::eventloop::User<Background>>> = 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");
|
||||
|
Loading…
Reference in New Issue
Block a user