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,
|
EspSubscription, EspTypedEventDeserializer, EspTypedEventSerializer, EspTypedEventSource, User,
|
||||||
};
|
};
|
||||||
use esp_idf_sys::c_types;
|
use esp_idf_sys::c_types;
|
||||||
use log::{info, warn};
|
use log::{info, warn, debug};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::voltage_detection::{VoltageDetectionWorker, VOLTAGE_EVENTLOOP};
|
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<
|
pub static mut DC_OUT_STATE_EVENT_LOOP: Option<
|
||||||
EspEventLoop<esp_idf_svc::eventloop::User<Background>>,
|
EspEventLoop<esp_idf_svc::eventloop::User<Background>>,
|
||||||
> = None;
|
> = None;
|
||||||
static mut INSTANCE: Option<DcOutController> = None;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum DcOutStatus {
|
pub enum DcOutStatus {
|
||||||
@ -174,7 +173,7 @@ pub struct DcOutController {
|
|||||||
|
|
||||||
impl DcOutController {
|
impl DcOutController {
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new() -> anyhow::Result<Self> {
|
||||||
let mut pin = unsafe { Gpio6::<Output>::new() }
|
let pin = unsafe { Gpio6::<Output>::new() }
|
||||||
.into_output()
|
.into_output()
|
||||||
.map_err(|err| anyhow::anyhow!("Make Gpio6 Into output Failed. {}", err))?;
|
.map_err(|err| anyhow::anyhow!("Make Gpio6 Into output Failed. {}", err))?;
|
||||||
|
|
||||||
@ -223,7 +222,7 @@ impl DcOutController {
|
|||||||
} else {
|
} else {
|
||||||
warn!("DC_OUT_STATE_EVENT_LOOP is None");
|
warn!("DC_OUT_STATE_EVENT_LOOP is None");
|
||||||
}
|
}
|
||||||
info!("status: {:?}", state);
|
debug!("status: {:?}", state);
|
||||||
})
|
})
|
||||||
.map_err(|err| anyhow::anyhow!("Subscribe Voltage Failed. {}", err))?;
|
.map_err(|err| anyhow::anyhow!("Subscribe Voltage Failed. {}", err))?;
|
||||||
self.voltage_subscription = Some(voltage_subscription);
|
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 embedded_svc::event_bus::{EventBus};
|
||||||
use esp_idf_svc::eventloop::{Background, EspBackgroundEventLoop, EspEventLoop};
|
use esp_idf_svc::eventloop::{EspBackgroundEventLoop};
|
||||||
use esp_idf_sys::{self as _};
|
use esp_idf_sys::{self as _};
|
||||||
use log::*;
|
use log::*;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
|
||||||
env,
|
env,
|
||||||
sync::{Arc, Mutex},
|
|
||||||
thread::{self, sleep},
|
thread::{self, sleep},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@ -105,11 +103,8 @@ fn main() {
|
|||||||
topic: "voltage".to_string(),
|
topic: "voltage".to_string(),
|
||||||
message: json_str,
|
message: json_str,
|
||||||
});
|
});
|
||||||
match result {
|
if let Err(err) = result {
|
||||||
Ok(()) => {
|
warn!("send voltage to mq message failed. {}", err)
|
||||||
warn!("send voltage to mq message failed.")
|
|
||||||
}
|
|
||||||
Err(err) => warn!("send voltage to mq message failed. {}", err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => 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(),
|
message: message.to_json(),
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
if let Err(err) = result {
|
||||||
Ok(_) => {
|
warn!("send dc_out_state message failed. {}", err)
|
||||||
info!("send dc_out_state message success.")
|
|
||||||
}
|
|
||||||
Err(err) => warn!("send dc_out_state message failed. {}", err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => warn!("send dc_out_state to mq 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 embedded_svc::sys_time::SystemTime;
|
||||||
use esp_idf_svc::sntp::{self, EspSntp};
|
use esp_idf_svc::sntp::{self, EspSntp};
|
||||||
use esp_idf_svc::systime::EspSystemTime;
|
use esp_idf_svc::systime::EspSystemTime;
|
||||||
use log::{warn, info};
|
use log::{info};
|
||||||
use std::time::{Duration};
|
use std::time::{Duration};
|
||||||
|
|
||||||
pub struct Time {
|
pub struct Time {
|
||||||
|
@ -23,7 +23,7 @@ use esp_idf_svc::{
|
|||||||
timer::{EspTimer, EspTimerService},
|
timer::{EspTimer, EspTimerService},
|
||||||
};
|
};
|
||||||
use esp_idf_sys::c_types;
|
use esp_idf_sys::c_types;
|
||||||
use log::{info, warn};
|
use log::{warn, debug};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub static mut VOLTAGE_EVENTLOOP: Option<EspEventLoop<esp_idf_svc::eventloop::User<Background>>> = None;
|
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() {
|
if let Err(err) = worker.read_once() {
|
||||||
warn!("Read Failed. {}", err);
|
warn!("Read Failed. {}", err);
|
||||||
}
|
}
|
||||||
info!(
|
debug!(
|
||||||
"Adapter: {},\tBattery: {},\t Output: {}",
|
"Adapter: {},\tBattery: {},\t Output: {}",
|
||||||
worker.adapter_voltage, worker.battery_voltage, worker.output_voltage
|
worker.adapter_voltage, worker.battery_voltage, worker.output_voltage
|
||||||
);
|
);
|
||||||
@ -78,8 +78,6 @@ impl VoltageDetection {
|
|||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
warn!("Post Result to Event Loop failed. {}", err);
|
warn!("Post Result to Event Loop failed. {}", err);
|
||||||
} else {
|
|
||||||
info!("Event Loop Post");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("EVENTLOOP IS NONE");
|
warn!("EVENTLOOP IS NONE");
|
||||||
|
Loading…
Reference in New Issue
Block a user