firmware streaming

This commit is contained in:
2024-08-11 18:44:24 +02:00
committed by Empire Phoenix
parent 3ece894592
commit 65e5d0d753
13 changed files with 3143 additions and 2851 deletions

View File

@@ -60,6 +60,7 @@ enum WaitType {
FlashError,
NormalConfig,
StayAlive,
StayAliveBtn
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
@@ -227,28 +228,41 @@ fn safe_main() -> anyhow::Result<()> {
println!("cur is {}", cur);
let mut to_config = false;
if board.is_config_reset() {
board.general_fault(true);
println!("Reset config is pressed, waiting 5s");
for _i in 0..25 {
for _i in 0..5 {
board.general_fault(true);
Delay::new_default().delay_ms(50);
Delay::new_default().delay_ms(100);
board.general_fault(false);
Delay::new_default().delay_ms(50);
Delay::new_default().delay_ms(100);
}
if board.is_config_reset() {
println!("Reset config is still pressed, deleting configs and reboot");
match board.remove_configs() {
Ok(case) => {
println!("Succeeded in deleting config {}", case);
to_config = true;
println!("Reset config is still pressed, proceed to config mode");
for _i in 0..25 {
board.general_fault(true);
Delay::new_default().delay_ms(25);
board.general_fault(false);
Delay::new_default().delay_ms(25);
}
if board.is_config_reset() {
println!("Reset config is still pressed, proceed to delete configs");
match board.remove_configs() {
Ok(case) => {
println!("Succeeded in deleting config {}", case);
}
Err(err) => {
println!("Could not remove config files, system borked {}", err);
//terminate main app and freeze
wait_infinity(WaitType::FlashError, Arc::new(AtomicBool::new(false)));
}
}
Err(err) => {
println!("Could not remove config files, system borked {}", err);
//terminate main app and freeze
} else {
wait_infinity(WaitType::FlashError, Arc::new(AtomicBool::new(false)));
}
}
} else {
board.general_fault(false);
@@ -310,7 +324,7 @@ fn safe_main() -> anyhow::Result<()> {
println!("Running logic at europe/berlin {}", europe_time);
let config: Config;
match board.get_config() {
match board.get_config() {
Ok(valid) => {
config = valid;
}
@@ -422,7 +436,9 @@ fn safe_main() -> anyhow::Result<()> {
&mut board,
);
let stay_alive = STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed);
let stay_alive_mqtt = STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed);
let stay_alive = stay_alive_mqtt;
println!("Check stay alive, current state is {}", stay_alive);
let mut did_pump = false;
@@ -442,7 +458,7 @@ fn safe_main() -> anyhow::Result<()> {
"Trying to pump for {}s with pump {} now",
plant_config.pump_time_s, plant
);
if !stay_alive {
if !stay_alive && !to_config {
did_pump = true;
board.any_pump(true)?;
board.store_last_pump_time(plant, cur);
@@ -552,7 +568,15 @@ fn safe_main() -> anyhow::Result<()> {
//is deep sleep
mark_app_valid();
if to_config {
println!("Go to button triggerd stay alive");
drop(board);
let reboot_now = Arc::new(AtomicBool::new(false));
let _webserver = httpd(reboot_now.clone());
wait_infinity(WaitType::StayAliveBtn, reboot_now.clone());
}
if stay_alive {
println!("Go to stay alive move");
drop(board);
let reboot_now = Arc::new(AtomicBool::new(false));
let _webserver = httpd(reboot_now.clone());
@@ -926,12 +950,14 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
WaitType::FlashError => 100_u32,
WaitType::NormalConfig => 500_u32,
WaitType::StayAlive => 1000_u32,
WaitType::StayAliveBtn => 25_u32
};
let led_count = match wait_type {
WaitType::InitialConfig => 8,
WaitType::FlashError => 8,
WaitType::NormalConfig => 4,
WaitType::StayAlive => 2,
WaitType::StayAliveBtn => 5
};
loop {
unsafe {