Skip to content
Snippets Groups Projects
Commit 6a90d7be authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add the ability to start ramps to the cli

parent 8d489866
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment