Improve error handling, ensure robust defaults, and eliminate unsafe unwraps/expectations across modules.
This commit is contained in:
@@ -150,7 +150,6 @@ pub trait BoardInteraction<'a> {
|
||||
async fn set_charge_indicator(&mut self, charging: bool) -> Result<(), FatError>;
|
||||
async fn deep_sleep(&mut self, duration_in_ms: u64) -> !;
|
||||
|
||||
|
||||
fn is_day(&self) -> bool;
|
||||
//should be multsampled
|
||||
async fn light(&mut self, enable: bool) -> FatResult<()>;
|
||||
@@ -165,7 +164,7 @@ pub trait BoardInteraction<'a> {
|
||||
async fn get_mptt_current(&mut self) -> FatResult<Current>;
|
||||
async fn can_power(&mut self, state: bool) -> FatResult<()>;
|
||||
|
||||
async fn backup_config(&mut self, config: &PlantControllerConfig) -> FatResult<()>;
|
||||
async fn backup_config(&mut self, config: &PlantControllerConfig) -> FatResult<()>;
|
||||
async fn read_backup(&mut self) -> FatResult<PlantControllerConfig>;
|
||||
async fn backup_info(&mut self) -> FatResult<BackupHeader>;
|
||||
|
||||
@@ -271,12 +270,17 @@ impl PlantHal {
|
||||
let rng = Rng::new();
|
||||
let esp_wifi_ctrl = &*mk_static!(
|
||||
Controller<'static>,
|
||||
init().expect("Could not init wifi controller")
|
||||
init().map_err(|e| FatError::String {
|
||||
error: format!("Could not init wifi controller: {:?}", e)
|
||||
})?
|
||||
);
|
||||
|
||||
let (controller, interfaces) =
|
||||
esp_radio::wifi::new(esp_wifi_ctrl, peripherals.WIFI, Default::default())
|
||||
.expect("Could not init wifi");
|
||||
esp_radio::wifi::new(esp_wifi_ctrl, peripherals.WIFI, Default::default()).map_err(
|
||||
|e| FatError::String {
|
||||
error: format!("Could not init wifi: {:?}", e),
|
||||
},
|
||||
)?;
|
||||
|
||||
let pcnt_module = Pcnt::new(peripherals.PCNT);
|
||||
|
||||
@@ -330,7 +334,7 @@ impl PlantHal {
|
||||
pt.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::Data(
|
||||
DataPartitionSubType::Ota,
|
||||
))?
|
||||
.expect("No OTA data partition found")
|
||||
.context("No OTA data partition found")?
|
||||
);
|
||||
|
||||
let ota_data = mk_static!(
|
||||
@@ -375,7 +379,7 @@ impl PlantHal {
|
||||
.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::Data(
|
||||
DataPartitionSubType::LittleFs,
|
||||
))?
|
||||
.expect("Data partition with littlefs not found");
|
||||
.context("Data partition with littlefs not found")?;
|
||||
let data_partition = mk_static!(PartitionEntry, data_partition);
|
||||
|
||||
let data = mk_static!(
|
||||
@@ -399,7 +403,8 @@ impl PlantHal {
|
||||
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
let fs = Arc::new(Mutex::new(
|
||||
lfs2Filesystem::mount(alloc, lfs2filesystem).expect("Could not mount lfs2 filesystem"),
|
||||
lfs2Filesystem::mount(alloc, lfs2filesystem)
|
||||
.context("Could not mount lfs2 filesystem")?,
|
||||
));
|
||||
|
||||
let uart0 =
|
||||
@@ -493,7 +498,9 @@ impl PlantHal {
|
||||
RefCell<I2c<Blocking>>,
|
||||
> = CriticalSectionMutex::new(RefCell::new(i2c));
|
||||
|
||||
I2C_DRIVER.init(i2c_bus).expect("Could not init i2c driver");
|
||||
I2C_DRIVER.init(i2c_bus).map_err(|_| FatError::String {
|
||||
error: "Could not init i2c driver".to_string(),
|
||||
})?;
|
||||
|
||||
let i2c_bus = I2C_DRIVER.get().await;
|
||||
let rtc_device = I2cDevice::new(i2c_bus);
|
||||
@@ -655,7 +662,7 @@ pub fn next_partition(current: AppPartitionSubType) -> FatResult<AppPartitionSub
|
||||
|
||||
pub async fn esp_time() -> DateTime<Utc> {
|
||||
let guard = TIME_ACCESS.get().await.lock().await;
|
||||
DateTime::from_timestamp_micros(guard.current_time_us() as i64).unwrap()
|
||||
DateTime::from_timestamp_micros(guard.current_time_us() as i64).unwrap_or(DateTime::UNIX_EPOCH)
|
||||
}
|
||||
|
||||
pub async fn esp_set_time(time: DateTime<FixedOffset>) -> FatResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user