93 lines
2.8 KiB
C
93 lines
2.8 KiB
C
#include <zephyr/kernel.h>
|
|
#include <zephyr/shell/shell.h>
|
|
#include <lib/valve.h>
|
|
#include <stdlib.h>
|
|
|
|
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_open_t <seconds>");
|
|
return -EINVAL;
|
|
}
|
|
|
|
uint16_t seconds = (uint16_t)atoi(argv[1]);
|
|
valve_set_max_open_time(seconds);
|
|
shell_print(sh, "Max open time set to %u seconds.", seconds);
|
|
return 0;
|
|
}
|
|
|
|
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_close_t <seconds>");
|
|
return -EINVAL;
|
|
}
|
|
|
|
uint16_t seconds = (uint16_t)atoi(argv[1]);
|
|
valve_set_max_close_time(seconds);
|
|
shell_print(sh, "Max close time set to %u seconds.", seconds);
|
|
return 0;
|
|
}
|
|
|
|
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_curr_open <milliamps>");
|
|
return -EINVAL;
|
|
}
|
|
|
|
uint16_t current_ma = (uint16_t)atoi(argv[1]);
|
|
valve_set_end_current_threshold_open(current_ma);
|
|
shell_print(sh, "End current threshold (open) set to %u mA.", current_ma);
|
|
return 0;
|
|
}
|
|
|
|
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_curr_close <milliamps>");
|
|
return -EINVAL;
|
|
}
|
|
|
|
uint16_t current_ma = (uint16_t)atoi(argv[1]);
|
|
valve_set_end_current_threshold_close(current_ma);
|
|
shell_print(sh, "End current threshold (close) set to %u mA.", current_ma);
|
|
return 0;
|
|
}
|
|
|
|
static int cmd_valve_show(const struct shell *sh, size_t argc, char **argv)
|
|
{
|
|
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_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_curr_open),
|
|
SHELL_CMD(set_end_curr_close,
|
|
NULL,
|
|
"Set end current threshold for closing (mA)",
|
|
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);
|