docs: Add Doxygen comment for movement_timeout_handler

feat: Configure valve logging via Kconfig

This commit adds a Kconfig option  to control the log level of the valve library.
- : Added the new Kconfig option.
- : Updated  to use  and adjusted log levels for debug messages.
- : Enabled debug logging for the valve library by setting .

refactor: Adjust k-vcc calibration value for VND7050AJ

Updated the  calibration value in  from 4139 to 3816 for the VND7050AJ driver.
Signed-off-by: Eduard Iten <eduard@iten.pro>
This commit is contained in:
Eduard Iten 2025-07-11 08:07:41 +02:00
parent 76d0d0647c
commit d6fb501594
4 changed files with 33 additions and 10 deletions

View File

@ -15,7 +15,7 @@
fault-reset-gpios = <&gpiob 3 GPIO_ACTIVE_LOW>; fault-reset-gpios = <&gpiob 3 GPIO_ACTIVE_LOW>;
io-channels = <&adc1 1>; io-channels = <&adc1 1>;
r-sense-ohms = <1500>; r-sense-ohms = <1500>;
k-vcc = <4139>; k-vcc = <3816>;
}; };
}; };

View File

@ -26,4 +26,4 @@ CONFIG_MODBUS_BUFFER_SIZE=256
# Enable VND7050AJ # Enable VND7050AJ
CONFIG_VND7050AJ=y CONFIG_VND7050AJ=y
CONFIG_LOG_VALVE_LEVEL=4

View File

@ -3,3 +3,12 @@ config LIB_VALVE
default y default y
help help
Enable the Valve Library. Enable the Valve Library.
if LIB_VALVE
config LOG_VALVE_LEVEL
int "Valve Log Level"
default 3
help
Set the log level for the Valve Library.
0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug
endif # LIB_VALVE

View File

@ -21,15 +21,15 @@
#endif #endif
const struct device *vnd7050aj_dev = DEVICE_DT_GET(VND_NODE); const struct device *vnd7050aj_dev = DEVICE_DT_GET(VND_NODE);
LOG_MODULE_REGISTER(valve, LOG_LEVEL_INF); LOG_MODULE_REGISTER(valve, CONFIG_LOG_VALVE_LEVEL);
static enum valve_state current_state = VALVE_STATE_OPEN; static enum valve_state current_state = VALVE_STATE_OPEN;
static enum valve_movement current_movement = VALVE_MOVEMENT_IDLE; static enum valve_movement current_movement = VALVE_MOVEMENT_IDLE;
static uint16_t max_opening_time_s = 10; static uint16_t max_opening_time_s = 10;
static uint16_t max_closing_time_s = 10; static uint16_t max_closing_time_s = 10;
static uint16_t end_current_threshold_open_ma = 10; // Default value for open static uint16_t end_current_threshold_open_ma = 10;
static uint16_t end_current_threshold_close_ma = 10; // Default value for close static uint16_t end_current_threshold_close_ma = 10;
static struct k_work_delayable valve_work; // Work item for scheduling valve movement timeouts static struct k_work_delayable valve_work;
static struct k_timer movement_timer; static struct k_timer movement_timer;
/** /**
@ -47,36 +47,39 @@ static void valve_work_handler(struct k_work *work)
if (current_movement == VALVE_MOVEMENT_OPENING) { if (current_movement == VALVE_MOVEMENT_OPENING) {
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, &current_ma); vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, &current_ma);
LOG_DBG("Current load during opening: %d mA", current_ma);
if (current_ma > VALVE_OBSTACLE_THRESHOLD_OPEN_MA) { if (current_ma > VALVE_OBSTACLE_THRESHOLD_OPEN_MA) {
LOG_ERR( LOG_ERR(
"Obstacle detected during opening (current: %d mA), stopping motor.", "Obstacle detected during opening (current: %d mA), stopping motor.",
current_ma); current_ma);
current_movement = VALVE_MOVEMENT_ERROR; current_movement = VALVE_MOVEMENT_ERROR;
valve_stop(); valve_stop();
return; goto work_handler_cleanup;
} else if (current_ma > end_current_threshold_open_ma) { } else if (current_ma > end_current_threshold_open_ma) {
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL); k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
return; return;
} }
LOG_INF("Valve finished opening"); LOG_DBG("Valve finished opening");
} else if (current_movement == VALVE_MOVEMENT_CLOSING) { } else if (current_movement == VALVE_MOVEMENT_CLOSING) {
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, &current_ma); vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, &current_ma);
LOG_DBG("Current load during closing: %d mA", current_ma);
if (current_ma > VALVE_OBSTACLE_THRESHOLD_CLOSE_MA) { if (current_ma > VALVE_OBSTACLE_THRESHOLD_CLOSE_MA) {
LOG_ERR( LOG_ERR(
"Obstacle detected during closing (current: %d mA), stopping motor.", "Obstacle detected during closing (current: %d mA), stopping motor.",
current_ma); current_ma);
current_movement = VALVE_MOVEMENT_ERROR; current_movement = VALVE_MOVEMENT_ERROR;
valve_stop(); valve_stop();
return; goto work_handler_cleanup;
} else if (current_ma > end_current_threshold_close_ma) { } else if (current_ma > end_current_threshold_close_ma) {
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL); k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
return; return;
} }
current_state = VALVE_STATE_CLOSED; current_state = VALVE_STATE_CLOSED;
LOG_INF("Valve finished closing"); LOG_DBG("Valve finished closing");
} }
current_movement = VALVE_MOVEMENT_IDLE; current_movement = VALVE_MOVEMENT_IDLE;
work_handler_cleanup:
// Reset the movement timer // Reset the movement timer
k_timer_stop(&movement_timer); k_timer_stop(&movement_timer);
@ -84,6 +87,15 @@ static void valve_work_handler(struct k_work *work)
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
} }
/**
* @brief Timer handler for valve movement timeouts.
*
* This function is called when the maximum allowed time for valve movement
* (opening or closing) has been reached. It stops the valve motor, cancels
* any pending end-position checks, and sets the movement status to error.
*
* @param timer Pointer to the k_timer instance that expired.
*/
void movement_timeout_handler(struct k_timer *timer) void movement_timeout_handler(struct k_timer *timer)
{ {
// Stop the end position check if the timer expires // Stop the end position check if the timer expires
@ -131,6 +143,7 @@ int valve_init(void)
void valve_open(void) void valve_open(void)
{ {
LOG_DBG("Opening valve");
vnd7050aj_reset_fault(vnd7050aj_dev); vnd7050aj_reset_fault(vnd7050aj_dev);
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, true); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, true);
@ -145,6 +158,7 @@ void valve_open(void)
void valve_close(void) void valve_close(void)
{ {
LOG_DBG("Closing valve");
vnd7050aj_reset_fault(vnd7050aj_dev); vnd7050aj_reset_fault(vnd7050aj_dev);
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false);
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, true); vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, true);