添加送纸属性;device_option添加是否创建分组属性的开关

This commit is contained in:
gb 2024-01-02 15:18:42 +08:00
parent bf8348cf95
commit 96ecacb861
10 changed files with 298 additions and 95 deletions

View File

@ -108,7 +108,9 @@ bool gVideo::wait(int msTimeout) {
return false;
}
void* gVideo::read_frame(int timeout) {
void* gVideo::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");
return 0;
@ -120,11 +122,41 @@ void* gVideo::read_frame(int timeout) {
LOG_ERROR(utils::format_string("VIDIOC_DQBUF error!!! index :%d\n", buf.index));
return 0;
}
if (-1 == ioctl(fd, VIDIOC_QBUF, &buf)) {
LOG_ERROR(utils::format_string("VIDIOC_QBUF error!!! index :%d\n", buf.index));
return 0;
// move to release_v4l2_memory method ...
// if (-1 == ioctl(fd, VIDIOC_QBUF, &buf)) {
// LOG_ERROR(utils::format_string("VIDIOC_QBUF error!!! index :%d\n", buf.index));
// return 0;
// }
ind = buf.index;
size = buffers[ind].length;
return buffers[ind].start;
}
int gVideo::add_v4l2_memory(int ind)
{
v4l2_buffer buf;
int ret = 0;
struct v4l2_plane planes[VIDEO_MAX_PLANES];
CLEAR(buf);
CLEAR(planes);
for(int j = 0; j < VIDEO_MAX_PLANES; j++)
{
planes[j].length = buf_size_;
planes[j].m.userptr =(unsigned long)buffers[ind].start;
}
return buffers[buf.index].start;
buf.index = ind;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
buf.memory = V4L2_MEMORY_USERPTR;//V4L2_MEMORY_MMAP;
buf.m.planes = planes;
buf.length = 1;
if (-1 == ioctl(fd, VIDIOC_QBUF, &buf))
{
ret = errno;
utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_QBUF(%d) failed: %s\n", ind, strerror(ret));
}
return ret;
}
void gVideo::set_size(int width,int height){
@ -144,11 +176,11 @@ void gVideo::stop_capturing(void) {
utils::to_log(LOG_LEVEL_FATAL, "streamo off\n");
}
unsigned int querybuf_length;
void gVideo::start_capturing(void)
{
enum v4l2_buf_type type;
printf("start_capturing::querybuf_length = %d.\n",querybuf_length);
printf("start_capturing::buf_size_ = %d.\n",buf_size_);
for (int i = 0; i < n_buffers; ++i)
{
struct v4l2_buffer buf;
@ -158,7 +190,7 @@ void gVideo::start_capturing(void)
for(int j = 0; j < VIDEO_MAX_PLANES; j++)
{
//planes[j].length = buffers[i].length;
planes[j].length = querybuf_length;
planes[j].length = buf_size_;
planes[j].m.userptr =(unsigned long)buffers[i].start;
}
buf.index = i;
@ -277,16 +309,16 @@ void gVideo::init_mmap(void)
unsigned int offset;
length = buf.m.planes[0].length;
offset = buf.m.planes[0].m.mem_offset;
querybuf_length = buf.m.planes[0].length;
buf_size_ = buf.m.planes[0].length;
printf("VIDIOC_QUERYBUFBuffer %u length = %d.\n",n_buffers,length);
printf("VIDIOC_QUERYBUFBuffer %u offset = %d.\n",n_buffers,offset);
printf("VIDIOC_QUERYBUFBuffer %u querybuf_length = %d.\n",n_buffers,querybuf_length);
printf("VIDIOC_QUERYBUFBuffer %u buf_size_ = %d.\n",n_buffers,buf_size_);
}
for (n_buffers = 0; n_buffers < buffers.size(); ++n_buffers)
{
buffers[n_buffers].length = querybuf_length;
buffers[n_buffers].start = memalign(/* boundary */ 1024, querybuf_length);
buffers[n_buffers].length = buf_size_;
buffers[n_buffers].start = memalign(/* boundary */ 1024, buf_size_);
printf("memalign:buffers[%d].length = %d\n", n_buffers,buffers[n_buffers].length);
printf("memalign:buffers[%d].start = %p\n", n_buffers,buffers[n_buffers].start);

View File

@ -19,7 +19,8 @@ public:
void stop();
void grab(int color, bool bcrrect = false, int timeout = 1000, int flatpara = 0);
bool hasframe();
virtual void *read_frame(int timeout);
virtual void *read_frame(int timeout, size_t& size, int& ind); // call add_v4l2_memory to put the buffer into the V4L2 queue again
int add_v4l2_memory(int ind);
void set_size(int width, int height);
protected:
@ -41,6 +42,7 @@ protected:
};
const int v4l_buffer_count = 5;
int buf_size_ = 0;
int v4l_width = 3100;
int v4l_height = 3100;
std::string dev_name;

View File

@ -137,45 +137,39 @@ GVideoISP1::~GVideoISP1()
}
void* GVideoISP1::read_frame(int timeout) {
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" );
return 0;
}
struct v4l2_plane planes[VIDEO_MAX_PLANES];
v4l2_buffer buf;
int ret;
memset(&buf, 0, sizeof buf);
memset(planes, 0, sizeof planes);
CLEAR(buf);
CLEAR(planes);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
//buf.memory = V4L2_MEMORY_USERPTR;//V4L2_MEMORY_MMAP;
buf.memory = V4L2_MEMORY_USERPTR;
buf.length = VIDEO_MAX_PLANES;
buf.m.planes = planes;
ret = ioctl(fd, VIDIOC_DQBUF, &buf);
if (ret < 0) {
if (ioctl(fd, VIDIOC_DQBUF, &buf) < 0) {
LOG_TRACE(utils::format_string("Unable to dequeue buffer: %s (%d).\n",strerror(errno), errno));
}
else {
LOG_TRACE(utils::format_string("VIDIOC_DQBUF sucess\n"));
return 0;
}
// move to add_v4l2_memory method ...
// ret = ioctl(fd, VIDIOC_QBUF, &buf);
// if (ret < 0) {
// LOG_ERROR(utils::format_string("Unable to requeue buffer: %s (%d).\n",strerror(errno), errno));
// }
ind = buf.index;
size = buffers[ind].length;
ret = ioctl(fd, VIDIOC_QBUF, &buf);
if (ret < 0) {
LOG_ERROR(utils::format_string("Unable to requeue buffer: %s (%d).\n",strerror(errno), errno));
}
else {
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;
return buffers[ind].start;
}
unsigned int gsp1querybuf_length;
void GVideoISP1::start_capturing(void) {
unsigned int i;
int ret;
@ -189,7 +183,7 @@ void GVideoISP1::start_capturing(void) {
for(int j = 0; j < VIDEO_MAX_PLANES; j++)
{
//planes[j].length = buffers[i].length;
planes[j].length = gsp1querybuf_length;
planes[j].length = buf_size_;
planes[j].m.userptr =(unsigned long)buffers[i].start;
}
buf.index = i;
@ -360,16 +354,16 @@ void GVideoISP1::init_mmap(void) {
unsigned int offset;
length = buf.m.planes[0].length;
offset = buf.m.planes[0].m.mem_offset;
gsp1querybuf_length = buf.m.planes[0].length;
buf_size_ = buf.m.planes[0].length;
LOG_TRACE(utils::format_string("VIDIOC_QUERYBUFBuffer %u length = %d.\n",n_buffers,length));
LOG_TRACE(utils::format_string("VIDIOC_QUERYBUFBuffer %u offset = %d.\n",n_buffers,offset));
LOG_TRACE(utils::format_string("VIDIOC_QUERYBUFBuffer %u querybuf_length = %d.\n",n_buffers,gsp1querybuf_length));
LOG_TRACE(utils::format_string("VIDIOC_QUERYBUFBuffer %u querybuf_length = %d.\n",n_buffers,buf_size_));
}
for (n_buffers = 0; n_buffers < buffers.size(); ++n_buffers)
{
buffers[n_buffers].length = gsp1querybuf_length;
buffers[n_buffers].start = memalign(/* boundary */ 1024, gsp1querybuf_length);
buffers[n_buffers].length = buf_size_;
buffers[n_buffers].start = memalign(/* boundary */ 1024, buf_size_);
LOG_TRACE(utils::format_string("memalign:buffers[%d].length = %d\n", n_buffers,buffers[n_buffers].length));
LOG_TRACE(utils::format_string("memalign:buffers[%d].start = %p\n", n_buffers,buffers[n_buffers].start));

View File

@ -8,7 +8,7 @@ public:
GVideoISP1();
virtual ~GVideoISP1();
virtual void *read_frame(int timeout);
virtual void *read_frame(int timeout, size_t& size, int& ind) override;
protected:
virtual void start_capturing(void);

File diff suppressed because one or more lines are too long

View File

@ -28,7 +28,6 @@ class scanner_hw : public sane_opt_provider
{
std::function<IMAGE_HANDLER_PROTO> img_handler_ = std::function<IMAGE_HANDLER_PROTO>();
bool scanning_ = false;
bool auto_scan_ = false;
int time_to_exit_auto_scan_ = 60; // seconds
std::unique_ptr<FpgaComm> img_controller_;
std::unique_ptr<GVideoISP1> camera_;
@ -49,6 +48,8 @@ class scanner_hw : public sane_opt_provider
};
std::string mode_;
std::string family_ = "G200";
volatile bool auto_scan_ = false;
int scan_count_ = -1;
int dpi_ = 300;
int baud_ = 921600;
int delay_ = 1000;
@ -68,6 +69,8 @@ class scanner_hw : public sane_opt_provider
void init(void);
void thread_image_capture(void);
bool is_scan_fatal(void);
public:
scanner_hw();
@ -144,6 +147,96 @@ public:
// "range": ["15s", "30s", "60s", "2min", "4min", "8min"],
// "depend": "is-wait-scan==true"
// },
// "scan-mode": {
// "cat": "base",
// "group": "feeder",
// "title": "扫描张数",
// "desc": "选择指定数量扫描或连续扫描",
// "type": "string",
// "fix-id": 34862,
// "ui-pos": 15,
// "auth": 0,
// "size": 24,
// "cur": "连续扫描",
// "default": "连续扫描",
// "range": ["连续扫描", "扫描指定张数"],
// "depend": "is-wait-scan==false"
// },
// "scan-count": {
// "cat": "base",
// "group": "feeder",
// "title": " 扫描数量",
// "desc": "扫描指定数量",
// "type": "int",
// "fix-id": 34863,
// "ui-pos": 16,
// "auth": 0,
// "size": 4,
// "cur": -1,
// "default": -1,
// "depend": "scan-mode.enabled&&scan-mode==扫描指定张数"
// },
// "is-auto-strength": {
// "cat": "base",
// "group": "feeder",
// "title": "自动分纸强度",
// "desc": "扫描仪自动修正分纸力度",
// "type": "bool",
// "fix-id": 34876,
// "ui-pos": 27,
// "auth": 0,
// "size": 4,
// "cur": false,
// "default": false
// },
// "feed-strength-value": {
// "cat": "base",
// "group": "feeder",
// "title": " 进纸失败率",
// "desc": "高于该值时扫描仪将调整分纸力度",
// "type": "float",
// "fix-id": 34877,
// "ui-pos": 28,
// "auth": 0,
// "size": 8,
// "cur": 0.000000,
// "default": 0.000000,
// "range": {
// "min": 0.100000,
// "max": 0.900000,
// "step": 0.080000
// },
// "depend": "is-auto-strength==true"
// },
// "feed-strength": {
// "cat": "base",
// "group": "feeder",
// "title": "分纸强度",
// "desc": "设置扫描仪的分纸力度",
// "type": "string",
// "fix-id": 34874,
// "ui-pos": 30,
// "auth": 0,
// "size": 12,
// "cur": "一般",
// "default": "一般",
// "range": ["弱", "一般", "强"],
// "depend": "is-auto-strength!=true"
// },
// "time-to-sleep": {
// "cat": "base",
// "group": "feeder",
// "title": "休眠时间",
// "desc": "设置扫描仪的休眠时间",
// "type": "string",
// "fix-id": 34875,
// "ui-pos": 33,
// "auth": 0,
// "size": 16,
// "cur": "不休眠",
// "default": "不休眠",
// "range": ["不休眠", "五分钟", "十分钟", "半小时", "一小时", "两小时", "四小时"]
// },
// "baud": {
// "cat": "none",
// "group": "CIS",
@ -371,7 +464,7 @@ public:
// "desc": "纸张已经在进纸台上放置好",
// "type": "bool",
// "fix-id": 34912,
// "ui-pos": 15,
// "ui-pos": 10,
// "auth": 0,
// "readonly": true,
// "size": 4,
@ -386,7 +479,7 @@ public:
// "title": "双张检测",
// "desc": "检测是否有两张或者多张纸同时搓进",
// "type": "string",
// "ui-pos": 16,
// "ui-pos": 18,
// "auth": 0,
// "size": 16,
// "cur": "超声波",
@ -400,7 +493,7 @@ public:
// "desc": "检测是否有订书钉存在",
// "type": "bool",
// "fix-id": 34861,
// "ui-pos": 17,
// "ui-pos": 20,
// "auth": 0,
// "size": 4,
// "cur": true,
@ -412,13 +505,11 @@ public:
// "title": "走纸速度",
// "desc": "设置走纸电机的速度,张\/分PPM",
// "type": "int",
// "ui-pos": 18,
// "ui-pos": 25,
// "auth": 0,
// "size": 4,
// "default": {
// "dev-model!=G200": 70,
// "default": 100
// },
// "cur": 100,
// "default": 100,
// "range": [{
// "dev-model!=G200": 70
// }, {
@ -440,7 +531,7 @@ public:
// "desc": "检测进纸是否歪斜",
// "type": "bool",
// "fix-id": 34868,
// "ui-pos": 19,
// "ui-pos": 22,
// "auth": 0,
// "size": 4,
// "cur": true,
@ -453,7 +544,7 @@ public:
// "desc": "值越小,能容忍得送入文稿歪斜角度越小",
// "type": "int",
// "fix-id": 34869,
// "ui-pos": 20,
// "ui-pos": 23,
// "auth": 0,
// "size": 4,
// "cur": 3,

View File

@ -58,7 +58,7 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
{
utils::log_info(msg, LOG_LEVEL_DEBUG);
};
cfg_mgr_ = new device_option(user, on_log);
cfg_mgr_ = new device_option(true, user, on_log);
utils::to_log(LOG_LEVEL_DEBUG, "OPT - initializing ...\n");
const_opts_ = new scanner_const_opts();
cfg_mgr_->add(const_opts_);

View File

@ -75,6 +75,8 @@ enum scanner_err
SCANNER_ERR_DEVICE_MAYBE_IS_HOLE, // 纸张有孔洞
SCANNER_ERR_DEVICE_DEVS_BOOTING, // 请稍等 - 设备正在准备
SCANNER_ERR_DEVICE_UNKNOWN_STATUS, // 设备处于未知状态
SCANNER_ERR_DEVICE_NOT_READY, // 设备未准备好(执行某操作的前置条件未准备好)
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -364,7 +364,9 @@ bool device_option::range_value::set_value(gb_json* jsn, const char* type, devic
}
device_option::device_option(std::function<bool(int)> user_priv, std::function<void(const char*)> log) : origin_(nullptr), now_(nullptr)
device_option::device_option(bool no_group, std::function<bool(int)> user_priv
, std::function<void(const char*)> log)
: no_grp_(no_group), origin_(nullptr), now_(nullptr)
, user_(user_priv), log_(log)
{}
device_option::~device_option()
@ -1236,10 +1238,17 @@ bool device_option::arrange_raw_json(sane_opt_provider* sop)
{
child->get_value("type", str);
if (str != JSON_SANE_TYPE_GROUP) // omit group
{
if(no_grp_)
{
insert_option(child, sop);
}
else
{
child->get_value("group", str);
insert_option(child, sop, str.empty() ? nullptr : str.c_str());
}
}
child->release();
child = jsn->next_child();
}
@ -1912,7 +1921,7 @@ int device_option::restore(sane_opt_provider* holder)
while (child)
{
if ((!holder || src_.count(child->key()) && src_[child->key()] == holder)
&& is_auto_restore_default(child->key().c_str()))
&& is_auto_restore_default(child))
{
std::string val(device_option::option_value(child, true));
update_data(child->key().c_str(), &val[0], false);
@ -1942,21 +1951,18 @@ int device_option::count(void)
else
return 0;
}
bool device_option::is_auto_restore_default(const char* name)
bool device_option::is_auto_restore_default(gb_json* jsn)
{
gb_json* jsn = now_ ? now_ : origin_,
* child = nullptr;
bool support = true;
std::string type("");
jsn->get_value(name, child);
if (child)
{
if (!child->get_value("auto", support))
jsn->get_value("type", type);
if(type == JSON_SANE_TYPE_BUTTON || type == JSON_SANE_TYPE_GROUP)
return false;
if (!jsn->get_value("auto", support))
support = true;
child->release();
}
return support;
}
std::string device_option::get_name_by_sane_id(int sane_ind)

View File

@ -24,6 +24,7 @@ class device_option : public refer
{
gb_json* origin_;
gb_json* now_;
bool no_grp_ = false;
std::map<std::string, sane_opt_provider*> src_;
std::vector<std::string> master_opts_; // options that value changed will affect others
std::map<std::string, simple_logic*> slaver_;
@ -345,7 +346,7 @@ protected:
public:
device_option(std::function<bool(int)> user_priv = std::function<bool(int)>()
device_option(bool no_group = false, std::function<bool(int)> user_priv = std::function<bool(int)>()
, std::function<void(const char*)> log = std::function<void(const char*)>());
~device_option();
@ -361,7 +362,7 @@ public:
int restore(sane_opt_provider* holder); //
int count(void); // return option count
bool is_auto_restore_default(const char* name);
bool is_auto_restore_default(gb_json* jsn);
std::string get_name_by_sane_id(int sane_ind);
std::string get_option_value_type(const char* name, size_t* size = nullptr);
std::string get_option_value_type(int sane_ind, size_t* size = nullptr);