From 0680d52f503248658e334b7bc73cde1c92619ed1 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 19 Oct 2014 22:57:29 +0100 Subject: [PATCH] Add support for the ColorHug2 sensor --- spectro/colorhug.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- spectro/colorhug.h | 5 +++-- spectro/inst.c | 3 ++- spectro/insttypes.c | 13 +++++++++++++ spectro/insttypes.h | 1 + 10 files changed, 71 insertions(+), 13 deletions(-) diff --git a/spectro/colorhug.c b/spectro/colorhug.c index 0152000..528f62e 100644 --- a/spectro/colorhug.c +++ b/spectro/colorhug.c @@ -6,10 +6,10 @@ * Hughski ColorHug related functions * * Author: Richard Hughes - * Date: 30/11/2011 + * Date: 30/11/2011 - 19/10/2014 * * Copyright 2006 - 2014, Graeme W. Gill - * Copyright 2011, Richard Hughes + * Copyright 2011 - 2014, Richard Hughes * All rights reserved. * * (Based on huey.c) @@ -53,6 +53,7 @@ typedef enum { ch_set_mult = 0x04, /* Set multiplier value */ ch_set_integral = 0x06, /* Set integral time */ ch_get_firmware_version = 0x07, /* Get the Firmware version number */ + ch_get_hardware_version = 0x30, /* Get the hardware version number */ ch_get_serial = 0x0b, /* Gets the serial number */ ch_set_leds = 0x0e, /* Sets the LEDs */ ch_take_reading = 0x22, /* Takes a raw reading minus dark offset */ @@ -487,6 +488,26 @@ colorhug_get_firmwareversion (colorhug *p) return ev; } +/* Get the hardware version */ +static inst_code +colorhug_get_hardwareversion (colorhug *p) +{ + inst_code ev; + unsigned char obuf; + + ev = colorhug_command(p, ch_get_firmware_version, + NULL, 0, + &obuf, 1, + 2.0); + if (ev != inst_ok) + return ev; + + p->hwrev = obuf; + a1logd(p->log,2,"colorhug: Hardware version = %u\n", p->hwrev); + + return ev; +} + /* Get the serial number */ static inst_code colorhug_get_serialnumber (colorhug *p) @@ -577,6 +598,11 @@ colorhug_init_inst(inst *pp) if (ev != inst_ok) return ev; + /* Get the hardware version */ + ev = colorhug_get_hardwareversion(p); + if (ev != inst_ok) + return ev; + /* Get the serial number */ ev = colorhug_get_serialnumber(p); if (ev != inst_ok) @@ -588,16 +614,21 @@ colorhug_init_inst(inst *pp) return ev; /* Turn the sensor on */ - ev = colorhug_set_multiplier(p, 0x03); - if (ev != inst_ok) - return ev; + if (p->itype == instColorHug) { + ev = colorhug_set_multiplier(p, 0x03); + if (ev != inst_ok) + return ev; + } /* Set the integral time to maximum precision */ - ev = colorhug_set_integral(p, 0xffff); - if (ev != inst_ok) - return ev; + if (p->itype == instColorHug) { + ev = colorhug_set_integral(p, 0xffff); + if (ev != inst_ok) + return ev; + } - if (p->maj <= 1 && p->min <= 1 && p->uro <= 4) { + if (p->itype == instColorHug && + p->maj <= 1 && p->min <= 1 && p->uro <= 4) { /* Get the post scale factor */ ev = colorhug_get_postscale(p, &p->postscale); @@ -621,8 +652,9 @@ colorhug_init_inst(inst *pp) a1logd(p->log, 2, "colorhug_init: inited coms OK\n"); a1logv(p->log,1,"Serial Number: %06u\n" + "Hardware Version: %u\n" "Firmware Version: %d.%d.%d\n" - ,p->ser_no,p->maj,p->min,p->uro); + ,p->ser_no,p->hwrev,p->maj,p->min,p->uro); /* Flash the LEDs */ ev = colorhug_set_LEDs(p, 0x1); diff --git a/spectro/colorhug.h b/spectro/colorhug.h index a591608..46460a3 100644 --- a/spectro/colorhug.h +++ b/spectro/colorhug.h @@ -6,10 +6,10 @@ * Hughski ColorHug related defines * * Author: Richard Hughes - * Date: 30/11/2011 + * Date: 30/11/2011 - 19/10/2014 * * Copyright 2006 - 2013, Graeme W. Gill - * Copyright 2011, Richard Hughes + * Copyright 2011 - 2014, Richard Hughes * All rights reserved. * * (Based on huey.h) @@ -68,6 +68,7 @@ struct _colorhug { inst_opt_type trig; /* Reading trigger mode */ int maj, min, uro; /* Version number */ + int hwrev; /* Hardware revision */ int ser_no; /* Serial number */ inst_disptypesel *dtlist; /* Display Type list */ diff --git a/spectro/inst.c b/spectro/inst.c index a910750..7c216f2 100644 --- a/spectro/inst.c +++ b/spectro/inst.c @@ -600,7 +600,8 @@ void *cntx /* Context for callback */ p = (inst *)new_huey(icom, itype); else if (itype == instSmile) p = (inst *)new_i1disp(icom, itype); - else if (itype == instColorHug) + else if (itype == instColorHug || + itype == instColorHug2) p = (inst *)new_colorhug(icom, itype); #endif /* ENABLE_USB */ diff --git a/spectro/insttypes.c b/spectro/insttypes.c index d70bc71..235ae5e 100644 --- a/spectro/insttypes.c +++ b/spectro/insttypes.c @@ -92,6 +92,8 @@ char *inst_sname(instType itype) { return "specbos"; case instColorHug: return "ColorHug"; + case instColorHug2: + return "ColorHug2"; default: break; } @@ -153,6 +155,8 @@ char *inst_name(instType itype) { return "JETI specbos"; case instColorHug: return "Hughski ColorHug"; + case instColorHug2: + return "Hughski ColorHug2"; default: break; } @@ -219,6 +223,8 @@ instType inst_enum(char *name) { return instSpecbos; else if (strcmp(name, "Hughski ColorHug") == 0) return instColorHug; + else if (strcmp(name, "Hughski ColorHug2") == 0) + return instColorHug2; return instUnknown; @@ -297,6 +303,12 @@ int nep) { /* Number of end points */ || (idVendor == 0x273f && idProduct == 0x1001)) { /* Hughski & ColorHug Fmw. >= 0.1.20 */ return instColorHug; } + + if (idVendor == 0x273f && idProduct == 0x1004) { + /* Hughski ColorHug */ + return instColorHug2; + } + /* Add other instruments here */ @@ -391,6 +403,7 @@ int inst_illuminant(xspect *sp, instType itype) { return 1; /* Not applicable */ case instColorHug: + case instColorHug2: return 1; /* Not applicable */ diff --git a/spectro/insttypes.h b/spectro/insttypes.h index ff86cc5..6b0c787 100644 --- a/spectro/insttypes.h +++ b/spectro/insttypes.h @@ -52,6 +52,7 @@ typedef enum { instSpecbos1201, /* JETI specbos 1201 */ instSpecbos, /* JETI specbos XXXX */ instColorHug, /* Hughski ColorHug */ + instColorHug2, /* Hughski ColorHug2 */ instFakeDisp = 9998, /* Fake display & instrument device id */