From: Drew Fisher Date: Sun, 13 Nov 2011 03:26:23 +0000 (-0800) Subject: Move timestamps into device struct. X-Git-Url: https://git.zarvox.org/shortlog/month?a=commitdiff_plain;h=c12f42f4fa39dfb28a5ec6fea38780f4c845a02a;p=libtouchmouse.git Move timestamps into device struct. Before this, if an image update was multiple packets, and one of the packets was dropped, then we didn't correctly reset the decoder when we received a packet with a different timestamp if the packets were handled in different calls to touchmouse_process_events_timeout(). Signed-off-by: Drew Fisher --- diff --git a/src/touchmouse-internal.h b/src/touchmouse-internal.h index ebadaec..0a9401b 100644 --- a/src/touchmouse-internal.h +++ b/src/touchmouse-internal.h @@ -11,6 +11,7 @@ struct touchmouse_device_ { touchmouse_image_callback cb; // Image decoder/reassembler state uint8_t timestamp_last_completed; + uint8_t timestamp_in_progress; int buf_index; int next_is_run_encoded; uint8_t partial_image[181]; diff --git a/src/touchmouse.c b/src/touchmouse.c index 8202ce2..bc7ad48 100644 --- a/src/touchmouse.c +++ b/src/touchmouse.c @@ -113,7 +113,7 @@ static int process_nybble(touchmouse_device *state, uint8_t nybble) if (state->buf_index + nybble + 3 > 181) { // Completing this decode would overrun the buffer. We've been // given invalid data. Abort. - fprintf(stderr, "process_nybble: run encoded would overflow buffer: got 0xF%x (%d zeros) with only %d bytes to fill in buffer\n", nybble, nybble + 3, 181 - state->buf_index); + fprintf(stderr, "process_nybble: run encoded would overflow buffer: got 0xF%X (%d zeros) with only %d bytes to fill in buffer\n", nybble, nybble + 3, 181 - state->buf_index); return DECODER_ERROR; } int i; @@ -336,12 +336,9 @@ int touchmouse_set_device_userdata(touchmouse_device *dev, void *userdata) int touchmouse_process_events_timeout(touchmouse_device *dev, int milliseconds) { unsigned char data[256] = {}; int res; - uint8_t first_timestamp_read = 0; - uint8_t last_timestamp = 0; uint64_t deadline; if(milliseconds == -1) { deadline = (uint64_t)(-1); - printf("Got infinite timeout\n"); } else { deadline = mono_timer_nanos() + (milliseconds * 1000000); } @@ -375,11 +372,10 @@ int touchmouse_process_events_timeout(touchmouse_device *dev, int milliseconds) //printf("\n"); // Reset the decoder if we've seen one timestamp already from earlier // transfers, and this one doesn't match. - if (first_timestamp_read && r->timestamp != last_timestamp) { + if (dev->buf_index != 0 && r->timestamp != dev->timestamp_in_progress) { reset_decoder(dev); // Reset decoder for next transfer } - first_timestamp_read = 1; - last_timestamp = r->timestamp; + dev->timestamp_in_progress = r->timestamp; for(t = 0; t < r->length - 1; t++) { // We subtract one byte because the length includes the timestamp byte. int res; // Yes, we process the low nybble first. Embedded systems are funny like that.