439 lines
11 KiB
C++
439 lines
11 KiB
C++
// 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)
|
|
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<void(int option, void* data)> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// ÖØÆôɨÃèÒÇ
|
|
/// </summary>
|
|
void CA4::OnBnClickedBtnReboot()
|
|
{
|
|
auto parent = (CHuaGoCorrectDlg*)GetParent();
|
|
if (parent->m_drv.get() && parent->m_drv->IsConnected()) {
|
|
parent->m_drv->Reboot();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ÉèÖÃvidpid
|
|
/// </summary>
|
|
void CA4::OnBnClickedBtnSetvidpid()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// »ñÈ¡vidpid
|
|
/// </summary>
|
|
void CA4::OnBnClickedBtnGetvidpid()
|
|
{
|
|
// TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
|
|
}
|
|
|
|
/// <summary>
|
|
/// »ñÈ¡ÐòÁкÅ
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Éú³ÉÐòÁкÅ
|
|
/// </summary>
|
|
void CA4::OnBnClickedBtnGenserial()
|
|
{
|
|
// TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
|
|
}
|
|
|
|
/// <summary>
|
|
/// ÉèÖÃÐòÁкÅ
|
|
/// </summary>
|
|
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()) {
|
|
parent->m_drv->GetRatio(0, ratio);
|
|
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()) {
|
|
parent->m_drv->GetRatio(1, ratio);
|
|
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()) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
void CA4::OnBnClickedBtnSetver()
|
|
{
|
|
auto parent = (CHuaGoCorrectDlg*)GetParent();
|
|
if (parent->m_drv.get() && parent->m_drv->IsConnected()) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
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: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
|
|
}
|