736 lines
18 KiB
C++
736 lines
18 KiB
C++
|
||
// HuaGoCorrectDlg.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "HuaGoCorrect.h"
|
||
#include "HuaGoCorrectDlg.h"
|
||
#include "afxdialogex.h"
|
||
#include "scn_config.h"
|
||
#include <numeric>
|
||
#include "imageprocess.h"
|
||
#include <iostream>
|
||
#include <fstream>
|
||
#include "gscan3399.h"
|
||
#include "gscn_drv.h"
|
||
#include "id_config.h"
|
||
|
||
using namespace std;
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#endif
|
||
|
||
#define N_TIME_SEC 1000 //一秒时间间隔
|
||
#define N_TIME_SHOW 300 //0.2s刷新显示
|
||
#define N_TIMER_SEC 1
|
||
#define N_TIMER_SHOW 2
|
||
|
||
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
|
||
|
||
class CAboutDlg : public CDialogEx
|
||
{
|
||
public:
|
||
CAboutDlg();
|
||
|
||
// 对话框数据
|
||
enum { IDD = IDD_ABOUTBOX };
|
||
|
||
protected:
|
||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||
|
||
// 实现
|
||
protected:
|
||
DECLARE_MESSAGE_MAP()
|
||
};
|
||
|
||
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
|
||
{
|
||
}
|
||
|
||
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialogEx::DoDataExchange(pDX);
|
||
}
|
||
|
||
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
|
||
END_MESSAGE_MAP()
|
||
|
||
|
||
// CHuaGoCorrectDlg 对话框
|
||
|
||
CHuaGoCorrectDlg::CHuaGoCorrectDlg(CWnd* pParent /*=NULL*/)
|
||
: CDialogEx(CHuaGoCorrectDlg::IDD, pParent)
|
||
{
|
||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||
|
||
papercount = 0;
|
||
ls_flat = FALSE;
|
||
m_bExit = FALSE;
|
||
|
||
m_iPicIndex = 0;
|
||
m_iflatIndex = -2;
|
||
|
||
m_iDpiIndex = 0;
|
||
m_iColorIndex = 0;
|
||
|
||
b_review = FALSE;
|
||
b_suspend = FALSE;
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialogEx::DoDataExchange(pDX);
|
||
DDX_Control(pDX, IDC_TAB1, m_tab);
|
||
DDX_Control(pDX, IDC_dpi_comboBox, m_ComboxDpi);
|
||
DDX_Control(pDX, IDC_color_comboBox, m_ComboxColor);
|
||
DDX_Control(pDX, IDC_lsFpgaFlat, m_A4Scanner);
|
||
DDX_Control(pDX, IDC_CMB_USBS, m_Usbs);
|
||
DDX_Text(pDX, IDC_EDIT_HOUR, s_hour);
|
||
DDX_Text(pDX, IDC_EDIT_MINUTE, s_minute);
|
||
DDX_Text(pDX, IDC_EDIT_SECOND, s_second);
|
||
}
|
||
|
||
BEGIN_MESSAGE_MAP(CHuaGoCorrectDlg, CDialogEx)
|
||
ON_WM_SYSCOMMAND()
|
||
ON_WM_PAINT()
|
||
ON_WM_QUERYDRAGICON()
|
||
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CHuaGoCorrectDlg::OnTcnSelChangeTab)
|
||
ON_BN_CLICKED(IDC_CheckParamSet, &CHuaGoCorrectDlg::OnBnClickedCheckparamset)
|
||
ON_BN_CLICKED(IDC_CheckParamRead, &CHuaGoCorrectDlg::OnBnClickedCheckparamread)
|
||
ON_BN_CLICKED(IDC_BTN_FLAT, &CHuaGoCorrectDlg::OnBnClickedBtnFlat)
|
||
ON_CBN_SELCHANGE(IDC_dpi_comboBox, &CHuaGoCorrectDlg::OnCbnSelChangeDpi)
|
||
ON_CBN_SELCHANGE(IDC_color_comboBox, &CHuaGoCorrectDlg::OnCbnSelChangeColor)
|
||
ON_WM_TIMER()
|
||
ON_BN_CLICKED(IDC_BTN_SELECTFILE, &CHuaGoCorrectDlg::OnBnClickedBtnSelectfile)
|
||
ON_BN_CLICKED(IDC_BTN_UPDATE, &CHuaGoCorrectDlg::OnBnClickedBtnUpdate)
|
||
ON_BN_CLICKED(IDC_BTN_REFRESH, &CHuaGoCorrectDlg::OnBnClickedBtnRefresh)
|
||
ON_CBN_SELCHANGE(IDC_CMB_USBS, &CHuaGoCorrectDlg::OnCbnSelchangeCmbUsbs)
|
||
ON_BN_CLICKED(IDC_BTNSTART, &CHuaGoCorrectDlg::OnBnClickedBtnstart)
|
||
ON_BN_CLICKED(IDC_BTNSTOP, &CHuaGoCorrectDlg::OnBnClickedBtnstop)
|
||
END_MESSAGE_MAP()
|
||
|
||
|
||
// CHuaGoCorrectDlg 消息处理程序
|
||
|
||
BOOL CHuaGoCorrectDlg::OnInitDialog()
|
||
{
|
||
CDialogEx::OnInitDialog();
|
||
// 将“关于...”菜单项添加到系统菜单中。
|
||
// IDM_ABOUTBOX 必须在系统命令范围内。
|
||
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
|
||
ASSERT(IDM_ABOUTBOX < 0xF000);
|
||
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
||
if (pSysMenu != NULL)
|
||
{
|
||
BOOL bNameValid;
|
||
CString strAboutMenu;
|
||
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
|
||
ASSERT(bNameValid);
|
||
if (!strAboutMenu.IsEmpty())
|
||
{
|
||
pSysMenu->AppendMenu(MF_SEPARATOR);
|
||
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
|
||
}
|
||
}
|
||
|
||
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
|
||
// 执行此操作
|
||
SetIcon(m_hIcon, TRUE); // 设置大图标
|
||
SetIcon(m_hIcon, FALSE); // 设置小图标
|
||
|
||
// TODO: 在此添加额外的初始化代码
|
||
m_tab.InsertItem(0, _T("参数设置"));
|
||
m_tab.InsertItem(1, _T("显示图像"));
|
||
m_tab.InsertItem(2, _T("CIS设置"));
|
||
m_A4Dlg.Create(IDD_A4_DIALOG, &m_tab); // 创建第二个标签页
|
||
m_VisonDlg.Create(IDD_VISION_DIALOG, &m_tab); //创建第三个标签页
|
||
m_A3dlg.Create(IDD_A3_DIALOG, &m_tab);
|
||
m_A4Dlg.SetParent(this);
|
||
m_VisonDlg.SetParent(this);
|
||
m_A3dlg.SetParent(this);
|
||
auto callback = [this](bool stoped, int num) {
|
||
if (stoped)
|
||
{
|
||
KillTimer(N_TIMER_SEC);
|
||
KillTimer(N_TIMER_SHOW);
|
||
}
|
||
else
|
||
{
|
||
CString str;
|
||
str.Format(L"%d", num);
|
||
SetDlgItemText(IDC_STATIC_NUM, str);
|
||
}
|
||
};
|
||
m_VisonDlg.SetCallBack(callback);
|
||
|
||
m_tab.GetClientRect(&tabRect); // 获取标签控件客户区Rect
|
||
// 调整tabRect,使其覆盖范围适合放置标签页
|
||
tabRect.left += 0;
|
||
tabRect.right -= 0;
|
||
tabRect.top += 100;
|
||
tabRect.bottom -= 50;
|
||
|
||
// 根据调整好的tabRect放置m_A3Dlg子对话框,并设置为显示
|
||
m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
// 根据调整好的tabRect放置m_A4Dlg子对话框,并设置为隐藏
|
||
m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
|
||
// 根据调整好的tabRect放置m_VisonDlg子对话框,并设置为隐藏
|
||
m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
|
||
m_ComboxDpi.InsertString(0, _T("200"));
|
||
m_ComboxDpi.InsertString(1, _T("300"));
|
||
m_ComboxDpi.InsertString(2, _T("600"));
|
||
m_ComboxDpi.SetCurSel(0);
|
||
|
||
m_ComboxColor.InsertString(0, _T("gray"));
|
||
m_ComboxColor.InsertString(1, _T("color"));
|
||
m_ComboxColor.SetCurSel(1);
|
||
|
||
m_A4Scanner.SetCheck(0);
|
||
n_hour = 0;
|
||
n_minute = 0;
|
||
n_second = 0;
|
||
s_hour = "00";
|
||
s_minute = "00";
|
||
s_second = "00";
|
||
UpdateData(FALSE);
|
||
((CEdit*)(m_A3dlg.GetDlgItem(IDC_LSTFLATINFO)))->SetLimitText(0xffffffff);
|
||
bool ret = RefreshUSBList();
|
||
if (ret)
|
||
{
|
||
m_Usbs.SetCurSel(0);//默认选择第一个设备
|
||
OnCbnSelchangeCmbUsbs();
|
||
}
|
||
m_tab.SetCurSel(0);
|
||
RefreshTabChange();
|
||
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::EnableUIItem(bool enbale)
|
||
{
|
||
GetDlgItem(IDC_CMB_USBS)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_BTNSTART)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_BTNSTOP)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_CheckParamSet)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_CheckParamRead)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_BTN_FLAT)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_BTN_SELECTFILE)->EnableWindow(enbale);
|
||
GetDlgItem(IDC_BTN_UPDATE)->EnableWindow(enbale);
|
||
m_A4Dlg.EnableItem(enbale);
|
||
}
|
||
|
||
bool CHuaGoCorrectDlg::RefreshUSBList()
|
||
{
|
||
auto ret = UsbScan_List::find_all_usb();
|
||
if (m_Usbs.GetCount() > 0)
|
||
m_Usbs.ResetContent();
|
||
if (ret.size() <= 0)
|
||
{
|
||
EnableUIItem(false);
|
||
MessageBox(TEXT("未找到扫描仪"), TEXT("提示"), MB_OK | MB_ICONWARNING);
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
EnableUIItem(true);
|
||
auto info = ret.begin();
|
||
int i = 0;
|
||
while (info != ret.end())
|
||
{
|
||
CString strinfo;
|
||
strinfo.Format(L"vid0x%x pid0X%x", info->vid, info->pid);
|
||
m_Usbs.InsertString(i, strinfo);
|
||
info++;
|
||
i++;
|
||
}
|
||
m_Usbs.SetCurSel(0);
|
||
OnCbnSelchangeCmbUsbs();
|
||
return true;
|
||
}
|
||
}
|
||
void CHuaGoCorrectDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||
{
|
||
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
||
{
|
||
CAboutDlg dlgAbout;
|
||
dlgAbout.DoModal();
|
||
}
|
||
else
|
||
{
|
||
CDialogEx::OnSysCommand(nID, lParam);
|
||
}
|
||
}
|
||
|
||
// 如果向对话框添加最小化按钮,则需要下面的代码
|
||
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
|
||
// 这将由框架自动完成。
|
||
|
||
void CHuaGoCorrectDlg::OnPaint()
|
||
{
|
||
if (IsIconic())
|
||
{
|
||
CPaintDC dc(this); // 用于绘制的设备上下文
|
||
|
||
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
||
|
||
// 使图标在工作区矩形中居中
|
||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
||
CRect rect;
|
||
GetClientRect(&rect);
|
||
int x = (rect.Width() - cxIcon + 1) / 2;
|
||
int y = (rect.Height() - cyIcon + 1) / 2;
|
||
|
||
// 绘制图标
|
||
dc.DrawIcon(x, y, m_hIcon);
|
||
}
|
||
else
|
||
{
|
||
CDialogEx::OnPaint();
|
||
}
|
||
}
|
||
|
||
//当用户拖动最小化窗口时系统调用此函数取得光标
|
||
//显示。
|
||
HCURSOR CHuaGoCorrectDlg::OnQueryDragIcon()
|
||
{
|
||
return static_cast<HCURSOR>(m_hIcon);
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::OnTcnSelChangeTab(NMHDR* pNMHDR, LRESULT* pResult)
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
*pResult = 0;
|
||
RefreshTabChange();
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::RefreshTabChange()
|
||
{
|
||
CRect tabRect; // 标签控件客户区的Rect
|
||
|
||
// 获取标签控件客户区Rect,并对其调整,以适合放置标签页
|
||
m_tab.GetClientRect(&tabRect);
|
||
tabRect.left += 0;
|
||
tabRect.right += 10;
|
||
tabRect.top += 35;
|
||
tabRect.bottom += 10;
|
||
|
||
switch (m_tab.GetCurSel())
|
||
{
|
||
case 0:
|
||
m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
|
||
m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
break;
|
||
case 1:
|
||
m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
|
||
m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
break;
|
||
case 2:
|
||
m_A4Dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
m_VisonDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
|
||
m_A3dlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::Scan()
|
||
{
|
||
HGScanConfig config = { 0 };
|
||
if (m_drv->CPU == 3399)
|
||
{
|
||
config.g200params.dpi = m_iDpiIndex==0?1:(m_iDpiIndex==1?2:3);//only support 200DPI
|
||
config.g200params.paper = 16;
|
||
config.g200params.pc_correct = ((CButton*)GetDlgItem(IDC_CKBORGINIMG))->GetCheck();
|
||
config.g200params.color = m_iColorIndex == 1 ? 1 : 0;
|
||
config.g200params.double_feed_enbale = TRUE;
|
||
config.g200params.screw_detect_enable = FALSE;
|
||
config.g200params.iscorrect_mode = 1;//校正模式
|
||
}
|
||
else
|
||
{
|
||
config.g400params.dpi = m_iDpiIndex == 0 ? 1 : (m_iDpiIndex == 1 ? 2 : 3);//only support 200DPI ;// 1;//only support 200DPI
|
||
config.g400params.pageSize = 0;
|
||
config.g400params.isCorrect = !((CButton*)GetDlgItem(IDC_CKBORGINIMG))->GetCheck();
|
||
//config.g400params.lutmode = ((CButton*)GetDlgItem(IDC_CKBLUTMODE))->GetCheck();
|
||
config.g400params.isColor = m_iColorIndex == 1 ? 1 : 0;
|
||
config.g400params.doubleFeeded = TRUE;
|
||
config.g400params.enableStable = FALSE;
|
||
config.g400params.reversed1 = 0;//校正模式
|
||
}
|
||
|
||
m_drv->Config_Scanner(config);
|
||
this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||
|
||
m_drv->Scanner_StartScan(-1);
|
||
m_drv->run();
|
||
|
||
if (b_suspend)
|
||
KillTimer(N_TIMER_SEC);
|
||
|
||
b_suspend = FALSE;
|
||
n_hour = 0;
|
||
n_minute = 0;
|
||
n_second = 0;
|
||
SetTimer(N_TIMER_SEC, N_TIME_SEC, NULL);
|
||
SetTimer(N_TIMER_SHOW, N_TIME_SHOW, NULL);
|
||
}
|
||
|
||
|
||
void CHuaGoCorrectDlg::OnBnClickedCheckparamset()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
if (!m_drv->IsConnected())
|
||
{
|
||
MessageBox(TEXT("扫描仪未连接"));
|
||
return;
|
||
}
|
||
m_A4Dlg.SendCorrectParam();
|
||
}
|
||
|
||
|
||
void CHuaGoCorrectDlg::OnBnClickedCheckparamread()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
if (!m_drv->IsConnected())
|
||
{
|
||
MessageBox(TEXT("扫描仪未连接"));
|
||
return;
|
||
}
|
||
m_tab.SetCurSel(0);
|
||
auto read = m_drv->GetFlatData();
|
||
m_A4Dlg.updateA4Config(read);
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnFlat()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
m_iflatIndex = -2;
|
||
if (!m_drv->IsConnected())
|
||
{
|
||
MessageBox(TEXT("扫描仪未连接"));
|
||
return;
|
||
}
|
||
if (GetDlgItem(IDC_CKBCORRECTMODE)->IsWindowVisible())
|
||
{
|
||
m_tab.SetCurSel(2);
|
||
RefreshTabChange();
|
||
((CEdit*)(m_A3dlg.GetDlgItem(IDC_LSTFLATINFO)))->Clear();
|
||
auto flatcall = [&](string info) {
|
||
USES_CONVERSION;
|
||
std::string c_str = StringToUtf(info);
|
||
CString pWideChar = A2T(c_str.c_str());
|
||
//CString oldinfo;
|
||
//UpdateData(FALSE);
|
||
//((CEdit*)(m_A3dlg.GetDlgItem(IDC_LSTFLATINFO)))->GetWindowText(oldinfo);
|
||
//oldinfo += pWideChar;
|
||
//((CEdit*)(m_A3dlg.GetDlgItem(IDC_LSTFLATINFO)))->SetWindowText(oldinfo);
|
||
auto edit = ((CEdit*)(m_A3dlg.GetDlgItem(IDC_LSTFLATINFO)));
|
||
assert(edit && edit->GetSafeHwnd());
|
||
edit->SetSel(edit->GetWindowTextLengthW(), edit->GetWindowTextLengthW());
|
||
edit->ReplaceSel(pWideChar);
|
||
//edit->LineScroll(edit->GetLineCount());
|
||
};
|
||
m_drv->SetFlatCallback(flatcall);
|
||
m_drv->StartFlat(((CButton*)GetDlgItem(IDC_CKBCORRECTMODE))->GetCheck());
|
||
|
||
}
|
||
else
|
||
m_drv->StartFlat(true);//彩色
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::WriteLog(CString msg)
|
||
{
|
||
if (!msg.IsEmpty())
|
||
{
|
||
//FILE* pFile = fopen(".//log//CorrectLog.log", "a+");
|
||
//if (pFile != NULL)
|
||
//{
|
||
// char cTime[32];
|
||
// CTime currTime = CTime::GetCurrentTime();
|
||
// _snprintf(cTime, 30, "[%04d-%02d-%02d %02d:%02d:%02d]",
|
||
// currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(),
|
||
// currTime.GetHour(), currTime.GetMinute(), currTime.GetSecond());
|
||
// fwrite(cTime, 1, strlen(cTime), pFile);
|
||
// fwrite(msg, 1, strlen(msg.GetBuffer()), pFile);
|
||
// fwrite("\n", 1, 1, pFile);
|
||
// fclose(pFile);
|
||
//}
|
||
}
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::OnCancel()
|
||
{
|
||
// TODO: 在此添加专用代码和/或调用基类
|
||
if (IDOK != AfxMessageBox(L"确定要退出此程序吗?", MB_ICONQUESTION | MB_OKCANCEL))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_bExit = TRUE;
|
||
CDialogEx::OnCancel();
|
||
}
|
||
|
||
|
||
void CHuaGoCorrectDlg::InitButton()
|
||
{
|
||
((CButton*)GetDlgItem(IDC_CheckParamSet))->EnableWindow(FALSE);
|
||
((CButton*)GetDlgItem(IDC_CheckParamRead))->EnableWindow(FALSE);
|
||
((CButton*)GetDlgItem(IDC_BTN_FLAT))->EnableWindow(FALSE);
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::OnCbnSelChangeDpi()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
m_iDpiIndex = m_ComboxDpi.GetCurSel();
|
||
}
|
||
|
||
|
||
void CHuaGoCorrectDlg::OnCbnSelChangeColor()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
m_iColorIndex = m_ComboxColor.GetCurSel();
|
||
//m_drv->set_decompress_pix_type(0 == m_iColorIndex ? TWPT_GRAY : TWPT_RGB);
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::OnBnClickedStopScan()
|
||
{
|
||
// TODO: 在此添加控件通知处理程序代码
|
||
}
|
||
|
||
|
||
void CHuaGoCorrectDlg::OnTimer(UINT_PTR nIDEvent)
|
||
{
|
||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||
switch (nIDEvent)
|
||
{
|
||
case 1:
|
||
{
|
||
if (b_review == FALSE)
|
||
{
|
||
n_second++;
|
||
if (n_second == 60)
|
||
{
|
||
n_second = 0;
|
||
n_minute++;
|
||
}
|
||
if (n_minute == 60)
|
||
{
|
||
n_minute = 0;
|
||
n_hour++;
|
||
}
|
||
}
|
||
}
|
||
case 2:
|
||
{
|
||
if (b_review == FALSE)
|
||
{
|
||
int h1, h2, m1, m2, s1, s2;
|
||
h1 = n_hour / 10;
|
||
h2 = n_hour % 10;
|
||
m1 = n_minute / 10;
|
||
m2 = n_minute % 10;
|
||
s1 = n_second / 10;
|
||
s2 = n_second % 10;
|
||
s_hour.Format(L"%d%d", h1, h2);
|
||
s_minute.Format(L"%d%d", m1, m2);
|
||
s_second.Format(L"%d%d", s1, s2);
|
||
}
|
||
UpdateData(FALSE);
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
CDialogEx::OnTimer(nIDEvent);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择更新文件
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnSelectfile()
|
||
{
|
||
CProgressCtrl* prb = (CProgressCtrl*)GetDlgItem(IDC_PRB_UPDATE);
|
||
prb->SetRange(0, 100);
|
||
CFileDialog ofd(TRUE,
|
||
_T(".zip"),
|
||
NULL,
|
||
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||
_TEXT("Upda Files (*.zip)|*.zip||)"),
|
||
NULL);
|
||
if (IDOK == ofd.DoModal())
|
||
{
|
||
USES_CONVERSION;
|
||
|
||
updateFilePath = ofd.GetPathName();
|
||
SetDlgItemText(IDC_LB_FILEPATH, updateFilePath);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开始系统升级
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnUpdate()
|
||
{
|
||
if (m_updateThread.joinable())
|
||
{
|
||
m_updateThread.join();
|
||
}
|
||
|
||
m_updateThread = std::thread(&CHuaGoCorrectDlg::updatefunc, this);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重新扫描USB
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnRefresh()
|
||
{
|
||
RefreshUSBList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// USB列表选择变化
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnCbnSelchangeCmbUsbs()
|
||
{
|
||
int ret = m_Usbs.GetCurSel();
|
||
if (ret >= 0)
|
||
{
|
||
if (m_drv.get() && m_drv->IsConnected())
|
||
m_drv->close();
|
||
|
||
auto usbs = UsbScan_List::find_all_usb();
|
||
if (usbs.size() > 0)
|
||
{
|
||
int vid, pid;
|
||
int j = 0;
|
||
auto ids = id_config().GetConfig();
|
||
ID_Config tmp;
|
||
for (auto i = usbs.begin(); i != usbs.end(); i++, j++)
|
||
{
|
||
if (std::find_if(ids.begin(), ids.end(), [&i,&tmp](ID_Config id)->bool {
|
||
if (i->vid == id.vid && i->pid == id.pid)
|
||
{
|
||
tmp = id;
|
||
return true;
|
||
}
|
||
return false;
|
||
}) != ids.end()) {
|
||
if (j == ret)
|
||
{
|
||
if (tmp.cpu_type == 3399)
|
||
m_drv.reset(new gscan3399());
|
||
else
|
||
{
|
||
m_drv.reset(new GScn_Drv());
|
||
GetDlgItem(IDC_CKBUVMODEL)->EnableWindow(i->vid == 0x3072 && i->pid == 0x0300);
|
||
}
|
||
m_drv->CPU = tmp.cpu_type;
|
||
m_drv->VID = tmp.vid;
|
||
m_drv->PID = tmp.pid;
|
||
m_drv->Driver_type = tmp.driver_type;
|
||
m_drv->open(i->vid, i->pid, 0);
|
||
USES_CONVERSION;
|
||
std::string savepath(W2A(GetMainApp()->path.GetBuffer()));
|
||
m_drv->SetPath(savepath);
|
||
if (tmp.cpu_type == 3399)
|
||
{
|
||
GetDlgItem(IDC_CKBCORRECTMODE)->EnableWindow(TRUE);
|
||
m_A3dlg.GetDlgItem(IDC_STATICUVSP)->ShowWindow(SW_HIDE);
|
||
m_A3dlg.GetDlgItem(IDC_LBGUVSP)->ShowWindow(SW_HIDE);
|
||
m_A3dlg.GetDlgItem(IDC_BTNGETUVSP)->ShowWindow(SW_HIDE);
|
||
m_A3dlg.GetDlgItem(IDC_BTNSETUVSP)->ShowWindow(SW_HIDE);
|
||
}
|
||
else
|
||
{
|
||
GetDlgItem(IDC_CKBCORRECTMODE)->EnableWindow(FALSE);
|
||
((CButton*)GetDlgItem(IDC_CKBCORRECTMODE))->SetCheck(FALSE);
|
||
m_A3dlg.GetDlgItem(IDC_STATICUVSP)->ShowWindow(SW_SHOW);
|
||
m_A3dlg.GetDlgItem(IDC_LBGUVSP)->ShowWindow(SW_SHOW);
|
||
m_A3dlg.GetDlgItem(IDC_BTNGETUVSP)->ShowWindow(SW_SHOW);
|
||
m_A3dlg.GetDlgItem(IDC_BTNSETUVSP)->ShowWindow(SW_SHOW);
|
||
}
|
||
|
||
if (!m_drv->IsConnected())
|
||
{
|
||
MessageBox(TEXT("open current select usb scanner failed"), TEXT("Notify"), MB_OK | MB_ICONINFORMATION);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开始扫描
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnstart()
|
||
{
|
||
m_iPicIndex = 0;
|
||
|
||
if (!m_drv->IsConnected())
|
||
{
|
||
MessageBox(L"扫描仪未连接");
|
||
return;
|
||
}
|
||
m_iColorIndex = m_ComboxColor.GetCurSel();
|
||
GetDlgItem(IDC_STATIC_NUM)->SetWindowText(L"0");
|
||
m_drv->DevStateChange();
|
||
m_drv->reset();
|
||
Scan();
|
||
papercount = 0;
|
||
m_tab.SetCurSel(1);
|
||
RefreshTabChange();
|
||
m_VisonDlg.SetEnableShow(true);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 停止扫描
|
||
/// </summary>
|
||
void CHuaGoCorrectDlg::OnBnClickedBtnstop()
|
||
{
|
||
b_suspend = !b_suspend;
|
||
if (b_suspend)
|
||
{
|
||
KillTimer(N_TIMER_SEC);
|
||
KillTimer(N_TIMER_SHOW);
|
||
int h1, h2, m1, m2, s1, s2;
|
||
h1 = n_hour / 10;
|
||
h2 = n_hour % 10;
|
||
m1 = n_minute / 10;
|
||
m2 = n_minute % 10;
|
||
s1 = n_second / 10;
|
||
s2 = n_second % 10;
|
||
s_hour.Format(L"%d%d", h1, h2);
|
||
s_minute.Format(L"%d%d", m1, m2);
|
||
s_second.Format(L"%d%d", s1, s2);
|
||
UpdateData(FALSE);
|
||
}
|
||
m_drv->Stop_scan();
|
||
}
|
||
|
||
void CHuaGoCorrectDlg::updatefunc()
|
||
{
|
||
CProgressCtrl* prb = (CProgressCtrl*)GetDlgItem(IDC_PRB_UPDATE);
|
||
USES_CONVERSION;
|
||
std::string updatefile(W2A(updateFilePath));
|
||
int ret = m_drv->Updata(updatefile, [this, &prb](long pos, long len) {
|
||
prb->SetRange32(0, len);
|
||
prb->SetPos(pos);
|
||
});
|
||
if (ret == false)
|
||
{
|
||
MessageBox(TEXT("更新失败"), TEXT("提示"), MB_OK);
|
||
}
|
||
else
|
||
{
|
||
MessageBox(TEXT("更新完成"), TEXT("提示"), MB_OK | MB_ICONINFORMATION);
|
||
}
|
||
}
|