修复3399系列纸张计数;修复control_io返回值

This commit is contained in:
gb 2022-07-21 17:54:58 +08:00
parent bcf3063818
commit c8ef08d47a
3 changed files with 53 additions and 2 deletions

View File

@ -1944,7 +1944,10 @@ int hg_scanner::save_usb_data(std::shared_ptr<tiny_buffer> data)
wait_img_.notify();
}
unsigned int bytes = data->size();
ui_ev_cb_((scanner_handle)this, SANE_EVENT_USB_DATA_RECEIVED, NULL, &bytes, NULL);
int type = io_->get_pid() & 0x0ff;
if(type != 0x39 || (usb_img_index_ & 1))
ui_ev_cb_((scanner_handle)this, SANE_EVENT_USB_DATA_RECEIVED, NULL, &bytes, NULL);
return ret;
}

View File

@ -835,7 +835,6 @@ int usb_io::control_io(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, vo
int ret = libusb_control_transfer(handle_, type, req, val, ind, (unsigned char*)buf, *len, to_);
*len = 0;
if (ret > 0)
{
*len = ret;
@ -855,7 +854,11 @@ int usb_io::control_io(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, vo
return last_err_;
}
else
*len = 0;
}
else
*len = 0;
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "libusb_control_transfer(%x, %x, %d, %d) = %s\n", type, req, val, ind, libusb_error_name(ret));
last_err_ = usb_manager::usb_error_2_hg_err(ret);
}

View File

@ -28,6 +28,48 @@ std::string g_scanner_path = "";
static std::string g_sane_name = "";
static std::string g_sane_ver = "";
namespace err_map
{
struct
{
int sane;
int scanner;
}g_err_map[] =
{ {SANE_STATUS_GOOD, SCANNER_ERR_OK}
, {SANE_STATUS_UNSUPPORTED, SCANNER_ERR_DEVICE_NOT_SUPPORT}
, {SANE_STATUS_CANCELLED, SCANNER_ERR_USER_CANCELED}
, {SANE_STATUS_DEVICE_BUSY, SCANNER_ERR_DEVICE_BUSY}
, {SANE_STATUS_INVAL, SCANNER_ERR_INVALID_PARAMETER}
, {SANE_STATUS_EOF, SCANNER_ERR_NO_DATA}
, {SANE_STATUS_JAMMED, SCANNER_ERR_DEVICE_PAPER_JAMMED}
, {SANE_STATUS_NO_DOCS, SCANNER_ERR_DEVICE_NO_PAPER}
, {SANE_STATUS_COVER_OPEN, SCANNER_ERR_DEVICE_COVER_OPENNED}
, {SANE_STATUS_IO_ERROR, SCANNER_ERR_IO}
, {SANE_STATUS_NO_MEM, SCANNER_ERR_INSUFFICIENT_MEMORY}
, {SANE_STATUS_ACCESS_DENIED, SCANNER_ERR_ACCESS_DENIED}
};
static int sane_2_scanner(int sane)
{
for (size_t i = 0; i < _countof(g_err_map); ++i)
{
if (g_err_map[i].sane == sane)
return g_err_map[i].scanner;
}
return sane;
}
static int scanner_2_sane(int scanner)
{
for (size_t i = 0; i < _countof(g_err_map); ++i)
{
if (g_err_map[i].scanner == scanner)
return g_err_map[i].sane;
}
return scanner;
}
}
extern "C"
{
scanner_err hg_scanner_initialize(sane_callback callback, void* reserve)
@ -200,6 +242,9 @@ extern "C"
}
const char* hg_scanner_err_description(int err)
{
if (err < 0x100)
err = err_map::sane_2_scanner(err);
RETURN_DESC_IF(err, SCANNER_ERR_OK);
RETURN_DESC_IF(err, SCANNER_ERR_DEVICE_NOT_SUPPORT);
RETURN_DESC_IF(err, SCANNER_ERR_USER_CANCELED);