From 9eceba0f96ef8b15735c310c11dd0741d50be1a9 Mon Sep 17 00:00:00 2001 From: masayume <1936714878@qq.com> Date: Fri, 25 Dec 2020 18:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4twain=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/CBasicPage.cpp | 2 +- huagao/Device/PublicFunc.h | 2 +- huagao/huagaods.cpp | 1364 ++++++++---------------------------- huagao/huagaods.hpp | 1 + huagao/stdafx.h | Bin 10770 -> 10774 bytes 5 files changed, 295 insertions(+), 1074 deletions(-) diff --git a/huagao/CBasicPage.cpp b/huagao/CBasicPage.cpp index 73932e2d..493c3bbb 100644 --- a/huagao/CBasicPage.cpp +++ b/huagao/CBasicPage.cpp @@ -87,7 +87,7 @@ static std::vector reslutions{ _T("240"), _T("300"), #ifndef LANXUM - _T("600") + //_T("600") #endif // LANXUM }; diff --git a/huagao/Device/PublicFunc.h b/huagao/Device/PublicFunc.h index 3c453829..0148b612 100644 --- a/huagao/Device/PublicFunc.h +++ b/huagao/Device/PublicFunc.h @@ -187,7 +187,7 @@ struct GScanCap byte en_sizecheck; /**< 尺寸检测*/ float imageRotateDegree; byte is_duplex; /**< True to use duplex false for simplex, ignored if flatbed*/ - byte en_fold; + byte en_fold; /**<对折*/ int pixtype; /**< type of pixels to transfer image as */ int automaticcolor; /**<顔色自動識別*/ int automaticcolortype; /**<顔色自動識別后非彩色上傳類型*/ diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index c9c3576a..d975c27f 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -438,6 +438,114 @@ Result HuagaoDs::capabilityQuerySupport(const Identity&, Capability& data) { return success(); } +template +Result CapSupGetAll(Msg msg, Capability& data, std::initializer_list values, T& currvalue, T defaultvalue, UInt32 currindex, UInt32 defaultindex) { + switch (msg) { + case Msg::Get: + data = Capability::createEnumeration((T2)values, currindex, defaultindex); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::GetCurrent: + case Msg::GetDefault: + data = Capability::createOneValue(values[defaultindex]); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} + +template +Result CapSupGetAll(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) { + switch (msg) { + case Msg::Get: + case Msg::GetCurrent: + case Msg::GetDefault: + data = Capability::createOneValue((T2)defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} +template +Result CapSupGetAllEx(Msg msg, Capability& data, T& currvalue, T defaultvalue) { + switch (msg) { + case Msg::Get: + case Msg::GetCurrent: + case Msg::GetDefault: + data = Capability::createOneValue(cap, defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} +template +Result CapSupGetAllReset(Msg msg, Capability& data, std::initializer_list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) { + switch (msg) { + case Msg::Get: + data = Capability::createEnumeration(values, currindex, defaultindex); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::GetCurrent: + data = Capability::createOneValue((T2)currvalue); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::Reset: + case Msg::GetDefault: + currvalue = (T1)defaultvalue; + data = Capability::createOneValue(defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} +template +Result CapSupGetAllReset(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) { + switch (msg) { + case Msg::Get: + case Msg::GetCurrent: + data = Capability::createOneValue((T2)currvalue); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::Reset: + case Msg::GetDefault: + currvalue = (T1)defaultvalue; + data = Capability::createOneValue(defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} +template +Result CapSupGetAllResetEx(Msg msg, Capability& data, std::initializer_list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) { + switch (msg) { + case Msg::Get: + data = Capability::createEnumeration(cap, values, currindex, defaultindex); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::GetCurrent: + data = Capability::createOneValue(cap,(T2)currvalue); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::Reset: + case Msg::GetDefault: + currvalue = (T1)defaultvalue; + data = Capability::createOneValue(cap,defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} +template +Result CapSupGetAllResetEx(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) { + switch (msg) { + case Msg::Get: + case Msg::GetCurrent: + data = Capability::createOneValue(cap,(T2)currvalue); + return { ReturnCode::Success, ConditionCode::Success }; + case Msg::Reset: + case Msg::GetDefault: + currvalue = (T1)defaultvalue; + data = Capability::createOneValue(cap,defaultvalue); + return { ReturnCode::Success, ConditionCode::Success }; + default: + return { ReturnCode::Failure, ConditionCode::CapBadOperation }; + } +} + Result HuagaoDs::capabilityReset(const Identity& origin, Capability& data) { return capCommon(origin, Msg::Reset, data); } @@ -563,10 +671,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) { // caps -> has handler for each specific cap m_query[CapType::SupportedCaps] = msgSupportGetAll; m_caps[CapType::SupportedCaps] = [this](Msg msg, Capability& data) { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - case Msg::GetDefault: { + if ((msg == Msg::Get) || (Msg::GetCurrent == msg) || (Msg::GetDefault == msg)){ data = Capability::createArray(m_caps.size()); auto arr = data.array(); UInt32 i = 0; @@ -574,13 +679,10 @@ Result HuagaoDs::identityOpenDs(const Identity&) { arr[i] = kv.first; i++; } - return success(); } - - default: + else return capBadOperation(); - } }; m_query[CapType::UiControllable] = msgSupportGetAll; @@ -599,7 +701,6 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_scanparam->scannum = item; return success(); } - Int16 tmp_count = m_scanparam->scannum; auto ret = oneValGetSet(msg, data, tmp_count, -1); if (!Twpp::success(ret) && m_scanparam->scannum == 0) { @@ -613,71 +714,30 @@ Result HuagaoDs::identityOpenDs(const Identity&) { //m_caps[CapType::ICompression] = std::bind(enmGetSetConst, _1, _2, Compression::None); m_caps[CapType::ICompression] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { Compression::None, Compression::Group4 }, m_compression == Compression::None ? 0 : 1, 0); - return success(); - // fallthrough - case Msg::GetCurrent: - data = Capability::createOneValue(m_compression); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_compression = Compression::None; - data = Capability::createOneValue(Compression::None); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (Compression::None == mech || mech == Compression::Group4) { m_compression = mech; return success(); } - else { + else return badValue(); - } - } - - default: - return capBadOperation(); } + return CapSupGetAllReset(msg, data, { Compression::None, Compression::Group4 }, m_compression, Compression::None, m_compression == Compression::None ? 0 : 1, 0); }; m_query[CapType::IBitDepth] = msgSupportGetAllSetReset; m_caps[CapType::IBitDepth] = [this](Msg msg, Capability& data) -> Result { - switch (msg) - { - case Msg::Get: - data = Capability::createOneValue(UInt16(m_iBitdepth)); - return success(); - - case Msg::Reset: - m_iBitdepth = 24; - data = Capability::createOneValue(UInt16(m_iBitdepth)); - return success(); - break; - case Msg::GetCurrent: - data = Capability::createOneValue(UInt16(m_iBitdepth)); - return success(); - - case Msg::GetDefault: - data = Capability::createOneValue(24); - return success(); - - case Msg::Set: { + if( Msg::Set==msg) { auto mech = data.currentItem(); - if (mech == 1 || mech == 8 || mech == 24) - { + if (mech == 1 || mech == 8 || mech == 24){ m_iBitdepth = (UINT16)mech; m_scanparam->pixtype = m_iBitdepth == 1 ? (int)PixelType::BlackWhite : (m_iBitdepth == 8 ? (int)PixelType::Gray : (int)PixelType::Rgb); return success(); } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_iBitdepth, 24); }; m_query[CapType::IBitOrder] = msgSupportGetAllSetReset; @@ -697,97 +757,53 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::IPixelType] = msgSupportGetAllSetReset; m_caps[CapType::IPixelType] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { PixelType::BlackWhite, PixelType::Gray, PixelType::Rgb }, (int)(m_scanparam->pixtype), (int)PixelType::Gray); - return success(); - - case Msg::GetCurrent: - data = Capability::createOneValue((PixelType)(m_scanparam->pixtype)); - return success(); - - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->pixtype = (byte)PixelType::Gray; - data = Capability::createOneValue(PixelType::Gray); - return success(); - - case Msg::Set: { - auto mech = data.currentItem(); - if (mech == PixelType::Rgb || mech == PixelType::Gray || mech == PixelType::BlackWhite) + if( Msg::Set==msg) { + auto mech = data.currentItem(); + if (mech == PixelType::Rgb || mech == PixelType::Gray || mech == PixelType::BlackWhite) + { + m_scanparam->pixtype = (int)mech; + if (m_scanparam->pixtype == (int)PixelType::Rgb) { - m_scanparam->pixtype = (int)mech; - if (m_scanparam->pixtype == (int)PixelType::Rgb) - { - m_scanparam->filter = (byte)Filter::None; - m_scanparam->enhance_color = (byte)Enchace_Color::Enhance_None; - m_scanparam->automaticcolor = FALSE; - } - else - { - m_scanparam->multi_output_red = 0;//非彩色模式下多流输出不可用 - //if (m_scanparam->pixtype == (int)PixelType::BlackWhite) - // m_scanparam->sharpen = SharpenBlur::Sharpen_None; - } - m_iBitdepth = mech == PixelType::Rgb ? 24 : (mech == PixelType::Gray ? 8 : 1); - return success(); + m_scanparam->filter = (byte)Filter::None; + m_scanparam->enhance_color = (byte)Enchace_Color::Enhance_None; + m_scanparam->automaticcolor = FALSE; } - return badValue(); + else + { + m_scanparam->multi_output_red = 0;//非彩色模式下多流输出不可用 + //if (m_scanparam->pixtype == (int)PixelType::BlackWhite) + // m_scanparam->sharpen = SharpenBlur::Sharpen_None; + } + m_iBitdepth = mech == PixelType::Rgb ? 24 : (mech == PixelType::Gray ? 8 : 1); + return success(); } - - default: - return capBadOperation(); + return badValue(); } + return CapSupGetAllReset(msg, data, m_scanparam->pixtype, PixelType::Rgb); }; m_query[CapType::IAutomaticColorEnabled] = msgSupportGetAllSetReset; m_caps[CapType::IAutomaticColorEnabled] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration(CapType::IAutomaticColorEnabled, { Bool(),Bool(true) }, Bool(m_scanparam->automaticcolor), FALSE); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(CapType::IAutomaticColorEnabled, (Bool)m_scanparam->automaticcolor); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->automaticcolor = FALSE; - data = Capability::createOneValue(CapType::IAutomaticColorEnabled, false); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (mech) { m_scanparam->automaticcolor = TRUE; + m_scanparam->filter = (byte)Filter::None; + m_scanparam->enhance_color = (byte)Enchace_Color::Enhance_None; m_scanparam->pixtype = (int)PixelType::Rgb; } else m_scanparam->automaticcolor = FALSE; + m_iBitdepth = m_scanparam->pixtype == int(PixelType::Rgb) ? 24 : (m_scanparam->pixtype == int(PixelType::Gray) ? 8 : 1); return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { FALSE,TRUE }, m_scanparam->automaticcolor, false, m_scanparam->automaticcolor ? 1 : 0, 0); }; m_query[CapType::IAutomaticColorNonColorPixelType] = msgSupportGetAllSetReset; m_caps[CapType::IAutomaticColorNonColorPixelType] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration(CapType::IAutomaticColorNonColorPixelType, { UInt16(TWPT_BW),UInt16(TWPT_GRAY) }, UInt16(m_scanparam->automaticcolortype), TWPT_GRAY); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(CapType::IAutomaticColorNonColorPixelType, (UInt16)m_scanparam->automaticcolortype); - return success(); - - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->automaticcolortype = TWPT_GRAY; - data = Capability::createOneValue(CapType::IAutomaticColorNonColorPixelType, TWPT_GRAY); - return success(); - - case Msg::Set: { + if (msg == Msg::Set) { auto mech = data.currentItem(); if (m_scanparam->automaticcolor == TRUE) { @@ -796,40 +812,22 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_scanparam->automaticcolortype = (UInt16)mech; return success(); } - else - return badValue(); } return seqError(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { PixelType::BlackWhite, PixelType::Gray }, m_scanparam->automaticcolortype, PixelType::Gray, m_scanparam->automaticcolortype, 1); }; //add------------------jpeg质量等级--------------------- m_query[CapType::IJpegQuality] = msgSupportGetAllSetReset; m_caps[CapType::IJpegQuality] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue(CapType::IJpegQuality, (UInt16)m_jpegQuality); - return success(); - - case Msg::Reset: - case Msg::GetDefault: - m_jpegQuality = 80; - data = Capability::createOneValue(CapType::IJpegQuality, 80); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if ((int)mech < 0 || (int)mech > 100) return badValue(); m_jpegQuality = (int)mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_jpegQuality, 80); }; m_query[CapType::IUnits] = msgSupportGetAllSetReset; @@ -837,23 +835,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::IXferMech] = msgSupportGetAllSetReset; m_caps[CapType::IXferMech] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { XferMech::Native, XferMech::Memory, XferMech::File }, m_capXferMech == XferMech::Native ? 0 : (m_capXferMech == XferMech::Memory ? 1 : 2), 0); - return success(); - // fallthrough - case Msg::GetCurrent: - data = Capability::createOneValue(m_capXferMech); - return success(); - - case Msg::GetDefault: - case Msg::Reset: - m_capXferMech = XferMech::Native; - data = Capability::createOneValue(XferMech::Native); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (mech == XferMech::Native || mech == XferMech::Memory || mech == XferMech::File) { m_capXferMech = mech; @@ -863,57 +845,22 @@ Result HuagaoDs::identityOpenDs(const Identity&) { return badValue(); } } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { XferMech::Native, XferMech::File, XferMech::Memory }, m_capXferMech, XferMech::Native, (int)m_capXferMech, 0); }; m_query[CapType::IXResolution] = msgSupportGetAllSetReset; m_caps[CapType::IXResolution] = [this](Msg msg, Capability& data) { - switch (msg) { - case Msg::Get: { - int index = -1; - std::list::iterator it = resList.begin(); - int i = 0; - for (it, i; it != resList.end(); ++it, i++) { - if (*it == m_scanparam->resolution_dst) { - index = i; - break; - } - } - data = Capability::createEnumeration(data.type(), { Fix32(100.0),Fix32(150.0),Fix32(200.0),Fix32(240.0),Fix32(300.0) }, index == -1 ? 2 : index, 2); - return success(); - } - case Msg::GetCurrent: { - data = Capability::createOneValue(data.type(), Fix32(m_scanparam->resolution_dst)); - return success(); - } - case Msg::GetDefault: - case Msg::Reset: { - m_scanparam->resolution_dst = 200.0f; - data = Capability::createOneValue(data.type(), Fix32(200.0)); - return success(); - } - case Msg::Set: { + if (Msg::Set == msg) { auto res = data.currentItem(); - std::list::iterator resIter = resList.begin(); - bool contains = false; - for (resIter; resIter != resList.end(); resIter++) { - if (*resIter == res) { - contains = true; - break; - } - } - if (contains) { + if(std::distance(resList.begin(), std::find(resList.begin(), resList.end(), res))==resList.size()) + return badValue(); + else{ m_scanparam->resolution_dst = (float)res; return success(); } - return badValue(); - } - default: - return capBadOperation(); } + return CapSupGetAllReset(msg, data, { Fix32(100.0),Fix32(150.0),Fix32(200.0),Fix32(240.0),Fix32(300.0),Fix32(600.0) }, m_scanparam->resolution_dst,200.0, + std::distance(resList.begin(), std::find(resList.begin(), resList.end(), m_scanparam->resolution_dst)) == resList.size() ? 2 : std::distance(resList.begin(), std::find(resList.begin(), resList.end(), m_scanparam->resolution_dst)), 2); }; m_query[CapType::IYResolution] = msgSupportGetAllSetReset; @@ -927,127 +874,62 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::ISupportedSizes] = msgSupportGetAllSetReset; m_caps[CapType::ISupportedSizes] = [this](Msg msg, Capability& data) { - switch (msg) { - case Msg::Get: { - int index = -1; - std::list::iterator it = paperSizeList.begin(); - int i = 0; - for (it, i; it != paperSizeList.end(); ++it, i++) { - if (*it == m_scanparam->papertype) { - index = i; - break; - } - } - data = Capability::createEnumeration(data.type(), { (UInt16)PaperSize::A3,(UInt16)PaperSize::A4,(UInt16)PaperSize::A5,(UInt16)PaperSize::A6, - (UInt16)PaperSize::IsoB5,(UInt16)PaperSize::IsoB6,(UInt16)PaperSize::UsLetter, - (UInt16)PaperSize::UsLegal,(UInt16)PaperSize::None -#ifndef G300 -#if defined G200 - ,(UInt16)PaperSize::UsLedger,(UInt16)PaperSize::IsoB4, - (UInt16)PaperSize::MaxSize,(UInt16)PaperSize::UsStatement -#elif defined G400 - ,(UInt16)PaperSize::UsLedger,(UInt16)PaperSize::IsoB4 -#endif -#endif // - }, - index == -1 ? 0 : index, - 0); - - return success(); - } - case Msg::GetCurrent: - data = Capability::createOneValue(data.type(), UInt16(m_scanparam->papertype)); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->papertype =(int)PaperSize::A3; - data = Capability::createOneValue(data.type(), UInt16(PaperSize::A3)); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto paper = data.currentItem(); - std::list::iterator resIter = paperSizeList.begin(); - bool contains = false; - for (resIter; resIter != paperSizeList.end(); resIter++) { - if (*resIter == paper) { - contains = true; - break; - } - } - if (contains) { + if (std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), paper)) == paperSizeList.size()) + return badValue(); + else { m_scanparam->papertype = (byte)paper; - if (paper == (byte)PaperSize::None || paper == (byte)PaperSize::UsStatement) - { + if (paper == (byte)PaperSize::None || paper == (byte)PaperSize::UsStatement){ m_scanparam->paperAlign = PaperAlign::Rot0; m_scanparam->en_sizecheck = 0; } - - if(paper== (byte)PaperSize::UsStatement) - { + if (paper == (byte)PaperSize::UsStatement){ m_autosize = (UInt16)AutoSize::None; m_autoboarderdetcet = false; m_scanparam->is_autocrop = 0; } - else - { + else{ m_autosize = (paper == (byte)PaperSize::None) ? (UInt16)AutoSize::Auto : (UInt16)AutoSize::None; m_autoboarderdetcet = paper == (byte)PaperSize::None; m_scanparam->is_autocrop = paper == (byte)PaperSize::None ? 1 : 0; } return success(); } - return badValue(); - } - default: - return capBadOperation(); } + return CapSupGetAllReset(msg, data, { PaperSize::A4,PaperSize::A5,PaperSize::A6, + PaperSize::IsoB5,PaperSize::IsoB6,PaperSize::UsLetter, + PaperSize::UsLegal,PaperSize::None +#ifndef G300 +#if defined G200 + ,PaperSize::A3,PaperSize::UsLedger,PaperSize::IsoB4, + PaperSize::MaxSize,PaperSize::UsStatement +#elif defined G400 + PaperSize::A3,,PaperSize::UsLedger,PaperSize::IsoB4 +#endif +#endif // + },m_scanparam->papertype, PaperSize::A3, + std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)) == paperSizeList.size() ? 0 : std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)), + std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), 11))); }; #ifdef G200 #ifndef ISG100 m_query[(CapType)(CapTypeEx::TwEx_SizeDetect)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_SizeDetect)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_SizeDetect), { Bool(),Bool(true) }, Bool(m_scanparam->en_sizecheck), 0); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->en_sizecheck = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_SizeDetect), Bool(false)); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_SizeDetect), m_scanparam->en_sizecheck); - return success(); - case Msg::Set: { + if( Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->en_sizecheck = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->en_sizecheck, false, m_scanparam->en_sizecheck, 0); }; #endif // !ISG100 #endif // G200 m_query[CapType::IOrientation] = msgSupportGetAllSetReset; m_caps[CapType::IOrientation] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { Orientation::Portrait, Orientation::Landscape }, m_scanparam->paperAlign, 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((Orientation)(m_scanparam->paperAlign)); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->paperAlign = PaperAlign::Rot0; - data = Capability::createOneValue(Orientation::Portrait); - return success(); - - case Msg::Set: { + if( Msg::Set == msg) { auto mech = data.currentItem(); if (mech == Orientation::Landscape || mech == Orientation::Portrait) { m_scanparam->paperAlign = (PaperAlign)mech; @@ -1055,62 +937,24 @@ Result HuagaoDs::identityOpenDs(const Identity&) { } return badValue(); } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { Orientation::Portrait, Orientation::Landscape }, m_scanparam->paperAlign, Orientation::Portrait, m_scanparam->paperAlign == 0 ? 0 : 1, 0); }; m_query[CapType::IRotation] = msgSupportGetAllSetReset; m_caps[CapType::IRotation] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: { - int index = -1; - std::list::iterator it = imageRotateList.begin(); - int i = 0; - for (it, i; it != imageRotateList.end(); ++it, i++) { - if ((m_scanparam->imageRotateDegree + 1) >= *it && (m_scanparam->imageRotateDegree - 1) <= *it) { - index = i; - break; - } - } - data = Capability::createEnumeration( - { Fix32(0.0f),Fix32(90.0f),Fix32(180.0f),Fix32(270.0f) }, - index == -1 ? 0 : index, - 0); - return success(); - } - case Msg::GetCurrent: - data = Capability::createOneValue(Fix32(m_scanparam->imageRotateDegree)); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->imageRotateDegree = 0.0f; - data = Capability::createOneValue(Fix32(0.0f)); - return success(); - - case Msg::Set: { + if( Msg::Set == msg){ auto res = data.currentItem(); - std::list::iterator resIter = imageRotateList.begin(); - bool contains = false; - for (resIter; resIter != imageRotateList.end(); resIter++) { - if (((float)res + 1) >= *resIter && ((float)res - 1) <= *resIter) { - contains = true; - break; - } - } - if (contains) { + if (std::distance(imageRotateList.begin(), std::find(imageRotateList.begin(), imageRotateList.end(), res)) == imageRotateList.size()) + return badValue(); + else{ m_scanparam->imageRotateDegree = (float)res; if (res != 0.0f) m_scanparam->is_autotext = 0; return success(); } - return badValue(); - } - - default: - return capBadOperation(); } + return CapSupGetAllReset(msg, data, { Fix32(0.0f),Fix32(90.0f),Fix32(180.0f),Fix32(270.0f) }, m_scanparam->imageRotateDegree, Fix32(0.0), + std::distance(imageRotateList.begin(), std::find(imageRotateList.begin(), imageRotateList.end(), m_scanparam->imageRotateDegree)),0); }; #ifndef G200 @@ -1121,95 +965,37 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::SerialNumber] = msgSupportGetAll; //m_caps[CapType::SerialNumber] = std::bind(oneValGetString, _1, _2, scanner->GetSerialNum()); m_caps[CapType::SerialNumber] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - case Msg::GetDefault: - { - std::string ser = scanner->GetSerialNum(); - Str255 str; - str.setData(ser.c_str(), ser.size()); - data = Capability::createOneValue(str); - return success(); - } - default: - return capBadOperation(); - } + Str255 str; + str.setData(scanner->GetSerialNum().c_str(), scanner->GetSerialNum().size()); + return CapSupGetAll(msg, data, str, str); }; - m_query[(CapType)(CapTypeEx::TwEx_HardwareVersion)] = msgSupportGetAll; //m_caps[(CapType)(CapTypeEx::TwEx_HardwareVersion)] = std::bind(oneValGetString, _1, _2, scanner->GetFWVersion()); m_caps[(CapType)(CapTypeEx::TwEx_HardwareVersion)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - case Msg::GetDefault: - { - std::string ser = scanner->GetFWVersion(); - Str255 str; - str.setData(ser.c_str(), ser.size()); - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_HardwareVersion),str); - return success(); - } - default: - return capBadOperation(); - } + Str255 str; + str.setData(scanner->GetFWVersion().c_str(), scanner->GetFWVersion().size()); + return CapSupGetAllEx(msg, data, str, str); }; - m_query[CapType::FeederLoaded] = msgSupportGetAll; m_caps[CapType::FeederLoaded] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - case Msg::GetDefault: - data = Capability::createOneValue(Bool(scanner->Get_Scanner_PaperOn())); - return success(); - default: - return capBadOperation(); - } + return CapSupGetAll(msg, data, Bool(scanner->Get_Scanner_PaperOn()), Bool(scanner->Get_Scanner_PaperOn())); }; m_query[CapType::Indicators] = msgSupportGetAllSetReset; m_caps[CapType::Indicators] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { Bool(true), Bool(false) }, Bool(m_bIndicator),true); - return success(); - - // fallthrough - case Msg::GetCurrent: - data = Capability::createOneValue(m_bIndicator); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_bIndicator = true; - data = Capability::createOneValue(m_bIndicator); - return success(); - - case Msg::Set: { + if (Msg::Set == msg){ auto show = data.currentItem(); m_bIndicator = show; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { FALSE,TRUE }, m_bIndicator, TRUE, m_bIndicator ? 1 : 0, 1); }; m_query[CapType::CustomDsData] = msgSupportGetAll; m_caps[CapType::CustomDsData] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - case Msg::GetDefault: - data = Capability::createOneValue(CapType::CustomDsData,Bool(true)); - return success(); - default: - return capBadOperation(); - } + return CapSupGetAllEx(msg, data, Bool(true), Bool(true)); }; m_query[CapType::EnableDsUiOnly] = msgSupportGetAll; @@ -1220,28 +1006,12 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::FeederEnabled] = msgSupportGetAllSetReset; m_caps[CapType::FeederEnabled] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue(Bool(m_bFeederEnabled)); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(Bool(m_bFeederEnabled)); - return success(); - - case Msg::GetDefault: - case Msg::Reset: - m_bFeederEnabled = true; - data = Capability::createOneValue(Bool(true)); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_bFeederEnabled = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_bFeederEnabled, Bool(true)); }; m_query[CapType::Duplex] = msgSupportGetAll; @@ -1249,110 +1019,29 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_query[CapType::DuplexEnabled] = msgSupportGetAllSetReset; m_caps[CapType::DuplexEnabled] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue(Bool(m_scanparam->is_duplex)); - return success(); - - case Msg::GetCurrent: - data = Capability::createOneValue(m_scanparam->is_duplex); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->is_duplex = true; - data = Capability::createOneValue(true); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_duplex = mech; - //FileTools::write_log("D:\\1.txt", std::to_string(mech ? 1 : 0)); m_scanparam->is_autodiscradblank_normal = m_scanparam->is_autodiscradblank_vince = m_scanparam->en_fold = 0; if (!mech) m_scanparam->is_backrotate180 = 0;//单面背面旋转180°不可用 return success(); } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_scanparam->is_duplex, Bool(true)); }; m_query[CapType::AutoFeed] = msgSupportGetAllSetReset; m_caps[CapType::AutoFeed] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue(m_bAutoFeed); - return success(); - // fallthrough - case Msg::GetCurrent: - data = Capability::createOneValue(m_bAutoFeed); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_bAutoFeed = true; - data = Capability::createOneValue(true); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_bAutoFeed = mech; return success(); } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_bAutoFeed, true); }; - - //m_query[CapType::AutoScan] = msgSupportGetAllSetReset; - //m_caps[CapType::AutoScan] = [this](Msg msg, Capability& data) -> Result { - // switch (msg) { - // case Msg::Get: - // data = Capability::createEnumeration( - // { Bool(), Bool(true) }, Bool(m_bAutoFeed)); - // return success(); - // // fallthrough - // case Msg::GetCurrent: - // data = Capability::createOneValue(m_bAutoFeed); - // return success(); - // case Msg::Reset: - // case Msg::GetDefault: - // m_bAutoFeed = true; - // data = Capability::createOneValue(true); - // return success(); - - // case Msg::Set: { - // auto mech = data.currentItem(); - // m_bAutoFeed = mech; - // return success(); - // } - - // default: - // return capBadOperation(); - // } - //}; - m_query[CapType::IImageFileFormat] = msgSupportGetAllSetReset; m_caps[CapType::IImageFileFormat] = [this](Msg msg, Capability& data) -> Result { - switch (msg) { - case Msg::Get: { - UInt32 capindex = 0; - if (m_capImageFileFormat == ImageFileFormat::Tiff) capindex = 1; - if (m_capImageFileFormat == ImageFileFormat::Jfif) capindex = 2; - data = Capability::createEnumeration( - { ImageFileFormat::Bmp, ImageFileFormat::Tiff,ImageFileFormat::Jfif }, capindex, 0); - return success(); - } - case Msg::Reset: - case Msg::GetDefault: - m_capImageFileFormat = ImageFileFormat::Bmp; - data = Capability::createOneValue(m_capImageFileFormat); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(m_capImageFileFormat); - return success(); - case Msg::Set: { + if (Msg::Set == msg){ auto mech = data.currentItem(); if (mech == ImageFileFormat::Bmp || mech == ImageFileFormat::Tiff || @@ -1363,316 +1052,145 @@ Result HuagaoDs::identityOpenDs(const Identity&) { else return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset < ImageFileFormat, ImageFileFormat , CapType::IImageFileFormat> (msg, data, { ImageFileFormat::Bmp, ImageFileFormat::Tiff,ImageFileFormat::Jfif }, + m_capImageFileFormat, ImageFileFormat::Bmp,m_capImageFileFormat == ImageFileFormat::Bmp ? 0 : (m_capImageFileFormat == ImageFileFormat::Tiff ? 1 : 2), 0); }; //custom define m_query[CapType::IAutomaticDeskew] = msgSupportGetAllSetReset; m_caps[CapType::IAutomaticDeskew] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - //data = Capability::createEnumeration( - // { Bool(), Bool(true) }, Bool(m_scanparam->autodescrew == 0 ? false : true)); - data = Capability::createOneValue(m_scanparam->autodescrew); - return success(); - case Msg::Reset: - m_scanparam->autodescrew = true; - data = Capability::createOneValue(m_scanparam->autodescrew); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(m_scanparam->autodescrew); - return success(); - case Msg::GetDefault: - data = Capability::createOneValue(true); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto atuodsw = data.currentItem(); m_scanparam->autodescrew = (bool)atuodsw; return success(); } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg,data, m_scanparam->autodescrew,true); }; m_query[(CapType)(CapTypeEx::TwEx_SwitchFrontBack)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_SwitchFrontBack)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)((CapType)(CapTypeEx::TwEx_SwitchFrontBack)), { Bool(),Bool(true) }, Bool(m_scanparam->is_switchfrontback), 0); - return success(); - case Msg::Reset: - case Msg::GetCurrent: - m_scanparam->is_switchfrontback = false; - data = Capability::createOneValue((CapType)((CapType)(CapTypeEx::TwEx_SwitchFrontBack)), m_scanparam->is_switchfrontback); - return success(); - case Msg::GetDefault: - data = Capability::createOneValue((CapType)((CapType)(CapTypeEx::TwEx_SwitchFrontBack)), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_switchfrontback = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->is_switchfrontback, (Bool)false, m_scanparam->is_switchfrontback ? 1 : 0, 0); }; m_query[CapType::IAutomaticRotate] = msgSupportGetAllSetReset; m_caps[CapType::IAutomaticRotate] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue(m_scanparam->is_autotext); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->is_autotext = false; - data = Capability::createOneValue(false); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_autotext = (bool)mech; if (mech) m_scanparam->imageRotateDegree = 0.0f; return success(); } - - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_scanparam->is_autotext, false); }; m_query[CapType::IAutomaticCropUsesFrame] = msgSupportGetAll; m_caps[CapType::IAutomaticCropUsesFrame] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::Capability::createOneValue(m_scanparam->is_autocrop); - return success(); - case Msg::Reset: - case Msg::GetCurrent: - m_scanparam->is_autocrop = false; - data = Capability::createOneValue(m_scanparam->is_autocrop); - return success(); - - case Msg::GetDefault: - data = Capability::createOneValue(false); - return success(); - - //case Msg::Set: { - // auto autocrop = data.currentItem(); - // m_scanparam->is_autocrop = (bool)autocrop; - // if (autocrop) - // m_scanparam->papertype = (byte)PaperSize::None; - // return success(); - //} - default: - return capBadOperation(); - } + return CapSupGetAll(msg, data, m_scanparam->is_autocrop, false); }; m_query[CapType::AutoScan] = msgSupportGetAllSetReset; m_caps[CapType::AutoScan] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { Bool(), Bool(true) }, m_autoscan); - return success(); - case Msg::Reset: - m_autoscan = true; - data = Capability::createOneValue(m_autoscan); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(m_autoscan); - return success(); - case Msg::GetDefault: - data = Capability::createOneValue(true); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto autoscan = data.currentItem(); m_autoscan = autoscan; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { FALSE,TRUE }, m_autoscan, Bool(true), m_autoscan ? 1 : 0, 1); }; m_query[CapType::IAutoSize] = msgSupportGetAllSetReset; m_caps[CapType::IAutoSize] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration( - { AutoSize::None, AutoSize::Auto}, (UInt16)m_autosize, 0); - return success(); - // fallthrough - case Msg::GetCurrent: - data = Capability::createOneValue((AutoSize)m_autosize); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_autosize = (UInt16)AutoSize::None; - data = Capability::createOneValue(AutoSize::None); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto autosize = data.currentItem(); - if (autosize == AutoSize::Auto) - { - if(m_scanparam->papertype==(byte)PaperSize::UsStatement) - { + if (autosize == AutoSize::Auto){ + if(m_scanparam->papertype==(byte)PaperSize::UsStatement){ m_scanparam->is_autocrop = 0; m_autoboarderdetcet = false; } - else - { + else{ m_scanparam->is_autocrop = 1; m_scanparam->papertype = (byte)Twpp::PaperSize::None; m_scanparam->paperAlign = PaperAlign::Rot0; m_autoboarderdetcet = true; } } - else - { + else{ m_autoboarderdetcet = false; m_scanparam->is_autocrop = 0; } - m_autosize = (byte)autosize; + m_autosize = (UInt16)autosize; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { AutoSize::None, AutoSize::Auto }, m_autosize, AutoSize::None, (m_autosize == (UInt16)AutoSize::Auto) ? 1 : 0, 0); }; m_query[CapType::IAutomaticBorderDetection] = msgSupportGetAllSetReset; m_caps[CapType::IAutomaticBorderDetection] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue(m_autoboarderdetcet); - return success(); - case Msg::Reset: - m_autoboarderdetcet = false; - data = Capability::createOneValue(m_autoboarderdetcet); - return success(); - - case Msg::GetDefault: - data = Capability::createOneValue(false); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto autodetectborder = data.currentItem(); - if (autodetectborder) - { - if(m_scanparam->papertype!=(byte)PaperSize::UsStatement) - { + if (autodetectborder){ + if(m_scanparam->papertype!=(byte)PaperSize::UsStatement){ m_scanparam->is_autocrop = true; m_scanparam->papertype = (byte)Twpp::PaperSize::None; m_scanparam->paperAlign = PaperAlign::Rot0; m_autosize = (UInt16)AutoSize::Auto; } } - else - { + else{ m_autosize = (UInt16)AutoSize::None; } m_autoboarderdetcet = autodetectborder; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, m_autoboarderdetcet, false); }; m_query[CapType::IImageMerge] = msgSupportGetAllSetReset; m_caps[CapType::IImageMerge] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue(CapType::IImageMerge, (UInt16)m_scanparam->en_fold); - return success(); - case Msg::Reset: - m_scanparam->en_fold = 0;//默认不对折 - data = Capability::createOneValue(CapType::IImageMerge, (UInt16)m_scanparam->en_fold); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(CapType::IImageMerge, (UInt16)m_scanparam->en_fold); - return success(); - - case Msg::GetDefault: - data = Capability::createOneValue(CapType::IImageMerge, 0); - return success(); - - case Msg::Set: { + if (Msg::Set == msg) { auto autocrop = data.currentItem(); m_scanparam->en_fold = (byte)autocrop; - if ((UInt16)autocrop != 0) - { + if ((UInt16)autocrop != 0){ m_scanparam->is_duplex = 1; m_scanparam->autodescrew = 1;//合并可用时 默认自动纠偏 m_scanparam->is_autodiscradblank_normal = m_scanparam->is_autodiscradblank_vince = 0; } return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->en_fold, 0); }; m_query[CapType::IAutoDiscardBlankPages] = msgSupportGetAllSetReset; - m_caps[CapType::IAutoDiscardBlankPages] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue(m_scanparam->is_autodiscradblank_normal ? DiscardBlankPages::Auto : DiscardBlankPages::Disabled); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->is_autodiscradblank_normal = false; - data = Capability::createOneValue(DiscardBlankPages::Disabled); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue(m_scanparam->is_autodiscradblank_normal ? DiscardBlankPages::Auto : DiscardBlankPages::Disabled); - return success(); - - case Msg::Set: { + m_caps[CapType::IAutoDiscardBlankPages] = [this](Msg msg, Capability& data)->Result { + if (Msg::Set == msg) { auto mech = data.currentItem(); if ((mech != DiscardBlankPages::Auto) || (mech != DiscardBlankPages::Disabled)) return badValue(); - m_scanparam->is_autodiscradblank_normal = (Int32)mech == (Int32)DiscardBlankPages::Auto; m_scanparam->is_duplex = 1; m_scanparam->en_fold = 0; m_scanparam->is_autodiscradblank_vince = 0; return success(); } - default: - return capBadOperation(); + DiscardBlankPages autodiscradblank; + if (Msg::GetDefault == msg || (Msg::Reset == msg)) { + m_scanparam->is_autodiscradblank_normal = false; } + m_scanparam->is_autodiscradblank_normal ? (autodiscradblank = DiscardBlankPages::Auto) : (autodiscradblank = DiscardBlankPages::Disabled); + return CapSupGetAllReset(msg, data, autodiscradblank, DiscardBlankPages::Disabled); }; /*costom caps*/ //跳过空白页发票 m_query[(CapType)(CapTypeEx::TwEx_IAutoDiscardBlankVince)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IAutoDiscardBlankVince)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)((CapType)(CapTypeEx::TwEx_IAutoDiscardBlankVince)), { Bool(),Bool(true) }, Bool(m_scanparam->is_autodiscradblank_vince), 0); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->is_autodiscradblank_vince = false; - data = Capability::createOneValue((CapType)((CapType)(CapTypeEx::TwEx_IAutoDiscardBlankVince)), Bool(false)); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)((CapType)(CapTypeEx::TwEx_IAutoDiscardBlankVince)), m_scanparam->is_autodiscradblank_vince); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_autodiscradblank_vince = mech; m_scanparam->is_duplex = 1; @@ -1681,201 +1199,92 @@ Result HuagaoDs::identityOpenDs(const Identity&) { m_scanparam->is_autodiscradblank_normal = 0; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->is_autodiscradblank_normal, Bool(false), m_scanparam->is_autodiscradblank_normal ? 1 : 0, 0); }; m_query[(CapType)(CapTypeEx::TwEx_IBackRotate180)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IBackRotate180)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IBackRotate180), { Bool(),Bool(true) }, Bool(m_scanparam->is_backrotate180), 0); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->is_backrotate180 = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IBackRotate180), Bool(false)); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IBackRotate180), m_scanparam->is_backrotate180); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_backrotate180 = mech; if (mech) m_scanparam->is_duplex = 1; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->is_backrotate180, Bool(false), m_scanparam->is_backrotate180 ? 1 : 0, 0); }; //填黑框 m_query[(CapType)(CapTypeEx::TwEx_IFillBackground)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IFillBackground)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IFillBackground), { Bool(),Bool(true) }, Bool(m_scanparam->fillbackground), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillBackground), m_scanparam->fillbackground); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->fillbackground = true; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillBackground), Bool(true)); - - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->fillbackground = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->fillbackground, Bool(true), m_scanparam->fillbackground ? 1 : 0, 1); }; //裁剪纠偏轮廓缩进像素 m_query[(CapType)(CapTypeEx::TwEx_CroporDesaskewIndent)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_CroporDesaskewIndent)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CroporDesaskewIndent), m_scanparam->indent); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->indent = 5; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CroporDesaskewIndent), UInt8(5)); - return success(); - case Msg::Set: { - auto mech = data.currentItem(); - - if (mech > 30 || mech < 5) + if (Msg::Set == msg) { + auto mech = data.currentItem(); + if ((mech > 30 || mech < 5) && ((bool)m_scanparam->is_autocrop == true)) return badValue(); m_scanparam->indent = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->indent, 5); }; //自动裁剪降噪像素 m_query[(CapType)(CapTypeEx::TwEx_CropNoise)] = msgSupportGetAllSetReset; - m_caps[(CapType)(CapTypeEx::TwEx_CropNoise)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CropNoise), m_scanparam->noise); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->noise = 40; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CropNoise), UInt8(40)); - return success(); - case Msg::Set: { + m_caps[(CapType)(CapTypeEx::TwEx_CropNoise)] = [this](Msg msg, Capability& data)->Result { + if (Msg::Set == msg) { auto mech = data.currentItem(); - - if (mech > 50 || mech < 30) + if ((mech > 50 || mech < 30) && ((bool)m_scanparam->is_autocrop == true)) return badValue(); m_scanparam->noise = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->noise, 40); }; //自动裁切和纠偏的二值化阀值 m_query[(CapType)(CapTypeEx::TwEx_CroporDesaskewThreshold)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_CroporDesaskewThreshold)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CroporDesaskewThreshold), m_scanparam->AutoCrop_threshold); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->AutoCrop_threshold = 40; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_CroporDesaskewThreshold), UInt8(40)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); - if (mech > 50 || mech < 30) + if ((mech > 50 || mech < 30) && ((bool)m_scanparam->is_autocrop == true)) return badValue(); m_scanparam->AutoCrop_threshold = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->AutoCrop_threshold, 40); }; //黑框填充方式 m_query[(CapType)(CapTypeEx::TwEx_FillBacngroundMode)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_FillBacngroundMode)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_FillBacngroundMode), { Bool(),Bool(true) }, Bool(m_scanparam->is_convex), true); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_FillBacngroundMode), m_scanparam->is_convex); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->is_convex = true; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_FillBacngroundMode), Bool(true)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->is_convex = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->is_convex, Bool(true)); }; //填穿孔 m_query[(CapType)(CapTypeEx::TwEx_IFillHole)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IFillHole)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IFillHole), { Bool(),Bool(true) }, Bool(m_scanparam->fillhole.is_fillhole), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillHole), m_scanparam->fillhole.is_fillhole); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->fillhole.is_fillhole = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillHole), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->fillhole.is_fillhole = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->fillhole.is_fillhole, Bool(true), m_scanparam->fillhole.is_fillhole ? 1 : 0, 0); }; m_query[(CapType)(CapTypeEx::TwEx_IFillHoleRatio)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IFillHoleRatio)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillHoleRatio), m_scanparam->fillhole.fillholeratio); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillHoleRatio), m_scanparam->fillhole.fillholeratio); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->fillhole.fillholeratio = 10; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IFillHoleRatio), Int32(10)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (mech > 0 && mech < 50) { m_scanparam->fillhole.fillholeratio = (int)mech; @@ -1883,182 +1292,82 @@ Result HuagaoDs::identityOpenDs(const Identity&) { } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->fillhole.fillholeratio, 10); }; - //噪点优化 m_query[(CapType)(CapTypeEx::TwEx_IDetachNoise)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IDetachNoise)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IDetachNoise), { Bool(),Bool(true) }, Bool(m_scanparam->fillhole.is_fillhole), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IDetachNoise), m_scanparam->detachnoise.is_detachnoise); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->detachnoise.is_detachnoise = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IDetachNoise), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { if (m_scanparam->pixtype != 0) return badValue(); auto mech = data.currentItem(); m_scanparam->detachnoise.is_detachnoise = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->detachnoise.is_detachnoise, FALSE, m_scanparam->detachnoise.is_detachnoise ? 1 : 0, 0); }; m_query[(CapType)(CapTypeEx::TwEx_IDetachNoiseValue)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IDetachNoiseValue)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IDetachNoiseValue), m_scanparam->detachnoise.detachnoise); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IDetachNoiseValue), m_scanparam->detachnoise.detachnoise); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->fillhole.fillholeratio = 10; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IDetachNoiseValue), Int32(3)); - return success(); - case Msg::Set: { - if (m_scanparam->detachnoise.is_detachnoise) - { - auto mech = data.currentItem(); - if (mech > 9 && mech < 51) { - m_scanparam->detachnoise.detachnoise = (int)mech; - return success(); - } + if (Msg::Set == msg) { + auto mech = data.currentItem(); + if (mech > 9 && mech < 51) { + m_scanparam->detachnoise.detachnoise = (int)mech; + return success(); } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->detachnoise.detachnoise, 10); }; - //多流除红 m_query[(CapType)(CapTypeEx::TwEx_IMultiOutputRed)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IMultiOutputRed)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IMultiOutputRed), { Bool(),Bool(true) }, Bool(m_scanparam->multi_output_red), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IMultiOutputRed), m_scanparam->multi_output_red); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->multi_output_red = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IMultiOutputRed), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (m_scanparam->pixtype == (byte)PixelType::Rgb) m_scanparam->multi_output_red = mech; else - { m_scanparam->multi_output_red = 0;//非彩色 不能使用多流除红 - } return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->multi_output_red, FALSE, m_scanparam->multi_output_red ? 1 : 0, 0); }; - //答题卡除红 m_query[(CapType)(CapTypeEx::TwEx_HsvCorrect)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_HsvCorrect)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_HsvCorrect), { Bool(),Bool(true) }, Bool(m_scanparam->hsvcorrect), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_HsvCorrect), m_scanparam->hsvcorrect); - return success(); - case Msg::Reset: - case Msg::GetDefault: - m_scanparam->hsvcorrect = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_HsvCorrect), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->hsvcorrect = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->hsvcorrect, FALSE, m_scanparam->hsvcorrect ? 1 : 0, 0); }; m_query[CapType::IFilter] = msgSupportGetAllSetReset; m_caps[CapType::IFilter] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration({ Filter::Red,Filter::Green,Filter::Blue,Filter::None }, - m_scanparam->filter, - 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((Filter)m_scanparam->filter); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->filter = (byte)Filter::None; - data = Capability::createOneValue(Filter::None); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (mech == Filter::None || mech == Filter::Red || mech == Filter::Green || mech == Filter::Blue) { m_scanparam->filter = (byte)mech; - if (mech != Filter::None) - { + if (mech != Filter::None){ m_scanparam->enhance_color = (byte)Enchace_Color::Enhance_None; } return success(); } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllReset(msg, data, { Filter::Red,Filter::Green,Filter::Blue,Filter::None }, m_scanparam->filter, Filter::None, m_scanparam->filter, 3); }; //颜色增强 m_query[(CapType)(CapTypeEx::TwEx_IEnhanceColor)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IEnhanceColor)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_IEnhanceColor), - { Enchace_Color::Enhance_None,Enchace_Color::Enhance_Red,Enchace_Color::Enhance_Green,Enchace_Color::Enhance_Blue }, - m_scanparam->enhance_color, - 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IEnhanceColor), (Enchace_Color)(m_scanparam->enhance_color)); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->enhance_color = Enchace_Color::Enhance_None; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_IEnhanceColor), Enchace_Color::Enhance_None); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); - if (m_scanparam->pixtype == (byte)PixelType::Rgb) - { + if (m_scanparam->pixtype == (byte)PixelType::Rgb){ m_scanparam->enhance_color = (byte)Enchace_Color::Enhance_None; } - else - { + else{ if (mech == Enchace_Color::Enhance_None || mech == Enchace_Color::Enhance_Red || mech == Enchace_Color::Enhance_Green || mech == Enchace_Color::Enhance_Blue) { m_scanparam->enhance_color = (byte)mech; @@ -2069,37 +1378,19 @@ Result HuagaoDs::identityOpenDs(const Identity&) { } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { Enchace_Color::Enhance_None,Enchace_Color::Enhance_Red,Enchace_Color::Enhance_Green,Enchace_Color::Enhance_Blue }, m_scanparam->enhance_color, Enchace_Color::Enhance_None, m_scanparam->enhance_color, 0); }; m_query[(CapType)(CapTypeEx::TwEx_Sharpen)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_Sharpen)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_Sharpen), { SharpenBlur::Sharpen_None,SharpenBlur::Sharpen_Normal,SharpenBlur::Sharpen_More,SharpenBlur::Sharpen_Blur,SharpenBlur::Sharpen_Blur_More }, - m_scanparam->sharpen, - 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_Sharpen), (SharpenBlur)(m_scanparam->sharpen)); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->sharpen = SharpenBlur::Sharpen_None; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_Sharpen), SharpenBlur::Sharpen_None); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (m_scanparam->pixtype == (int)PixelType::BlackWhite) return badValue(); m_scanparam->sharpen = (byte)mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { SharpenBlur::Sharpen_None,SharpenBlur::Sharpen_Normal,SharpenBlur::Sharpen_More,SharpenBlur::Sharpen_Blur,SharpenBlur::Sharpen_Blur_More }, m_scanparam->sharpen, SharpenBlur::Sharpen_None, m_scanparam->sharpen, 0); }; /*亮度 对比度 gamma range类型 Range 类型*/ @@ -2235,47 +1526,20 @@ Result HuagaoDs::identityOpenDs(const Identity&) { // return capBadOperation(); // } //}; - /*以下为硬件协议*/ m_query[(CapType)(CapTypeEx::TwEx_ScrewDetectEnable)] = msgSupportGetAllSetReset; - m_caps[(CapType)(CapTypeEx::TwEx_ScrewDetectEnable)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_ScrewDetectEnable), { Bool(),Bool(true) }, Bool(m_scanparam->hardwarecaps.en_skrewdetect), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_ScrewDetectEnable), m_scanparam->hardwarecaps.en_skrewdetect); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->hardwarecaps.en_skrewdetect = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_ScrewDetectEnable), Bool(false)); - return success(); - case Msg::Set: { + m_caps[(CapType)(CapTypeEx::TwEx_ScrewDetectEnable)] = [this](Msg msg, Capability& data)->Result { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->hardwarecaps.en_skrewdetect = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->sharpen, FALSE, m_scanparam->hardwarecaps.en_skrewdetect ? 1 : 0, 0); }; m_query[(CapType)(CapTypeEx::TwEx_ScrewLevel)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_ScrewLevel)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_ScrewLevel), m_scanparam->hardwarecaps.skrewdetectlevel); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_ScrewLevel), m_scanparam->hardwarecaps.skrewdetectlevel); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->hardwarecaps.skrewdetectlevel = 3; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_ScrewLevel), UInt8(3)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); if (mech >= 1 && mech <= 5) { m_scanparam->hardwarecaps.skrewdetectlevel = mech; @@ -2283,82 +1547,38 @@ Result HuagaoDs::identityOpenDs(const Identity&) { } return badValue(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, m_scanparam->hardwarecaps.skrewdetectlevel, 3); }; - //装订检测 m_query[(CapType)(CapTypeEx::TwEx_StableDetectEnable)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_StableDetectEnable)] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - data = Capability::createEnumeration((CapType)(CapTypeEx::TwEx_StableDetectEnable), { Bool(),Bool(true) }, Bool(m_scanparam->hardwarecaps.en_stapledetect), 0); - return success(); - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_StableDetectEnable), m_scanparam->hardwarecaps.en_stapledetect); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->hardwarecaps.en_stapledetect = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_StableDetectEnable), Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->hardwarecaps.en_stapledetect = mech; return success(); } - default: - return capBadOperation(); - } + return CapSupGetAllResetEx(msg, data, { FALSE,TRUE }, m_scanparam->hardwarecaps.en_stapledetect, FALSE, m_scanparam->hardwarecaps.en_stapledetect ? 1 : 0, 0); }; - m_query[(CapType)(CapTypeEx::TwEx_DogEarDelection)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_DogEarDelection)] = [this](Msg msg, Capability& data)->Result { - switch (msg) - { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue((CapType)CapTypeEx::TwEx_DogEarDelection, m_scanparam->is_dogeardetection); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->is_dogeardetection = false; - data = Capability::createOneValue((CapType)(CapTypeEx::TwEx_DogEarDelection), Bool(false)); - return success(); - case Msg::Set: - { - auto mech = data.currentItem(); - m_scanparam->is_dogeardetection= mech; - return success(); - } - default: - return capBadOperation(); + if (Msg::Set == msg) { + auto mech = data.currentItem(); + m_scanparam->is_dogeardetection= mech; + return success(); } + return CapSupGetAllResetEx(msg, data, m_scanparam->is_dogeardetection, FALSE); }; //双张检测 与官方标准定义有所差异 此协议修改为bool型 m_query[CapType::DoubleFeedDetection] = msgSupportGetAllSetReset; m_caps[CapType::DoubleFeedDetection] = [this](Msg msg, Capability& data)->Result { - switch (msg) { - case Msg::Get: - case Msg::GetCurrent: - data = Capability::createOneValue(CapType::DoubleFeedDetection, m_scanparam->hardwarecaps.en_doublefeed); - return success(); - case Msg::GetDefault: - case Msg::Reset: - m_scanparam->hardwarecaps.en_doublefeed = false; - data = Capability::createOneValue(CapType::DoubleFeedDetection, Bool(false)); - return success(); - case Msg::Set: { + if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->hardwarecaps.en_doublefeed = mech; return success(); } - default: - return capBadOperation(); - } - }; + return CapSupGetAllResetEx(msg, data, m_scanparam->hardwarecaps.en_doublefeed, FALSE); + }; return success(); } diff --git a/huagao/huagaods.hpp b/huagao/huagaods.hpp index a9c16e91..a60b4024 100644 --- a/huagao/huagaods.hpp +++ b/huagao/huagaods.hpp @@ -94,6 +94,7 @@ private://method void updataGscanCap(); Twpp::Result capCommon(const Twpp::Identity& origin, Twpp::Msg msg, Twpp::Capability& data); + private://field std::unordered_map> m_caps; std::unordered_map m_query; diff --git a/huagao/stdafx.h b/huagao/stdafx.h index 46db6d3080fc94df43ab6aa7863d249534c2f793..9c1ba2d7ee567dbe6f8320c439f1bd13f33a29ac 100644 GIT binary patch delta 30 mcmbOfGA(4oHV#%}1_K6z$&HMXldo`uG3ztvZ`R~|sQ>_#l?fRD delta 30 mcmbOhGAU%kHV#%31_K6z$&HMXldo`uO`fJCu-T6Dh5`VdVG0-k