diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 21bdcd9..0900fcc 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -1870,6 +1870,8 @@ int hg_scanner::save_usb_data(std::shared_ptr data) if (wait_img_.is_waiting()) wait_img_.notify(); } + unsigned int bytes = data->size(); + ui_ev_cb_((scanner_handle)this, SANE_EVENT_USB_DATA_RECEIVED, NULL, &bytes, NULL); return ret; } @@ -2333,7 +2335,10 @@ int hg_scanner::read_image_data(unsigned char* buf, int* len) return over ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK; } else + { + *len = 0; return SCANNER_ERR_NO_DATA; + } } int hg_scanner::stop(void) { @@ -2441,13 +2446,10 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) return SCANNER_ERR_INSUFFICIENT_MEMORY; } - char* buf = strcpy((char*)data, fw.c_str()); + if (data) + strcpy((char*)data, fw.c_str()); - if (buf) - { - return SCANNER_ERR_OK; - } - return SCANNER_ERR_DATA_DAMAGED; + return SCANNER_ERR_OK; } else if(code == IO_CTRL_CODE_GET_SERIAL) { @@ -2457,12 +2459,10 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) *len = ser.size(); return SCANNER_ERR_INSUFFICIENT_MEMORY; } - char* buf = strcpy((char*)data, ser.c_str()); - if (buf) - { - return SCANNER_ERR_OK; - } - return SCANNER_ERR_DATA_DAMAGED; + if (data) + strcpy((char*)data, ser.c_str()); + + return SCANNER_ERR_OK; } else if (code == IO_CTRL_CODE_GET_HARDWARE_VERSION) { @@ -2472,13 +2472,10 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) *len = ip.size(); return SCANNER_ERR_INSUFFICIENT_MEMORY; } - char* buf = strcpy((char*)data, ip.c_str()); + if (data) + strcpy((char*)data, ip.c_str()); - if (buf) - { - return SCANNER_ERR_OK; - } - return SCANNER_ERR_DATA_DAMAGED; + return SCANNER_ERR_OK; } else if (code == IO_CTRL_CODE_GET_PAPER_ON) { @@ -2566,6 +2563,14 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) return wait_img_.is_waiting() && wait_usb_.is_waiting() ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK; } + else if (code == IO_CTRL_CODE_GET_PAPER_SIZE) + { + std::string name((char*)data); + int paper = match_best_paper(name, NULL); + SIZE size = paper_size(paper); + + *len = (size.cx & 0x0ffff) | ((size.cy & 0x0ffff) << 16); + } return SCANNER_ERR_DEVICE_NOT_SUPPORT; } diff --git a/hgdriver/hgdev/scanner_manager.cpp b/hgdriver/hgdev/scanner_manager.cpp index d1c7f8c..6f82390 100644 --- a/hgdriver/hgdev/scanner_manager.cpp +++ b/hgdriver/hgdev/scanner_manager.cpp @@ -31,13 +31,12 @@ g_supporting_devices[] = { , {0x31c9, 0x8629, SCANNER_NAME_LSC_G62S, "G6290U", ""} , {0x31c9, 0x8730, SCANNER_NAME_LSC_G73S, "G73x0U", ""} , {0x31c9, 0x8739, SCANNER_NAME_LSC_G73S, "G73x0U", ""}, -#endif -#ifdef OEM_HANWANG +#elif defined(OEM_HANWANG) {0x2903, 0x7000, SCANNER_NAME_HW_7000, "HW-74x0WA", ""} , {0x2903, 0x1000, SCANNER_NAME_HW_1060A, "HW-1060A", ""} , {0x2903, 0x8000, SCANNER_NAME_HW_8090F, "HW-8090F", ""} , {0x2903, 0x9000, SCANNER_NAME_HW_9110F, "HW-9110F", ""}, -#endif +#else {0x3072, 0x100, SCANNER_NAME_HG_G100, "GScanO200", ""} , {0x3072, 0x200, SCANNER_NAME_HG_G200, "GScanO200", ""} , {0x3072, 0x300, SCANNER_NAME_HG_G300, "GScanO400", ""} @@ -47,6 +46,7 @@ g_supporting_devices[] = { , {0x3072, 0x339, SCANNER_NAME_HG_G339, "GScanO1003399", ""} , {0x3072, 0x439, SCANNER_NAME_HG_G439, "GScanO1003399", ""} , {0x064B, 0x7823, SCANNER_NAME_HG_G200, "GScanO200", ""} +#endif }; static std::string g_vendor = COMPANY_NAME; diff --git a/hgsane/sane_hg_mdw.cpp b/hgsane/sane_hg_mdw.cpp index 2058a47..bd05f1d 100644 --- a/hgsane/sane_hg_mdw.cpp +++ b/hgsane/sane_hg_mdw.cpp @@ -308,6 +308,12 @@ namespace local_utility if (version_code) *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, VERSION_BUILD); // leading-char '1' is used for avoid compiler considering '0118' as an octal number :) } + void set_callback(sane_callback cb, void* param) + { + std::lock_guard lck(cb_lock_); + cb_ui_ = cb; + cb_ui_parm_ = param; + } void stop_work(void) { std::lock_guard lck(cb_lock_); @@ -469,6 +475,10 @@ hg_sane_middleware* hg_sane_middleware::instance(void) return hg_sane_middleware::inst_; } +void hg_sane_middleware::set_callback(sane_callback cb, void* param) +{ + local_utility::set_callback(cb, param); +} void hg_sane_middleware::clear(void) { local_utility::stop_work(); @@ -1097,7 +1107,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, int option, vo jsn->get_value("title", val); - VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str()); + VLOG_MINI_3(LOG_LEVEL_ALL, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str()); } delete jsn; @@ -1458,11 +1468,11 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, SANE_Int option, SANE_ if (prev == v) { - VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "-->Set option(%d - %s) value: %s\n", option, desc->title, v.c_str()); + VLOG_MINI_3(LOG_LEVEL_ALL, "-->Set option(%d - %s) value: %s\n", option, desc->title, v.c_str()); } else { - VLOG_4(LOG_LEVEL_DEBUG_INFO, 512, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc->title, prev.c_str(), v.c_str()); + VLOG_4(LOG_LEVEL_ALL, 512, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc->title, prev.c_str(), v.c_str()); } if (err == SCANNER_ERR_OK) @@ -1996,8 +2006,7 @@ extern "C" { // avoid compiler exporting name in C++ style !!! SANE_Status inner_sane_init_ex(SANE_Int* version_code, sane_callback cb, void* param) { - local_utility::cb_ui_ = cb; - local_utility::cb_ui_parm_ = param; + local_utility::set_callback(cb, param); hg_sane_middleware::instance(); local_utility::get_version(version_code); @@ -2015,10 +2024,12 @@ extern "C" { // avoid compiler exporting name in C++ style !!! #ifdef WIN32 +HMODULE g_my_inst = NULL; BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) { if (reason == DLL_PROCESS_ATTACH) { + g_my_inst = inst; if (g_sane_path.empty()) { char path[MAX_PATH] = { 0 }; diff --git a/hgsane/sane_hg_mdw.h b/hgsane/sane_hg_mdw.h index d0f62e9..057329a 100644 --- a/hgsane/sane_hg_mdw.h +++ b/hgsane/sane_hg_mdw.h @@ -162,6 +162,7 @@ protected: public: static std::string sane_path(void); static hg_sane_middleware* instance(void); + static void set_callback(sane_callback cb, void* param); static void clear(void); static scanner_handle sane_handle_to_scanner(SANE_Handle h); static SANE_Handle scanner_handle_to_sane(scanner_handle h);