2023-12-19 07:27:16 +00:00
|
|
|
#include "hardware.h"
|
|
|
|
|
|
|
|
#include "./cis/FpgaComm.h"
|
2023-12-20 07:23:24 +00:00
|
|
|
#include "./cis/gvideoisp1.h"
|
|
|
|
#include "./motor/motorboard.h"
|
2023-12-19 07:27:16 +00:00
|
|
|
#include <huagao/hgscanner_error.h>
|
|
|
|
#include <sane/sane_ex.h>
|
2024-01-05 09:36:50 +00:00
|
|
|
#include <json/gb_json.h>
|
2024-01-11 09:59:23 +00:00
|
|
|
#include <base/paper.h>
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// scanner_hw
|
|
|
|
static std::string device_opt_json[] = {
|
2024-01-13 09:14:12 +00:00
|
|
|
"{\"mode\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u955c\\u5934\\u8272\\u5f69\\u5de5\\u4f5c\\u6a21\\u5f0f\",\"type\":\"string\",\"fix-id\":34819,\"ui-pos\":10,\"auth\":0,\"size\":12,\"cur\":\"\\u5f69\\u8272\",\"default\":\"\\u5f69\\u8272\",\"range\":[\"\\u5f69\\u8272\",\"\\u7070\\u5ea6\"]},\"resolution\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u955c\\u5934\\u5de5\\u4f5c\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"fix-id\":34840,\"ui-pos\":11,\"auth\":0,\"size\":4,\"cur\":200,\"default\":200,\"range\":[200,300,600]},\"paper\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u7eb8\\u5f20\\u5c3a\\u5bf8\",\"desc\":\"\\u8bbe\\u7f6e\\u51fa\\u56fe\\u5927\\u5c0f\",\"type\":\"string\",\"fix-id\":34831,\"ui-pos\":10,\"auth\":0,\"size\":44,\"cur\":\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"default\":\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",\"range\":[\"A3\",\"8\\u5f00\",\"A4\",\"16\\u5f00\",\"A5\",\"A6\",\"B4\",\"B5\",\"B6\",\"Letter\",\"Double Letter\",\"LEGAL\",\"\\u5339\\u914d\\u539f\\u59cb\\u5c3a\\u5bf8\",{\"resolution<500\":\"\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207\"},{\"resolution<500\":\"\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\"},{\"resolution<500\":\"\\u4e09\\u8054\\u8bd5\\u5377\"}]},\"lateral\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u6a2a\\u5411\",\"desc\":\"\\u6a2a\\u5411\\u653e\\u7f6e\\u7eb8\\u5f20\",\"type\":\"bool\",\"fix-id\":34924,\"ui-pos\":12,\"auth\":0,\"affect\":6,\"visible\":0,\"size\":4,\"cur\":false,\"default\":false,\"depend\":\"paper==A4 || paper==16\\u5f00 || paper==A5 || paper==A6 || paper==B5 || paper==B6 || paper==Letter\"},\"paper-w\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u7eb8\\u5f20\\u5bbd\\u5ea6\",\"desc\":\"\\u4ee5\\u6beb\\u7c73\\u4e3a\\u5355\\u4f4d\\u7684\\u7eb8\\u5f20\\u5bbd\",\"type\":\"float\",\"fix-id\":34922,\"ui-pos\":13,\"auth\":0,\"unit\":\"mm\",\"readonly\":true,\"visible\":0,\"size\":8,\"auto\":false,\"ownread\":true,\"cur\":210.000000,\"default\":210.000000},\"paper-h\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u7eb8\\u5f20\\u9ad8\\u5ea6\",\"desc\":\"\\u4ee5\\u6beb\\u7c73\\u4e3a\\u5355\\u4f4d\\u7684\\u7eb8\\u5f20\\u9ad8\",\"type\":\"float\",\"fix-id\":34923,\"ui-pos\":14,\"auth\":0,\"unit\":\"mm\",\"readonly\":true,\"visible\":0,\"size\":8,\"auto\":false,\"ownread\":true,\"cur\":297.000000,\"default\":297.000000},\"is-wait-scan\":{\"cat\":\"base\",\"group\":\"feeder\",\"title\":\"\\u5f85\\u7eb8\\u626b\\u63cf\",\"desc\":\"\\u542f\\u7528\\u540e\\uff0c\\u6587\\u7a3f\\u653e\\u5165\\u626b\\u63cf\\u4eea\\u65f6\\u5c06\\u81ea\\u52a8\\u542f\\u52a8\\u626b\\u63cf\",\"type\":\"bool\",\"fix-id\":34873,\"ui-pos\":12,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"wait-scan-exit\":{\"cat\":\"base\",\"group\":\"feeder\",\"title\":\"\\u5f85\\u7eb8\\u626b\\u63cf\\u9000\\u51fa\\u65f6\\u95f4\",\"desc\":\"\\u8bbe\\u7f6e\\u7ed3\\u675f\\u5f85\\u7eb8\\u626b\\u63cf\\u7684\\u65f6\\u95f4\",\"type\":\"string\",\"fix-id\":34920,\"ui-pos\":13,\"auth\":0,\"size\":16,\"cur\":\"60s\",\"default\":\"60s\",\"range\":[\"15s\",\"30s\",\"60s\",\"2min\",\"4min\",\"8min\"],\"depend\":\"is-wait-scan==true\"},\"scan-mode\":{\"cat\":\"base\",\"group\":\"feeder\",\"title\":\"\\u626b\\u63cf\\u5f20\\u6570\",\"desc\":\"\\u9009\\u62e9\\u6307\\u5b9a\\u6570\\u91cf\\u626b\\u63cf\\u6216\\u8fde\\u7eed\\u626b\\u63cf\",\"type\":\"string\",\"fix-id\":34862,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"\\u8fde\\u7eed\\u626b\\u63cf\",\"default\":\"\\u8fde\\u7eed\\u626b\\u63cf\",\"range\":[\"\\u8fde\\u7eed\\u626b\\u63cf\",\"\\u626b\\u63cf\\u6307\\u5b9a\\u5f20\\u6570\"],\"depend\":\"is-wait-scan==false\"},\"scan-count\":{\"cat\":\"base\",\"group\":\"feeder\",\"title\":\" \\u626b\\u63cf\\u6570\\u91cf\",\"desc\":\"\\u626b\\u63cf\\u6307\\u5b9a\\u6570\\u91cf\",\"type\":\"int\",\"fix-id\":34863,\"ui-pos\":16,\"auth\":0,\"size\":4,\"cur\":-1,\"default\":-1,\"depend\":\"scan-mode.enabled&&scan-mode==\\u626b\\u63cf\\u6307\\u5b9a\\u5f20
|
|
|
|
"87\",\"desc\":\"\\u4e3a\\u62b5\\u6297\\u5f62\\u53d8\\uff0c\\u5728\\u6c34\\u5e73\\u65b9\\u5411\\u7684\\u62c9\\u4f38\\u7387\",\"type\":\"float\",\"ui-pos\":40,\"auth\":0,\"size\":8,\"auto\":false,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==300\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==200\":1.000000,\"mode==\\u5f69\\u8272 && resolution==600\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==600\":1.000000,\"default\":1.000000},\"range\":{\"min\":0.500000,\"max\":2.000000,\"step\":0.100000}},\"stretch-v\":{\"cat\":\"base\",\"group\":\"CIS\",\"title\":\"\\u5782\\u76f4\\u62c9\\u4f38\\u7387\",\"desc\":\"\\u4e3a\\u62b5\\u6297\\u5f62\\u53d8\\uff0c\\u5728\\u5782\\u76f4\\u65b9\\u5411\\u7684\\u62c9\\u4f38\\u7387\",\"type\":\"float\",\"ui-pos\":41,\"auth\":0,\"size\":8,\"auto\":false,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==300\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==200\":1.000000,\"mode==\\u5f69\\u8272 && resolution==600\":1.000000,\"mode==\\u7070\\u5ea6 && resolution==600\":1.000000,\"default\":1.000000},\"range\":{\"min\":0.500000,\"max\":2.000000,\"step\":0.100000}},\"cis-sp\":{\"cat\":\"base\",\"group\":\"CIS\",\"title\":\"\\u901f\\u73871\",\"desc\":\"FPGA\\u6700\\u4f73\\u901f\\u7387\",\"type\":\"int\",\"ui-pos\":42,\"auth\":0,\"size\":4,\"auto\":false,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":878,\"mode==\\u7070\\u5ea6 && resolution==300\":2637,\"mode==\\u7070\\u5ea6 && resolution==200\":2450,\"mode==\\u5f69\\u8272 && resolution==600\":1531,\"mode==\\u7070\\u5ea6 && resolution==600\":4595,\"default\":816}},\"expo-fr\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u6b63\\u9762\\u7ea2\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7ea2\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":70,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":313,\"mode==\\u7070\\u5ea6 && resolution==300\":336,\"mode==\\u7070\\u5ea6 && resolution==200\":337,\"mode==\\u5f69\\u8272 && resolution==600\":622,\"mode==\\u7070\\u5ea6 && resolution==600\":673,\"default\":312},\"range\":{\"min\":1,\"max\":1100,\"step\":1}},\"expo-fg\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u6b63\\u9762\\u7eff\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7eff\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":71,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":306,\"mode==\\u7070\\u5ea6 && resolution==300\":336,\"mode==\\u7070\\u5ea6 && resolution==200\":337,\"mode==\\u5f69\\u8272 && resolution==600\":611,\"mode==\\u7070\\u5ea6 && resolution==600\":673,\"default\":305},\"range\":{\"min\":1,\"max\":1100,\"step\":1}},\"expo-fb\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u6b63\\u9762\\u84dd\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u6b63\\u9762\\u84dd\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":72,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":297,\"mode==\\u7070\\u5ea6 && resolution==300\":336,\"mode==\\u7070\\u5ea6 && resolution==200\":337,\"mode==\\u5f69\\u8272 && resolution==600\":590,\"mode==\\u7070\\u5ea6 && resolution==600\":673,\"default\":295},\"range\":{\"min\":1,\"max\":1100,\"step\":1}},\"expo-br\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u80cc\\u9762\\u7ea2\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7ea2\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":73,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":360,\"mode==\\u7070\\u5ea6 && resolution==300\":410,\"mode==\\u7070\\u5ea6 && resolution==200\":406,\"mode==\\u5f69\\u8272 && resolution==600\":713,\"mode==\\u7070\\u5ea6 && resolution==600\":811,\"default\":360},\
|
|
|
|
"t\":{\"mode==\\u5f69\\u8272 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==200\":170,\"mode==\\u5f69\\u8272 && resolution==600\":170,\"mode==\\u7070\\u5ea6 && resolution==600\":170,\"default\":170},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"gain-b-4\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u80cc\\u9762\\u901a\\u90534\\uff09\",\"desc\":\"\\u80cc\\u9762\\u901a\\u90534\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":123,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==200\":170,\"mode==\\u5f69\\u8272 && resolution==600\":170,\"mode==\\u7070\\u5ea6 && resolution==600\":170,\"default\":170},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"gain-b-5\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u80cc\\u9762\\u901a\\u90535\\uff09\",\"desc\":\"\\u80cc\\u9762\\u901a\\u90535\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":124,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==200\":170,\"mode==\\u5f69\\u8272 && resolution==600\":170,\"mode==\\u7070\\u5ea6 && resolution==600\":170,\"default\":170},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"gain-b-6\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u80cc\\u9762\\u901a\\u90536\\uff09\",\"desc\":\"\\u80cc\\u9762\\u901a\\u90536\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":125,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==300\":170,\"mode==\\u7070\\u5ea6 && resolution==200\":170,\"mode==\\u5f69\\u8272 && resolution==600\":170,\"mode==\\u7070\\u5ea6 && resolution==600\":170,\"default\":170},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"off-f-1\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\u901a\\u90531\\uff09\",\"desc\":\"\\u6b63\\u9762\\u901a\\u90531\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":160,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":113,\"mode==\\u7070\\u5ea6 && resolution==300\":116,\"mode==\\u7070\\u5ea6 && resolution==200\":116,\"mode==\\u5f69\\u8272 && resolution==600\":115,\"mode==\\u7070\\u5ea6 && resolution==600\":116,\"default\":113},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"off-f-2\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\u901a\\u90532\\uff09\",\"desc\":\"\\u6b63\\u9762\\u901a\\u90532\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":161,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":118,\"mode==\\u7070\\u5ea6 && resolution==300\":121,\"mode==\\u7070\\u5ea6 && resolution==200\":119,\"mode==\\u5f69\\u8272 && resolution==600\":119,\"mode==\\u7070\\u5ea6 && resolution==600\":121,\"default\":118},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"off-f-3\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\u901a\\u90533\\uff09\",\"desc\":\"\\u6b63\\u9762\\u901a\\u90533\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":162,\"auth\":0,\"bind\":true,\"size\":4,\"default\":{\"mode==\\u5f69\\u8272 && resolution==300\":118,\"mode==\\u7070\\u5ea6 && resolution==300\":119,\"mode==\\u7070\\u5ea6 && resolution==200\":121,\"mode==\\u5f69\\u8272 && resolution==600\":118,\"mode==\\u7070\\u5ea6 && resolution==600\":121,\"default\":118},\"range\":{\"min\":1,\"max\":200,\"step\":1}},\"off-f-4\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\u901a\\u90534\\uff09\",\"desc\":\"\\u6b63\\u9762\\u901a\\u90534\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":1
|
2023-12-19 07:27:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// scanner_hw
|
2024-01-09 07:32:03 +00:00
|
|
|
scanner_hw::scanner_hw() : mb_events_("motorboard-event")
|
2023-12-19 07:27:16 +00:00
|
|
|
{
|
|
|
|
set_where("hardware");
|
2024-01-09 07:32:03 +00:00
|
|
|
mb_events_.enable_wait_log(false);
|
|
|
|
|
2024-01-13 09:14:12 +00:00
|
|
|
CLEAN_ARRAY(exposure_);
|
|
|
|
CLEAN_ARRAY(gain_);
|
|
|
|
CLEAN_ARRAY(off_);
|
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
scanner_hw::~scanner_hw()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void scanner_hw::init(void)
|
|
|
|
{
|
|
|
|
std::string text("");
|
|
|
|
|
|
|
|
for(auto& v: device_opt_json)
|
|
|
|
text += v;
|
2024-01-05 09:36:50 +00:00
|
|
|
init_version(text);
|
2023-12-19 07:27:16 +00:00
|
|
|
set_opt_json_text(&text[0]);
|
|
|
|
|
2024-01-02 07:18:42 +00:00
|
|
|
#define OPT_HANDLER(name) \
|
|
|
|
auto name = [this](void* value) -> void
|
|
|
|
|
2023-12-19 09:11:41 +00:00
|
|
|
auto a = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
auto_scan_ = *(bool*)value;
|
|
|
|
};
|
|
|
|
auto e = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
if(strcmp((char*)value, "15s") == 0)
|
|
|
|
time_to_exit_auto_scan_ = 15;
|
|
|
|
else if(strcmp((char*)value, "30s") == 0)
|
|
|
|
time_to_exit_auto_scan_ = 30;
|
|
|
|
else if(strcmp((char*)value, "2min") == 0)
|
|
|
|
time_to_exit_auto_scan_ = 120;
|
|
|
|
else if(strcmp((char*)value, "4min") == 0)
|
|
|
|
time_to_exit_auto_scan_ = 240;
|
|
|
|
else if(strcmp((char*)value, "8min") == 0)
|
|
|
|
time_to_exit_auto_scan_ = 480;
|
|
|
|
else
|
|
|
|
time_to_exit_auto_scan_ = 60;
|
|
|
|
};
|
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
auto m = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
if(strcmp((char*)value, "\347\201\260\345\272\246") == 0)
|
|
|
|
mode_ = (char*)value;
|
|
|
|
else
|
|
|
|
mode_ = "\345\275\251\350\211\262";
|
|
|
|
};
|
|
|
|
auto r = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
if(*(int*)value <= 200)
|
|
|
|
dpi_ = 200;
|
|
|
|
else
|
|
|
|
dpi_ = 300;
|
|
|
|
};
|
|
|
|
auto b = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
baud_ = *(int*)value;
|
|
|
|
};
|
|
|
|
auto d = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
delay_ = *(int*)value;
|
|
|
|
};
|
|
|
|
auto f = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
frame_h_ = *(int*)value;
|
|
|
|
};
|
|
|
|
auto s = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
sample_ = *(int*)value;
|
|
|
|
};
|
2024-01-13 09:14:12 +00:00
|
|
|
auto sp = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
sp_ = *(int*)value;
|
|
|
|
};
|
|
|
|
auto stretch_h = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
stretch_h_ = *(double*)value;
|
|
|
|
};
|
|
|
|
auto stretch_v = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
stretch_v_ = *(double*)value;
|
|
|
|
};
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
auto efb = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_FRONT][COLOR_IND_BLUE] = *(int*)value;
|
|
|
|
};
|
|
|
|
auto efg = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_FRONT][COLOR_IND_GREEN] = *(int*)value;
|
|
|
|
};
|
|
|
|
auto efr = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_FRONT][COLOR_IND_RED] = *(int*)value;
|
|
|
|
};
|
|
|
|
auto ebb = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_BACK][COLOR_IND_BLUE] = *(int*)value;
|
|
|
|
};
|
|
|
|
auto ebg = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_BACK][COLOR_IND_GREEN] = *(int*)value;
|
|
|
|
};
|
|
|
|
auto ebr = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
exposure_[SIDE_BACK][COLOR_IND_RED] = *(int*)value;
|
|
|
|
};
|
|
|
|
|
2023-12-19 09:11:41 +00:00
|
|
|
CLEAN_ARRAY(exposure_);
|
|
|
|
CLEAN_ARRAY(gain_);
|
|
|
|
CLEAN_ARRAY(off_);
|
|
|
|
|
|
|
|
opt_handler_[SANE_FULL_NAME(WAIT_TO_SCAN)] = a;
|
|
|
|
opt_handler_[SANE_FULL_NAME(WAIT_SCAN_EXIT)] = e;
|
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(COLOR_MODE)] = m;
|
|
|
|
opt_handler_[SANE_FULL_NAME(RESOLUTION)] = r;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_BAUD)] = b;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_DELAY)] = d;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_FRAME_H)] = f;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_SAMPLE)] = s;
|
2024-01-13 09:14:12 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_SP)] = sp;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_STRETCH_H)] = stretch_h;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_STRETCH_V)] = stretch_v;
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_FB)] = efb;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_FG)] = efg;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_FR)] = efr;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_BB)] = ebb;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_BG)] = ebg;
|
|
|
|
opt_handler_[SANE_FULL_NAME(CIS_EXPO_BR)] = ebr;
|
|
|
|
|
2023-12-20 08:44:39 +00:00
|
|
|
|
2024-01-11 09:59:23 +00:00
|
|
|
auto p = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
paper_ = (char*)value;
|
|
|
|
};
|
|
|
|
auto l = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
lateral_ = *(bool*)value;
|
|
|
|
};
|
|
|
|
|
|
|
|
opt_handler_[SANE_FULL_NAME(PAPER)] = p;
|
|
|
|
opt_handler_[SANE_FULL_NAME(LATERAL)] = l;
|
|
|
|
|
2023-12-20 08:44:39 +00:00
|
|
|
auto staple = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
staple_chk_ = *(bool*)value;
|
|
|
|
};
|
|
|
|
auto screw = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
screw_chk_ = *(bool*)value;
|
|
|
|
};
|
2023-12-29 02:53:04 +00:00
|
|
|
auto screwl = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
screw_chk_level_ = *(int*)value;
|
|
|
|
};
|
2023-12-20 08:44:39 +00:00
|
|
|
auto dbchk = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
double_chk_ = strcmp((char*)value, "\347\246\201\347\224\250") != 0;
|
|
|
|
};
|
|
|
|
auto motsp = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
int speed = *(int*)value;
|
2023-12-29 08:58:41 +00:00
|
|
|
if(family_ == "G200")
|
2023-12-29 02:53:04 +00:00
|
|
|
{
|
2023-12-29 08:58:41 +00:00
|
|
|
speed -= 100; // 100 110 120 130
|
2023-12-29 02:53:04 +00:00
|
|
|
}
|
2023-12-20 08:44:39 +00:00
|
|
|
else
|
2023-12-29 02:53:04 +00:00
|
|
|
{
|
2023-12-29 08:58:41 +00:00
|
|
|
speed -= 70; // 70 80 90 100
|
2023-12-29 02:53:04 +00:00
|
|
|
}
|
|
|
|
switch(speed)
|
|
|
|
{
|
|
|
|
case 10:
|
|
|
|
motor_speed_ = SPEED_PPM_BASE_10;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
motor_speed_ = SPEED_PPM_BASE_20;
|
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
motor_speed_ = SPEED_PPM_BASE_30;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
motor_speed_ = SPEED_PPM_BASE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto fm = [this](void* value) -> void
|
|
|
|
{
|
|
|
|
family_ = (char*)value;
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "Device family set as: %s\n", family_.c_str());
|
2023-12-20 08:44:39 +00:00
|
|
|
};
|
2024-01-02 07:18:42 +00:00
|
|
|
OPT_HANDLER(cntm)
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
OPT_HANDLER(cnt)
|
|
|
|
{
|
|
|
|
scan_count_ = *(int*)value;
|
|
|
|
};
|
|
|
|
OPT_HANDLER(afs)
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
OPT_HANDLER(ff)
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
OPT_HANDLER(fs)
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
OPT_HANDLER(slp)
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
2023-12-20 08:44:39 +00:00
|
|
|
|
|
|
|
opt_handler_[SANE_FULL_NAME(IS_CHECK_STAPLE)] = staple;
|
|
|
|
opt_handler_[SANE_FULL_NAME(IS_CHECK_ASKEW)] = screw;
|
2023-12-29 02:53:04 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(ASKEW_RANGE)] = screwl;
|
2023-12-20 08:44:39 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(DOUBLE_CHECK)] = dbchk;
|
|
|
|
opt_handler_[SANE_FULL_NAME(MOTOR_SPEED)] = motsp;
|
2023-12-29 02:53:04 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(DEVICE_MODEL)] = fm;
|
2024-01-02 07:18:42 +00:00
|
|
|
opt_handler_[SANE_FULL_NAME(SCAN_MODE)] = cntm;
|
|
|
|
opt_handler_[SANE_FULL_NAME(SCAN_COUNT)] = cnt;
|
|
|
|
opt_handler_[SANE_FULL_NAME(IS_AUTO_FEED_STRENGTH)] = afs;
|
|
|
|
opt_handler_[SANE_FULL_NAME(FEED_STRENGTH_VALUE)] = ff;
|
|
|
|
opt_handler_[SANE_FULL_NAME(FEED_STRENGTH)] = fs;
|
|
|
|
opt_handler_[SANE_FULL_NAME(TIME_TO_SLEEP)] = slp;
|
|
|
|
}
|
2024-01-05 09:36:50 +00:00
|
|
|
void scanner_hw::init_version(std::string& text)
|
|
|
|
{
|
|
|
|
gb_json *jsn = new gb_json();
|
|
|
|
|
|
|
|
if(jsn->attach_text(&text[0]))
|
|
|
|
{
|
|
|
|
gb_json *child = nullptr;
|
|
|
|
jsn->get_value(SANE_FULL_NAME(MOTOR_VER), child);
|
|
|
|
if(child)
|
|
|
|
{
|
|
|
|
unsigned int val = 0;
|
|
|
|
char buf[20] = {0};
|
|
|
|
|
2024-01-09 06:26:46 +00:00
|
|
|
motor_.reset(new MotorBoard(nullptr));
|
|
|
|
motor_->read(MB_PORT_VERSION, val);
|
2024-01-05 09:36:50 +00:00
|
|
|
motor_.reset();
|
|
|
|
|
|
|
|
sprintf(buf, "%u", val);
|
|
|
|
child->set_value("cur", buf);
|
|
|
|
child->set_value("default", buf);
|
|
|
|
child->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
jsn->get_value(SANE_FULL_NAME(FPGA_VER), child);
|
|
|
|
if(child)
|
|
|
|
{
|
|
|
|
unsigned int val = 0;
|
|
|
|
char buf[20] = {0};
|
|
|
|
|
|
|
|
img_controller_.reset(new FpgaComm(baud_, true));
|
|
|
|
img_controller_->read(MAX_REGS - 1, val);
|
|
|
|
img_controller_.reset();
|
|
|
|
|
|
|
|
sprintf(buf, "0x%08x", val);
|
|
|
|
child->set_value("cur", buf);
|
|
|
|
child->set_value("default", buf);
|
|
|
|
child->release();
|
|
|
|
}
|
2024-01-09 06:26:46 +00:00
|
|
|
|
|
|
|
jsn->get_value(SANE_FULL_NAME(CIS_LENGTH), child);
|
|
|
|
if(child)
|
|
|
|
{
|
|
|
|
child->get_value("default", cis_length_);
|
|
|
|
child->release();
|
|
|
|
}
|
|
|
|
|
2024-01-05 09:36:50 +00:00
|
|
|
text = jsn->to_string();
|
|
|
|
}
|
|
|
|
jsn->release();
|
|
|
|
}
|
2024-01-02 07:18:42 +00:00
|
|
|
void scanner_hw::thread_image_capture(void)
|
|
|
|
{
|
2024-01-03 09:39:16 +00:00
|
|
|
PACKIMAGE img;
|
|
|
|
safe_fifo<int> avail_mem("v4l2-mem");
|
2024-01-09 06:26:46 +00:00
|
|
|
int used_v4l2_mem = 0, times = 0;
|
2024-01-09 07:32:03 +00:00
|
|
|
std::pair<int, int> mbev;
|
|
|
|
|
2024-01-03 09:39:16 +00:00
|
|
|
auto put_v4l2_mem = [&](BEFORE_DESTROY_PARAM) -> BEFORE_DESTROY_RET
|
|
|
|
{
|
|
|
|
int ind = (int)(long)param;
|
|
|
|
|
|
|
|
mem->detach(nullptr);
|
|
|
|
avail_mem.save(ind);
|
|
|
|
};
|
2024-01-02 07:18:42 +00:00
|
|
|
|
2024-01-03 09:39:16 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "scanning thread working ...\n");
|
2024-01-02 07:18:42 +00:00
|
|
|
memset(&img, 0, sizeof(img));
|
2024-01-11 07:23:05 +00:00
|
|
|
img.bpp = 8;
|
|
|
|
img.channels = 3;
|
|
|
|
img.resolution_x = 200;
|
|
|
|
img.resolution_y = 200;
|
2024-01-11 09:59:23 +00:00
|
|
|
img.width = cis_length_;
|
2024-01-11 07:23:05 +00:00
|
|
|
img.height = 16380;
|
2024-01-09 06:26:46 +00:00
|
|
|
motor_->clear_error();
|
2024-01-05 09:36:50 +00:00
|
|
|
motor_->start();
|
2024-01-11 07:23:05 +00:00
|
|
|
if(mb_events_.take(mbev, true))
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "take first motorboard event: %d - 0x%08x\n", mbev.first, mbev.second);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Wait Lifter event before scanning failed.\n");
|
2024-01-09 07:32:03 +00:00
|
|
|
while(scanning_ && mbev.first == MOTOR_BORD_EVENT_LIFTER_READY) // auto scan cycle ...
|
2024-01-02 07:18:42 +00:00
|
|
|
{
|
2024-01-05 09:36:50 +00:00
|
|
|
motor_->pick_paper();
|
2024-01-09 06:26:46 +00:00
|
|
|
|
2024-01-03 09:39:16 +00:00
|
|
|
// scanning ONE turn ...
|
2024-01-09 06:26:46 +00:00
|
|
|
while(scanning_ && motor_->wait_paper_out(3000))
|
2024-01-02 07:18:42 +00:00
|
|
|
{
|
2024-01-05 09:36:50 +00:00
|
|
|
size_t size = 0;
|
|
|
|
int ind = -1;
|
2024-01-11 09:59:23 +00:00
|
|
|
void* frame = camera_->read_frame(5 * 1000, size, ind);
|
2024-01-09 07:32:03 +00:00
|
|
|
dyn_mem_shared_ptr mem = nullptr;
|
2024-01-02 07:18:42 +00:00
|
|
|
|
2024-01-09 07:32:03 +00:00
|
|
|
if(!frame)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mem = new dyn_mem_shared(frame, size, put_v4l2_mem, (void*)ind);
|
2024-01-03 09:39:16 +00:00
|
|
|
used_v4l2_mem++;
|
2024-01-02 07:18:42 +00:00
|
|
|
img.pos.paper_ind++;
|
|
|
|
img.pos.status = IMG_STATUS_OK;
|
|
|
|
img_handler_(mem, true, &img);
|
|
|
|
|
|
|
|
if(img.pos.paper_ind == scan_count_ || is_scan_fatal())
|
|
|
|
break;
|
|
|
|
|
2024-01-03 09:39:16 +00:00
|
|
|
// retrieve V4L2 memory ...
|
|
|
|
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
|
|
|
|
if(used_v4l2_mem >= camera_->get_mem_count())
|
|
|
|
{
|
|
|
|
stop_scan();
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Scanning stopped for that V4L2 is out of memory!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-02 07:18:42 +00:00
|
|
|
motor_->pick_paper();
|
|
|
|
}
|
|
|
|
|
2024-01-03 09:39:16 +00:00
|
|
|
// retrieve v4l2-mem ...
|
2024-01-09 06:26:46 +00:00
|
|
|
int ind = -1;
|
2024-01-03 09:39:16 +00:00
|
|
|
while(avail_mem.take(ind, false))
|
|
|
|
{
|
|
|
|
used_v4l2_mem--;
|
|
|
|
camera_->add_v4l2_memory(ind);
|
|
|
|
}
|
|
|
|
|
2024-01-09 06:26:46 +00:00
|
|
|
if(!auto_scan_ || !scanning_)
|
2024-01-03 09:39:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// wait paper ...
|
|
|
|
}
|
|
|
|
|
2024-01-09 06:26:46 +00:00
|
|
|
stop_scan();
|
2024-01-03 09:39:16 +00:00
|
|
|
while(used_v4l2_mem)
|
|
|
|
{
|
|
|
|
if(times++ == 0)
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "Wait to retrieve %d V4L2 memory(s) ...\n", used_v4l2_mem);
|
|
|
|
else if(times >= 1000)
|
|
|
|
{
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Wait %d times, but %d V4L2 memory(s) has not returned yet!\n", times, used_v4l2_mem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
}
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "scanning thread exited.\n");
|
2024-01-05 09:36:50 +00:00
|
|
|
|
|
|
|
scanning_ = false;
|
2024-01-02 07:18:42 +00:00
|
|
|
}
|
|
|
|
bool scanner_hw::is_scan_fatal(void)
|
|
|
|
{
|
|
|
|
return false;
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
2024-01-03 09:39:16 +00:00
|
|
|
void scanner_hw::retrieve_v4l2_mem(safe_fifo<int>* mem, int* used)
|
|
|
|
{
|
|
|
|
int u = *used,
|
|
|
|
ind = 0;
|
|
|
|
|
|
|
|
while(u >= camera_->get_mem_count())
|
|
|
|
{
|
|
|
|
if(mem->size())
|
|
|
|
{
|
|
|
|
if(ind)
|
|
|
|
utils::to_log(LOG_LEVEL_WARNING, "V4L2 memory returned.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(ind == 0)
|
|
|
|
utils::to_log(LOG_LEVEL_WARNING, "V4L2 is out of memory, wait image processor return ...\n");
|
|
|
|
|
|
|
|
if(ind++ > 1000) // 3 seconds ...
|
|
|
|
break;
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
|
|
|
}
|
|
|
|
while(mem->take(ind, false))
|
|
|
|
{
|
|
|
|
u--;
|
|
|
|
camera_->add_v4l2_memory(ind);
|
|
|
|
}
|
|
|
|
*used = u;
|
|
|
|
}
|
2024-01-13 09:14:12 +00:00
|
|
|
void scanner_hw::set_gain_value(bool front, bool gain, int sector, int val)
|
|
|
|
{
|
|
|
|
if(gain)
|
|
|
|
{
|
|
|
|
if(sector < _countof(gain_[0]))
|
|
|
|
{
|
|
|
|
gain_[!front][sector] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(sector < _countof(off_[0]))
|
|
|
|
{
|
|
|
|
off_[!front][sector] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
// sane_opt_provider
|
|
|
|
char* scanner_hw::get_value(const char* name, void* value, size_t* size, int* err)
|
|
|
|
{
|
|
|
|
char *ret = nullptr;
|
|
|
|
|
2023-12-20 08:44:39 +00:00
|
|
|
if(err)
|
|
|
|
*err = SCANNER_ERR_OK;
|
|
|
|
|
|
|
|
if(strcmp(name, SANE_FULL_NAME(PAPER_ON)) == 0)
|
|
|
|
{
|
2023-12-25 02:08:37 +00:00
|
|
|
ret = (char*)malloc(sizeof(int));
|
|
|
|
*(int*)ret = 0;
|
2023-12-20 08:44:39 +00:00
|
|
|
*(bool*)ret = paper_on_;
|
|
|
|
if(size)
|
|
|
|
*size = sizeof(bool);
|
|
|
|
}
|
2024-01-11 09:59:23 +00:00
|
|
|
else if(strcmp(name, SANE_FULL_NAME(PAPER_W)) == 0)
|
|
|
|
{
|
|
|
|
SIZE sz = paper::size(paper_.c_str());
|
|
|
|
double mm = lateral_ && lateral_en_ ? sz.cy : sz.cx;
|
|
|
|
|
|
|
|
ret = (char*)malloc(sizeof(double));
|
|
|
|
*(double*)ret = mm;
|
|
|
|
if(size)
|
|
|
|
*size = sizeof(double);
|
|
|
|
}
|
|
|
|
else if(strcmp(name, SANE_FULL_NAME(PAPER_H)) == 0)
|
|
|
|
{
|
|
|
|
SIZE sz = paper::size(paper_.c_str());
|
|
|
|
double mm = lateral_ && lateral_en_ ? sz.cx : sz.cy;
|
|
|
|
|
|
|
|
ret = (char*)malloc(sizeof(double));
|
|
|
|
*(double*)ret = mm;
|
|
|
|
if(size)
|
|
|
|
*size = sizeof(double);
|
|
|
|
}
|
2023-12-20 08:44:39 +00:00
|
|
|
else if(err)
|
|
|
|
*err = SCANNER_ERR_DEVICE_NOT_FOUND;
|
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int scanner_hw::set_value(const char* name, void* val)
|
|
|
|
{
|
2024-01-02 07:18:42 +00:00
|
|
|
if(scanning_) // working, no set
|
2023-12-29 02:53:04 +00:00
|
|
|
{
|
|
|
|
return SCANNER_ERR_DEVICE_BUSY;
|
|
|
|
}
|
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
if(opt_handler_.count(name))
|
|
|
|
{
|
|
|
|
opt_handler_[name](val);
|
2024-01-13 09:14:12 +00:00
|
|
|
}
|
|
|
|
else if(strstr(name, SANE_FULL_NAME(CIS_GAIN_FRONT)) == name)
|
|
|
|
{
|
|
|
|
name += strlen(SANE_FULL_NAME(CIS_GAIN_FRONT)) + 1;
|
|
|
|
set_gain_value(true, true, atoi(name), *(int*)val);
|
|
|
|
}
|
|
|
|
else if(strstr(name, SANE_FULL_NAME(CIS_GAIN_BACK)) == name)
|
|
|
|
{
|
|
|
|
name += strlen(SANE_FULL_NAME(CIS_GAIN_BACK)) + 1;
|
|
|
|
set_gain_value(false, true, atoi(name), *(int*)val);
|
|
|
|
}
|
|
|
|
else if(strstr(name, SANE_FULL_NAME(CIS_OFFSET_FRONT)) == name)
|
|
|
|
{
|
|
|
|
name += strlen(SANE_FULL_NAME(CIS_OFFSET_FRONT)) + 1;
|
|
|
|
set_gain_value(true, false, atoi(name), *(int*)val);
|
|
|
|
}
|
|
|
|
else if(strstr(name, SANE_FULL_NAME(CIS_OFFSET_BACK)) == name)
|
|
|
|
{
|
|
|
|
name += strlen(SANE_FULL_NAME(CIS_OFFSET_BACK)) + 1;
|
|
|
|
set_gain_value(false, false, atoi(name), *(int*)val);
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
|
|
|
}
|
2024-01-13 09:14:12 +00:00
|
|
|
|
|
|
|
return 0;
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
2024-01-11 09:59:23 +00:00
|
|
|
void scanner_hw::enable(const char* name, bool able)
|
|
|
|
{
|
|
|
|
if(strcmp(name, SANE_FULL_NAME(LATERAL)) == 0)
|
|
|
|
lateral_en_ = able;
|
|
|
|
}
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
// operation ...
|
|
|
|
int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler)
|
|
|
|
{
|
2023-12-29 02:53:04 +00:00
|
|
|
this->close();
|
2024-01-11 07:23:05 +00:00
|
|
|
int fh = 16380;
|
2023-12-29 02:53:04 +00:00
|
|
|
|
|
|
|
if(!image_handler)
|
|
|
|
return SCANNER_ERR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
img_handler_ = image_handler;
|
2023-12-19 07:27:16 +00:00
|
|
|
img_controller_.reset(new FpgaComm(baud_));
|
2024-01-05 09:36:50 +00:00
|
|
|
if(!img_controller_->is_ok())
|
|
|
|
return DEV_ERR(HD_001);
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
img_controller_->setColorMode(mode_ == "\345\275\251\350\211\262" ? COLOR_MODE : GRAY_MODE);
|
2024-01-11 09:59:23 +00:00
|
|
|
img_controller_->setDpi((dpi_ + 100) / 200);
|
2023-12-19 07:27:16 +00:00
|
|
|
img_controller_->setDelayTime(delay_);
|
|
|
|
img_controller_->setSample(sample_);
|
2024-01-13 09:14:12 +00:00
|
|
|
img_controller_->setSp(sp_);
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
void(FpgaComm::* exposure[])(int) = {&FpgaComm::setAExposureB, &FpgaComm::setAExposureG
|
|
|
|
, &FpgaComm::setAExposureR, &FpgaComm::setBExposureB, &FpgaComm::setBExposureG, &FpgaComm::setBExposureR};
|
|
|
|
for(int i = 0; i < SIDE_COUNT; ++i)
|
|
|
|
{
|
|
|
|
for(int j = 0; j < COLOR_IND_COUNT; ++j)
|
|
|
|
(img_controller_.get()->*exposure[i * SIDE_COUNT + j])(exposure_[i][j]);
|
|
|
|
}
|
|
|
|
|
2023-12-20 07:23:24 +00:00
|
|
|
for(int i = 0; i < FpgaComm::CIS_SECTOR_COUNT; ++i)
|
2024-01-13 09:14:12 +00:00
|
|
|
img_controller_->setAGain(i, gain_[SIDE_FRONT][i]);
|
2023-12-20 07:23:24 +00:00
|
|
|
for(int i = 0; i < FpgaComm::CIS_SECTOR_COUNT; ++i)
|
2024-01-13 09:14:12 +00:00
|
|
|
img_controller_->setBGain(i, gain_[SIDE_BACK][i]);
|
2023-12-19 07:27:16 +00:00
|
|
|
|
2023-12-20 07:23:24 +00:00
|
|
|
for(int i = 0; i < FpgaComm::CIS_SECTOR_COUNT; ++i)
|
2024-01-13 09:14:12 +00:00
|
|
|
img_controller_->setAOffset(i, off_[SIDE_FRONT][i]);
|
2023-12-20 07:23:24 +00:00
|
|
|
for(int i = 0; i < FpgaComm::CIS_SECTOR_COUNT; ++i)
|
2024-01-13 09:14:12 +00:00
|
|
|
img_controller_->setBOffset(i, off_[SIDE_BACK][i]);
|
2023-12-19 07:27:16 +00:00
|
|
|
|
2024-01-09 07:32:03 +00:00
|
|
|
auto cb = [this](int ev, unsigned int data) -> void
|
|
|
|
{
|
|
|
|
mb_events_.save(std::make_pair(ev, data), true);
|
|
|
|
};
|
|
|
|
mb_events_.clear();
|
|
|
|
motor_.reset(new MotorBoard(cb));
|
2023-12-20 08:44:39 +00:00
|
|
|
motor_->set_double_inpect(double_chk_);
|
|
|
|
motor_->set_staple_inpect(staple_chk_);
|
|
|
|
motor_->set_screw_inpect(screw_chk_);
|
2023-12-29 02:53:04 +00:00
|
|
|
motor_->set_screw_level(screw_chk_level_);
|
2023-12-20 08:44:39 +00:00
|
|
|
motor_->set_speed_mode(motor_speed_);
|
2024-01-09 06:26:46 +00:00
|
|
|
motor_->set_auto_paper(auto_scan_, true);
|
2023-12-20 07:23:24 +00:00
|
|
|
|
2023-12-29 02:53:04 +00:00
|
|
|
unsigned int val = 0;
|
2024-01-09 06:26:46 +00:00
|
|
|
if(motor_->read(MB_PORT_CONFIG, val))
|
2023-12-29 02:53:04 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard config : %p\n", val);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board config failed.\n");
|
2024-01-09 06:26:46 +00:00
|
|
|
if(motor_->read(MB_PORT_STATUS, val))
|
2023-12-29 02:53:04 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard status : %p\n", val);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board status failed.\n");
|
2024-01-09 06:26:46 +00:00
|
|
|
if(motor_->read(MB_PORT_MODE, val))
|
2023-12-29 02:53:04 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard mode : %p\n", val);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board mode failed.\n");
|
2024-01-09 06:26:46 +00:00
|
|
|
if(motor_->read(MB_PORT_VERSION, val))
|
2023-12-29 02:53:04 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard version: %p\n", val);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board version failed.\n");
|
2024-01-09 06:26:46 +00:00
|
|
|
if(motor_->read(MB_PORT_CONFIG_EX, val))
|
2023-12-29 02:53:04 +00:00
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard confige: %p\n", val);
|
|
|
|
else
|
|
|
|
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board confige failed.\n");
|
|
|
|
|
2024-01-11 07:23:05 +00:00
|
|
|
camera_.reset(new GVideoISP1());
|
|
|
|
camera_->open(3888, fh);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
|
|
|
|
img_controller_->setFrameHeight(frame_h_);
|
|
|
|
img_controller_->capture();
|
|
|
|
size_t size;
|
|
|
|
int _int;
|
|
|
|
auto data = camera_->read_frame(100,size,_int);
|
|
|
|
if(data)
|
|
|
|
camera_->add_v4l2_memory(_int);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
img_controller_->setFrameHeight(fh / 2 * 3);
|
|
|
|
if(1)
|
|
|
|
{
|
|
|
|
// debug ...
|
|
|
|
unsigned int vals[] = {0x5ffa, 0x3300c9d, 0x1, 0xaa00aa, 0x340030aa, 0x1380193
|
|
|
|
, 0x1270131, 0x340030aa, 0x168000c, 0x168017b, 0, 0x0afa3f
|
|
|
|
, 0x3e8};
|
|
|
|
for(int i = 0; i < _countof(vals); ++i)
|
|
|
|
img_controller_->write(i, vals[i]);
|
|
|
|
img_controller_->update();
|
|
|
|
}
|
|
|
|
|
2023-12-29 02:53:04 +00:00
|
|
|
return SCANNER_ERR_OK;
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
|
|
|
int scanner_hw::start_scan(void)
|
|
|
|
{
|
2024-01-03 09:39:16 +00:00
|
|
|
unsigned int val = 0;
|
|
|
|
|
2023-12-29 02:53:04 +00:00
|
|
|
if(!camera_.get() || !motor_.get() || !img_controller_.get())
|
2024-01-03 09:39:16 +00:00
|
|
|
return DEV_ERR(NOT_READY);
|
2023-12-26 01:33:05 +00:00
|
|
|
|
2023-12-29 02:53:04 +00:00
|
|
|
motor_->clear_error();
|
2024-01-09 06:26:46 +00:00
|
|
|
if(!motor_->read(MB_PORT_STATUS, val))
|
2024-01-03 09:39:16 +00:00
|
|
|
return DEV_ERR(GET_STATUS_FAILED);
|
|
|
|
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "start scan: status = 0x%08x.\n", val);
|
|
|
|
if (((SMBSTATUS*)&val)->open_machine) // 0x700fe
|
|
|
|
return DEV_ERR(COVER_OPENNED);
|
|
|
|
|
2024-01-09 06:26:46 +00:00
|
|
|
if(!motor_->read(MB_PORT_MODE, val))
|
2024-01-03 09:39:16 +00:00
|
|
|
return DEV_ERR(GET_STATUS_FAILED);
|
|
|
|
|
|
|
|
utils::to_log(LOG_LEVEL_DEBUG, "start scan: mode-status = 0x%08x.\n", val);
|
2024-01-05 09:36:50 +00:00
|
|
|
if(((SMBMODE*)&val)->paper_jammed_in ||
|
|
|
|
((SMBMODE*)&val)->paper_jammed_out)
|
2024-01-03 09:39:16 +00:00
|
|
|
return DEV_ERR(PAPER_JAMMED);
|
|
|
|
|
|
|
|
if(((SMBMODE*)&val)->feeding_paper_ready == 0 && !auto_scan_)
|
|
|
|
return DEV_ERR(NO_PAPER);
|
2024-01-02 07:18:42 +00:00
|
|
|
|
2024-01-09 06:26:46 +00:00
|
|
|
scanning_ = true;
|
2024-01-11 07:23:05 +00:00
|
|
|
mb_events_.clear();
|
2024-01-09 06:26:46 +00:00
|
|
|
scan_thread_.reset(new std::thread(&scanner_hw::thread_image_capture, this));
|
2023-12-20 07:23:24 +00:00
|
|
|
|
2024-01-02 07:18:42 +00:00
|
|
|
return SCANNER_ERR_OK;
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
|
|
|
int scanner_hw::stop_scan(void)
|
|
|
|
{
|
2024-01-09 06:26:46 +00:00
|
|
|
scanning_ = auto_scan_ = false;
|
2024-01-11 07:23:05 +00:00
|
|
|
mb_events_.trigger();
|
2023-12-29 02:53:04 +00:00
|
|
|
if(motor_.get())
|
2024-01-02 07:18:42 +00:00
|
|
|
{
|
2024-01-09 06:26:46 +00:00
|
|
|
motor_->set_auto_paper(false, false);
|
2023-12-29 02:53:04 +00:00
|
|
|
motor_->stop();
|
2024-01-02 07:18:42 +00:00
|
|
|
}
|
2023-12-29 02:53:04 +00:00
|
|
|
|
2023-12-26 01:33:05 +00:00
|
|
|
if(camera_.get())
|
|
|
|
camera_->stop();
|
2024-01-11 07:23:05 +00:00
|
|
|
mb_events_.clear();
|
2023-12-20 07:23:24 +00:00
|
|
|
|
2023-12-19 07:27:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int scanner_hw::close(void)
|
|
|
|
{
|
2023-12-29 02:53:04 +00:00
|
|
|
img_controller_.reset();
|
|
|
|
if(motor_.get())
|
2023-12-19 07:27:16 +00:00
|
|
|
{
|
2023-12-29 02:53:04 +00:00
|
|
|
motor_->stop();
|
|
|
|
motor_.reset();
|
|
|
|
}
|
|
|
|
if(camera_.get())
|
|
|
|
{
|
|
|
|
camera_->stop();
|
|
|
|
camera_->close();
|
|
|
|
camera_.reset();
|
2023-12-19 07:27:16 +00:00
|
|
|
}
|
2024-01-09 06:26:46 +00:00
|
|
|
if(scan_thread_.get() && scan_thread_->joinable())
|
|
|
|
scan_thread_->join();
|
|
|
|
scan_thread_.reset();
|
2023-12-19 07:27:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2024-01-05 09:36:50 +00:00
|
|
|
bool scanner_hw::is_scanning(void)
|
|
|
|
{
|
|
|
|
return scanning_;
|
|
|
|
}
|