调整启动流程以适应第三方APP调用
This commit is contained in:
parent
eb83eec0d5
commit
d93d82f5ec
|
@ -1676,12 +1676,11 @@ int hg_scanner::try_third_app_after_start(int err)
|
||||||
{
|
{
|
||||||
if (!async_io_)
|
if (!async_io_)
|
||||||
{
|
{
|
||||||
if (wait_usb_result_.wait(500))
|
while (wait_img_.is_waiting() && !wait_usb_.is_waiting())
|
||||||
{
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
if (status_ != SCANNER_ERR_DEVICE_BUSY && status_ != SCANNER_ERR_OK)
|
if (wait_img_.is_waiting() && wait_usb_.is_waiting())
|
||||||
err = status_;
|
err = status_;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -2154,6 +2153,9 @@ std::string hg_scanner::name(void)
|
||||||
}
|
}
|
||||||
int hg_scanner::status(void)
|
int hg_scanner::status(void)
|
||||||
{
|
{
|
||||||
|
if (!wait_usb_.is_waiting() || !wait_img_.is_waiting())
|
||||||
|
return SCANNER_ERR_DEVICE_BUSY;
|
||||||
|
else
|
||||||
return status_;
|
return status_;
|
||||||
}
|
}
|
||||||
bool hg_scanner::is_online(void)
|
bool hg_scanner::is_online(void)
|
||||||
|
|
|
@ -450,16 +450,18 @@ int hg_scanner_200::start(void)
|
||||||
|
|
||||||
ret = writeusb(usb);
|
ret = writeusb(usb);
|
||||||
io_->set_timeout(500);
|
io_->set_timeout(500);
|
||||||
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start is.(%s)\n", hg_scanner_err_name(ret));
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "write start command = %s\n", hg_scanner_err_name(ret));
|
||||||
|
|
||||||
if(ret == SCANNER_ERR_OK)
|
if(ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
status_ = SCANNER_ERR_DEVICE_BUSY;
|
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||||
wait_usb_.notify();
|
wait_usb_.notify();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||||
|
ret = try_third_app_after_start(ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1388,7 +1388,7 @@ void hg_scanner_239::thread_handle_usb_read(void)
|
||||||
to_cnt = 0,
|
to_cnt = 0,
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
status_ = SCANNER_ERR_DEVICE_BUSY;
|
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||||
while (run_ )//&& !user_cancel_
|
while (run_ )//&& !user_cancel_
|
||||||
{
|
{
|
||||||
if (user_cancel_)
|
if (user_cancel_)
|
||||||
|
@ -1617,83 +1617,23 @@ int hg_scanner_239::start(void)
|
||||||
|
|
||||||
ret = write_command(SC_START);
|
ret = write_command(SC_START);
|
||||||
|
|
||||||
VLOG_MINI_1(LOG_LEVEL_WARNING, "start status02 is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
|
|
||||||
io_->set_timeout(1000);
|
io_->set_timeout(1000);
|
||||||
if (ret == SCANNER_ERR_OK)
|
if (ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Write SC_START command success, and now scanner stauts is %x\n", get_status());
|
|
||||||
|
|
||||||
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||||
wait_usb_.notify();
|
wait_usb_.notify();
|
||||||
this_thread::sleep_for(chrono::milliseconds(100));
|
this_thread::sleep_for(chrono::milliseconds(100));
|
||||||
|
ret = try_third_app_after_start(ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status_ = ret;
|
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_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;
|
return ret;
|
||||||
}
|
}
|
||||||
//int hg_scanner_239::get_image_info(IMG_PARAM* ii)
|
|
||||||
//{
|
|
||||||
// int ret = SCANNER_ERR_OK;
|
|
||||||
// IMH imh;
|
|
||||||
//
|
|
||||||
// bzero(&imh, sizeof(imh));
|
|
||||||
// while((!wait_img_.is_waiting() || !wait_usb_.is_waiting()) && final_imgs_.Size() <= 0)
|
|
||||||
// this_thread::sleep_for(chrono::milliseconds(10));
|
|
||||||
//
|
|
||||||
// if (final_imgs_.Size() <= 0)
|
|
||||||
// ret = status_;
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (!final_imgs_.front(&imh))
|
|
||||||
// ret = SCANNER_ERR_NO_DATA;
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS)
|
|
||||||
// ii->format = FRAME_RGB;
|
|
||||||
// else
|
|
||||||
// ii->format = FRAME_GRAY;
|
|
||||||
// ii->depth = 8; // 此处指每一个颜色分量的位深,我们的扫描仪固定为“8”
|
|
||||||
// ii->last_frame = true; // 一幅图片如果各个分量相互分离,则最后一个分量的时候设置为true。彩色图像RGB时也只有一“帧”,所以也为true
|
|
||||||
// ii->bytes_per_line = imh.line_bytes;
|
|
||||||
// ii->pixels_per_line = imh.width;
|
|
||||||
// ii->lines = imh.height;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "Get image info(%d * %d * %d) = %s\n", ii->pixels_per_line, ii->lines, imh.bits, hg_scanner_err_name(ret));
|
|
||||||
//
|
|
||||||
// return ret;
|
|
||||||
//}
|
|
||||||
//int hg_scanner_239::read_image_data(unsigned char* buf, int* len)
|
|
||||||
//{
|
|
||||||
// if (!len)
|
|
||||||
// return SCANNER_ERR_INVALID_PARAMETER;
|
|
||||||
//
|
|
||||||
// if (!buf)
|
|
||||||
// {
|
|
||||||
// IMH imh;
|
|
||||||
// final_imgs_.front(&imh);
|
|
||||||
// *len = imh.bytes;
|
|
||||||
//
|
|
||||||
// return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (final_imgs_.Size() > 0)
|
|
||||||
// {
|
|
||||||
// int fetch = *len;
|
|
||||||
//
|
|
||||||
// final_imgs_.fetch_front(buf, len);
|
|
||||||
// VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "[%s]UI fetch image 0x%x/0x%x to buf %s...\n", hg_log::format_current_thread_id().c_str(), *len, fetch
|
|
||||||
// , hg_log::format_ptr(buf).c_str());
|
|
||||||
//
|
|
||||||
// return SCANNER_ERR_OK;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// return SCANNER_ERR_NO_DATA;
|
|
||||||
//}
|
|
||||||
int hg_scanner_239::stop(void)
|
int hg_scanner_239::stop(void)
|
||||||
{
|
{
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
|
|
|
@ -395,16 +395,16 @@ void hg_scanner_300::thread_handle_usb_read(void)
|
||||||
USBCB usb = {START_COMMAND, img_conf_.scannum, 0};
|
USBCB usb = {START_COMMAND, img_conf_.scannum, 0};
|
||||||
ret = writeusb(usb);
|
ret = writeusb(usb);
|
||||||
io_->set_timeout(500);
|
io_->set_timeout(500);
|
||||||
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start is.(%s)\n", hg_scanner_err_name(ret));
|
|
||||||
|
|
||||||
if(ret == SCANNER_ERR_OK)
|
if(ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
status_ = SCANNER_ERR_DEVICE_BUSY;
|
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||||
wait_usb_.notify();
|
wait_usb_.notify();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||||
|
ret = try_third_app_after_start(ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,12 +396,14 @@ int hg_scanner_400::start(void)
|
||||||
|
|
||||||
if(ret == SCANNER_ERR_OK)
|
if(ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
status_ = SCANNER_ERR_DEVICE_BUSY;
|
//status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||||
wait_usb_.notify();
|
wait_usb_.notify();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||||
|
ret = try_third_app_after_start(ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue