95
88
#endif /* !__APPLE__ */
98
p->icom->debug = p->debug; /* Turn on debugging */
99
fprintf(stderr,"munki: About to init coms\n");
102
if (p->icom->is_usb_portno(p->icom, port) == instUnknown) {
103
if (p->debug) fprintf(stderr,"munki: init_coms called to wrong device!\n");
90
a1logd(p->log, 2, "munki_init_coms: called\n");
92
if (p->icom->port_type(p->icom) != icomt_usb) {
93
a1logd(p->log, 1, "munki_init_coms: wrong sort of coms!\n");
105
94
return munki_interp_code(p, MUNKI_UNKNOWN_MODEL);
108
if (p->debug) fprintf(stderr,"munki: About to init USB\n");
97
a1logd(p->log, 2, "munki_init_coms: about to init USB\n");
110
99
/* Set config, interface, write end point, read end point, read quanta */
111
100
/* ("serial" end points aren't used - the Munki uses USB control messages) */
112
p->icom->set_usb_port(p->icom, port, 1, 0x00, 0x00, usbflags, retries, pnames);
101
if ((se = p->icom->set_usb_port(p->icom, 1, 0x00, 0x00, usbflags, retries, pnames))
103
a1logd(p->log, 1, "munki_init_coms: failed ICOM err 0x%x\n",se);
104
return munki_interp_code(p, icoms2munki_err(se));
114
if (p->debug) fprintf(stderr,"munki: init coms has suceeded\n");
107
a1logd(p->log, 2, "munki_init_coms: init coms has suceeded\n");
121
munki_discover_capabilities(munki *p) {
114
munki_determine_capabilities(munki *p) {
123
116
/* Set the Munki capabilities mask */
124
p->cap |= inst_ref_spot
128
| inst_emis_proj /* Support of a specific projector mode */
130
| inst_trans_spot /* Support this manually using a light table */
132
| inst_emis_strip /* Also likely to be light table reading */
136
| inst_emis_ambient_flash
117
p->cap = inst_mode_ref_spot
118
| inst_mode_ref_strip
119
| inst_mode_emis_spot
120
| inst_mode_emis_tele
121
| inst_mode_trans_spot /* Support this manually using a light table */
122
| inst_mode_trans_strip
123
| inst_mode_emis_strip /* Also likely to be light table reading */
124
| inst_mode_emis_ambient
125
| inst_mode_emis_ambient_flash
126
| inst_mode_emis_nonadaptive
127
| inst_mode_colorimeter
129
| inst_mode_calibration /* Can indicate cal configuration */
139
p->cap2 |= inst2_cal_ref_white
140
| inst2_cal_trans_white
141
| inst2_cal_disp_int_time
142
| inst2_cal_proj_int_time
145
| inst2_keyb_switch_trig
132
if (munki_imp_highres(p)) /* Static */
133
p->cap |= inst_mode_highres;
135
p->cap2 = inst2_prog_trig
137
| inst2_user_switch_trig
146
138
| inst2_bidi_scan
147
139
| inst2_has_scan_toll
148
140
| inst2_no_feedback
150
142
| inst2_has_sensmode
153
if (munki_imp_highres(p)) /* Static */
154
p->cap |= inst_highres;
146
munkiimp *m = (munkiimp *)p->m;
147
munki_state *s = &m->ms[m->mmode];
149
p->cap2 |= inst2_emis_refr_meas;
152
p->cap3 = inst3_none;
157
/* Return current or given configuration available measurement modes. */
158
static inst_code munki_meas_config(
161
inst_cal_cond *cconds,
164
munki *p = (munki *)pp;
169
*mmodes = inst_mode_none;
171
*cconds = inst_calc_none;
174
|| *conf_ix < mk_spos_proj
175
|| *conf_ix > mk_spos_amb) {
176
/* Return current configuration measrement modes */
177
ev = munki_getstatus(p, &spos, NULL);
179
return munki_interp_code(p, ev);
181
/* Return given configuration measurement modes */
185
if (spos == mk_spos_proj) {
187
*mmodes = inst_mode_emis_tele;
188
} else if (spos == mk_spos_surf) {
190
*mmodes = inst_mode_ref_spot
191
| inst_mode_ref_strip
192
| inst_mode_emis_spot
193
| inst_mode_trans_spot
194
| inst_mode_trans_strip;
195
} else if (spos == mk_spos_calib) {
197
*cconds = inst_calc_man_cal_smode;
199
*mmodes = inst_mode_calibration;
200
} else if (spos == mk_spos_amb) {
202
*mmodes = inst_mode_emis_ambient
203
| inst_mode_emis_ambient_flash;
206
/* Return configuration index returned */
208
*conf_ix = (int)spos;
210
/* Add the extra dependent and independent modes */
212
*mmodes |= inst_mode_emis_nonadaptive
213
| inst_mode_colorimeter
214
| inst_mode_spectral;
159
220
/* Initialise the MUNKI */
160
221
/* return non-zero on an error, with dtp error code */
221
284
munki_read_sample(
223
286
char *name, /* Strip name (7 chars) */
224
ipatch *val) { /* Pointer to instrument patch value */
225
munki *p = (munki *)pp;
233
rv = munki_imp_measure(p, val, 1);
235
return munki_interp_code(p, rv);
238
/* Determine if a calibration is needed. Returns inst_calt_none if not, */
239
/* inst_calt_unknown if it is unknown, or inst_calt_XXX if needs calibration, */
240
/* and the first type of calibration needed. */
241
inst_cal_type munki_needs_calibration(inst *pp) {
242
munki *p = (munki *)pp;
249
return munki_imp_needs_calibration(p);
287
ipatch *val, /* Pointer to instrument patch value */
288
instClamping clamp) { /* Clamp XYZ/Lab to be +ve */
289
munki *p = (munki *)pp;
297
rv = munki_imp_measure(p, val, 1, clamp);
299
return munki_interp_code(p, rv);
302
/* Read an emissive refresh rate */
307
munki *p = (munki *)pp;
315
rv = munki_imp_meas_refrate(p, ref_rate);
317
return munki_interp_code(p, rv);
320
/* Return needed and available inst_cal_type's */
321
static inst_code munki_get_n_a_cals(inst *pp, inst_cal_type *pn_cals, inst_cal_type *pa_cals) {
322
munki *p = (munki *)pp;
325
rv = munki_imp_get_n_a_cals(p, pn_cals, pa_cals);
326
return munki_interp_code(p, rv);
252
329
/* Request an instrument calibration. */
253
/* This is use if the user decides they want to do a calibration, */
254
/* in anticipation of a calibration (needs_calibration()) to avoid */
255
/* requiring one during measurement, or in response to measuring */
256
/* returning inst_needs_cal. Initially us an inst_cal_cond of inst_calc_none, */
257
/* and then be prepared to setup the right conditions, or ask the */
258
/* user to do so, each time the error inst_cal_setup is returned. */
259
330
inst_code munki_calibrate(
261
inst_cal_type calt, /* Calibration type. inst_calt_all for all neeeded */
332
inst_cal_type *calt, /* Calibration type to do/remaining */
262
333
inst_cal_cond *calc, /* Current condition/desired condition */
263
334
char id[CALIDLEN] /* Condition identifier (ie. white reference ID) */
508
581
case MUNKI_INT_CREATE_EEPROM_STORE:
509
582
case MUNKI_INT_NEW_RSPL_FAILED:
510
583
case MUNKI_INT_CAL_SAVE:
584
case MUNKI_INT_CAL_RESTORE:
585
case MUNKI_INT_CAL_TOUCH:
511
586
case MUNKI_INT_WRONGPATCHES:
512
case MUNKI_INT_CAL_RESTORE:
587
case MUNKI_INT_ASSERT:
513
588
return inst_internal_error | ec;
515
590
return inst_other_error | ec;
593
/* Convert instrument specific inst_wrong_config error to inst_config enum */
594
static inst_config munki_config_enum(inst *pp, int ec) {
595
// munki *p = (munki *)pp;
600
case MUNKI_SPOS_PROJ:
601
return inst_conf_projector;
603
case MUNKI_SPOS_SURF:
604
return inst_conf_surface;
607
return inst_conf_ambient;
609
case MUNKI_SPOS_CALIB:
610
return inst_conf_calibration;
612
return inst_conf_unknown;
518
615
/* Return the instrument capabilities */
519
inst_capability munki_capabilities(inst *pp) {
520
munki *p = (munki *)pp;
525
/* Return the instrument capabilities 2 */
526
inst2_capability munki_capabilities2(inst *pp) {
527
munki *p = (munki *)pp;
616
void munki_capabilities(inst *pp,
618
inst2_capability *pcap2,
619
inst3_capability *pcap3) {
620
munki *p = (munki *)pp;
632
/* Return the corresponding munki measurement mode, */
633
/* or mk_no_modes if invalid */
634
static mk_mode munki_convert_mode(munki *p, inst_mode m) {
641
if (IMODETST(m, inst_mode_ref_spot)) {
642
mmode = mk_refl_spot;
643
} else if (IMODETST(m, inst_mode_ref_strip)) {
644
mmode = mk_refl_scan;
645
} else if (IMODETST(m, inst_mode_trans_spot)) {
646
mmode = mk_trans_spot;
647
} else if (IMODETST(m, inst_mode_trans_strip)) {
648
mmode = mk_trans_scan;
649
} else if (IMODETST(m, inst_mode_emis_spot)) {
650
if (IMODETST(m, inst_mode_emis_nonadaptive))
651
mmode = mk_emiss_spot_na;
653
mmode = mk_emiss_spot;
654
} else if (IMODETST(m, inst_mode_emis_tele)) {
655
if (IMODETST(m, inst_mode_emis_nonadaptive))
656
mmode = mk_tele_spot_na;
658
mmode = mk_tele_spot;
659
} else if (IMODETST(m, inst_mode_emis_strip)) {
660
mmode = mk_emiss_scan;
661
} else if (IMODETST(m, inst_mode_emis_ambient)) {
663
} else if (IMODETST(m, inst_mode_emis_ambient_flash)) {
664
mmode = mk_amb_flash;
672
/* Check device measurement mode */
673
inst_code munki_check_mode(inst *pp, inst_mode m) {
674
munki *p = (munki *)pp;
682
if (munki_convert_mode(p, m) == mk_no_modes)
683
return inst_unsupported;
535
688
/* Set device measurement mode */
536
689
inst_code munki_set_mode(inst *pp, inst_mode m) {
537
690
munki *p = (munki *)pp;
538
inst_mode mm; /* Request measurement mode */
539
mk_mode mmode = -1; /* Instrument measurement mode */
692
inst_mode cap = p->cap;
542
696
return inst_no_coms;
544
698
return inst_no_init;
546
/* The measurement mode portion of the mode */
547
mm = m & inst_mode_measurement_mask;
549
if ((mm & inst_mode_illum_mask) == inst_mode_reflection) {
550
if ((mm & inst_mode_sub_mask) == inst_mode_spot) {
551
mmode = mk_refl_spot;
552
} else if ((mm & inst_mode_sub_mask) == inst_mode_strip) {
553
mmode = mk_refl_scan;
555
return inst_unsupported;
557
} else if ((mm & inst_mode_illum_mask) == inst_mode_transmission) {
558
if ((mm & inst_mode_sub_mask) == inst_mode_spot) {
559
mmode = mk_trans_spot;
560
} else if ((mm & inst_mode_sub_mask) == inst_mode_strip) {
561
mmode = mk_trans_scan;
563
return inst_unsupported;
565
} else if ((mm & inst_mode_illum_mask) == inst_mode_emission) {
566
if ((mm & inst_mode_sub_mask) == inst_mode_spot) {
567
if ((mm & inst_mode_mod_mask) == inst_mode_disp) {
568
mmode = mk_disp_spot;
570
mmode = mk_emiss_spot;
572
} else if ((mm & inst_mode_sub_mask) == inst_mode_tele) {
573
if ((mm & inst_mode_mod_mask) == inst_mode_disp) {
574
mmode = mk_proj_spot;
576
mmode = mk_tele_spot;
578
} else if ((mm & inst_mode_sub_mask) == inst_mode_strip) {
579
mmode = mk_emiss_scan;
580
} else if ((mm & inst_mode_sub_mask) == inst_mode_ambient) {
582
} else if ((mm & inst_mode_sub_mask) == inst_mode_ambient_flash) {
583
mmode = mk_amb_flash;
585
return inst_unsupported;
700
if ((mmode = munki_convert_mode(p, m)) == mk_no_modes)
588
701
return inst_unsupported;
590
return munki_interp_code(p, munki_imp_set_mode(p, mmode, m & inst_mode_spectral));
593
/* Get a dynamic status */
594
static inst_code munki_get_status(
596
inst_status_type m, /* Requested status type */
597
...) { /* Status parameters */
598
munki *p = (munki *)pp;
605
/* Return the sensor mode */
606
if (m == inst_stat_sensmode) {
608
inst_stat_smode *smode;
613
smode = va_arg(args, inst_stat_smode *);
616
*smode = inst_stat_smode_unknown;
618
/* Get the device status */
619
ev = munki_getstatus(p, &spos, NULL);
621
return munki_interp_code(p, ev);
623
if (spos == mk_spos_proj)
624
*smode = inst_stat_smode_proj;
625
else if (spos == mk_spos_surf)
626
*smode = inst_stat_smode_ref | inst_stat_smode_disp;
627
else if (spos == mk_spos_calib)
628
*smode = inst_stat_smode_calib;
629
else if (spos == mk_spos_amb)
630
*smode = inst_stat_smode_amb;
635
/* Return the filter */
636
else if (m == inst_stat_get_filter) {
637
inst_opt_filter *filt;
641
filt = va_arg(args, inst_opt_filter *);
644
/* The ColorMunki is always UV cut */
645
*filt = inst_opt_filter_UVCut;
650
return inst_unsupported;
703
if ((rv = munki_interp_code(p, munki_imp_set_mode(p, mmode, m & inst_mode_spectral)))
707
munki_determine_capabilities(p);
654
713
* set or reset an optional mode
655
* We assume that the instrument has been initialised.
715
* Some options talk to the instrument, and these will
716
* error if it hasn't been initialised.
658
munki_set_opt_mode(inst *pp, inst_opt_mode m, ...)
719
munki_get_set_opt(inst *pp, inst_opt_type m, ...) {
660
720
munki *p = (munki *)pp;
667
if (m == inst_opt_noautocalib) {
668
munki_set_noautocalib(p, 1);
722
if (m == inst_opt_noinitcalib) {
727
losecs = va_arg(args, int);
730
munki_set_noinitcalib(p, 1, losecs);
671
} else if (m == inst_opt_autocalib) {
672
munki_set_noautocalib(p, 0);
733
} else if (m == inst_opt_initcalib) {
734
munki_set_noinitcalib(p, 0, 0);
675
737
/* Record the trigger mode */
676
738
} else if (m == inst_opt_trig_prog
677
|| m == inst_opt_trig_keyb
678
|| m == inst_opt_trig_keyb_switch) {
739
|| m == inst_opt_trig_user
740
|| m == inst_opt_trig_user_switch) {
679
741
munki_set_trig(p, m);
682
if (m == inst_opt_trig_return) {
683
munki_set_trigret(p, 1);
685
} else if (m == inst_opt_trig_no_return) {
686
munki_set_trigret(p, 0);
745
if (m == inst_opt_scan_toll) {
747
double toll_ratio = 1.0;
750
toll_ratio = va_arg(args, double);
752
return munki_interp_code(p, munki_set_scan_toll(p, toll_ratio));
760
/* Not sure if hires can be set before init */
690
761
if (m == inst_opt_highres) {
691
762
return munki_interp_code(p, munki_set_highres(p));
692
763
} else if (m == inst_opt_stdres) {
693
764
return munki_interp_code(p, munki_set_stdres(p));
696
if (m == inst_opt_scan_toll) {
698
double toll_ratio = 1.0;
701
toll_ratio = va_arg(args, double);
703
return munki_interp_code(p, munki_set_scan_toll(p, toll_ratio));
706
767
if (m == inst_opt_get_gen_ledmask) {
708
769
int *mask = NULL;
811
898
/* Constructor */
812
extern munki *new_munki(icoms *icom, instType itype, int debug, int verb)
899
extern munki *new_munki(icoms *icom, instType itype) {
815
if ((p = (munki *)calloc(sizeof(munki),1)) == NULL)
816
error("munki: malloc failed!");
819
p->icom = new_icoms();
823
/* Preliminary capabilities */
824
munki_discover_capabilities(p);
828
if (add_munkiimp(p) != MUNKI_OK) {
830
error("munki: creating munkiimp");
902
if ((p = (munki *)calloc(sizeof(munki),1)) == NULL) {
903
a1loge(icom->log, 1, "new_munki: malloc failed!\n");
907
p->log = new_a1log_d(icom->log);
833
909
/* Inst methods */
834
910
p->init_coms = munki_init_coms;
835
911
p->init_inst = munki_init_inst;
836
912
p->capabilities = munki_capabilities;
837
p->capabilities2 = munki_capabilities2;
913
p->meas_config = munki_meas_config;
838
914
p->get_serial_no = munki_get_serial_no;
915
p->check_mode = munki_check_mode;
839
916
p->set_mode = munki_set_mode;
840
p->get_status = munki_get_status;
841
p->set_opt_mode = munki_set_opt_mode;
917
p->get_set_opt = munki_get_set_opt;
842
918
p->read_strip = munki_read_strip;
843
919
p->read_sample = munki_read_sample;
844
p->needs_calibration = munki_needs_calibration;
920
p->read_refrate = munki_read_refrate;
921
p->get_n_a_cals = munki_get_n_a_cals;
845
922
p->calibrate = munki_calibrate;
846
923
p->interp_error = munki_interp_error;
924
p->config_enum = munki_config_enum;
847
925
p->del = munki_del;
928
p->itype = icom->itype;
930
/* Preliminary capabilities */
931
munki_determine_capabilities(p);
933
if ((rv = add_munkiimp(p) != MUNKI_OK)) {
935
a1loge(icom->log, 1, "new_munki: error %d creating munkiimp\n",rv);