1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-23 22:11:53 +02:00

ubbctl/ubbctl.c: new option -c for continuous display

This commit is contained in:
Werner Almesberger 2013-01-06 13:24:56 -03:00
parent fd5707ee72
commit 5fadbce41d

View File

@ -56,7 +56,6 @@ static void show_pins(void)
} }
printf("%d", pin); printf("%d", pin);
} }
printf("\n");
} }
@ -121,8 +120,9 @@ static int setup_pin(const char *s, int doit)
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s\n" "usage: %s [-c]\n"
" %s name=value|action ...\n\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" "Names: nPWR, CMD, CLK, DAT0, DAT1, DAT2, DAT3\n"
"Values: F, 0, 1, Z, R\n" "Values: F, 0, 1, Z, R\n"
"Actions: ON, OFF\n" "Actions: ON, OFF\n"
@ -133,21 +133,39 @@ static void usage(const char *name)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int continuous = 0;
int c, i; int c, i;
while ((c = getopt(argc, argv, "")) != EOF) while ((c = getopt(argc, argv, "c")) != EOF)
switch (c) { switch (c) {
case 'c':
continuous = 1;
break;
default: default:
usage(*argv); usage(*argv);
} }
if (argc != optind && continuous)
usage(*argv);
for (i = optind; i != argc; i++) for (i = optind; i != argc; i++)
if (!setup_pin(argv[i], 0)) if (!setup_pin(argv[i], 0))
usage(*argv); usage(*argv);
ubb_open(UBB_ALL); ubb_open(UBB_ALL);
if (argc == optind) { 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 { } else {
for (i = optind; i != argc; i++) for (i = optind; i != argc; i++)
setup_pin(argv[i], 1); setup_pin(argv[i], 1);