From da0da5b40107ddf53b7bdc752c98991dedaaf6f4 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Sat, 28 Oct 2023 16:32:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E6=8F=8F=E7=BB=93=E6=9D=9F=E6=97=B6?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E4=B8=BA=E4=BF=9D=E7=95=99=E5=8F=8C=E5=BC=A0?= =?UTF-8?q?=EF=BC=8C=E5=88=99=E7=BB=A7=E7=BB=AD=E6=89=AB=E6=8F=8F=EF=BC=8C?= =?UTF-8?q?=E5=90=A6=E5=88=99=E5=81=9C=E6=AD=A2=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/scanner.cpp | 53 +++++++++++++++++++++++++++++++++++++----------- sane/scanner.h | 4 +++- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/sane/scanner.cpp b/sane/scanner.cpp index 08f383c..7b4ddda 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -553,6 +553,10 @@ scanner::~scanner() thread_starting_->join(); thread_starting_.reset(); + if (start_after_keep_.get() && start_after_keep_->joinable()) + start_after_keep_->join(); + start_after_keep_.reset(); + if (cfg_) { cfg_->remove_all_schemes(); // schemes would add_ref on cfg_, so we clear them first. NOTE: do not call save after this !!! @@ -1663,6 +1667,12 @@ int scanner::thread_start(void) return ret; } +int scanner::thread_start_after_keep() +{ + int ret = hg_sane_middleware::instance()->start(handle_, NULL); + return ret; +} + scanner::EXAPIPOS scanner::find_ex_api(int op_id) { return std::find(ex_opts_.begin(), ex_opts_.end(), op_id); @@ -3621,6 +3631,10 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len) if (double_handle_ == DOUBLE_FEED_DISCARD) return 0; } + else + { + double_handle_ = DOUBLE_FEED_NEED_UI; + } swprintf_s(name, _countof(name) - 1, L"img_%05u.bmp", ++img_ind_); img = new scanned_img(handle_, simg->header, simg->data, simg->bytes, simg->flag.dpi, (tmp_path_ + name).c_str(), xfer_, &img_fmt_); @@ -3674,19 +3688,34 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len) } else if (ev_code == SANE_EVENT_SCAN_FINISHED) { - err_ = *len; - scan_over_ = true; - scan_msg_ = data ? (char*)data : "OK"; - - if (done_.get() && done_->joinable()) - done_->join(); - done_.reset(new std::thread(&scanner::scan_done, this)); - // scan_done(); // invoking move to the last image fetched - + if (double_handle_ == DOUBLE_FEED_KEEP) { - wchar_t msg[128] = { 0 }; - swprintf_s(msg, _countof(msg) - 1, L"Scan finished with error: %u\r\n", *len); - log_info(msg, 1); + if (start_after_keep_.get() && start_after_keep_->joinable()) + start_after_keep_->join(); + start_after_keep_.reset(new std::thread(&scanner::thread_start_after_keep, this)); + } + else + { + err_ = *len; + scan_over_ = true; + scan_msg_ = data ? (char*)data : "OK"; + + if (double_handle_ == DOUBLE_FEED_DISCARD) + { + scan_msg_ = "OK"; + err_ = 0; + } + + if (done_.get() && done_->joinable()) + done_->join(); + done_.reset(new std::thread(&scanner::scan_done, this)); + // scan_done(); // invoking move to the last image fetched + + { + wchar_t msg[128] = { 0 }; + swprintf_s(msg, _countof(msg) - 1, L"Scan finished with error: %u\r\n", *len); + log_info(msg, 1); + } } } //else if (ev_code == SANE_EVENT_ERROR) // 閻忕偛绻楅弬鈧柨娑樿嫰濠€顏堝磻濠婂嫷鍓鹃柟娈垮亝瀵潡寮捄铏规綌缂佲偓鏉為绻嗛柟?- 2023-05-30 diff --git a/sane/scanner.h b/sane/scanner.h index 62f6981..a66be91 100644 --- a/sane/scanner.h +++ b/sane/scanner.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "scanned_img.h" #include @@ -116,7 +116,9 @@ class scanner : public ISaneInvoker, virtual public refer int set_is_multiout(bool enable); int thread_start(void); + int thread_start_after_keep(); std::unique_ptr thread_starting_; + std::unique_ptr start_after_keep_; typedef struct _ex_api {