v0.2:重写项目。 #6

Merged
Ivan merged 20 commits from v0.2 into master 2022-09-12 11:58:32 +08:00
4 changed files with 12 additions and 24 deletions
Showing only changes of commit 98751ffc9c - Show all commits

View File

@ -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);

View File

@ -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),

View File

@ -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 {

View File

@ -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");