From 5fd904de9eb8139e021d7fbbd26c1cf13211c370 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Thu, 10 Jul 2025 23:45:21 +0200 Subject: [PATCH] fix(valve): Start movement timer only if timeout is greater than 0 Ensures that the k_timer for valve movement timeouts is only started if the configured max_opening_time_s or max_closing_time_s is greater than 0. This prevents unnecessary timer activations when timeouts are disabled or zero. --- software/lib/valve/valve.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/software/lib/valve/valve.c b/software/lib/valve/valve.c index cfc3a28..a54b7bd 100644 --- a/software/lib/valve/valve.c +++ b/software/lib/valve/valve.c @@ -123,7 +123,9 @@ void valve_open(void) current_state = VALVE_STATE_OPEN; current_movement = VALVE_MOVEMENT_OPENING; /* Security: assume valve open as soons as it starts opening */ - k_timer_start(&movement_timer, K_SECONDS(max_opening_time_s), K_NO_WAIT); + if (max_opening_time_s > 0) { + k_timer_start(&movement_timer, K_SECONDS(max_opening_time_s), K_NO_WAIT); + } k_work_schedule(&valve_work, K_MSEC(100)); } @@ -132,7 +134,9 @@ void valve_close(void) vnd7050aj_reset_fault(vnd7050aj_dev); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, true); - k_timer_start(&movement_timer, K_SECONDS(max_closing_time_s), K_NO_WAIT); + if (max_closing_time_s > 0) { + k_timer_start(&movement_timer, K_SECONDS(max_closing_time_s), K_NO_WAIT); + } current_movement = VALVE_MOVEMENT_CLOSING; k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL); }