LRESULT CALLBACK RecordsListDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { RecordsListDlg = hDlg; RecordsListDlg_list.handle = GetDlgItem(hDlg, LV_GLIST); RecordsListDlg_list.AddColumn("Game", 200); RecordsListDlg_list.AddColumn("App", 140); RecordsListDlg_list.AddColumn("Time", 130); RecordsListDlg_list.AddColumn("fn", 10); RecordsListDlg_list.FullRowSelect(); RecordsList_Populate(); initialize_mode_cb(GetDlgItem(hDlg, CMB_MODE)); } break; case WM_CLOSE: EndDialog(hDlg, 0); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCREFRESH: { RecordsList_Populate(); } break; case BTN_PLAY: RecordsList_PlaySelected(); break; case BTN_DELETE: RecordsList_DeleteSelected(); break; case CMB_MODE: if (HIWORD(wParam)==CBN_SELCHANGE) { if (activate_mode(SendMessage(GetDlgItem(hDlg, CMB_MODE), CB_GETCURSEL, 0, 0))){ SendMessage(hDlg, WM_CLOSE, 0, 0); } } break; }; break; case WM_NOTIFY: if(((LPNMHDR)lParam)->code==NM_DBLCLK && ((LPNMHDR)lParam)->hwndFrom==RecordsListDlg_list.handle){ RecordsList_PlaySelected(); } break; }; return 0; }
/* * set measurement mode * We assume that the instrument has been initialised. */ static inst_code dtp41_set_mode(inst *pp, inst_mode m) { dtp41 *p = (dtp41 *)pp; inst_code ev; if ((ev = dtp41_check_mode(pp, m)) != inst_ok) return ev; p->lastmode = m; if (p->lastmode != p->mode) { return activate_mode(p); } return inst_ok; }
/* Return the instrument error code */ static inst_code dtp41_read_sample( inst *pp, char *name, /* Strip name (7 chars) */ ipatch *val, /* Pointer to instrument patch value */ instClamping clamp) { /* NZ if clamp XYZ/Lab to be +ve */ dtp41 *p = (dtp41 *)pp; char *tp; static char buf[MAX_RD_SIZE]; int i, se; inst_code ev = inst_ok; int switch_trig = 0; int user_trig = 0; if (!p->gotcoms) return inst_no_coms; if (!p->inited) return inst_no_init; /* Configure for static mode */ p->lastmode = (p->lastmode & ~inst_mode_sub_mask) | inst_mode_spot; activate_mode(p); /* Set static measurement mode */ if ((ev = dtp41_command(p, "0013CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; if (p->trig == inst_opt_trig_user_switch) { /* Wait for the Read status, or a user trigger/abort */ for (;;) { if ((ev = dtp41_command(p, "", buf, MAX_MES_SIZE, 0.5)) != inst_ok) { if ((ev & inst_mask) == inst_needs_cal) p->need_cal = 1; if ((ev & inst_imask) != DTP41_TIMEOUT) return ev; /* Instrument or comms error */ /* Timed out */ if (p->uicallback != NULL) { /* Check for user trigger */ if ((ev = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) { if (ev == inst_user_abort) return ev; /* User abort */ if (ev == inst_user_trig) { user_trig = 1; break; /* User trigger */ } } } } else { /* Assume read status and trigger */ switch_trig = 1; break; /* Switch activated */ } } /* Notify of trigger */ if (p->uicallback) p->uicallback(p->uic_cntx, inst_triggered); } else if (p->trig == inst_opt_trig_user) { if (p->uicallback == NULL) { a1logd(p->log, 1, "dtp41: inst_opt_trig_user but no uicallback function set!\n"); return inst_unsupported; } for (;;) { if ((ev = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) { if (ev == inst_user_abort) return ev; /* Abort */ if (ev == inst_user_trig) { user_trig = 1; break; /* Trigger */ } } msec_sleep(200); } /* Notify of trigger */ if (p->uicallback) p->uicallback(p->uic_cntx, inst_triggered); /* Progromatic Trigger */ } else { /* Check for abort */ if (p->uicallback != NULL && (ev = p->uicallback(p->uic_cntx, inst_armed)) == inst_user_abort) return ev; /* Abort */ } /* Trigger a read if the switch has not been used */ if (switch_trig == 0) { /* Do a read */ if ((ev = dtp41_command(p, "RM\r", buf, MAX_MES_SIZE, 20.0)) != inst_ok) { if ((ev & inst_mask) == inst_needs_cal) p->need_cal = 1; return ev; } } /* Gather the results in D50_2 XYZ */ if ((ev = dtp41_command(p, "0405TS\r", buf, MAX_RD_SIZE, 0.5)) != inst_ok) return ev; /* Strip misread */ /* Parse the buffer */ /* Replace '\r' with '\000' */ for (tp = buf; *tp != '\000'; tp++) { if (*tp == '\r') *tp = '\000'; } val->XYZ[0] = val->XYZ[1] = val->XYZ[2] = 0.0; /* for all the readings taken */ for (tp = buf, i = 0; i < p->nstaticr; i++) { double XYZ[3]; if (*tp == '\000') return inst_protocol_error; if (sscanf(tp, " %lf %lf %lf ", &XYZ[0], &XYZ[1], &XYZ[2]) != 3) { return inst_protocol_error; } val->XYZ[0] += XYZ[0]; val->XYZ[1] += XYZ[1]; val->XYZ[2] += XYZ[2]; tp += strlen(tp) + 1; } /* Average */ val->XYZ[0] /= (double)p->nstaticr; val->XYZ[1] /= (double)p->nstaticr; val->XYZ[2] /= (double)p->nstaticr; /* This may not change anything since instrument may clamp */ if (clamp) icmClamp3(val->XYZ, val->XYZ); val->loc[0] = '\000'; if ((p->mode & inst_mode_illum_mask) == inst_mode_transmission) val->mtype = inst_mrt_transmissive; else val->mtype = inst_mrt_reflective; val->XYZ_v = 1; val->sp.spec_n = 0; val->duration = 0.0; if (p->mode & inst_mode_spectral) { int j; /* Gather the results in Spectral reflectance */ if ((ev = dtp41_command(p, "0403TS\r", buf, MAX_RD_SIZE, 0.5)) != DTP41_OK) return ev; /* Strip misread */ /* Parse the buffer */ /* Replace '\r' with '\000' */ for (tp = buf; *tp != '\000'; tp++) { if (*tp == '\r') *tp = '\000'; } for (j = 0; j < 31; j++) val->sp.spec[j] = 0.0; /* Get each readings spetra */ for (tp = buf, i = 0; i < p->nstaticr; i++) { char *tpp; if (strlen(tp) < (31 * 8 - 1)) { return inst_protocol_error; } /* Read the spectral value */ for (tpp = tp, j = 0; j < 31; j++, tpp += 8) { char c; c = tpp[7]; tpp[7] = '\000'; val->sp.spec[j] += atof(tpp); tpp[7] = c; } tp += strlen(tp) + 1; } /* Average the result */ for (j = 0; j < 31; j++) val->sp.spec[j] /= (double)p->nstaticr; val->sp.spec_n = 31; val->sp.spec_wl_short = 400.0; val->sp.spec_wl_long = 700.0; val->sp.norm = 100.0; } /* Set back to dynamic measurement mode */ if ((ev = dtp41_command(p, "0113CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; if (user_trig) return inst_user_trig; return inst_ok; }
/* Return the instrument error code */ static inst_code dtp41_read_strip( inst *pp, char *name, /* Strip name (7 chars) */ int npatch, /* Number of patches in the pass */ char *pname, /* Pass name (3 chars) */ int sguide, /* Guide number */ double pwid, /* Patch length in mm (For DTP41) */ double gwid, /* Gap length in mm (For DTP41) */ double twid, /* Trailer length in mm (For DTP41T) */ ipatch *vals) { /* Pointer to array of instrument patch values */ dtp41 *p = (dtp41 *)pp; char tbuf[200], *tp; static char buf[MAX_RD_SIZE]; int i, se; inst_code ev = inst_ok; int switch_trig = 0; int user_trig = 0; if (!p->gotcoms) return inst_no_coms; if (!p->inited) return inst_no_init; /* Configure for dynamic mode */ p->lastmode = (p->lastmode & ~inst_mode_sub_mask) | inst_mode_strip; activate_mode(p); build_strip(p, tbuf, name, npatch, pname, sguide, pwid, gwid, twid); /* Send strip definition */ if ((ev = dtp41_command(p, tbuf, buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; if (p->trig == inst_opt_trig_user_switch) { /* Wait for the Read status, or a user trigger/abort */ for (;;) { if ((ev = dtp41_command(p, "", buf, MAX_MES_SIZE, 0.5)) != inst_ok) { if ((ev & inst_mask) == inst_needs_cal) p->need_cal = 1; if ((ev & inst_imask) != DTP41_TIMEOUT) return ev; /* Instrument or comms error */ /* Timed out */ if (p->uicallback != NULL) { /* Check for user trigger */ if ((ev = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) { if (ev == inst_user_abort) return ev; /* User abort */ if (ev == inst_user_trig) { user_trig = 1; break; } } } } else { /* Got read status - assume triggered */ switch_trig = 1; break; /* Switch activated */ } } /* Notify of trigger */ if (p->uicallback) p->uicallback(p->uic_cntx, inst_triggered); } else if (p->trig == inst_opt_trig_user) { if (p->uicallback == NULL) { a1logd(p->log, 1, "dtp41: inst_opt_trig_user but no uicallback function set!\n"); return inst_unsupported; } for (;;) { if ((ev = p->uicallback(p->uic_cntx, inst_armed)) != inst_ok) { if (ev == inst_user_abort) return ev; /* Abort */ if (ev == inst_user_trig) { user_trig = 1; break; /* Trigger */ } } msec_sleep(200); } /* Notify of trigger */ if (p->uicallback) p->uicallback(p->uic_cntx, inst_triggered); /* Progromatic Trigger */ } else { /* Check for abort */ if (p->uicallback != NULL && (ev = p->uicallback(p->uic_cntx, inst_armed)) == inst_user_abort) return ev; /* Abort */ } /* Trigger a read if the switch has not been used */ if (switch_trig == 0) { /* Do a strip read */ if ((ev = dtp41_command(p, "RM\r", buf, MAX_MES_SIZE, 30.0)) != inst_ok) { if ((ev & inst_mask) == inst_needs_cal) p->need_cal = 1; return ev; } } /* Gather the results in D50_2 XYZ */ if ((ev = dtp41_command(p, "0405TS\r", buf, MAX_RD_SIZE, 0.5 + npatch * 0.1)) != inst_ok) return ev; /* Strip misread */ /* Parse the buffer */ /* Replace '\r' with '\000' */ for (tp = buf; *tp != '\000'; tp++) { if (*tp == '\r') *tp = '\000'; } for (tp = buf, i = 0; i < npatch; i++) { if (*tp == '\000') return inst_protocol_error; if (sscanf(tp, " %lf %lf %lf ", &vals[i].XYZ[0], &vals[i].XYZ[1], &vals[i].XYZ[2]) != 3) { if (sscanf(tp, " %lf %lf %lf ", &vals[i].XYZ[0], &vals[i].XYZ[1], &vals[i].XYZ[2]) != 3) { return inst_protocol_error; } } vals[i].loc[0] = '\000'; if ((p->mode & inst_mode_illum_mask) == inst_mode_transmission) vals[i].mtype = inst_mrt_transmissive; else vals[i].mtype = inst_mrt_reflective; vals[i].XYZ_v = 1; vals[i].sp.spec_n = 0; vals[i].duration = 0.0; tp += strlen(tp) + 1; } if (p->mode & inst_mode_spectral) { /* Gather the results in Spectral reflectance */ if ((ev = dtp41_command(p, "0403TS\r", buf, MAX_RD_SIZE, 0.5 + npatch * 0.1)) != inst_ok) return ev; /* Strip misread */ /* Parse the buffer */ /* Replace '\r' with '\000' */ for (tp = buf; *tp != '\000'; tp++) { if (*tp == '\r') *tp = '\000'; } /* Get each patches spetra */ for (tp = buf, i = 0; i < npatch; i++) { int j; char *tpp; if (strlen(tp) < (31 * 8 - 1)) { return inst_protocol_error; } /* Read the spectral value */ for (tpp = tp, j = 0; j < 31; j++, tpp += 8) { char c; c = tpp[7]; tpp[7] = '\000'; vals[i].sp.spec[j] = atof(tpp); tpp[7] = c; } vals[i].sp.spec_n = 31; vals[i].sp.spec_wl_short = 400.0; vals[i].sp.spec_wl_long = 700.0; vals[i].sp.norm = 100.0; tp += strlen(tp) + 1; } } if (user_trig) return inst_user_trig; return inst_ok; }
/* return non-zero on an error, with instrument error code */ static inst_code dtp41_init_inst(inst *pp) { dtp41 *p = (dtp41 *)pp; static char tbuf[100], buf[MAX_MES_SIZE]; inst_code ev = inst_ok; a1logd(p->log, 2, "dtp41_init_inst: called\n"); if (p->gotcoms == 0) return inst_internal_error; /* Must establish coms before calling init */ /* Resetting instrument resets the baud rate, so do manual reset. */ /* Set emulation mode to DTP41 */ if ((ev = dtp41_command(p, "0010CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Turn echoing of characters off */ if ((ev = dtp41_command(p, "0009CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Response delimeter to CR */ if ((ev = dtp41_command(p, "0008CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Get the model and version number */ if ((ev = dtp41_command(p, "SV\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Check that it is a DTP41 */ if ( strlen(buf) < 12 || strncmp(buf,"X-Rite DTP41",11) != 0 || (buf[11] != '1' && buf[11] != '2')) return inst_unknown_model; /* Set Language to English */ if ((ev = dtp41_command(p, "0000CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Beeper to medium */ if ((ev = dtp41_command(p, "0201CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Automatic Transmit off */ if ((ev = dtp41_command(p, "0005CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set decimal point on */ if ((ev = dtp41_command(p, "0106CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set color data separator to TAB */ if ((ev = dtp41_command(p, "0207CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set 2 decimal digit resolution */ if ((ev = dtp41_command(p, "020ACF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Min/Max mode off */ if ((ev = dtp41_command(p, "000CCF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set persistent errors off */ if ((ev = dtp41_command(p, "000DCF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set show data labels mode off */ if ((ev = dtp41_command(p, "000FCF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set drive motor calibration at power up to off */ if ((ev = dtp41_command(p, "0011CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Reflection calibration timeout to 24 Hrs */ if ((ev = dtp41_command(p, "181ECF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Trailer timout to 2 seconds */ if ((ev = dtp41_command(p, "021FCF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Transmission calibration timeout to 24 Hrs */ if ((ev = dtp41_command(p, "1820CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) { /* This may fail if the firmware version is < v8212 */ if ((ev & inst_imask) != DTP41_PRM_RANGE_ERROR) return ev; } /* - - - - - - - - - - - - - - - - - - - - - - - - */ /* Setup for the type of measurements we want to do */ /* Enable the read microswitch */ if ((ev = dtp41_command(p, "01PB\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; p->trig = inst_opt_trig_user_switch; /* Set dynamic measurement mode */ if ((ev = dtp41_command(p, "0113CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set instrument to reflectance mode */ if ((ev = dtp41_command(p, "0019CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set data format to Reflectance, so TS can select. */ if ((ev = dtp41_command(p, "0318CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set density format to spectral */ if ((ev = dtp41_command(p, "0417CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set Illuminant to D50_2 */ if ((ev = dtp41_command(p, "0416CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set static samples to 10 */ if ((ev = dtp41_command(p, "0A14CF\r", buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; /* Set static readings to configured number (usually 5) */ sprintf(tbuf, "%02x15CF\r", p->nstaticr); if ((ev = dtp41_command(p, tbuf, buf, MAX_MES_SIZE, 1.5)) != inst_ok) return ev; #ifdef NEVER /* See what the transmission mode is up to */ dtp41_command(p, "DEVELOPERPW\r", buf, MAX_MES_SIZE, 1.5); dtp41_command(p, "0119CF\r", buf, MAX_MES_SIZE, 1.5); dtp41_command(p, "36OD\r", buf, MAX_MES_SIZE, 1.5); dtp41_command(p, "1422OD\r", buf, MAX_MES_SIZE, 1.5); #endif /* We are configured in this mode now */ p->mode = inst_mode_ref_strip; if (p->lastmode != p->mode) { if ((ev = activate_mode(p)) != inst_ok) return ev; } p->inited = 1; a1logd(p->log, 2, "dtp41_init_inst: instrument inited OK\n"); return inst_ok; }