Blob Blame History Raw
--- spectro/colorhug.c.old	2012-08-21 10:25:31.822454477 +0100
+++ spectro/colorhug.c	2012-08-21 10:46:44.867367427 +0100
@@ -213,15 +213,16 @@ colorhug_command(colorhug *p,
 	rv = colorhug_interp_code((inst *)p, icoms2colorhug_err(ua));
 	if (isdeb)
 		fprintf(stderr,"colorhug: ICOM err 0x%x\n",ua);
-	if (rv == inst_ok && wbytes != in_size + 1)
+	if (rv == inst_ok && (wbytes != in_size + 1 && rbytes != 64))
 		rv = colorhug_interp_code((inst *)p, COLORHUG_BAD_WR_LENGTH);
 
 	if (rv != inst_ok) {
 		/* Flush any response if write failed */
+		fprintf(stderr,"colorhug: flushing as write failed\n");
 		if (p->icom->is_hid) {
-			p->icom->hid_read(p->icom, buf, out_size + 2, &rbytes, timeout);
+			p->icom->hid_read(p->icom, buf, 64, &rbytes, timeout);
 		} else {
-			p->icom->usb_read(p->icom, 0x81, buf, out_size + 2, &rbytes, timeout);
+			p->icom->usb_read(p->icom, 0x81, buf, 64, &rbytes, timeout);
 		}
 		p->icom->debug = isdeb;
 		return rv;
@@ -232,11 +233,16 @@ colorhug_command(colorhug *p,
 		fprintf(stderr,"colorhug: Reading response\n");
 
 	if (p->icom->is_hid) {
-		se = p->icom->hid_read(p->icom, buf, out_size + 2, &rbytes, timeout);
+		se = p->icom->hid_read(p->icom, buf, 64, &rbytes, timeout);
 	} else {
-		se = p->icom->usb_read(p->icom, 0x81, buf, out_size + 2, &rbytes, timeout);
+		se = p->icom->usb_read(p->icom, 0x81, buf, 64, &rbytes, timeout);
 	}
 
+	/* ColorHug firmware < 1.2.0 returned less than 64 bytes which was
+	 * specified in the HID descriptor */
+	if ((se & ICOM_SHORT) > 0)
+		se &= ~ICOM_SHORT;
+
 	if (isdeb && rbytes >= 2) {
 		fprintf(stderr,"Recieved cmd '%s' error '%s' args '%s'\n",
 				inst_desc(buf[1]),
@@ -254,7 +260,7 @@ colorhug_command(colorhug *p,
 		}
 
 		/* deal with underrun or overrun */
-		if (rbytes != out_size + 2) {
+		if (rbytes != out_size + 2 && rbytes != 64) {
 			rv = colorhug_interp_code((inst *)p, COLORHUG_BAD_RD_LENGTH);
 			p->icom->debug = isdeb;
 			return rv;