diff --git a/main.c b/main.c index 7f91441abe08301653f89ab7577ae66dc58461ca..ef3a92a993df665a6e0d73695fa2f5433513f57f 100644 --- a/main.c +++ b/main.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <string.h> #include <signal.h> +#include <time.h> #include "coincellhell/coincellhell.h" #include "options.h" @@ -39,6 +40,7 @@ static void print_commands(void) { puts("Valid commands:"); puts("set [HEATER] [TEMP]\t | set the temperature setpoint of the given heater"); + puts("ramp [HEATER] [TEMP] [SECONDS] | ramp to the given temperature in given seconds"); puts("get [HEATER] [LOCATION]\t | get the temperature of the given heater"); puts("get_setpoint [HEATER]\t | get the temperature setpoint of the given heater"); puts("state\t\t\t | get the state of eatch heater"); @@ -62,6 +64,18 @@ static int convert_string_to_heater_id(const char* str) return id; } +static long convert_string_to_seconds(const char* str) +{ + char* str_end; + long seconds = strtol(str, &str_end, 10); + if(str == str_end || seconds < 0) + { + puts("SECONDS must be a whole nummber above 0"); + return -1; + } + return seconds; +} + static float convert_string_to_temperature(const char* str) { char* str_end; @@ -108,6 +122,26 @@ static int process_commands(char** commands, size_t command_count, struct coince ret = coincellhell_set_temperature(hell, id, temperature); } + else if(strcmp(commands[0], "ramp") == 0) + { + if(command_count < 4) + printf("Usage %s %s [HEATER] [TEMPERATURE] [SECONDS]\n", name, commands[0]); + + int id = convert_string_to_heater_id(commands[1]); + if(id < 0) + return 1; + + float temperature = convert_string_to_temperature(commands[2]); + if(temperature == FLT_MIN) + return 2; + + long seconds = convert_string_to_seconds(commands[3]); + if(seconds < 0) + return 2; + + time_t endtime = time(NULL) + seconds; + ret = coincellhell_set_temperature_ramp(hell, id, endtime, temperature); + } else if(strcmp(commands[0], "get") == 0) { if(command_count == 1)