]> git.zarvox.org Git - libtouchmouse.git/commitdiff
Move timestamps into device struct.
authorDrew Fisher <drew.m.fisher@gmail.com>
Sun, 13 Nov 2011 03:26:23 +0000 (19:26 -0800)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sun, 13 Nov 2011 03:26:23 +0000 (19:26 -0800)
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 <drew.m.fisher@gmail.com>
src/touchmouse-internal.h
src/touchmouse.c

index ebadaec5003fd4df703e12a0242bd0c9033bb470..0a9401b974a213842c51c5dbba94ecd8d6061d9f 100644 (file)
@@ -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];
index 8202ce2f895d74c813400c74cedb4b7eebef1a9e..bc7ad4861e21cb9b414dc02e3fe4b2ae563cabf8 100644 (file)
@@ -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.