diff options
Diffstat (limited to 'spectro/illumread.c')
-rw-r--r-- | spectro/illumread.c | 115 |
1 files changed, 84 insertions, 31 deletions
diff --git a/spectro/illumread.c b/spectro/illumread.c index 282ec2f..7cc7eae 100644 --- a/spectro/illumread.c +++ b/spectro/illumread.c @@ -30,7 +30,7 @@ */ -#undef DEBUG /* Save measurements and restore them to outname_X.sp */ +#define DEBUG /* Save measurements and restore them to outname_X.sp */ /* outname_i.sp Illuminant spectrum @@ -41,7 +41,7 @@ */ -#define SHOWDXX /* Plot the best matched daylight as well */ +#undef SHOWDXX /* Plot the best matched daylight as well */ #include <stdio.h> #include <stdlib.h> @@ -109,7 +109,7 @@ typedef struct { xsp2cie *pap; /* Estimated illuminant + UV on paper lookup inc FWA */ xsp2cie *ref; /* Measured illuminant on paper lookup */ - xspect ill; /* Illuminant with UV added */ + xspect ill; /* Illuminant with UV added - set by bfindfunc() */ xspect cpsp; /* FWA corrected calculated paper reflectance */ xspect srop; /* Scaled measured paper reflectance */ @@ -124,7 +124,7 @@ static double bfindfunc(void *adata, double pv[]) { /* Add UV level to illuminant */ b->ill = *b->i_sp; - xsp_setUV(&b->ill, b->i_sp, pv[0]); + xsp_setUV(&b->ill, b->i_sp, pv[0]); /* Extends ill range into UV */ /* Update the conversion */ if (b->pap->update_fwa_custillum(b->pap, NULL, &b->ill) != 0) @@ -212,12 +212,20 @@ static double cfindfunc(void *adata, double pv[]) { /* ============================================================== */ void -usage() { +usage(char *diag, ...) { icompaths *icmps; fprintf(stderr,"Measure an illuminant, Version %s\n",ARGYLL_VERSION_STR); fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n"); if (setup_spyd2() == 2) fprintf(stderr,"WARNING: This file contains a proprietary firmware image, and may not be freely distributed !\n"); + if (diag != NULL) { + va_list args; + fprintf(stderr,"Diagnostic: "); + va_start(args, diag); + vfprintf(stderr, diag, args); + va_end(args); + fprintf(stderr,"\n"); + } fprintf(stderr,"usage: illumread [-options] output.sp\n"); fprintf(stderr," -v Verbose mode\n"); fprintf(stderr," -S Plot spectrum for each reading\n"); @@ -239,6 +247,8 @@ usage() { } fprintf(stderr," -N Disable initial calibration of instrument if possible\n"); fprintf(stderr," -H Use high resolution spectrum mode (if available)\n"); + fprintf(stderr," -Y r Set refresh measurement mode\n"); + fprintf(stderr," -Y R:rate Override measured refresh rate with rate Hz\n"); fprintf(stderr," -W n|h|x Override serial port flow control: n = none, h = HW, x = Xon/Xoff\n"); fprintf(stderr," -D [level] Print debug diagnostics to stderr\n"); fprintf(stderr," illuminant.sp File to save measurement to\n"); @@ -257,6 +267,8 @@ int main(int argc, char *argv[]) int nocal = 0; /* Disable initial calibration */ int pspec = 0; /* 2 = Plot out the spectrum for each reading */ int highres = 0; /* Use high res mode if available */ + int refrmode = -1; /* -1 = default, = non-refresh mode, 1 = non-refresh mode */ + double refrate = 0.0; /* 0.0 = default, > 0.0 = override refresh rate */ char outname[MAXNAMEL+1] = "\000"; /* Spectral output file name */ #ifdef DEBUG char tname[MAXNAMEL+11] = "\000", *tnp; @@ -316,7 +328,7 @@ int main(int argc, char *argv[]) } if (argv[fa][1] == '?') { - usage(); + usage(NULL); } else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') { verb = 1; @@ -328,9 +340,9 @@ int main(int argc, char *argv[]) /* COM port */ } else if (argv[fa][1] == 'c') { fa = nfa; - if (na == NULL) usage(); + if (na == NULL) usage(NULL); comno = atoi(na); - if (comno < 1 || comno > 99) usage(); + if (comno < 1 || comno > 99) usage(NULL); /* No initial calibration */ } else if (argv[fa][1] == 'N') { @@ -340,18 +352,36 @@ int main(int argc, char *argv[]) } else if (argv[fa][1] == 'H') { highres = 1; + /* Extra flags */ + } else if (argv[fa][1] == 'Y') { + if (na == NULL) + usage(NULL); + + if (na[0] == 'R') { + if (na[1] != ':') + usage("-Y R:rate syntax incorrect"); + refrate = atof(na+2); + if (refrate < 5.0 || refrate > 150.0) + usage("-Y R:rate %f Hz not in valid range",refrate); + } else if (na[0] == 'r') + refrmode = 1; + else + usage(NULL); + fa = nfa; + /* Serial port flow control */ } else if (argv[fa][1] == 'W') { fa = nfa; - if (na == NULL) usage(); - if (na[0] == 'n' || na[0] == 'N') - fc = fc_none; - else if (na[0] == 'h' || na[0] == 'H') - fc = fc_Hardware; - else if (na[0] == 'x' || na[0] == 'X') - fc = fc_XonXOff; - else - usage(); + if (na == NULL) usage(NULL); + + if (na[0] == 'n' || na[0] == 'N') + fc = fc_none; + else if (na[0] == 'h' || na[0] == 'H') + fc = fc_Hardware; + else if (na[0] == 'x' || na[0] == 'X') + fc = fc_XonXOff; + else + usage(NULL); } else if (argv[fa][1] == 'D') { debug = 1; @@ -361,7 +391,7 @@ int main(int argc, char *argv[]) } g_log->debug = debug; } else - usage(); + usage(NULL); } else break; @@ -369,7 +399,7 @@ int main(int argc, char *argv[]) /* Get the output spectrum file name argument */ if (fa >= argc) - usage(); + usage(NULL); strncpy(outname,argv[fa++],MAXNAMEL-1); outname[MAXNAMEL-1] = '\000'; @@ -495,25 +525,22 @@ int main(int argc, char *argv[]) printf("Instrument lacks spectral measurement capability"); } + if (refrmode >= 0 && !IMODETST(cap, inst_mode_emis_refresh_ovd) + && !IMODETST(cap, inst_mode_emis_norefresh_ovd)) { + if (verb) { + printf("Requested refresh mode override and instrument doesn't support it (ignored)\n"); + refrmode = -1; + } + } + /* Disable iniial calibration of machine if selected */ - if (nocal != 0){ + if (nocal != 0) { if ((rv = it->get_set_opt(it,inst_opt_noinitcalib, 0)) != inst_ok) { printf("Setting no-initial calibrate failed failed with '%s' (%s) !!!\n", it->inst_interp_error(it, rv), it->interp_error(it, rv)); printf("Disable initial-calibrate not supported\n"); } } - if (highres) { - if (IMODETST(cap, inst_mode_highres)) { - inst_code ev; - if ((ev = it->get_set_opt(it, inst_opt_highres)) != inst_ok) { - printf("!!! Setting high res mode failed with error :'%s' (%s) !!!\n", - it->inst_interp_error(it, ev), it->interp_error(it, ev)); - } - } else if (verb) { - printf("!!! High resolution ignored - instrument doesn't support it !!!\n"); - } - } } /* Check the instrument has the necessary capabilities for this measurement */ @@ -558,6 +585,19 @@ int main(int argc, char *argv[]) } mode |= inst_mode_spectral; + if (refrmode == 0) + mode |= inst_mode_emis_norefresh_ovd; + else if (refrmode == 1) + mode |= inst_mode_emis_refresh_ovd; + + if (highres) { + if (IMODETST(cap, inst_mode_highres)) { + mode |= inst_mode_highres; + } else if (verb) { + printf("!!! High resolution ignored - instrument doesn't support it !!!\n"); + } + } + if ((rv = it->set_mode(it, mode)) != inst_ok) { printf("!!! Setting instrument mode failed with error :'%s' (%s) !!!\n", it->inst_interp_error(it, rv), it->interp_error(it, rv)); @@ -565,6 +605,19 @@ int main(int argc, char *argv[]) } it->capabilities(it, &cap, &cap2, &cap3); + if (refrate > 0.0) { + if (!(cap2 & inst2_set_refresh_rate)) { + if (verb) + printf("Attempted to set refresh rate and instrument doesn't support setting it (ignored)\n"); + refrate = 0.0; + } else { + if ((rv = it->set_refr_rate(it, refrate)) != inst_ok) { + error("Setting instrument refresh rate to %f Hz failed with error :'%s' (%s)", + refrate, it->inst_interp_error(it, rv), it->interp_error(it, rv)); + } + } + } + /* If it batter powered, show the status of the battery */ if ((cap2 & inst2_has_battery)) { double batstat = 0.0; |