adda lot of basic webserver back
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::hal::Box;
|
||||
use alloc::string::String;
|
||||
use async_trait::async_trait;
|
||||
use core::error::Error;
|
||||
use serde::Serialize;
|
||||
|
||||
#[async_trait]
|
||||
@@ -17,6 +18,12 @@ pub trait BatteryInteraction {
|
||||
async fn get_battery_state(&mut self) -> Result<BatteryState, BatteryError>;
|
||||
}
|
||||
|
||||
impl From<BatteryError> for anyhow::Error {
|
||||
fn from(err: BatteryError) -> Self {
|
||||
anyhow::anyhow!(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct BatteryInfo {
|
||||
pub voltage_milli_volt: u16,
|
||||
|
||||
@@ -76,6 +76,7 @@ pub struct Esp<'a> {
|
||||
pub slot: usize,
|
||||
pub next_slot: usize,
|
||||
pub ota_state: OtaImageState,
|
||||
pub slot_addres: u32,
|
||||
}
|
||||
|
||||
pub struct IpInfo {
|
||||
@@ -200,7 +201,7 @@ impl Esp<'_> {
|
||||
let (stack, runner) = embassy_net::new(
|
||||
device,
|
||||
config,
|
||||
mk_static!(StackResources<3>, StackResources::<3>::new()),
|
||||
mk_static!(StackResources<4>, StackResources::<4>::new()),
|
||||
seed,
|
||||
);
|
||||
let stack = mk_static!(Stack, stack);
|
||||
|
||||
@@ -35,7 +35,9 @@ use embassy_net::{IpListenEndpoint, Ipv4Cidr, Runner, Stack, StackResources, Sta
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::once_lock::OnceLock;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_bootloader_esp_idf::partitions::DataPartitionSubType;
|
||||
use esp_bootloader_esp_idf::partitions::{
|
||||
AppPartitionSubType, DataPartitionSubType, PartitionEntry,
|
||||
};
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::gpio::{Input, InputConfig, Io, Pull};
|
||||
use esp_hal::timer::systimer::SystemTimer;
|
||||
@@ -286,6 +288,23 @@ impl PlantHal {
|
||||
println!("current {:?} - next {:?}", current, current.next());
|
||||
let ota_state = ota.current_ota_state()?;
|
||||
|
||||
let current_app = if current.number() == 0 {
|
||||
pt.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::App(
|
||||
AppPartitionSubType::Ota0,
|
||||
))
|
||||
} else {
|
||||
pt.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::App(
|
||||
AppPartitionSubType::Ota1,
|
||||
))
|
||||
};
|
||||
let app_address = match current_app {
|
||||
Result::Ok(part) => match part {
|
||||
None => 0,
|
||||
Some(entry) => entry.offset(),
|
||||
},
|
||||
Err(_) => 0,
|
||||
};
|
||||
|
||||
let mut esp = Esp {
|
||||
rng,
|
||||
controller: Some(controller),
|
||||
@@ -294,6 +313,7 @@ impl PlantHal {
|
||||
mqtt_client: None,
|
||||
storage,
|
||||
slot: current.number(),
|
||||
slot_addres: app_address,
|
||||
next_slot: current.next().number(),
|
||||
ota_state,
|
||||
wall_clock_offset: 0,
|
||||
|
||||
Reference in New Issue
Block a user