Allow for custom baud rates.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2010-07-21 14:41:04 +10:00
parent b7df155dcb
commit ea3346592a

View File

@ -503,7 +503,7 @@ static void show_help(void)
struct input_types *type;
puts("");
puts("Usage: inputattach [--daemon] <mode> <device>");
puts("Usage: inputattach [--daemon] [--baud <baud>] <mode> <device>");
puts("");
puts("Modes:");
@ -527,6 +527,7 @@ int main(int argc, char **argv)
int i;
char c;
int retval;
int baud = -1;
for (i = 1; i < argc; i++) {
if (!strcasecmp(argv[i], "--help")) {
@ -537,6 +538,15 @@ int main(int argc, char **argv)
} else if (need_device) {
device = argv[i];
need_device = 0;
} else if (!strcasecmp(argv[i], "--baud")) {
if (argc <= i + 1) {
show_help();
fprintf(stderr,
"inputattach: require baud rate\n");
return EXIT_FAILURE;
}
baud = atoi(argv[++i]);
} else {
if (type && type->name) {
fprintf(stderr,
@ -577,6 +587,19 @@ int main(int argc, char **argv)
return 1;
}
switch(baud) {
case -1: break;
case 2400: type->speed = B2400; break;
case 4800: type->speed = B4800; break;
case 9600: type->speed = B9600; break;
case 19200: type->speed = B19200; break;
case 38400: type->speed = B38400; break;
default:
fprintf(stderr, "inputattach: invalid baud rate '%d'\n",
baud);
return EXIT_FAILURE;
}
setline(fd, type->flags, type->speed);
if (type->flush)