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

@@ -58,9 +58,9 @@ use alloc::sync::Arc;
use async_trait::async_trait;
use bincode::{Decode, Encode};
use bq34z100::Bq34z100g1Driver;
use canapi::SensorSlot;
use chrono::{DateTime, FixedOffset, Utc};
use core::cell::RefCell;
use canapi::SensorSlot;
use ds323x::ic::DS3231;
use ds323x::interface::I2cInterface;
use ds323x::{DateTimeAccess, Ds323x};
@@ -108,7 +108,6 @@ use log::{error, info, warn};
use portable_atomic::AtomicBool;
use serde::Serialize;
pub static TIME_ACCESS: OnceLock<Mutex<CriticalSectionRawMutex, Rtc>> = OnceLock::new();
//Only support for 8 right now!
@@ -127,9 +126,9 @@ pub enum Sensor {
B,
}
impl Into<SensorSlot> for Sensor {
fn into(self) -> SensorSlot {
match self {
impl From<Sensor> for SensorSlot {
fn from(val: Sensor) -> Self {
match val {
Sensor::A => SensorSlot::A,
Sensor::B => SensorSlot::B,
}
@@ -138,6 +137,7 @@ impl Into<SensorSlot> for Sensor {
pub struct PlantHal {}
#[allow(clippy::upper_case_acronyms)]
pub struct HAL<'a> {
pub board_hal: Box<dyn BoardInteraction<'a> + Send>,
}
@@ -177,17 +177,17 @@ pub trait BoardInteraction<'a> {
let current = counter % PLANT_COUNT as u32;
for led in 0..PLANT_COUNT {
if let Err(err) = self.fault(led, current == led as u32).await {
warn!("Fault on plant {}: {:?}", led, err);
warn!("Fault on plant {led}: {err:?}");
}
}
let even = counter % 2 == 0;
let _ = self.general_fault(even.into()).await;
let _ = self.general_fault(even).await;
}
async fn clear_progress(&mut self) {
for led in 0..PLANT_COUNT {
if let Err(err) = self.fault(led, false).await {
warn!("Fault on plant {}: {:?}", led, err);
warn!("Fault on plant {led}: {err:?}");
}
}
let _ = self.general_fault(false).await;
@@ -272,11 +272,11 @@ impl PlantHal {
let timg0 = TimerGroup::new(peripherals.TIMG0);
let esp_wifi_ctrl = &*mk_static!(
EspWifiController<'static>,
init(timg0.timer0, rng.clone()).expect("Could not init wifi controller")
init(timg0.timer0, rng).expect("Could not init wifi controller")
);
let (controller, interfaces) =
esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).expect("Could not init wifi");
esp_wifi::wifi::new(esp_wifi_ctrl, peripherals.WIFI).expect("Could not init wifi");
use esp_hal::timer::systimer::SystemTimer;
esp_hal_embassy::init(systimer.alarm0);
@@ -351,9 +351,9 @@ impl PlantHal {
let running = get_current_slot_and_fix_ota_data(&mut ota, state_0, state_1)?;
let target = running.next();
info!("Currently running OTA slot: {:?}", running);
info!("Slot0 state: {:?}", state_0);
info!("Slot1 state: {:?}", state_1);
info!("Currently running OTA slot: {running:?}");
info!("Slot0 state: {state_0:?}");
info!("Slot1 state: {state_1:?}");
//obtain current_state and next_state here!
let ota_target = match target {
@@ -401,11 +401,12 @@ impl PlantHal {
log::info!("Littlefs2 filesystem is formatted");
}
Err(err) => {
error!("Littlefs2 filesystem could not be formatted: {:?}", err);
error!("Littlefs2 filesystem could not be formatted: {err:?}");
}
}
}
#[allow(clippy::arc_with_non_send_sync)]
let fs = Arc::new(Mutex::new(
lfs2Filesystem::mount(alloc, lfs2filesystem).expect("Could not mount lfs2 filesystem"),
));
@@ -498,8 +499,8 @@ impl PlantHal {
I2C_DRIVER.init(i2c_bus).expect("Could not init i2c driver");
let i2c_bus = I2C_DRIVER.get().await;
let rtc_device = I2cDevice::new(&i2c_bus);
let eeprom_device = I2cDevice::new(&i2c_bus);
let rtc_device = I2cDevice::new(i2c_bus);
let eeprom_device = I2cDevice::new(i2c_bus);
let mut rtc: Ds323x<
I2cInterface<I2cDevice<CriticalSectionRawMutex, I2c<Blocking>>>,
@@ -511,10 +512,10 @@ impl PlantHal {
let rtc_time = rtc.datetime();
match rtc_time {
Ok(tt) => {
log::info!("Rtc Module reports time at UTC {}", tt);
log::info!("Rtc Module reports time at UTC {tt}");
}
Err(err) => {
log::info!("Rtc Module could not be read {:?}", err);
log::info!("Rtc Module could not be read {err:?}");
}
}
@@ -566,7 +567,7 @@ impl PlantHal {
};
let board_hal: Box<dyn BoardInteraction + Send> = match config.hardware.board {
BoardVersion::INITIAL => {
BoardVersion::Initial => {
initial_hal::create_initial_board(free_pins, config, esp)?
}
BoardVersion::V3 => {
@@ -620,8 +621,8 @@ fn ota_state(slot: ota_slot, ota_data: &mut FlashRegion<FlashStorage>) -> OtaIma
let _ = ota_data.read(0x1000, &mut slot_buf);
}
let raw_state = u32::from_le_bytes(slot_buf[24..28].try_into().unwrap_or([0xff; 4]));
let state0 = OtaImageState::try_from(raw_state).unwrap_or(OtaImageState::Undefined);
state0
OtaImageState::try_from(raw_state).unwrap_or(OtaImageState::Undefined)
}
fn get_current_slot_and_fix_ota_data(
@@ -666,10 +667,7 @@ fn get_current_slot_and_fix_ota_data(
}
_ => {}
}
info!(
"Current slot has state {:?} other state has {:?} swapping",
state, other
);
info!("Current slot has state {state:?} other state has {other:?} swapping");
ota.set_current_slot(current.next())?;
//we actually booted other slot, than partition table assumes
return Ok(ota.current_slot()?);
@@ -699,17 +697,17 @@ pub async fn esp_set_time(time: DateTime<FixedOffset>) -> FatResult<()> {
}
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize)]
pub struct Moistures{
pub struct Moistures {
pub sensor_a_hz: [f32; PLANT_COUNT],
pub sensor_b_hz: [f32; PLANT_COUNT],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize)]
pub struct DetectionResult {
plant: [DetectionSensorResult; crate::hal::PLANT_COUNT]
plant: [DetectionSensorResult; crate::hal::PLANT_COUNT],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize)]
pub struct DetectionSensorResult{
pub struct DetectionSensorResult {
sensor_a: bool,
sensor_b: bool,
}
}