调整为根据json文件读取id打开设备
This commit is contained in:
parent
5bd17e89b2
commit
15361bf545
|
@ -13,6 +13,7 @@
|
|||
#include <fstream>
|
||||
#include "gscan3399.h"
|
||||
#include "gscn_drv.h"
|
||||
#include "id_config.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -340,10 +341,7 @@ void CHuaGoCorrectDlg::RefreshTabChange()
|
|||
void CHuaGoCorrectDlg::Scan()
|
||||
{
|
||||
HGScanConfig config = { 0 };
|
||||
if (m_drv->PID == 0x0139 ||
|
||||
m_drv->PID == 0x0239 ||
|
||||
m_drv->PID == 0x8739 ||
|
||||
m_drv->PID == 0x8629)
|
||||
if (m_drv->CPU == 3399)
|
||||
{
|
||||
config.g200params.dpi = m_iDpiIndex==0?1:(m_iDpiIndex==1?2:3);//only support 200DPI
|
||||
config.g200params.paper = 16;
|
||||
|
@ -607,47 +605,57 @@ void CHuaGoCorrectDlg::OnCbnSelchangeCmbUsbs()
|
|||
{
|
||||
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 (j == ret)
|
||||
{
|
||||
if ((i->vid == 0x3072 && i->pid == 0x0139) ||
|
||||
(i->vid == 0x3072 && i->pid == 0x0239) ||
|
||||
(i->vid == 0x31c9 && i->pid == 0x8629) ||
|
||||
(i->vid == 0x31c9 && i->pid == 0x8739))
|
||||
m_drv.reset(new gscan3399());
|
||||
else
|
||||
if (std::find_if(ids.begin(), ids.end(), [&i,&tmp](ID_Config id)->bool {
|
||||
if (i->vid == id.vid && i->pid == id.pid)
|
||||
{
|
||||
m_drv.reset(new GScn_Drv());
|
||||
GetDlgItem(IDC_CKBUVMODEL)->EnableWindow(i->vid == 0x3072 && i->pid == 0x0300);
|
||||
tmp = id;
|
||||
return true;
|
||||
}
|
||||
m_drv->open(i->vid, i->pid, 0);
|
||||
USES_CONVERSION;
|
||||
std::string savepath(W2A(GetMainApp()->path.GetBuffer()));
|
||||
m_drv->SetPath(savepath);
|
||||
if (i->pid & 0x39)
|
||||
return false;
|
||||
}) != ids.end()) {
|
||||
if (j == ret)
|
||||
{
|
||||
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 (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->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);
|
||||
if (!m_drv->IsConnected())
|
||||
{
|
||||
MessageBox(TEXT("open current select usb scanner failed"), TEXT("Notify"), MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,4 +72,5 @@ public:
|
|||
std::string csPath;
|
||||
unsigned short VID;
|
||||
unsigned short PID;
|
||||
unsigned short CPU;
|
||||
};
|
|
@ -0,0 +1,97 @@
|
|||
#include "stdafx.h"
|
||||
#include "id_config.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <corecrt_io.h>
|
||||
id_config::id_config()
|
||||
{
|
||||
jsoninit();
|
||||
}
|
||||
|
||||
std::vector<ID_Config> id_config::GetConfig()
|
||||
{
|
||||
std::vector<ID_Config> configs;
|
||||
try
|
||||
{
|
||||
if (access(ID_JSON_PATH.c_str(), 0) == 0) {
|
||||
std::ifstream i(ID_JSON_PATH);
|
||||
json j;
|
||||
i >> j;
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it)
|
||||
{
|
||||
auto tmv = it.value();
|
||||
configs.push_back(to_param(tmv));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw "file error";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
configs.clear();
|
||||
json j = GetDefaultJson();
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it)
|
||||
{
|
||||
auto tmv = it.value();
|
||||
configs.push_back(to_param(tmv));
|
||||
}
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
void id_config::SaveConfig(std::vector<ID_Config> configs)
|
||||
{
|
||||
json j = json::array();
|
||||
for (int i = 0; i < configs.size(); i++)
|
||||
{
|
||||
j.push_back(to_json({configs[i].vid,configs[i].pid,configs[i].cpu_type}));
|
||||
}
|
||||
std::ofstream ofs(ID_JSON_PATH);
|
||||
ofs << std::setw(4) << j << std::endl;
|
||||
}
|
||||
|
||||
void id_config::SaveConfig(json j)
|
||||
{
|
||||
std::ofstream ofs(ID_JSON_PATH);
|
||||
ofs << std::setw(4) << j << std::endl;
|
||||
}
|
||||
|
||||
json id_config::GetDefaultJson()
|
||||
{
|
||||
json j = json::array();
|
||||
j.push_back(to_json({ 0x3072, 0x239,3399 }));
|
||||
j.push_back(to_json({ 0x3072, 0x139,3399 }));
|
||||
j.push_back(to_json({ 0x3072, 0x300,3288 }));
|
||||
j.push_back(to_json({ 0x3072, 0x400,3288 }));
|
||||
j.push_back(to_json({ 0x31c9, 0x8629,3399 }));
|
||||
j.push_back(to_json({ 0x31c9, 0x8739,3399 }));
|
||||
return j;
|
||||
}
|
||||
|
||||
void id_config::jsoninit()
|
||||
{
|
||||
if (access(ID_JSON_PATH.c_str(),0) != 0)
|
||||
{
|
||||
std::ofstream ofs(ID_JSON_PATH);
|
||||
ofs << std::setw(4) << GetDefaultJson() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
json id_config::to_json(ID_Config param)
|
||||
{
|
||||
return json{
|
||||
{"vid",param.vid},
|
||||
{"pid",param.pid},
|
||||
{"cpu",param.cpu_type}};
|
||||
}
|
||||
|
||||
ID_Config id_config::to_param(json j)
|
||||
{
|
||||
ID_Config tmp;
|
||||
j.at("vid").get_to(tmp.vid);
|
||||
j.at("pid").get_to(tmp.pid);
|
||||
j.at("cpu").get_to(tmp.cpu_type);
|
||||
return tmp;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include "json.hpp"
|
||||
#include <vector>
|
||||
|
||||
const std::string ID_JSON_PATH = "./idconfig.json";
|
||||
using json = nlohmann::json;
|
||||
struct ID_Config
|
||||
{
|
||||
std::uint16_t vid;
|
||||
std::uint16_t pid;
|
||||
std::uint16_t cpu_type;
|
||||
};
|
||||
|
||||
class id_config
|
||||
{
|
||||
public:
|
||||
id_config();
|
||||
std::vector<ID_Config> GetConfig();
|
||||
void SaveConfig(std::vector<ID_Config> configs);
|
||||
void SaveConfig(json j);
|
||||
private:
|
||||
json GetDefaultJson();
|
||||
void jsoninit();
|
||||
json to_json(ID_Config param);
|
||||
ID_Config to_param(json j);
|
||||
};
|
||||
|
Loading…
Reference in New Issue