From a58b20d2c8663ae75356663b68a1734936f4d0dd Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 2 Aug 2019 22:39:04 +0300 Subject: [PATCH 1/2] genesys: Move cmd_set from model to device struct --- backend/genesys.cc | 253 ++++++++++++++++++------------------- backend/genesys_device.h | 6 +- backend/genesys_devices.cc | 43 ------- backend/genesys_gl124.cc | 2 +- backend/genesys_gl646.cc | 2 +- backend/genesys_gl841.cc | 6 +- backend/genesys_gl843.cc | 4 +- backend/genesys_gl846.cc | 2 +- backend/genesys_gl847.cc | 2 +- backend/genesys_low.cc | 18 ++- 10 files changed, 140 insertions(+), 198 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 1a0b0e3b7..8e98fb1f8 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -835,8 +835,7 @@ sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg, { if (dev->model->motor_type == MOTOR_5345) { - if (dev->model->cmd_set->get_filter_bit (reg)) - { + if (dev->cmd_set->get_filter_bit(reg)) { /* monochrome */ switch (xdpi) { @@ -875,8 +874,7 @@ sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg, } else if (dev->model->motor_type == MOTOR_HP2400) { - if (dev->model->cmd_set->get_filter_bit (reg)) - { + if (dev->cmd_set->get_filter_bit(reg)) { /* monochrome */ switch (xdpi) { @@ -900,8 +898,7 @@ sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg, } else if (dev->model->motor_type == MOTOR_HP2300) { - if (dev->model->cmd_set->get_filter_bit (reg)) - { + if (dev->cmd_set->get_filter_bit(reg)) { /* monochrome */ switch (xdpi) { @@ -958,9 +955,8 @@ static void genesys_send_offset_and_shading(Genesys_Device* dev, const Genesys_S /* ASIC higher than gl843 doesn't have register 2A/2B, so we route to * a per ASIC shading data loading function if available. * It is also used for scanners using SHDAREA */ - if(dev->model->cmd_set->send_shading_data!=NULL) - { - dev->model->cmd_set->send_shading_data(dev, sensor, data, size); + if (dev->cmd_set->send_shading_data != nullptr) { + dev->cmd_set->send_shading_data(dev, sensor, data, size); return; } @@ -1005,7 +1001,7 @@ static void genesys_send_offset_and_shading(Genesys_Device* dev, const Genesys_S sanei_genesys_set_buffer_address(dev, start_address); - dev->model->cmd_set->bulk_write_data(dev, 0x3c, data, size); + dev->cmd_set->bulk_write_data(dev, 0x3c, data, size); } // ? @@ -1022,7 +1018,7 @@ void sanei_genesys_init_shading_data(Genesys_Device* dev, const Genesys_Sensor& || dev->model->ccd_type==CCD_G4050 || dev->model->ccd_type==CCD_CS4400F || dev->model->ccd_type==CCD_CS8400F - || dev->model->cmd_set->send_shading_data!=NULL) + || dev->cmd_set->send_shading_data != NULL) return; DBG(DBG_proc, "%s (pixels_per_line = %d)\n", __func__, pixels_per_line); @@ -1450,7 +1446,7 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens std::vector calibration_data(size); std::vector all_data(size * 4, 1); - dev->model->cmd_set->set_fe(dev, sensor, AFE_INIT); + dev->cmd_set->set_fe(dev, sensor, AFE_INIT); dev->frontend.set_gain(0, 2); dev->frontend.set_gain(1, 2); @@ -1543,7 +1539,7 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens dev->frontend.get_offset(2)); - dev->model->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); + dev->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); sanei_genesys_read_data_from_scanner(dev, calibration_data.data(), size); @@ -1558,7 +1554,7 @@ static void genesys_coarse_calibration(Genesys_Device* dev, Genesys_Sensor& sens sanei_genesys_write_pnm_file("gl_coarse.pnm", all_data_8.data(), 8, channels, size / 6, 4); } - dev->model->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { @@ -1684,11 +1680,11 @@ static void genesys_dark_shading_calibration(Genesys_Device* dev, const Genesys_ // wait some time to let lamp to get dark sanei_genesys_sleep_ms(200); - dev->model->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); + dev->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); sanei_genesys_read_data_from_scanner(dev, calibration_data.data(), size); - dev->model->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); std::fill(dev->dark_average_data.begin(), dev->dark_average_data.begin() + dev->calib_pixels_offset * channels * 2, @@ -1802,16 +1798,16 @@ static void genesys_repark_sensor_before_shading(Genesys_Device* dev) if (dev->model->flags & GENESYS_FLAG_SHADING_REPARK) { // rewind keeps registers and slopes table intact from previous scan but is not // available on all supported chipsets (or may cause scan artifacts, see #7) - if (dev->model->cmd_set->rewind) { - dev->model->cmd_set->rewind(dev); + if (dev->cmd_set->rewind) { + dev->cmd_set->rewind(dev); } else { - dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); + dev->cmd_set->slow_back_home(dev, SANE_TRUE); } if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) { - dev->model->cmd_set->move_to_ta(dev); + dev->cmd_set->move_to_ta(dev); } } } @@ -1860,11 +1856,11 @@ static void genesys_white_shading_calibration(Genesys_Device* dev, const Genesys sanei_genesys_sleep_ms(500); // make sure lamp is bright again } - dev->model->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE); + dev->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE); sanei_genesys_read_data_from_scanner(dev, calibration_data.data(), size); - dev->model->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); if (DBG_LEVEL >= DBG_data) sanei_genesys_write_pnm_file("gl_white_shading.pnm", calibration_data.data(), 16, @@ -1890,7 +1886,7 @@ static void genesys_white_shading_calibration(Genesys_Device* dev, const Genesys if (dev->model->flags & GENESYS_FLAG_SHADING_REPARK) { - dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); + dev->cmd_set->slow_back_home(dev, SANE_TRUE); } } @@ -1942,11 +1938,11 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev, dev->write_registers(dev->calib_reg); - dev->model->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); + dev->cmd_set->begin_scan(dev, sensor, &dev->calib_reg, SANE_FALSE); sanei_genesys_read_data_from_scanner(dev, calibration_data.data(), size); - dev->model->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->calib_reg, SANE_TRUE); if (DBG_LEVEL >= DBG_data) { @@ -2574,10 +2570,11 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_ Wn = white average for column n Dn = dark average for column n */ - if (dev->model->cmd_set->get_gain4_bit(&dev->calib_reg)) - coeff = 0x4000; - else - coeff = 0x2000; + if (dev->cmd_set->get_gain4_bit(&dev->calib_reg)) { + coeff = 0x4000; + } else { + coeff = 0x2000; + } /* compute avg factor */ if(dev->settings.xres>sensor.optical_res) @@ -2808,17 +2805,16 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) { DBG_HELPER(dbg); - /* if no cache or no function to evaluate cache entry ther can be no match */ - if (!dev->model->cmd_set->is_compatible_calibration - || dev->calibration_cache.empty()) - return false; + // if no cache or no function to evaluate cache entry ther can be no match/ + if (dev->cmd_set->is_compatible_calibration == nullptr || dev->calibration_cache.empty()) { + return false; + } /* we walk the link list of calibration cache in search for a * matching one */ for (auto& cache : dev->calibration_cache) { - if (dev->model->cmd_set->is_compatible_calibration(dev, sensor, &cache, SANE_FALSE)) - { + if (dev->cmd_set->is_compatible_calibration(dev, sensor, &cache, SANE_FALSE)) { dev->frontend = cache.frontend; /* we don't restore the gamma fields */ sensor.exposure = cache.sensor.exposure; @@ -2830,8 +2826,7 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) dev->dark_average_data = cache.dark_average_data; dev->white_average_data = cache.white_average_data; - if(dev->model->cmd_set->send_shading_data==NULL) - { + if(dev->cmd_set->send_shading_data == nullptr) { genesys_send_shading_coefficient(dev, sensor); } @@ -2851,15 +2846,14 @@ static void genesys_save_calibration(Genesys_Device* dev, const Genesys_Sensor& struct timeval time; #endif - if (dev->model->cmd_set->is_compatible_calibration == nullptr) + if (dev->cmd_set->is_compatible_calibration == nullptr) return; auto found_cache_it = dev->calibration_cache.end(); for (auto cache_it = dev->calibration_cache.begin(); cache_it != dev->calibration_cache.end(); cache_it++) { - if (dev->model->cmd_set->is_compatible_calibration(dev, sensor, &*cache_it, SANE_TRUE)) - { + if (dev->cmd_set->is_compatible_calibration(dev, sensor, &*cache_it, SANE_TRUE)) { found_cache_it = cache_it; break; } @@ -2918,18 +2912,18 @@ static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sen if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { sanei_usb_testing_record_message("offset_calibration"); - dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); /* since all the registers are set up correctly, just use them */ sanei_usb_testing_record_message("coarse_gain_calibration"); - dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, coarse_res); + dev->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, coarse_res); } else /* since we have 2 gain calibration proc, skip second if first one was used. */ { sanei_usb_testing_record_message("init_regs_for_coarse_calibration"); - dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); sanei_usb_testing_record_message("genesys_coarse_calibration"); genesys_coarse_calibration(dev, sensor); @@ -2939,25 +2933,25 @@ static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sen { /* the afe now sends valid data for doing led calibration */ sanei_usb_testing_record_message("led_calibration"); - dev->model->cmd_set->led_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->led_calibration(dev, sensor, dev->calib_reg); /* calibrate afe again to match new exposure */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { sanei_usb_testing_record_message("offset_calibration"); - dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); /* since all the registers are set up correctly, just use them */ sanei_usb_testing_record_message("coarse_gain_calibration"); - dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, coarse_res); + dev->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, coarse_res); } else /* since we have 2 gain calibration proc, skip second if first one was used. */ { sanei_usb_testing_record_message("init_regs_for_coarse_calibration"); - dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); sanei_usb_testing_record_message("genesys_coarse_calibration"); genesys_coarse_calibration(dev, sensor); @@ -2981,13 +2975,12 @@ static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sen if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) { - dev->model->cmd_set-> - move_to_ta(dev); + dev->cmd_set->move_to_ta(dev); } /* shading calibration */ sanei_usb_testing_record_message("init_regs_for_shading"); - dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); if (dev->model->flags & GENESYS_FLAG_DARK_WHITE_CALIBRATION) { @@ -3008,14 +3001,13 @@ static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sen genesys_repark_sensor_before_shading(dev); sanei_usb_testing_record_message("init_regs_for_shading2"); - dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); sanei_usb_testing_record_message("genesys_white_shading_calibration"); genesys_white_shading_calibration(dev, sensor); } - if(dev->model->cmd_set->send_shading_data==NULL) - { + if (dev->cmd_set->send_shading_data == nullptr) { sanei_usb_testing_record_message("genesys_send_shading_coefficient"); genesys_send_shading_coefficient(dev, sensor); } @@ -3036,13 +3028,12 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se SANE_Bool forward = SANE_TRUE; int xres; - if (dev->model->cmd_set->search_strip == NULL) - { + if (dev->cmd_set->search_strip == nullptr) { throw SaneException(SANE_STATUS_UNSUPPORTED, "no strip searching function available"); } // first step, load document - dev->model->cmd_set->load_document(dev); + dev->cmd_set->load_document(dev); /* led, offset and gain calibration are influenced by scan * settings. So we set it to sensor resolution */ @@ -3057,31 +3048,31 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se /* go to a white area */ try { - dev->model->cmd_set->search_strip(dev, sensor, forward, SANE_FALSE); + dev->cmd_set->search_strip(dev, sensor, forward, SANE_FALSE); } catch (...) { - catch_all_exceptions(__func__, [&](){ dev->model->cmd_set->eject_document(dev); }); + catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); throw; } if (dev->model->is_cis) { - dev->model->cmd_set->led_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->led_calibration(dev, sensor, dev->calib_reg); } /* calibrate afe */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { - dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); /* since all the registers are set up correctly, just use them */ - dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, xres); + dev->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, xres); } else /* since we have 2 gain calibration proc, skip second if first one was used. */ { - dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); genesys_coarse_calibration(dev, sensor); } @@ -3092,18 +3083,18 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se { /* seek black/white reverse/forward */ try { - dev->model->cmd_set->search_strip(dev, sensor, forward, SANE_TRUE); + dev->cmd_set->search_strip(dev, sensor, forward, SANE_TRUE); } catch (...) { - catch_all_exceptions(__func__, [&](){ dev->model->cmd_set->eject_document(dev); }); + catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); throw; } - dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); try { genesys_dark_shading_calibration(dev, sensor); } catch (...) { - catch_all_exceptions(__func__, [&](){ dev->model->cmd_set->eject_document(dev); }); + catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); throw; } forward = SANE_FALSE; @@ -3112,20 +3103,20 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se /* go to a white area */ try { - dev->model->cmd_set->search_strip(dev, sensor, forward, SANE_FALSE); + dev->cmd_set->search_strip(dev, sensor, forward, SANE_FALSE); } catch (...) { - catch_all_exceptions(__func__, [&](){ dev->model->cmd_set->eject_document(dev); }); + catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); throw; } genesys_repark_sensor_before_shading(dev); - dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); + dev->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); try { genesys_white_shading_calibration(dev, sensor); } catch (...) { - catch_all_exceptions(__func__, [&](){ dev->model->cmd_set->eject_document(dev); }); + catch_all_exceptions(__func__, [&](){ dev->cmd_set->eject_document(dev); }); throw; } @@ -3146,8 +3137,7 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se /* send the shading coefficient when doing whole line shading * but not when using SHDAREA like GL124 */ - if(dev->model->cmd_set->send_shading_data==NULL) - { + if (dev->cmd_set->send_shading_data == nullptr) { genesys_send_shading_coefficient(dev, sensor); } @@ -3155,7 +3145,7 @@ static void genesys_sheetfed_calibration(Genesys_Device* dev, Genesys_Sensor& se genesys_save_calibration(dev, sensor); // and finally eject calibration sheet - dev->model->cmd_set->eject_document(dev); + dev->cmd_set->eject_document(dev); /* resotre settings */ dev->settings.xres = xres; @@ -3197,20 +3187,20 @@ static void genesys_warmup_lamp(Genesys_Device* dev) int empty, lines = 3; /* check if the current chipset implements warmup */ - if (dev->model->cmd_set->init_regs_for_warmup == NULL) { + if (dev->cmd_set->init_regs_for_warmup == NULL) { throw SaneException("init_regs_for_warmup not implemented"); } const auto& sensor = sanei_genesys_find_sensor_any(dev); - dev->model->cmd_set->init_regs_for_warmup(dev, sensor, &dev->reg, &channels, &total_size); + dev->cmd_set->init_regs_for_warmup(dev, sensor, &dev->reg, &channels, &total_size); std::vector first_line(total_size); std::vector second_line(total_size); do { DBG(DBG_info, "%s: one more loop\n", __func__); - dev->model->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_FALSE); + dev->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_FALSE); do { sanei_genesys_test_buffer_empty(dev, &empty); @@ -3224,12 +3214,12 @@ static void genesys_warmup_lamp(Genesys_Device* dev) sanei_genesys_read_data_from_scanner(dev, first_line.data(), total_size); } - dev->model->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); sanei_genesys_sleep_ms(1000); seconds++; - dev->model->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_FALSE); + dev->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_FALSE); do { sanei_genesys_test_buffer_empty(dev, &empty); @@ -3237,14 +3227,13 @@ static void genesys_warmup_lamp(Genesys_Device* dev) } while (empty); sanei_genesys_read_data_from_scanner(dev, second_line.data(), total_size); - dev->model->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); + dev->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); /* compute difference between the two scans */ for (pixel = 0; pixel < total_size; pixel++) { - /* 16 bit data */ - if (dev->model->cmd_set->get_bitset_bit(&dev->reg)) - { + // 16 bit data + if (dev->cmd_set->get_bitset_bit(&dev->reg)) { first_average += (first_line[pixel] + first_line[pixel + 1] * 256); second_average += (second_line[pixel] + second_line[pixel + 1] * 256); pixel++; @@ -3255,8 +3244,7 @@ static void genesys_warmup_lamp(Genesys_Device* dev) second_average += second_line[pixel]; } } - if (dev->model->cmd_set->get_bitset_bit(&dev->reg)) - { + if (dev->cmd_set->get_bitset_bit(&dev->reg)) { first_average /= pixel; second_average /= pixel; difference = fabs (first_average - second_average); @@ -3320,7 +3308,7 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) } // disable power saving - dev->model->cmd_set->save_power(dev, SANE_FALSE); + dev->cmd_set->save_power(dev, SANE_FALSE); /* wait for lamp warmup : until a warmup for TRANSPARENCY is designed, skip * it when scanning from XPA. */ @@ -3337,10 +3325,10 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) if ((dev->model->flags & GENESYS_FLAG_SEARCH_START) && (dev->model->y_offset_calib == 0)) { - dev->model->cmd_set->search_start_position (dev); + dev->cmd_set->search_start_position (dev); dev->parking = SANE_FALSE; - dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); + dev->cmd_set->slow_back_home (dev, SANE_TRUE); dev->scanhead_position_in_steps = 0; } else @@ -3349,7 +3337,7 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) /* TODO: check we can drop this since we cannot have the scanner's head wandering here */ dev->parking = SANE_FALSE; - dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); + dev->cmd_set->slow_back_home (dev, SANE_TRUE); dev->scanhead_position_in_steps = 0; } @@ -3358,16 +3346,16 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) /* move to calibration area for transparency adapter */ if ((dev->settings.scan_method == ScanMethod::TRANSPARENCY || dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) && - dev->model->cmd_set->move_to_ta != NULL) + dev->cmd_set->move_to_ta != nullptr) { - dev->model->cmd_set->move_to_ta(dev); + dev->cmd_set->move_to_ta(dev); } /* load document if needed (for sheetfed scanner for instance) */ if (dev->model->is_sheetfed == SANE_TRUE - && dev->model->cmd_set->load_document != NULL) + && dev->cmd_set->load_document != nullptr) { - dev->model->cmd_set->load_document(dev); + dev->cmd_set->load_document(dev); } auto& sensor = sanei_genesys_find_sensor_for_write(dev, dev->settings.xres, @@ -3375,7 +3363,7 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) // send gamma tables. They have been set to device or user value // when setting option value */ - dev->model->cmd_set->send_gamma_table(dev, sensor); + dev->cmd_set->send_gamma_table(dev, sensor); /* try to use cached calibration first */ if (!genesys_restore_calibration (dev, sensor)) @@ -3401,24 +3389,24 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) dev->settings.threshold-127); } - if (dev->model->cmd_set->wait_for_motor_stop) { - dev->model->cmd_set->wait_for_motor_stop(dev); + if (dev->cmd_set->wait_for_motor_stop) { + dev->cmd_set->wait_for_motor_stop(dev); } - if (dev->model->cmd_set->needs_home_before_init_regs_for_scan && - dev->model->cmd_set->needs_home_before_init_regs_for_scan(dev) && - dev->model->cmd_set->slow_back_home) + if (dev->cmd_set->needs_home_before_init_regs_for_scan && + dev->cmd_set->needs_home_before_init_regs_for_scan(dev) && + dev->cmd_set->slow_back_home) { - dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); + dev->cmd_set->slow_back_home(dev, SANE_TRUE); } if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || dev->settings.scan_method == ScanMethod::TRANSPARENCY_INFRARED) { - dev->model->cmd_set->move_to_ta(dev); + dev->cmd_set->move_to_ta(dev); } - dev->model->cmd_set->init_regs_for_scan(dev, sensor); + dev->cmd_set->init_regs_for_scan(dev, sensor); /* no lamp during scan */ if(lamp_off == SANE_TRUE) @@ -3428,8 +3416,8 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) /* GL124 is using SHDAREA, so we have to wait for scan to be set up before * sending shading data */ - if( (dev->model->cmd_set->send_shading_data!=NULL) - && !(dev->model->flags & GENESYS_FLAG_NO_CALIBRATION)) + if (dev->cmd_set->send_shading_data != nullptr && + !(dev->model->flags & GENESYS_FLAG_NO_CALIBRATION)) { genesys_send_shading_coefficient(dev, sensor); } @@ -3438,7 +3426,7 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) dev->write_registers(dev->reg); // start effective scan - dev->model->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_TRUE); + dev->cmd_set->begin_scan(dev, sensor, &dev->reg, SANE_TRUE); /*do we really need this? the valid data check should be sufficent -- pierre*/ /* waits for head to reach scanning position */ @@ -3460,10 +3448,11 @@ static void genesys_start_scan(Genesys_Device* dev, SANE_Bool lamp_off) /* when doing one or two-table movement, let the motor settle to scanning speed */ /* and scanning start before reading data */ /* the valid data check already waits until the scanner delivers data. this here leads to unnecessary buffer full conditions in the scanner. - if (dev->model->cmd_set->get_fast_feed_bit (dev->reg)) - sanei_genesys_sleep_ms(1000); - else - sanei_genesys_sleep_ms(500); + if (dev->cmd_set->get_fast_feed_bit (dev->reg)) { + sanei_genesys_sleep_ms(1000); + } else { + sanei_genesys_sleep_ms(500); + } */ /* then we wait for at least one word of valid scan data @@ -3486,7 +3475,7 @@ static void accurate_line_read(Genesys_Device* dev, Genesys_Buffer& buffer) DBG_HELPER(dbg); buffer.reset(); - dev->model->cmd_set->bulk_read_data(dev, 0x45, buffer.get_write_pos(buffer.size()), + dev->cmd_set->bulk_read_data(dev, 0x45, buffer.get_write_pos(buffer.size()), buffer.size()); buffer.produce(buffer.size()); @@ -3641,7 +3630,7 @@ static void genesys_fill_read_buffer(Genesys_Device* dev) * the requested scan */ if (dev->model->is_sheetfed == SANE_TRUE) { - dev->model->cmd_set->detect_document_end(dev); + dev->cmd_set->detect_document_end(dev); } space = dev->read_buffer.size() - dev->read_buffer.avail(); @@ -3695,7 +3684,7 @@ static void genesys_fill_read_buffer(Genesys_Device* dev) } else /* regular case with no extra copy */ { - dev->model->cmd_set->bulk_read_data(dev, 0x45, work_buffer_dst, size); + dev->cmd_set->bulk_read_data(dev, 0x45, work_buffer_dst, size); } if (size > dev->read_bytes_left) @@ -3780,7 +3769,7 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio && !(dev->model->flags & GENESYS_FLAG_MUST_WAIT) && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home(dev, SANE_FALSE); + dev->cmd_set->slow_back_home(dev, SANE_FALSE); dev->parking = SANE_TRUE; } throw SaneException(SANE_STATUS_EOF, "nothing more to scan: EOF"); @@ -4071,10 +4060,9 @@ Problems with the first approach: /* end scan if all needed data have been read */ if(dev->total_bytes_read >= dev->total_bytes_to_read) { - dev->model->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); - if (dev->model->is_sheetfed == SANE_TRUE) - { - dev->model->cmd_set->eject_document (dev); + dev->cmd_set->end_scan(dev, &dev->reg, SANE_TRUE); + if (dev->model->is_sheetfed == SANE_TRUE) { + dev->cmd_set->eject_document (dev); } } @@ -5354,7 +5342,7 @@ static void genesys_buffer_image(Genesys_Scanner *s) if (dev->model->is_sheetfed == SANE_FALSE && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home(dev, dev->model->flags & GENESYS_FLAG_MUST_WAIT); + dev->cmd_set->slow_back_home(dev, dev->model->flags & GENESYS_FLAG_MUST_WAIT); dev->parking = !(s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); } @@ -5592,10 +5580,10 @@ sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle) // FIXME: we create sensor tables for the sensor, this should happen when we know which sensor // we will select - dev->model->cmd_set->init(dev); + dev->cmd_set->init(dev); // some hardware capabilities are detected through sensors - s->dev->model->cmd_set->update_hardware_sensors (s); + s->dev->cmd_set->update_hardware_sensors (s); /* here is the place to fetch a stored calibration cache */ if (s->dev->force_calibration == 0) @@ -5648,7 +5636,7 @@ sane_close_impl(SANE_Handle handle) /* eject document for sheetfed scanners */ if (s->dev->model->is_sheetfed == SANE_TRUE) { - catch_all_exceptions(__func__, [&](){ s->dev->model->cmd_set->eject_document(s->dev); }); + catch_all_exceptions(__func__, [&](){ s->dev->cmd_set->eject_document(s->dev); }); } else { @@ -5661,7 +5649,7 @@ sane_close_impl(SANE_Handle handle) } // enable power saving before leaving - s->dev->model->cmd_set->save_power(s->dev, SANE_TRUE); + s->dev->cmd_set->save_power(s->dev, SANE_TRUE); // here is the place to store calibration cache if (s->dev->force_calibration == 0) { @@ -5888,7 +5876,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val) case OPT_OCR_SW: case OPT_POWER_SW: case OPT_EXTRA_SW: - s->dev->model->cmd_set->update_hardware_sensors(s); + s->dev->cmd_set->update_hardware_sensors(s); *(SANE_Bool *) val = s->buttons[genesys_option_to_button(option)].read(); break; case OPT_NEED_CALIBRATION_SW: @@ -5897,8 +5885,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val) *(SANE_Bool *) val = SANE_TRUE; for (auto& cache : s->dev->calibration_cache) { - if (s->dev->model->cmd_set->is_compatible_calibration(s->dev, sensor, &cache, SANE_FALSE)) - { + if (s->dev->cmd_set->is_compatible_calibration(s->dev, sensor, &cache, SANE_FALSE)) { *(SANE_Bool *) val = SANE_FALSE; } } @@ -6188,14 +6175,14 @@ set_option_value (Genesys_Scanner * s, int option, void *val, case OPT_LAMP_OFF_TIME: if (*reinterpret_cast(val) != s->lamp_off_time) { s->lamp_off_time = *reinterpret_cast(val); - s->dev->model->cmd_set->set_powersaving(s->dev, s->lamp_off_time); + s->dev->cmd_set->set_powersaving(s->dev, s->lamp_off_time); } break; case OPT_EXPIRATION_TIME: if (*reinterpret_cast(val) != s->expiration_time) { s->expiration_time = *reinterpret_cast(val); // BUG: this is most likely not intended behavior, found out during refactor - s->dev->model->cmd_set->set_powersaving(s->dev, s->expiration_time); + s->dev->cmd_set->set_powersaving(s->dev, s->expiration_time); } break; @@ -6271,12 +6258,12 @@ set_option_value (Genesys_Scanner * s, int option, void *val, case OPT_CALIBRATE: { catch_all_exceptions(__func__, [&]() { - s->dev->model->cmd_set->save_power(s->dev, SANE_FALSE); + s->dev->cmd_set->save_power(s->dev, SANE_FALSE); genesys_scanner_calibration(s->dev, sensor); }); catch_all_exceptions(__func__, [&]() { - s->dev->model->cmd_set->save_power(s->dev, SANE_TRUE); + s->dev->cmd_set->save_power(s->dev, SANE_TRUE); }); *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; break; @@ -6584,7 +6571,7 @@ sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* && !(dev->model->flags & GENESYS_FLAG_MUST_WAIT) && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home(dev, SANE_FALSE); + dev->cmd_set->slow_back_home(dev, SANE_FALSE); dev->parking = SANE_TRUE; } return SANE_STATUS_EOF; @@ -6683,7 +6670,7 @@ void sane_cancel_impl(SANE_Handle handle) /* no need to end scan if we are parking the head */ if(s->dev->parking==SANE_FALSE) { - s->dev->model->cmd_set->end_scan(s->dev, &s->dev->reg, SANE_TRUE); + s->dev->cmd_set->end_scan(s->dev, &s->dev->reg, SANE_TRUE); } /* park head if flatbed scanner */ @@ -6691,7 +6678,7 @@ void sane_cancel_impl(SANE_Handle handle) { if(s->dev->parking==SANE_FALSE) { - s->dev->model->cmd_set->slow_back_home (s->dev, s->dev->model->flags & + s->dev->cmd_set->slow_back_home (s->dev, s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); s->dev->parking = !(s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); @@ -6699,13 +6686,13 @@ void sane_cancel_impl(SANE_Handle handle) } else { /* in case of sheetfed scanners, we have to eject the document if still present */ - s->dev->model->cmd_set->eject_document(s->dev); + s->dev->cmd_set->eject_document(s->dev); } /* enable power saving mode unless we are parking .... */ if(s->dev->parking==SANE_FALSE) { - s->dev->model->cmd_set->save_power(s->dev, SANE_TRUE); + s->dev->cmd_set->save_power(s->dev, SANE_TRUE); } return; diff --git a/backend/genesys_device.h b/backend/genesys_device.h index 3d9d40989..cedd0229a 100644 --- a/backend/genesys_device.h +++ b/backend/genesys_device.h @@ -95,9 +95,6 @@ struct Genesys_Model // ASIC type gl646 or gl841 unsigned asic_type = 0; - // pointers to low level functions - Genesys_Command_Set* cmd_set = nullptr; - // possible x resolutions std::vector xdpi_values; // possible y resolutions @@ -225,6 +222,9 @@ struct Genesys_Device Genesys_Model *model = nullptr; + // pointers to low level functions + Genesys_Command_Set* cmd_set = nullptr; + Genesys_Register_Set reg; Genesys_Register_Set calib_reg; Genesys_Settings settings; diff --git a/backend/genesys_devices.cc b/backend/genesys_devices.cc index 2a7800bf3..085ddfb5f 100644 --- a/backend/genesys_devices.cc +++ b/backend/genesys_devices.cc @@ -3016,7 +3016,6 @@ void genesys_init_usb_device_tables() model.model = "Astra 4500"; model.model_id = MODEL_UMAX_ASTRA_4500; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 75 }; model.ydpi_values = { 2400, 1200, 600, 300, 150, 75 }; @@ -3069,7 +3068,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 35/40/50"; model.model_id = MODEL_CANON_LIDE_50; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 240, 200, 150, 75 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 240, 200, 150, 75 }; @@ -3129,7 +3127,6 @@ void genesys_init_usb_device_tables() model.model = "KV-SS080"; model.model_id = MODEL_PANASONIC_KV_SS080; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 600, /* 500, 400,*/ 300, 200, 150, 100, 75 }; model.ydpi_values = { 1200, 600, /* 500, 400, */ 300, 200, 150, 100, 75 }; @@ -3185,7 +3182,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet 4850C"; model.model_id = MODEL_HP_SCANJET_4850C; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; @@ -3242,7 +3238,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet G4010"; model.model_id = MODEL_HP_SCANJET_G4010; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; @@ -3299,7 +3294,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet G4050"; model.model_id = MODEL_HP_SCANJET_G4050; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100 }; @@ -3357,7 +3351,6 @@ void genesys_init_usb_device_tables() model.model = "Canoscan 4400f"; model.model_id = MODEL_CANON_CANOSCAN_4400F; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 400, 300, 200, 150, 100 }; model.ydpi_values = { 4800, 2400, 1200, 600, 400, 300, 200, 150, 100 }; @@ -3417,7 +3410,6 @@ void genesys_init_usb_device_tables() model.model = "Canoscan 8400f"; model.model_id = MODEL_CANON_CANOSCAN_8400F; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 400, 300, 200, 150, 100 }; model.ydpi_values = { 4800, 2400, 1200, 600, 400, 300, 200, 150, 100 }; @@ -3479,7 +3471,6 @@ void genesys_init_usb_device_tables() model.model = "Canoscan 8600f"; model.model_id = MODEL_CANON_CANOSCAN_8600F; model.asic_type = GENESYS_GL843; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 400, 300 }; // TODO: resolutions for non-XPA mode model.ydpi_values = { 4800, 2400, 1200, 600, 400, 300 }; // TODO: resolutions for non-XPA mode @@ -3541,7 +3532,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 100"; model.model_id = MODEL_CANON_LIDE_100; model.asic_type = GENESYS_GL847; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; @@ -3602,7 +3592,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 110"; model.model_id = MODEL_CANON_LIDE_110; model.asic_type = GENESYS_GL124; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, /* 400,*/ 300, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, /* 400,*/ 300, 150, 100, 75 }; @@ -3661,7 +3650,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 120"; model.model_id = MODEL_CANON_LIDE_120; model.asic_type = GENESYS_GL124; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 300, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, 300, 150, 100, 75 }; @@ -3719,7 +3707,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 210"; model.model_id = MODEL_CANON_LIDE_210; model.asic_type = GENESYS_GL124; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, /* 400,*/ 300, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, /* 400,*/ 300, 150, 100, 75 }; @@ -3780,7 +3767,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 220"; model.model_id = MODEL_CANON_LIDE_220; model.asic_type = GENESYS_GL124; // or a compatible one - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 300, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, 300, 150, 100, 75 }; @@ -3840,7 +3826,6 @@ void genesys_init_usb_device_tables() model.model = "5600F"; model.model_id = MODEL_CANON_CANOSCAN_5600F; model.asic_type = GENESYS_GL847; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 200, 150, 100, 75 }; model.ydpi_values = { 1200, 600, 400, 300, 200, 150, 100, 75 }; @@ -3901,7 +3886,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 700F"; model.model_id = MODEL_CANON_LIDE_700F; model.asic_type = GENESYS_GL847; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; @@ -3961,7 +3945,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 200"; model.model_id = MODEL_CANON_LIDE_200; model.asic_type = GENESYS_GL847; - model.cmd_set = NULL; model.xdpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; model.ydpi_values = { 4800, 2400, 1200, 600, 300, 200, 150, 100, 75 }; @@ -4021,7 +4004,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 60"; model.model_id = MODEL_CANON_LIDE_60; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 75 }; model.ydpi_values = { 2400, 1200, 600, 300, 150, 75 }; @@ -4081,7 +4063,6 @@ void genesys_init_usb_device_tables() model.model = "LiDE 80"; model.model_id = MODEL_CANON_LIDE_80; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 240, 150, 100, 75 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 240, 150, 100, 75 }; @@ -4140,7 +4121,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet 2300c"; model.model_id = MODEL_HP_SCANJET_2300C; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4198,7 +4178,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet 2400c"; model.model_id = MODEL_HP_SCANJET_2400C; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 100, 50 }; model.ydpi_values = { 1200, 600, 300, 150, 100, 50 }; @@ -4257,7 +4236,6 @@ void genesys_init_usb_device_tables() model.model = "Strobe XP200"; model.model_id = MODEL_VISIONEER_STROBE_XP200; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 200, 100, 75 }; model.ydpi_values = { 600, 300, 200, 100, 75 }; @@ -4315,7 +4293,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet 3670c"; model.model_id = MODEL_HP_SCANJET_3670C; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 100, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 100, 75 }; @@ -4374,7 +4351,6 @@ void genesys_init_usb_device_tables() model.model = "OpticPro ST12"; model.model_id = MODEL_PLUSTEK_OPTICPRO_ST12; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4426,7 +4402,6 @@ void genesys_init_usb_device_tables() model.model = "OpticPro ST24"; model.model_id = MODEL_PLUSTEK_OPTICPRO_ST24; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 75 }; model.ydpi_values = { 2400, 1200, 600, 300, 150, 75 }; @@ -4483,7 +4458,6 @@ void genesys_init_usb_device_tables() model.model = "MD5345/MD6228/MD6471"; model.model_id = MODEL_MEDION_MD5345; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; @@ -4545,7 +4519,6 @@ void genesys_init_usb_device_tables() model.model = "Strobe XP300"; model.model_id = MODEL_VISIONEER_STROBE_XP300; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 600, 300, 150, 75 }; @@ -4601,7 +4574,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 665"; model.model_id = MODEL_SYSCAN_DOCKETPORT_665; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4657,7 +4629,6 @@ void genesys_init_usb_device_tables() model.model = "Readwarrior"; model.model_id = MODEL_VISIONEER_ROADWARRIOR; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4713,7 +4684,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 465"; model.model_id = MODEL_SYSCAN_DOCKETPORT_465; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4770,7 +4740,6 @@ void genesys_init_usb_device_tables() model.model = "XP100 Revision 3"; model.model_id = MODEL_VISIONEER_STROBE_XP100_REVISION3; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4826,7 +4795,6 @@ void genesys_init_usb_device_tables() model.model = "DSmobile 600"; model.model_id = MODEL_PENTAX_DSMOBILE_600; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4884,7 +4852,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 467"; model.model_id = MODEL_SYSCAN_DOCKETPORT_467; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -4939,7 +4906,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 685"; model.model_id = MODEL_SYSCAN_DOCKETPORT_685; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 600, 300, 150, 75 }; @@ -4997,7 +4963,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 485"; model.model_id = MODEL_SYSCAN_DOCKETPORT_485; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 600, 300, 150, 75 }; @@ -5054,7 +5019,6 @@ void genesys_init_usb_device_tables() model.model = "DocketPORT 487"; model.model_id = MODEL_DCT_DOCKETPORT_487; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 600, 300, 150, 75 }; @@ -5112,7 +5076,6 @@ void genesys_init_usb_device_tables() model.model = "OneTouch 7100"; model.model_id = MODEL_VISIONEER_7100; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; @@ -5174,7 +5137,6 @@ void genesys_init_usb_device_tables() model.model = "OneTouch 2400"; model.model_id = MODEL_XEROX_2400; model.asic_type = GENESYS_GL646; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100, 75, 50 }; @@ -5236,7 +5198,6 @@ void genesys_init_usb_device_tables() model.model = "Travelscanner 100"; model.model_id = MODEL_XEROX_TRAVELSCANNER_100; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { 600, 300, 150, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 75 }; @@ -5293,7 +5254,6 @@ void genesys_init_usb_device_tables() model.model = "OpticBook 3600"; model.model_id = MODEL_PLUSTEK_OPTICPRO_3600; model.asic_type = GENESYS_GL841; - model.cmd_set = NULL; model.xdpi_values = { /*1200,*/ 600, 400, 300, 200, 150, 100, 75 }; model.ydpi_values = { /*2400,*/ 1200, 600, 400, 300, 200, 150, 100, 75 }; model.bpp_gray_values = { 16, 8 }; @@ -5350,7 +5310,6 @@ void genesys_init_usb_device_tables() model.model = "ScanJet N6310"; model.model_id = MODEL_HP_SCANJET_N6310; model.asic_type = GENESYS_GL847; - model.cmd_set = NULL; model.xdpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100, 75 }; model.ydpi_values = { 2400, 1200, 600, 400, 300, 200, 150, 100, 75 }; @@ -5412,7 +5371,6 @@ void genesys_init_usb_device_tables() model.model = "OpticBook 3800"; model.model_id = MODEL_PLUSTEK_OPTICBOOK_3800; model.asic_type = GENESYS_GL845; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 100, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 100, 75 }; @@ -5468,7 +5426,6 @@ void genesys_init_usb_device_tables() model.model = "Image Formula 101"; model.model_id = MODEL_CANON_IMAGE_FORMULA_101; model.asic_type = GENESYS_GL846; - model.cmd_set = NULL; model.xdpi_values = { 1200, 600, 300, 150, 100, 75 }; model.ydpi_values = { 1200, 600, 300, 150, 100, 75 }; diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 4ed31b1a3..bc82cf8a3 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -3121,5 +3121,5 @@ static Genesys_Command_Set gl124_cmd_set = { void sanei_gl124_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl124_cmd_set; + dev->cmd_set = &gl124_cmd_set; } diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 12e0eb7c8..611d43a03 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -4151,5 +4151,5 @@ static Genesys_Command_Set gl646_cmd_set = { void sanei_gl646_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl646_cmd_set; + dev->cmd_set = &gl646_cmd_set; } diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index f5e79d75c..0b6a5bf5e 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -4577,7 +4577,7 @@ static void gl841_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s sanei_genesys_set_buffer_address(dev, 0x0000); // shading data whole line - dev->model->cmd_set->bulk_write_data(dev, 0x3c, data, size); + dev->cmd_set->bulk_write_data(dev, 0x3c, data, size); return; } @@ -4652,7 +4652,7 @@ static void gl841_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s // 0x5400 alignment for LIDE80 internal memory sanei_genesys_set_buffer_address(dev, 0x5400*i); - dev->model->cmd_set->bulk_write_data(dev, 0x3c, buffer.data(), pixels); + dev->cmd_set->bulk_write_data(dev, 0x3c, buffer.data(), pixels); } } @@ -4715,5 +4715,5 @@ static Genesys_Command_Set gl841_cmd_set = { void sanei_gl841_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl841_cmd_set; + dev->cmd_set = &gl841_cmd_set; } diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 605265ece..ae9146ffe 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -3912,7 +3912,7 @@ static void gl843_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s // send data sanei_genesys_set_buffer_address(dev, 0); - dev->model->cmd_set->bulk_write_data (dev, 0x3c, final_data.data(), count); + dev->cmd_set->bulk_write_data (dev, 0x3c, final_data.data(), count); } @@ -3974,5 +3974,5 @@ static Genesys_Command_Set gl843_cmd_set = { void sanei_gl843_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl843_cmd_set; + dev->cmd_set = &gl843_cmd_set; } diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 920223c61..c85586eef 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -2905,5 +2905,5 @@ static Genesys_Command_Set gl846_cmd_set = { void sanei_gl846_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl846_cmd_set; + dev->cmd_set = &gl846_cmd_set; } diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index b1c1a998c..b009bed5e 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -3015,5 +3015,5 @@ static Genesys_Command_Set gl847_cmd_set = { void sanei_gl847_init_cmd_set(Genesys_Device* dev) { - dev->model->cmd_set = &gl847_cmd_set; + dev->cmd_set = &gl847_cmd_set; } diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 2cbcc6bd1..5890992b6 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -733,8 +733,7 @@ void sanei_genesys_test_buffer_empty(Genesys_Device* dev, SANE_Bool* empty) sanei_genesys_sleep_ms(1); sanei_genesys_get_status(dev, &val); - if (dev->model->cmd_set->test_buffer_empty_bit (val)) - { + if (dev->cmd_set->test_buffer_empty_bit(val)) { /* fix timing issue on USB3 (or just may be too fast) hardware * spotted by John S. Weber */ @@ -776,7 +775,7 @@ void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, uint8_t* data, si throw SaneException(SANE_STATUS_IO_ERROR, "timeout, buffer does not get filled"); } - dev->model->cmd_set->bulk_read_data(dev, 0x45, data, size); + dev->cmd_set->bulk_read_data(dev, 0x45, data, size); } void sanei_genesys_read_feed_steps(Genesys_Device* dev, unsigned int* steps) { @@ -1164,7 +1163,7 @@ void sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/) } // set up hardware and registers - dev->model->cmd_set->asic_boot(dev, cold); + dev->cmd_set->asic_boot(dev, cold); /* now hardware part is OK, set up device struct */ dev->white_average_data.clear(); @@ -1178,16 +1177,16 @@ void sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/) const auto& sensor = sanei_genesys_find_sensor_any(dev); // Set analog frontend - dev->model->cmd_set->set_fe(dev, sensor, AFE_INIT); + dev->cmd_set->set_fe(dev, sensor, AFE_INIT); dev->already_initialized = SANE_TRUE; // Move to home if needed - dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); + dev->cmd_set->slow_back_home(dev, SANE_TRUE); dev->scanhead_position_in_steps = 0; // Set powersaving (default = 15 minutes) - dev->model->cmd_set->set_powersaving(dev, 15); + dev->cmd_set->set_powersaving(dev, 15); } /** @@ -1450,13 +1449,12 @@ bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys #endif int compatible = 1, resolution; - if(dev->model->cmd_set->calculate_current_setup==NULL) - { + if(dev->cmd_set->calculate_current_setup == nullptr) { DBG (DBG_proc, "%s: no calculate_setup, non compatible cache\n", __func__); return false; } - dev->model->cmd_set->calculate_current_setup(dev, sensor); + dev->cmd_set->calculate_current_setup(dev, sensor); DBG (DBG_proc, "%s: checking\n", __func__); From 16c55bf330f80db64f886cd5bc9ceda588e00ba0 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 2 Aug 2019 22:39:05 +0300 Subject: [PATCH 2/2] genesys: Init cmd_set directly instead of going through a function --- backend/genesys_gl124.cc | 7 +------ backend/genesys_gl646.cc | 7 +------ backend/genesys_gl841.cc | 7 +------ backend/genesys_gl843.cc | 7 +------ backend/genesys_gl846.cc | 7 +------ backend/genesys_gl847.cc | 7 +------ backend/genesys_low.cc | 19 +++++++++++++------ backend/genesys_low.h | 6 ------ 8 files changed, 19 insertions(+), 48 deletions(-) diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index bc82cf8a3..285ba545e 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -3063,7 +3063,7 @@ static void gl124_update_hardware_sensors(Genesys_Scanner* s) /** the gl124 command set */ -static Genesys_Command_Set gl124_cmd_set = { +Genesys_Command_Set gl124_cmd_set = { "gl124-generic", /* the name of this set */ [](Genesys_Device* dev) -> bool { (void) dev; return true; }, @@ -3118,8 +3118,3 @@ static Genesys_Command_Set gl124_cmd_set = { gl124_calculate_current_setup, gl124_boot }; - -void sanei_gl124_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl124_cmd_set; -} diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 611d43a03..d41ca05a2 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -4093,7 +4093,7 @@ static void gl646_search_strip(Genesys_Device* dev, const Genesys_Sensor& sensor } /** the gl646 command set */ -static Genesys_Command_Set gl646_cmd_set = { +Genesys_Command_Set gl646_cmd_set = { "gl646-generic", /* the name of this set */ gl646_needs_home_before_init_regs_for_scan, @@ -4148,8 +4148,3 @@ static Genesys_Command_Set gl646_cmd_set = { NULL, NULL }; - -void sanei_gl646_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl646_cmd_set; -} diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index 0b6a5bf5e..9ae095120 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -4658,7 +4658,7 @@ static void gl841_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s /** the gl841 command set */ -static Genesys_Command_Set gl841_cmd_set = { +Genesys_Command_Set gl841_cmd_set = { "gl841-generic", /* the name of this set */ [](Genesys_Device* dev) -> bool { (void) dev; return true; }, @@ -4712,8 +4712,3 @@ static Genesys_Command_Set gl841_cmd_set = { gl841_calculate_current_setup, NULL }; - -void sanei_gl841_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl841_cmd_set; -} diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index ae9146ffe..56a8fbd0a 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -3917,7 +3917,7 @@ static void gl843_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& s /** the gl843 command set */ -static Genesys_Command_Set gl843_cmd_set = { +Genesys_Command_Set gl843_cmd_set = { "gl843-generic", /* the name of this set */ [](Genesys_Device* dev) -> bool { (void) dev; return true; }, @@ -3971,8 +3971,3 @@ static Genesys_Command_Set gl843_cmd_set = { gl843_calculate_current_setup, gl843_boot }; - -void sanei_gl843_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl843_cmd_set; -} diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index c85586eef..65eb63f58 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -2848,7 +2848,7 @@ static void gl846_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen /** the gl846 command set */ -static Genesys_Command_Set gl846_cmd_set = { +Genesys_Command_Set gl846_cmd_set = { "gl846-generic", /* the name of this set */ nullptr, @@ -2902,8 +2902,3 @@ static Genesys_Command_Set gl846_cmd_set = { gl846_calculate_current_setup, gl846_boot }; - -void sanei_gl846_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl846_cmd_set; -} diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index b009bed5e..5cef05a89 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -2958,7 +2958,7 @@ static void gl847_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen /** the gl847 command set */ -static Genesys_Command_Set gl847_cmd_set = { +Genesys_Command_Set gl847_cmd_set = { "gl847-generic", /* the name of this set */ nullptr, @@ -3012,8 +3012,3 @@ static Genesys_Command_Set gl847_cmd_set = { gl847_calculate_current_setup, gl847_boot }; - -void sanei_gl847_init_cmd_set(Genesys_Device* dev) -{ - dev->cmd_set = &gl847_cmd_set; -} diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 5890992b6..a407a0b3b 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -56,18 +56,25 @@ /** * setup the hardware dependent functions */ +extern Genesys_Command_Set gl124_cmd_set; +extern Genesys_Command_Set gl646_cmd_set; +extern Genesys_Command_Set gl841_cmd_set; +extern Genesys_Command_Set gl843_cmd_set; +extern Genesys_Command_Set gl846_cmd_set; +extern Genesys_Command_Set gl847_cmd_set; + void sanei_genesys_init_cmd_set(Genesys_Device* dev) { DBG_INIT (); DBG_HELPER(dbg); switch (dev->model->asic_type) { - case GENESYS_GL646: sanei_gl646_init_cmd_set(dev); break; - case GENESYS_GL841: sanei_gl841_init_cmd_set(dev); break; - case GENESYS_GL843: sanei_gl843_init_cmd_set(dev); break; + case GENESYS_GL646: dev->cmd_set = &gl646_cmd_set; break; + case GENESYS_GL841: dev->cmd_set = &gl841_cmd_set; break; + case GENESYS_GL843: dev->cmd_set = &gl843_cmd_set; break; case GENESYS_GL845: // since only a few reg bits differs we handle both together - case GENESYS_GL846: sanei_gl846_init_cmd_set(dev); break; - case GENESYS_GL847: sanei_gl847_init_cmd_set(dev); break; - case GENESYS_GL124: sanei_gl124_init_cmd_set(dev); break; + case GENESYS_GL846: dev->cmd_set = &gl846_cmd_set; break; + case GENESYS_GL847: dev->cmd_set = &gl847_cmd_set; break; + case GENESYS_GL124: dev->cmd_set = &gl124_cmd_set; break; default: throw SaneException(SANE_STATUS_INVAL, "unknown ASIC type"); } } diff --git a/backend/genesys_low.h b/backend/genesys_low.h index 03eb40e57..cf62fbd26 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -681,12 +681,6 @@ extern void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev, /*---------------------------------------------------------------------------*/ /* ASIC specific functions declarations */ /*---------------------------------------------------------------------------*/ -extern void sanei_gl646_init_cmd_set(Genesys_Device* dev); -extern void sanei_gl841_init_cmd_set(Genesys_Device* dev); -extern void sanei_gl843_init_cmd_set(Genesys_Device* dev); -extern void sanei_gl846_init_cmd_set(Genesys_Device* dev); -extern void sanei_gl847_init_cmd_set(Genesys_Device* dev); -extern void sanei_gl124_init_cmd_set(Genesys_Device* dev); // same as usleep, except that it does nothing if testing mode is enabled extern void sanei_genesys_usleep(unsigned int useconds);