From 43f196b8046c3b93734c1c3cd7d6644063b78bb3 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 17 Feb 2018 10:26:49 +0100 Subject: [PATCH] Remove the code to purge the input buffer Trying to purge the input buffer by reading and discarding data packets, results in an annoying and confusing error message if no data packet is received. To avoid this error, the functionality should be integrated in the USB HID code, either automatically during initialization or by implementing the purge function. But since there seems to be no evidence that this is actually necessary, let's remove this code. --- src/suunto_eonsteel.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 719ca64..4de3fa9 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -565,23 +565,8 @@ initialize_eonsteel(suunto_eonsteel_device_t *eon) { dc_status_t rc = DC_STATUS_SUCCESS; const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00}; - unsigned char buf[64]; struct eon_hdr hdr; - dc_iostream_set_timeout(eon->iostream, 10); - - /* Get rid of any pending stale input first */ - for (;;) { - size_t transferred = 0; - rc = dc_iostream_read(eon->iostream, buf, sizeof(buf), &transferred); - if (rc != DC_STATUS_SUCCESS) - break; - if (!transferred) - break; - } - - dc_iostream_set_timeout(eon->iostream, 5000); - rc = send_cmd(eon, CMD_INIT, sizeof(init), init); if (rc != DC_STATUS_SUCCESS) { ERROR(eon->base.context, "Failed to send initialization command"); @@ -634,6 +619,12 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i goto error_free; } + status = dc_iostream_set_timeout(eon->iostream, 5000); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to set the timeout."); + goto error_close; + } + status = initialize_eonsteel(eon); if (status != DC_STATUS_SUCCESS) { ERROR(context, "unable to initialize device");