more work

This commit is contained in:
Bob 2014-02-09 22:46:47 +01:00
parent 3ab4903c91
commit abbe6b2b38

View file

@ -55,11 +55,13 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[])
{
{"on-command", required_argument, NULL, 'n'},
{"off-command", required_argument, NULL, 'f'},
{"switch-time", required_argument, NULL, 's'},
{"trigger-level", required_argument, NULL, 't'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
const char* shortoptions = "n:f:h";
const char* shortoptions = "n:f:s:t:h";
int c;
int optionindex = 0;
while ((c = getopt_long(argc, argv, shortoptions, longoptions, &optionindex)) != -1)
@ -77,6 +79,28 @@ CAmpSwitch::CAmpSwitch(int argc, char *argv[])
PrintHelpMessage();
exit(1);
}
else if (c == 's')
{
float switchtime;
if (sscanf(optarg, "%f", &switchtime) != 1)
{
printf("ERROR: Wrong value for switch-time: \"%s\"\n", optarg);
exit(1);
}
m_switchtime = switchtime;
}
else if (c == 't')
{
float triggerlevel;
if (sscanf(optarg, "%f", &triggerlevel) != 1)
{
printf("ERROR: Wrong value for trigger-level: \"%s\"\n", optarg);
exit(1);
}
m_triggerlevel = triggerlevel;
}
else if (c == '?')
{
exit(1);
@ -154,6 +178,8 @@ void CAmpSwitch::PrintHelpMessage()
"\n"
" -n, --on-command command to execute when switching on\n"
" -f, --off-command command to execute when switching off\n"
" -s, --switch-time minimum number of seconds between switches\n"
" -t, --trigger-level absolute value of trigger level\n"
" -h, --help print this message\n"
"\n"
);