#include #include #include #include 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 "); 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 "); 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 "); 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 "); 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_set_obstacle_open(const struct shell *sh, size_t argc, char **argv) { if (argc != 2) { shell_print(sh, "Usage: valve set_obstacle_open "); return -EINVAL; } uint16_t current_ma = (uint16_t)atoi(argv[1]); valve_set_obstacle_threshold_open(current_ma); shell_print(sh, "Obstacle threshold (open) set to %u mA.", current_ma); return 0; } static int cmd_valve_set_obstacle_close(const struct shell *sh, size_t argc, char **argv) { if (argc != 2) { shell_print(sh, "Usage: valve set_obstacle_close "); return -EINVAL; } uint16_t current_ma = (uint16_t)atoi(argv[1]); valve_set_obstacle_threshold_close(current_ma); shell_print(sh, "Obstacle 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()); shell_print(sh, "%*s %u mA", label_width, "Obstacle Threshold (Open):", valve_get_obstacle_threshold_open()); shell_print(sh, "%*s %u mA", label_width, "Obstacle Threshold (Close):", valve_get_obstacle_threshold_close()); return 0; } static int cmd_valve_open(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); ARG_UNUSED(argv); if (valve_get_movement() != VALVE_MOVEMENT_IDLE) { shell_print(sh, "Valve is already moving."); return -EBUSY; } valve_open(); shell_print(sh, "Valve is opening."); return 0; } static int cmd_valve_close(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); ARG_UNUSED(argv); if (valve_get_movement() != VALVE_MOVEMENT_IDLE) { shell_print(sh, "Valve is already moving."); return -EBUSY; } valve_close(); shell_print(sh, "Valve is closing."); return 0; } static int cmd_valve_stop(const struct shell *sh, size_t argc, char **argv) { ARG_UNUSED(argc); ARG_UNUSED(argv); if (valve_get_movement() == VALVE_MOVEMENT_IDLE) { shell_print(sh, "Valve is already stopped."); return -EINVAL; } valve_stop(); shell_print(sh, "Valve movement stopped."); return 0; } SHELL_STATIC_SUBCMD_SET_CREATE(sub_valve_settings, SHELL_CMD(open_t, NULL, "Set max open time (seconds)", cmd_valve_set_open_t), SHELL_CMD(close_t, NULL, "Set max close time (seconds)", cmd_valve_set_close_t), SHELL_CMD(end_curr_open, NULL, "Set end current threshold for opening (mA)", cmd_valve_set_end_curr_open), SHELL_CMD(end_curr_close, NULL, "Set end current threshold for closing (mA)", cmd_valve_set_end_curr_close), SHELL_CMD(obstacle_curr_open, NULL, "Set obstacle threshold for opening (mA)", cmd_valve_set_obstacle_open), SHELL_CMD(obstacle_curr_close, NULL, "Set obstacle threshold for closing (mA)", cmd_valve_set_obstacle_close), SHELL_SUBCMD_SET_END); SHELL_STATIC_SUBCMD_SET_CREATE(valve_cmds, SHELL_CMD(show, NULL, "Show valve configuration", cmd_valve_show), SHELL_CMD(set, &sub_valve_settings, "Valve settings commands", NULL), SHELL_CMD(open, NULL, "Open the valve", cmd_valve_open), SHELL_CMD(close, NULL, "Close the valve", cmd_valve_close), SHELL_CMD(stop, NULL, "Stop the valve movement", cmd_valve_stop), SHELL_SUBCMD_SET_END); SHELL_CMD_REGISTER(valve, &valve_cmds, "Valve commands", NULL);