refactor(shell): Improve shell command naming and output formatting
- Renamed shell commands in and to be shorter and remove underscores (e.g., to ). - Consolidated get functions into a single show command for both valve and Modbus settings (e.g., , ). - Adjusted output formatting for show commands to be right-aligned and remove horizontal lines for better readability. - Fixed missing getter function implementations in and their declarations in . - Ensured is correctly selected in to make valve shell commands available.
This commit is contained in:
@@ -1 +1 @@
|
||||
zephyr_library()
|
||||
zephyr_library_sources(shell_valve.c)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
config SHELL_VALVE
|
||||
bool "Shell Valve commands"
|
||||
default y
|
||||
depends on SHELL
|
||||
help
|
||||
Enable the shell commands for valve control.
|
||||
default n
|
||||
depends on SHELL
|
||||
depends on LIB_VALVE
|
||||
help
|
||||
Enable the valve shell commands.
|
||||
@@ -3,10 +3,10 @@
|
||||
#include <lib/valve.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int cmd_valve_set_max_open_time(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_open_t(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_max_open_time <seconds>");
|
||||
shell_print(sh, "Usage: valve set_open_t <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -16,17 +16,10 @@ static int cmd_valve_set_max_open_time(const struct shell *sh, size_t argc, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_max_open_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t seconds = valve_get_max_open_time();
|
||||
shell_print(sh, "Max open time: %u seconds.", seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_max_close_time(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_close_t(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_max_close_time <seconds>");
|
||||
shell_print(sh, "Usage: valve set_close_t <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -36,18 +29,10 @@ static int cmd_valve_set_max_close_time(const struct shell *sh, size_t argc, cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_max_close_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t seconds = valve_get_max_close_time();
|
||||
shell_print(sh, "Max close time: %u seconds.", seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_end_current_threshold_open(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_end_curr_open(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_end_current_threshold_open <milliamps>");
|
||||
shell_print(sh, "Usage: valve set_end_curr_open <milliamps>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -57,19 +42,10 @@ static int cmd_valve_set_end_current_threshold_open(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_end_current_threshold_open(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t current_ma = valve_get_end_current_threshold_open();
|
||||
shell_print(sh, "End current threshold (open): %u mA.", current_ma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_end_current_threshold_close(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_end_curr_close(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_end_current_threshold_close <milliamps>");
|
||||
shell_print(sh, "Usage: valve set_end_curr_close <milliamps>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -79,37 +55,38 @@ static int cmd_valve_set_end_current_threshold_close(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_end_current_threshold_close(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_show(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t current_ma = valve_get_end_current_threshold_close();
|
||||
shell_print(sh, "End current threshold (close): %u mA.", current_ma);
|
||||
const int label_width = 30;
|
||||
|
||||
shell_print(sh, "Valve Settings:");
|
||||
shell_print(sh, "%*s %u s", label_width, "Max Open Time:", valve_get_max_open_time());
|
||||
shell_print(sh, "%*s %u s", label_width, "Max Close Time:", valve_get_max_close_time());
|
||||
shell_print(sh,
|
||||
"%*s %u mA",
|
||||
label_width,
|
||||
"End Current Threshold (Open):",
|
||||
valve_get_end_current_threshold_open());
|
||||
shell_print(sh,
|
||||
"%*s %u mA",
|
||||
label_width,
|
||||
"End Current Threshold (Close):",
|
||||
valve_get_end_current_threshold_close());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_valve_settings,
|
||||
SHELL_CMD(set_max_open_time, NULL, "Set max open time (seconds)", cmd_valve_set_max_open_time),
|
||||
SHELL_CMD(get_max_open_time, NULL, "Get max open time (seconds)", cmd_valve_get_max_open_time),
|
||||
SHELL_CMD(
|
||||
set_max_close_time, NULL, "Set max close time (seconds)", cmd_valve_set_max_close_time),
|
||||
SHELL_CMD(
|
||||
get_max_close_time, NULL, "Get max close time (seconds)", cmd_valve_get_max_close_time),
|
||||
SHELL_CMD(set_end_current_threshold_open,
|
||||
SHELL_CMD(set_open_t, NULL, "Set max open time (seconds)", cmd_valve_set_open_t),
|
||||
SHELL_CMD(set_close_t, NULL, "Set max close time (seconds)", cmd_valve_set_close_t),
|
||||
SHELL_CMD(set_end_curr_open,
|
||||
NULL,
|
||||
"Set end current threshold for opening (mA)",
|
||||
cmd_valve_set_end_current_threshold_open),
|
||||
SHELL_CMD(get_end_current_threshold_open,
|
||||
NULL,
|
||||
"Get end current threshold for opening (mA)",
|
||||
cmd_valve_get_end_current_threshold_open),
|
||||
SHELL_CMD(set_end_current_threshold_close,
|
||||
cmd_valve_set_end_curr_open),
|
||||
SHELL_CMD(set_end_curr_close,
|
||||
NULL,
|
||||
"Set end current threshold for closing (mA)",
|
||||
cmd_valve_set_end_current_threshold_close),
|
||||
SHELL_CMD(get_end_current_threshold_close,
|
||||
NULL,
|
||||
"Get end current threshold for closing (mA)",
|
||||
cmd_valve_get_end_current_threshold_close),
|
||||
cmd_valve_set_end_curr_close),
|
||||
SHELL_CMD(show, NULL, "Show valve configuration", cmd_valve_show),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(valve, &sub_valve_settings, "Valve commands", NULL);
|
||||
|
||||
Reference in New Issue
Block a user