set DPI and scan count

This commit is contained in:
gb 2023-04-13 14:42:43 +08:00
parent 25a4395bb2
commit a88adbadfe
13 changed files with 186 additions and 33 deletions

View File

@ -130,7 +130,7 @@ struct MotorBoardGlue
struct ScannerNativeParam struct ScannerNativeParam
{ {
u32 TotalScanned; //扫描总计<EFBFBD>? u32 TotalScanned; //<EFBFBD><EFBFBD><EFBFBD>餉恣嚙?
u32 RollerNum; //滚轴计数 u32 RollerNum; //滚轴计数
u32 H_ratio; //横向修正系数 u32 H_ratio; //横向修正系数
u32 V_ratio; //纵向修正系数 u32 V_ratio; //纵向修正系数
@ -138,13 +138,13 @@ struct ScannerNativeParam
u32 FeedErrorTimes; //搓纸失败次数 u32 FeedErrorTimes; //搓纸失败次数
u32 DoubleFeedTimes; //双张次数 u32 DoubleFeedTimes; //双张次数
u32 ScanSessionsCount; //总计扫描次数 u32 ScanSessionsCount; //总计扫描次数
u16 gray_sp; //灰度sp<EFBFBD>? u16 gray_sp; //<EFBFBD>啣漲sp嚙?
u16 color_sp; //彩色sp<EFBFBD>? u16 color_sp; //敶抵𠧧sp嚙?
int sleeptime; //休眠模式时间 -1 不休<E4B88D>? int sleeptime; //隡𤑳<EFBFBD><EFBFBD><EFBFBD>園𡢿 -1 銝滢<E98A9D>?
std::string SerialNum; //序列<EFBFBD>? std::string SerialNum; //摨誩<EFBFBD>?
std::string Token; //识别<EFBFBD>? std::string Token; //<EFBFBD><EFBFBD>?
u32 clr_maxbright; //彩色平场校正最大亮<EFBFBD>? u32 clr_maxbright; //敶抵𠧧撟喳㦤<EFBFBD>⊥迤<EFBFBD><EFBFBD>憭找漁嚙?
u32 gray_maxbright; //灰度平场校正最大亮<EFBFBD>? u32 gray_maxbright; //<EFBFBD>啣漲撟喳㦤<EFBFBD>⊥迤<EFBFBD><EFBFBD>憭找漁嚙?
u32 speedmode; //速度模式 G100 0->70 1->80 2->90 3->100 G200 0->100 1->110 2->120 3->130 u32 speedmode; //速度模式 G100 0->70 1->80 2->90 3->100 G200 0->100 1->110 2->120 3->130
u16 Vid; //USB vid u16 Vid; //USB vid
u16 Pid; //USB Pid u16 Pid; //USB Pid
@ -265,7 +265,7 @@ enum HGType
STOPSCAN, STOPSCAN,
}; };
//usb int 端点通信结构<EFBFBD>? //usb int 蝡舐<EFBFBD><EFBFBD>帋縑蝏𤘪<EFBFBD>?
struct HGIntInfo struct HGIntInfo
{ {
HGType From; HGType From;
@ -440,7 +440,10 @@ enum Scanner_Reg_Defs
SR_GET_MBVERSION_LENGHT, SR_GET_MBVERSION_LENGHT,
SR_GET_MBVERSION, SR_GET_MBVERSION,
SR_GET_USBVIDPID, SR_GET_USBVIDPID,
SR_SET_USBVIDPID SR_SET_USBVIDPID,
SR_SCAN_DPI = 0x600,
SR_SCAN_CNT,
}; };
enum Updata_Stautus enum Updata_Stautus
@ -662,8 +665,8 @@ typedef struct tagCrop_Rect
int enable; int enable;
int x; /*****自定义裁切区域左上角x坐标*/ int x; /*****自定义裁切区域左上角x坐标*/
int y; /*****自定义裁切区域左上角y坐标*/ int y; /*****自定义裁切区域左上角y坐标*/
int width; /*****自定义裁切区域宽<EFBFBD>?******/ int width; /*****<EFBFBD><EFBFBD>銋㕑<EFBFBD><EFBFBD><EFBFBD><EFBFBD>笔捐嚙?******/
int height; /*****自定义裁切区域高<EFBFBD>?******/ int height; /*****<EFBFBD><EFBFBD>銋㕑<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?******/
}CropRect; }CropRect;
typedef enum tagMulti_Output { typedef enum tagMulti_Output {

View File

@ -36,6 +36,26 @@ void get_system_output(char *cmd, char *output, int size)
} }
} }
static std::string load_mini_file(const char* path)
{
// /root/.scanner/log
FILE *src = fopen(path, "rb");
std::string ret("");
if(src)
{
int len = 0;
fseek(src, 0, SEEK_END);
len = ftell(src);
fseek(src, 0, SEEK_SET);
ret.resize(len);
fread(&ret[0], 1, len, src);
fclose(src);
}
return ret;
}
static const std::string loggername = "ScannerRegAccess"; static const std::string loggername = "ScannerRegAccess";
ScannerRegAccess::ScannerRegAccess(std::shared_ptr<Scanner> scanner, std::shared_ptr<UsbImageProcQueue> usbimages, std::shared_ptr<ITransmit> transmit, std::shared_ptr<IReceive> receiv) ScannerRegAccess::ScannerRegAccess(std::shared_ptr<Scanner> scanner, std::shared_ptr<UsbImageProcQueue> usbimages, std::shared_ptr<ITransmit> transmit, std::shared_ptr<IReceive> receiv)
@ -55,10 +75,43 @@ ScannerRegAccess::~ScannerRegAccess()
bool ScannerRegAccess::write(unsigned int addr, const unsigned int val) bool ScannerRegAccess::write(unsigned int addr, const unsigned int val)
{ {
// printf("write(0x%x, 0x%x), sizeof(unsigned int) = %d, sizeof(long) = %d, sizeof(long long) = %d\n", addr, val static uint64_t img_cb = 0, img_param = 0;
// , sizeof(unsigned int), sizeof(long), sizeof(long long)); static uint32_t scan_dpi = 200, scan_cnt = -1;
printf("ScannerRegAccess::write(%d, %d)\n", addr, val); if(addr == (unsigned int)-1)
{
img_cb = val;
img_cb <<= 32;
printf("image callback (1/2) = %p\n", img_cb);
return true;
}
else if(addr == (unsigned int)-2)
{
img_cb |= val;
return true;
}
else if(addr == (unsigned int)-3)
{
img_param = val;
img_param <<= 32;
printf("image callback (1/2) = %p\n", img_param);
return true;
}
else if(addr == (unsigned int)-4)
{
void(*func)(MemoryPtr, bool, void*) = nullptr;
void* param = nullptr;
img_param |= val;
param = (void*)img_param;
*((uint64_t*)&func) = img_cb;
usbimages->set_image_keeper(func, param);
return true;
}
switch (addr) switch (addr)
{ {
case SR_CMD: case SR_CMD:
@ -100,9 +153,23 @@ bool ScannerRegAccess::write(unsigned int addr, const unsigned int val)
case SR_CONFIG_SCAN_PARAM: case SR_CONFIG_SCAN_PARAM:
scanner->configparam(*((HGScanConfig *)&val)); scanner->configparam(*((HGScanConfig *)&val));
return true; return true;
case SR_SCAN_DPI:
scan_dpi = val;
return true;
case SR_SCAN_CNT:
scan_cnt = val;
return true;
case SR_CONFIF_IMGPROCPARAM: case SR_CONFIF_IMGPROCPARAM:
{ {
printf("\nSR_CONFIF_IMGPROCPARAM size =%d",val); printf("\nSR_CONFIF_IMGPROCPARAM size =%d",val);
#ifdef ASYNC_EP
std::string cfg(load_mini_file("/root/.scanner/log/cfg_4308.bin"));
GScanCap cap = *(GScanCap*)&cfg[0];
cap.resolution_dst = cap.resolution_native = scan_dpi;
cap.scannum = scan_cnt;
printf("DPI: %d, Count: %d\n", scan_dpi, scan_cnt);
#else
std::vector<char> data(val); std::vector<char> data(val);
if(val==0) if(val==0)
data.resize(116); data.resize(116);
@ -111,6 +178,7 @@ bool ScannerRegAccess::write(unsigned int addr, const unsigned int val)
printf("\n gcap size = %d \n",sizeof(GScanCap)); printf("\n gcap size = %d \n",sizeof(GScanCap));
memcpy(capdata,data.data(),std::min(sizeof(GScanCap),data.size())); memcpy(capdata,data.data(),std::min(sizeof(GScanCap),data.size()));
GScanCap cap = *(GScanCap *)capdata; GScanCap cap = *(GScanCap *)capdata;
#endif
scanner->set_hgimgconfig(cap); scanner->set_hgimgconfig(cap);
return true; return true;
} }

View File

@ -25,7 +25,9 @@ class UsbDevice
uint32_t img_cnt_; uint32_t img_cnt_;
uint32_t scan_id_; uint32_t scan_id_;
uint32_t dpi_; uint32_t dpi_;
uint32_t scan_cnt_;
std::string cfg_text_; std::string cfg_text_;
dyn_mem_ptr scan_over_pack_;
dyn_mem_ptr unhandled_ep0(struct usb_functionfs_event* pev); dyn_mem_ptr unhandled_ep0(struct usb_functionfs_event* pev);
dyn_mem_ptr handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required); dyn_mem_ptr handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required);

View File

@ -19,7 +19,7 @@ unsigned long linux_event::to_abs_time_us = 0;
linux_event::linux_event(const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(false) linux_event::linux_event(const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(false)
{ {
log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) unamed for '%s' constructing ...\n", this, desc_.c_str()); //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) unamed for '%s' constructing ...\n", this, desc_.c_str());
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
err_ = 0; err_ = 0;
@ -40,7 +40,7 @@ linux_event::linux_event(const char* desc) : waiting_(false), sem_(nullptr), des
} }
linux_event::linux_event(const char* name, const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(true) linux_event::linux_event(const char* name, const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(true)
{ {
log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) of named '%s' for '%s' constructing ...\n", this, name, desc_.c_str()); //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) of named '%s' for '%s' constructing ...\n", this, name, desc_.c_str());
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
local_sem_ = CreateEventA(NULL, TRUE, FALSE, name); local_sem_ = CreateEventA(NULL, TRUE, FALSE, name);
sem_ = &local_sem_; sem_ = &local_sem_;
@ -93,7 +93,7 @@ linux_event::linux_event(const char* name, const char* desc) : waiting_(false),
} }
linux_event::linux_event(sem_t* mem_sem, bool first, const char* desc) : waiting_(false), sem_(mem_sem), desc_(desc ? desc : ""), first_(first), multi_proc_(true) linux_event::linux_event(sem_t* mem_sem, bool first, const char* desc) : waiting_(false), sem_(mem_sem), desc_(desc ? desc : ""), first_(first), multi_proc_(true)
{ {
log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) at mem(%p) for '%s' constructing ...\n", this, mem_sem, desc_.c_str()); //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) at mem(%p) for '%s' constructing ...\n", this, mem_sem, desc_.c_str());
if(first) if(first)
{ {
@ -138,7 +138,7 @@ linux_event::~linux_event()
#endif #endif
} }
} }
log_cls::log(LOG_LEVEL_ALL, "-linux_event(%p) destroyed.\n", this); //log_cls::log(LOG_LEVEL_ALL, "-linux_event(%p) destroyed.\n", this);
} }
int32_t linux_event::clear_named_event(const char* name) int32_t linux_event::clear_named_event(const char* name)

View File

@ -326,7 +326,7 @@ UsbDevice::UsbDevice(std::function<bool(int, struct usb_ctrlrequest *, unsigned
: b_connected(false) : b_connected(false)
, connect_call(call_back) , connect_call(call_back)
#ifdef ASYNC_EP #ifdef ASYNC_EP
, usb_(nullptr), cfg_(nullptr) , usb_(nullptr), cfg_(nullptr), scan_over_pack_(nullptr)
#endif #endif
{ {
camtp_context.reset(new camtp_ctx); camtp_context.reset(new camtp_ctx);
@ -1734,8 +1734,9 @@ dyn_mem_ptr UsbDevice::handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_
LPCFGVAL cfg = (LPCFGVAL)pack->payload, LPCFGVAL cfg = (LPCFGVAL)pack->payload,
cfg_ret = nullptr; cfg_ret = nullptr;
std::string name(cfg->data + cfg->name_off); std::string name(cfg->data + cfg->name_off);
size_t l = base_head_size + sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1; size_t l = base_head_size + sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1, val_size = cfg->val_size;
int32_t err = 0; int32_t err = 0;
uint32_t after = 0;
reply = dyn_mem::memory(l); reply = dyn_mem::memory(l);
pk = (LPPACK_BASE)reply->ptr(); pk = (LPPACK_BASE)reply->ptr();
@ -1747,8 +1748,11 @@ dyn_mem_ptr UsbDevice::handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_
cfg_ret->val_size = cfg->val_size; cfg_ret->val_size = cfg->val_size;
cfg_ret->max_size = cfg->max_size; cfg_ret->max_size = cfg->max_size;
cfg_ret->type = cfg->type; cfg_ret->type = cfg->type;
err = cfg_->set_config(cfg->data + cfg->name_off, cfg_ret->data + cfg_ret->val_off, (size_t*)&cfg_ret->val_size, (uint32_t*)&cfg_ret->after_do); err = cfg_->set_config(cfg->data + cfg->name_off, cfg_ret->data + cfg_ret->val_off, &val_size, &after);
cfg_ret->after_do = after;
cfg_ret->val_size = val_size;
BASE_PACKET_REPLY(*pk, pack->cmd + 1, pack->pack_id, err); BASE_PACKET_REPLY(*pk, pack->cmd + 1, pack->pack_id, err);
pk->payload_len = sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1;
reply->set_len(l); reply->set_len(l);
} }
break; break;
@ -1822,12 +1826,21 @@ dyn_mem_ptr UsbDevice::handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_
int err = 0; int err = 0;
img_cnt_ = 0; img_cnt_ = 0;
scan_id_ = pack->pack_id; scan_id_ = pack->pack_id;
log_cls::log(LOG_LEVEL_ALL, "Start scanning ...\n"); if(scan_over_pack_)
{
scan_over_pack_->release();
scan_over_pack_ = nullptr;
}
{ {
bool ret = ctrl_handler(-1, (usb_ctrlrequest*)15, (unsigned char*)0x160); // hardware configuration bool ret = ctrl_handler(-1, (usb_ctrlrequest*)15, (unsigned char*)0x160); // hardware configuration
ret = ctrl_handler(-1, (usb_ctrlrequest*)20, (unsigned char*)dpi_); ctrl_handler(-1, (usb_ctrlrequest*)SR_SCAN_CNT, (unsigned char*)scan_cnt_);
ctrl_handler(-1, nullptr, nullptr); ctrl_handler(-1, (usb_ctrlrequest*)SR_SCAN_DPI, (unsigned char*)dpi_);
ctrl_handler(-1, (usb_ctrlrequest*)SR_CONFIF_IMGPROCPARAM, (unsigned char*)0);
log_cls::log(LOG_LEVEL_ALL, "Start scanning with %d DPI ...\n", dpi_);
ret = ctrl_handler(-1, nullptr, nullptr);
log_cls::log(LOG_LEVEL_ALL, "Start scanning %s\n", ret ? "OK" : "Failed");
} }
reply = dyn_mem::memory(base_head_size); reply = dyn_mem::memory(base_head_size);
@ -1871,8 +1884,9 @@ void UsbDevice::init(void)
readonly_cfg* r = new readonly_cfg(); readonly_cfg* r = new readonly_cfg();
size_t l = sizeof(dpi_); size_t l = sizeof(dpi_);
cfg_text_ = "{\"resolution\":{\"category\":\"base\",\"readonly\":false,\"affect\":2,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":[100,150,200,300,600]}}"; cfg_text_ = "{\"resolution\":{\"category\":\"base\",\"readonly\":false,\"affect\":2,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":[100,150,200,300,600]},\"count\":{\"category\":\"base\",\"readonly\":false,\"affect\":0,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u5f20\\u6570\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u7684\\u7eb8\\u5f20\\u6570\\u91cf\",\"type\":\"int\",\"cur\":-1,\"default\":-1,\"size\":4,\"range\":[-1,1]}}";
l = get_config(&dpi_, &l, "resolution"); l = get_config(&dpi_, &l, "resolution");
l = get_config(&scan_cnt_, &l, "count");
cfg_ = new sane_cfg_mgr(); cfg_ = new sane_cfg_mgr();
cfg_->reg_sane_provider(dynamic_cast<sane_cfg_provider*>(r)); cfg_->reg_sane_provider(dynamic_cast<sane_cfg_provider*>(r));
l = cfg_->reg_sane_provider(dynamic_cast<sane_cfg_provider*>(this)); l = cfg_->reg_sane_provider(dynamic_cast<sane_cfg_provider*>(this));
@ -1895,6 +1909,18 @@ void UsbDevice::save_image(MemoryPtr data, bool img)
log_cls::log(LOG_LEVEL_ALL, "New image with bytes: %u\n", data->size()); log_cls::log(LOG_LEVEL_ALL, "New image with bytes: %u\n", data->size());
usb_->write_bulk(ip); usb_->write_bulk(ip);
ip->release(); ip->release();
// check has completed ?
if(scan_over_pack_)
{
ctrl_handler(-2, (usb_ctrlrequest*)SR_GET_IMAGEPROCESSDONE, (unsigned char*)&n);
if(n)
{
usb_->write_bulk(scan_over_pack_);
scan_over_pack_->release();
scan_over_pack_ = nullptr;
}
}
} }
else else
{ {
@ -1954,14 +1980,22 @@ void UsbDevice::save_image(MemoryPtr data, bool img)
{ {
cmd = PACK_CMD_SCAN_FINISHED_ROGER; cmd = PACK_CMD_SCAN_FINISHED_ROGER;
} }
if(scan_id_ && cmd == PACK_CMD_SCAN_FINISHED_ROGER) if(scan_id_ && cmd == PACK_CMD_SCAN_FINISHED_ROGER && scan_over_pack_ == nullptr)
{ {
log_cls::log(LOG_LEVEL_ALL, "Scan over with error: %d\n", err); log_cls::log(LOG_LEVEL_ALL, "Scan over with error: %d\n", err);
BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), cmd, scan_id_, err); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), cmd, scan_id_, err);
reply->set_len(sizeof(PACK_BASE)); reply->set_len(sizeof(PACK_BASE));
scan_id_ = 0; scan_id_ = 0;
// check if the image-proc-queue has completed ...
ctrl_handler(-2, (usb_ctrlrequest*)SR_GET_IMAGEPROCESSDONE, (unsigned char*)&err);
if(err)
usb_->write_bulk(reply); usb_->write_bulk(reply);
else
{
scan_over_pack_ = reply;
scan_over_pack_->add_ref();
}
} }
reply->release(); reply->release();
} }
@ -2058,6 +2092,21 @@ int32_t UsbDevice::set_config(const char* cfg_name, void* data, size_t* len, uin
log_cls::log(LOG_LEVEL_ALL, "Set %s to %d\n", cfg_name, dpi_); log_cls::log(LOG_LEVEL_ALL, "Set %s to %d\n", cfg_name, dpi_);
cfg_text_ = jsn->to_string(); cfg_text_ = jsn->to_string();
} }
else if(strcmp(cfg_name, "count") == 0)
{
child->get_value("cur", val);
ret = EUCLEAN;
val = *(int*)data;
if(val == -1 || val == 1)
ret = 0;
else
val = -1;
*(int*)data = val;
child->set_value("cur", val);
scan_cnt_ = val;
log_cls::log(LOG_LEVEL_ALL, "Set %s to %d\n", cfg_name, scan_cnt_);
cfg_text_ = jsn->to_string();
}
child->release(); child->release();
} }
jsn->release(); jsn->release();

View File

@ -102,6 +102,14 @@ UsbService::UsbService(std::shared_ptr<IRegsAccess> fgparegs, std::shared_ptr<IR
} }
return true; return true;
} }
else if(fd == -2) // read
{
unsigned int addr = (unsigned int)(uint64_t)setup,
val = 0;
devregs->read(addr, val);
*(unsigned int*)buffer = val;
}
printf("req = %x, type = %x, ind = %x, len = %x, val = %x\n", setup->bRequest, setup->bRequestType, setup->wIndex, setup->wLength, setup->wValue); printf("req = %x, type = %x, ind = %x, len = %x, val = %x\n", setup->bRequest, setup->bRequestType, setup->wIndex, setup->wLength, setup->wValue);
if (!(setup->bRequestType & USB_TYPE_VENDOR) || (setup->bRequestType & USB_RECIP_MASK) != USB_RECIP_DEVICE) if (!(setup->bRequestType & USB_TYPE_VENDOR) || (setup->bRequestType & USB_RECIP_MASK) != USB_RECIP_DEVICE)

View File

@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release")
target("gusb") target("gusb")
set_kind("static") set_kind("static")
add_syslinks("pthread") add_syslinks("pthread")
add_files("*.cpp", "src/*.cpp", "src/common/*.cpp") add_files("*.cpp", "src/*.cpp", "src/common/*.cpp", "src/common/json/*.c*")
add_includedirs("inc") add_includedirs("inc")
add_includedirs("src/common") add_includedirs("src/common")
add_includedirs(".", { public = true}) add_includedirs(".", { public = true})

View File

@ -667,6 +667,9 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp)
KillTimer(TIMER_ID_REFRESH_BULK); KillTimer(TIMER_ID_REFRESH_BULK);
((CButton*)GetDlgItem(IDC_CHECK_AUTO))->SetCheck(BST_UNCHECKED); ((CButton*)GetDlgItem(IDC_CHECK_AUTO))->SetCheck(BST_UNCHECKED);
enable_buttons(pnp != NULL); enable_buttons(pnp != NULL);
GetDlgItem(IDC_CHECK_AUTO)->EnableWindow(pnp != NULL);
GetDlgItem(IDC_BUTTON_RESET_BULK)->EnableWindow(pnp != NULL);
GetDlgItem(IDC_BUTTON_REFRESH)->EnableWindow(pnp != NULL);
if (scanner_) if (scanner_)
{ {
@ -687,6 +690,8 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp)
{ {
CDlgScanner* dlg = (CDlgScanner*)user_data; CDlgScanner* dlg = (CDlgScanner*)user_data;
log_cls::log(LOG_LEVEL_DEBUG, "Finished in receiving new image = %d\r\n", err);
if (err) if (err)
//::SetDlgItemTextW(m_hWnd, IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str()); //::SetDlgItemTextW(m_hWnd, IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str());
dlg->set_text(IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str()); dlg->set_text(IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str());
@ -707,9 +712,12 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp)
file_saver* saver = new file_saver(); file_saver* saver = new file_saver();
std::string root(usb::u2a(img_root_.c_str())); std::string root(usb::u2a(img_root_.c_str()));
char name[40] = { 0 }; char name[40] = { 0 };
int err = 0;
sprintf_s(name, _countof(name) - 1, "scan_%04d.jpg", ++img_cnt_); sprintf_s(name, _countof(name) - 1, "scan_%04d.jpg", ++img_cnt_);
if (saver->open((root + name).c_str(), size)) err = saver->open((root + name).c_str(), size);
log_cls::log(LOG_LEVEL_DEBUG, "Begin receiving new image (%s + %llu) = %d\r\n", (root + name).c_str(), size, err);
if (err)
{ {
saver->release(); saver->release();
saver = NULL; saver = NULL;
@ -733,6 +741,8 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp)
::SetTextColor(dc, size ? RGB(255, 0, 0) : RGB(0, 0, 0)); ::SetTextColor(dc, size ? RGB(255, 0, 0) : RGB(0, 0, 0));
::ReleaseDC(wnd, dc); ::ReleaseDC(wnd, dc);
log_cls::log(LOG_LEVEL_DEBUG, "Scan stopped with error %s\r\n", usb::u2a(scanner_status(size, buf)).c_str());
if (size) if (size)
set_text(IDC_EDIT_COUNT, (std::to_wstring(img_cnt_) + L" (Error: " + scanner_status(size, buf) + L")").c_str()); set_text(IDC_EDIT_COUNT, (std::to_wstring(img_cnt_) + L" (Error: " + scanner_status(size, buf) + L")").c_str());
else else
@ -1174,6 +1184,7 @@ void CDlgScanner::OnBnClickedButtonScan()
if (scanner_) if (scanner_)
{ {
int err = scanner_->scan_start(); int err = scanner_->scan_start();
log_cls::log(LOG_LEVEL_DEBUG, "Start to scan = %d\r\n", err);
if (err) if (err)
msg_box(m_hWnd, MB_OK, L"Error", L"Failed in startin scanning with code %d", err); msg_box(m_hWnd, MB_OK, L"Error", L"Failed in startin scanning with code %d", err);
else else

View File

@ -88,8 +88,9 @@
#define IDC_STATIC_CMD_QUE 1061 #define IDC_STATIC_CMD_QUE 1061
#define IDC_STATIC_SENT_QUE 1062 #define IDC_STATIC_SENT_QUE 1062
#define IDC_STATIC_OPTS 1063 #define IDC_STATIC_OPTS 1063
#define IDC_CHECK1 1064
#define IDC_CHECK_AUTO_OPEN_IMG 1064 #define IDC_CHECK_AUTO_OPEN_IMG 1064
#define IDC_EDIT1 1065
#define IDC_EDIT_LOG_FILE 1065
#define ID_TRAY_EXIT 32771 #define ID_TRAY_EXIT 32771
// Next default values for new objects // Next default values for new objects
@ -98,7 +99,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 137 #define _APS_NEXT_RESOURCE_VALUE 137
#define _APS_NEXT_COMMAND_VALUE 32772 #define _APS_NEXT_COMMAND_VALUE 32772
#define _APS_NEXT_CONTROL_VALUE 1065 #define _APS_NEXT_CONTROL_VALUE 1066
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

View File

@ -574,6 +574,7 @@ int scanner_handler::scan_start(void)
{ {
auto call = [&](cmd_result* cmd) -> int auto call = [&](cmd_result* cmd) -> int
{ {
cmd->set_timeout(4000);
return usb_->scan_start(cmd->get_id()); return usb_->scan_start(cmd->get_id());
}; };
auto clean = [&](cmd_result* cmd) -> int auto clean = [&](cmd_result* cmd) -> int

View File

@ -271,6 +271,7 @@ CusbtoolsDlg::CusbtoolsDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_USB_TOOLS_DIALOG, pParent) : CDialogEx(IDD_USB_TOOLS_DIALOG, pParent)
{ {
log_cls::initialize(NULL); log_cls::initialize(NULL);
log_cls::log(LOG_LEVEL_DEBUG, "--------------------New instance started ...--------------------\r\n");
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
} }
@ -347,6 +348,7 @@ BOOL CusbtoolsDlg::OnInitDialog()
usb::register_tray(m_hWnd, m_hIcon, true); usb::register_tray(m_hWnd, m_hIcon, true);
SetPropW(m_hWnd, L"task_usb", m_hWnd); SetPropW(m_hWnd, L"task_usb", m_hWnd);
::SetDlgItemTextA(m_hWnd, IDC_EDIT_LOG_FILE, log_cls::get_log_file().c_str());
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
} }
@ -533,6 +535,7 @@ void CusbtoolsDlg::log_pnp(usb::LPUSBPNP pnp)
swprintf_s(buf + lstrlenW(buf), _countof(buf) - 1, L"%s: %04X:%04X %s\r\n", usb::now().c_str(), swprintf_s(buf + lstrlenW(buf), _countof(buf) - 1, L"%s: %04X:%04X %s\r\n", usb::now().c_str(),
pnp->vid, pnp->pid, pnp->arrive ? L"Arrive" : L"Left"); pnp->vid, pnp->pid, pnp->arrive ? L"Arrive" : L"Left");
append_log(buf, IDC_EDIT_PNP_MSG); append_log(buf, IDC_EDIT_PNP_MSG);
log_cls::log(LOG_LEVEL_ALL, "%04X:%04X %s\r\n", pnp->vid, pnp->pid, pnp->arrive ? "Arrived" : "Left");
} }
bool CusbtoolsDlg::endpoint_from_combo_text(wchar_t* text, BYTE& type, BYTE& addr) bool CusbtoolsDlg::endpoint_from_combo_text(wchar_t* text, BYTE& type, BYTE& addr)
{ {
@ -666,6 +669,13 @@ LRESULT CusbtoolsDlg::OnUsbPnp(WPARAM wp, LPARAM lp)
usb::LPUSBPNP pnp = (usb::LPUSBPNP)lp; usb::LPUSBPNP pnp = (usb::LPUSBPNP)lp;
log_pnp(pnp); log_pnp(pnp);
if (pnp->pid == 0 && pnp->vid == 0)
{
delete pnp;
return 0;
}
if (pnp->arrive) if (pnp->arrive)
{ {
////for (auto& v : pnp_que_) ////for (auto& v : pnp_que_)