diff --git a/hgdriver/hgdev/scanner/scanner_handler.cpp b/hgdriver/hgdev/scanner/scanner_handler.cpp index 4021889..ec42eda 100644 --- a/hgdriver/hgdev/scanner/scanner_handler.cpp +++ b/hgdriver/hgdev/scanner/scanner_handler.cpp @@ -2,7 +2,7 @@ #include "async_usb_host.h" - +#include @@ -132,7 +132,7 @@ int cmd_result::clean(void) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // scanner_handler -scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_STATUS_NOT_OPEN) +scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_ERR_NOT_OPEN) , img_receiver_(std::function()) , status_notify_(std::function()) { @@ -149,20 +149,20 @@ scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_STATUS_N ret = cmd->roger(reply, used, more); if (cmd->is_over()) cmd->release(); - else if (status_ != SCANNER_STATUS_RESET_BULK) + else // if (status_ != SCANNER_STATUS_RESET_BULK) { SIMPLE_LOCK(lock_reply_); reply_.push_back(cmd); } } - else if (status_ == SCANNER_STATUS_RESET_BULK) - { - if (pack->size == sizeof(PACK_BASE) && - pack->cmd == PACK_CMD_SYNC_ROGER && - pack->payload_len == 0) - status_ = SCANNER_STATUS_READY; - } + //else if (status_ == SCANNER_STATUS_RESET_BULK) + //{ + // if (pack->size == sizeof(PACK_BASE) && + // pack->cmd == PACK_CMD_SYNC_ROGER && + // pack->payload_len == 0) + // status_ = SCANNER_STATUS_READY; + //} else if (pack->size == sizeof(PACK_BASE)) { if (pack->cmd == PACK_CMD_SCAN_IMG_ROGER) @@ -489,7 +489,7 @@ int scanner_handler::scan_start(void) *used = sizeof(PACK_BASE); *more = nullptr; - status_ = pack->data == 0 ? SCANNER_STATUS_START_SCANNING : SCANNER_STATUS_READY; + status_ = pack->data == 0 ? SCANNER_ERR_DEVICE_BUSY : SCANNER_ERR_OK; cmd->trigger(); return nullptr; @@ -590,7 +590,7 @@ int scanner_handler::file_transfer(const char* local_path, const char* remote_pa else { *more = dynamic_cast(freader); - status_ = SCANNER_STATUS_BUSY; + status_ = SCANNER_ERR_DEVICE_BUSY; } } } @@ -651,7 +651,7 @@ int scanner_handler::file_transfer(const char* local_path, const char* remote_pa fsaver->set_progress_notify(progress); *more = dynamic_cast(fsaver); (*(LPPACK_BASE)reply->ptr()).data = 0; - status_ = SCANNER_STATUS_BUSY; + status_ = SCANNER_ERR_DEVICE_BUSY; } } } @@ -781,7 +781,7 @@ int scanner_handler::open_usb_scanner(libusb_device* dev) { ret = usb_->start(dev); if(ret == 0) - status_ = SCANNER_STATUS_READY; + status_ = SCANNER_ERR_OK; //usb_->set_gadget_encrypting_method(ENCRYPT_CMD_XOR_PID); } @@ -798,7 +798,7 @@ int scanner_handler::close(void) reply_.clear(); } if(ret == 0) - status_ = SCANNER_STATUS_NOT_OPEN; + status_ = SCANNER_ERR_NOT_OPEN; return ret; } @@ -806,37 +806,36 @@ int scanner_handler::reset_message_que(void) { return 0; - int err = usb_->cancel_write(); - - status_ = SCANNER_STATUS_RESET_BULK; - utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send reset command ...\r\n"); - err = usb_->reset_peer(); - utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send reset command = %d\r\n", err); - if (err == 0) - { - EP0REPLYSTATUS s; - dyn_mem_ptr raw(dyn_mem::memory(sizeof(PACK_BASE))); - LPPACK_BASE pack = (LPPACK_BASE)raw->ptr(); - - BASE_PACKET_REPLY(*pack, PACK_CMD_SYNC, 0, 0); - raw->set_len(sizeof(PACK_BASE)); - utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - wait 100ms ...\r\n"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send SYNC packet ...\r\n"); - usb_->send_bulk_raw_data(raw); - raw->release(); - - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - if (status_ == SCANNER_STATUS_RESET_BULK) - err = EFAULT; - utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - final status = %d\r\n", status_); - } - - return err; + //int err = usb_->cancel_write(); + // + //status_ = SCANNER_STATUS_RESET_BULK; + //utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send reset command ...\r\n"); + //err = usb_->reset_peer(); + //utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send reset command = %d\r\n", err); + //if (err == 0) + //{ + // EP0REPLYSTATUS s; + // dyn_mem_ptr raw(dyn_mem::memory(sizeof(PACK_BASE))); + // LPPACK_BASE pack = (LPPACK_BASE)raw->ptr(); + // + // BASE_PACKET_REPLY(*pack, PACK_CMD_SYNC, 0, 0); + // raw->set_len(sizeof(PACK_BASE)); + // utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - wait 100ms ...\r\n"); + // std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - send SYNC packet ...\r\n"); + // usb_->send_bulk_raw_data(raw); + // raw->release(); + // + // std::this_thread::sleep_for(std::chrono::milliseconds(50)); + // if (status_ == SCANNER_STATUS_RESET_BULK) + // err = EFAULT; + // utils::to_log(LOG_LEVEL_DEBUG, "reset_message_que - final status = %d\r\n", status_); + //} + // + //return err; } bool scanner_handler::is_scanner_available(void) { - return status_ != SCANNER_STATUS_NOT_OPEN - && status_ != SCANNER_STATUS_LOST_CONNECT - && status_ != SCANNER_STATUS_RESET_BULK; + return status_ == SCANNER_ERR_OK || + status_ == SCANNER_ERR_DEVICE_BUSY; } diff --git a/hgdriver/hgdev/user-opt/user.h b/hgdriver/hgdev/user-opt/user.h index 404d27a..9c2e7ac 100644 --- a/hgdriver/hgdev/user-opt/user.h +++ b/hgdriver/hgdev/user-opt/user.h @@ -7,6 +7,16 @@ #include +// name password time-limit +// +// developer calc(dev-sn + login-times) 6min +// +// owner calc(dev-sn + login-times) 30min +// +// admin dev-sn 1hour +// +// user none, default level always +// class hguser { std::string name_; diff --git a/sdk/base/data.cpp b/sdk/base/data.cpp index cc33c22..cbc35a0 100644 --- a/sdk/base/data.cpp +++ b/sdk/base/data.cpp @@ -10,28 +10,6 @@ #include #endif -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// sys_info -uint32_t sys_info::page_size = 0; -uint32_t sys_info::page_map_size = 0; -uint32_t sys_info::cluster_size = 0; - -sys_info::sys_info() -{ - sys_info::page_size = utils::get_page_size(&sys_info::page_map_size); - - std::string path(utils::get_local_data_path()); - unsigned long long cluster = 0; - - utils::get_disk_space(path.c_str(), nullptr, nullptr, &cluster); - sys_info::cluster_size = cluster; - - printf("Page size: %u\nMap size: %u\nCluster : %u\n", sys_info::page_size, sys_info::page_map_size, sys_info::cluster_size); -} -sys_info::~sys_info() -{} - -static sys_info g_si; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // diff --git a/sdk/base/data.h b/sdk/base/data.h index 5a2d5e5..9bf507a 100644 --- a/sdk/base/data.h +++ b/sdk/base/data.h @@ -76,17 +76,6 @@ public: uint8_t* buffer(void); }; -class sys_info -{ -public: - sys_info(); - ~sys_info(); - -public: - static uint32_t page_size; - static uint32_t page_map_size; - static uint32_t cluster_size; -}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // diff --git a/sdk/base/packet.h b/sdk/base/packet.h index cffed45..6b7e68a 100644 --- a/sdk/base/packet.h +++ b/sdk/base/packet.h @@ -126,33 +126,6 @@ enum img_cb_type IMG_CB_STOPPED, }; -enum scanner_status -{ - SCANNER_STATUS_READY = 0x10000, // status beginning, avoiding conficts with standards/system error code - SCANNER_STATUS_NOT_OPEN, - SCANNER_STATUS_LOST_CONNECT, - SCANNER_STATUS_RESET_BULK, - SCANNER_STATUS_START_SCANNING, // start ok, but scanning-thread not working - SCANNER_STATUS_SCANNING, // start ok, and scanning-thread is working - SCANNER_STATUS_SCAN_FINISHED, // not a persistance status - SCANNER_STATUS_BUSY, // doing task exclude scanning - SCANNER_STATUS_COVER_OPENNED, - SCANNER_STATUS_COVER_CLOSED, - SCANNER_STATUS_SLEEPING, - SCANNER_STATUS_WAKED_UP, - SCANNER_STATUS_COUNT_MODE, - SCANNER_STATUS_DOUBLE_FEEDED, - SCANNER_STATUS_PAPER_JAMMED, - SCANNER_STATUS_PAPER_ASKEW, - SCANNER_STATUS_FEED_FAILED, - SCANNER_STATUS_NO_PAPER, - SCANNER_STATUS_PAPER_ON, - SCANNER_STATUS_STAPLE_ON, - SCANNER_STATUS_SIZE_ERR, - SCANNER_STATUS_DOGEAR, - SCANNER_STATUS_CFG_CHANGED, // PACK_BASE::payload - LPCFGVAL -}; - // option affection if value changed, see SANE_INFO_xxx enum opt_affect { diff --git a/sdk/base/plat_types.h b/sdk/base/plat_types.h index 354fe72..de53859 100644 --- a/sdk/base/plat_types.h +++ b/sdk/base/plat_types.h @@ -17,6 +17,7 @@ #define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align)) #define ALIGN_INT(v) ALIGN_TO(v, sizeof(int)) #define CLEAN_ARRAY(a) memset(a, 0, sizeof(a)) +#define BMP_LINE_BYTES(bits) (((bits) + 31) / 32 * 4) #define RETURN_ENUM_STR(v, e) \ if(v == e) \ diff --git a/sdk/base/utils.cpp b/sdk/base/utils.cpp index 1167bbe..b0d7731 100644 --- a/sdk/base/utils.cpp +++ b/sdk/base/utils.cpp @@ -606,7 +606,11 @@ namespace utils ldp += PATH_SEPARATOR; } #else +#ifdef BUILD_AS_DEVICE + const char* path = "/var/log"; +#else const char* path(getenv("HOME")); +#endif if (path) { @@ -926,11 +930,11 @@ namespace utils HMODULE load_dll(const char* path_file, int flag) { #if OS_WIN - HMODULE h = LoadLibraryA(path_file); - int ret = GetLastError(); + HMODULE h = NULL; // LoadLibraryA(path_file); + int ret = 0; // GetLastError(); - utils::to_log(1, "[TWAIN]Load: LoadLibraryA(%s) = %d\r\n", path_file, ret); - if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT)) + // utils::to_log(1, "[TWAIN]Load: LoadLibraryA(%s) = %d\r\n", path_file, ret); + // if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT)) { std::string dir(path_file); size_t pos = dir.rfind('\\'); @@ -1239,6 +1243,53 @@ namespace utils return 0; } + std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy) + { + BITMAPINFODEADER bih = {0}; + std::string stream(""); + + if(dpiy == 0) + dpiy = dpix; + bih.biSize = sizeof(bih); + bih.biWidth = pixel_w; + bih.biHeight = pixel_h; + bih.biBitCount = bpp; + bih.biSizeImage = BMP_LINE_BYTES(pixel_w * bpp) * pixel_h; + bih.biPlanes = 1; + bih.biCompression = BI_RGB; + bih.biXPelsPerMeter = (LONG)(dpix * 39.37f + .5f); + bih.biYPelsPerMeter = (LONG)(dpiy * 39.37f + .5f); + stream = std::string((char*)&bih, sizeof(bih)); + if(bpp == 1) + { + int pal[] = { 0, 0x0ffffff }; + stream += std::string((char*)pal, sizeof(pal)); + bih.biClrUsed = _countof(pal); + } + else if(bpp == 8) + { + stream += std::string((char*)global_info::gray_pallete, sizeof(global_info::gray_pallete)); + bih.biClrUsed = _countof(global_info::gray_pallete); + } + + return std::move(stream); + } + std::string bitmap_file_header(BITMAPINFOHEADER *lpbi) // return BITMAPFILEHEADER + { + BITMAPFILEHEADER bfh = {0}; + int pal_size = 0; + + bfh.bfType = MAKEWORD('B', 'M'); + if(lpbi->biBitCount == 1) + pal_size = 2 * sizeof(int); + else if(lpbi->biBitCount == 8) + pal_size = 256 * sizeof(int); + bfh.bfOffBits = sizeof(bfh) + sizeof(BITMAPINFOHEADER) + pal_size; + bfh.bfSize = bfh.bfOffBits + lpbi->biSizeImage; + + return std::move(std::string((char*)&bfh, sizeof(bfh))); + } + #if OS_WIN bool run_get_message(HWND hwnd, UINT filter_min, UINT filter_max, std::function msghandler) { @@ -1598,6 +1649,32 @@ void chronograph::reset() +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// global_info +uint32_t global_info::page_size = 0; +uint32_t global_info::page_map_size = 0; +uint32_t global_info::cluster_size = 0; +uint32_t global_info::gray_pallete[] = {0}; + +global_info::global_info() +{ + global_info::page_size = utils::get_page_size(&global_info::page_map_size); + + std::string path(utils::get_local_data_path()); + unsigned long long cluster = 0; + + utils::get_disk_space(path.c_str(), nullptr, nullptr, &cluster); + global_info::cluster_size = cluster; + for(int i = 0; i < _countof(global_info::gray_pallete); ++i) + global_info::gray_pallete[i] = MAKELONG(MAKEWORD(i, i), MAKEWORD(i, 0)); + + printf("Page size: %u\nMap size: %u\nCluster : %u\n", global_info::page_size, global_info::page_map_size, global_info::cluster_size); +} +global_info::~global_info() +{} + +static global_info g_si; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/sdk/base/utils.h b/sdk/base/utils.h index f01aef7..2e875c2 100644 --- a/sdk/base/utils.h +++ b/sdk/base/utils.h @@ -77,6 +77,10 @@ namespace utils int copy_log_file_to(const char* dst); int clear_log_file(void); + // bitmap header ... + std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy = 0); // return BITMPINFOHEADER + pallete if need. dpiy same as dpix if was ZERO + std::string bitmap_file_header(BITMAPINFOHEADER *lpbi); // return BITMAPFILEHEADER + #if OS_WIN // Function: pump message recycle (GetMessageW) // @@ -232,6 +236,20 @@ public: void reset(void); }; +// global info +class global_info +{ +public: + global_info(); + ~global_info(); + +public: + static uint32_t page_size; + static uint32_t page_map_size; + static uint32_t cluster_size; + static uint32_t gray_pallete[256]; +}; + // event class platform_event : public refer { diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index 62c5e04..9f43d4b 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -1785,6 +1785,20 @@ int device_option::update_data(const char* name, void* value, bool reorder_if_ne || (child->get_value("auth", err) && user_ && !user_(err))) { err = SCANNER_ERR_ACCESS_DENIED; + + // following ... + if (src_.count(name)) + { + sane_opt_provider* opt = src_[name]->get_following(name); + while(opt) + { + opt->set_value(name, value); + + sane_opt_provider* next = opt->get_following(name); + opt->release(); + opt = next; + } + } } else { @@ -1921,7 +1935,8 @@ int device_option::restore(sane_opt_provider* holder) while (child) { if ((!holder || src_.count(child->key()) && src_[child->key()] == holder) - && is_auto_restore_default(child)) + // && is_auto_restore_default(child) + ) { std::string val(device_option::option_value(child, true)); update_data(child->key().c_str(), &val[0], false); diff --git a/sdk/sane_opt_json/device_opt.h b/sdk/sane_opt_json/device_opt.h index 9ae2270..6821c62 100644 --- a/sdk/sane_opt_json/device_opt.h +++ b/sdk/sane_opt_json/device_opt.h @@ -375,8 +375,8 @@ public: // "resolution": { // "cat": "base", // "group" : "base", -// "title" : "·Ö±æÂÊ", -// "desc" : "ÉèÖÃɨÃèͼÏñµÄ·Ö±æÂÊ", +// "title" : "�ֱ���", +// "desc" : "����ɨ��ͼ��ķֱ���", // "type" : "int", // "fix-id" : 34840, // "size" : 4, @@ -386,7 +386,7 @@ public: // "min": 100, // "max" : { // "default": 600, -// "paper==×î´óɨÃè³ß´ç×Ô¶¯²ÃÇÐ || paper==×î´óɨÃè³ß´ç || paper==ÈýÁªÊÔ¾í" : 500 +// "paper==���ɨ��ߴ��Զ����� || paper==���ɨ��ߴ� || paper==�����Ծ�" : 500 // }, // "step" : 1 // } @@ -395,19 +395,19 @@ public: // "paper": { // "cat": "base", // "group" : "base", -// "title" : "Ö½Õųߴç", -// "desc" : "ÉèÖóöͼ´óС", +// "title" : "ֽ�ųߴ�", +// "desc" : "���ó�ͼ��С", // "type" : "string", // "fix-id" : 34831, // "size" : 44, -// "cur" : "Æ¥Åäԭʼ³ß´ç", -// "default" : "Æ¥Åäԭʼ³ß´ç", -// "range" : ["A3", "8¿ª", "A4", "16¿ª", "A5", "A6", "B4", "B5", "B6", "Letter", "Double Letter", "LEGAL", "Æ¥Åäԭʼ³ß´ç", { -// "resolution<500": "×î´óɨÃè³ß´ç×Ô¶¯²ÃÇÐ" +// "cur" : "ƥ��ԭʼ�ߴ�", +// "default" : "ƥ��ԭʼ�ߴ�", +// "range" : ["A3", "8��", "A4", "16��", "A5", "A6", "B4", "B5", "B6", "Letter", "Double Letter", "LEGAL", "ƥ��ԭʼ�ߴ�", { +// "resolution<500": "���ɨ��ߴ��Զ�����" // }, { -// "resolution<500": "×î´óɨÃè³ß´ç" +// "resolution<500": "���ɨ��ߴ�" // }, { -// "resolution<500": "ÈýÁªÊÔ¾í" +// "resolution<500": "�����Ծ�" // }] // } //} diff --git a/twain/ds/scanned_img.cpp b/twain/ds/scanned_img.cpp index 0e441ba..c2d643b 100644 --- a/twain/ds/scanned_img.cpp +++ b/twain/ds/scanned_img.cpp @@ -275,6 +275,7 @@ std::string scanned_img::file_header(SANE_ImageType type, float resolution) pal_size = 2 * sizeof(int); else if (bih.biBitCount == 8) pal_size = 256 * sizeof(int); + bih.biClrUsed = pal_size / sizeof(int); // some APP (PJScanner.exe 光大……) use this field to calculate pallete { BITMAPFILEHEADER fh = { 0 };