add ability to override frequency per plant and adjust timezone, fix missing workhour for plants
This commit is contained in:
@@ -5,8 +5,8 @@ use std::{
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use chrono::{DateTime, Datelike, Timelike};
|
||||
use chrono_tz::{Europe::Berlin, Tz};
|
||||
|
||||
use chrono_tz::Tz::UTC;
|
||||
use chrono_tz::Tz;
|
||||
use esp_idf_hal::delay::Delay;
|
||||
use esp_idf_sys::{
|
||||
esp_ota_get_app_partition_count, esp_ota_get_running_partition, esp_ota_get_state_partition,
|
||||
@@ -32,8 +32,6 @@ pub mod util;
|
||||
use plant_state::PlantState;
|
||||
use tank::*;
|
||||
|
||||
const TIME_ZONE: Tz = Berlin;
|
||||
|
||||
pub static BOARD_ACCESS: Lazy<Mutex<PlantCtrlBoard>> = Lazy::new(|| PlantHal::create().unwrap());
|
||||
pub static STAY_ALIVE: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
|
||||
|
||||
@@ -280,11 +278,20 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let timezone_time = cur.with_timezone(&TIME_ZONE);
|
||||
let timezone = match &config.timezone {
|
||||
Some(tz_str) => tz_str.parse::<Tz>().unwrap_or_else(|_| {
|
||||
println!("Invalid timezone '{}', falling back to UTC", tz_str);
|
||||
UTC
|
||||
}),
|
||||
None => UTC, // Fallback to UTC if no timezone is set
|
||||
};
|
||||
|
||||
|
||||
let timezone_time = cur.with_timezone(&timezone);
|
||||
println!(
|
||||
"Running logic at utc {} and {} {}",
|
||||
cur,
|
||||
TIME_ZONE.name(),
|
||||
timezone.name(),
|
||||
timezone_time
|
||||
);
|
||||
|
||||
@@ -579,28 +586,51 @@ fn publish_battery_state(
|
||||
|
||||
fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
|
||||
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);
|
||||
let mut lock = BOARD_ACCESS.lock().unwrap();
|
||||
lock.update_charge_indicator();
|
||||
match wait_type {
|
||||
WaitType::MissingConfig => {
|
||||
// Keep existing behavior: circular filling pattern
|
||||
led_count %= 8;
|
||||
led_count += 1;
|
||||
for i in 0..8 {
|
||||
lock.fault(i, i < led_count);
|
||||
}
|
||||
}
|
||||
WaitType::ConfigButton => {
|
||||
// Alternating pattern: 1010 1010 -> 0101 0101
|
||||
pattern_step = (pattern_step + 1) % 2;
|
||||
for i in 0..8 {
|
||||
lock.fault(i, (i + pattern_step) % 2 == 0);
|
||||
}
|
||||
}
|
||||
WaitType::MqttConfig => {
|
||||
// Moving dot pattern
|
||||
pattern_step = (pattern_step + 1) % 8;
|
||||
for i in 0..8 {
|
||||
lock.fault(i, i == pattern_step);
|
||||
}
|
||||
}
|
||||
}
|
||||
BOARD_ACCESS.lock().unwrap().general_fault(true);
|
||||
|
||||
lock.general_fault(true);
|
||||
drop(lock);
|
||||
vTaskDelay(delay);
|
||||
BOARD_ACCESS.lock().unwrap().general_fault(false);
|
||||
//TODO move locking outside of loop and drop afterwards
|
||||
let mut lock = BOARD_ACCESS.lock().unwrap();
|
||||
lock.general_fault(false);
|
||||
|
||||
// Clear all LEDs
|
||||
for i in 0..8 {
|
||||
BOARD_ACCESS.lock().unwrap().fault(i, false);
|
||||
lock.fault(i, false);
|
||||
}
|
||||
drop(lock);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user