config stuff

This commit is contained in:
2024-11-19 18:05:51 +01:00
parent bfcf5e150c
commit 8218c4b9a6
6 changed files with 330 additions and 175 deletions

View File

@@ -51,7 +51,8 @@ mod webserver {
#[derive(Serialize, Deserialize, Debug, PartialEq)]
enum WaitType {
MissingConfig,
Config,
ConfigButton,
MqttConfig,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
@@ -345,7 +346,7 @@ fn safe_main() -> anyhow::Result<()> {
drop(board);
let reboot_now = Arc::new(AtomicBool::new(false));
let _webserver = httpd(reboot_now.clone());
wait_infinity(WaitType::Config, reboot_now.clone());
wait_infinity(WaitType::ConfigButton, reboot_now.clone());
}
let tank_state = determine_tank_state(&mut board, &config);
@@ -528,7 +529,7 @@ fn safe_main() -> anyhow::Result<()> {
drop(board);
let reboot_now = Arc::new(AtomicBool::new(false));
let _webserver = httpd(reboot_now.clone());
wait_infinity(WaitType::Config, reboot_now.clone());
wait_infinity(WaitType::MqttConfig, reboot_now.clone());
}
unsafe { esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64) };
@@ -895,7 +896,8 @@ fn update_plant_state(
fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
let delay = match wait_type {
WaitType::MissingConfig => 500_u32,
WaitType::Config => 100_u32,
WaitType::ConfigButton => 100_u32,
WaitType::MqttConfig => 200_u32,
};
let mut led_count = 8;
loop {
@@ -919,7 +921,8 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
vTaskDelay(delay);
match wait_type {
WaitType::MissingConfig => {}
WaitType::Config => {
WaitType::ConfigButton => {}
WaitType::MqttConfig => {
if !STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed) {
reboot_now.store(true, std::sync::atomic::Ordering::Relaxed);
}