mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 22:57:11 +02:00
ubbctl/ubbctl.c: new option -c for continuous display
This commit is contained in:
parent
fd5707ee72
commit
5fadbce41d
@ -56,7 +56,6 @@ static void show_pins(void)
|
||||
}
|
||||
printf("%d", pin);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
@ -121,8 +120,9 @@ static int setup_pin(const char *s, int doit)
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s\n"
|
||||
"usage: %s [-c]\n"
|
||||
" %s name=value|action ...\n\n"
|
||||
" -c continously update the pin status (until user interrupts)\n\n"
|
||||
"Names: nPWR, CMD, CLK, DAT0, DAT1, DAT2, DAT3\n"
|
||||
"Values: F, 0, 1, Z, R\n"
|
||||
"Actions: ON, OFF\n"
|
||||
@ -133,21 +133,39 @@ static void usage(const char *name)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int continuous = 0;
|
||||
int c, i;
|
||||
|
||||
while ((c = getopt(argc, argv, "")) != EOF)
|
||||
while ((c = getopt(argc, argv, "c")) != EOF)
|
||||
switch (c) {
|
||||
case 'c':
|
||||
continuous = 1;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
if (argc != optind && continuous)
|
||||
usage(*argv);
|
||||
|
||||
for (i = optind; i != argc; i++)
|
||||
if (!setup_pin(argv[i], 0))
|
||||
usage(*argv);
|
||||
|
||||
ubb_open(UBB_ALL);
|
||||
if (argc == optind) {
|
||||
show_pins();
|
||||
if (continuous) {
|
||||
while (1) {
|
||||
show_pins();
|
||||
printf("%*s\r", sizeof(pins)/sizeof(*pins)*2,
|
||||
"");
|
||||
fflush(stdout);
|
||||
usleep(200*1000);
|
||||
}
|
||||
} else {
|
||||
show_pins();
|
||||
putchar('\n');
|
||||
}
|
||||
} else {
|
||||
for (i = optind; i != argc; i++)
|
||||
setup_pin(argv[i], 1);
|
||||
|
Loading…
Reference in New Issue
Block a user