From 077613efc501195f4ad0018e9d94f848654f6c3e Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Mon, 26 Aug 2019 19:26:30 +0200 Subject: improve exit handling on device removal --- src/fl2k_test.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/fl2k_test.c') diff --git a/src/fl2k_test.c b/src/fl2k_test.c index 6d82922..b166dda 100644 --- a/src/fl2k_test.c +++ b/src/fl2k_test.c @@ -213,6 +213,12 @@ static void ppm_test(uint32_t len) void fl2k_callback(fl2k_data_info_t *data_info) { + if (data_info->device_error) { + fprintf(stderr, "Device error, exiting.\n"); + do_exit = 1; + return; + } + /* drop first couple of callbacks until everything is settled */ if (cb_cnt > 20) { ppm_test(FL2K_BUF_LEN); @@ -222,7 +228,6 @@ void fl2k_callback(fl2k_data_info_t *data_info) data_info->r_buf = buffer; cb_cnt++; } - } int main(int argc, char **argv) @@ -295,9 +300,6 @@ int main(int argc, char **argv) while (!do_exit) sleep_ms(500); - if (do_exit) - fprintf(stderr, "\nUser cancel, exiting...\n"); - exit: fl2k_close(dev); free(buffer); -- cgit v1.2.3