feat(valve): Add current measurement callbacks and shell commands
This commit introduces several enhancements to the valve library. - New weak callback functions `valve_current_open_callback` and `valve_current_close_callback` are added to allow the application to monitor the current during valve opening and closing operations. - The `movement_timeout_handler` now correctly sets the valve state to `VALVE_STATE_OPEN` and movement to `VALVE_MOVEMENT_IDLE` upon timeout. - New shell commands `valve open`, `valve close`, and `valve stop` are added for direct control of the valve. - The existing setting commands are reorganized under a `valve set` subcommand, and their names are shortened (e.g., `set_open_t` to `open_t`). - The default configuration for `LIB_MODBUS_SERVER` and `LIB_VALVE` is changed to `n`. Signed-off-by: Eduard Iten <eduard@iten.pro>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
config LIB_VALVE
|
||||
bool "Enable Valve Library"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Enable the Valve Library.
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ static void valve_work_handler(struct k_work *work)
|
||||
|
||||
if (current_movement == VALVE_MOVEMENT_OPENING) {
|
||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, ¤t_ma);
|
||||
LOG_DBG("Current load during opening: %d mA", current_ma);
|
||||
valve_current_open_callback(current_ma);
|
||||
if (current_ma > obstacle_threshold_open_ma) {
|
||||
LOG_ERR(
|
||||
"Obstacle detected during opening (current: %d mA), stopping motor.",
|
||||
@@ -64,7 +64,7 @@ static void valve_work_handler(struct k_work *work)
|
||||
LOG_DBG("Valve finished opening");
|
||||
} else if (current_movement == VALVE_MOVEMENT_CLOSING) {
|
||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, ¤t_ma);
|
||||
LOG_DBG("Current load during closing: %d mA", current_ma);
|
||||
valve_current_close_callback(current_ma);
|
||||
if (current_ma > obstacle_threshold_close_ma) {
|
||||
LOG_ERR(
|
||||
"Obstacle detected during closing (current: %d mA), stopping motor.",
|
||||
@@ -106,7 +106,8 @@ void movement_timeout_handler(struct k_timer *timer)
|
||||
}
|
||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false);
|
||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
|
||||
current_state = VALVE_STATE_CLOSED;
|
||||
current_state = VALVE_STATE_OPEN;
|
||||
current_movement = VALVE_MOVEMENT_IDLE;
|
||||
}
|
||||
|
||||
int valve_init(void)
|
||||
@@ -291,3 +292,13 @@ uint16_t valve_get_obstacle_threshold_close(void)
|
||||
{
|
||||
return obstacle_threshold_close_ma;
|
||||
}
|
||||
|
||||
__weak void valve_current_open_callback(int current_ma)
|
||||
{
|
||||
LOG_DBG("Open current callback: %d mA", current_ma);
|
||||
}
|
||||
|
||||
__weak void valve_current_close_callback(int current_ma)
|
||||
{
|
||||
LOG_DBG("Close current callback: %d mA", current_ma);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user