adjust log

This commit is contained in:
gb 2023-12-29 10:53:04 +08:00
parent 225efeff9d
commit 90b2550dd6
11 changed files with 248 additions and 125 deletions

View File

@ -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()));
}

View File

@ -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++)

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@ class MotorBoard;
class scanner_hw : public sane_opt_provider
{
std::function<IMAGE_HANDLER_PROTO> img_handler_;
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
@ -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"
// }
// }

View File

@ -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()

View File

@ -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<IRegsAccess> regs();
void release_statecontrol();
void init_statecontrol();
private:
void pin_call(unsigned int pinNum);
void scansensor_call(unsigned int pinNum);

View File

@ -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;

View File

@ -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<void(void)> 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;

View File

@ -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));

View File

@ -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,10 +680,13 @@ 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;
}
}
}
}
return ret;
}

View File

@ -28,6 +28,8 @@ async_usb_gadget::async_usb_gadget(std::function<FUNCTION_PROTO_COMMAND_HANDLE>
{
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);