恢复200通信代码,修改SANE_Gamma结构
This commit is contained in:
parent
ac6c138fb3
commit
a88d505c25
|
@ -26,7 +26,7 @@ hg_scanner::hg_scanner(ScannerSerial serial
|
||||||
{
|
{
|
||||||
paper_size_mm_.cx = 210;
|
paper_size_mm_.cx = 210;
|
||||||
paper_size_mm_.cy = 297;
|
paper_size_mm_.cy = 297;
|
||||||
custom_gamma_val_.pt_count = 0;
|
custom_gamma_val_.pt_count_r = custom_gamma_val_.pt_count_g = custom_gamma_val_.pt_count_b = 0;
|
||||||
for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i)
|
for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i)
|
||||||
custom_gamma_val_.table[i] = i & 0x0ff;
|
custom_gamma_val_.table[i] = i & 0x0ff;
|
||||||
|
|
||||||
|
@ -455,7 +455,7 @@ int hg_scanner::restore(int setting_no)
|
||||||
setting_jsn_.at(key).at("name").get_to(val);
|
setting_jsn_.at(key).at("name").get_to(val);
|
||||||
if (val == KNOWN_OPT_NAME_CUSTOM_GAMMA)
|
if (val == KNOWN_OPT_NAME_CUSTOM_GAMMA)
|
||||||
{
|
{
|
||||||
custom_gamma_val_.pt_count = 0;
|
custom_gamma_val_.pt_count_r = custom_gamma_val_.pt_count_g = custom_gamma_val_.pt_count_b = 0;
|
||||||
for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i)
|
for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i)
|
||||||
custom_gamma_val_.table[i] = i & 0x0ff;
|
custom_gamma_val_.table[i] = i & 0x0ff;
|
||||||
|
|
||||||
|
|
|
@ -207,12 +207,7 @@ enum hg_239_setting_item
|
||||||
|
|
||||||
|
|
||||||
hg_scanner_200::hg_scanner_200(const char* dev_name,int pid, usb_io* io) : hg_scanner(G100Serial, dev_name, io), pid_(pid)
|
hg_scanner_200::hg_scanner_200(const char* dev_name,int pid, usb_io* io) : hg_scanner(G100Serial, dev_name, io), pid_(pid)
|
||||||
, buf_read_img_len_(512 * 1024), buf_read_img_(nullptr), io_read_img_(0)
|
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
|
||||||
buf_read_img_ = new char[buf_read_img_len_];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
string fw = get_firmware_version();
|
string fw = get_firmware_version();
|
||||||
HG_VLOG_MINI_1(HG_LOG_LEVEL_DEBUG_INFO, "get_firmware_version is: %s\n",fw.c_str());
|
HG_VLOG_MINI_1(HG_LOG_LEVEL_DEBUG_INFO, "get_firmware_version is: %s\n",fw.c_str());
|
||||||
// initdevice();
|
// initdevice();
|
||||||
|
@ -225,35 +220,33 @@ hg_scanner_200::hg_scanner_200(const char* dev_name,int pid, usb_io* io) : hg_sc
|
||||||
printf_devconfig();
|
printf_devconfig();
|
||||||
}
|
}
|
||||||
hg_scanner_200::~hg_scanner_200()
|
hg_scanner_200::~hg_scanner_200()
|
||||||
{
|
{}
|
||||||
if (buf_read_img_)
|
|
||||||
delete[] buf_read_img_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hg_scanner_200::discard_prev(void)
|
void hg_scanner_200::discard_prev(void)
|
||||||
{
|
{
|
||||||
int ret = get_scanner_status(),
|
USBCB usb = { 0 };
|
||||||
|
int ret = get_scanner_status(usb),
|
||||||
imgs = 0,
|
imgs = 0,
|
||||||
packets = 0,
|
packets = 0,
|
||||||
normal = 0;
|
normal = 0;
|
||||||
|
|
||||||
while (ret == HG_ERR_OK)
|
while (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
if (buf_statu_.data.u32_Data == HAVE_IMAGE)
|
if (usb.u32_Data == HAVE_IMAGE)
|
||||||
{
|
{
|
||||||
pop_image();
|
pop_image();
|
||||||
imgs++;
|
imgs++;
|
||||||
normal = 0;
|
normal = 0;
|
||||||
packets++;
|
packets++;
|
||||||
}
|
}
|
||||||
else if (buf_statu_.data.u32_Data == NORMAL)
|
else if (usb.u32_Data == NORMAL)
|
||||||
{
|
{
|
||||||
if(normal++ > 10)
|
if(normal++ > 10)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
packets++;
|
packets++;
|
||||||
ret = get_scanner_status();
|
ret = get_scanner_status(usb);
|
||||||
}
|
}
|
||||||
if (imgs || packets)
|
if (imgs || packets)
|
||||||
HG_VLOG_MINI_2(HG_LOG_LEVEL_DEBUG_INFO, "discard prev-scanning %d packets and %d images.\n", packets, imgs);
|
HG_VLOG_MINI_2(HG_LOG_LEVEL_DEBUG_INFO, "discard prev-scanning %d packets and %d images.\n", packets, imgs);
|
||||||
|
@ -343,7 +336,8 @@ void hg_scanner_200::thread_handle_usb_read(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = get_scanner_status();
|
USBCB usb = {0};
|
||||||
|
ret = get_scanner_status(usb);
|
||||||
|
|
||||||
if (ret == HG_ERR_DEVICE_NOT_FOUND)
|
if (ret == HG_ERR_DEVICE_NOT_FOUND)
|
||||||
{
|
{
|
||||||
|
@ -351,9 +345,9 @@ void hg_scanner_200::thread_handle_usb_read(void)
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (buf_statu_.data.u32_Data == HAVE_IMAGE)
|
else if (usb.u32_Data == HAVE_IMAGE)
|
||||||
{
|
{
|
||||||
ret = get_img_data(buf_statu_.data.u32_Count);
|
ret = get_img_data(usb.u32_Count);
|
||||||
io_->set_timeout(200);
|
io_->set_timeout(200);
|
||||||
pop_image();
|
pop_image();
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
@ -372,10 +366,10 @@ void hg_scanner_200::thread_handle_usb_read(void)
|
||||||
{
|
{
|
||||||
// if the error occurs at the 2nd paper, then the first normal paper maybe lost, we delay 2 seconds here ...
|
// if the error occurs at the 2nd paper, then the first normal paper maybe lost, we delay 2 seconds here ...
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
get_scanner_status();
|
get_scanner_status(usb);
|
||||||
if (buf_statu_.data.u32_Data == HAVE_IMAGE)
|
if (usb.u32_Data == HAVE_IMAGE)
|
||||||
{
|
{
|
||||||
get_img_data(buf_statu_.data.u32_Count);
|
get_img_data(usb.u32_Count);
|
||||||
io_->set_timeout(200);
|
io_->set_timeout(200);
|
||||||
pop_image();
|
pop_image();
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
@ -483,6 +477,21 @@ int hg_scanner_200::writeusb(USBCB &usb)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
int hg_scanner_200::readusb(USBCB &usb)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
|
|
||||||
|
int ret = HG_ERR_OK;
|
||||||
|
int len = sizeof(USBCB);
|
||||||
|
|
||||||
|
ret = io_->read_bulk(&usb,&len);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
status_ = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
int hg_scanner_200::pop_image()
|
int hg_scanner_200::pop_image()
|
||||||
{
|
{
|
||||||
int ret = HG_ERR_OK;
|
int ret = HG_ERR_OK;
|
||||||
|
@ -492,43 +501,35 @@ int hg_scanner_200::pop_image()
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int hg_scanner_200::get_scanner_status(void)
|
int hg_scanner_200::get_scanner_status(USBCB &usb)
|
||||||
{
|
{
|
||||||
int ret = HG_ERR_OK;
|
int ret = HG_ERR_OK;
|
||||||
|
|
||||||
buf_statu_ = {GET_DSP_STATUS, 0, 0};
|
usb = {GET_DSP_STATUS, 0, 0};
|
||||||
|
|
||||||
ret = writeusb(buf_statu_.data);
|
ret = writeusb(usb);
|
||||||
if (ret != HG_ERR_OK)
|
if (ret != HG_ERR_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
buf_statu_.len = sizeof(buf_statu_.data);
|
|
||||||
io_->set_timeout(500);
|
io_->set_timeout(500);
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
ret = readusb(usb);
|
||||||
ret = io_->read_bulk(&buf_statu_.data, &buf_statu_.len);
|
|
||||||
}
|
|
||||||
if (ret != HG_ERR_OK)
|
if (ret != HG_ERR_OK)
|
||||||
{
|
{
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return settingsdsp_200::device_status_to_hg_err(buf_statu_.data.u32_Data, nullptr);
|
return settingsdsp_200::device_status_to_hg_err(usb.u32_Data, nullptr);
|
||||||
}
|
}
|
||||||
int hg_scanner_200::get_img_data(unsigned int bytes)
|
int hg_scanner_200::get_img_data(unsigned int bytes)
|
||||||
{
|
{
|
||||||
int total = bytes,
|
int total = bytes,
|
||||||
ret = HG_ERR_OK;
|
ret = HG_ERR_OK,
|
||||||
|
index = 0,
|
||||||
|
block = total;
|
||||||
std::shared_ptr<std::vector<char >> imagedata(new std::vector<char>(total));
|
std::shared_ptr<std::vector<char >> imagedata(new std::vector<char>(total));
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
char* buf = buf_read_img_;
|
|
||||||
#else
|
|
||||||
char* buf = imagedata->data();
|
|
||||||
#endif
|
|
||||||
char* dst = imagedata->data();
|
|
||||||
|
|
||||||
USBCB usb{GET_IMAGE, 0, total};
|
USBCB usb{GET_IMAGE, 0, total};
|
||||||
ret = writeusb(usb);
|
ret = writeusb(usb);
|
||||||
if (ret != HG_ERR_OK)
|
if (ret != HG_ERR_OK)
|
||||||
|
@ -536,27 +537,22 @@ int hg_scanner_200::get_img_data(unsigned int bytes)
|
||||||
status_ = ret;
|
status_ = ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
io_->set_timeout(2000);
|
io_->set_timeout(500);
|
||||||
|
|
||||||
while (total > 0)
|
while (total > 0)
|
||||||
{
|
{
|
||||||
io_read_img_ = buf_read_img_len_;
|
block = 512 * 1024;
|
||||||
|
|
||||||
if (total < io_read_img_)
|
if (total < block)
|
||||||
io_read_img_ = total;
|
block = total;
|
||||||
|
|
||||||
ret = io_->read_bulk(buf, &io_read_img_);
|
|
||||||
|
|
||||||
|
ret = io_->read_bulk(imagedata->data() + index,&block);
|
||||||
|
io_->set_timeout(500); //不能删除可能会导致IO超时
|
||||||
if (ret != HG_ERR_OK)
|
if (ret != HG_ERR_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef WIN32
|
index += block;
|
||||||
memcpy(dst, buf, io_read_img_);
|
total -= block;
|
||||||
dst += io_read_img_;
|
|
||||||
#else
|
|
||||||
buf += io_read_img_;
|
|
||||||
#endif
|
|
||||||
total -= io_read_img_;
|
|
||||||
}
|
}
|
||||||
if (ret == HG_ERR_OK)
|
if (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
|
@ -1124,36 +1120,36 @@ void hg_scanner_200::printf_devconfig(HGSCANCONF_DSP *d)
|
||||||
}
|
}
|
||||||
std::string hg_scanner_200::get_firmware_version()
|
std::string hg_scanner_200::get_firmware_version()
|
||||||
{
|
{
|
||||||
|
char buf[20] = { 0 };
|
||||||
int ret = HG_ERR_OK,
|
int ret = HG_ERR_OK,
|
||||||
len = 8; //协议定义长度为8 300 400 =10
|
len = 8; //协议定义长度为8 300 400 =10
|
||||||
USBCB cmd = {GET_FW_VERSION, len, 0,};
|
USBCB cmd = {GET_FW_VERSION, len, 0,};
|
||||||
|
|
||||||
memset(buf_mini_str_, 0, sizeof(buf_mini_str_));
|
|
||||||
ret = writeusb(cmd);
|
ret = writeusb(cmd);
|
||||||
if(ret == HG_ERR_OK)
|
if(ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
ret = io_->read_bulk(buf_mini_str_, &len);
|
ret = io_->read_bulk(buf, &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf_mini_str_;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hg_scanner_200::get_serial_num()
|
std::string hg_scanner_200::get_serial_num()
|
||||||
{
|
{
|
||||||
|
char buf[20] = { 0 };
|
||||||
int ret = HG_ERR_OK,
|
int ret = HG_ERR_OK,
|
||||||
len = 12; //协议定义长度为8 300 400 =10
|
len = 12; //协议定义长度为8 300 400 =10
|
||||||
USBCB cmd = {GET_SERIAL, len, 0,};
|
USBCB cmd = {GET_SERIAL, len, 0,};
|
||||||
|
|
||||||
memset(buf_mini_str_, 0, sizeof(buf_mini_str_));
|
|
||||||
ret = writeusb(cmd);
|
ret = writeusb(cmd);
|
||||||
if (ret == HG_ERR_OK)
|
if (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
ret = io_->read_bulk(buf_mini_str_, &len);
|
ret = io_->read_bulk(buf, &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf_mini_str_;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1229,19 +1225,16 @@ int hg_scanner_200::get_sleep_time(SANE_Power* getime)
|
||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
buf_sleep_.data = usbcb;
|
len = sizeof(usbcb);
|
||||||
buf_sleep_.len = sizeof(buf_sleep_.data);
|
ret = io_->read_bulk(&usbcb,&len);
|
||||||
{
|
printf("usbcb.u32_Data = %d\r\n",usbcb.u32_Data);
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
|
||||||
ret = io_->read_bulk(&buf_sleep_.data, &buf_sleep_.len);
|
|
||||||
}
|
|
||||||
if (ret == HG_ERR_OK)
|
if (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
if (getime)
|
if (getime)
|
||||||
{
|
{
|
||||||
*getime = (SANE_Power)buf_sleep_.data.u32_Data;
|
*getime = (SANE_Power)usbcb.u32_Data;
|
||||||
}
|
}
|
||||||
if (buf_sleep_.data.u32_Data)
|
if (usbcb.u32_Data)
|
||||||
{
|
{
|
||||||
return HG_ERR_DEVICE_SLEEPING;
|
return HG_ERR_DEVICE_SLEEPING;
|
||||||
}
|
}
|
||||||
|
@ -1282,19 +1275,23 @@ int hg_scanner_200::get_scanner_paperon(SANE_Bool* paperon)
|
||||||
ret = writeusb(usbcb);
|
ret = writeusb(usbcb);
|
||||||
io_->set_timeout(500);
|
io_->set_timeout(500);
|
||||||
|
|
||||||
buf_paper_on_.data = usbcb;
|
|
||||||
buf_paper_on_.len = sizeof(buf_paper_on_.data);
|
|
||||||
if (ret == HG_ERR_OK)
|
if (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
ret = io_->read_bulk(&buf_paper_on_.data, &buf_paper_on_.len);
|
ret = io_->read_bulk(&usbcb,&len);
|
||||||
if (ret == HG_ERR_OK && buf_paper_on_.data.u32_Data == 0)
|
|
||||||
ret = HG_ERR_DEVICE_NO_PAPER;
|
|
||||||
}
|
}
|
||||||
|
if (ret != HG_ERR_OK)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if (usbcb.u32_Data == 0)
|
||||||
|
ret = HG_ERR_DEVICE_NO_PAPER;
|
||||||
|
else
|
||||||
|
ret = HG_ERR_OK;
|
||||||
if (paperon)
|
if (paperon)
|
||||||
*paperon = buf_paper_on_.data.u32_Data;
|
{
|
||||||
|
*paperon = usbcb.u32_Data;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int hg_scanner_200::set_scan_when_paper_on(void)
|
int hg_scanner_200::set_scan_when_paper_on(void)
|
||||||
|
@ -1319,8 +1316,7 @@ int hg_scanner_200::get_scan_is_sleep()
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
USBCB usbcb = { CHECK_IS_SLEEP, 0, 0};
|
USBCB usbcb = { CHECK_IS_SLEEP, 0, 0};
|
||||||
buf_is_sleep_.data = usbcb;
|
len = sizeof(USBCB);
|
||||||
buf_is_sleep_.len = len = sizeof(USBCB);
|
|
||||||
ret = writeusb(usbcb);
|
ret = writeusb(usbcb);
|
||||||
|
|
||||||
io_->set_timeout(200);
|
io_->set_timeout(200);
|
||||||
|
@ -1328,17 +1324,17 @@ int hg_scanner_200::get_scan_is_sleep()
|
||||||
if (ret == HG_ERR_OK)
|
if (ret == HG_ERR_OK)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
ret = io_->read_bulk(&buf_is_sleep_.data, &buf_is_sleep_.len);
|
ret = io_->read_bulk(&usbcb,&len);
|
||||||
}
|
}
|
||||||
if (ret != HG_ERR_OK)
|
if (ret != HG_ERR_OK)
|
||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (buf_is_sleep_.data.u32_Data == 0x10)
|
if (usbcb.u32_Data == 0x10)
|
||||||
{
|
{
|
||||||
return HG_ERR_OK;
|
return HG_ERR_OK;
|
||||||
}
|
}
|
||||||
else if (buf_is_sleep_.data.u32_Data == 0x100)
|
else if (usbcb.u32_Data == 0x100)
|
||||||
{
|
{
|
||||||
return HG_ERR_DEVICE_SLEEPING;
|
return HG_ERR_DEVICE_SLEEPING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,23 +15,6 @@
|
||||||
|
|
||||||
class hg_scanner_200 : public hg_scanner
|
class hg_scanner_200 : public hg_scanner
|
||||||
{
|
{
|
||||||
// reading buffers ... (for overlapped IO maybe rewrite the buffer after the timeout)
|
|
||||||
typedef struct _usb_block
|
|
||||||
{
|
|
||||||
USBCB data;
|
|
||||||
int len;
|
|
||||||
}USBBLOCK;
|
|
||||||
const int buf_read_img_len_;
|
|
||||||
char *buf_read_img_;
|
|
||||||
int io_read_img_;
|
|
||||||
|
|
||||||
char buf_mini_str_[20];
|
|
||||||
|
|
||||||
USBBLOCK buf_sleep_;
|
|
||||||
USBBLOCK buf_paper_on_;
|
|
||||||
USBBLOCK buf_is_sleep_;
|
|
||||||
USBBLOCK buf_statu_;
|
|
||||||
|
|
||||||
void discard_prev(void);
|
void discard_prev(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -61,8 +44,9 @@ public:
|
||||||
private:
|
private:
|
||||||
int initdevice();
|
int initdevice();
|
||||||
int writeusb(USBCB &usb);
|
int writeusb(USBCB &usb);
|
||||||
|
int readusb(USBCB &usb);
|
||||||
int pop_image();
|
int pop_image();
|
||||||
int get_scanner_status(void);
|
int get_scanner_status(USBCB &usb);
|
||||||
int get_img_data(unsigned int bytes);
|
int get_img_data(unsigned int bytes);
|
||||||
int writedown_device_configuration(bool type =false,HGSCANCONF_DSP *d = NULL);
|
int writedown_device_configuration(bool type =false,HGSCANCONF_DSP *d = NULL);
|
||||||
void writedown_image_configuration(void);
|
void writedown_image_configuration(void);
|
||||||
|
|
Loading…
Reference in New Issue