From 3572b15564c51b23e3f138beb080da4fa411735b Mon Sep 17 00:00:00 2001 From: Empire Phoenix Date: Thu, 24 Apr 2025 01:46:16 +0200 Subject: [PATCH] led pattern, error in flashing if firmeware to large -> watchdog? --- rust/.cargo/config.toml | 1 + rust/Cargo.toml | 6 +----- rust/src/main.rs | 40 ++++++++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml index 12018ac..e1f26aa 100644 --- a/rust/.cargo/config.toml +++ b/rust/.cargo/config.toml @@ -21,5 +21,6 @@ build-std = ["std", "panic_abort"] MCU="esp32c6" # Note: this variable is not used by the pio builder (`cargo build --features pio`) ESP_IDF_VERSION = "v5.2.1" +CHRONO_TZ_TIMEZONE_FILTER="UTC|Europe/Berlin" CARGO_WORKSPACE_DIR = { value = "", relative = true } RUST_BACKTRACE = "full" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a4cfe3b..43d09d6 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -63,14 +63,10 @@ one-wire-bus = "0.1.1" ds323x = "0.6.0" #pure code dependencies -log = { version = "0.4", default-features = false } once_cell = "1.19.0" anyhow = { version = "1.0.75", features = ["std", "backtrace"] } -average = { version = "0.14.1" , features = ["std"] } -bit_field = "0.10.2" strum = { version = "0.27.0", features = ["derive"] } measurements = "0.11.0" -schemars = "0.8.16" #json serde = { version = "1.0.192", features = ["derive"] } @@ -78,7 +74,7 @@ serde_json = "1.0.108" #timezone chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone" , "alloc"] } -chrono-tz = {version="0.8.0", default-features = false} +chrono-tz = {version="0.8.0", default-features = false , features = [ "filter-by-regex" ]} eeprom24x = "0.7.2" url = "2.5.3" crc = "3.2.1" diff --git a/rust/src/main.rs b/rust/src/main.rs index 2d4586d..6cdf2e9 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -910,28 +910,47 @@ fn update_plant_state( fn wait_infinity(wait_type: WaitType, reboot_now: Arc) -> ! { let delay = wait_type.blink_pattern(); - let mut led_count = 8; + let mut pattern_step = 0; + loop { - // TODO implement actually different blink patterns instead of modulating blink duration - if wait_type == WaitType::MissingConfig { - led_count %= 8; - led_count += 1; - }; unsafe { BOARD_ACCESS.lock().unwrap().update_charge_indicator(); - //do not trigger watchdog - for i in 0..8 { - BOARD_ACCESS.lock().unwrap().fault(i, i < led_count); + match wait_type { + WaitType::MissingConfig => { + // Keep existing behavior: circular filling pattern + led_count %= 8; + led_count += 1; + for i in 0..8 { + BOARD_ACCESS.lock().unwrap().fault(i, i < led_count); + } + } + WaitType::ConfigButton => { + // Alternating pattern: 1010 1010 -> 0101 0101 + pattern_step = (pattern_step + 1) % 2; + for i in 0..8 { + BOARD_ACCESS.lock().unwrap().fault(i, (i + pattern_step) % 2 == 0); + } + } + WaitType::MqttConfig => { + // Moving dot pattern + pattern_step = (pattern_step + 1) % 8; + for i in 0..8 { + BOARD_ACCESS.lock().unwrap().fault(i, i == pattern_step); + } + } } + BOARD_ACCESS.lock().unwrap().general_fault(true); vTaskDelay(delay); BOARD_ACCESS.lock().unwrap().general_fault(false); - //TODO move locking outside of loop and drop afterwards + + // Clear all LEDs for i in 0..8 { BOARD_ACCESS.lock().unwrap().fault(i, false); } vTaskDelay(delay); + if wait_type == WaitType::MqttConfig { if !STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed) { reboot_now.store(true, std::sync::atomic::Ordering::Relaxed); @@ -946,6 +965,7 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc) -> ! { } } + fn main() { let result = safe_main(); match result {