From cc4ad6be9936e408a9cb51abae59b246b142340d Mon Sep 17 00:00:00 2001 From: Ralph Little Date: Sat, 19 Nov 2022 20:38:24 -0800 Subject: [PATCH] brother_mfp: Added ADF duplex function for supported devices. --- backend/brother_mfp/brother_mfp-encoder.cpp | 14 +++++--- backend/brother_mfp/brother_mfp-encoder.h | 1 + backend/brother_mfp/brother_mfp.cpp | 23 +++++++++++-- .../brother_mfp/brother_mfp_tests_family2.cpp | 14 ++++++++ .../brother_mfp/brother_mfp_tests_family3.cpp | 14 ++++++++ .../brother_mfp/brother_mfp_tests_family4.cpp | 33 ++++++++++++++----- 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/backend/brother_mfp/brother_mfp-encoder.cpp b/backend/brother_mfp/brother_mfp-encoder.cpp index e6ccf3d56..06b84f256 100644 --- a/backend/brother_mfp/brother_mfp-encoder.cpp +++ b/backend/brother_mfp/brother_mfp-encoder.cpp @@ -466,7 +466,7 @@ DecodeStatus BrotherEncoderFamily2::EncodeParameterBlock (SANE_Byte *data, size_ "%s\n" "B=%u\nN=%u\n" "A=%u,%u,%u,%u\n" - "D=SIN\n" + "D=%s\n" "\x80", (unsigned int) scan_params.param_x_res, (unsigned int) scan_params.param_y_res, @@ -481,7 +481,8 @@ DecodeStatus BrotherEncoderFamily2::EncodeParameterBlock (SANE_Byte *data, size_ (unsigned int) (scan_params.param_pixel_x_offset + scan_params.param_pixel_x_width), (unsigned int) (scan_params.param_pixel_y_offset - + scan_params.param_pixel_y_height)); + + scan_params.param_pixel_y_height), + scan_params.param_source == BROTHER_SOURCE_ADF_DUPLEX? "DUP": "SIN"); if (*length > data_len) { @@ -1137,7 +1138,7 @@ DecodeStatus BrotherEncoderFamily3::EncodeParameterBlock (SANE_Byte *data, size_ "%s\n" "B=%u\nN=%u\n" "A=%u,%u,%u,%u\n" - "D=SIN\n" + "D=%s\n" "\x80", (unsigned int) scan_params.param_x_res, (unsigned int) scan_params.param_y_res, @@ -1152,7 +1153,8 @@ DecodeStatus BrotherEncoderFamily3::EncodeParameterBlock (SANE_Byte *data, size_ (unsigned int) (scan_params.param_pixel_x_offset + scan_params.param_pixel_x_width), (unsigned int) (scan_params.param_pixel_y_offset - + scan_params.param_pixel_y_height)); + + scan_params.param_pixel_y_height), + scan_params.param_source == BROTHER_SOURCE_ADF_DUPLEX ? "DUP" : "SIN"); if (*length > data_len) { @@ -1834,6 +1836,7 @@ DecodeStatus BrotherEncoderFamily4::EncodeParameterBlock (SANE_Byte *data, size_ "A=%u,%u,%u,%u\n" "S=NORMAL_SCAN\n" "P=0\nG=0\nL=0\n" + "D=%s\n" "\x80", (unsigned int) scan_params.param_x_res, (unsigned int) scan_params.param_y_res, @@ -1847,7 +1850,8 @@ DecodeStatus BrotherEncoderFamily4::EncodeParameterBlock (SANE_Byte *data, size_ (unsigned int) (scan_params.param_pixel_x_offset + scan_params.param_pixel_x_width), (unsigned int) (scan_params.param_pixel_y_offset - + scan_params.param_pixel_y_height)); + + scan_params.param_pixel_y_height), + scan_params.param_source == BROTHER_SOURCE_ADF_DUPLEX ? "DUP" : "SIN"); if (*length > data_len) { diff --git a/backend/brother_mfp/brother_mfp-encoder.h b/backend/brother_mfp/brother_mfp-encoder.h index adec3be8b..5f957d6ac 100644 --- a/backend/brother_mfp/brother_mfp-encoder.h +++ b/backend/brother_mfp/brother_mfp-encoder.h @@ -88,6 +88,7 @@ typedef enum { BROTHER_SOURCE_FLATBED, BROTHER_SOURCE_ADF, + BROTHER_SOURCE_ADF_DUPLEX, } BrotherSource; typedef SANE_Int BrotherSensor; diff --git a/backend/brother_mfp/brother_mfp.cpp b/backend/brother_mfp/brother_mfp.cpp index af2196cc4..6acaa06d0 100644 --- a/backend/brother_mfp/brother_mfp.cpp +++ b/backend/brother_mfp/brother_mfp.cpp @@ -57,6 +57,8 @@ #define SANE_VALUE_SOURCE_FLATBED SANE_I18N("Flatbed") #define SANE_VALUE_SOURCE_ADF SANE_I18N("Automatic Document Feeder") +#define SANE_VALUE_SOURCE_ADF_SIMPLEX SANE_I18N("Automatic Document Feeder (one sided)") +#define SANE_VALUE_SOURCE_ADF_DUPLEX SANE_I18N("Automatic Document Feeder (duplex)") #define SANE_NAME_FILE_BUTTON "file-sensor" #define SANE_NAME_EMAIL_BUTTON "email-sensor" @@ -410,7 +412,15 @@ attach_with_ret (const char *devicename, BrotherDevice **dev) } if (model->capabilities & CAP_SOURCE_HAS_ADF) { - device->sources[num_sources++] = SANE_VALUE_SOURCE_ADF; + if (model->capabilities & CAP_SOURCE_HAS_ADF_DUPLEX) + { + device->sources[num_sources++] = SANE_VALUE_SOURCE_ADF_SIMPLEX; + device->sources[num_sources++] = SANE_VALUE_SOURCE_ADF_DUPLEX; + } + else + { + device->sources[num_sources++] = SANE_VALUE_SOURCE_ADF; + } } ++num_devices; @@ -1397,7 +1407,8 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) return rc; } } - else if (strcmp(device->val[OPT_SOURCE].s, SANE_VALUE_SOURCE_ADF) == 0) + else if ((strcmp (device->val[OPT_SOURCE].s, SANE_VALUE_SOURCE_ADF) == 0) + || (strcmp (device->val[OPT_SOURCE].s, SANE_VALUE_SOURCE_ADF) == 0)) { rc = device->driver->SetSource(BROTHER_SOURCE_ADF); if (rc != SANE_STATUS_GOOD) @@ -1405,6 +1416,14 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) return rc; } } + else if (strcmp(device->val[OPT_SOURCE].s, SANE_VALUE_SOURCE_ADF_DUPLEX) == 0) + { + rc = device->driver->SetSource(BROTHER_SOURCE_ADF_DUPLEX); + if (rc != SANE_STATUS_GOOD) + { + return rc; + } + } /* * Compute the geometry in terms of pixels at the selected resolution. diff --git a/testsuite/backend/brother_mfp/brother_mfp_tests_family2.cpp b/testsuite/backend/brother_mfp/brother_mfp_tests_family2.cpp index 6ee6ade87..12a30f1f4 100644 --- a/testsuite/backend/brother_mfp/brother_mfp_tests_family2.cpp +++ b/testsuite/backend/brother_mfp/brother_mfp_tests_family2.cpp @@ -348,6 +348,20 @@ static void test_family2_encode_param() ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } + // ADF duplex + encoder.SetScanDimensions (0, 10, 50, 100); + encoder.SetSource (BROTHER_SOURCE_ADF_DUPLEX); + decode_resp = encoder.EncodeParameterBlock (data_buffer, sizeof(data_buffer), &ret_length); + + ASSERT_EQ(decode_resp, DECODE_STATUS_GOOD); + + { + const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" + "B=100\nN=90\nA=0,50,10,150\nD=DUP\n" "\x80"; + ASSERT_EQ(ret_length, sizeof(test_ret) - 1); + ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); + } + // Buffer too short. decode_resp = encoder.EncodeParameterBlock (data_buffer, 15, &ret_length); diff --git a/testsuite/backend/brother_mfp/brother_mfp_tests_family3.cpp b/testsuite/backend/brother_mfp/brother_mfp_tests_family3.cpp index ebbfc91c1..8198eb08f 100644 --- a/testsuite/backend/brother_mfp/brother_mfp_tests_family3.cpp +++ b/testsuite/backend/brother_mfp/brother_mfp_tests_family3.cpp @@ -348,6 +348,20 @@ static void test_family3_encode_param() ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } + // ADF duplex + encoder.SetScanDimensions (0, 10, 50, 100); + encoder.SetSource(BROTHER_SOURCE_ADF_DUPLEX); + decode_resp = encoder.EncodeParameterBlock (data_buffer, sizeof(data_buffer), &ret_length); + + ASSERT_EQ(decode_resp, DECODE_STATUS_GOOD); + + { + const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" + "B=100\nN=90\nA=0,50,10,150\nD=DUP\n" "\x80"; + ASSERT_EQ(ret_length, sizeof(test_ret) - 1); + ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); + } + // Buffer too short. decode_resp = encoder.EncodeParameterBlock (data_buffer, 15, &ret_length); diff --git a/testsuite/backend/brother_mfp/brother_mfp_tests_family4.cpp b/testsuite/backend/brother_mfp/brother_mfp_tests_family4.cpp index 748de2771..e497c1ab5 100644 --- a/testsuite/backend/brother_mfp/brother_mfp_tests_family4.cpp +++ b/testsuite/backend/brother_mfp/brother_mfp_tests_family4.cpp @@ -237,7 +237,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=100,100\nM=CGRAY\nC=JPEG\nJ=MID\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp(test_ret, data_buffer, sizeof(test_ret)), 0); } @@ -252,7 +252,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=CGRAY\nC=JPEG\nJ=MID\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp(test_ret, data_buffer, sizeof(test_ret)), 0); } @@ -267,7 +267,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=GRAY64\nC=RLENGTH\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -281,7 +281,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=CGRAY\nC=JPEG\nJ=MID\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -295,7 +295,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=ERRDIF\nC=RLENGTH\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -309,7 +309,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" "B=50\nN=50\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -324,7 +324,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" "B=30\nN=20\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -338,7 +338,7 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" "B=100\nN=90\nA=0,0,0,0\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); } @@ -352,7 +352,22 @@ static void test_family4_encode_param() { const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" "B=100\nN=90\nA=0,50,10,150\nS=NORMAL_SCAN\nP=0\n" - "G=0\nL=0\n" "\x80"; + "G=0\nL=0\nD=SIN\n" "\x80"; + ASSERT_EQ(ret_length, sizeof(test_ret) - 1); + ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); + } + + // Duplex ADF + encoder.SetScanDimensions (0, 10, 50, 100); + encoder.SetSource (BROTHER_SOURCE_ADF_DUPLEX); + decode_resp = encoder.EncodeParameterBlock (data_buffer, sizeof(data_buffer), &ret_length); + + ASSERT_EQ(decode_resp, DECODE_STATUS_GOOD); + + { + const char test_ret[] = "\x1b" "X\nR=200,300\nM=TEXT\nC=RLENGTH\n" + "B=100\nN=90\nA=0,50,10,150\nS=NORMAL_SCAN\nP=0\n" + "G=0\nL=0\nD=DUP\n" "\x80"; ASSERT_EQ(ret_length, sizeof(test_ret) - 1); ASSERT_EQ(memcmp (test_ret, data_buffer, sizeof(test_ret) - 1), 0); }