添加多流输出类以管理多流输出及颜色模式;修改电机板事件获取逻辑

This commit is contained in:
gb 2024-03-09 15:38:23 +08:00
parent b7c0f6600a
commit 6655847110
10 changed files with 271 additions and 8 deletions

View File

@ -0,0 +1,49 @@
{
"is-multiout": {
"cat": "base",
"group": "base",
"title": "多流输出",
"desc": "同时输出多种颜色模式的图像",
"type": "bool",
"pos": 40,
"fix-id": 34817,
"ui-pos": 10,
"auth": 0,
"size": 4,
"cur": false,
"default": false
},
"multiout-type": {
"cat": "base",
"group": "base",
"title": "多流输出类型",
"desc": "选择多流输出的类型",
"type": "string",
"pos": 41,
"fix-id": 34818,
"ui-pos": 11,
"auth": 0,
"enabled": false,
"size": 66,
"cur": "彩色+灰度+黑白",
"default": "彩色+灰度+黑白",
"range": ["彩色+灰度+黑白", "彩色+灰度", "彩色+黑白", "灰度+黑白"],
"depend": "is-multiout==true"
},
"mode": {
"cat": "base",
"group": "base",
"title": "颜色模式",
"desc": "选择色彩模式",
"type": "string",
"pos": 50,
"fix-id": 34819,
"ui-pos": 15,
"auth": 0,
"size": 24,
"cur": "24位彩色",
"default": "24位彩色",
"range": ["24位彩色", "256级灰度", "黑白", "颜色自动识别"],
"depend": "is-multiout!=true"
}
}

View File

@ -434,6 +434,10 @@ void scanner_hw::thread_image_capture(bool paper_ready)
}
break;
}
else if(fatal == MOTOR_BORD_EVENT_SCAN_DONE)
{
motor_->clear_error();
}
}
if(!waited)
break;

View File

@ -18,14 +18,13 @@ static const std::string loggername = "MotorBoard";
MotorBoard::MotorBoard(std::function<void(int, unsigned int)> evcb)
: devPort(MOTOR_UART), event_cb_(evcb)
, autopaperkeystop(nullptr)
, autopaperkeystop(nullptr), mb_events_("motor-events")
{
// LOG_INIT();
//m_uartEnable.reset(new GpioOut(149));
//m_uartEnable->setValue(Gpio::Low);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
m_regsAccess.reset(new UartRegsAccess(devPort, bauds, 0x07, 0x87));
if(event_cb_)
m_intPinMonitor.reset(new PinMonitor(intport, std::bind(&MotorBoard::pin_call, this, std::placeholders::_1)));
//m_uartEnable->setValue(Gpio::High);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -153,6 +152,8 @@ void MotorBoard::clear_error()
write(0, val);
smbc->error_clean = 0;
write(0, val);
mb_events_.clear();
}
bool MotorBoard::wait_arrival_top(int timeout_ms)
@ -395,6 +396,17 @@ std::shared_ptr<IRegsAccess> MotorBoard::regs()
static int countindex =0;
void MotorBoard::pin_call(unsigned int pinNum)
{
if(!event_cb_)
{
unsigned int val = 0;
if (!read(MB_PORT_STATUS, val))
utils::to_log(LOG_LEVEL_FATAL, "read motorboard status failed.\n");
else
mb_events_.save(val, true);
return;
}
static int index = 0;
// int os_m = os_mode(); //安路屏蔽计数 扫描过程中无法操作按键
// if (m_os_mode != os_m)
@ -881,12 +893,12 @@ bool MotorBoard::wait_event(int event, int *evdata, int to_ms, int* fatal_ev, in
*fatal_ev = 0;
while(watch.elapse_ms() < to_ms)
{
unsigned int val = 0;
int val = 0;
SMBSTATUS *s = (SMBSTATUS *)&val;
if (!read(MB_PORT_STATUS, val))
// if (!read(MB_PORT_STATUS, val))
if(!mb_events_.take(val))
{
utils::to_log(LOG_LEVEL_FATAL, "read motorboard status failed.\n");
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}
@ -981,5 +993,8 @@ bool MotorBoard::wait_event(int event, int *evdata, int to_ms, int* fatal_ev, in
}
}
printf("\twait event %d = %s: evdata = %d, fatal_ev = %d\n", event, waited ? "true" : "false"
, *evdata, *fatal_ev);
return waited;
}

View File

@ -9,6 +9,7 @@
#include <vector>
#include <atomic>
#include <base/ui.h>
#include <base/utils.h>
//static std::vector<std::uint32_t> frep_cfg(int a,int b,float k,int s)
static std::vector<std::uint32_t> frep_cfg(int finalPeriod, int Fmin, float stepnum, float a, float offset, float finalDelay,float acceleration_time)
@ -211,6 +212,7 @@ enum
class MotorBoard
{
std::function<void(int, unsigned int)> event_cb_;
safe_fifo<int> mb_events_;
public:
MotorBoard(std::function<void(int, unsigned int)> evcb = std::function<void(int, unsigned int)>());

145
imgproc/algs/multi_out.cpp Normal file
View File

@ -0,0 +1,145 @@
#include "multi_out.h"
#include <huagao/hgscanner_error.h>
#include <sane/sane_ex.h>
#include <base/utils.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
static std::string device_opt_json[] = {
"{\"is-multiout\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"pos\":40,\"fix-id\":34817,\"ui-pos\":10,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"multiout-type\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"pos\":41,\"fix-id\":34818,\"ui-pos\":11,\"auth\":0,\"enabled\":false,\"size\":66,\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend\":\"is-multiout==true\"},\"mode\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"pos\":50,\"fix-id\":34819,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend\":\"is-multiout!=true\"}}"
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
multi_out::multi_out(bool weaker) : image_processor("multi_out")
{
if(weaker)
return;
ADD_THIS_JSON();
}
multi_out::~multi_out()
{}
void multi_out::refresh_final_mode(void)
{
if(multi_)
{
coef_ = 2;
if(multi_str_ == WORDS_MULTI_OUT_GBW)
{
clr_ = false;
gray_ = bw_ = true;
}
else if(multi_str_ == WORDS_MULTI_OUT_CG)
{
clr_ = gray_ = true;
bw_ = false;
}
else if(multi_str_ == WORDS_MULTI_OUT_CBW)
{
clr_ = bw_ = true;
gray_ = false;
}
else
{
coef_ = 3;
clr_ = gray_ = bw_ = true;
}
}
else
{
coef_ = 1;
if(mode_str_.find(WORDS_COLOR_BW) != std::string::npos)
{
clr_ = gray_ = false;
bw_ = true;
}
else if(mode_str_.find(WORDS_COLOR_GRAY) != std::string::npos)
{
clr_ = bw_ = false;
gray_ = true;
}
else
{
clr_ = true;
gray_ = bw_ = false;
}
}
}
int multi_out::set_value(const char* name/*nullptr for all options*/, void* val/*nullptr for restore*/)
{
int ret = SCANNER_ERR_OK;
if(strcmp(name, SANE_OPT_NAME(IS_MULTI_OUT)) == 0)
{
multi_ = *(bool*)val;
refresh_final_mode();
}
else if(strcmp(name, SANE_OPT_NAME(MULTI_OUT_TYPE)) == 0)
{
multi_str_ = (char*)val;
refresh_final_mode();
}
else if(strcmp(name, SANE_OPT_NAME(COLOR_MODE)) == 0)
{
mode_str_ = (char*)val;
refresh_final_mode();
}
else
ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
return ret;
}
image_processor* multi_out::copy_weaker(void)
{
multi_out *weaker = new multi_out(true);
weaker->pos_ = pos_;
weaker->enabled_ = enabled_;
weaker->multi_ = multi_;
weaker->clr_ = clr_;
weaker->gray_ = gray_;
weaker->bw_ = bw_;
weaker->coef_ = coef_;
return weaker;
}
int multi_out::process(std::vector<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& out)
{
int cnt = in.size() * coef_,
index = 0;
for(auto& v: in)
{
if(clr_ && v.info.channels == 3)
{
PROCIMGINFO o = v;
o.info.prc_stage = get_position();
o.info.prc_time = 0;
o.info.pos.paper_all = cnt;
o.info.pos.ind_in_paper = index++;
out.push_back(o);
}
if(gray_)
{
}
if(bw_)
{
}
}
return SCANNER_ERR_OK;
}

34
imgproc/algs/multi_out.h Normal file
View File

@ -0,0 +1,34 @@
// to produce out multi colors or given color images
//
// Date: 2024-03-09
#pragma once
#include <imgprc/img_processor.h>
#include <base/words.h>
class multi_out : public image_processor
{
bool multi_ = false;
bool clr_ = true;
bool gray_ = false;
bool bw_ = false;
int coef_ = 1;
std::string mode_str_ = WORDS_COLOR_COLOR;
std::string multi_str_ = WORDS_MULTI_OUT_ALL;
void refresh_final_mode(void);
public:
multi_out(bool weaker = false);
protected:
~multi_out();
public:
virtual int set_value(const char* name/*nullptr for all options*/, void* val/*nullptr for restore*/) override;
public:
virtual image_processor* copy_weaker(void) override;
virtual int process(std::vector<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& out) override;
};

View File

@ -10,6 +10,7 @@
#include "./algs/stretch.h"
#include "./algs/auto_crop.h"
#include "./algs/color_correct.h"
#include "./algs/multi_out.h"
#include "./algs/ImageProcess_Public.h"
@ -501,6 +502,7 @@ int imgproc_mgr::load_processor(const char* path)
ADD_IMG_PROCESSOR(stretch);
ADD_IMG_PROCESSOR(auto_crop);
ADD_IMG_PROCESSOR(color_correct);
ADD_IMG_PROCESSOR(multi_out);
// ADD_IMG_PROCESSOR(img_encoder);
std::sort(processors_.begin(), processors_.end(), &imgproc_mgr::sort_processor_by_pos);

View File

@ -15,6 +15,12 @@
WORDS_AND_ID_IMPL(WORDS_COLOR_COLOR, "\345\275\251\350\211\262");
WORDS_AND_ID_IMPL(WORDS_COLOR_GRAY, "\347\201\260\345\272\246");
WORDS_AND_ID_IMPL(WORDS_COLOR_BW, "\351\273\221\347\231\275");
WORDS_AND_ID_IMPL(WORDS_MULTI_OUT_ALL, "\345\275\251\350\211\262+\347\201\260\345\272\246+\351\273\221\347\231\275");
WORDS_AND_ID_IMPL(WORDS_MULTI_OUT_CG, "\345\275\251\350\211\262+\347\201\260\345\272\246");
WORDS_AND_ID_IMPL(WORDS_MULTI_OUT_CBW, "\345\275\251\350\211\262+\351\273\221\347\231\275");
WORDS_AND_ID_IMPL(WORDS_MULTI_OUT_GBW, "\347\201\260\345\272\246+\351\273\221\347\231\275");
WORDS_AND_ID_IMPL(WORDS_PAPER_ORIGIN_SIZE, "\345\214\271\351\205\215\345\216\237\345\247\213\345\260\272\345\257\270");
WORDS_AND_ID_IMPL(WORDS_PAPER_MAX_SIZE_CROP, "\346\234\200\345\244\247\346\211\253\346\217\217\345\260\272\345\257\270\350\207\252\345\212\250\350\243\201\345\210\207");

View File

@ -28,6 +28,12 @@ const char* words_from_id(int id);
//
WORDS_AND_ID_DECL(WORDS_COLOR_COLOR);
WORDS_AND_ID_DECL(WORDS_COLOR_GRAY);
WORDS_AND_ID_DECL(WORDS_COLOR_BW);
WORDS_AND_ID_DECL(WORDS_MULTI_OUT_ALL); // color + gray + BW
WORDS_AND_ID_DECL(WORDS_MULTI_OUT_CG); // color + gray
WORDS_AND_ID_DECL(WORDS_MULTI_OUT_CBW); // color + BW
WORDS_AND_ID_DECL(WORDS_MULTI_OUT_GBW); // gray + BW
WORDS_AND_ID_DECL(WORDS_PAPER_ORIGIN_SIZE);
WORDS_AND_ID_DECL(WORDS_PAPER_MAX_SIZE_CROP);

View File

@ -61,7 +61,7 @@ add_defines("BUILD_AS_DEVICE")
add_defines("VER_MAIN=2")
add_defines("VER_FAMILY=200")
add_defines("VER_DATE=20240309")
add_defines("VER_BUILD=5")
add_defines("VER_BUILD=12")
target("conf")
set_kind("phony")