From 7ca9725b910b9764a0381012c3b99d5165e50033 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Tue, 1 Mar 2011 15:43:38 -0500 Subject: [PATCH] Read and discard old packet --- usbscale.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/usbscale.c b/usbscale.c index 5851ecf..5c223cc 100644 --- a/usbscale.c +++ b/usbscale.c @@ -166,6 +166,21 @@ int main(void) int continue_reading = 0; int scale_result = -1; + // + // For some reason, we get old data the first time, so let's just get that + // out of the way now. It can't hurt to grab another packet from the scale. + // + r = libusb_interrupt_transfer( + handle, + //bmRequestType => direction: in, type: class, + // recipient: interface + LIBUSB_ENDPOINT_IN | //LIBUSB_REQUEST_TYPE_CLASS | + LIBUSB_RECIPIENT_INTERFACE, + data, + WEIGH_REPORT_SIZE, // length of data + &len, + 10000 //timeout => 10 sec + ); // // We read data from the scale in an infinite loop, stopping when // **print_scale_data** tells us that it's successfully gotten the weight