code_device/hgdriver/hgdev/hg_scanner_239.cpp

1970 lines
80 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "hg_scanner_239.h"
#include "../wrapper/hg_log.h"
#include "filetools.h"
#if defined(WIN32) || defined(_WIN64)
#include "scanner_manager.h"
#endif
#include <map>
//#define SAVE_TO_FILE
#define USB_REQ_GET_FPGA_REGS 0x40
#define USB_REQ_SET_FPGA_REGS 0x41
#define USB_REQ_GET_MOTOR_REGS 0x42
#define USB_REQ_SET_MOTOR_REGS 0x43
#define USB_REQ_GET_DEV_STATUS 0x60
#define USB_REQ_GET_DEV_CONFIGURATION 0x61
#define USB_REQ_SET_DEV_CONFIGURATION 0x62
#define USB_REQ_GET_DEV_REGS 0x63
#define USB_REQ_SET_DEV_REGS 0x64
static std::string jsontext1("{\"device_type\":\"G139-G239\",\"option_count\":76,\"1\":{\"category\":\"base\",\"name\":\"restore\",\"title\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"desc\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"type\":\"button\",\"cur\":\"button\",\"default\":\"button\",\"size\":0},\"2\":{\"category\":\"advanced\",\"name\":\"help\",\"title\":\"\\u5e2e\\u52a9\",\"desc\":\"\\u663e\\u793a\\u8f6f\\u4ef6\\u5e2e\\u52a9\\u6587\\u6863\",\"type\":\"button\",\"cur\":\"true\",\"default\":\"true\",\"size\":4},\"3\":{\"category\":\"base\",\"name\":\"grp-1\",\"title\":\"\\u57fa\\u672c\\u8bbe\\u7f6e\",\"type\":\"group\"},\"4\":{\"category\":\"base\",\"name\":\"is-multiout\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"5\":{\"category\":\"base\",\"name\":\"multiout-type\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"size\":32,\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend_or\":[\"4==true\"]},\"6\":{\"category\":\"base\",\"name\":\"mode\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"size\":32,\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend_or\":[\"4!=true\"]},\"7\":{\"category\":\"base\",\"name\":\"binary-threshold\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u9608\\u503c\",\"desc\":\"\\u9ad8\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a1\\uff08\\u767d\\uff09\\uff0c\\u4f4e\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a0\\uff08\\u9ed1\\uff09\",\"type\":\"int\",\"cur\":127,\"default\":127,\"size\":4,\"range\":{\"min\":0,\"max\":255},\"depend_or\":[\"4==true\",\"6==\\u9ed1\\u767d\"]},\"8\":{\"category\":\"base\",\"name\":\"reverse-bw\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u53cd\\u8272\\u8f93\\u51fa\",\"desc\":\"\\u8f93\\u51fa\\u7684\\u9ed1\\u767d\\u56fe\\u50cf\\u4ee5\\u201c1\\u201d\\u4ee3\\u8868\\u9ed1\\u8272\\uff0c\\u201c0\\u201d\\u4ee3\\u8868\\u767d\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"4==true\",\"6==\\u9ed1\\u767d\"]},\"9\":{\"category\":\"base\",\"name\":\"filter\",\"title\":\"\\u7070\\u5ea6\\u6216\\u9ed1\\u767d\\u56fe\\u50cf - \\u9664\\u8272\\u4e0e\\u589e\\u5f3a\",\"desc\":\"\\u6d88\\u9664\\u6216\\u589e\\u5f3a\\u6307\\u5b9a\\u8272\\u5f69\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u9664\\u8272\",\"default\":\"\\u4e0d\\u9664\\u8272\",\"size\":24,\"range\":[\"\\u4e0d\\u9664\\u8272\",\"\\u9664\\u7ea2\\u8272\",\"\\u9664\\u7eff\\u8272\",\"\\u9664\\u84dd\\u8272\",\"\\u7ea2\\u8272\\u589e\\u5f3a\",\"\\u7eff\\u8272\\u589e\\u5f3a\",\"\\u84dd\\u8272\\u589e\\u5f3a\"],\"depend_and\":[\"4!=true\",\"6!=24\\u4f4d\\u5f69\\u8272\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"10\":{\"category\":\"base\",\"name\":\"is-rid-multiout-red\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u591a\\u6d41\\u8f93\\u51fa\\u9664\\u7ea2\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u5f69\\u8272\\u56fe\\u50cf\\u548c\\u7070\\u5ea6\\u9664\\u7ea2\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"11\":{\"category\":\"base\",\"name\":\"is-rid-answer-sheet-red\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u7b54\\u9898\\u5361\\u9664\\u7ea2\",\"desc\":\"\\u8f93\\u51fa\\u9664\\u7ea2\\u5f69\\u8272\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"12\":{\"category\":\"base\",\"name\":\"is-erase-bkg\",\"title\":\"\\u80cc\\u666f\\u79fb\\u9664\",\"desc\":\"\\u79fb\\u9664\\u6587\\u7a3f\\u80cc\\u666f\\u5e95\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"13\":{\"category\":\"base\",\"name\":\"bkg-color-range\",\"title\":\" \\u80cc\\u666f\\u8272\\u5f69\\u6d6e\\u52a8\\u8303\\u56f4\",\"desc\":\"\\u4e0e\\u80cc\\u666f\\u5e95\\u8272\\u504f\\u5dee\\u5728\\u8be5\\u503c\\u8303\\u56f4\\u5185\\u7684\\u989c\\u8272\\uff0c\\u90fd\\u5c06\\u88ab\\u79fb\\u9664\",\"type\":\"int\",\"cur\":20,\"default\":20,\"size\":4,\"range\":{\"min\":1,\"max\":128},\"depend_or\":[\"12==true\"]},\"14\":{\"category\":\"base\",\"name\":\"sharpen\",\"title\":\"\\u9510\\u5316\\u4e0e\\u6a21\\u7cca\",\"desc\":\"\\u9009\\u62e9\\u9510\\u5316\\u6548\\u679c\\u6216\\u6a21\\u7cca\\u6548\\u679c\",\"type\":\"string\",\"cur\":\"\\u65e0\",\"default\":\"\\u65e0\",\"size\":24,\"range\":[\"\\u65e0\",\"\\u9510\\u5316\",\"\\u8fdb\\u4e00\\u6b65\\u9510\\u5316\",\"\\u6a21\\u7cca\",\"\\u8fdb\\u4e00\\u6b65\\u6a21\\u7cca\"],\"depend_and\":[\"4!=true\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"15\":{\"category\":\"base\",\"name\":\"is-rid-morr\",\"title\":\"\\u53bb\\u9664\\u6469\\u5c14\\u7eb9\",\"desc\":\"\\u53bb\\u9664\\u56fe\\u50cf\\u4e2d\\u7684\\u6469\\u5c14\\u7eb9\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"16\":{\"category\":\"base\",\"name\":\"is-rid-grid\",\"title\":\"\\u9664\\u7f51\\u7eb9\",\"desc\":\"\\u53bb\\u9664\\u56fe\\u50cf\\u4e2d\\u7684\\u7f51\\u7eb9\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"17\":{\"category\":\"base\",\"name\":\"is-err-extension\",\"title\":\"\\u9519\\u8bef\\u6269\\u6563\",\"desc\":\"\\u4ee5\\u70b9\\u9635\\u5f62\\u5f0f\\u6784\\u5efa\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"6==\\u9ed1\\u767d\"]},\"18\":{\"category\":\"base\",\"name\":\"is-noise-optimize\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u566a\\u70b9\\u4f18\\u5316\",\"desc\":\"\\u53bb\\u9664\\u56fe\\u50cf\\u4e2d\\u7684\\u5b64\\u7acb\\u9ed1\\u70b9\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"6==\\u9ed1\\u767d\"]},\"19\":{\"category\":\"base\",\"name\":\"noise-size\",\"title\":\" \\u566a\\u70b9\\u4f18\\u5316\\u5c3a\\u5bf8\",\"desc\":\"\\u8bbe\\u7f6e\\u9700\\u8981\\u53bb\\u9664\\u7684\\u9ed1\\u8272\\u5b64\\u7acb\\u70b9\\u7684\\u8fde\\u901a\\u4e2a\\u6570\",\"type\":\"int\",\"cur\":30,\"default\":30,\"size\":4,\"range\":{\"min\":10,\"max\":50},\"depend_or\":[\"18==true\"]},\"20\":{\"category\":\"base\",\"name\":\"paper\",\"title\":\"\\u7eb8\\u5f20\\u5c3a\\u5bf8\",\"desc\":\"\\u8bbe\\u7f6e\\u51fa\\u56fe\\u5927\\u5c0f\",\"type\":\"string\",\"cur\":\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"default\":\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"size\":48,\"range\":[\"A3\",\"8\\u5f00\",\"A4\",\"A4\\u6a2a\\u5411\",\"16\\u5f00\",\"16\\u5f00\\u6a2a\\u5411\",\"A5\",\"A5\\u6a2a\\u5411\",\"A6\",\"A6\\u6a2a\\u5411\",\"B4\",\"B5\",\"B5\\u6a2a\\u5411\",\"B6\",\"B6\\u6a2a\\u5411\",\"Letter\",\"Letter\\u6a2a\\u5411\",\"Double Letter\",\"LEGAL\",\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\",\"\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\",\"\\u4e09\\u8054\\u8bd5\\u5377\"]},\"21\":{\"category\":\"base\",\"name\":\"is-custom-area\",\"title\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"20!=\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"20!=\\u4e09\\u8054\\u8bd5\\u5377\",\"20!=\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\",\"20!=\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\"]},\"22\":{\"category\":\"base\",\"name\":\"tl-x\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u5de6\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u5de6\\u4e0a\\u89d2x\\u5750\\u6807\",\"type\":\"float\",\"cur\":0.000000,\"default\":0.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":210.000000},\"depend_and\":[\"21==true\"]},\"23\":{\"category\":\"base\",\"name\":\"br-x\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u53f3\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u53f3\\u4e0b\\u89d2x\\u5750\\u6807\",\"type\":\"float\",\"cur\":210.000000,\"default\":210.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":210.000000},\"depend_and\":[\"21==true\"]},\"24\":{\"category\":\"base\",\"name\":\"tl-y\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u4e0a\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u5de6\\u4e0a\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":0.000000,\"default\":0.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000},\"depend_and\":[\"21==true\"]},\"25\":{\"category\":\"base\",\"name\":\"br-y\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u4e0b\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u53f3\\u4e0b\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":297.000000,\"default\":297.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000},\"depend_and\":[\"21==true\"]},\"26\":{\"category\":\"base\",\"name\":\"is-size-check\",\"title\":\"\\u5c3a\\u5bf8\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u7eb8\\u5f20\\u5b9e\\u9645\\u5c3a\\u5bf8\\u4e0e\\u8bbe\\u7f6e\\u662f\\u5426\\u5339\\u914d\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"20==A3\",\"20==A4\",\"20==A4\\u6a2a\\u5411\",\"20==A5\",\"20==A5\\u6a2a\\u5411\",\"20==A6\",\"20==A6\\u6a2a\\u5411\",\"20==B4\",\"20==B5\",\"20==B5\\u6a2a\\u5411\",\"20==B6\",\"20==B6\\u6a2a\\u5411\",\"20==Double Letter\",\"20==LEGAL\",\"20==Letter\",\"20==Letter\\u6a2a\\u5411\"]},\"27\":{\"category\":\"base\",\"name\":\"page\",\"title\":\"\\u626b\\u63cf\\u9875\\u9762\",\"desc\":\"\\u8bbe\\u7f6e\\u9875\\u9762\\u626b\\u63cf\\u65b9\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u53cc\\u9762\",\"default\":\"\\u53cc\\u9762\",\"size\":40,\"range\":[\"\\u5355\\u9762\",\"\\u53cc\\u9762\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"\\u5bf9\\u6298\"]},\"28\":{\"category\":\"base\",\"name\":\"blank-sensitivity\",\"title\":\" \\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\u7075\\u654f\\u5ea6\",\"desc\":\"\\u6570\\u503c\\u8d8a\\u5927\\uff0c\\u5219\\u8d8a\\u5bb9\\u6613\\u8df3\\u8fc7\",\"type\":\"int\",\"cur\":50,\"default\":50,\"size\":4,\"range\":{\"min\":1,\"max\":100},\"depend_or\":[\"27==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"27==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\"]},\"29\":{\"category\":\"base\",\"name\":\"cfg-29\",\"title\":\"\\u5bf9\\u6298\\u6a21\\u5f0f\",\"desc\":\"\",\"type\":\"string\",\"cur\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"default\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"size\":50,\"range\":[\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"\\u4e0a\\u4e0b\\u5bf9\\u6298\",\"\\u81ea\\u52a8\\u5bf9\\u6298\"],\"depend_or\":[\"27==\\u5bf9\\u6298\"]},\"30\":{\"category\":\"base\",\"name\":\"resolution\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":{\"min\":1,\"max\":600}},\"31\":{\"category\":\"base\",\"name\":\"image-quality\",\"title\":\"\\u753b\\u8d28\",\"desc\":\"\\u9009\\u62e9\\u626b\\u63cf\\u4eea\\u7684\\u753b\\u8d28\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u901f\\u5ea6\\u4f18\\u5148\",\"default\":\"\\u901f\\u5ea6\\u4f18\\u5148\",\"size\":24,\"range\":[\"\\u901f\\u5ea6\\u4f18\\u5148\",\"\\u753b\\u8d28\\u4f18\\u5148\"],\"depend_or\":[\"30>=300\"]},\"32\":{\"category\":\"base\",\"name\":\"is-exchange\",\"title\":\"\\u4ea4\\u6362\\u6b63\\u53cd\\u9762\",\"desc\":\"\\u4ea4\\u6362\\u6bcf\\u5f20\\u6587\\u7a3f\\u7684\\u6b63\\u53cd\\u9762\\u51fa\\u56fe\\u987a\\u5e8f\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"27!=\\u5355\\u9762\"]},\"33\":{\"category\":\"base\",\"name\":\"grp-2\",\"title\":\"\\u4eae\\u5ea6\",\"type\":\"group\"},\"34\":{\"category\":\"base\",\"name\":\"is-custom-gamma\",\"title\":\"\\u542f\\u7528\\u8272\\u8c03\\u66f2\\u7ebf\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u56fe\\u50cf\\u8272\\u8c03\\u6548\\u679c\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"35\":{\"category\":\"base\",\"name\":\"brightness\",\"title\":\"\\u4eae\\u5ea6\\u503c\",\"desc\":\"\\u8c03\\u6574\\u56fe\\u50cf\\u4eae\\u5ea6\",\"type\":\"int\",\"cur\":128,\"default\":128,\"size\":4,\"range\":{\"min\":1,\"max\":255},\"depend_and\":[\"34==false\"]},\"36\":{\"category\":\"base\",\"name\":\"contrast\",\"title\":\"\\u5bf9\\u6bd4\\u5ea6\",\"desc\":\"\\u8c03\\u6574\\u56fe\\u50cf\\u5bf9\\u6bd4\\u5ea6\",\"type\":\"int\",\"cur\":4,\"default\":4,\"size\":4,\"range\":{\"min\":1,\"max\":7},\"depend_and\":[\"34==false\"]},\"37\":{\"category\":\"base\",\"name\":\"gamma\",\"title\":\"\\u4f3d\\u9a6c\\u503c\",\"desc\":\"\\u8c03\\u6574\\u56fe\\u50cf\\u4f3d\\u739b\\u503c\",\"type\":\"float\",\"cur\":1.000000,\"default\":1.000000,\"size\":4,\"range\":{\"min\":0.010000,\"max\":5.000000},\"depend_and\":[\"34==false\"]},\"38\":{\"category\":\"base\",\"name\":\"grp-3\",\"title\":\"\\u56fe\\u50cf\\u5904\\u7406\",\"type\":\"group\"},\"39\":{\"category\":\"base\",\"name\":\"is-anti-skew\",\"title\":\"\\u81ea\\u52a8\\u7ea0\\u504f\",\"desc\":\"\\u81ea\\u52a8\\u7ea0\\u6b63\\u6b6a\\u659c\\u9001\\u5165\\u7684\\u6587\\u7a3f\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":true,\"default\":true,\"size\":4,\"depend_or\":[\"27!=\\u5bf9\\u6298\"]},\"40\":{\"category\":\"base\",\"name\":\"is-split\",\"title\":\"\\u56fe\\u50cf\\u62c6\\u5206\",\"desc\":\"\\u81ea\\u52a8\\u62c6\\u5206\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"27!=\\u5bf9\\u6298\",\"27!=\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"27!=\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\"]},\"41\":{\"category\":\"base\",\"name\":\"is-photo-mode\",\"title\":\"\\u7167\\u7247\\u6a21\\u5f0f\",\"desc\":\"\\u542f\\u7528\\u");
static std::string jsontext2("8be5\\u6a21\\u5f0f\\u53ef\\u4fdd\\u7559\\u56fe\\u50cf\\u539f\\u59cb\\u7ec6\\u8282\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"42\":{\"category\":\"base\",\"name\":\"is-erase-black-frame\",\"title\":\"\\u6d88\\u9664\\u9ed1\\u6846\",\"desc\":\"\\u6d88\\u9664\\u6587\\u7a3f\\u8303\\u56f4\\u5916\\u7684\\u9ed1\\u8272\\u80cc\\u666f\",\"type\":\"bool\",\"cur\":true,\"default\":true,\"size\":4},\"43\":{\"category\":\"advanced\",\"name\":\"bkg-fill-mode\",\"title\":\"\\u80cc\\u666f\\u586b\\u5145\\u65b9\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u80cc\\u666f\\u586b\\u5145\\u65b9\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u51f8\\u591a\\u8fb9\\u5f62\",\"default\":\"\\u51f8\\u591a\\u8fb9\\u5f62\",\"size\":40,\"range\":[\"\\u51f8\\u591a\\u8fb9\\u5f62\",\"\\u51f9\\u591a\\u8fb9\\u5f62\"],\"depend_or\":[\"42==true\"]},\"44\":{\"category\":\"base\",\"name\":\"is-fill-color\",\"title\":\"\\u8272\\u5f69\\u586b\\u5145\",\"desc\":\"\\u542f\\u7528\\u540e\\u9ed1\\u6846\\u90e8\\u5206\\u5c06\\u586b\\u5145\\u4e3a\\u6587\\u7a3f\\u5e95\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"42==true\"]},\"45\":{\"category\":\"advanced\",\"name\":\"threshold\",\"title\":\"\\u9608\\u503c\",\"desc\":\"\\u6587\\u7a3f\\u5e95\\u8272\\u4e0e\\u9ed1\\u8272\\u80cc\\u666f\\u7070\\u5ea6\\u503c\\u7684\\u5dee\\u503c\\u5927\\u4e8e\\u8be5\\u503c\\uff0c\\u624d\\u4f1a\\u88ab\\u8bc6\\u522b\\u4e3a\\u6587\\u7a3f\",\"type\":\"int\",\"cur\":40,\"default\":40,\"size\":4,\"range\":{\"min\":30,\"max\":50},\"depend_or\":[\"42==true\",\"20==\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\",\"39==true\"]},\"46\":{\"category\":\"advanced\",\"name\":\"anti-noise-level\",\"title\":\"\\u80cc\\u666f\\u6297\\u566a\\u7b49\\u7ea7\",\"desc\":\"\\u80fd\\u591f\\u5bb9\\u5fcd\\u7684\\u80cc\\u666f\\u6742\\u8272\\u6761\\u7eb9\\u7684\\u5bbd\\u5ea6\",\"type\":\"int\",\"cur\":8,\"default\":8,\"size\":4,\"range\":{\"min\":1,\"max\":20},\"depend_or\":[\"42==true\",\"20==\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\",\"39==true\"]},\"47\":{\"category\":\"advanced\",\"name\":\"margin\",\"title\":\"\\u8fb9\\u7f18\\u7f29\\u8fdb\",\"desc\":\"\\u5bfb\\u627e\\u6587\\u7a3f\\u8fb9\\u7f18\\u65f6\\u5bf9\\u8fb9\\u7f18\\u7684\\u4fb5\\u5165\\u7a0b\\u5ea6\",\"type\":\"int\",\"cur\":5,\"default\":5,\"size\":4,\"range\":{\"min\":5,\"max\":30},\"depend_or\":[\"42==true\",\"20==\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\",\"39==true\",\"20==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\"]},\"48\":{\"category\":\"base\",\"name\":\"is-dark-sample\",\"title\":\"\\u6df1\\u8272\\u6837\\u5f20\",\"desc\":\"\\u542f\\u7528\\u8be5\\u6a21\\u5f0f\\u9632\\u6b62\\u6df1\\u8272\\u5e95\\u8272\\u7684\\u6587\\u7a3f\\u56fe\\u50cf\\u88ab\\u8bef\\u5904\\u7406\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"27!=\\u5bf9\\u6298\",\"42!=true\",\"20!=\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"20!=\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\",\"20!=\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\",\"39!=true\"]},\"49\":{\"category\":\"base\",\"name\":\"is-anti-permeate\",\"title\":\"\\u9632\\u6b62\\u6e17\\u900f\",\"desc\":\"\\u9632\\u6b62\\u80cc\\u9762\\u56fe\\u6848\\u6e17\\u900f\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"50\":{\"category\":\"base\",\"name\":\"permeate-level\",\"title\":\" \\u9632\\u6b62\\u6e17\\u900f\\u7b49\\u7ea7\",\"desc\":\"\\u9009\\u62e9\\u9632\\u6b62\\u6e17\\u900f\\u7684\\u7b49\\u7ea7\",\"type\":\"string\",\"cur\":\"\\u8f83\\u5f31\",\"default\":\"\\u8f83\\u5f31\",\"size\":16,\"range\":[\"\\u5f31\",\"\\u8f83\\u5f31\",\"\\u4e00\\u822c\",\"\\u8f83\\u5f3a\",\"\\u5f3a\"],\"depend_or\":[\"49==true\"]},\"51\":{\"category\":\"base\",\"name\":\"is-rid-hole-l\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u5de6\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u5de6\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"52\":{\"category\":\"base\",\"name\":\"search-hole-range-l\",\"title\":\" \\u5de6\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000},\"depend_and\":[\"51==true\"]},\"53\":{\"category\":\"base\",\"name\":\"is-rid-hole-r\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u53f3\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u53f3\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"54\":{\"category\":\"base\",\"name\":\"search-hole-range-r\",\"title\":\" \\u53f3\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000},\"depend_and\":[\"53==true\"]},\"55\":{\"category\":\"base\",\"name\":\"is-rid-hole-t\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0a\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0a\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"56\":{\"category\":\"base\",\"name\":\"search-hole-range-t\",\"title\":\" \\u4e0a\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000},\"depend_and\":[\"55==true\"]},\"57\":{\"category\":\"base\",\"name\":\"is-rid-hole-b\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0b\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0b\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"58\":{\"category\":\"base\",\"name\":\"search-hole-range-b\",\"title\":\" \\u4e0b\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000},\"depend_and\":[\"57==true\"]},\"59\":{\"category\":\"base\",\"name\":\"grp-4\",\"title\":\"\\u9001\\u7eb8\\u65b9\\u5f0f\\u8bbe\\u7f6e\",\"type\":\"group\"},\"60\":{\"category\":\"base\",\"name\":\"is-wait-scan\",\"title\":\"\\u5f85\\u7eb8\\u626b\\u63cf\",\"desc\":\"\\u542f\\u7528\\u540e\\uff0c\\u6587\\u7a3f\\u653e\\u5165\\u626b\\u63cf\\u4eea\\u65f6\\u5c06\\u81ea\\u52a8\\u542f\\u52a8\\u626b\\u63cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"61\":{\"category\":\"base\",\"name\":\"scan-mode\",\"title\":\"\\u626b\\u63cf\\u5f20\\u6570\",\"desc\":\"\\u9009\\u62e9\\u6307\\u5b9a\\u6570\\u91cf\\u626b\\u63cf\\u6216\\u8fde\\u7eed\\u626b\\u63cf\",\"type\":\"string\",\"cur\":\"\\u8fde\\u7eed\\u626b\\u63cf\",\"default\":\"\\u8fde\\u7eed\\u626b\\u63cf\",\"size\":32,\"range\":[\"\\u8fde\\u7eed\\u626b\\u63cf\",\"\\u626b\\u63cf\\u6307\\u5b9a\\u5f20\\u6570\"]},\"62\":{\"category\":\"base\",\"name\":\"scan-count\",\"title\":\" \\u626b\\u63cf\\u6570\\u91cf\",\"desc\":\"\\u626b\\u63cf\\u6307\\u5b9a\\u6570\\u91cf\",\"type\":\"int\",\"cur\":1,\"default\":1,\"size\":4,\"depend_or\":[\"61==\\u626b\\u63cf\\u6307\\u5b9a\\u5f20\\u6570\"]},\"63\":{\"category\":\"base\",\"name\":\"direction\",\"title\":\"\\u6587\\u7a3f\\u65b9\\u5411\",\"desc\":\"\\u8bbe\\u7f6e\\u56fe\\u50cf\\u7684\\u65b9\\u5411\",\"type\":\"string\",\"cur\":\"0\\u00b0\",\"default\":\"0\\u00b0\",\"size\":40,\"range\":[\"0\\u00b0\",\"90\\u00b0\",\"180\\u00b0\",\"-90\\u00b0\",\"\\u81ea\\u52a8\\u6587\\u672c\\u65b9\\u5411\\u8bc6\\u522b\\u00b0\"]},\"64\":{\"category\":\"base\",\"name\":\"is-rotate-bkg-180\",\"title\":\"\\u80cc\\u9762\\u65cb\\u8f6c180\\u00b0\",\"desc\":\"\\u80cc\\u9762\\u626b\\u63cf\\u7684\\u56fe\\u50cf\\u65cb\\u8f6c180\\u00b0\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"27!=\\u5355\\u9762\",\"27!=\\u5bf9\\u6298\",\"63!=\\u81ea\\u52a8\\u6587\\u672c\\u65b9\\u5411\\u8bc6\\u522b\\u00b0\"]},\"65\":{\"category\":\"base\",\"name\":\"is-ultrosonic\",\"title\":\"\\u8d85\\u58f0\\u6ce2\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u51fa\\u73b0\\u53cc\\u5f20\\u9001\\u5165\",\"type\":\"bool\",\"cur\":true,\"default\":true,\"size\":4},\"66\":{\"category\":\"base\",\"name\":\"double-feed\",\"title\":\"\\u53cc\\u5f20\\u56fe\\u7247\\u5904\\u7406\",\"desc\":\"\\u68c0\\u6d4b\\u5230\\u53cc\\u5f20\\u8fdb\\u7eb8\\u540e\\u7684\\u5904\\u7406\\u65b9\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u4e22\\u5f03\\u56fe\\u50cf\\u5e76\\u505c\\u6b62\\u626b\\u63cf\",\"default\":\"\\u4e22\\u5f03\\u56fe\\u50cf\\u5e76\\u505c\\u6b62\\u626b\\u63cf\",\"size\":40,\"range\":[\"\\u4e22\\u5f03\\u56fe\\u50cf\\u5e76\\u505c\\u6b62\\u626b\\u63cf\",\"\\u4e0a\\u4f20\\u56fe\\u50cf\\u5e76\\u505c\\u6b62\\u626b\\u63cf\"],\"depend_or\":[\"65==true\"]},\"67\":{\"category\":\"base\",\"name\":\"is-staple\",\"title\":\"\\u88c5\\u8ba2\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u51fa\\u73b0\\u7c98\\u8fde\\u9001\\u5165\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"68\":{\"category\":\"base\",\"name\":\"is-check-askew\",\"title\":\"\\u6b6a\\u659c\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u51fa\\u73b0\\u6b6a\\u659c\\u9001\\u5165\",\"type\":\"bool\",\"cur\":true,\"default\":true,\"size\":4},\"69\":{\"category\":\"base\",\"name\":\"askew-range\",\"title\":\"\\u6b6a\\u659c\\u5bb9\\u5fcd\\u5ea6\",\"desc\":\"\\u503c\\u8d8a\\u5c0f\\uff0c\\u80fd\\u5bb9\\u5fcd\\u5f97\\u9001\\u5165\\u6587\\u7a3f\\u6b6a\\u659c\\u89d2\\u5ea6\\u8d8a\\u5c0f\",\"type\":\"int\",\"cur\":3,\"default\":3,\"size\":4,\"range\":{\"min\":1,\"max\":5},\"depend_or\":[\"68==true\"]},\"70\":{\"category\":\"base\",\"name\":\"is-check-dog-ear\",\"title\":\"\\u6298\\u89d2\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u6587\\u7a3f\\u662f\\u5426\\u5b58\\u5728\\u6298\\u89d2\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"71\":{\"category\":\"base\",\"name\":\"dog-ear-size\",\"title\":\" \\u6298\\u89d2\\u5927\\u5c0f\",\"desc\":\"\\u503c\\u8d8a\\u5c0f\\uff0c\\u80fd\\u68c0\\u6d4b\\u5230\\u7684\\u6298\\u89d2\\u8d8a\\u5c0f\",\"type\":\"int\",\"cur\":70,\"default\":70,\"size\":4,\"range\":{\"min\":0,\"max\":100},\"depend_or\":[\"70==true\"]},\"72\":{\"category\":\"base\",\"name\":\"feed-strength\",\"title\":\"\\u5206\\u7eb8\\u5f3a\\u5ea6\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u4eea\\u7684\\u5206\\u7eb8\\u529b\\u5ea6\",\"type\":\"string\",\"cur\":\"\\u5f31\",\"default\":\"\\u5f31\",\"size\":16,\"range\":[\"\\u5f31\",\"\\u4e00\\u822c\",\"\\u5f3a\"]},\"73\":{\"category\":\"base\",\"name\":\"time-to-sleep\",\"title\":\"\\u4f11\\u7720\\u65f6\\u95f4\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u4eea\\u7684\\u4f11\\u7720\\u65f6\\u95f4\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u4f11\\u7720\",\"default\":\"\\u4e0d\\u4f11\\u7720\",\"size\":24,\"range\":[\"\\u4e0d\\u4f11\\u7720\",\"\\u4e94\\u5206\\u949f\",\"\\u5341\\u5206\\u949f\",\"\\u534a\\u5c0f\\u65f6\",\"\\u4e00\\u5c0f\\u65f6\",\"\\u4e24\\u5c0f\\u65f6\",\"\\u56db\\u5c0f\\u65f6\"]},\"74\":{\"category\":\"base\",\"name\":\"is-auto-strength\",\"title\":\"\\u81ea\\u52a8\\u5206\\u7eb8\\u5f3a\\u5ea6\",\"desc\":\"\\u626b\\u63cf\\u4eea\\u81ea\\u52a8\\u4fee\\u6b63\\u5206\\u7eb8\\u529b\\u5ea6\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"75\":{\"category\":\"base\",\"name\":\"feed-strength-value\",\"title\":\" \\u8fdb\\u7eb8\\u5931\\u8d25\\u7387\",\"desc\":\"\\u9ad8\\u4e8e\\u8be5\\u503c\\u65f6\\u626b\\u63cf\\u4eea\\u5c06\\u8c03\\u6574\\u5206\\u7eb8\\u529b\\u5ea6\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.100000,\"max\":0.900000},\"depend_or\":[\"74==true\"]}}");
enum hg_239_setting_item
{
HG_239_SETTING_RESTORE = 1, // 恢复默认设置
HG_239_SETTING_HELP, // 帮助
HG__239_SETTING_GROUP_1,
HG_239_SETTING_COLOR_MODE, // 颜色模式
HG_239_SETTING_ERASE_COLOR, // 除色
HG_239_SETTING_ERASE_MULTI_RED, // 多流输出除红
HG_239_SETTING_ERASE_ANSWER_RED, // 答题卡除红
HG_239_SETTING_ERASE_BACKGROUND, // 移除背景
HG_239_SETTING_ERASE_BKG_RANGE, // 移除背景范围
HG_239_SETTING_NOISE, // 黑白图像噪点优化
HG_239_SETTING_NOISE_SIZE, // 噪点优化尺寸
HG_239_SETTING_PAPER_SIZE, // 纸张尺寸
HG_239_SETTING_CUSTOM_AREA, // 自定义扫描区域
HG_239_SETTING_CUSTOM_AREA_LEFT, // 扫描区域左侧mm
HG_239_SETTING_CUSTOM_AREA_RIGHT, // 扫描区域右侧mm
HG_239_SETTING_CUSTOM_AREA_TOP, // 扫描区域上侧mm
HG_239_SETTING_CUSTOM_AREA_BOTTOM, // 扫描区域下侧mm
HG_239_SETTING_PAPER_SIZE_CHECK, // 尺寸检测
HG_239_SETTING_PAGE, // 扫描页面
HG_239_SETTING_SKIP_NILL, // 跳过空白页灵敏度
HG_239_SETTING_RESOLUTION, // 分辨率
HG_239_SETTING_IMG_QUALITY, // 画质
HG_239_SETTING_REVERSE, // 交换正反面
HG_239_SETTING_SPLIT, // 图像拆分
HG_239_SETTING_CORRECT, // 自动纠偏
HG_239_SETTING_ERASE_HOLE, // 穿孔移除
HG_239_SETTING_HOLE_SEARCH, // 穿孔搜索范围
HG__239_SETTING_GROUP_2,
HG_239_SETTING_CUSTOM_GAMMA, // 启用色调曲线
HG_239_SETTING_LIGHT, // 亮度
HG_239_SETTING_CONTRAST, // 对比度
HG_239_SETTING_GAMMA, // 伽玛
HG__239_SETTING_GROUP_3,
HG_239_SETTING_SHARP, // 锐化与模糊
HG_239_SETTING_ERASE_BLACK_BORDER, // 消除黑框
HG_239_SETTING_SAMPLE, // 深色样张
HG_239_SETTING_THRESHOLD, // 阈值
HG_239_SETTING_ANTI_NOISE, // 背景抗噪等级
HG_239_SETTING_MARGIN, // 边缘缩进
HG_239_SETTING_FILLING, // 背景填充方式
HG_239_SETTING_PERMEATE, // 防止渗透
HG_239_SETTING_PERMEATE_lv, // 防止渗透等级
HG_239_SETTING_REMOVE_MORR, // 去除摩尔纹
HG_239_SETTING_ERROR_EXTENTION, // 错误扩散
HG_239_SETTING_REMOVE_TXTTURE, // 除网纹
HG__239_SETTING_GROUP_4,
HG_239_SETTING_ULTRASONIC, // 超声波检测
HG_239_SETTING_STAPLE, // 装订检测
HG_239_SETTING_SCAN_METHOD, // 连续扫描或扫描指定张数
HG_239_SETTING_SCAN_COUNT, // 扫描指定数量
HG_239_SETTING_DIRECTION, // 文稿方向 删除文稿自动识别
HG_239_SETTING_ROTATE, // 背面旋转180°
HG_239_SETTING_FRACTATE, // 折角检测
HG_239_SETTING_FRACTATE_COMPLEX, // 折角检测复杂度
HG_239_SETTING_SCREW, // 歪斜检测
HG_239_SETTING_SCREW_COMPLEX, // 歪斜检测复杂度
HG_239_SETTING_END,
//暂时屏蔽
HG_239_SETTING_MULTI_OUT = 500, // 多流输出
};
namespace settings
{
scanner_err device_status_to_hg_err(setting3399::HGEIntInfo* ds)
{
scanner_err code = SCANNER_ERR_OK;
if (ds->From == setting3399::HGType::FPGA)
code = SCANNER_ERR_OK;
else if (ds->From == setting3399::HGType::MtBoard)
{
switch (ds->Code)
{
case 0x00002:
code = SCANNER_ERR_DEVICE_NO_PAPER;
break;
case 0x00004:
code = SCANNER_ERR_DEVICE_COVER_OPENNED;
break;
case 0x00008:
code = SCANNER_ERR_DEVICE_FEEDING_PAPER;
break;
case 0x00010:
code = SCANNER_ERR_DEVICE_PAPER_JAMMED;
break;
case 0x00020:
code = SCANNER_ERR_DEVICE_DOUBLE_FEEDING;
break;
case 0x00040:
code = SCANNER_ERR_DEVICE_STAPLE_ON;
break;
case 0x00080:
code = SCANNER_ERR_DEVICE_PAPER_SKEW;
break;
case 0x10000:
case 0x80000:
code = SCANNER_ERR_TIMEOUT;
break;
case 0x20000:
code = SCANNER_ERR_DEVICE_SIZE_CHECK;
break;
default:
break;
}
}
else if (ds->From == setting3399::HGType::IMG)
{
if (ds->Code == 1)
code = SCANNER_ERR_DEVICE_DOGEAR;
else if (ds->Code == 2)
code = SCANNER_ERR_DEVICE_SIZE_CHECK;
}
else if (ds->From == setting3399::HGType::V4L2)
{
if (ds->Code == 0)
code = SCANNER_ERR_DEVICE_SCANN_ERROR;
else if (ds->Code == 1)
code = SCANNER_ERR_DEVICE_NO_IMAGE;
}
else if (ds->From == setting3399::HGType::STOPSCAN)
code = SCANNER_ERR_DEVICE_STOPPED;
return code;
}
// resolution
static struct
{
float resolution;
int dev_value;
}resolution_map[] =
{
{100.0f, 1},
{150.0f, 1},
{200.0f, 1},
{240.0f, 1},
{300.0f, 0},
{600.0f, 1} //临时版本发1 原来发2
};
bool is_equal(float l, float r)
{
return fabs(l - r) < .000001f;
}
int match_best_resolution(int resolution, bool* exact)
{
int rsl = resolution,
ind = 0;
bool good = true, *r = exact ? exact : &good;
if (rsl <= resolution_map[0].resolution)
{
ind = 0;
}
else if (rsl >= resolution_map[ARRAY_SIZE(resolution_map) - 1].resolution)
{
ind = ARRAY_SIZE(resolution_map) - 1;
}
else
{
for (int i = 1; i < ARRAY_SIZE(resolution_map); ++i)
{
if (is_equal(rsl, resolution_map[i].resolution))
{
ind = i;
break;
}
if (rsl < resolution_map[i].resolution)
{
float dif_l = rsl - resolution_map[i - 1].resolution,
dif_r = resolution_map[i].resolution - rsl;
if (dif_l > dif_r)
ind = i;
else
ind = i - 1;
break;
}
}
}
*r = is_equal(rsl, resolution_map[ind].resolution);
return ind;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class ...
hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_scanner(G20039Serial, dev_name, io)
, rewrite_conf_(false), reset_(false),is_start_status(false)
{
pid_ = pid;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_239(%s) constructing ...\n", hg_log::format_ptr(this).c_str());
dev_conf_.value = 0;
#ifndef MAPPING_FUNCTION_IN_BASE
init_setting_map(setting_map_, ARRAY_SIZE(setting_map_));
#endif
if (init_settings(0x239))
init_settings((jsontext1 + jsontext2).c_str());
writedown_device_configuration(); // initialize the hardware settings
init_version();
}
hg_scanner_239::~hg_scanner_239()
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_239(%s) destroyed.\n", hg_log::format_ptr(this).c_str());
}
int hg_scanner_239::read_register(int addr, int* val)
{
std::lock_guard<std::mutex> lock(io_lock_);
int l = sizeof(*val),
ret = io_->control_io(0x0c0, USB_REQ_GET_DEV_REGS, addr, 0, val, &l);
if (ret)
status_ = ret;
return ret;
}
int hg_scanner_239::write_register(int addr, int val)
{
std::lock_guard<std::mutex> lock(io_lock_);
int l = sizeof(val),
ret = io_->control_io(0x040, USB_REQ_SET_DEV_REGS, addr, 0, &val, &l);
if (ret)
status_ = ret;
return ret;
}
int hg_scanner_239::write_command(int cmd)
{
return write_register(0, cmd);
}
std::string hg_scanner_239::control_fetch(int addr, int val, int size)
{
int l = sizeof(val),
ret = 0;
std::string data("");
ret = write_register(addr, val);
if (ret == SCANNER_ERR_OK)
{
std::lock_guard<std::mutex> lock(io_lock_);
l = size + 1;
data.resize(size + 2);
bzero(&data[0], size + 2);
ret = io_->read_bulk(&data[0], &l);
if (ret || l == 0)
{
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) - read_bulk %d byte(s) = %s\n", addr, val, l, hg_scanner_err_name(ret));
data.clear();
}
}
else
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret));
return data;
}
std::string hg_scanner_239::get_fpga(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_MBVERSION_LENGHT, &val);
std::string fpga("");
if (ret == SCANNER_ERR_OK)
{
fpga.resize(val + 2);
bzero(&fpga[0], val + 2);
return control_fetch(setting3399::SR_GET_MBVERSION, 0, val);
}
return fpga;
}
int hg_scanner_239::clr_roller_num(void)
{
int val = 0,
ret = read_register(setting3399::SR_CLR_ROLLER_NUM, &val);
if (ret == SCANNER_ERR_OK)
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "clr_roller_num = %s\n", hg_scanner_err_name(ret));
return -1;
}
}
int hg_scanner_239::get_sleep_time(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_SLEEPTIME, &val);
if (ret == SCANNER_ERR_OK)
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %s\n", hg_scanner_err_name(ret));
return -1;
}
}
int hg_scanner_239::get_scan_mode(void)
{
int val = 0,
ret = read_register(setting3399::SR_OS, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get scan mode error: %s\n", hg_scanner_err_name(ret));
status_ = ret;
return -1;
}
else
return val;
}
int hg_scanner_239::get_status(void)
{
int val = 0,
ret = read_register(setting3399::SR_STATUS, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get status error: %s\n", hg_scanner_err_name(ret));
status_ = ret;
return -1;
}
else
return val;
}
bool hg_scanner_239::is_dev_tx(void)
{
int val = 0,
ret = read_register(setting3399::SR_STATUS, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_tx() error: %s\n", hg_scanner_err_name(ret));
status_ = ret;
return false;
}
else
return val;
}
bool hg_scanner_239::is_dev_image_process_done(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_IMAGEPROCESSDONE, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret));
status_ = ret;
return true;
}
else
return val;
}
bool hg_scanner_239::is_dev_image_keep_last_paper(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_KEEP_LAST_PAPER, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret));
status_ = ret;
return true;
}
else
return val;
}
int hg_scanner_239::get_scanned_count(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_SCANN_NUM, &val);
if (ret == SCANNER_ERR_OK)
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scanned_count = %s\n", hg_scanner_err_name(ret));
return -1;
}
}
int hg_scanner_239::get_image_count(void)
{
int val = 0,
ret = read_register(setting3399::SR_IM_COUNT, &val);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_image_count() = %d, error: %s\n", val, hg_scanner_err_name(ret));
if (ret == SCANNER_ERR_OK)
return val;
else
return -1;
}
int hg_scanner_239::get_front_data_size(void)
{
int val = 0,
ret = read_register(setting3399::SR_IM_FRONT_SIZE, &val);
if (ret == SCANNER_ERR_OK)
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_front_data_size = %s\n", hg_scanner_err_name(ret));
return -1;
}
}
void hg_scanner_239::init_version(void)
{
std::string fv(get_firmware_version()),
sn(get_serial_num());
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware version: %s\n", fv.c_str());
if (fv.length() >= 10 && (fv[5] > 'A' || atoi(fv.substr(6, 4).c_str()) >= 1209))
{
is_kernelsnap_211209_ = atoi(get_fpga().c_str()) >= 35211210;
}
else if (fv.length() >= 10 && (fv[5] > 'B' || atoi(fv.substr(6, 4).c_str()) >= 830))
{
is_kernelsnap_220830_ = true;
}
else
{
is_kernelsnap_211209_ = false;
is_kernelsnap_220830_ = false;
}
}
int hg_scanner_239::get_device_sleep_stautus()
{
int val = 0,
ret = 0;
ret = read_register(setting3399::SR_GET_SLEEP_STAUTUS,&val);
return val;
}
int hg_scanner_239::get_device_paperon_stautus(void)
{
int ret =read_register(setting3399::SR_GET_PAPERON,0);
return ret;
}
int hg_scanner_239::writedown_device_configuration(setting_hardware::HGSCANCONF_3399 *dev_conf)
{
int ret = SCANNER_ERR_OK;
if (!dev_conf)
{
dev_conf = &dev_conf_;
}
if (image_prc_param_.bits.rid_color != RID_COLOR_NONE
&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE))
{
dev_conf->params_3399.color = 1;
}
else if (image_prc_param_.bits.rid_color == RID_COLOR_NONE
&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE))
{
dev_conf->params_3399.color = 0;
}
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
|| image_prc_param_.bits.paper == PAPER_TRIGEMINY
|| image_prc_param_.bits.paper == PAPER_16K
|| image_prc_param_.bits.paper == PAPER_8K
|| image_prc_param_.bits.paper == PAPER_16K_LATERAL
)
{
dev_conf->params_3399.enable_sizecheck = false;
}
ret = write_register(setting3399::SR_CONFIG_SCAN_PARAM, dev_conf->value);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Writedown scanner configuration(0x%x) = %s\n", dev_conf->value, hg_scanner_err_name(ret));
return ret;
}
int hg_scanner_239::writedown_image_configuration(void)
{
int ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF));
if (ret != SCANNER_ERR_OK)
return ret;
SCANCONF ic;
int len = sizeof(ic);
bzero(&ic, len);
ic.papertype = paper_size_;
if (is_lateral(image_prc_param_.bits.paper))
ic.paperAlign = Rot270;
else
ic.paperAlign = Rot0;
ic.en_sizecheck = dev_conf_.params_3399.enable_sizecheck;
if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO)
ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction;
else
ic.imageRotateDegree = 0;
ic.imageRotateDegree *= 90.0f;
ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT
|| image_prc_param_.bits.page ==PAGE_FOLIO);
ic.en_fold = (image_prc_param_.bits.page == PAGE_FOLIO);
ic.pixtype = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode;
ic.automaticcolor = is_auto_matic_color;
ic.automaticcolortype = 1;// ic.pixtype; //存疑
if (resolution_ >= 300)
{
if(is_quality_ == IMG_SPEED)
{
ic.resolution_dst = 200;
}
else if(is_quality_ ==IMG_QUALITY)
{
ic.resolution_dst = resolution_;
}
}
else
{
ic.resolution_dst = resolution_;
}
ic.resolution_native = 200.0f;
ic.gamma = (float)gamma_;
ic.contrast = (contrast_ - 4) * 333.0;
ic.brightness = (bright_ - 128) * (2000.0 / 254.0);
ic.threshold = threshold_;
ic.is_autocontrast = 0; //无参数
ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype ==TwSS::USStatement);
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY;
ic.discardblank_percent = omit_empty_level_ >= 70 ? 70 : omit_empty_level_;
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
ic.is_switchfrontback = image_prc_param_.bits.exchange;
ic.autodescrew = image_prc_param_.bits.automatic_skew;
//ic.multi_output_red = image_prc_param_.bits.rid_red; //必须屏蔽,否则超时,未知错误不可描述。
ic.hsvcorrect = image_prc_param_.bits.rid_answer_red;
ic.sharpen = image_prc_param_.bits.sharpen;
//ic.enhance_color = image_prc_param_.bits.rid_color; //加这个会有问题
ic.fillbackground = image_prc_param_.bits.erase_black_frame;
ic.is_convex = (image_prc_param_.bits.fill_background == FILL_BKG_CONVEX_POLYGON);
if (ic.resolution_dst == 300)
ic.noise = anti_noise_ * 1.5;
else if(ic.resolution_dst == 600)
ic.noise = anti_noise_ * 3;
else
ic.noise = anti_noise_;
ic.indent = margin_;
ic.AutoCrop_threshold = threshold_;
if (test_1_paper_)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n");
ic.scannum = ic.is_duplex ? 2 : 1;
}
else
{
if (scan_count_ == -1)
ic.scannum = -1;
else
ic.scannum = (ic.is_duplex ? scan_count_ * 2 : scan_count_);
}
ic.is_backrotate180 = image_prc_param_.bits.rotate_back_180;
ic.is_dogeardetection = image_prc_param_.bits.fractate_check;
ic.hardwarecaps.en_skrewdetect = dev_conf_.params_3399.screw_detect_enable;
ic.hardwarecaps.en_doublefeed = dev_conf_.params_3399.ultrasonic_enable;
ic.hardwarecaps.en_stapledetect = dev_conf_.params_3399.staple_enbale;
ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
// ic.hardwarecaps.is_autopaper = dev_conf_.params_3399.is_autopaper;
ic.hardwarecaps.capturepixtype = 0; //暂无参数 获取图像类型
ic.hardwarecaps.lowpowermode = LowPowerMode::Min_None; //暂无参数 设置休眠时间 两个参数3399未使用
ic.fillhole.is_fillhole = image_prc_param_.bits.rid_hole;
ic.fillhole.fillholeratio = rid_hole_range_;
ic.detachnoise.is_detachnoise = image_prc_param_.bits.noise_optimize;
ic.detachnoise.detachnoise = noise_range_;
ic.is_autotext = image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO ? 1 :0;
ic.isfillcolor = is_color_fill;
ic.refuseInflow = image_prc_param_.bits.is_permeate;
ic.colorCorrection = 0;
ic.removeMorr = image_prc_param_.bits.remove_morr;
ic.errorExtention = image_prc_param_.bits.error_extention ;//
ic.textureRemove = image_prc_param_.bits.remove_txtture;//
ic.splitImage = image_prc_param_.bits.split;
{
ic.cropRect.enable = custom_area_;
int height = (custom_area_br_y_ *ic.resolution_dst) /25.4 - (custom_area_lt_y_ *ic.resolution_dst /25.4);
int width = (custom_area_br_x_ *ic.resolution_dst) /25.4 - (custom_area_lt_x_ *ic.resolution_dst /25.4);
ic.cropRect.height = height;
ic.cropRect.width = width;
ic.cropRect.x = custom_area_lt_x_ *ic.resolution_dst /25.4;
ic.cropRect.y = custom_area_lt_y_ *ic.resolution_dst /25.4;
}
ic.multiOutput = (MultiOutput)image_prc_param_.bits.multi_out;
ic.normalCrop = image_prc_param_.bits.dark_sample;
ic.dogeardistabce = fractate_level_;
ic.fadeback = image_prc_param_.bits.erase_bakground;
ic.fadebackrange = erase_bkg_range_;
ic.isuoloadexceptionimage = (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) == DOUBLE_PAPER_SAVE_IMG;
adjust_filling_hole(&ic);
ic.fold_concatmode = fold_type_;
int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 };
if(image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH)
ic.filter = 3;
else
{
ic.filter = filter_clr[image_prc_param_.bits.rid_color];
// if(ic.filter != 3)
// ic.pixtype = 2;
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.multiOutput = MultiOutput::Unused;
}
//多留输出的处理
if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW && is_multiout)
{
ic.pixtype = 1;
}
else if ((image_prc_param_.bits.multi_out == MULTI_OUT_ALL ||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_GRAY||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_BW) && is_multiout)
{
ic.pixtype = 2;
}
if (is_multiout)
{
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.fadeback = false;
ic.sharpen = 0;
ic.removeMorr = 0;
ic.textureRemove = 0;
ic.errorExtention = 0;
ic.detachnoise.is_detachnoise = 0;
}
if (ic.pixtype == 0)
{
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.fadeback = false;
ic.sharpen = 0;
ic.removeMorr = 0;
ic.textureRemove = 0;
}
//自定义裁切
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
||image_prc_param_.bits.paper == PAPER_MAX_SIZE
||image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
||image_prc_param_.bits.paper == PAPER_TRIGEMINY
)
{
ic.cropRect.enable = false;
}
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->write_bulk(&ic, &len);
this_thread::sleep_for(chrono::milliseconds(500));
io_->set_timeout(2000);//必要延时
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Write-down 0x%x bytes image process parameters\n", len);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.pixtype=%d", ic.pixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.papertype=%d", ic.papertype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.AutoCrop_threshold=%d", ic.AutoCrop_threshold);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.autodescrew=%d", ic.autodescrew);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.automaticcolor=%d", ic.automaticcolor);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.brightness=%f", ic.brightness);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.contrast=%f", ic.contrast);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.en_fold=%d", ic.en_fold);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.en_sizecheck=%d", ic.en_sizecheck);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.enhance_color=%d", ic.enhance_color);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillbackground=%d", ic.fillbackground);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.filter=%d", ic.filter);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.gamma=%f", ic.gamma);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hardwarecaps.capturepixtype=%d", ic.hardwarecaps.capturepixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hardwarecaps.en_doublefeed=%d", ic.hardwarecaps.en_doublefeed);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hsvcorrect=%d", ic.hsvcorrect);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.imageRotateDegree=%f", ic.imageRotateDegree);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.indent=%d", 5);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autocontrast=%d", ic.is_autocontrast);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autocrop=%d", ic.is_autocrop);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autodiscradblank_normal=%d", ic.is_autodiscradblank_normal);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autodiscradblank_vince=%d", ic.is_autodiscradblank_vince);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autotext=%d", ic.is_autotext);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_backrotate180=%d", ic.is_backrotate180);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_convex=%d", ic.is_convex);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_duplex=%d", ic.is_duplex);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_switchfrontback=%d", ic.is_switchfrontback);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_dogeardetection=%d", ic.is_dogeardetection);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillhole.multi_output_red=%d", ic.multi_output_red);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.noise=%d", ic.noise);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.pixtype=%d", ic.pixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.resolution_dst=%f", ic.resolution_dst);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.resolution_native=%f", ic.resolution_native);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.scannum=%d", ic.scannum);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.sharpen=%d", ic.sharpen);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.discardblank_percent=%d", ic.discardblank_percent);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.is_detachnoise=%d", ic.detachnoise.is_detachnoise);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.detachnoise=%d\r ", ic.detachnoise.detachnoise);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.refuseInflow=%d\r ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.refuseInflow=%d\r ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.removeMorr=%d\r ", ic.removeMorr);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.errorExtention=%d\r ", ic.errorExtention);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.textureRemove=%d\r\n ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillhole.is_fillhole=%d\r\n ", ic.fillhole.is_fillhole);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.ic.fillhole.fillholeratio=%d\r\n ", ic.fillhole.fillholeratio);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fadeback=%d\r\n ",ic.fadeback);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.enable=%d\r ", ic.cropRect.enable);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.width=%d\r\n ", ic.cropRect.width);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.height=%d\r\n ", ic.cropRect.height);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.x=%d\r\n ", ic.cropRect.x);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.y=%d\r\n ",ic.cropRect.y);
img_conf_ = ic;
return ret;
}
int hg_scanner_239::pop_first_image(void)
{
int ret = write_register(setting3399::SR_IM_POP, 1);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "popup first image = %s\n", hg_scanner_err_name(ret));
return ret;
}
int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
{
int r = 0,
total = get_front_data_size(),
off = 0,
ret = SCANNER_ERR_OK;
if (!waiting_for_memory_enough(total))
{
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
return status_;
}
if (total == -1)
ret = status_;
else
{
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
if (!buf.get())
return SCANNER_ERR_INSUFFICIENT_MEMORY;
// write reading command
ret = write_register(setting3399::SR_IM_TX, 1);
buf->set_image_statu(statu);
if (ret == SCANNER_ERR_OK)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
r = total;
{
std::lock_guard<std::mutex> lock(io_lock_);
unsigned int size = r;
void* buff = buf->data(off, &size);
int block = 0;
if (!buff)
{
VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", off, r, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
}
else
{
r = size;
while (r > 0)
{
block = 512 * 1024;
if (r < block)
block = r;
unsigned int size = block;
void* buff = buf->data(off, &size);
if (!buf)
{
//VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
break;
}
block = size;
ret = io_->read_bulk(buff, &block);
if (ret != SCANNER_ERR_OK)
break;
off += block;
r -= block;
}
}
}
if (ret == SCANNER_ERR_OK)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret));
ret = save_usb_data(buf);
if (ret == SCANNER_ERR_OK)
{
pop_first_image();
//if(image_prc_param_.bits.page == PAGE_SINGLE)
// pop_first_image();
}
}
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
}
}
}
return ret;
}
void hg_scanner_239::discard_all_images(void)
{
char buf[64];
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
int size = sizeof(buf),
oto = 0,
pre_img = 0,
pre_int = 0,
ret = SCANNER_ERR_OK;
{
std::lock_guard<std::mutex> lock(io_lock_);
oto = io_->get_timeout();
io_->set_timeout(100);
ret = io_->read_interrupt(buf, &size);
}
while (ret == SCANNER_ERR_OK)
{
pre_int++;
if (info->From == setting3399::IMG)
{
while (get_image_count() > 0)
{
pop_first_image();
pre_img++;
}
}
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
}
}
{
std::lock_guard<std::mutex> lock(io_lock_);
io_->set_timeout(oto);
}
if (pre_int)
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "prev-connection has left %d interrupt packet(s) && %d image(s).\n", pre_int, pre_img);
}
//color_mode =-1 除色选项
int hg_scanner_239::on_color_mode_changed(int& color_mode)
{
int ret = SCANNER_ERR_OK;
if ((((color_mode == COLOR_MODE_24_BITS || color_mode == COLOR_MODE_AUTO_MATCH) && !dev_conf_.params_3399.color) ||
((color_mode != COLOR_MODE_24_BITS && color_mode != COLOR_MODE_AUTO_MATCH) && dev_conf_.params_3399.color)) && color_mode != -1)
{
dev_conf_.params_3399.color ^= 1;
ret = writedown_device_configuration();
if(ret)
dev_conf_.params_3399.color ^= 1;
}
if(color_mode == COLOR_MODE_AUTO_MATCH)
{
dev_conf_.params_3399.color = 1;
}
//setting_hardware::HGSCANCONF_3399 d = dev_conf_;
/*if (image_prc_param_.bits.rid_color != RID_COLOR_NONE
&&(image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
)
{
d.params_3399.color = 1;
ret = writedown_device_configuration(&d);
}*/
//if(image_prc_param_.bits.rid_color != RID_COLOR_NONE
//&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
//&& color_mode == -1)
//{
// d.params_3399.color = 1;
//}
//else if (image_prc_param_.bits.rid_color == RID_COLOR_NONE
//&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
//&& color_mode == -1)
//{
// d.params_3399.color = 0;
//}
//if(color_mode == -1)
//ret = writedown_device_configuration(&d);
return ret;
}
int hg_scanner_239::on_paper_changed(int& paper)
{
bool exact = true;
int ind = hgpaper_to_devspaper(paper_map_3399, ARRAY_SIZE(paper_map_3399),paper, &exact, &paper_size_),
ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT;
if (dev_conf_.params_3399.paper != paper_map_3399[ind].dev_value)
{
int old = dev_conf_.params_3399.paper;
dev_conf_.params_3399.paper = paper_map_3399[ind].dev_value;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.paper = old;
for (int i = 0; i < ARRAY_SIZE(paper_map_3399); ++i)
{
if (paper_map_3399[i].dev_value == old)
{
paper = paper_map_3399[i].paper;
break;
}
}
}
else if (!exact)
ret = SCANNER_ERR_NOT_EXACT;
}
return ret;
}
int hg_scanner_239::on_paper_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
if (dev_conf_.params_3399.enable_sizecheck ^ check)
{
dev_conf_.params_3399.enable_sizecheck = check;
size_check = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.enable_sizecheck = !check;
check = dev_conf_.params_3399.enable_sizecheck;
}
}
//if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
// || image_prc_param_.bits.paper == PAPER_MAX_SIZE
// || image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
// || image_prc_param_.bits.paper == PAPER_TRIGEMINY
// || image_prc_param_.bits.paper == PAPER_16K
// || image_prc_param_.bits.paper == PAPER_8K
// || image_prc_param_.bits.paper == PAPER_16K_LATERAL
// )
//{
// setting_hardware::HGSCANCONF_3399* d = &dev_conf_;
// d->params_3399.enable_sizecheck = false;
// ret = writedown_device_configuration(d);
//}
return ret;
}
int hg_scanner_239::on_resolution_changed(int& dpi)
{
//bool exact = true;
//int ind = settings::match_best_resolution(dpi, &exact),
// ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT;
//if (dev_conf_.params_3399.dpi != settings::resolution_map[ind].dev_value)
//{
// int old = dev_conf_.params_3399.dpi;
// dev_conf_.params_3399.dpi = settings::resolution_map[ind].dev_value;
// dev_conf_.params_3399.dpi = 1;
// ret = writedown_device_configuration();
// if (ret)
// {
// dev_conf_.params_3399.dpi = old;
// }
// else if (!exact)
// ret = SCANNER_ERR_NOT_EXACT;
//}
//
//if (ret == SCANNER_ERR_NOT_EXACT)
// dpi = settings::resolution_map[ind].resolution;
//return ret;
dev_conf_.params_3399.dpi = 1; //dpi 华凌cis和敦南cis 默认发1无需改变
int ret = writedown_device_configuration();
return ret;
}
int hg_scanner_239::on_ultrasonic_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
if (dev_conf_.params_3399.ultrasonic_enable ^ check)
{
dev_conf_.params_3399.ultrasonic_enable = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.ultrasonic_enable = !check;
check = dev_conf_.params_3399.ultrasonic_enable;
}
}
return ret;
}
int hg_scanner_239::on_staple_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
if (dev_conf_.params_3399.staple_enbale ^ check)
{
dev_conf_.params_3399.staple_enbale = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.staple_enbale = !check;
check = dev_conf_.params_3399.staple_enbale;
}
}
return ret;
}
int hg_scanner_239::on_skew_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
if (dev_conf_.params_3399.screw_detect_enable ^ check)
{
dev_conf_.params_3399.screw_detect_enable = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.screw_detect_enable = !check;
check = dev_conf_.params_3399.screw_detect_enable;
}
}
return ret;
}
int hg_scanner_239::on_skew_check_level_changed(int& check)
{
int ret = SCANNER_ERR_OK,
val = check,
old = dev_conf_.params_3399.screw_detect_level;
setting_hardware::HGSCANCONF_3399 cf;
cf.params_3399.screw_detect_level = -1;
if (val < 0)
{
val = 0;
ret = SCANNER_ERR_NOT_EXACT;
}
else if (val > cf.params_3399.screw_detect_level)
{
val = cf.params_3399.screw_detect_level;
ret = SCANNER_ERR_NOT_EXACT;
}
if (val != dev_conf_.params_3399.screw_detect_level)
{
dev_conf_.params_3399.screw_detect_level = val;
ret = writedown_device_configuration();
if (ret)
check = dev_conf_.params_3399.screw_detect_level = old;
}
if (ret == SCANNER_ERR_OK && val != check)
{
check = val;
ret = SCANNER_ERR_NOT_EXACT;
}
return ret;
}
int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度
{
int ret = SCANNER_ERR_OK,
val = 0;
ret = read_register(setting3399::SR_GET_FEEDMODE,&feedmode);
if (ret == SCANNER_ERR_OK)
{
save_feedmode_type_ = true;
}
return ret;
}
int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度
{
int ret = SCANNER_ERR_OK,
val = 0;
ret = write_register(setting3399::SR_SET_FEEDMODE,feedmode);
return ret;
}
int hg_scanner_239::on_pic_type(bool& pic)
{
dev_conf_.params_3399.is_textcorrect = pic;
int ret = writedown_device_configuration();
return ret;
}
int hg_scanner_239::on_pick_paper(bool autostrength)
{
int val = 0,
ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE, autostrength);
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_AUTOMATICCONTROLFEEDMODE_ENABLE,&val);
return ret;
}
int hg_scanner_239::on_pick_paper_threshold(double threshold)
{
threshold *= 10;
int val = 0,
ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_THRESHOLD, threshold);
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_AUTOMATICCONTROLFEEDMODE_THRESHOLD,&val);
return ret;
}
int hg_scanner_239::on_is_auto_paper(bool isautopaper)
{
int val = 0,
ret = SCANNER_ERR_OK;
if (is_kernelsnap_220830_)
{
dev_conf_.params_3399.is_autopaper = isautopaper;
ret = writedown_device_configuration();
if (isautopaper)
notify_ui_working_status("\345\276\205\347\272\270\346\211\253\346\217\217\347\212\266\346\200\201\344\270\255...", SANE_EVENT_WORKING, status_);
}
else
{
ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
return ret;
}
void hg_scanner_239::on_device_reconnected(void)
{
int ret = writedown_device_configuration();
init_version();
rewrite_conf_ = ret != SCANNER_ERR_OK;
if (reset_)
{
reset_ = false;
start();
}
}
int hg_scanner_239::on_scanner_closing(bool force)
{
return SCANNER_ERR_OK;
}
void hg_scanner_239::thread_handle_usb_read(void)
{
char buf[64];
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
int size = sizeof(buf),
ret = SCANNER_ERR_OK,
to_cnt = 0,
count = 0;
int auoto_paper_indx = 0;
//status_ = SCANNER_ERR_DEVICE_BUSY;
while (run_ )//&& !user_cancel_
{
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
io_->set_timeout(1000);
}
if (ret == SCANNER_ERR_TIMEOUT)
{
if (img_conf_.resolution_dst == 600.0 && ++to_cnt > 50 && !is_auto_paper_scan)
{
status_ = ret;
notify_ui_working_status("\351\200\232\344\277\241\350\266\205\346\227\266", SANE_EVENT_ERROR, ret); // 通信超时
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "600dpi '%s'\n", hg_scanner_err_name(status_));
break;
}
else if (img_conf_.resolution_dst != 600.0 &&++to_cnt > 20 && !is_auto_paper_scan)
{
status_ = ret;
notify_ui_working_status("\351\200\232\344\277\241\350\266\205\346\227\266", SANE_EVENT_ERROR, ret); // 通信超时
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "\345\205\266\344\273\226dpi '%s'\n", hg_scanner_err_name(status_));
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if ((get_status() & 0x03) == 0)
{
status_ = SCANNER_ERR_OK;
//break;
}
if (user_cancel_ && is_auto_paper_scan)
{
size = sizeof(buf);
memset(buf, 0, size);
info->From = setting3399::STOPSCAN;
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "User cancelled (checked when read INT timeout), we faked a 'STOP' messag to enter exiting process ...\n");
}
else
continue;
}
else if (ret != SCANNER_ERR_OK)
{
status_ = ret;
break;
}
to_cnt = 0;
if (size == sizeof(buf))
{
status_ = settings::device_status_to_hg_err(info);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status from interrupt point is '%s'\n", hg_scanner_err_name(status_));
if (status_ != SCANNER_ERR_OK && status_ != SCANNER_ERR_TIMEOUT && status_ != SCANNER_ERR_DEVICE_STOPPED)
{
if (!is_dev_image_process_done() || (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG))
{
int st = status_, count = 0, statu = last_usb_image_statu(st);
while (!is_dev_image_process_done())
std::this_thread::sleep_for(std::chrono::milliseconds(30));
StopWatch delay;
if((double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) &&
st == SCANNER_ERR_DEVICE_DOUBLE_FEEDING)
{
int wait = 3000 + (img_conf_.resolution_dst / 200 * 10000);
while (get_image_count() == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(30));
if (delay.elapsed_ms() > wait)
break;
}
}
while ((count = get_image_count()) > 0)
{
int s = SANE_Image_Statu_OK;
if (count <= 2)
{
if (image_prc_param_.bits.page == PAGE_SINGLE)
s = count == 1 ? statu : s;
else
s = statu;
}
ret = read_one_image_from_usb((SANE_Image_Statu)s);
count++;
if (ret != SCANNER_ERR_OK
&& ret != SCANNER_ERR_CREATE_FILE_FAILED
&& ret != SCANNER_ERR_WRITE_FILE_FAILED)
break;
}
status_ = st;
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "\346\211\253\346\217\217\345\244\261\350\264\245, read interrupt\350\277\224\345\233\236\347\212\266\346\200\201\344\270\272\357\274\232%s\n", hg_scanner_err_description(status_));
break;
}
if (info->From == setting3399::IMG)
{
int s = get_status();
// if (s > 0 && s < 4) // running ...
{
while (get_image_count() > 0)
{
count++;
ret = read_one_image_from_usb();
if (ret != SCANNER_ERR_OK
&& ret != SCANNER_ERR_CREATE_FILE_FAILED
&& ret != SCANNER_ERR_WRITE_FILE_FAILED)
break;
}
}
//else
// VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status(0x%x) is not accept in usb thread\n", status);
}
else if (info->From == setting3399::STOPSCAN)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "received 'STOPSCAN' message in usb thread, check remaining image and finish scanning ...\n");
// fetch all buffered images and exit ...
//while(!is_dev_image_process_done())
if (img_conf_.resolution_dst > 200 && is_quality_ == IMG_QUALITY)
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
else
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
while (get_image_count() > 0)
{
ret = read_one_image_from_usb();
count++;
if (ret != SCANNER_ERR_OK
&& ret != SCANNER_ERR_CREATE_FILE_FAILED
&& ret != SCANNER_ERR_WRITE_FILE_FAILED)
break;
}
if (user_cancel_)
{
if (status_) // thread_handle_image_process maybe call stop() when insufficient memory occurs .
ret = status_;
else
status_ = ret = SCANNER_ERR_USER_CANCELED;
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "用户取消操作 '%s'\n", hg_scanner_err_name(status_));
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "\347\224\250\346\210\267\345\217\226\346\266\210\346\223\215\344\275\234 '%s'\n", hg_scanner_err_name(status_));
auoto_paper_indx = 0;
break;
}
if (count == 0)
{
std::lock_guard<std::mutex> lock(io_lock_);
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "First message received from USB is 'STOPSCAN'\n");
// notify_ui_working_status(STATU_DESC_DEVICE_RESET);
// reset_ = true;
// ret = io_->reset();
// status_ = SCANNER_ERR_IO;
}
else if (status_ == SCANNER_ERR_TIMEOUT || status_ == SCANNER_ERR_IO || status_ == SCANNER_ERR_DEVICE_STOPPED)
status_ = SCANNER_ERR_OK;
int s = get_status();
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status after received 'STOPSCAN': 0x%x\n", s);
if (count || (s & 3) == 0)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n");
//string str = "当前批次扫描完成(第"+to_string(++auoto_paper_indx)+"批)";
string str = "\345\275\223\345\211\215\346\211\271\346\254\241\346\211\253\346\217\217\345\256\214\346\210\220(\347\254\254"+to_string(++auoto_paper_indx)+"\346\211\271)";
if(is_auto_paper_scan)
notify_ui_working_status(str.c_str(), SANE_EVENT_STATUS, status_);
else
break;
}
}
else if (info->From == setting3399::V4L2)
{
VLOG_MINI_2(LOG_LEVEL_WARNING, "V4L2 message received, code = %d, index = %d\n", info->Code, info->Img_Index);
// stop();
break;
}
else
{
// error handling ...
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "Read HGEIntInfo: From = %d, Code = %d, Img_Index = %d, status = %s\n", info->From, info->Code, info->Img_Index, hg_scanner_err_name(status_));
}
}
else
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "read %d bytes, sizeof(buf) = %d\n", size, sizeof(buf));
this_thread::sleep_for(chrono::milliseconds(10));
}
if (status_ == SCANNER_ERR_DEVICE_STOPPED)
{
status_ = ret = get_scanner_paperon();
}
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_name(status_));
}
int hg_scanner_239::start(void)
{
bool handled = false;
int ret = try_third_app_handle_start(handled),
val = 0;
// for third-sane-app invoking, added on 2022-05-19
if (handled)
return ret;
user_cancel_ = false;
on_is_auto_paper(is_auto_paper_scan);
split3399_ = 0;
cb_mem_ = true;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status());
notify_ui_working_status(STATU_DESC_PREPARE_START);
reset();
get_roller_num();
val = get_device_sleep_stautus();//211220固件版本不支持返回
if (val == 0)
{
status_ = SCANNER_ERR_DEVICE_SLEEPING;;
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING);
if(is_kernelsnap_220830_)
val = notify_sleep();
notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_NOTIFY_SLEEP, SANE_EVENT_ERROR, status_);
return status_;
}
val = get_scan_mode();
if (status_ == SCANNER_ERR_DEVICE_NOT_FOUND)
return status_;
if (val == -1)
return status_;
if (val & 1)
{
status_ = SCANNER_ERR_DEVICE_COUNT_MODE;
return status_;
}
notify_ui_working_status(STATU_DESC_REWRITE_CONFIGURATION);
if(ret == SCANNER_ERR_OK)
{
ret = writedown_device_configuration();
}
if(ret == SCANNER_ERR_OK)
{
ret = writedown_image_configuration();
}
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_WARNING, "Write down image process parameters fail is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
std::string info(STATU_DESC_REWRITE_CONFIGURATION);
info += std::string("\345\244\261\350\264\245\357\274\232") + hg_scanner_err_name(ret);
notify_ui_working_status(info.c_str(), SANE_EVENT_ERROR, ret);
}
if (ret != SCANNER_ERR_OK)
{
VLOG_MINI_1(LOG_LEVEL_WARNING, "start status01 is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
return ret;
}
ret = write_command(setting3399::SC_START);
io_->set_timeout(1000);
if (ret == SCANNER_ERR_OK)
{
wait_usb_.notify();
this_thread::sleep_for(chrono::milliseconds(100));
ret = try_third_app_after_start(ret);
}
else
{
status_ = ret;
VLOG_MINI_3(LOG_LEVEL_WARNING, "(%s)[Thread %s]Send start command = %s\n", hg_log::current_time().c_str(), hg_log::format_current_thread_id().c_str(), hg_scanner_err_name(ret));
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
return ret;
}
int hg_scanner_239::stop(void)
{
int ret = SCANNER_ERR_OK;
user_cancel_ = true;
ret = write_command(setting3399::SC_STOP);
io_->set_timeout(500);
return status_;
}
int hg_scanner_239::reset(void)
{
final_imgs_.clear();
discard_all_images();
return status_;
}
int hg_scanner_239::device_io_control(unsigned long code, void* data, unsigned* len)
{
int ret = SCANNER_ERR_OUT_OF_RANGE;
if (HG_CONTROL_CODE_OPTION_ENABLE == code)
{
OPTEN* opten = (OPTEN*)data;
ret = SCANNER_ERR_OK;
if (opten->opt_num == HG_239_SETTING_CORRECT && !opten->enabled) // for BUG-20 modified by Gongbing on 2022-03-12
{
bool enable = true;
setting_automatic_skew(opten->opt_num, &enable);
}
}
else if (IO_CTRL_CODE_TEST_SINGLE == code)
{
test_1_paper_ = true;
ret = start();
}
else
ret = hg_scanner::device_io_control(code, data, len);
return ret;
}
std::string hg_scanner_239::get_firmware_version(void)
{
return control_fetch(setting3399::SR_GET_FWVERSION, 0, 20);
}
std::string hg_scanner_239::get_serial_num(void)
{
return control_fetch(setting3399::SR_GET_SERIALNUM, 0, 20);
}
std::string hg_scanner_239::get_ip(void)
{
return control_fetch(setting3399::SR_GET_IPADDR, 0, 40);
}
int hg_scanner_239::get_roller_num(void)
{
int val = 0,
ret = read_register(setting3399::SR_GET_ROLLER_NUM, &val);
if (ret == SCANNER_ERR_OK)
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_roller_num = %s\n", hg_scanner_err_name(ret));
return -1;
}
}
int hg_scanner_239::clear_roller_num(void)
{
int val = 0,
ret = read_register(setting3399::SR_CLR_ROLLER_NUM, &val);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int hg_scanner_239::set_leaflet_scan(void)
{
int ret = SCANNER_ERR_OK;
test_1_paper_ = true;
ret = start();
return ret;
}
int hg_scanner_239::get_abuot_info(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::restore_default_setting(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::set_final_image_format(SANE_FinalImgFormat* fmt)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_compression_format(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::set_compression_format(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::set_auto_color_type(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_device_code(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_sleep_time(int& getime)
{
int val = 0,
ret = read_register(setting3399::SR_GET_SLEEPTIME, &val);
if (ret == SCANNER_ERR_OK)
{
getime = val;
save_sleeptime_type_ = true;
}
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_sleep_time %d= %s\n", val,hg_scanner_err_name(ret));
return ret;
}
int hg_scanner_239::set_sleep_time(int setsleepime)
{
int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret));
return ret;
}
int hg_scanner_239::get_dogear_distance(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::set_dogear_distance(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_scanner_paperon(SANE_Bool* paperon)
{
int val = 0,
ret = read_register(setting3399::SR_GET_PAPERON, &val);
if (ret == SCANNER_ERR_OK)
{
if (!val)
{
ret = SCANNER_ERR_DEVICE_NO_PAPER;
if (paperon)
{
*paperon = false;
}
}
else
{
ret = SCANNER_ERR_OK;
if (paperon)
{
*paperon = true;
}
}
}
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scanner_paperon = %s\n", hg_scanner_err_name(ret));
return -1;
}
return ret;
}
int hg_scanner_239::set_scan_when_paper_on(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_scan_when_paper_on(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_scan_with_hole(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::set_scan_with_hole(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::get_scan_is_sleep()
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_239::notify_sleep()
{
int val = 0,
ret = SCANNER_ERR_OK;
if (is_kernelsnap_220830_)
{
ret = write_register(setting3399::SR_NOTIFY_SLEEP, val);
}
return ret;
}
int hg_scanner_239::get_history_count()
{
return -2;
}
int hg_scanner_239::get_device_log(string &logpath)
{
string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log";
string device_log_path = "/var/log/syslog";
string str ;
int ret = SCANNER_ERR_OK;
int buffersize = 0;
int len = device_log_path.size();
io_->set_timeout(3000);
ret = write_register(setting3399::SR_SET_JSON_PATH, len);
if (ret != SCANNER_ERR_OK)
return ret;
ret = io_->write_bulk(&device_log_path[0],&len);
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_JSON_SIZE,&buffersize);
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
ret = write_register(setting3399::SR_GET_JSON,buffersize);
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
str.resize(buffersize);
ret = io_->read_bulk(&str[0],&buffersize);
if (ret != SCANNER_ERR_OK)
return ret;
ofstream f;
f.open(save_path,ios::out | ios::app);
if (!f.is_open())
return SCANNER_ERR_CREATE_FILE_FAILED;
f << str << endl;
f.close();
logpath = save_path;
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(),hg_scanner_err_name(ret),buffersize);
return ret;
}
int hg_scanner_239::set_devreboot()
{
int val = 0,
ret = write_register(setting3399::SR_REBOOT, val);
if (ret != SCANNER_ERR_OK)
return ret;
}
int hg_scanner_239::set_devshtudown()
{
int val = 0,
ret = write_register(setting3399::SR_POWEROFF, val);
if (ret != SCANNER_ERR_OK)
return ret;
}
int hg_scanner_239::set_scan_islock(SANE_Bool set_islock)
{
if (set_islock != 0 && set_islock != 1)
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
int val = 0,
ret = write_register(setting3399::SR_SET_LOCK_STATES, set_islock);
if (ret != SCANNER_ERR_OK)
return ret;
}
int hg_scanner_239::get_scan_islock(SANE_Bool* islock)
{
if (!is_kernelsnap_220830_)
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
int val = 0,
ret = read_register(setting3399::SR_GET_LOCK_STATES, &val);
if (ret == SCANNER_ERR_OK)
*islock = val;
if ( val == 1)
ret = SCANNER_ERR_DEVICE_ISLOCK;
return ret;
}
int hg_scanner_239::set_scan_lock_check_val(string check_str)
{
#if defined(WIN32) || defined(_WIN64)
if (check_str.empty())
{
return SCANNER_ERR_INVALID_PARAMETER;
}
std::string sn = get_serial_num(),
token = check_str;
std::string encoded;
std::string cipher;
int check_val_len = token.length();
int num = 32 - check_val_len; //始终保持32位发下去
SANE_Bool islock;
int ret = SCANNER_ERR_OK;
std::uint8_t key[CryptoPP::AES::DEFAULT_KEYLENGTH] = { 0 };
ret = get_scan_islock(&islock);
if (ret == SCANNER_ERR_DEVICE_ISLOCK)
return ret;
if (num > 0)
{
std::string str(num, '0');
token += str;
}
else if(num < 0)
token = token.substr(0, 32);
for (size_t i = 0; i < 16; i++)
{
key[i] = _strtoi64(token.substr(i * 2, 2).c_str(), nullptr, 16);
}
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption encode(key, 16);
CryptoPP::StringSink* strcip = new CryptoPP::StringSink(cipher);
CryptoPP::StreamTransformationFilter* ecb_filter = (
new CryptoPP::StreamTransformationFilter(encode, strcip, CryptoPP::BlockPaddingSchemeDef::W3C_PADDING));
CryptoPP::StringSource* soure_plain = new CryptoPP::StringSource(sn,true,ecb_filter);
CryptoPP::StringSink* str_encode = new CryptoPP::StringSink(encoded);
CryptoPP::HexEncoder* hex_encode = new CryptoPP::HexEncoder(str_encode);
CryptoPP::StringSource* suorce_cipher = new CryptoPP::StringSource(cipher,true,hex_encode);
SAFE_DELETE(strcip);
SAFE_DELETE(ecb_filter);
SAFE_DELETE(soure_plain);
SAFE_DELETE(str_encode);
SAFE_DELETE(hex_encode);
SAFE_DELETE(suorce_cipher);
ret = write_register(setting3399::SR_DECODE_TOKEN, encoded.length());
if (ret != SCANNER_ERR_OK)
{
return ret;
}
int len = encoded.length();
ret = io_->write_bulk(&encoded[0], &len);
return ret;
#endif
}
int hg_scanner_239::firmware_upgrade(std::string filename)
{
std::ifstream fwname;
int ret = SCANNER_ERR_OK;
fwname.open(filename, std::ios_base::in | std::ios_base::binary);
if (!fwname.is_open())
{
return false;
}
fwname.seekg(0, std::ios::end);
int total = fwname.tellg();//记录总长度
fwname.seekg(0, std::ios::beg);
int pos = fwname.tellg();//记录pos位置
ret = write_register(setting3399::SR_UPDATA_START,total);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
int block = total;
while (total > 0)
{
block = 512 * 1024;
if (total < block)
block = total;
std::vector<char>data;
data.resize(block + 1);
fwname.read(data.data(), block);
io_->write_bulk(data.data(), &block);
if (ret != SCANNER_ERR_OK)
return ret;
pos += block;
total -= block;
fwname.seekg(pos);
}
this_thread::sleep_for(std::chrono::milliseconds(200));
int val = 0;
int ret = read_register(setting3399::SR_UPDATA_STAUTUS, &val);
if (ret != SCANNER_ERR_OK)
return ret;
else if (!val)
return SCANNER_ERR_DEVICE_UPGRADE_FAIL;
int to_cnt = 0;
//暂时屏蔽 到这个位置已经能够升级成功了 后面对升级结果做下判断
//while (to_cnt++ > 20)
{
/*int ret = read_register(setting3399::SR_UPDATA_MD5_RELUST, &val);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
if (val == 2)
{
}
else if(val ==3)
{
}
else if (true)
{
}
this_thread::sleep_for(std::chrono::milliseconds(20));*/
}
return ret;
}