From 64a97fa04817309bce61391baadf65a2d39baa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Mar 2021 21:56:21 +0100 Subject: [PATCH] Issue #26: Add overtemp function to shell --- stm-firmware/shell.c | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 8e31918..9405c97 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -641,6 +641,48 @@ shellmatta_retCode_t shell_cmd_update(const shellmatta_handle_t handle, const ch return SHELLMATTA_OK; } +shellmatta_retCode_t shell_cmd_overtemp_cfg(const shellmatta_handle_t handle, const char *args, uint32_t len) +{ + float overtemp_lim; + shellmatta_retCode_t ret; + char *argument; + uint32_t arg_length; + char option; + bool temp_passed = false; + bool persistent = false; + + static const shellmatta_opt_long_t options[] = { + {"persistent", 'p', SHELLMATTA_OPT_ARG_NONE}, + {NULL, '\0', SHELLMATTA_OPT_ARG_NONE}, + }; + + do { + ret = shellmatta_opt_long(handle, options, &option, &argument, &arg_length); + if (ret != SHELLMATTA_OK) + break; + switch (option) { + case 'p': + persistent = true; + break; + case '\0': + temp_passed = true; + overtemp_lim = strtof(argument, NULL); + break; + } + } while (1); + + if (temp_passed) { + safety_controller_set_overtemp_limit(overtemp_lim); + if (persistent) + settings_save_overtemp_limit(overtemp_lim, true); + } + + overtemp_lim = safety_controller_get_overtemp_limit(); + shellmatta_printf(handle, "Overtemperature configured for: %.1f °C\r\n", overtemp_lim); + + return ret; +} + //typedef struct shellmatta_cmd //{ // char *cmd; /**< command name */ @@ -650,7 +692,7 @@ shellmatta_retCode_t shell_cmd_update(const shellmatta_handle_t handle, const ch // shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */ // struct shellmatta_cmd *next; /**< pointer to next command or NULL */ //} shellmatta_cmd_t; -static shellmatta_cmd_t cmd[19] = { +static shellmatta_cmd_t cmd[20] = { { .cmd = "version", .cmdAlias = "ver", @@ -801,8 +843,16 @@ static shellmatta_cmd_t cmd[19] = { .helpText = "Update Firmware", .usageText = "", .cmdFct = shell_cmd_update, - .next = NULL, + .next = &cmd[19], + }, + { + .cmd = "overtemp", + .cmdAlias = NULL, + .helpText = "Overtemperature Config", + .usageText = "", + .cmdFct = shell_cmd_overtemp_cfg, + .next = NULL, } };