uru4000: handle images without headers

While testing the new code on my MS keyboard, I found some strange
conditions where occasionally, the device will stop providing images
headers until it is replugged.

Detect and work around this when it happens.
This commit is contained in:
Daniel Drake 2007-11-04 18:57:44 +00:00
parent 2e6c3b940c
commit cbe1111e4e

View file

@ -305,6 +305,7 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional,
int r; int r;
struct fp_img *img; struct fp_img *img;
size_t image_size = DATABLK1_RQLEN + DATABLK2_EXPECT - CAPTURE_HDRLEN; size_t image_size = DATABLK1_RQLEN + DATABLK2_EXPECT - CAPTURE_HDRLEN;
int hdr_skip = CAPTURE_HDRLEN;
r = set_mode(dev, MODE_CAPTURE); r = set_mode(dev, MODE_CAPTURE);
if (r < 0) if (r < 0)
@ -338,13 +339,20 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional,
fp_err("part 2 capture failed, error %d", r); fp_err("part 2 capture failed, error %d", r);
goto err; goto err;
} else if (r != DATABLK2_EXPECT) { } else if (r != DATABLK2_EXPECT) {
if (r == DATABLK2_EXPECT - CAPTURE_HDRLEN) {
/* this is rather odd, but it happens sometimes with my MS
* keyboard */
fp_dbg("got image with no header!");
hdr_skip = 0;
} else {
fp_err("unexpected part 2 capture size (%d)", r); fp_err("unexpected part 2 capture size (%d)", r);
r = -EIO; r = -EIO;
goto err; goto err;
} }
}
/* remove header and shrink allocation */ /* remove header and shrink allocation */
g_memmove(img->data, img->data + CAPTURE_HDRLEN, image_size); g_memmove(img->data, img->data + hdr_skip, image_size);
img = fpi_img_resize(img, image_size); img = fpi_img_resize(img, image_size);
img->flags = FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED | FP_IMG_COLORS_INVERTED; img->flags = FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED | FP_IMG_COLORS_INVERTED;