From eb87926c8a3837bf42724dab07b98814128ae2ca Mon Sep 17 00:00:00 2001 From: masayume <1936714878@qq.com> Date: Tue, 5 Jan 2021 19:27:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=AB=E6=8F=8F=E6=97=A0?= =?UTF-8?q?=E7=BA=B8=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/Device/GScanO200.cpp | 1 + huagao/huagaods.cpp | 42 ++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/huagao/Device/GScanO200.cpp b/huagao/Device/GScanO200.cpp index b15a6817..2d89e9bf 100644 --- a/huagao/Device/GScanO200.cpp +++ b/huagao/Device/GScanO200.cpp @@ -516,6 +516,7 @@ void GScanO200::clear_hwerror() } + void GScanO200::usbhotplug_callback(bool isconnect, void* userdata) { GScanO200* This = (GScanO200*)userdata; diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index 39190ab3..90ff22eb 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -452,7 +452,6 @@ Result CapSupGetAll(Msg msg, Capability& data, std::initializer_list values, return { ReturnCode::Failure, ConditionCode::CapBadOperation }; } } - template Result CapSupGetAll(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) { switch (msg) { @@ -641,8 +640,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) { BITMAPINFOHEADER& bmInfo = *((BITMAPINFOHEADER*)header()); bmInfo.biHeight = 2000; bmInfo.biWidth = 2000; - bmInfo.biBitCount = m_scanparam->pixtype == 2 ? 24 : (m_scanparam->pixtype == 1 ? 8 : 0); - m_iBitdepth = m_scanparam->pixtype == 2 ? 24 : (m_scanparam->pixtype == 1 ? 8 : 0); + bmInfo.biBitCount = m_scanparam->pixtype == 2 ? 24 : (m_scanparam->pixtype == 1 ? 8 : 1); + m_iBitdepth = m_scanparam->pixtype == 2 ? 24 : (m_scanparam->pixtype == 1 ? 8 : 1); #ifdef LANXUM scanner->open(0x31c9, 0x8200); #else @@ -785,7 +784,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) { } return badValue(); } - return CapSupGetAllReset(msg, data, m_scanparam->pixtype, PixelType::Rgb); + return CapSupGetAllReset(msg, data, { PixelType::BlackWhite,PixelType::Gray,PixelType::Rgb }, m_scanparam->pixtype, PixelType::Rgb, + m_scanparam->pixtype == (int)PixelType::Rgb ? 2 : (m_scanparam->pixtype == (int)PixelType::Gray ? 1 : 0), 2); }; m_query[CapType::IAutomaticColorEnabled] = msgSupportGetAllSetReset; @@ -1598,7 +1598,7 @@ Result HuagaoDs::identityCloseDs(const Identity&) { // no need to explicitly release any resources if using RAII // TWPP will free the whole source on its own after this method - if (guiIndicator) + if (guiIndicator->GetSafeHwnd()) guiIndicator->DestroyWindow(); if (guiTwain.get()) @@ -1634,7 +1634,7 @@ Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) { if (ret != 0) { scanner->Set_ErrorCode(0); - if (guiIndicator) + if (guiIndicator->GetSafeHwnd()) guiIndicator->ShowWindow(SW_HIDE); //if (guiIndicator.get()) // guiIndicator.reset(); @@ -1668,7 +1668,7 @@ Result HuagaoDs::pendingXfersReset(const Identity&, PendingXfers& data) { scanner->ResetScanner(); } //guiIndicator.reset(); - if (guiIndicator) + if (guiIndicator->GetSafeHwnd()) guiIndicator->DestroyWindow(); return success(); } @@ -1719,23 +1719,28 @@ Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) { //{ // MessageBox(NULL, TEXT("MemoryFile"), _T("bb"), MB_OK); //} + if (!ui.showUi()) { // this is an exception when we want to set state explicitly, notifyXferReady can be called only in enabled state // with hidden UI, the usual workflow DsState::Enabled -> notifyXferReady() -> DsState::XferReady is a single step + while (!scanner->Get_Scanner_PaperOn()) + { + if (MessageBox(NULL, L"检测到无纸,请添加纸张", L"提示", MB_YESNO) == IDNO) + return seqError(); + } setState(DsState::Enabled); auto ret = startScan(); - if (ret.status().condition() == Twpp::CC::NoMedia) - return ret; + //if (ret.status().condition() == Twpp::CC::NoMedia) + // return ret; if (ret == success()) { m_pendingXfers = 1; - auto notified = notifyXferReady(); - return success(); } else { m_pendingXfers = 0; - setState(DsState::Open); - return ret; + //setState(DsState::Open); } + auto notified = notifyXferReady(); + return success(); } return showTwainUI(ui); @@ -1748,6 +1753,8 @@ Result HuagaoDs::userInterfaceEnableUiOnly(const Identity&, UserInterface& ui) { Result HuagaoDs::imageInfoGet(const Identity&, ImageInfo& data) { // our image does not change + if (m_pendingXfers == 0) + return success(); auto dib = header(); data.setBitsPerPixel(static_cast(dib->biBitCount)); data.setHeight(dib->biHeight); @@ -2038,6 +2045,13 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly) //!< show ui to scan button push auto scanFunction = [this](const GScanCap& caps) { + while (!scanner->Get_Scanner_PaperOn()) + { + if (MessageBox(guiTwain.get()->GetSafeHwnd(), L"检测到无纸,请添加纸张", L"提示", MB_YESNO) == IDNO){ + m_pendingXfers = 0; + return; + } + } m_pendingXfers = 1; m_scanparam.reset(new GScanCap(caps)); saveGscanCapSetting(); @@ -2229,7 +2243,7 @@ Twpp::Result HuagaoDs::startScan() int retCode = scanner->aquire_bmpdata(*bmpData.get()); if (retCode != 0) { scanner->Set_ErrorCode(0); - if (guiIndicator) + if (guiIndicator->GetSafeHwnd()) guiIndicator->DestroyWindow(); //if(guiIndicator.get())