// A4.cpp : 实现文件 // #include "stdafx.h" #include "HuaGoCorrect.h" #include "A4.h" #include "afxdialogex.h" #include "HuaGoCorrectDlg.h" // CA4 对话框 IMPLEMENT_DYNAMIC(CA4, CDialog) CA4::CA4(CWnd* pParent /*=NULL*/) : CDialog(CA4::IDD, pParent) { m_iLastIndex = 0; m_iSelIndex = 0; jsonparams = { 0 }; params = { 0 }; } CA4::~CA4() { } void CA4::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_BTNGET_SERIAL, m_GetSerial); DDX_Control(pDX,IDC_BTN_SET_SERIAL,m_SetSerial); DDX_Control(pDX, IDC_BTN_GENSERIAL, m_AutoGenSerial); DDX_Control(pDX, IDC_BTN_GETVIDPID, m_GetVid); DDX_Control(pDX, IDC_BTN_SETVIDPID, m_SetVid); DDX_Control(pDX, IDC_BTN_REBOOT, m_Reboot); for (size_t i = 0; i < Exposures.size(); i++) { DDX_Text(pDX, Exposures[i], params.Exposures[i]);; } for (size_t i = 0; i < Gains.size(); i++) { DDX_Text(pDX, Gains[i], params.Gain[i]); } for (size_t i = 0; i < Offsets.size(); i++) { DDX_Text(pDX, Offsets[i], params.Offset[i]); } DDX_Control(pDX, IDC_CMB_A4FlatModel, m_A4FlatModel); } BEGIN_MESSAGE_MAP(CA4, CDialog) ON_CBN_SELCHANGE(IDC_CMB_A4FlatModel, &CA4::OnCbnSelChangeA4FlatModel) ON_BN_CLICKED(IDC_BTN_REBOOT, &CA4::OnBnClickedBtnReboot) ON_BN_CLICKED(IDC_BTN_SETVIDPID, &CA4::OnBnClickedBtnSetvidpid) ON_BN_CLICKED(IDC_BTN_GETVIDPID, &CA4::OnBnClickedBtnGetvidpid) ON_BN_CLICKED(IDC_BTNGET_SERIAL, &CA4::OnBnClickedBtngetSerial) ON_BN_CLICKED(IDC_BTN_GENSERIAL, &CA4::OnBnClickedBtnGenserial) ON_BN_CLICKED(IDC_BTN_SET_SERIAL, &CA4::OnBnClickedBtnSetSerial) ON_BN_CLICKED(IDC_BTN_GETHOR, &CA4::OnBnClickedBtnGethor) ON_BN_CLICKED(IDC_BTN_GETVER, &CA4::OnBnClickedBtnGetver) ON_BN_CLICKED(IDC_BTN_SETHOR, &CA4::OnBnClickedBtnSethor) ON_BN_CLICKED(IDC_BTN_SETVER, &CA4::OnBnClickedBtnSetver) ON_BN_CLICKED(IDC_BTNGET_VERSION, &CA4::OnBnClickedBtngetVersion) ON_EN_CHANGE(IDC_tbxSerial, &CA4::OnEnChangetbxserial) ON_BN_CLICKED(IDC_BTN_GETEXPOS, &CA4::OnBnClickedBtnGetexpos) ON_BN_CLICKED(IDC_BTN_SETEXPOS, &CA4::OnBnClickedBtnSetexpos) ON_BN_CLICKED(IDC_BTNAUP, &CA4::OnBnClickedBtnaup) ON_BN_CLICKED(IDC_BTNADOWN, &CA4::OnBnClickedBtnadown) ON_BN_CLICKED(IDC_BTNBUP, &CA4::OnBnClickedBtnbup) ON_BN_CLICKED(IDC_BTNBDOWN, &CA4::OnBnClickedBtnbdown) ON_BN_CLICKED(IDC_BTNGET_MB_VERSION, &CA4::OnBnClickedBtngetMbVersion) END_MESSAGE_MAP() // CA4 消息处理程序 BOOL CA4::OnInitDialog() { CDialog::OnInitDialog(); // TODO: 在此添加额外的初始化 LoadCfg(); m_A4FlatModel.InsertString(0, _T("彩色校正模式")); m_A4FlatModel.InsertString(1, _T("彩色")); m_A4FlatModel.InsertString(2, _T("灰度校正模式")); m_A4FlatModel.InsertString(3, _T("灰度")); m_A4FlatModel.SetCurSel(0); GetDlgItem(IDC_BTN_GENSERIAL)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_GETVIDPID)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_SETVIDPID)->EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CA4::SetCallBack(std::function t_call) { m_func = t_call; } void CA4::EnableItem(bool enable) { this->GetDlgItem(IDC_BTNGET_SERIAL) ->EnableWindow(enable); this->GetDlgItem(IDC_BTN_GENSERIAL)->EnableWindow(enable); this->GetDlgItem(IDC_BTN_SET_SERIAL)->EnableWindow(enable); this->GetDlgItem(IDC_BTN_GETVIDPID)->EnableWindow(enable); this->GetDlgItem(IDC_BTN_SETVIDPID)->EnableWindow(enable); this->GetDlgItem(IDC_BTN_REBOOT)->EnableWindow(enable); } void CA4::SendCorrectParam() { UpdateData(); int index = m_A4FlatModel.GetCurSel(); auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { parent->m_drv->SendFlatData(params, index); } } void CA4::OnCbnSelChangeA4FlatModel() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get()&&parent->m_drv->IsConnected()) { auto correctdata = parent->m_drv->GetFlatData(); updateA4Config(correctdata); } } void CA4::updateA4Config(CaptureParams& pValues) { UpdateData(TRUE); switch (m_A4FlatModel.GetCurSel()) { case 0: memcpy(params.Exposures, pValues.correctColorExposure, sizeof(pValues.correctColorExposure)); memcpy(params.Gain, pValues.correctColorGain, sizeof(pValues.correctColorGain)); memcpy(params.Offset, pValues.correctColorOffset, sizeof(pValues.correctColorOffset)); break; case 1: memcpy(params.Exposures, pValues.colorExposure, sizeof(pValues.colorExposure)); memcpy(params.Gain, pValues.colorGain, sizeof(pValues.colorGain)); memcpy(params.Offset, pValues.colorOffset, sizeof(pValues.colorOffset)); break; case 2: memcpy(params.Exposures, pValues.correctGrayExposure, sizeof(pValues.correctGrayExposure)); memcpy(params.Gain, pValues.correctGrayGain, sizeof(pValues.correctGrayGain)); memcpy(params.Offset, pValues.correctGrayOffset, sizeof(pValues.correctGrayOffset)); break; case 3: memcpy(params.Exposures, pValues.grayExposure, sizeof(pValues.grayExposure)); memcpy(params.Gain, pValues.grayGain, sizeof(pValues.grayGain)); memcpy(params.Offset, pValues.grayOffset, sizeof(pValues.grayOffset)); break; default: break; } UpdateData(FALSE); } void CA4::LoadCfg() { UpdateData(TRUE); jsonConfig.ReadParam(jsonparams); memcpy(params.Exposures, jsonparams.correctColorExposure, sizeof(jsonparams.correctColorExposure)); memcpy(params.Gain, jsonparams.correctColorGain, sizeof(jsonparams.correctColorGain)); memcpy(params.Offset, jsonparams.correctColorOffset, sizeof(jsonparams.correctColorOffset)); UpdateData(FALSE); } /// /// 重启扫描仪 /// void CA4::OnBnClickedBtnReboot() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { bool ret= ((CButton*)GetDlgItem(IDC_CKBLOADER))->GetCheck(); parent->m_drv->Reboot(ret); } } /// /// 设置vidpid /// void CA4::OnBnClickedBtnSetvidpid() { auto ret = MessageBox(L"设置前请务必确认校正以及速度模式等与设备相关的设置已完成,避免更改VID PID后部分功能不可用!确认设置吗?", L"提示", MB_YESNO | MB_ICONWARNING); if (ret == IDOK || ret == IDYES) { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { auto vidpid = AqrVIDPID(); parent->m_drv->GetOrSetVIDPID(vidpid, false); } } } /// /// 获取vidpid /// void CA4::OnBnClickedBtnGetvidpid() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int vidpid = 0; parent->m_drv->GetOrSetVIDPID(vidpid, true); VIDPID tvpd; tvpd.Value = vidpid; UpdateVidPid(tvpd); } } /// /// 获取序列号 /// void CA4::OnBnClickedBtngetSerial() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { std::string serial = parent->m_drv->GetSerialNum(); CString c_serial(serial.c_str()); SetDlgItemText(IDC_tbxSerial, c_serial); } } /// /// 生成序列号 /// void CA4::OnBnClickedBtnGenserial() { // TODO: 在此添加控件通知处理程序代码 } /// /// 设置序列号 /// void CA4::OnBnClickedBtnSetSerial() { auto parent = (CHuaGoCorrectDlg*)GetParent(); CString cserial; GetDlgItemText(IDC_tbxSerial, cserial); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { if (!cserial.IsEmpty()) { USES_CONVERSION; std::string str(W2A(cserial)); parent->m_drv->SetSerialNum(str); } } } void CA4::OnBnClickedBtnGethor() { auto parent = (CHuaGoCorrectDlg*)GetParent(); int ratio = 0; if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int dpi = parent->GetSelectDPIIndex() == 0 ? 1 : (parent->GetSelectDPIIndex() == 1 ? 2 : 3); parent->m_drv->GetRatio(0, ratio, dpi); float f_ratio = *(float*)∶ CString str; str.Format(L"%.4f", f_ratio); SetDlgItemText(IDC_tbxHOR, str); } } void CA4::OnBnClickedBtnGetver() { auto parent = (CHuaGoCorrectDlg*)GetParent(); int ratio = 0; if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int dpi = parent->GetSelectDPIIndex() == 0 ? 1 : (parent->GetSelectDPIIndex() == 1 ? 2 : 3); parent->m_drv->GetRatio(1, ratio, dpi); float f_ratio = *(float*)∶ CString str; str.Format(L"%.4f", f_ratio); SetDlgItemText(IDC_tbxVER, str); } } void CA4::OnBnClickedBtnSethor() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int dpi = parent->GetSelectDPIIndex() == 0 ? 1 : (parent->GetSelectDPIIndex() == 1 ? 2 : 3); CString str; GetDlgItemText(IDC_tbxHOR, str); USES_CONVERSION; std::string s_str(W2A(str)); float f_value = atof(s_str.c_str()); int value = *(int*)&f_value; parent->m_drv->SetRatio(0, value, dpi); } } void CA4::OnBnClickedBtnSetver() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int dpi = parent->GetSelectDPIIndex() == 0 ? 1 : (parent->GetSelectDPIIndex() == 1 ? 2 : 3); CString str; GetDlgItemText(IDC_tbxVER, str); USES_CONVERSION; std::string s_str(W2A(str)); float f_value = atof(s_str.c_str()); int value = *(int*)&f_value; parent->m_drv->SetRatio(1, value, dpi); } } void CA4::OnBnClickedBtngetVersion() { auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { std::string ver = parent->m_drv->GetFWVersion(); if (ver.size() > 0) { CString str(ver.c_str()); SetDlgItemText(IDC_tbxVersion, str); } } } #define MAX_LENGTH 14 void CA4::OnEnChangetbxserial() { // TODO: 如果该控件是 RICHEDIT 控件,它将不 // 发送此通知,除非重写 CDialog::OnInitDialog() // 函数并调用 CRichEditCtrl().SetEventMask(), // 同时将 ENM_CHANGE 标志“或”运算到掩码中。 auto tbxSerial = (CEdit*)GetDlgItem(IDC_tbxSerial); CString str; GetDlgItemText(IDC_tbxSerial, str); int length = str.GetLength(); if (length > 14) { if (tbxSerial) { SetDlgItemText(IDC_tbxSerial, str.Left(MAX_LENGTH)); tbxSerial->SetSel(str.GetLength(), str.GetLength()); } } } void CA4::OnBnClickedBtnGetexpos() { // TODO: 在此添加控件通知处理程序代码 auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { int esposeA, exposeB; parent->m_drv->GetExpose(esposeA, exposeB); CString expA, expB; expA.Format(L"%d", esposeA); expB.Format(L"%d", exposeB); SetDlgItemText(IDC_tbxUVAExpos, expA); SetDlgItemText(IDC_tbxUVBExpos, expB); } } void CA4::OnBnClickedBtnSetexpos() { // TODO: 在此添加控件通知处理程序代码 auto parent = (CHuaGoCorrectDlg*)GetParent(); int esposeA, exposeB; CString expA, expB; GetDlgItemText(IDC_tbxUVAExpos, expA); GetDlgItemText(IDC_tbxUVBExpos, expB); USES_CONVERSION; std::string str_a(W2A(expA)); std::string str_b(W2A(expB)); esposeA= atoi(str_a.c_str()); exposeB = atoi(str_b.c_str()); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { parent->m_drv->SetExpose(esposeA, exposeB); } } void CA4::OnBnClickedBtnaup() { // TODO: 在此添加控件通知处理程序代码 UpdateGains(IDC_BTNAUP, true); } void CA4::OnBnClickedBtnadown() { // TODO: 在此添加控件通知处理程序代码 UpdateGains(IDC_BTNADOWN, false); } void CA4::OnBnClickedBtnbup() { // TODO: 在此添加控件通知处理程序代码 UpdateGains(IDC_BTNBUP, true); } void CA4::OnBnClickedBtnbdown() { // TODO: 在此添加控件通知处理程序代码 UpdateGains(IDC_BTNBDOWN, false); } void CA4::UpdateGains(int id, bool increase) { UpdateData(TRUE); int offect; CString offectstr; GetDlgItemText(IDC_tbxOffect, offectstr); USES_CONVERSION; std::string str_b(W2A(offectstr)); offect = atoi(str_b.c_str()); if (offect <= 0) offect = 1; if ((id == IDC_BTNAUP || id == IDC_BTNBUP) && increase) { int startindex = id == IDC_BTNAUP ? 0 : 6; for (size_t i = startindex; i < (6+ startindex); i++) { params.Gain[i] += offect; } } else if((id==IDC_BTNADOWN||id==IDC_BTNBDOWN)&&!increase) { int startindex = id == IDC_BTNADOWN ? 0 : 6; for (size_t i = startindex; i < (6 + startindex); i++) { params.Gain[i] -= offect; } } UpdateData(FALSE); } void CA4::OnEnChangetbxfrexposure2() { // TODO: 如果该控件是 RICHEDIT 控件,它将不 // 发送此通知,除非重写 CDialog::OnInitDialog() // 函数并调用 CRichEditCtrl().SetEventMask(), // 同时将 ENM_CHANGE 标志“或”运算到掩码中。 // TODO: 在此添加控件通知处理程序代码 } void CA4::OnBnClickedBtngetMbVersion() { // TODO: 在此添加控件通知处理程序代码 auto parent = (CHuaGoCorrectDlg*)GetParent(); if (parent->m_drv.get() && parent->m_drv->IsConnected()) { std::string version = parent->m_drv->GetMbVersion(); CString vs(version.c_str()); SetDlgItemText(IDC_tbxMbVersion, vs); } } int CA4::AqrVIDPID() { VIDPID t_vidpid = { 0 }; CString str_vid, str_pid; GetDlgItemText(IDC_tbxVID, str_vid); str_vid.Replace(L"0x",L""); USES_CONVERSION; std::string str(W2A(str_vid)); t_vidpid.VID = strtol(str.c_str(),NULL,16);// atoi(str.c_str()); GetDlgItemText(IDC_tbxPID, str_pid); str_pid.Replace(L"0x", L""); std::string cstr_pid(W2A(str_pid)); t_vidpid.PID = strtol(cstr_pid.c_str(), NULL, 16);// atoi(cstr_pid.c_str()); return t_vidpid.Value; } void CA4::UpdateVidPid(VIDPID vidpid) { if (vidpid.PID != 0 && vidpid.VID != 0) { CString str_vid, str_pid; str_vid.Format(L"0x%x", vidpid.VID); str_pid.Format(L"0x%x", vidpid.PID); GetDlgItem(IDC_tbxVID)->SetWindowText(str_vid); GetDlgItem(IDC_tbxPID)->SetWindowText(str_pid); } else { MessageBox(L"错误的VID PID", L"提示", MB_OK); } }