chore: 📎 + fmt

This commit is contained in:
2025-10-18 20:40:38 +02:00
parent 6357ec773f
commit 1db3f7af64
26 changed files with 548 additions and 578 deletions

View File

@@ -155,7 +155,7 @@ impl Esp<'_> {
pub(crate) async fn delete_file(&self, filename: String) -> FatResult<()> {
let file = PathBuf::try_from(filename.as_str())?;
let access = self.fs.lock().await;
access.remove(&*file)?;
access.remove(&file)?;
Ok(())
}
pub(crate) async fn write_file(
@@ -168,7 +168,7 @@ impl Esp<'_> {
let access = self.fs.lock().await;
access.open_file_with_options_and_then(
|options| options.read(true).write(true).create(true),
&*file,
&file,
|file| {
file.seek(SeekFrom::Start(offset))?;
file.write(buf)?;
@@ -181,7 +181,7 @@ impl Esp<'_> {
pub async fn get_size(&mut self, filename: String) -> FatResult<usize> {
let file = PathBuf::try_from(filename.as_str())?;
let access = self.fs.lock().await;
let data = access.metadata(&*file)?;
let data = access.metadata(&file)?;
Ok(data.len())
}
pub(crate) async fn get_file(
@@ -198,7 +198,7 @@ impl Esp<'_> {
let offset = chunk * buf.len() as u32;
access.open_file_with_options_and_then(
|options| options.read(true),
&*file,
&file,
|file| {
let length = file.len()? as u32;
if length == 0 {
@@ -226,7 +226,7 @@ impl Esp<'_> {
self.ota_target.write(offset, buf)?;
self.ota_target.read(offset, read_back)?;
if buf != read_back {
info!("Expected {:?} but got {:?}", buf, read_back);
info!("Expected {buf:?} but got {read_back:?}");
bail!(
"Flash error, read back does not match write buffer at offset {:x}",
offset
@@ -238,10 +238,7 @@ impl Esp<'_> {
pub(crate) async fn finalize_ota(&mut self) -> Result<(), FatError> {
let current = self.ota.current_slot()?;
if self.ota.current_ota_state()? != OtaImageState::Valid {
info!(
"Validating current slot {:?} as it was able to ota",
current
);
info!("Validating current slot {current:?} as it was able to ota");
self.ota.set_current_ota_state(Valid)?;
}
@@ -250,7 +247,7 @@ impl Esp<'_> {
self.ota.set_current_ota_state(OtaImageState::New)?;
info!("switched state for new partition");
let state_new = self.ota.current_ota_state()?;
info!("state on new partition now {:?}", state_new);
info!("state on new partition now {state_new:?}");
//determine nextslot crc
self.set_restart_to_conf(true);
@@ -290,7 +287,7 @@ impl Esp<'_> {
if ntp_addrs.is_empty() {
bail!("Failed to resolve DNS");
}
info!("NTP server: {:?}", ntp_addrs);
info!("NTP server: {ntp_addrs:?}");
let mut counter = 0;
loop {
@@ -302,12 +299,12 @@ impl Esp<'_> {
match timeout {
Ok(result) => {
let time = result?;
info!("Time: {:?}", time);
info!("Time: {time:?}");
return DateTime::from_timestamp(time.seconds as i64, 0)
.context("Could not convert Sntp result");
}
Err(err) => {
warn!("sntp timeout, retry: {:?}", err);
warn!("sntp timeout, retry: {err:?}");
counter += 1;
if counter > 10 {
bail!("Failed to get time from NTP server");
@@ -426,7 +423,7 @@ impl Esp<'_> {
println!("start net task");
spawner.spawn(net_task(runner)).ok();
println!("run dhcp");
spawner.spawn(run_dhcp(stack.clone(), gw_ip_addr_str)).ok();
spawner.spawn(run_dhcp(*stack, gw_ip_addr_str)).ok();
loop {
if stack.is_link_up() {
@@ -442,7 +439,7 @@ impl Esp<'_> {
.config_v4()
.inspect(|c| println!("ipv4 config: {c:?}"));
Ok(stack.clone())
Ok(*stack)
}
pub(crate) async fn wifi(
@@ -505,12 +502,9 @@ impl Esp<'_> {
} + max_wait as u64 * 1000;
loop {
let state = esp_wifi::wifi::sta_state();
match state {
WifiState::StaStarted => {
self.controller.lock().await.connect()?;
break;
}
_ => {}
if state == WifiState::StaStarted {
self.controller.lock().await.connect()?;
break;
}
if {
let guard = TIME_ACCESS.get().await.lock().await;
@@ -527,11 +521,8 @@ impl Esp<'_> {
} + max_wait as u64 * 1000;
loop {
let state = esp_wifi::wifi::sta_state();
match state {
WifiState::StaConnected => {
break;
}
_ => {}
if state == WifiState::StaConnected {
break;
}
if {
let guard = TIME_ACCESS.get().await.lock().await;
@@ -572,7 +563,7 @@ impl Esp<'_> {
}
info!("Connected WIFI, dhcp: {:?}", stack.config_v4());
Ok(stack.clone())
Ok(*stack)
}
pub fn deep_sleep(
@@ -611,12 +602,12 @@ impl Esp<'_> {
}
let data = self.fs.lock().await.read::<4096>(&cfg)?;
let config: PlantControllerConfig = serde_json::from_slice(&data)?;
return Ok(config);
Ok(config)
}
pub(crate) async fn save_config(&mut self, config: Vec<u8>) -> FatResult<()> {
let filesystem = self.fs.lock().await;
let cfg = PathBuf::try_from(CONFIG_FILE)?;
filesystem.write(&cfg, &*config)?;
filesystem.write(&cfg, &config)?;
Ok(())
}
pub(crate) async fn list_files(&self) -> FatResult<FileList> {
@@ -690,19 +681,15 @@ impl Esp<'_> {
"",
)
.await;
for i in 0..PLANT_COUNT {
log::info!(
"LAST_WATERING_TIMESTAMP[{}] = UTC {}",
i,
LAST_WATERING_TIMESTAMP[i]
);
// is executed before main, no other code will alter these values during printing
#[allow(static_mut_refs)]
for (i, time) in LAST_WATERING_TIMESTAMP.iter().enumerate() {
log::info!("LAST_WATERING_TIMESTAMP[{i}] = UTC {time}");
}
for i in 0..PLANT_COUNT {
log::info!(
"CONSECUTIVE_WATERING_PLANT[{}] = {}",
i,
CONSECUTIVE_WATERING_PLANT[i]
);
// is executed before main, no other code will alter these values during printing
#[allow(static_mut_refs)]
for (i, item) in CONSECUTIVE_WATERING_PLANT.iter().enumerate() {
log::info!("CONSECUTIVE_WATERING_PLANT[{i}] = {item}");
}
}
}
@@ -734,9 +721,9 @@ impl Esp<'_> {
bail!("Mqtt url was empty")
}
let last_will_topic = format!("{}/state", base_topic);
let round_trip_topic = format!("{}/internal/roundtrip", base_topic);
let stay_alive_topic = format!("{}/stay_alive", base_topic);
let last_will_topic = format!("{base_topic}/state");
let round_trip_topic = format!("{base_topic}/internal/roundtrip");
let stay_alive_topic = format!("{base_topic}/stay_alive");
let mut builder: McutieBuilder<'_, String, PublishDisplay<String, &str>, 0> =
McutieBuilder::new(stack, "plant ctrl", mqtt_url);
@@ -879,8 +866,7 @@ impl Esp<'_> {
Ok(()) => {}
Err(err) => {
info!(
"Error during mqtt send on topic {} with message {:#?} error is {:?}",
subtopic, message, err
"Error during mqtt send on topic {subtopic} with message {message:#?} error is {err:?}"
);
}
};
@@ -932,7 +918,7 @@ async fn mqtt_incoming_task(
LOG_ACCESS
.lock()
.await
.log(LogMessage::UnknownTopic, 0, 0, "", &*topic)
.log(LogMessage::UnknownTopic, 0, 0, "", &topic)
.await;
}
}