From c3c23efc9510807d5cbfd9fded18b7e69ce8d46c Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Fri, 11 Jul 2025 11:43:47 +0200 Subject: [PATCH] Cleaning up Signed-off-by: Eduard Iten --- software/Kconfig | 6 ------ .../boards/weact_stm32g431_core.conf | 0 .../boards/weact_stm32g431_core_mcuboot.overlay | 0 software/apps/slave_node/CMakeLists.txt | 2 +- .../boards/weact_stm32g431_core.overlay | 2 +- software/apps/slave_node/prj.conf | 3 --- software/include/lib/valve.h | 3 ++- software/lib/modbus_server/modbus_server.c | 1 + software/lib/valve/Kconfig | 16 +++++++++++++++- software/lib/valve/valve.c | 8 ++++---- 10 files changed, 24 insertions(+), 17 deletions(-) delete mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core.conf delete mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay diff --git a/software/Kconfig b/software/Kconfig index f123eca..25ba986 100644 --- a/software/Kconfig +++ b/software/Kconfig @@ -1,7 +1 @@ rsource "lib/Kconfig" -rsource "lib/shell_valve/Kconfig" - -config SLAVE_NODE_APP - bool "Slave Node Application" - default y - select SHELL_VALVE diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core.conf b/software/apps/firmware_node/boards/weact_stm32g431_core.conf deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay b/software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/slave_node/CMakeLists.txt b/software/apps/slave_node/CMakeLists.txt index 8ce3635..8771a0f 100644 --- a/software/apps/slave_node/CMakeLists.txt +++ b/software/apps/slave_node/CMakeLists.txt @@ -5,4 +5,4 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(slave_node LANGUAGES C) zephyr_include_directories(../../include) add_subdirectory(../../lib lib) -target_sources(app PRIVATE src/main.c) \ No newline at end of file +target_sources(app PRIVATE src/main.c) diff --git a/software/apps/slave_node/boards/weact_stm32g431_core.overlay b/software/apps/slave_node/boards/weact_stm32g431_core.overlay index 4e41f6b..f5a2bf8 100644 --- a/software/apps/slave_node/boards/weact_stm32g431_core.overlay +++ b/software/apps/slave_node/boards/weact_stm32g431_core.overlay @@ -15,7 +15,7 @@ fault-reset-gpios = <&gpiob 3 GPIO_ACTIVE_LOW>; io-channels = <&adc1 1>; r-sense-ohms = <1500>; - k-vcc = <3816>; + k-vcc = <4000>; }; }; diff --git a/software/apps/slave_node/prj.conf b/software/apps/slave_node/prj.conf index b11234f..20ab1e4 100644 --- a/software/apps/slave_node/prj.conf +++ b/software/apps/slave_node/prj.conf @@ -26,6 +26,3 @@ CONFIG_MODBUS_BUFFER_SIZE=256 # Enable VND7050AJ CONFIG_VND7050AJ=y -CONFIG_LOG_VALVE_LEVEL=4 -CONFIG_VALVE_OBSTACLE_THRESHOLD_OPEN_MA=200 -CONFIG_VALVE_OBSTACLE_THRESHOLD_CLOSE_MA=200 \ No newline at end of file diff --git a/software/include/lib/valve.h b/software/include/lib/valve.h index 0b50abd..4738e3b 100644 --- a/software/include/lib/valve.h +++ b/software/include/lib/valve.h @@ -15,7 +15,8 @@ #define VALVE_CHANNEL_OPEN 0 #define VALVE_CHANNEL_CLOSE 1 -#define VALVE_ENDPOSITION_CHECK_INTERVAL K_MSEC(100) +#define VALVE_CURRENT_CHECK_INTERVAL K_MSEC(CONFIG_VALVE_INTERVALL_CURRENT_CHECK_MS) +#define VALVE_INITIAL_CURRENT_CHECK_INTERVAL K_MSEC(CONFIG_VALVE_INITIAL_INTERVALL_CURRENT_CHECK_MS) /** * @brief Represents the static state of the valve (open or closed). diff --git a/software/lib/modbus_server/modbus_server.c b/software/lib/modbus_server/modbus_server.c index e84a755..b1489dd 100644 --- a/software/lib/modbus_server/modbus_server.c +++ b/software/lib/modbus_server/modbus_server.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/software/lib/valve/Kconfig b/software/lib/valve/Kconfig index 2dce57d..0bc1d8b 100644 --- a/software/lib/valve/Kconfig +++ b/software/lib/valve/Kconfig @@ -12,6 +12,20 @@ config LOG_VALVE_LEVEL Set the log level for the Valve Library. 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug +config VALVE_INTERVALL_CURRENT_CHECK_MS + int "Interval Current Check (ms)" + default 100 + help + Set the interval in milliseconds for checking the motor current + during valve operation. This is used to detect obstacles. + +config VALVE_INITIAL_INTERVALL_CURRENT_CHECK_MS + int "Initial Current Check (ms)" + default 200 + help + Set the initial delay in milliseconds before the first current check + after starting the valve operation. This allows the motor to stabilize. + config VALVE_OBSTACLE_THRESHOLD_OPEN_MA int "Obstacle Threshold Open (mA)" default 200 @@ -25,7 +39,7 @@ config VALVE_OBSTACLE_THRESHOLD_CLOSE_MA default 200 help Set the current threshold in milliamps for obstacle detection - during valve closing. If the motor current exceeds this value, + during vaslve closing. If the motor current exceeds this value, an obstacle is detected and the valve stops. endif # LIB_VALVE diff --git a/software/lib/valve/valve.c b/software/lib/valve/valve.c index 311de01..f6f3e5a 100644 --- a/software/lib/valve/valve.c +++ b/software/lib/valve/valve.c @@ -58,7 +58,7 @@ static void valve_work_handler(struct k_work *work) valve_stop(); return; } else if (current_ma > end_current_threshold_open_ma) { - k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL); + k_work_schedule(&valve_work, VALVE_CURRENT_CHECK_INTERVAL); return; } LOG_DBG("Valve finished opening"); @@ -73,7 +73,7 @@ static void valve_work_handler(struct k_work *work) valve_stop(); return; } else if (current_ma > end_current_threshold_close_ma) { - k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL); + k_work_schedule(&valve_work, VALVE_CURRENT_CHECK_INTERVAL); return; } current_state = VALVE_STATE_CLOSED; @@ -158,7 +158,7 @@ void valve_open(void) 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)); + k_work_schedule(&valve_work, VALVE_INITIAL_CURRENT_CHECK_INTERVAL); } void valve_close(void) @@ -171,7 +171,7 @@ void valve_close(void) 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); + k_work_schedule(&valve_work, VALVE_INITIAL_CURRENT_CHECK_INTERVAL); } void valve_stop(void)