From 15361bf5450f810f81ffb64093279bf2e2364c88 Mon Sep 17 00:00:00 2001 From: masayume <1936714878@qq.com> Date: Sun, 24 Apr 2022 16:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=BA=E6=A0=B9=E6=8D=AEjs?= =?UTF-8?q?on=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96id=E6=89=93=E5=BC=80?= =?UTF-8?q?=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HuaGoCorrect/HuaGoCorrectDlg.cpp | 84 ++++++++++++++------------- HuaGoCorrect/IScanner.h | 1 + HuaGoCorrect/id_config.cpp | 97 ++++++++++++++++++++++++++++++++ HuaGoCorrect/id_config.h | 28 +++++++++ 4 files changed, 172 insertions(+), 38 deletions(-) create mode 100644 HuaGoCorrect/id_config.cpp create mode 100644 HuaGoCorrect/id_config.h diff --git a/HuaGoCorrect/HuaGoCorrectDlg.cpp b/HuaGoCorrect/HuaGoCorrectDlg.cpp index 15da577..0174f55 100644 --- a/HuaGoCorrect/HuaGoCorrectDlg.cpp +++ b/HuaGoCorrect/HuaGoCorrectDlg.cpp @@ -13,6 +13,7 @@ #include #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); + } } - } } } diff --git a/HuaGoCorrect/IScanner.h b/HuaGoCorrect/IScanner.h index 3eb939a..562f911 100644 --- a/HuaGoCorrect/IScanner.h +++ b/HuaGoCorrect/IScanner.h @@ -72,4 +72,5 @@ public: std::string csPath; unsigned short VID; unsigned short PID; + unsigned short CPU; }; \ No newline at end of file diff --git a/HuaGoCorrect/id_config.cpp b/HuaGoCorrect/id_config.cpp new file mode 100644 index 0000000..721d4d2 --- /dev/null +++ b/HuaGoCorrect/id_config.cpp @@ -0,0 +1,97 @@ +#include "stdafx.h" +#include "id_config.h" +#include +#include +#include +#include +#include +id_config::id_config() +{ + jsoninit(); +} + +std::vector id_config::GetConfig() +{ + std::vector 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 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; +} diff --git a/HuaGoCorrect/id_config.h b/HuaGoCorrect/id_config.h new file mode 100644 index 0000000..1d6a03f --- /dev/null +++ b/HuaGoCorrect/id_config.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include "json.hpp" +#include + +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 GetConfig(); + void SaveConfig(std::vector configs); + void SaveConfig(json j); +private: + json GetDefaultJson(); + void jsoninit(); + json to_json(ID_Config param); + ID_Config to_param(json j); +}; +