From 6655847110ee504fffdade5193cfb46b0eb2847b Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 9 Mar 2024 15:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=9A=E6=B5=81=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=B1=BB=E4=BB=A5=E7=AE=A1=E7=90=86=E5=A4=9A=E6=B5=81?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=8F=8A=E9=A2=9C=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?;=E4=BF=AE=E6=94=B9=E7=94=B5=E6=9C=BA=E6=9D=BF=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sane-opts/multi_out.txt | 49 ++++++++++++ hardware/hardware.cpp | 4 + hardware/motor/motorboard.cpp | 29 +++++-- hardware/motor/motorboard.h | 2 + imgproc/algs/multi_out.cpp | 145 ++++++++++++++++++++++++++++++++++ imgproc/algs/multi_out.h | 34 ++++++++ imgproc/imgprc_mgr.cpp | 2 + sdk/base/words.cpp | 6 ++ sdk/base/words.h | 6 ++ xmake.lua | 2 +- 10 files changed, 271 insertions(+), 8 deletions(-) create mode 100644 docs/sane-opts/multi_out.txt create mode 100644 imgproc/algs/multi_out.cpp create mode 100644 imgproc/algs/multi_out.h diff --git a/docs/sane-opts/multi_out.txt b/docs/sane-opts/multi_out.txt new file mode 100644 index 0000000..1a9d57b --- /dev/null +++ b/docs/sane-opts/multi_out.txt @@ -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" + } +} \ No newline at end of file diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index 6673068..36e539d 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -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; diff --git a/hardware/motor/motorboard.cpp b/hardware/motor/motorboard.cpp index 087c793..2d6d384 100644 --- a/hardware/motor/motorboard.cpp +++ b/hardware/motor/motorboard.cpp @@ -18,15 +18,14 @@ static const std::string loggername = "MotorBoard"; MotorBoard::MotorBoard(std::function 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_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)); m_os_mode = os_mode(); @@ -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 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; - SMBSTATUS *s = (SMBSTATUS *)&val; + 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; } \ No newline at end of file diff --git a/hardware/motor/motorboard.h b/hardware/motor/motorboard.h index 9a1ec41..1b0bf52 100644 --- a/hardware/motor/motorboard.h +++ b/hardware/motor/motorboard.h @@ -9,6 +9,7 @@ #include #include #include +#include //static std::vector frep_cfg(int a,int b,float k,int s) static std::vector 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 event_cb_; + safe_fifo mb_events_; public: MotorBoard(std::function evcb = std::function()); diff --git a/imgproc/algs/multi_out.cpp b/imgproc/algs/multi_out.cpp new file mode 100644 index 0000000..2820e18 --- /dev/null +++ b/imgproc/algs/multi_out.cpp @@ -0,0 +1,145 @@ +#include "multi_out.h" + + +#include +#include +#include + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +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& in, std::vector& 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; +} diff --git a/imgproc/algs/multi_out.h b/imgproc/algs/multi_out.h new file mode 100644 index 0000000..fbe5a7a --- /dev/null +++ b/imgproc/algs/multi_out.h @@ -0,0 +1,34 @@ +// to produce out multi colors or given color images +// +// Date: 2024-03-09 +#pragma once + +#include +#include + +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& in, std::vector& out) override; +}; diff --git a/imgproc/imgprc_mgr.cpp b/imgproc/imgprc_mgr.cpp index 712523c..15f5989 100644 --- a/imgproc/imgprc_mgr.cpp +++ b/imgproc/imgprc_mgr.cpp @@ -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); diff --git a/sdk/base/words.cpp b/sdk/base/words.cpp index 59496c8..6e45cec 100644 --- a/sdk/base/words.cpp +++ b/sdk/base/words.cpp @@ -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"); diff --git a/sdk/base/words.h b/sdk/base/words.h index 2f6a48e..b470589 100644 --- a/sdk/base/words.h +++ b/sdk/base/words.h @@ -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); diff --git a/xmake.lua b/xmake.lua index 8dd96a9..41c9157 100644 --- a/xmake.lua +++ b/xmake.lua @@ -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")