]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add br x value
authorBastian Dehn <hhaalo@arcor.de>
Mon, 24 Feb 2025 18:47:40 +0000 (19:47 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 6 Mar 2025 20:44:53 +0000 (21:44 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_handler_opts.c
src/kds_s2000w_option_descriptors.c
tests/kds_s2000w_net_get_opt_tests.c
tests/kds_s2000w_net_get_opt_tests.h
tests/kds_s2000w_net_get_opt_tests_run.c
tests/kds_s2000w_option_descriptor_tests.c
tests/kds_s2000w_option_descriptor_tests.h
tests/kds_s2000w_option_descriptor_tests_run.c

index d082cc121a4a111278f01545353d399fb284dd9f..8061dc1fc29e7f2a7a214a0a7fabc7f38ff73465 100644 (file)
@@ -59,6 +59,7 @@ handler* kds_s2000w_handler_init()
        kds_s2000w_debug_printf(ALL, "init handler");
 
        handler* h = malloc(sizeof(handler));
+       h->br = malloc(sizeof(coordinate));
        h->current_scanner_config = NULL;
        h->current_scan_status = malloc(sizeof(scanstatus));
        h->read_info = malloc(sizeof(readinfo));
@@ -66,6 +67,8 @@ handler* kds_s2000w_handler_init()
 
        h->sessionid = 0;
        h->state = NOTCONNECTED;
+       h->br->x = 0;
+       h->br->y = 0;
        h->current_scan_status->current_image_number = 1;
        h->current_scan_status->available_images = 0;
        h->current_scan_status->downloaded_images = 0;
@@ -94,6 +97,8 @@ void kds_s2000w_handler_free(handler* h)
 
        json_object_put(h->current_scanner_config);
        h->current_scanner_config = NULL;
+       free(h->br);
+       h->br = NULL;
        free(h->current_scan_status);
        h->current_scan_status = NULL;
        free(h->read_info);
index 67e3312642022bf539232166a1cb4e60980a7e11..35021708cdde0a3388f10865499f504b3c7d2c0f 100644 (file)
@@ -21,6 +21,11 @@ enum {
        Automatic
 };
 
+typedef struct {
+       int32_t x;
+       int32_t y;
+} coordinate;
+
 typedef struct {
        size_t size;
        void* data;
@@ -52,6 +57,7 @@ typedef struct {
 typedef struct {
        uint64_t sessionid;
        uint8_t state;
+       coordinate* br;
        json_object* current_scanner_config;
        scanstatus* current_scan_status;
        readinfo* read_info;
index 379bc8a928bc83db970022aa227eccc911e8414d..6d6dcc55a6d0756f813e8fbf6e58249997cbff3c 100644 (file)
@@ -7,7 +7,7 @@
 #include "kds_s2000w_debug.h"
 
 #define AUTOSTART_ON 1
-#define OPTION_COUNT 47
+#define OPTION_COUNT 48
 
 #define OFFSET_X_MAX_INCH 75
 #define OFFSET_Y_MAX_INCH 390
@@ -305,26 +305,38 @@ void _kds_s2000w_handler_opts_set_enable_color_drop_out_aggressiveness(json_obje
        color_drop_out_aggressiveness->cap &= ~SANE_CAP_SOFT_SELECT;
 }
 
-void _kds_s2000w_handler_opts_get_pixel_value_from_inch(json_object* config, const char* option_name, void* value)
+int32_t _kds_s2000w_handler_opts_inch_to_pixel(json_object* config, int32_t inch)
 {
-       int32_t* pixel = (int32_t*) value;
+       json_object* object_value = json_object_object_get(config, "DPI");
+       int32_t dpi = json_object_get_int(object_value);
 
+       return kds_s2000w_handler_opts_calc_inch_to_pixel(dpi, inch);
+}
+
+int32_t _kds_s2000w_handler_opts_pixel_to_inch(json_object* config, int32_t pixel)
+{
        json_object* object_value = json_object_object_get(config, "DPI");
        int32_t dpi = json_object_get_int(object_value);
-       object_value = json_object_object_get(config, option_name);
+
+       return kds_s2000w_handler_opts_calc_pixel_to_inch(dpi, pixel);
+}
+
+void _kds_s2000w_handler_opts_get_pixel_value_from_inch(json_object* config, const char* option_name, void* value)
+{
+       int32_t* pixel = (int32_t*) value;
+
+       json_object* object_value = json_object_object_get(config, option_name);
        int32_t inch = json_object_get_int(object_value);
 
-       *pixel = kds_s2000w_handler_opts_calc_inch_to_pixel(dpi, inch);
+       *pixel = _kds_s2000w_handler_opts_inch_to_pixel(config, inch);
 }
 
 void _kds_s2000w_handler_opts_set_inch_value_from_pixel(json_object* config, const char* option_name, void* value)
 {
        int32_t* pixel = (int32_t*) value;
 
-       json_object* object_value = json_object_object_get(config, "DPI");
-       int32_t dpi = json_object_get_int(object_value);
-       object_value = json_object_object_get(config, option_name);
-       int32_t inch = kds_s2000w_handler_opts_calc_pixel_to_inch(dpi, *pixel);
+       json_object* object_value = json_object_object_get(config, option_name);
+       int32_t inch = _kds_s2000w_handler_opts_pixel_to_inch(config, *pixel);
 
        _kds_s2000w_handler_opts_write_int_value_to_json(object_value, &inch);
 }
@@ -512,6 +524,10 @@ void kds_s2000w_handler_opts_get_option(handler* h, uint32_t option, void* value
                        value_object = json_object_object_get(config, "DocumentFeederTimeoutResponse");
                        _kds_s2000w_handler_opts_write_string_value(value_object, value);
                        break;
+               case 47:
+                       int* br_x = (int*) value;
+                       *br_x = _kds_s2000w_handler_opts_inch_to_pixel(config, h->br->x);
+                       break;
                default:
                        break;
        }
@@ -747,6 +763,10 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value
                        value_object = json_object_object_get(config, "DocumentFeederTimeoutResponse");
                        _kds_s2000w_handler_opts_write_string_value_to_json(value_object, value);
                        break;
+               case 47:
+                       int* br_x = (int*) value;
+                       *br_x = _kds_s2000w_handler_opts_pixel_to_inch(config, h->br->x);
+                       break;
                default:
                        break;
        }
index 57638bb062581b3f7ba1c786df116868fab5bb87..57d02e0243554e9b3f041c1fee67e0ca9aa42351 100644 (file)
@@ -3,7 +3,7 @@
 #include "kds_s2000w_option_descriptors.h"
 #include "kds_s2000w_debug.h"
 
-#define MAX_OPTION_COUNT 47
+#define MAX_OPTION_COUNT 48
 
 SANE_Option_Descriptor* descriptor_array = NULL;
 
@@ -1108,6 +1108,30 @@ SANE_Option_Descriptor _kds_s2000w_option_descriptor_feeder_group()
        return descriptor;
 }
 
+SANE_Option_Descriptor _kds_s2000w_option_descriptor_br_x()
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_br_x");
+
+       SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       constraint->min = 0;
+       constraint->max = 1500;
+       constraint->quant = 20;
+
+       SANE_Option_Descriptor descriptor = {
+               SANE_NAME_SCAN_BR_X,
+               SANE_TITLE_SCAN_BR_X,
+               SANE_DESC_SCAN_BR_X,
+               SANE_TYPE_INT,
+               SANE_UNIT_PIXEL,
+               sizeof(SANE_Int),
+               SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED,
+               SANE_CONSTRAINT_RANGE,
+               {.range = constraint}
+       };
+
+       return descriptor;
+}
+
 void kds_s2000w_option_descriptors_init()
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_init_option_descriptors");
@@ -1160,6 +1184,7 @@ void kds_s2000w_option_descriptors_init()
        descriptor_array[44] = _kds_s2000w_option_descriptor_multifeed_response();
        descriptor_array[45] = _kds_s2000w_option_descriptor_document_feeder_timeout();
        descriptor_array[46] = _kds_s2000w_option_descriptor_document_feeder_timeout_response();
+       descriptor_array[47] = _kds_s2000w_option_descriptor_br_x();
 }
 
 void kds_s2000w_option_descriptors_free()
index c34fcec3f7618692bfcd13d58fdceea02d0b51e2..03cca1542aae792b8386759a755c87f015927612 100644 (file)
@@ -7,7 +7,7 @@
 #include "../src/kds_s2000w_net.h"
 #include "../src/kds_s2000w_handler.h"
 
-#define MAX_OPTION_COUNT 47
+#define MAX_OPTION_COUNT 48
 
 void sane_kds_s2000w_net_control_get_option_zero_test(void** state)
 {
@@ -612,6 +612,21 @@ void sane_kds_s2000w_net_control_get_option_fourtysix_test(void** state)
 
        assert_string_equal(value, "Stop");
 
+       kds_s2000w_handler_free(h);
+       h = NULL;
+}
+
+void sane_kds_s2000w_net_control_get_option_fourtyseven_test(void** state)
+{
+       handler* h = kds_s2000w_handler_init();
+       response* resp = (response*) *state;
+       h->current_scanner_config = json_tokener_parse(resp->data);
+       int32_t value;
+
+       sane_kds_s2000w_net_control_option(h, 47, SANE_ACTION_GET_VALUE, &value, NULL);
+
+       assert_int_equal(value, 0);
+
        kds_s2000w_handler_free(h);
        h = NULL;
 }
\ No newline at end of file
index 36599631e5b1f296c3af785e1d48fdcb502a1b13..d8cd0081fbe278a010db3064ba6aa6fef90b1f2b 100644 (file)
@@ -46,5 +46,6 @@ void sane_kds_s2000w_net_control_get_option_fourtythree_test(void** state);
 void sane_kds_s2000w_net_control_get_option_fourtyfour_test(void** state);
 void sane_kds_s2000w_net_control_get_option_fourtyfive_test(void** state);
 void sane_kds_s2000w_net_control_get_option_fourtysix_test(void** state);
+void sane_kds_s2000w_net_control_get_option_fourtyseven_test(void** state);
 
 #endif
\ No newline at end of file
index c5de03a47a70fc01284181508248de20ef025700..b077855ef0878d2b56b5ba675b2661f97068dad2 100644 (file)
@@ -119,7 +119,8 @@ int main()
                cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtythree_test, setup_default_get_option, teardown_default_get_option),
                cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyfour_test, setup_default_get_option, teardown_default_get_option),
                cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyfive_test, setup_default_get_option, teardown_default_get_option),
-               cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtysix_test, setup_default_get_option, teardown_default_get_option)
+               cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtysix_test, setup_default_get_option, teardown_default_get_option),
+               cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyseven_test, setup_default_get_option, teardown_default_get_option)
        };
 
        return cmocka_run_group_tests(net_tests, NULL, NULL);
index fc70f10f99f851c33487bddfe35b38cf42c2c788..6af316bde4d1b25bc209bf2bfdfdabdd3e9a1c36 100644 (file)
@@ -4,7 +4,7 @@
 #include "kds_s2000w_client_mock.h"
 #include "../src/kds_s2000w_option_descriptors.h"
 
-#define MAX_OPTION_COUNT 47
+#define MAX_OPTION_COUNT 48
 
 int setup(void** state)
 {
@@ -822,6 +822,23 @@ void kds_s2000w_option_get_descriptor_fourtysix_test()
        assert_null(option->constraint.string_list[3]);
 }
 
+void kds_s2000w_option_get_descriptor_fourtyseven_test()
+{
+       SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get(47);
+
+       assert_string_equal(SANE_NAME_SCAN_BR_X, option->name);
+       assert_string_equal(SANE_TITLE_SCAN_BR_X, option->title);
+       assert_string_equal(SANE_DESC_SCAN_BR_X, option->desc);
+       assert_int_equal(SANE_TYPE_INT, option->type);
+       assert_int_equal(SANE_UNIT_PIXEL, option->unit);
+       assert_int_equal(sizeof(SANE_Int), option->size);
+       assert_int_equal(SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED, option->cap);
+       assert_int_equal(SANE_CONSTRAINT_RANGE, option->constraint_type);
+       assert_int_equal(option->constraint.range->min, 0);
+       assert_int_equal(option->constraint.range->max, 1500);
+       assert_int_equal(option->constraint.range->quant, 20);
+}
+
 void kds_s2000w_option_get_descriptor_get_by_name_test()
 {
        SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get_by_name("config-reset");
index 938952a0380304b809a0df98f6b118741dc7fede..d412f3d255e19e206c5f719f5dd79e29d2fa3892 100644 (file)
@@ -55,6 +55,7 @@ void kds_s2000w_option_get_descriptor_fourtythree_test();
 void kds_s2000w_option_get_descriptor_fourtyfour_test();
 void kds_s2000w_option_get_descriptor_fourtyfive_test();
 void kds_s2000w_option_get_descriptor_fourtysix_test();
+void kds_s2000w_option_get_descriptor_fourtyseven_test();
 void kds_s2000w_option_get_descriptor_get_by_name_test();
 void kds_s2000w_option_get_descriptor_over_max_options_test();
 #endif
\ No newline at end of file
index f3ef88d6144d407f693f196647f889772e676c39..126e943031871df9ba6dfb6869f5148590cb98df 100644 (file)
@@ -50,6 +50,7 @@ int main()
                cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyfour_test, setup, teardown),
                cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyfive_test, setup, teardown),
                cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtysix_test, setup, teardown),
+               cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyseven_test, setup, teardown),
                cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_get_by_name_test, setup, teardown),
                cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_over_max_options_test, setup, teardown),
        };