fxlink: add reconnecting interactive mode (-ir)

This exposes how terrible the libusb code is. Future problem for now.
This commit is contained in:
Lephenixnoir 2022-12-03 13:34:06 +01:00
parent e31d053a08
commit ebfde1f13d
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -41,6 +41,8 @@ static const char *help_string =
" -q, --quiet Quite mode (minimum verbosity)\n" " -q, --quiet Quite mode (minimum verbosity)\n"
" -u, --unmount In -s mode, always unmount the disk, even if it was\n" " -u, --unmount In -s mode, always unmount the disk, even if it was\n"
" mounted by someone else\n" " mounted by someone else\n"
" -r, --repeat In interactive mode, reconnect infinitely if the\n"
" calculator disconnects (implies -w)\n"
"\n" "\n"
"Device filters:\n" "Device filters:\n"
" A device filter is a comma-separated list of properties that a device has\n" " A device filter is a comma-separated list of properties that a device has\n"
@ -68,6 +70,7 @@ int main(int argc, char **argv)
int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_ERROR; int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_ERROR;
delay_t delay = delay_seconds(0); delay_t delay = delay_seconds(0);
filter_t *filter = NULL; filter_t *filter = NULL;
bool repeat = false;
options.quiet = false; options.quiet = false;
options.force_unmount = false; options.force_unmount = false;
@ -88,10 +91,11 @@ int main(int argc, char **argv)
{ "quiet", no_argument, NULL, 'q' }, { "quiet", no_argument, NULL, 'q' },
{ "fxlink-log", optional_argument, NULL, LOG_TO_FILE }, { "fxlink-log", optional_argument, NULL, LOG_TO_FILE },
{ "unmount", no_argument, NULL, 'u' }, { "unmount", no_argument, NULL, 'u' },
{ "repeat", no_argument, NULL, 'r' },
}; };
while(option >= 0 && option != '?') while(option >= 0 && option != '?')
switch((option = getopt_long(argc, argv, "hlbsiquf:w::", longs, NULL))) switch((option = getopt_long(argc, argv, "hlbsiquf:w::r", longs, NULL)))
{ {
case 'h': case 'h':
fprintf(stderr, help_string, argv[0]); fprintf(stderr, help_string, argv[0]);
@ -122,6 +126,10 @@ int main(int argc, char **argv)
case 'u': case 'u':
options.force_unmount = true; options.force_unmount = true;
break; break;
case 'r':
repeat = true;
delay = delay_infinite();
break;
case LOG_TO_FILE: case LOG_TO_FILE:
if(optarg) if(optarg)
options.log_file = fopen(optarg, "a"); options.log_file = fopen(optarg, "a");
@ -198,8 +206,11 @@ int main(int argc, char **argv)
#endif #endif
} }
else if(mode == 'i') { else if(mode == 'i') {
do {
rc = main_interactive(filter, &delay, context); rc = main_interactive(filter, &delay, context);
} }
while(repeat);
}
if(context) if(context)
libusb_exit(context); libusb_exit(context);