From 935374f2cbe9f525be1b44c4d609a61f9d02759d Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 3 Jun 2023 09:16:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=20optimize-402:=20change=20DoubleFeedDetect?= =?UTF-8?q?ion=20protocol=20for=20=E7=88=B1=E4=BA=91=E6=A0=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twain/twain/huagaods.cpp | 39 ++++++++++++++++++++++++++++++++++----- twain/twain/huagaods.hpp | 2 ++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index cb97420..96606eb 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -1005,6 +1005,20 @@ Result huagao_ds::identityOpenDs(const Identity& id) } log_all_triple_ = get_config_number(L"twain-app", L"log-all-triple") == 1; notify_close_ = get_config_number(L"twain-app", L"notify-close"); + double_check_mode_ = get_config_number(L"twain-app", L"double-check"); + if (double_check_mode_ == 0) + { + wchar_t pe[MAX_PATH] = { 0 }, * name = NULL; + GetModuleFileNameW(NULL, pe, _countof(pe) - 1); + name = wcsrchr(pe, L'\\'); + if (name++ == NULL) + name = pe; + if (wcsicmp(name, L"\u597D\u5206\u6570\u9605\u5377\u626B\u63CF\u7AEF.exe") == 0) // °®ÔÆУPE£ººÃ·ÖÊýÔľíɨÃè¶Ë.exe + double_check_mode_ = DOUBLE_CHECK_ULTRASONIC; + else + double_check_mode_ = DOUBLE_CHECK_TWAIN; + } + load_sane_util::to_log(1, L"Double check mode = %d\r\n", double_check_mode_); m_compression = Compression::None; init_support_caps(); @@ -2704,18 +2718,33 @@ void huagao_ds::init_support_caps(void) m_caps[CapType::DoubleFeedDetection] = [this](Msg msg, Capability& data)->Result { log_attr_access((int)CapType::DoubleFeedDetection, (int)msg); if (Msg::Set == msg) { - auto atuodsw = data.currentItem(); + auto val = data.currentItem(); int ret = SCANNER_ERR_OK; - bool enable = atuodsw == DoubleFeedDetection::Ultrasonic; + bool enable = val == DoubleFeedDetection::Ultrasonic; + if (double_check_mode_ == DOUBLE_CHECK_ULTRASONIC) + { + enable = (bool)val; + load_sane_util::to_log(1, L"DoubleFeedDetection parameter is for boolean of Ultrasonic. set to %s\r\n", enable ? L"TRUE" : L"FALSE"); + } SET_SANE_OPT_EX(ret, scanner_, is_ultrasonic_check, &enable); return ret == SCANNER_ERR_OK ? success() : seqError(); } DoubleFeedDetection init = DoubleFeedDetection::Ultrasonic; std::vector all; GET_SANE_OPT_EX(bool, scanner_, is_ultrasonic_check, NULL, &all); - BYTE ato = !all[sane_opts::RANGE_POS_CURRENT]; - init = all[sane_opts::RANGE_POS_DEFAULT] ? DoubleFeedDetection::Ultrasonic : DoubleFeedDetection::ByLength; - return CapSupGetAllReset(msg, data, ato, init); + if (double_check_mode_ == DOUBLE_CHECK_ULTRASONIC) + { + Bool ni = all[sane_opts::RANGE_POS_CURRENT], + ii = all[sane_opts::RANGE_POS_DEFAULT]; + data = Capability::createEnumeration(CapType::DoubleFeedDetection, { FALSE, TRUE }, ni, ii); + return success(); + } + else + { + BYTE ato = !all[sane_opts::RANGE_POS_CURRENT]; + init = all[sane_opts::RANGE_POS_DEFAULT] ? DoubleFeedDetection::Ultrasonic : DoubleFeedDetection::ByLength; + return CapSupGetAllReset(msg, data, ato, init); + } }; m_query[CapType::IAutomaticCropUsesFrame] = msgSupportGetAll; diff --git a/twain/twain/huagaods.hpp b/twain/twain/huagaods.hpp index c92a3e1..6b54bcc 100644 --- a/twain/twain/huagaods.hpp +++ b/twain/twain/huagaods.hpp @@ -61,6 +61,8 @@ class huagao_ds : public Twpp::SourceFromThis { volatile bool notfify_close_ = false; enum {NOTIFY_AUTO = 0, NOTIFY_ALWAYS, NOTIFY_NONE}; volatile unsigned notify_close_ = 0; // 0 - auto; 1 - notify always; 2 - no notify + enum {DOUBLE_CHECK_TWAIN = 1, DOUBLE_CHECK_ULTRASONIC, DOUBLE_CHECK_INFRARED}; // for BUG-402 + volatile unsigned double_check_mode_ = 0; // 1 - standard twain protocol; 2 - bool for ultrasonic; 3 - bool for infrared std::mutex notify_close_lock_; std::unique_ptr notify_close_thread_; bool take_and_reset_notify_close_flag(void);