Added tdtool --learn, closes #56
This commit is contained in:
parent
c5df327668
commit
d9db06db80
1 changed files with 31 additions and 5 deletions
|
@ -14,8 +14,9 @@ void print_usage( char *name ) {
|
||||||
printf("Usage: %s [ options ]\n", name);
|
printf("Usage: %s [ options ]\n", name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -[bdfhlnv] [ --list ] [ --help ]\n");
|
printf(" -[bdefhlnv] [ --list ] [ --help ]\n");
|
||||||
printf(" [ --on device ] [ --off device ] [ --bell device ]\n");
|
printf(" [ --on device ] [ --off device ] [ --bell device ]\n");
|
||||||
|
printf(" [ --learn device ]\n");
|
||||||
printf(" [ --dimlevel level --dim device ]\n");
|
printf(" [ --dimlevel level --dim device ]\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" --list (-l short option)\n");
|
printf(" --list (-l short option)\n");
|
||||||
|
@ -49,6 +50,12 @@ void print_usage( char *name ) {
|
||||||
printf(" either be an integer of the device-id, or the name of the device.\n");
|
printf(" either be an integer of the device-id, or the name of the device.\n");
|
||||||
printf(" Both device-id and name is outputed with the --list option\n");
|
printf(" Both device-id and name is outputed with the --list option\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
printf(" --learn device (-e short option)\n");
|
||||||
|
printf(" Sends a special learn command to devices supporting this. This is normaly\n");
|
||||||
|
printf(" devices of 'selflearning' type. 'device' could either be an integer\n");
|
||||||
|
printf(" of the device-id, or the name of the device.\n");
|
||||||
|
printf(" Both device-id and name is outputed with the --list option\n");
|
||||||
|
printf("\n");
|
||||||
printf("Report bugs to <info.tech@telldus.se>\n");
|
printf("Report bugs to <info.tech@telldus.se>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,10 +179,25 @@ void bell_device( char *device ) {
|
||||||
free(errorString);
|
free(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void learn_device( char *device ) {
|
||||||
|
int deviceId = find_device( device );
|
||||||
|
if (deviceId == 0) {
|
||||||
|
printf("Device '%s', not found!\n", device);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *name = tdGetName( deviceId );
|
||||||
|
int retval = tdLearn( deviceId );
|
||||||
|
char *errorString = tdGetErrorString(retval);
|
||||||
|
printf("Learning device: %i %s - %s\n", deviceId, name, errorString);
|
||||||
|
free(name);
|
||||||
|
free(errorString);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int optch, longindex;
|
int optch, longindex;
|
||||||
static char optstring[] = "ln:f:d:b:v:hi";
|
static char optstring[] = "ln:f:d:b:v:e:hi";
|
||||||
static struct option long_opts[] = {
|
static struct option long_opts[] = {
|
||||||
{ "list", 0, 0, 'l' },
|
{ "list", 0, 0, 'l' },
|
||||||
{ "on", 1, 0, 'n' },
|
{ "on", 1, 0, 'n' },
|
||||||
|
@ -183,6 +205,7 @@ int main(int argc, char **argv)
|
||||||
{ "dim", 1, 0, 'd' },
|
{ "dim", 1, 0, 'd' },
|
||||||
{ "bell", 1, 0, 'b' },
|
{ "bell", 1, 0, 'b' },
|
||||||
{ "dimlevel", 1, 0, 'v' },
|
{ "dimlevel", 1, 0, 'v' },
|
||||||
|
{ "learn", 1, 0, 'e' },
|
||||||
{ "help", 0, 0, 'h' },
|
{ "help", 0, 0, 'h' },
|
||||||
{ "version", 0, 0, 'i'},
|
{ "version", 0, 0, 'i'},
|
||||||
{ 0, 0, 0, 0}
|
{ 0, 0, 0, 0}
|
||||||
|
@ -219,6 +242,9 @@ int main(int argc, char **argv)
|
||||||
case 'n' :
|
case 'n' :
|
||||||
switch_device(true, &optarg[0]);
|
switch_device(true, &optarg[0]);
|
||||||
break;
|
break;
|
||||||
|
case 'e' :
|
||||||
|
learn_device(&optarg[0]);
|
||||||
|
break;
|
||||||
case 'v' :
|
case 'v' :
|
||||||
level = atoi( &optarg[0] );
|
level = atoi( &optarg[0] );
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue