diff --git a/hardware/cis/gvideo.cpp b/hardware/cis/gvideo.cpp index 2e67da1..31ec4ec 100644 --- a/hardware/cis/gvideo.cpp +++ b/hardware/cis/gvideo.cpp @@ -110,7 +110,7 @@ bool gVideo::wait(int msTimeout) { void* gVideo::read_frame(int timeout) { if (!wait(timeout)){ - utils::to_log(LOG_LEVEL_FATAL, "read frame time out"); + utils::to_log(LOG_LEVEL_FATAL, "read frame time out\n"); return 0; } v4l2_buffer buf; @@ -141,7 +141,7 @@ void gVideo::stop_capturing(void) { type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type)) - utils::to_log(LOG_LEVEL_FATAL, "streamo off"); + utils::to_log(LOG_LEVEL_FATAL, "streamo off\n"); } unsigned int querybuf_length; @@ -168,14 +168,14 @@ void gVideo::start_capturing(void) buf.length = 1; if (-1 == ioctl(fd, VIDIOC_QBUF, &buf)) - LOG_ERROR(utils::format_string("VIDIOC_QBUF Error %d", i)); + LOG_ERROR(utils::format_string("VIDIOC_QBUF Error %d\n", i)); else LOG_ERROR(utils::format_string("VIDIOC_QBUF %d\n", i)); } type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == ioctl(fd, VIDIOC_STREAMON, &type)) - utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_STREAMON"); + utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_STREAMON\n"); } void gVideo::uninit_device(void) @@ -185,16 +185,16 @@ void gVideo::uninit_device(void) struct v4l2_requestbuffers req; CLEAR(req); req.count = 0; - LOG_TRACE(utils::format_string("frame count: %d", req.count)); + LOG_TRACE(utils::format_string("frame count: %d\n", req.count)); req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_USERPTR; if (-1 == ioctl(fd, VIDIOC_REQBUFS, &req)) { if (EINVAL == errno) - utils::to_log(LOG_LEVEL_FATAL, "does not support user pointer i/o"); + utils::to_log(LOG_LEVEL_FATAL, "does not support user pointer i/o\n"); else - utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS"); + utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS\n"); } for (int i = 0; i < n_buffers; ++i) @@ -398,9 +398,9 @@ void printCamInfo(int fd) while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) { if(frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) - LOG_TRACE(utils::format_string("line:%d %dx%d", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); + LOG_TRACE(utils::format_string("line:%d %dx%d\n", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) - LOG_TRACE(utils::format_string("line:%d %dx%d", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); + LOG_TRACE(utils::format_string("line:%d %dx%d\n", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); frmsize.index++; } fmt_1.index++; @@ -413,16 +413,16 @@ void gVideo::init_device(void) { printCamInfo(fd); if (-1 == ioctl(fd, VIDIOC_QUERYCAP, &cap)) { if (EINVAL == errno) - LOG_ERROR(utils::format_string("%s is no V4L2 device", dev_name.c_str())); + LOG_ERROR(utils::format_string("%s is no V4L2 device\n", dev_name.c_str())); else - utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_QUERYCAP"); + utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_QUERYCAP\n"); } if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) - LOG_ERROR(utils::format_string("%s is no video capture device", dev_name.c_str())); + LOG_ERROR(utils::format_string("%s is no video capture device\n", dev_name.c_str())); if (!(cap.capabilities & V4L2_CAP_STREAMING)) - LOG_ERROR(utils::format_string("%s does not support streaming i/o", dev_name.c_str())); + LOG_ERROR(utils::format_string("%s does not support streaming i/o\n", dev_name.c_str())); CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -433,13 +433,13 @@ void gVideo::init_device(void) { fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; if (-1 == ioctl(fd, VIDIOC_S_FMT, &fmt)) - utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_S_FMT error"); + utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_S_FMT error\n"); init_mmap(); } void gVideo::close_device(void) { if (-1 == ::close(fd)) - utils::to_log(LOG_LEVEL_DEBUG, "close"); + utils::to_log(LOG_LEVEL_DEBUG, "close\n"); fd = -1; } @@ -447,5 +447,5 @@ void gVideo::close_device(void) { void gVideo::open_device(void) { if((fd = ::open(dev_name.c_str(), O_RDWR /* required */ /*| O_NONBLOCK*/, 0)) == -1) - LOG_ERROR(utils::format_string("Cannot open %s", dev_name.c_str())); + LOG_ERROR(utils::format_string("Cannot open %s\n", dev_name.c_str())); } \ No newline at end of file diff --git a/hardware/cis/gvideoisp1.cpp b/hardware/cis/gvideoisp1.cpp index bdf18f8..86b9207 100644 --- a/hardware/cis/gvideoisp1.cpp +++ b/hardware/cis/gvideoisp1.cpp @@ -157,10 +157,10 @@ void* GVideoISP1::read_frame(int timeout) { ret = ioctl(fd, VIDIOC_DQBUF, &buf); if (ret < 0) { - LOG_TRACE(utils::format_string("Unable to dequeue buffer: %s (%d).",strerror(errno), errno)); + LOG_TRACE(utils::format_string("Unable to dequeue buffer: %s (%d).\n",strerror(errno), errno)); } else { - LOG_TRACE(utils::format_string("VIDIOC_DQBUF sucess")); + LOG_TRACE(utils::format_string("VIDIOC_DQBUF sucess\n")); } @@ -169,7 +169,7 @@ void* GVideoISP1::read_frame(int timeout) { LOG_ERROR(utils::format_string("Unable to requeue buffer: %s (%d).\n",strerror(errno), errno)); } else { - LOG_TRACE(utils::format_string("VIDIOC_QBUF sucess")); + LOG_TRACE(utils::format_string("VIDIOC_QBUF sucess\n")); } LOG_TRACE(utils::format_string("buf.index = %d,buf.addr = %p\n",buf.index,buffers[buf.index].start)); return buffers[buf.index].start; @@ -200,18 +200,18 @@ void GVideoISP1::start_capturing(void) { ret = ioctl(fd, VIDIOC_QBUF, &buf); if (ret < 0) - LOG_ERROR(utils::format_string("Unable to queue buffer: %s (%d).",strerror(errno), errno)); + 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.",i)); + LOG_TRACE(utils::format_string("buf.index = %d VIDIOC_QBUF sucess.\n",i)); } type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; ret = ioctl(fd, VIDIOC_STREAMON, &type); if (ret < 0) { - LOG_ERROR(utils::format_string("Unable to %s streaming: %s (%d).","start", strerror(errno), errno)); + LOG_ERROR(utils::format_string("Unable to %s streaming: %s (%d).\n","start", strerror(errno), errno)); } else { - LOG_TRACE(utils::format_string("VIDIOC_STREAMON sucess.")); + LOG_TRACE(utils::format_string("VIDIOC_STREAMON sucess.\n")); } } @@ -220,9 +220,9 @@ 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")); + LOG_ERROR(utils::format_string("streamo off\n")); - LOG_TRACE(utils::format_string("gVideo stop_capturing")); + LOG_TRACE(utils::format_string("gVideo stop_capturing\n")); } static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_source) @@ -428,12 +428,13 @@ static const char *v4l2_format_name(unsigned int fourcc) return name; } -static void video_enum_frame_intervals(int fd, __u32 pixelformat, +static std::string video_enum_frame_intervals(int fd, __u32 pixelformat, unsigned int width, unsigned int height) { struct v4l2_frmivalenum ival; unsigned int i; int ret; + std::string fsdesc(""); for (i = 0; ; ++i) { memset(&ival, 0, sizeof ival); @@ -459,21 +460,23 @@ static void video_enum_frame_intervals(int fd, __u32 pixelformat, switch (ival.type) { case V4L2_FRMIVAL_TYPE_DISCRETE: - LOG_TRACE(utils::format_string("%u/%u", ival.discrete.numerator, ival.discrete.denominator)); - break; + fsdesc = utils::format_string("%u/%u", ival.discrete.numerator, ival.discrete.denominator); + return std::move(fsdesc); case V4L2_FRMIVAL_TYPE_CONTINUOUS: - LOG_TRACE(utils::format_string("%u/%u - %u/%u", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator)); - return; + fsdesc = utils::format_string("%u/%u - %u/%u", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator); + return std::move(fsdesc); case V4L2_FRMIVAL_TYPE_STEPWISE: - LOG_TRACE(utils::format_string("%u/%u - %u/%u (by %u/%u)", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator, ival.stepwise.step.numerator, ival.stepwise.step.denominator)); - return; + fsdesc = utils::format_string("%u/%u - %u/%u (by %u/%u)", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator, ival.stepwise.step.numerator, ival.stepwise.step.denominator); + return std::move(fsdesc); default: break; } } + + return std::move(fsdesc); } static void video_enum_frame_sizes(int fd, __u32 pixelformat) @@ -497,18 +500,18 @@ static void video_enum_frame_sizes(int fd, __u32 pixelformat) switch (frame.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: - LOG_TRACE(utils::format_string("\tFrame size: %ux%u (", frame.discrete.width, frame.discrete.height)); - video_enum_frame_intervals(fd, frame.pixel_format, frame.discrete.width, frame.discrete.height); + LOG_TRACE(utils::format_string("\tFrame size: %ux%u (%s)\n", frame.discrete.width, frame.discrete.height, + video_enum_frame_intervals(fd, frame.pixel_format, frame.discrete.width, frame.discrete.height).c_str())); break; case V4L2_FRMSIZE_TYPE_CONTINUOUS: - LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height)); - video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height); + LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (%s)\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height, + video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height).c_str())); break; case V4L2_FRMSIZE_TYPE_STEPWISE: - LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (by %ux%u) (\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height, frame.stepwise.step_width, frame.stepwise.step_height)); - video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height); + LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (by %ux%u) (%s)\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height, frame.stepwise.step_width, frame.stepwise.step_height, + video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height).c_str())); break; default: @@ -537,7 +540,7 @@ static void video_enum_formats(int fd, enum v4l2_buf_type type) if (type != fmt.type) LOG_TRACE(utils::format_string("Warning: driver returned wrong format type " "%u.\n", fmt.type)); - LOG_TRACE(utils::format_string("\tFormat %u: %s (%08x)\n", i, v4l2_format_name(fmt.pixelformat), fmt.pixelformat)); + LOG_TRACE(utils::format_string("Format %u: %s (%08x)\n", i, v4l2_format_name(fmt.pixelformat), fmt.pixelformat)); LOG_TRACE(utils::format_string("\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type), fmt.type)); LOG_TRACE(utils::format_string("\tName: %.32s\n", fmt.description)); video_enum_frame_sizes(fd, fmt.pixelformat); @@ -880,7 +883,7 @@ void GVideoISP1::init_device(void) { LOG_TRACE(utils::format_string("Unable to get format: %s (%d).\n", strerror(errno),errno)); } else { - utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_G_FMT sucess."); + utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_G_FMT sucess.\n"); } LOG_TRACE(utils::format_string("Video format: %s (%08x) %ux%u field %s, %u planes: \n", v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes)); for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index dafcd6f..47a12a8 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -9,7 +9,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////// // scanner_hw static std::string device_opt_json[] = { - "{\"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\":300,\"default\":300,\"range\":[200,300]},\"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\"},\"baud\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u6ce2\\u7279\\u7387\",\"desc\":\"CIS\\u63a7\\u5236\\u901a\\u4fe1\\u901f\\u7387\",\"type\":\"int\",\"ui-pos\":20,\"auth\":0,\"size\":4,\"cur\":921600,\"default\":921600,\"range\":[110,300,600,1200,2400,4800,9600,19200,38400,57600,115200,500000,921600,1500000]},\"act-after\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u5ef6\\u8fdf\\u54cd\\u5e94\",\"desc\":\"\\u91c7\\u96c6\\u5934\\u63a5\\u53d7\\u547d\\u4ee4\\u540e\\u7684\\u52a8\\u4f5c\\u5ef6\\u8fdf\\u65f6\\u95f4\",\"type\":\"int\",\"ui-pos\":21,\"auth\":0,\"unit\":\"microsec\",\"size\":4,\"cur\":1000,\"default\":1000},\"frame-h\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u5e27\\u9ad8\\u5ea6\",\"desc\":\"\\u91c7\\u96c6\\u5934\\u6bcf\\u4e00\\u5e27\\u7684\\u91c7\\u96c6\\u9ad8\\u5ea6\",\"type\":\"int\",\"ui-pos\":22,\"auth\":0,\"size\":4,\"cur\":12,\"default\":12},\"sample\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u91c7\\u6837\\u9891\\u7387\",\"desc\":\"\\u91c7\\u6837\\u9891\\u7387\",\"type\":\"int\",\"ui-pos\":23,\"auth\":0,\"size\":4,\"cur\":256,\"default\":256},\"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\":32,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"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\":31,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"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\":30,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"expo-bb\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u80cc\\u9762\\u84dd\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u80cc\\u9762\\u84dd\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":35,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"expo-bg\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u80cc\\u9762\\u7eff\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7eff\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":34,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"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\":33,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"gain-f\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u6b63\\u9762\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":40,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"gain-b\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u80cc\\u9762\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":41,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"off-f\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":45,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-100,\"max\":100,\"step\":1}},\"off-b\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u80cc\\u9762\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":46,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-100,\"max\":100,\"step\":1}},\"paper-on\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u7eb8\\u5f20\\u5c31\\u7eea\",\"desc\":\"\\u7eb8\\u5f20\\u5df2\\u7ecf\\u5728\\u8fdb\\u7eb8\\u53f0\\u4e0a\\u653e\\u7f6e\\u597d\",\"type\":\"bool\",\"fix-id\":34912,\"ui-pos\":15,\"auth\":0,\"readonly\":true,\"size\":4,\"auto\":false,\"ownread\":true,\"cur\":false,\"default\":false},\"double-chk\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u53cc\\u5f20\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u6709\\u4e24\\u5f20\\u6216\\u8005\\u591a\\u5f20\\u7eb8\\u540c\\u65f6\\u6413\\u8fdb\",\"type\":\"string\",\"ui-pos\":16,\"auth\":0,\"size\":16,\"cur\":\"\\u8d85\\u58f0\\u6ce2\",\"default\":\"\\u8d85\\u58f0\\u6ce2\",\"range\":[\"\\u8d85\\u58f0\\u6ce2\",\"\\u7981\\u7528\"]},\"is-staple\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u88c5\\u8ba2\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u6709\\u8ba2\\u4e66\\u9489\\u5b58\\u5728\",\"type\":\"bool\",\"fix-id\":34861,\"ui-pos\":17,\"auth\":0,\"size\":4,\"cur\":true,\"default\":true},\"motor-speed\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u8d70\\u7eb8\\u901f\\u5ea6\",\"desc\":\"\\u8bbe\\u7f6e\\u8d70\\u7eb8\\u7535\\u673a\\u7684\\u901f\\u5ea6\\uff0c\\u5f20\\/\\u5206\\uff08PPM\\uff09\",\"type\":\"int\",\"ui-pos\":18,\"auth\":0,\"size\":4,\"cur\":100,\"default\":100,\"range\":[70,100,120,150]},\"is-check-askew\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u6b6a\\u659c\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u8fdb\\u7eb8\\u662f\\u5426\\u6b6a\\u659c\",\"type\":\"bool\",\"fix-id\":34868,\"ui-pos\":19,\"auth\":0,\"size\":4,\"cur\":true,\"default\":true}}" + "{\"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\":300,\"default\":300,\"range\":[200,300]},\"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\"},\"baud\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u6ce2\\u7279\\u7387\",\"desc\":\"CIS\\u63a7\\u5236\\u901a\\u4fe1\\u901f\\u7387\",\"type\":\"int\",\"ui-pos\":20,\"auth\":0,\"size\":4,\"cur\":921600,\"default\":921600,\"range\":[110,300,600,1200,2400,4800,9600,19200,38400,57600,115200,500000,921600,1500000]},\"act-after\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u5ef6\\u8fdf\\u54cd\\u5e94\",\"desc\":\"\\u91c7\\u96c6\\u5934\\u63a5\\u53d7\\u547d\\u4ee4\\u540e\\u7684\\u52a8\\u4f5c\\u5ef6\\u8fdf\\u65f6\\u95f4\",\"type\":\"int\",\"ui-pos\":21,\"auth\":0,\"unit\":\"microsec\",\"size\":4,\"cur\":1000,\"default\":1000},\"frame-h\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u5e27\\u9ad8\\u5ea6\",\"desc\":\"\\u91c7\\u96c6\\u5934\\u6bcf\\u4e00\\u5e27\\u7684\\u91c7\\u96c6\\u9ad8\\u5ea6\",\"type\":\"int\",\"ui-pos\":22,\"auth\":0,\"size\":4,\"cur\":12,\"default\":12},\"sample\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u91c7\\u6837\\u9891\\u7387\",\"desc\":\"\\u91c7\\u6837\\u9891\\u7387\",\"type\":\"int\",\"ui-pos\":23,\"auth\":0,\"size\":4,\"cur\":256,\"default\":256},\"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\":32,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"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\":31,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"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\":30,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"expo-bb\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u80cc\\u9762\\u84dd\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u80cc\\u9762\\u84dd\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":35,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"expo-bg\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u66dd\\u5149\\u5ea6\\uff08\\u80cc\\u9762\\u7eff\\u8272\\u901a\\u9053\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7eff\\u8272\\u901a\\u9053\\u7684\\u66dd\\u5149\\u5f3a\\u5ea6\",\"type\":\"int\",\"ui-pos\":34,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"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\":33,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"gain-f\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u6b63\\u9762\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":40,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"gain-b\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\uff08\\u80cc\\u9762\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7684\\u589e\\u76ca\\u91cf\",\"type\":\"int\",\"ui-pos\":41,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-1000,\"max\":1000,\"step\":1}},\"off-f\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u6b63\\u9762\\uff09\",\"desc\":\"\\u6b63\\u9762\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":45,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-100,\"max\":100,\"step\":1}},\"off-b\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"\\u589e\\u76ca\\u8865\\u507f\\uff08\\u80cc\\u9762\\uff09\",\"desc\":\"\\u80cc\\u9762\\u7684\\u589e\\u76ca\\u8865\\u507f\\u91cf\",\"type\":\"int\",\"ui-pos\":46,\"auth\":0,\"size\":4,\"cur\":0,\"default\":0,\"range\":{\"min\":-100,\"max\":100,\"step\":1}},\"paper-on\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u7eb8\\u5f20\\u5c31\\u7eea\",\"desc\":\"\\u7eb8\\u5f20\\u5df2\\u7ecf\\u5728\\u8fdb\\u7eb8\\u53f0\\u4e0a\\u653e\\u7f6e\\u597d\",\"type\":\"bool\",\"fix-id\":34912,\"ui-pos\":15,\"auth\":0,\"readonly\":true,\"size\":4,\"auto\":false,\"ownread\":true,\"cur\":false,\"default\":false},\"double-chk\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u53cc\\u5f20\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u6709\\u4e24\\u5f20\\u6216\\u8005\\u591a\\u5f20\\u7eb8\\u540c\\u65f6\\u6413\\u8fdb\",\"type\":\"string\",\"ui-pos\":16,\"auth\":0,\"size\":16,\"cur\":\"\\u8d85\\u58f0\\u6ce2\",\"default\":\"\\u8d85\\u58f0\\u6ce2\",\"range\":[\"\\u8d85\\u58f0\\u6ce2\",\"\\u7981\\u7528\"]},\"is-staple\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u88c5\\u8ba2\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u662f\\u5426\\u6709\\u8ba2\\u4e66\\u9489\\u5b58\\u5728\",\"type\":\"bool\",\"fix-id\":34861,\"ui-pos\":17,\"auth\":0,\"size\":4,\"cur\":true,\"default\":true},\"motor-speed\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u8d70\\u7eb8\\u901f\\u5ea6\",\"desc\":\"\\u8bbe\\u7f6e\\u8d70\\u7eb8\\u7535\\u673a\\u7684\\u901f\\u5ea6\\uff0c\\u5f20\\/\\u5206\\uff08PPM\\uff09\",\"type\":\"int\",\"ui-pos\":18,\"auth\":0,\"size\":4,\"default\":{\"dev-model==G100\":70,\"default\":100},\"range\":[{\"dev-model==G100\":70},{\"dev-model==G100\":80},{\"dev-model==G100\":90},100,{\"dev-model!=G100\":110},{\"dev-model!=G100\":120},{\"dev-model!=G100\":130}]},\"is-check-askew\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u6b6a\\u659c\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u8fdb\\u7eb8\\u662f\\u5426\\u6b6a\\u659c\",\"type\":\"bool\",\"fix-id\":34868,\"ui-pos\":19,\"auth\":0,\"size\":4,\"cur\":true,\"default\":true},\"askew-range\":{\"cat\":\"none\",\"group\":\"feeder\",\"title\":\"\\u6b6a\\u659c\\u5bb9\\u5fcd\\u5ea6\",\"desc\":\"\\u503c\\u8d8a\\u5c0f\\uff0c\\u80fd\\u5bb9\\u5fcd\\u5f97\\u9001\\u5165\\u6587\\u7a3f\\u6b6a\\u659c\\u89d2\\u5ea6\\u8d8a\\u5c0f\",\"type\":\"int\",\"fix-id\":34869,\"ui-pos\":20,\"auth\":0,\"size\":4,\"cur\":3,\"default\":3,\"range\":{\"min\":1,\"max\":7,\"step\":1},\"depend\":\"is-check-askew==true\"}}" }; @@ -164,6 +164,10 @@ void scanner_hw::init(void) { screw_chk_ = *(bool*)value; }; + auto screwl = [this](void* value) -> void + { + screw_chk_level_ = *(int*)value; + }; auto dbchk = [this](void* value) -> void { double_chk_ = strcmp((char*)value, "\347\246\201\347\224\250") != 0; @@ -171,21 +175,42 @@ void scanner_hw::init(void) auto motsp = [this](void* value) -> void { int speed = *(int*)value; - #define CASE_SPEED(n) \ - if(speed == n) \ - motor_speed_ = SPEED_PPM_##n; - - CASE_SPEED(70) - else CASE_SPEED(120) - else CASE_SPEED(150) + if(family_ == "G100") + { + speed -= 70; // 70 80 90 100 + } else - motor_speed_ = SPEED_PPM_100; + { + speed -= 100; // 100 110 120 130 + } + 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()); }; opt_handler_[SANE_FULL_NAME(IS_CHECK_STAPLE)] = staple; opt_handler_[SANE_FULL_NAME(IS_CHECK_ASKEW)] = screw; + opt_handler_[SANE_FULL_NAME(ASKEW_RANGE)] = screwl; opt_handler_[SANE_FULL_NAME(DOUBLE_CHECK)] = dbchk; opt_handler_[SANE_FULL_NAME(MOTOR_SPEED)] = motsp; + opt_handler_[SANE_FULL_NAME(DEVICE_MODEL)] = fm; } // sane_opt_provider @@ -211,6 +236,11 @@ char* scanner_hw::get_value(const char* name, void* value, size_t* size, int* er } int scanner_hw::set_value(const char* name, void* val) { + if(img_controller_.get()) // working, no set + { + return SCANNER_ERR_DEVICE_BUSY; + } + if(opt_handler_.count(name)) { opt_handler_[name](val); @@ -226,6 +256,12 @@ int scanner_hw::set_value(const char* name, void* val) // operation ... int scanner_hw::open(std::function image_handler) { + this->close(); + + if(!image_handler) + return SCANNER_ERR_INVALID_PARAMETER; + + img_handler_ = image_handler; img_controller_.reset(new FpgaComm(baud_)); img_controller_->setColorMode(mode_ == "\345\275\251\350\211\262" ? COLOR_MODE : GRAY_MODE); @@ -253,26 +289,54 @@ int scanner_hw::open(std::function image_handler) img_controller_->setBOffset(i, off_[SIDE_BACK]); camera_.reset(new GVideoISP1()); + camera_->open(0, 0); motor_.reset(new MotorBoard()); motor_->set_double_inpect(double_chk_); motor_->set_staple_inpect(staple_chk_); motor_->set_screw_inpect(screw_chk_); + motor_->set_screw_level(screw_chk_level_); motor_->set_speed_mode(motor_speed_); - return 0; + unsigned int val = 0; + if(motor_->read(PORT_CONFIG, val)) + utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard config : %p\n", val); + else + utils::to_log(LOG_LEVEL_FATAL, "Get motor-board config failed.\n"); + if(motor_->read(PORT_STATUS, val)) + utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard status : %p\n", val); + else + utils::to_log(LOG_LEVEL_FATAL, "Get motor-board status failed.\n"); + if(motor_->read(PORT_MODE, val)) + utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard mode : %p\n", val); + else + utils::to_log(LOG_LEVEL_FATAL, "Get motor-board mode failed.\n"); + if(motor_->read(PORT_VERSION, val)) + utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard version: %p\n", val); + else + utils::to_log(LOG_LEVEL_FATAL, "Get motor-board version failed.\n"); + if(motor_->read(PORT_CONFIG_EX, val)) + utils::to_log(LOG_LEVEL_DEBUG, "MotorBoard confige: %p\n", val); + else + utils::to_log(LOG_LEVEL_FATAL, "Get motor-board confige failed.\n"); + + return SCANNER_ERR_OK; } int scanner_hw::start_scan(void) { - if(!camera_.get()) + if(!camera_.get() || !motor_.get() || !img_controller_.get()) return EBADF; + motor_->clear_error(); camera_->start(); return 0; } int scanner_hw::stop_scan(void) { + if(motor_.get()) + motor_->stop(); + if(camera_.get()) camera_->stop(); @@ -280,9 +344,17 @@ int scanner_hw::stop_scan(void) } int scanner_hw::close(void) { - if(img_controller_.get()) + img_controller_.reset(); + if(motor_.get()) { - img_controller_.reset(); + motor_->stop(); + motor_.reset(); + } + if(camera_.get()) + { + camera_->stop(); + camera_->close(); + camera_.reset(); } return 0; diff --git a/hardware/hardware.h b/hardware/hardware.h index 3277c66..cb67bce 100644 --- a/hardware/hardware.h +++ b/hardware/hardware.h @@ -26,14 +26,14 @@ class MotorBoard; class scanner_hw : public sane_opt_provider { - std::function img_handler_; + std::function img_handler_ = std::function(); bool scanning_ = false; bool auto_scan_ = false; int time_to_exit_auto_scan_ = 60; // seconds std::unique_ptr img_controller_; std::unique_ptr camera_; std::unique_ptr motor_; - + enum { SIDE_FRONT = 0, @@ -48,6 +48,7 @@ class scanner_hw : public sane_opt_provider COLOR_IND_COUNT, }; std::string mode_; + std::string family_ = "G200"; int dpi_ = 300; int baud_ = 921600; int delay_ = 1000; @@ -59,6 +60,7 @@ class scanner_hw : public sane_opt_provider bool staple_chk_ = true; bool screw_chk_ = true; + int screw_chk_level_ = 3; bool paper_on_ = false; bool double_chk_ = true; int motor_speed_ = /*SPEED_PPM_100*/0; @@ -429,5 +431,24 @@ public: // "size": 4, // "cur": true, // "default": true +// }, +// "askew-range": { +// "cat": "none", +// "group": "feeder", +// "title": "歪斜容忍度", +// "desc": "值越小,能容忍得送入文稿歪斜角度越小", +// "type": "int", +// "fix-id": 34869, +// "ui-pos": 20, +// "auth": 0, +// "size": 4, +// "cur": 3, +// "default": 3, +// "range": { +// "min": 1, +// "max": 7, +// "step": 1 +// }, +// "depend": "is-check-askew==true" // } // } \ No newline at end of file diff --git a/hardware/motor/motorboard.cpp b/hardware/motor/motorboard.cpp index 3fc74bf..f3db984 100644 --- a/hardware/motor/motorboard.cpp +++ b/hardware/motor/motorboard.cpp @@ -57,13 +57,13 @@ void MotorBoard::pick_paper(void) { unsigned int val; SMBCONFIG *smbc = (SMBCONFIG *)(&val); - read(0x00, val); + read(PORT_CONFIG, val); smbc->pick_paper = 0; - write(0x00, val); + write(PORT_CONFIG, val); smbc->pick_paper = 1; - write(0x00, val); + write(PORT_CONFIG, val); // smbc->pick_paper = 0; - // write(0x00, val); + // write(PORT_CONFIG, val); } void MotorBoard::clear_error() @@ -100,7 +100,7 @@ bool MotorBoard::wait_done(int timeout_ms) int MotorBoard::os_mode() { unsigned int val; - read(0x02, val); + read(PORT_MODE, val); SMB_MODE *smb_mode = (SMB_MODE *)&val; return smb_mode->scan_mode; } @@ -108,7 +108,7 @@ int MotorBoard::os_mode() bool MotorBoard::paper_ready() { unsigned int val; - read(0x02, val); + read(PORT_MODE, val); SMB_MODE *smb_mode = (SMB_MODE *)&val; return smb_mode->feeding_paper_ready; } @@ -116,7 +116,7 @@ bool MotorBoard::paper_ready() bool MotorBoard::is_scanning() { unsigned int val; - read(0x02, val); + read(PORT_MODE, val); SMB_MODE *smb_mode = (SMB_MODE *)&val; return smb_mode->work_status; } @@ -124,7 +124,7 @@ bool MotorBoard::is_scanning() int MotorBoard::paper_counter() { unsigned int val; - read(0x02, val); + read(PORT_MODE, val); SMBMODE *smb_mode = (SMBMODE *)&val; return smb_mode->scan_num; } @@ -132,11 +132,11 @@ int MotorBoard::paper_counter() bool MotorBoard::set_paper_inspect_param(unsigned int value /* = 1000 */) { unsigned int val; - if (!read(0x04, val)) + if (!read(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(PORT_CONFIG_EX, val); } bool MotorBoard::get_keeplastpaper(){ @@ -146,31 +146,31 @@ bool MotorBoard::get_keeplastpaper(){ bool MotorBoard::set_paper_inpect_info(unsigned int value) { unsigned int val; - if (!read(0x04, val)) + if (!read(PORT_CONFIG_EX, val)) return false; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; smb_config_ext->paper_infor = value; - return write(0x04, val); + return write(PORT_CONFIG_EX, val); } bool MotorBoard::set_paper_inspect(bool enable /* = true */) { unsigned int val; - if (!read(0x04, val)) + if (!read(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(PORT_CONFIG_EX, val); } bool MotorBoard::set_double_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->double_paper = enable; - return write(0x00, val); + return write(PORT_CONFIG, val); } bool MotorBoard::get_doublle_inpect() { @@ -178,21 +178,21 @@ bool MotorBoard::get_doublle_inpect() bool MotorBoard::set_auto_paper(bool enable){ unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->paper_auto_module = enable; - return write(0x00, val); + return write(PORT_CONFIG, val); } bool MotorBoard::set_staple_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->staple_enable = enable; - return write(0x00, val); + return write(PORT_CONFIG, val); } bool MotorBoard::get_staple_inpect() @@ -201,11 +201,11 @@ bool MotorBoard::get_staple_inpect() bool MotorBoard::set_color_mode(int mode) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->color_mode = mode; - return write(0x00, val); + return write(PORT_CONFIG, val); } int MotorBoard::get_color_mode() { @@ -214,21 +214,21 @@ int MotorBoard::get_color_mode() bool MotorBoard::set_speed_mode(int mode) { unsigned int val; - if (!read(0x00, val)) + if (!read(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(PORT_CONFIG, val); smb_config->speed_set_enable = 0; - return write(0x00, val); + return write(PORT_CONFIG, val); } int MotorBoard::get_speed_mode() { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return -1; SMBCONFIG *smb_config = (SMBCONFIG *)&val; return smb_config->v_setting; @@ -237,11 +237,11 @@ int MotorBoard::get_speed_mode() bool MotorBoard::set_cuospeed(unsigned int speed) { unsigned int val; - if (!read(0x04, val)) + if (!read(PORT_CONFIG_EX, val)) return -1; SMB_CONFIG_EXT *smb_config = (SMB_CONFIG_EXT *)&val; smb_config->cuo_speed = speed; - return write(0x04,val); + return write(PORT_CONFIG_EX,val); } @@ -272,7 +272,7 @@ void MotorBoard::pin_call(unsigned int pinNum) unsigned int val; SMBSTATUS *smb_status = (SMBSTATUS *)&val; - if (!read(0x01, val)) + if (!read(PORT_STATUS, val)) utils::to_log(LOG_LEVEL_DEBUG, "read error"); utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("status %08x", val).c_str()); //printf("\n reg 1 val =%d",val); @@ -355,16 +355,16 @@ void MotorBoard::set_callbacks(MotorBoardGlue glue) bool MotorBoard::set_screw_inpect(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->skew_enable = enable; - return write(0x00, val); + return write(PORT_CONFIG, val); } bool MotorBoard::get_screw_inpect() { unsigned int val; - read(0x00, val); + read(PORT_CONFIG, val); SMBCONFIG *smb_mode = (SMBCONFIG *)&val; return smb_mode->skew_enable; } @@ -372,27 +372,27 @@ bool MotorBoard::get_screw_inpect() bool MotorBoard::set_screw_level(int level) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->skew_parameter = level; - return write(0x00, val); + return write(PORT_CONFIG, val); } bool MotorBoard::set_long_paper(bool enable) { unsigned int val; - if (!read(0x00, val)) + if (!read(PORT_CONFIG, val)) return false; SMBCONFIG *smb_config = (SMBCONFIG *)&val; smb_config->paper = enable; - return write(0x00, val); + return write(PORT_CONFIG, val); } int MotorBoard::get_screw_level() { unsigned int val; - auto ret= read(0x00, val); + auto ret= read(PORT_CONFIG, val); if(!ret) return -1; SMBCONFIG *smb_mode = (SMBCONFIG *)&val; @@ -402,12 +402,12 @@ int MotorBoard::get_screw_level() bool MotorBoard::en_testbit(bool en) { unsigned int val; - auto ret= read(0x00, val); + auto ret= read(PORT_CONFIG, val); if(!ret) return -1; SMBCONFIG *smb_mode = (SMBCONFIG *)&val; smb_mode->testbit = en?1:0; - return write(0x00,val); + return write(PORT_CONFIG,val); } void MotorBoard::release_statecontrol() @@ -424,4 +424,4 @@ void MotorBoard::init_statecontrol() m_intPinMonitor.reset(new PinMonitor(intport, std::bind(&MotorBoard::pin_call, this, std::placeholders::_1))); std::this_thread::sleep_for(std::chrono::milliseconds(10)); m_os_mode = os_mode(); -} \ No newline at end of file +} diff --git a/hardware/motor/motorboard.h b/hardware/motor/motorboard.h index 054bf41..eb38d2e 100644 --- a/hardware/motor/motorboard.h +++ b/hardware/motor/motorboard.h @@ -102,10 +102,18 @@ struct MotorBoardGlue enum { - SPEED_PPM_100 = 0, - SPEED_PPM_70, - SPEED_PPM_120, - SPEED_PPM_150 + PORT_CONFIG = 0, + PORT_STATUS, + PORT_MODE, + PORT_VERSION, + PORT_CONFIG_EX = 4, +}; +enum +{ + SPEED_PPM_BASE = 0, + SPEED_PPM_BASE_10, + SPEED_PPM_BASE_20, + SPEED_PPM_BASE_30, }; class MotorBoard @@ -151,6 +159,8 @@ public: std::shared_ptr regs(); void release_statecontrol(); void init_statecontrol(); + + private: void pin_call(unsigned int pinNum); void scansensor_call(unsigned int pinNum); diff --git a/scanner/async_scanner.cpp b/scanner/async_scanner.cpp index 0157ba5..5c332c9 100644 --- a/scanner/async_scanner.cpp +++ b/scanner/async_scanner.cpp @@ -62,6 +62,7 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0) utils::to_log(LOG_LEVEL_DEBUG, "OPT - initializing ...\n"); const_opts_ = new scanner_const_opts(); cfg_mgr_->add(const_opts_); + cis_->set_value(SANE_FULL_NAME(DEVICE_MODEL), &cfg_mgr_->get_option_value(SANE_FULL_NAME(DEVICE_MODEL), SANE_ACTION_GET_VALUE)[0]); cfg_mgr_->add(cis_); utils::to_log(LOG_LEVEL_DEBUG, "OPT - initialized %u options.\n", cfg_mgr_->count()); @@ -412,9 +413,16 @@ dyn_mem_ptr async_scanner::handle_scan_start(LPPACK_BASE pack, uint32_t* used, p scan_err_ = 0; reply_start_ = false; + auto receiver = [this](dyn_mem_ptr, bool, LPPACKIMAGE) -> void + { + + }; + *used = base_head_size; reply->set_len(base_head_size); - // scan_err_ = capture_->start(); + scan_err_ = cis_->open(receiver); + if(scan_err_ == 0) + scan_err_ = cis_->start_scan(); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, scan_err_); *used |= INT32_MAX + 1; @@ -427,7 +435,7 @@ dyn_mem_ptr async_scanner::handle_scan_stop(LPPACK_BASE pack, uint32_t* used, pa int err = 0; utils::to_log(LOG_LEVEL_DEBUG, "Received command Stop-Scan.\n"); - // err = capture_->stop(); + err = cis_->stop_scan(); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, err); reply->set_len(base_head_size); *used = base_head_size; diff --git a/sdk/base/utils.cpp b/sdk/base/utils.cpp index c6e9944..1167bbe 100644 --- a/sdk/base/utils.cpp +++ b/sdk/base/utils.cpp @@ -1958,6 +1958,7 @@ int shared_memory::write(const char* data, size_t len) // safe_thread safe_thread::safe_thread() : excep_que_("thread-exception") { + excep_que_.enable_wait_log(false); notify_thread_.reset(new std::thread(&safe_thread::thread_notify_exception, this)); } safe_thread::~safe_thread() @@ -1980,7 +1981,7 @@ void safe_thread::thread_worker(std::function func, std::string name { try { - utils::to_log(LOG_LEVEL_DEBUG, "+++ safe_thread of '%s(%p) - %p' is running ...\n", name.c_str(), addr, GetCurrentThreadId()); + utils::to_log(LOG_LEVEL_DEBUG, "+++ safe_thread of '%s(addr: %p) - id: %p' is running ...\n", name.c_str(), addr, GetCurrentThreadId()); func(); utils::to_log(LOG_LEVEL_DEBUG, "--- safe_thread of '%s - %p' exited.\n", name.c_str(), GetCurrentThreadId()); return; diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index 94c573b..5bfeb1f 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -1198,24 +1198,24 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c from->add_ref(); } - if (added) - { - // restore to default value ... - int size = 0; - bool can_auto = false; - std::string val(get_option_value(opt->key().c_str(), SANE_ACTION_GET_DEFAULT_VALUE, &size)); - - if (!opt->get_value("auto", can_auto) || can_auto) - { - std::string type(""); - opt->get_value("type", type); - val.resize(size); - type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]); - utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str()); - from->set_value(opt->key().c_str(), &val[0]); - sane_opt_provider::set_opt_value(opt, &val[0]); - } - } + //if (added) // error occurs when condition default value, move to after to_now ... + //{ + // // restore to default value ... + // int size = 0; + // bool can_auto = false; + // std::string val(get_option_value(opt->key().c_str(), SANE_ACTION_GET_DEFAULT_VALUE, &size)); + // + // if (!opt->get_value("auto", can_auto) || can_auto) + // { + // std::string type(""); + // opt->get_value("type", type); + // val.resize(size); + // type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]); + // utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str()); + // from->set_value(opt->key().c_str(), &val[0]); + // sane_opt_provider::set_opt_value(opt, &val[0]); + // } + //} } bool device_option::arrange_raw_json(sane_opt_provider* sop) { @@ -1703,7 +1703,9 @@ bool device_option::add(sane_opt_provider* sop) if (arrange_raw_json(sop)) { ret = to_now(true, nullptr); - if (!ret) + if (ret) + restore(nullptr); + else clear(); } else @@ -1909,7 +1911,7 @@ int device_option::restore(sane_opt_provider* holder) child = cur->first_child(); while (child) { - if (src_.count(child->key()) && src_[child->key()] == holder + if ((!holder || src_.count(child->key()) && src_[child->key()] == holder) && is_auto_restore_default(child->key().c_str())) { std::string val(device_option::option_value(child, true)); diff --git a/usb/usb_dev.cpp b/usb/usb_dev.cpp index d1f3a37..dc44e65 100644 --- a/usb/usb_dev.cpp +++ b/usb/usb_dev.cpp @@ -555,7 +555,7 @@ int usb_device::open_device(const char* dev, bool ffs_mode, int* fd) } else { - utils::to_log(LOG_LEVEL_DEBUG, "Open usb device(%s) success.\n", dev); + utils::to_log(LOG_LEVEL_DEBUG, "Open usb device(%s) success, fd = %d.\n", dev, gadget_.usb_device); ffs_mode_ = ffs_mode; // get_system_output(R"(echo linaro | sudo -S sh -c "chmod 777 /dev/ffs-camtp -R")"); @@ -608,7 +608,7 @@ int usb_device::open_endpoint(int ep_ind, int* fd) } else { - utils::to_log(LOG_LEVEL_DEBUG, "open endpoint(%s - %s) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_path[ep_ind]); + utils::to_log(LOG_LEVEL_DEBUG, "open endpoint(%s - %s) ok, fd = %d.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_path[ep_ind], gadget_.ep_handles[ep_ind]); } } } @@ -639,6 +639,7 @@ int usb_device::close_endpoint(int ep_ind) utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(i).c_str(), errno, strerror(errno)); break; } + utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s, fd = %d) ok.\n", usb_device::endpoint_index_str(i).c_str(), gadget_.ep_handles[i]); gadget_.ep_handles[i] = -1; } } @@ -653,8 +654,8 @@ int usb_device::close_endpoint(int ep_ind) utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(ep_ind).c_str(), errno, strerror(errno)); else { + utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s, fd = %d) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_handles[ep_ind]); gadget_.ep_handles[ep_ind] = -1; - utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str()); } } } @@ -679,7 +680,10 @@ int usb_device::close_device(void) { ret = close(gadget_.usb_device); if(ret == 0) + { + utils::to_log(LOG_LEVEL_DEBUG, "Close usb device(fd = %d) ok.\n", gadget_.usb_device); gadget_.usb_device = -1; + } } } } diff --git a/usb/usb_io.cpp b/usb/usb_io.cpp index 190b729..34ad20f 100644 --- a/usb/usb_io.cpp +++ b/usb/usb_io.cpp @@ -28,6 +28,8 @@ async_usb_gadget::async_usb_gadget(std::function { cmd_que_.enable_wait_log(false); sent_que_.enable_wait_log(false); + wait_in_.enable_log(false); + wait_out_.enable_log(false); dev_ = new usb_device("fe900000.dwc3", "/opt/cfg/usb_gadget/g1/UDC", "linaro"); dev_->add_endpoint(USB_EP_BULK_IN, true, true);