feat: Make valve obstacle detection parameters configurable via settings and shell
This commit introduces configurable obstacle detection thresholds for the valve, allowing them to be set and persisted via the Zephyr settings subsystem and controlled through the shell and Modbus tool.
- `software/lib/valve/Kconfig`: Added new Kconfig options `VALVE_OBSTACLE_THRESHOLD_OPEN_MA` and `VALVE_OBSTACLE_THRESHOLD_CLOSE_MA` for compile-time configuration and default values.
- `software/include/lib/valve.h`: Removed hardcoded defines and added API functions for setting and getting obstacle thresholds.
- `software/lib/valve/valve.c`:
- Updated `valve_work_handler` to use the new configurable obstacle thresholds.
- Integrated loading and saving of obstacle thresholds via the settings subsystem in `valve_init`.
- Implemented the new setter and getter functions for obstacle thresholds.
- Updated the `LOG_INF` message in `valve_init` to display the new obstacle threshold values.
- `software/apps/slave_node/prj.conf`: Added default values for the new Kconfig options.
- `software/lib/shell_valve/shell_valve.c`: Added new shell commands `valve set_obstacle_open` and `valve set_obstacle_close` to modify the obstacle thresholds, and updated `valve show` to display them.
- `software/tools/modbus_tool/modbus_tool.py`:
- Defined new Modbus holding registers (`REG_HOLDING_OBSTACLE_THRESHOLD_OPEN_MA`, `REG_HOLDING_OBSTACLE_THRESHOLD_CLOSE_MA`).
- Updated `poll_status` to read these new registers.
- Modified the `main_menu` to include "Set Obstacle Open" and "Set Obstacle Close" options in the settings menu, allowing users to view and modify these parameters.
- `software/lib/modbus_server/modbus_server.c`:
- Updated `holding_reg_rd` to read the new obstacle threshold registers.
- Updated `holding_reg_wr` to write to the new obstacle threshold registers.
- Removed incorrect `REG_HOLDING_END_CURRENT_THRESHOLD_OPEN_MA` and `REG_HOLDING_END_CURRENT_THRESHOLD_CLOSE_MA` cases from `input_reg_rd`.
- `software/include/lib/modbus_registers.h`: Created a new header file to centralize Modbus register definitions, which were previously hardcoded in `modbus_tool.py`.
Signed-off-by: Eduard Iten <eduard@iten.pro>
This commit is contained in:
35
software/include/lib/modbus_registers.h
Normal file
35
software/include/lib/modbus_registers.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef MODBUS_REGISTERS_H
|
||||
#define MODBUS_REGISTERS_H
|
||||
|
||||
// Input Registers (Read-Only)
|
||||
#define REG_INPUT_VALVE_STATE_MOVEMENT 0x0000
|
||||
#define REG_INPUT_MOTOR_OPEN_CURRENT_MA 0x0001
|
||||
#define REG_INPUT_MOTOR_CLOSE_CURRENT_MA 0x0002
|
||||
#define REG_INPUT_DIGITAL_INPUTS_STATE 0x0020
|
||||
#define REG_INPUT_BUTTON_EVENTS 0x0021
|
||||
#define REG_INPUT_FIRMWARE_VERSION_MAJOR_MINOR 0x00F0
|
||||
#define REG_INPUT_FIRMWARE_VERSION_PATCH 0x00F1
|
||||
#define REG_INPUT_DEVICE_STATUS 0x00F2
|
||||
#define REG_INPUT_UPTIME_SECONDS_LOW 0x00F3
|
||||
#define REG_INPUT_UPTIME_SECONDS_HIGH 0x00F4
|
||||
#define REG_INPUT_SUPPLY_VOLTAGE_MV 0x00F5
|
||||
#define REG_INPUT_FWU_LAST_CHUNK_CRC 0x0100
|
||||
|
||||
// Holding Registers (Read-Write)
|
||||
#define REG_HOLDING_VALVE_COMMAND 0x0000
|
||||
#define REG_HOLDING_MAX_OPENING_TIME_S 0x0001
|
||||
#define REG_HOLDING_MAX_CLOSING_TIME_S 0x0002
|
||||
#define REG_HOLDING_END_CURRENT_THRESHOLD_OPEN_MA 0x0003
|
||||
#define REG_HOLDING_END_CURRENT_THRESHOLD_CLOSE_MA 0x0004
|
||||
#define REG_HOLDING_OBSTACLE_THRESHOLD_OPEN_MA 0x0005
|
||||
#define REG_HOLDING_OBSTACLE_THRESHOLD_CLOSE_MA 0x0006
|
||||
#define REG_HOLDING_DIGITAL_OUTPUTS_STATE 0x0010
|
||||
#define REG_HOLDING_WATCHDOG_TIMEOUT_S 0x00F0
|
||||
#define REG_HOLDING_DEVICE_RESET 0x00F1
|
||||
#define REG_HOLDING_FWU_COMMAND 0x0100
|
||||
#define REG_HOLDING_FWU_CHUNK_OFFSET_LOW 0x0101
|
||||
#define REG_HOLDING_FWU_CHUNK_OFFSET_HIGH 0x0102
|
||||
#define REG_HOLDING_FWU_CHUNK_SIZE 0x0103
|
||||
#define REG_HOLDING_FWU_DATA_BUFFER 0x0180
|
||||
|
||||
#endif // MODBUS_REGISTERS_H
|
||||
@@ -17,9 +17,6 @@
|
||||
#define VALVE_CHANNEL_CLOSE 1
|
||||
#define VALVE_ENDPOSITION_CHECK_INTERVAL K_MSEC(100)
|
||||
|
||||
#define VALVE_OBSTACLE_THRESHOLD_OPEN_MA 200
|
||||
#define VALVE_OBSTACLE_THRESHOLD_CLOSE_MA 200
|
||||
|
||||
/**
|
||||
* @brief Represents the static state of the valve (open or closed).
|
||||
*/
|
||||
@@ -164,4 +161,33 @@ int32_t valve_get_vnd_temp(void);
|
||||
* @return The voltage in millivolts.
|
||||
*/
|
||||
int32_t valve_get_vnd_voltage(void);
|
||||
#endif // VALVE_H
|
||||
|
||||
/**
|
||||
* @brief Sets the current threshold for obstacle detection during opening.
|
||||
*
|
||||
* @param current_ma The current threshold in milliamps.
|
||||
*/
|
||||
void valve_set_obstacle_threshold_open(uint16_t current_ma);
|
||||
|
||||
/**
|
||||
* @brief Sets the current threshold for obstacle detection during closing.
|
||||
*
|
||||
* @param current_ma The current threshold in milliamps.
|
||||
*/
|
||||
void valve_set_obstacle_threshold_close(uint16_t current_ma);
|
||||
|
||||
/**
|
||||
* @brief Gets the current threshold for obstacle detection during opening.
|
||||
*
|
||||
* @return The current threshold in milliamps.
|
||||
*/
|
||||
uint16_t valve_get_obstacle_threshold_open(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the current threshold for obstacle detection during closing.
|
||||
*
|
||||
* @return The current threshold in milliamps.
|
||||
*/
|
||||
uint16_t valve_get_obstacle_threshold_close(void);
|
||||
|
||||
#endif // VALVE_H
|
||||
Reference in New Issue
Block a user