add packet GOOD_BYE; fix bugs when exiting app
This commit is contained in:
parent
fbe158c845
commit
742dcd1535
|
@ -264,13 +264,17 @@ int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler)
|
||||||
}
|
}
|
||||||
int scanner_hw::start_scan(void)
|
int scanner_hw::start_scan(void)
|
||||||
{
|
{
|
||||||
|
if(!camera_.get())
|
||||||
|
return EBADF;
|
||||||
|
|
||||||
camera_->start();
|
camera_->start();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int scanner_hw::stop_scan(void)
|
int scanner_hw::stop_scan(void)
|
||||||
{
|
{
|
||||||
camera_->stop();
|
if(camera_.get())
|
||||||
|
camera_->stop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,6 +449,8 @@ uint32_t async_scanner::stop(void)
|
||||||
{
|
{
|
||||||
usb_->stop();
|
usb_->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
int async_scanner::last_error(void)
|
int async_scanner::last_error(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ enum cancel_io
|
||||||
enum ep0_req
|
enum ep0_req
|
||||||
{
|
{
|
||||||
USB_REQ_EP0_HAND_SHAKE = 100, // hand-shake[in/out] with data LPPEERCFG, req = me, ind = 0, val = 0, len = sizeof(PEERCFG)
|
USB_REQ_EP0_HAND_SHAKE = 100, // hand-shake[in/out] with data LPPEERCFG, req = me, ind = 0, val = 0, len = sizeof(PEERCFG)
|
||||||
|
USB_REQ_EP0_GOOD_BYE, // disconnect, req = me, ind = 0, val = 0, len = sizeof(PEERCFG)
|
||||||
USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = bool: whether write log, len = sizeof(EP0REPLYSTATUS)
|
USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = bool: whether write log, len = sizeof(EP0REPLYSTATUS)
|
||||||
USB_REQ_EP0_CANCEL_IO, // 设置当前IO数据的有效性. req = me, ind = 0, val = 0, len = sizeof(uint32_t), discard IO data when data is CANCEL_IO_CANCEL
|
USB_REQ_EP0_CANCEL_IO, // 设置当前IO数据的有效性. req = me, ind = 0, val = 0, len = sizeof(uint32_t), discard IO data when data is CANCEL_IO_CANCEL
|
||||||
// work-flow: write control with 'CANCEL_IO_CANCEL', write bulk with 1 byte, write control with not 'CANCEL_IO_CANCEL' to restore
|
// work-flow: write control with 'CANCEL_IO_CANCEL', write bulk with 1 byte, write control with not 'CANCEL_IO_CANCEL' to restore
|
||||||
|
|
|
@ -62,7 +62,8 @@ async_usb_gadget::async_usb_gadget(std::function<FUNCTION_PROTO_COMMAND_HANDLE>
|
||||||
if(err == 0)
|
if(err == 0)
|
||||||
{
|
{
|
||||||
thread_write_bulk(fd);
|
thread_write_bulk(fd);
|
||||||
dev_->close_endpoint(EP_IND_BULK_IN);
|
if(run_)
|
||||||
|
dev_->close_endpoint(EP_IND_BULK_IN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -80,7 +81,8 @@ async_usb_gadget::async_usb_gadget(std::function<FUNCTION_PROTO_COMMAND_HANDLE>
|
||||||
if(err == 0)
|
if(err == 0)
|
||||||
{
|
{
|
||||||
thread_read_bulk(fd);
|
thread_read_bulk(fd);
|
||||||
dev_->close_endpoint(EP_IND_BULK_OUT);
|
if(run_)
|
||||||
|
dev_->close_endpoint(EP_IND_BULK_OUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -284,6 +286,13 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_setup(dyn_mem_ptr data)
|
||||||
utils::to_log(LOG_LEVEL_DEBUG, "Host process %llu connected.\n", host_pid_);
|
utils::to_log(LOG_LEVEL_DEBUG, "Host process %llu connected.\n", host_pid_);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case USB_REQ_EP0_GOOD_BYE:
|
||||||
|
{
|
||||||
|
host_pid_ = ((LPPEERCFG)(pev + 1))->pid;
|
||||||
|
utils::to_log(LOG_LEVEL_DEBUG, "Host process %llu disconnected.\n", host_pid_);
|
||||||
|
host_pid_ = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case USB_REQ_EP0_GET_STATUS:
|
case USB_REQ_EP0_GET_STATUS:
|
||||||
reply = dyn_mem::memory(sizeof(struct _ep0_reply));
|
reply = dyn_mem::memory(sizeof(struct _ep0_reply));
|
||||||
reply->set_len(sizeof(struct _ep0_reply));
|
reply->set_len(sizeof(struct _ep0_reply));
|
||||||
|
@ -459,7 +468,7 @@ void async_usb_gadget::thread_read_ep0(void)
|
||||||
while(run_)
|
while(run_)
|
||||||
{
|
{
|
||||||
ret = wait_fd_event(fd);
|
ret = wait_fd_event(fd);
|
||||||
if( ret <= 0 )
|
if( !run_ || ret <= 0 )
|
||||||
{
|
{
|
||||||
utils::to_log(LOG_LEVEL_ALL, "select EP0(%d) failed: %d(%s)\n", fd, errno, strerror(errno));
|
utils::to_log(LOG_LEVEL_ALL, "select EP0(%d) failed: %d(%s)\n", fd, errno, strerror(errno));
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue