From d91363b1fe68f42fd6f2b26afae117e38f5146d4 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 11 Jan 2024 15:23:05 +0800 Subject: [PATCH] able to get test image :) --- hardware/cis/FpgaComm.cpp | 8 +- hardware/cis/FpgaComm.h | 28 +++-- hardware/cis/gvideoisp1.cpp | 7 +- hardware/hardware.cpp | 49 ++++++-- hardware/hardware.h | 89 +++++++------- hardware/motor/motorboard.cpp | 222 +++++++++++++++++----------------- hardware/uart/PinMonitor.cpp | 4 +- scanner/async_scanner.cpp | 2 +- xmake.lua | 2 +- 9 files changed, 230 insertions(+), 181 deletions(-) diff --git a/hardware/cis/FpgaComm.cpp b/hardware/cis/FpgaComm.cpp index e17a5d1..17d5940 100644 --- a/hardware/cis/FpgaComm.cpp +++ b/hardware/cis/FpgaComm.cpp @@ -22,7 +22,12 @@ FpgaComm::controller::controller() status_.reset(new Gpio(PORT_STATUS)); cfg_.reset(new Gpio(PORT_CONFIG)); reload_.reset(new Gpio(PORT_RELOAD)); - reset_.reset(new Gpio(PORT_RESET)); + reset_.reset(new GpioOut(PORT_RESET)); + + vdd_3voff_.reset(new GpioOut(PORT_VDD_3VOFF)); + vdd_5ven_.reset(new GpioOut(PORT_VDD_5VEN)); + init_done_.reset(new Gpio(PORT_INIT_DONE)); + img_tx_.reset(new Gpio(PORT_IMAGE_TX)); } FpgaComm::controller::~controller() {} @@ -70,6 +75,7 @@ FpgaComm::FpgaComm(int bauds, bool query) : bauds_(bauds) WR_Reg(AledR); controller_->reset(); + resetADC(); } } diff --git a/hardware/cis/FpgaComm.h b/hardware/cis/FpgaComm.h index fefcd41..bf71104 100644 --- a/hardware/cis/FpgaComm.h +++ b/hardware/cis/FpgaComm.h @@ -20,7 +20,7 @@ typedef struct Frame_FPGA typedef struct Mode_FPGA { unsigned short int colorMode : 1; - unsigned short int dpi : 2; + unsigned short int dpi : 2;//0x01 200dpi 0x02 300dpi 0x03 600dpi unsigned short int led : 1; unsigned short sample : 9; unsigned short int adcA : 1; @@ -51,14 +51,14 @@ typedef struct Ad_Gain typedef struct CIS_AD_Gain { - unsigned short int ad0_value : 8; //!< 数据位 - unsigned short int ad0_reserved : 2; //!< 保留位 + unsigned short int ad0_value : 8; //!< 数据? + unsigned short int ad0_reserved : 2; //!< 保留? unsigned short int ad0_addr : 5; //!< 寄存器地址 - unsigned short int ad0_rw : 1; //!< 读写位 1:读, 0:写 - unsigned short int ad1_value : 8; //!< 数据位 - unsigned short int ad1_reserved : 2; //!< 保留位 + unsigned short int ad0_rw : 1; //!< 读写? 1:读, 0:? + unsigned short int ad1_value : 8; //!< 数据? + unsigned short int ad1_reserved : 2; //!< 保留? unsigned short int ad1_addr : 5; //!< 寄存器地址 - unsigned short int ad1_rw : 1; //!< 读写位 1:读, 0:写; + unsigned short int ad1_rw : 1; //!< 读写? 1:读, 0:? } CisAdGain; typedef struct CIS_LED_RF @@ -127,8 +127,10 @@ enum }; enum { - DPI_300 = 0, - DPI_200, + DPI_200 = 1, + DPI_300 = 2, + DPI_600 = 3, + }; class GpioOut; @@ -146,12 +148,20 @@ class FpgaComm : public IRegsAccess PORT_STATUS = 69, PORT_RELOAD = 70, PORT_CONFIG = 71, + PORT_VDD_3VOFF = 96, + PORT_VDD_5VEN = 98, + PORT_INIT_DONE = 99, + PORT_IMAGE_TX = 101, PORT_RESET = 232, }; std::unique_ptr status_; // status reader - port 69 std::unique_ptr reload_; // codes reload - port 70 std::unique_ptr cfg_; // configuration reload - port 71 std::unique_ptr reset_; // circuit reset - port Fpga_Reset + std::unique_ptr vdd_3voff_; + std::unique_ptr vdd_5ven_; + std::unique_ptr init_done_; + std::unique_ptr img_tx_; public: controller(); diff --git a/hardware/cis/gvideoisp1.cpp b/hardware/cis/gvideoisp1.cpp index 47c389f..68d1b19 100644 --- a/hardware/cis/gvideoisp1.cpp +++ b/hardware/cis/gvideoisp1.cpp @@ -141,7 +141,7 @@ void* GVideoISP1::read_frame(int timeout, size_t& size, int& ind) { size = 0; ind = -1; if (!wait(timeout)){ - utils::to_log(LOG_LEVEL_FATAL, "read frame time out!!!\n" ); + utils::to_log(LOG_LEVEL_FATAL, "GVideoISP1::read_frame time out!!!\n" ); return 0; } struct v4l2_plane planes[VIDEO_MAX_PLANES]; @@ -165,6 +165,7 @@ void* GVideoISP1::read_frame(int timeout, size_t& size, int& ind) { // } ind = buf.index; size = buffers[ind].length; + utils::to_log(LOG_LEVEL_DEBUG, "\tvideo buf[%d] = %d\n", ind, size); return buffers[ind].start; } @@ -196,7 +197,7 @@ void GVideoISP1::start_capturing(void) { if (ret < 0) LOG_ERROR(utils::format_string("Unable to queue buffer: %s (%d).\n",strerror(errno), errno)); else - LOG_TRACE(utils::format_string("buf.index = %d VIDIOC_QBUF sucess.\n",i)); + LOG_TRACE(utils::format_string("buf.index = %d, length = %d, VIDIOC_QBUF sucess.\n", i, buf_size_)); } type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; @@ -214,7 +215,7 @@ void GVideoISP1::stop_capturing(void) { type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type)) - LOG_ERROR(utils::format_string("streamo off\n")); + LOG_ERROR(utils::format_string("stream off\n")); LOG_TRACE(utils::format_string("gVideo stop_capturing\n")); } diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index 71233c6..35e7587 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -316,11 +316,18 @@ void scanner_hw::thread_image_capture(void) utils::to_log(LOG_LEVEL_DEBUG, "scanning thread working ...\n"); memset(&img, 0, sizeof(img)); + img.bpp = 8; + img.channels = 3; + img.resolution_x = 200; + img.resolution_y = 200; + img.width = 3888; + img.height = 16380; motor_->clear_error(); - camera_->start(); - img_controller_->capture(); motor_->start(); - mb_events_.take(mbev, true); + 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"); while(scanning_ && mbev.first == MOTOR_BORD_EVENT_LIFTER_READY) // auto scan cycle ... { motor_->pick_paper(); @@ -330,7 +337,7 @@ void scanner_hw::thread_image_capture(void) { size_t size = 0; int ind = -1; - void* frame = camera_->read_frame(10 * 1000, size, ind); + void* frame = camera_->read_frame(3 * 1000, size, ind); dyn_mem_shared_ptr mem = nullptr; if(!frame) @@ -465,6 +472,7 @@ int scanner_hw::set_value(const char* name, void* val) int scanner_hw::open(std::function image_handler) { this->close(); + int fh = 16380; if(!image_handler) return SCANNER_ERR_INVALID_PARAMETER; @@ -476,9 +484,9 @@ int scanner_hw::open(std::function image_handler) img_controller_->setColorMode(mode_ == "\345\275\251\350\211\262" ? COLOR_MODE : GRAY_MODE); img_controller_->setDpi(dpi_ == 200 ? DPI_200 : DPI_300); - img_controller_->setFrameHeight(frame_h_); img_controller_->setDelayTime(delay_); img_controller_->setSample(sample_); + // img_controller_->setSp(2520); void(FpgaComm::* exposure[])(int) = {&FpgaComm::setAExposureB, &FpgaComm::setAExposureG , &FpgaComm::setAExposureR, &FpgaComm::setBExposureB, &FpgaComm::setBExposureG, &FpgaComm::setBExposureR}; @@ -498,9 +506,6 @@ int scanner_hw::open(std::function image_handler) for(int i = 0; i < FpgaComm::CIS_SECTOR_COUNT; ++i) img_controller_->setBOffset(i, off_[SIDE_BACK]); - camera_.reset(new GVideoISP1()); - camera_->open(cis_length_, 1000); - auto cb = [this](int ev, unsigned int data) -> void { mb_events_.save(std::make_pair(ev, data), true); @@ -536,6 +541,31 @@ int scanner_hw::open(std::function image_handler) else utils::to_log(LOG_LEVEL_FATAL, "Get motor-board confige failed.\n"); + 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(); + } + return SCANNER_ERR_OK; } int scanner_hw::start_scan(void) @@ -565,6 +595,7 @@ int scanner_hw::start_scan(void) return DEV_ERR(NO_PAPER); scanning_ = true; + mb_events_.clear(); scan_thread_.reset(new std::thread(&scanner_hw::thread_image_capture, this)); return SCANNER_ERR_OK; @@ -572,6 +603,7 @@ int scanner_hw::start_scan(void) int scanner_hw::stop_scan(void) { scanning_ = auto_scan_ = false; + mb_events_.trigger(); if(motor_.get()) { motor_->set_auto_paper(false, false); @@ -580,6 +612,7 @@ int scanner_hw::stop_scan(void) if(camera_.get()) camera_->stop(); + mb_events_.clear(); return 0; } diff --git a/hardware/hardware.h b/hardware/hardware.h index 4c13d19..5f1c9a8 100644 --- a/hardware/hardware.h +++ b/hardware/hardware.h @@ -23,6 +23,7 @@ class FpgaComm; class GVideoISP1; +class gVideo; class MotorBoard; class scanner_hw : public sane_opt_provider @@ -31,7 +32,7 @@ class scanner_hw : public sane_opt_provider volatile bool scanning_ = false; int time_to_exit_auto_scan_ = 60; // seconds std::unique_ptr img_controller_; - std::unique_ptr camera_; + std::unique_ptr camera_; std::unique_ptr motor_; std::unique_ptr scan_thread_; safe_fifo> mb_events_; @@ -53,7 +54,7 @@ class scanner_hw : public sane_opt_provider std::string family_ = "G200"; volatile bool auto_scan_ = false; int scan_count_ = -1; - int cis_length_ = 1632; + int cis_length_ = 3888; int dpi_ = 300; int baud_ = 921600; int delay_ = 1000; @@ -115,7 +116,7 @@ public: // "resolution": { // "cat": "none", // "group": "CIS", -// "title": "分辨率", +// "title": "分辨?, // "desc": "设置镜头工作的分辨率", // "type": "int", // "fix-id": 34840, @@ -130,7 +131,7 @@ public: // "cat": "base", // "group": "feeder", // "title": "待纸扫描", -// "desc": "启用后,文稿放入扫描仪时将自动启动扫描", +// "desc": "启用后,文稿放入扫描仪时将自动启动扫?, // "type": "bool", // "fix-id": 34873, // "ui-pos": 12, @@ -142,8 +143,8 @@ public: // "wait-scan-exit": { // "cat": "base", // "group": "feeder", -// "title": "待纸扫描退出时间", -// "desc": "设置结束待纸扫描的时间", +// "title": "待纸扫描退出时?, +// "desc": "设置结束待纸扫描的时?, // "type": "string", // "fix-id": 34920, // "ui-pos": 13, @@ -158,7 +159,7 @@ public: // "cat": "base", // "group": "feeder", // "title": "扫描张数", -// "desc": "选择指定数量扫描或连续扫描", +// "desc": "选择指定数量扫描或连续扫?, // "type": "string", // "fix-id": 34862, // "ui-pos": 15, @@ -187,7 +188,7 @@ public: // "cat": "base", // "group": "feeder", // "title": "自动分纸强度", -// "desc": "扫描仪自动修正分纸力度", +// "desc": "扫描仪自动修正分纸力?, // "type": "bool", // "fix-id": 34876, // "ui-pos": 27, @@ -199,7 +200,7 @@ public: // "feed-strength-value": { // "cat": "base", // "group": "feeder", -// "title": " 进纸失败率", +// "title": " 进纸失败?, // "desc": "高于该值时扫描仪将调整分纸力度", // "type": "float", // "fix-id": 34877, @@ -225,9 +226,9 @@ public: // "ui-pos": 30, // "auth": 0, // "size": 12, -// "cur": "一般", -// "default": "一般", -// "range": ["弱", "一般", "强"], +// "cur": "一?, +// "default": "一?, +// "range": ["?, "一?, "?], // "depend": "is-auto-strength!=true" // }, // "time-to-sleep": { @@ -240,14 +241,14 @@ public: // "ui-pos": 33, // "auth": 0, // "size": 16, -// "cur": "不休眠", -// "default": "不休眠", -// "range": ["不休眠", "五分钟", "十分钟", "半小时", "一小时", "两小时", "四小时"] +// "cur": "不休?, +// "default": "不休?, +// "range": ["不休?, "五分?, "十分?, "半小?, "一小时", "两小?, "四小?] // }, // "baud": { // "cat": "none", // "group": "CIS", -// "title": "波特率", +// "title": "波特?, // "desc": "CIS控制通信速率", // "type": "int", // "ui-pos": 20, @@ -261,7 +262,7 @@ public: // "cat": "none", // "group": "CIS", // "title": "延迟响应", -// "desc": "采集头接受命令后的动作延迟时间", +// "desc": "采集头接受命令后的动作延迟时?, // "type": "int", // "ui-pos": 21, // "auth": 0, @@ -273,7 +274,7 @@ public: // "frame-h": { // "cat": "none", // "group": "CIS", -// "title": "帧高度", +// "title": "帧高?, // "desc": "采集头每一帧的采集高度", // "type": "int", // "ui-pos": 22, @@ -297,8 +298,8 @@ public: // "expo-fb": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(正面蓝色通道)", -// "desc": "正面蓝色通道的曝光强度", +// "title": "曝光度(正面蓝色通道?, +// "desc": "正面蓝色通道的曝光强?, // "type": "int", // "ui-pos": 32, // "auth": 0, @@ -314,8 +315,8 @@ public: // "expo-fg": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(正面绿色通道)", -// "desc": "正面绿色通道的曝光强度", +// "title": "曝光度(正面绿色通道?, +// "desc": "正面绿色通道的曝光强?, // "type": "int", // "ui-pos": 31, // "auth": 0, @@ -331,8 +332,8 @@ public: // "expo-fr": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(正面红色通道)", -// "desc": "正面红色通道的曝光强度", +// "title": "曝光度(正面红色通道?, +// "desc": "正面红色通道的曝光强?, // "type": "int", // "ui-pos": 30, // "auth": 0, @@ -348,8 +349,8 @@ public: // "expo-bb": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(背面蓝色通道)", -// "desc": "背面蓝色通道的曝光强度", +// "title": "曝光度(背面蓝色通道?, +// "desc": "背面蓝色通道的曝光强?, // "type": "int", // "ui-pos": 35, // "auth": 0, @@ -365,8 +366,8 @@ public: // "expo-bg": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(背面绿色通道)", -// "desc": "背面绿色通道的曝光强度", +// "title": "曝光度(背面绿色通道?, +// "desc": "背面绿色通道的曝光强?, // "type": "int", // "ui-pos": 34, // "auth": 0, @@ -382,8 +383,8 @@ public: // "expo-br": { // "cat": "none", // "group": "CIS", -// "title": "曝光度(背面红色通道)", -// "desc": "背面红色通道的曝光强度", +// "title": "曝光度(背面红色通道?, +// "desc": "背面红色通道的曝光强?, // "type": "int", // "ui-pos": 33, // "auth": 0, @@ -483,21 +484,21 @@ public: // "double-chk": { // "cat": "none", // "group": "feeder", -// "title": "双张检测", +// "title": "双张检?, // "desc": "检测是否有两张或者多张纸同时搓进", // "type": "string", // "ui-pos": 18, // "auth": 0, // "size": 16, -// "cur": "超声波", -// "default": "超声波", -// "range": ["超声波", "禁用"] +// "cur": "超声?, +// "default": "超声?, +// "range": ["超声?, "禁用"] // }, // "is-staple": { // "cat": "none", // "group": "feeder", -// "title": "装订检测", -// "desc": "检测是否有订书钉存在", +// "title": "装订检?, +// "desc": "检测是否有订书钉存?, // "type": "bool", // "fix-id": 34861, // "ui-pos": 20, @@ -510,7 +511,7 @@ public: // "cat": "none", // "group": "feeder", // "title": "走纸速度", -// "desc": "设置走纸电机的速度,张\/分(PPM)", +// "desc": "设置走纸电机的速度,张\/分(PPM?, // "type": "int", // "ui-pos": 25, // "auth": 0, @@ -534,8 +535,8 @@ public: // "is-check-askew": { // "cat": "none", // "group": "feeder", -// "title": "歪斜检测", -// "desc": "检测进纸是否歪斜", +// "title": "歪斜检?, +// "desc": "检测进纸是否歪?, // "type": "bool", // "fix-id": 34868, // "ui-pos": 22, @@ -547,7 +548,7 @@ public: // "askew-range": { // "cat": "none", // "group": "feeder", -// "title": "歪斜容忍度", +// "title": "歪斜容忍?, // "desc": "值越小,能容忍得送入文稿歪斜角度越小", // "type": "int", // "fix-id": 34869, @@ -566,8 +567,8 @@ public: // "cis-len": { // "cat": "base", // "group": "关于", -// "title": "镜头长", -// "desc": "图像采集镜头的长度,单位为毫米(mm)", +// "title": "镜头?, +// "desc": "图像采集镜头的长度,单位为毫米(mm?, // "type": "int", // "ui-pos": 30, // "auth": 0, @@ -596,8 +597,8 @@ public: // "fpga-ver": { // "cat": "none", // "group": "关于", -// "title": "CIS控制器版本", -// "desc": "镜头参数控制驱动程序版本号", +// "title": "CIS控制器版?, +// "desc": "镜头参数控制驱动程序版本?, // "type": "string", // "ui-pos": 17, // "auth": 0, diff --git a/hardware/motor/motorboard.cpp b/hardware/motor/motorboard.cpp index afd6ece..6598d2a 100644 --- a/hardware/motor/motorboard.cpp +++ b/hardware/motor/motorboard.cpp @@ -81,25 +81,25 @@ bool MotorBoard::en_lifter() { unsigned int val; SMBCONFIG *smbc = (SMBCONFIG *)(&val); - read(0x00, val); + read(MB_PORT_CONFIG, val); smbc->lifter_en = 1; - write(0x00, val); + write(MB_PORT_CONFIG, val); smbc->lifter_en = 0; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } void MotorBoard::pick_paper(void) { unsigned int val,pick_en; SMBCONFIG *smbc = (SMBCONFIG *)(&val); - read(0x00, val); + read(MB_PORT_CONFIG, val); smbc->pick_paper = 0; - write(0x00, val); + write(MB_PORT_CONFIG, val); std::this_thread::sleep_for(std::chrono::microseconds(400)); smbc->pick_paper = 1; - write(0x00, val); + write(MB_PORT_CONFIG, val); std::string v_str = std::to_string(m_version); - if(v_str.size()<8) + // if(v_str.size()<8) return; uint32_t date = atoi(v_str.substr(2,6).c_str()); #ifdef G100 @@ -114,13 +114,13 @@ void MotorBoard::pick_paper(void) if(!(pick_en&0xffff)) { smbc->pick_paper = 0; - write(0x00, val); + write(MB_PORT_CONFIG, val); std::this_thread::sleep_for(std::chrono::microseconds(400)); smbc->pick_paper = 1; - write(0x00, val); + write(MB_PORT_CONFIG, val); } // smbc->pick_paper = 0; - // write(0x00, val); + // write(MB_PORT_CONFIG, val); } void MotorBoard::clean_paper_road(){ @@ -191,11 +191,11 @@ bool MotorBoard::wait_done(int timeout_ms) int MotorBoard::os_mode() { // unsigned int val; - // read(0x02, val); + // read(MB_PORT_MODE, val); // SMB_MODE *smb_mode = (SMB_MODE *)&val; // return smb_mode->scan_mode; unsigned int val; - read(0x06,val); + read(MB_PORT_FUNCTION,val); SMB_FUNC smb_func = *(SMB_FUNC*)&val; return smb_func.param.work_mode == 1; } @@ -203,7 +203,7 @@ int MotorBoard::os_mode() bool MotorBoard::paper_ready() { unsigned int val; - read(0x02, val); + read(MB_PORT_MODE, val); SMB_MODE *smb_mode = (SMB_MODE *)&val; return smb_mode->feeding_paper_ready; } @@ -211,7 +211,7 @@ bool MotorBoard::paper_ready() bool MotorBoard::is_scanning() { unsigned int val; - read(0x02, val); + read(MB_PORT_MODE, val); SMB_MODE *smb_mode = (SMB_MODE *)&val; return smb_mode->work_status; } @@ -219,7 +219,7 @@ bool MotorBoard::is_scanning() int MotorBoard::paper_counter() { unsigned int val; - read(0x02, val); + read(MB_PORT_MODE, val); SMBMODE *smb_mode = (SMBMODE *)&val; return smb_mode->scan_num; } @@ -227,11 +227,11 @@ int MotorBoard::paper_counter() bool MotorBoard::set_paper_inspect_param(unsigned int value /* = 1000 */) { unsigned int val; - if (!read(0x04, val)) + if (!read(MB_PORT_CONFIG_EX, val)) return false; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; smb_config_ext->error_range_set = value; - return write(0x04, val); + return write(MB_PORT_CONFIG_EX, val); } bool MotorBoard::get_keeplastpaper(){ @@ -241,32 +241,32 @@ bool MotorBoard::get_keeplastpaper(){ bool MotorBoard::set_paper_inpect_info(unsigned int value) { unsigned int val; - if (!read(0x04, val)) + if (!read(MB_PORT_CONFIG_EX, val)) return false; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; smb_config_ext->paper_infor = value; - return write(0x04, val); + return write(MB_PORT_CONFIG_EX, val); } bool MotorBoard::set_paper_inspect(bool enable /* = true */) { unsigned int val; - if (!read(0x04, val)) + if (!read(MB_PORT_CONFIG_EX, val)) return false; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; smb_config_ext->paper_size_check_en = enable; - return write(0x04, val); + return write(MB_PORT_CONFIG_EX, val); } bool MotorBoard::set_double_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; // enable?m_statecontrol->lcdcontrol(4):m_statecontrol->lcdcontrol(5); SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->double_paper = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::get_doublle_inpect() { @@ -275,16 +275,16 @@ bool MotorBoard::get_doublle_inpect() bool MotorBoard::set_double_out_en(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->double_out_en = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::get_double_out_en() { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; return smb_config->double_out_en; @@ -292,11 +292,11 @@ bool MotorBoard::get_double_out_en() bool MotorBoard::set_staple_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->staple_enable = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::get_staple_inpect() { @@ -310,35 +310,35 @@ bool MotorBoard::set_cuospeed(int value) return false; SMBCONFIGEXT *smb_config = (SMBCONFIGEXT *)&val; smb_config->cuo_speed = value; - return write(0x04, val); + return write(MB_PORT_CONFIG_EX, val); } // bool MotorBoard::set_en600DPI(bool en) // { // unsigned int val; -// if (!read(0x00, val)) +// if (!read(MB_PORT_CONFIG, val)) // return false; // SMBCONFIG *smb_config = (SMBCONFIG *)&val; // smb_config->dpi600 = en?1:0; -// return write(0x00, val); +// return write(MB_PORT_CONFIG, val); // } bool MotorBoard::set_color_mode(int mode) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->color_mode = mode; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::set_slowmoire(bool en){ unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->slow_moire = en; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } @@ -350,35 +350,35 @@ int MotorBoard::get_color_mode() bool MotorBoard::set_speed_mode(int mode) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->speed_set_enable = 1; smb_config->v_setting = mode; - write(0x00, val); + write(MB_PORT_CONFIG, val); smb_config->speed_set_enable = 0; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::set_speed_mode_v_temp(int mode) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; printf(" set v_tmp = %d \n",mode); SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->speed_set_enable = 1; smb_config->v_temp = mode; - write(0x00, val); + write(MB_PORT_CONFIG, val); smb_config->speed_set_enable = 0; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } int MotorBoard::get_speed_mode() { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return -1; SMBCONFIG *smb_config = (SMBCONFIG *)&val; return smb_config->v_setting; @@ -411,8 +411,6 @@ void MotorBoard::pin_call(unsigned int pinNum) SMBSTATUS *s = (SMBSTATUS *)&val; if (!read(MB_PORT_STATUS, val)) utils::to_log(LOG_LEVEL_FATAL, "read motorboard status failed.\n"); - else - utils::to_log(LOG_LEVEL_DEBUG, "motorboard status = 0x%08x\n", val); if(s->keep_last_paper) // (val & 0x800) { //printf("\n keep_last_paper "); @@ -467,7 +465,7 @@ void MotorBoard::pin_call(unsigned int pinNum) { cv_paper_in.notify_all(); unsigned int papercount = 0; - read(0x02,papercount); + read(MB_PORT_MODE,papercount); SMBMODE smbmode = *(SMBMODE*)&papercount; printf("paper in arm count = %d ,motorcount = %d\n",++countindex,smbmode.scan_num); startcapimage(true); @@ -505,26 +503,26 @@ bool MotorBoard::read(unsigned int addr, unsigned int &val) bool MotorBoard::set_time_error(int value){ unsigned int val; - if (!read(0x05, val)) + if (!read(MB_PORT_TIME, val)) return false; SMBCONFIGTIME *smb_config = (SMBCONFIGTIME *)&val; smb_config->error_time_set = value; - return write(0x05, val); + return write(MB_PORT_TIME, val); } bool MotorBoard::set_screw_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->skew_enable = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::get_screw_inpect() { unsigned int val; - read(0x00, val); + read(MB_PORT_CONFIG, val); SMBCONFIG *smb_mode = (SMBCONFIG *)&val; return smb_mode->skew_enable; } @@ -532,37 +530,37 @@ bool MotorBoard::get_screw_inpect() bool MotorBoard::set_screw_level(int level) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->skew_parameter = level; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::set_auto_paper(bool enable,bool enkey){ unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; // m_statecontrol?m_statecontrol->setautopaperflag(enable,enkey):void(0); SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->autofeed_mode = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } bool MotorBoard::set_long_paper(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(MB_PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->paper = enable; - return write(0x00, val); + return write(MB_PORT_CONFIG, val); } int MotorBoard::get_screw_level() { unsigned int val; - auto ret= read(0x00, val); + auto ret= read(MB_PORT_CONFIG, val); if(!ret) return -1; SMBCONFIG *smb_mode = (SMBCONFIG *)&val; @@ -573,23 +571,23 @@ void MotorBoard::start_countmode() { unsigned int regval=0; - read(0x06,regval); + read(MB_PORT_FUNCTION,regval); utils::to_log(LOG_LEVEL_DEBUG, "func6 regval = 0x%08x\n", regval); SMBFUNC func = *(SMBFUNC*)®val; func.param.work_mode =1; func.param.func_feed_mid = 1; func.param.func_clear_count = 1; utils::to_log(LOG_LEVEL_DEBUG, "func6 value = 0x%08x\n", func.value); - write(0x06,func.value); + write(MB_PORT_FUNCTION,func.value); func.param.func_encount = 1; func.param.key_sound = 1; func.param.func_clear_count = 0; utils::to_log(LOG_LEVEL_DEBUG, "func6 value = 0x%08x\n", func.value); - write(0x06,func.value); + write(MB_PORT_FUNCTION,func.value); func.param.func_encount = 0; func.param.key_sound = 0; utils::to_log(LOG_LEVEL_DEBUG, "func6 value = 0x%08x\n",func.value); - write(0x06,func.value); + write(MB_PORT_FUNCTION,func.value); } @@ -602,28 +600,28 @@ void MotorBoard::PutMsg(int type, int value, int clearscreen) void MotorBoard::errormsg(uint value) { - // if(value & 0x4) - // PutMsg((int)DisType::Dis_Err_CoverOpen,0,(int)ClearScreen::All); - // else if (value & 0x2) - // PutMsg((int)DisType::Dis_Err_NoPaper,0,(int)ClearScreen::All); - // else if (value & 0x8) - // PutMsg((int)DisType::Dis_Err_FeedError,0,(int)ClearScreen::All); - // // else if (value & 0x10) - // // PutMsg((int)DisType::Dis_Err_JamIn,0,(int)ClearScreen::All); - // else if (value & 0x20) - // PutMsg((int)DisType::Dis_Err_DoubleFeed,0,(int)ClearScreen::All); - // else if (value & 0x40) - // PutMsg((int)DisType::Dis_Err_Stable,0,(int)ClearScreen::All); - // else if (value & 0x80) - // PutMsg((int)DisType::Dis_Err_PaperScrew,0,(int)ClearScreen::All); - // else if (value & 0x00010000) - // PutMsg((int)DisType::Dis_Err_AqrImgTimeout,0,(int)ClearScreen::All); - // else if((value & 0x1000010) == 0x1000010) - // PutMsg((int)DisType::Dis_Err_JamIn,3,(int)ClearScreen::All); - // else if((value & 0x800010) == 0x800010) - // PutMsg((int)DisType::Dis_Err_JamIn,2,(int)ClearScreen::All); - // else if((value & 0x400010) == 0x400010) - // PutMsg((int)DisType::Dis_Err_JamIn,1,(int)ClearScreen::All); + if(value & 0x4) + PutMsg((int)DisType::Dis_Err_CoverOpen,0,(int)ClearScreen::All); + else if (value & 0x2) + PutMsg((int)DisType::Dis_Err_NoPaper,0,(int)ClearScreen::All); + else if (value & 0x8) + PutMsg((int)DisType::Dis_Err_FeedError,0,(int)ClearScreen::All); + // else if (value & 0x10) + // PutMsg((int)DisType::Dis_Err_JamIn,0,(int)ClearScreen::All); + else if (value & 0x20) + PutMsg((int)DisType::Dis_Err_DoubleFeed,0,(int)ClearScreen::All); + else if (value & 0x40) + PutMsg((int)DisType::Dis_Err_Stable,0,(int)ClearScreen::All); + else if (value & 0x80) + PutMsg((int)DisType::Dis_Err_PaperScrew,0,(int)ClearScreen::All); + else if (value & 0x00010000) + PutMsg((int)DisType::Dis_Err_AqrImgTimeout,0,(int)ClearScreen::All); + else if((value & 0x1000010) == 0x1000010) + PutMsg((int)DisType::Dis_Err_JamIn,3,(int)ClearScreen::All); + else if((value & 0x800010) == 0x800010) + PutMsg((int)DisType::Dis_Err_JamIn,2,(int)ClearScreen::All); + else if((value & 0x400010) == 0x400010) + PutMsg((int)DisType::Dis_Err_JamIn,1,(int)ClearScreen::All); } void MotorBoard::SetKeyState(bool value) @@ -635,11 +633,11 @@ void MotorBoard::SetKeyState(bool value) void MotorBoard::set_keystopenable(bool value){ unsigned int regval=0; - read(0x06,regval); + read(MB_PORT_FUNCTION,regval); utils::to_log(LOG_LEVEL_DEBUG, "func6 regval = 0x%08x\n", regval); SMBFUNC func = *(SMBFUNC*)®val; func.param.key_stop_enable = value; - write(0x06, regval); + write(MB_PORT_FUNCTION, regval); } @@ -663,14 +661,14 @@ void MotorBoard::set_freq(int motor_choose,int speedmode,int colormode,int dpi) // { // int x = 0; // (dpi == 1?(Get_static_jsonconfig().getscannerinfo().chu_motor_speed_200):(dpi == 2?Get_static_jsonconfig().getscannerinfo().chu_motor_speed_300 : Get_static_jsonconfig().getscannerinfo().chu_motor_speed_600)); // unsigned int regval=0; -// read(0x06,regval); +// read(MB_PORT_FUNCTION,regval); // SMBFUNC func = *(SMBFUNC*)®val; // func.param.motor_choose = motor_choose; // func.param.wr_en = 1; -// write(0x06,func.value); -// write(0x04,x); +// write(MB_PORT_FUNCTION,func.value); +// write(MB_PORT_CONFIG_EX,x); // //func.param.wr_en = 0; -// //write(0x06,func.value); +// //write(MB_PORT_FUNCTION,func.value); // return ; // } // if(motor_choose == 1) @@ -680,7 +678,7 @@ void MotorBoard::set_freq(int motor_choose,int speedmode,int colormode,int dpi) // if(motor_choose == 3) // table = frep_cfg(param.finalPeriod,param.Fmin,param.stepnum,param.a,param.offset,param.finalDelay,param.acceleration_time); // unsigned int regval=0; -// read(0x06,regval); +// read(MB_PORT_FUNCTION,regval); // SMBFUNC func = *(SMBFUNC*)®val; // int start_addr_cuo = 0; // #ifdef G200 @@ -695,12 +693,12 @@ void MotorBoard::set_freq(int motor_choose,int speedmode,int colormode,int dpi) // func.param.motor_choose = motor_choose; // func.param.wr_en = 1; // func.param.motor_addr =i; -// write(0x06,func.value); -// write(0x04,i6) return false; @@ -766,15 +764,15 @@ bool MotorBoard::set_sensor_pwm_duty(int sensorid,int duty) SMBCONFIGTIME *smb_config_time = (SMBCONFIGTIME *)&val; smb_config_time->sen_duty_set_sel = sensorid; smb_config_time->duty_set = duty*8+50; - write(0x05, val); + write(MB_PORT_TIME, val); smb_config_time->sen_duty_set_sel = 0; - return write(0x05, val); + return write(MB_PORT_TIME, val); } bool MotorBoard::enable_sensor_pwm(int sensorid,bool en) { std::uint32_t val; - if (!read(0x05, val)) + if (!read(MB_PORT_TIME, val)) return false; if(sensorid< 1 || sensorid >6) return false; @@ -782,13 +780,13 @@ bool MotorBoard::enable_sensor_pwm(int sensorid,bool en) bit.set(sensorid+6,en); val = bit.to_ulong(); printf("enable_sensor_pwm = %d \n",val); - return write(0x05, val); + return write(MB_PORT_TIME, val); } bool MotorBoard::set_ultrasonic_param(int type,int value){ //1:双张检测周期;2:有无纸检测周期;3:双张阈值;4:单张阈值; unsigned int val; - if (!read(0x07, val)) + if (!read(MB_PORT_ULTROSONIC, val)) return false; if(type< 1 || type >4) return false; @@ -813,9 +811,9 @@ bool MotorBoard::set_ultrasonic_param(int type,int value){ } printf("val = %d \n",val); tmp->param.send_cyc_en = 1; - write(0x07,val); + write(MB_PORT_ULTROSONIC,val); tmp->param.send_cyc_en = 0; - return write(0x07,val); + return write(MB_PORT_ULTROSONIC,val); } void MotorBoard::init_sensor_duty() @@ -837,13 +835,13 @@ void MotorBoard::init_sensor_duty() std::uint32_t MotorBoard::get_ultrasonic_version(){ unsigned int val; - if (!read(0x07, val)) + if (!read(MB_PORT_ULTROSONIC, val)) return 0; SMB_Ultrasonic_Config *tmp = (SMB_Ultrasonic_Config *)&val; tmp->param.rd_ver_en = 1; - write(0x07,val); + write(MB_PORT_ULTROSONIC,val); tmp->param.rd_ver_en = 0; - write(0x07,val); + write(MB_PORT_ULTROSONIC,val); std::this_thread::sleep_for(std::chrono::milliseconds(10)); read(0x08,val); return val; @@ -851,7 +849,7 @@ std::uint32_t MotorBoard::get_ultrasonic_version(){ std::string MotorBoard::getmbversion(){ uint32_t value = 0; - read(0x03, value); + read(MB_PORT_VERSION, value); m_version = value; printf("mb version: = %s \n", std::to_string(value).c_str()); return std::to_string(value); diff --git a/hardware/uart/PinMonitor.cpp b/hardware/uart/PinMonitor.cpp index df99485..d9d76c1 100644 --- a/hardware/uart/PinMonitor.cpp +++ b/hardware/uart/PinMonitor.cpp @@ -71,9 +71,9 @@ void PinMonitor::monitor() //LOG_TRACE("poll call"); if (call_back) { - sw.reset(); + // sw.reset(); call_back(pin.getPort()); - utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("poll call times = %.2f \n",sw.elapse_ms()).c_str()); + // utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("= %.2f \n",sw.elapse_ms()).c_str()); } diff --git a/scanner/async_scanner.cpp b/scanner/async_scanner.cpp index 51b4605..beee270 100644 --- a/scanner/async_scanner.cpp +++ b/scanner/async_scanner.cpp @@ -457,7 +457,7 @@ dyn_mem_ptr async_scanner::handle_scan_start(LPPACK_BASE pack, uint32_t* used, p FILE* dst = fopen(("/tmp/scan_" + std::to_string(lpinfo->pos.paper_ind) + ".bmp").c_str(), "wb"); if(dst) { - std::string bih(utils::bitmap_info_header(lpinfo->width, lpinfo->height, lpinfo->bpp, lpinfo->resolution_x, lpinfo->resolution_y)), + std::string bih(utils::bitmap_info_header(lpinfo->width, lpinfo->height, lpinfo->bpp * lpinfo->channels, lpinfo->resolution_x, lpinfo->resolution_y)), bfh(utils::bitmap_file_header((BITMAPINFOHEADER*)&bih[0])); fwrite(bfh.c_str(), 1, bfh.length(), dst); fwrite(bih.c_str(), 1, bih.length(), dst); diff --git a/xmake.lua b/xmake.lua index 7fcdb30..eb87783 100644 --- a/xmake.lua +++ b/xmake.lua @@ -60,7 +60,7 @@ add_packagedirs("sdk") add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=300") -add_defines("VER_DATE=20240109") +add_defines("VER_DATE=20240111") add_defines("VER_BUILD=14") target("conf")