From 8aee1f0982dbca641b5553766d692c0626b3d8f8 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:19:18 +0200 Subject: [PATCH 1/4] genesys: Expose slow_back_home_ta() to the cmd set --- backend/genesys/command_set.h | 2 ++ backend/genesys/genesys.cpp | 2 +- backend/genesys/gl124.cpp | 6 ++++++ backend/genesys/gl124.h | 1 + backend/genesys/gl646.cpp | 6 ++++++ backend/genesys/gl646.h | 1 + backend/genesys/gl841.cpp | 6 ++++++ backend/genesys/gl841.h | 1 + backend/genesys/gl843.cpp | 4 +++- backend/genesys/gl843.h | 1 + backend/genesys/gl846.cpp | 6 ++++++ backend/genesys/gl846.h | 1 + backend/genesys/gl847.cpp | 6 ++++++ backend/genesys/gl847.h | 1 + 14 files changed, 42 insertions(+), 2 deletions(-) diff --git a/backend/genesys/command_set.h b/backend/genesys/command_set.h index 89f7e7160..767e7ad55 100644 --- a/backend/genesys/command_set.h +++ b/backend/genesys/command_set.h @@ -108,6 +108,8 @@ public: virtual void wait_for_motor_stop(Genesys_Device* dev) const = 0; virtual void slow_back_home(Genesys_Device* dev, bool wait_until_home) const = 0; + virtual void slow_back_home_ta(Genesys_Device& dev) const = 0; + virtual void rewind(Genesys_Device* dev) const = 0; virtual bool has_rewind() const { return true; } diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index 09dc84e70..87d99c83f 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -960,7 +960,7 @@ void scanner_slow_back_home(Genesys_Device& dev, bool wait_until_home) } if (dev.needs_home_ta) { - gl843::gl843_park_xpa_lamp(&dev); + dev.cmd_set->slow_back_home_ta(dev); } if (dev.cmd_set->needs_update_home_sensor_gpio()) { diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 4a81dd213..b32bcb7d4 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -1181,6 +1181,12 @@ void CommandSetGl124::slow_back_home(Genesys_Device* dev, bool wait_until_home) scanner_slow_back_home(*dev, wait_until_home); } +void CommandSetGl124::slow_back_home_ta(Genesys_Device& dev) const +{ + (void) dev; + throw SaneException("not implemented"); +} + /** @brief moves the slider to steps at motor base dpi * @param dev device to work on * @param steps number of steps to move diff --git a/backend/genesys/gl124.h b/backend/genesys/gl124.h index a734e4d42..dcd7a11f4 100644 --- a/backend/genesys/gl124.h +++ b/backend/genesys/gl124.h @@ -165,6 +165,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; void update_hardware_sensors(struct Genesys_Scanner* s) const override; diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index eb583206f..eefc17380 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -1579,6 +1579,12 @@ void CommandSetGl646::slow_back_home(Genesys_Device* dev, bool wait_until_home) DBG(DBG_info, "%s: scanhead is still moving\n", __func__); } +void CommandSetGl646::slow_back_home_ta(Genesys_Device& dev) const +{ + (void) dev; + throw SaneException("not implemented"); +} + /** * Automatically set top-left edge of the scan area by scanning an * area at 300 dpi from very top of scanner diff --git a/backend/genesys/gl646.h b/backend/genesys/gl646.h index 7e93bbb06..e0f289886 100644 --- a/backend/genesys/gl646.h +++ b/backend/genesys/gl646.h @@ -282,6 +282,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; bool has_rewind() const override { return false; } diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index 152cbb49b..fabdb98ca 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -2325,6 +2325,12 @@ void CommandSetGl841::slow_back_home(Genesys_Device* dev, bool wait_until_home) DBG(DBG_info, "%s: scanhead is still moving\n", __func__); } +void CommandSetGl841::slow_back_home_ta(Genesys_Device& dev) const +{ + (void) dev; + throw SaneException("not implemented"); +} + // Automatically set top-left edge of the scan area by scanning a 200x200 pixels area at 600 dpi // from very top of scanner void CommandSetGl841::search_start_position(Genesys_Device* dev) const diff --git a/backend/genesys/gl841.h b/backend/genesys/gl841.h index dd3b1e0bd..18d5c18cd 100644 --- a/backend/genesys/gl841.h +++ b/backend/genesys/gl841.h @@ -99,6 +99,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; bool has_rewind() const override { return false; } diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 59e1a34f1..0c3f81aeb 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -1727,8 +1727,10 @@ void CommandSetGl843::end_scan(Genesys_Device* dev, Genesys_Register_Set* reg, /** @brief park XPA lamp * park the XPA lamp if needed */ -void gl843_park_xpa_lamp(Genesys_Device* dev) +void CommandSetGl843::slow_back_home_ta(Genesys_Device& devr) const { + Genesys_Device* dev = &devr; + DBG_HELPER(dbg); Genesys_Register_Set local_reg; GenesysRegister *r; diff --git a/backend/genesys/gl843.h b/backend/genesys/gl843.h index 5912b50a9..93dc87798 100644 --- a/backend/genesys/gl843.h +++ b/backend/genesys/gl843.h @@ -99,6 +99,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; bool has_rewind() const override { return false; } diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index 42d7a2c54..ddc9e4de1 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -934,6 +934,12 @@ void CommandSetGl846::slow_back_home(Genesys_Device* dev, bool wait_until_home) scanner_slow_back_home(*dev, wait_until_home); } +void CommandSetGl846::slow_back_home_ta(Genesys_Device& dev) const +{ + (void) dev; + throw SaneException("not implemented"); +} + // Automatically set top-left edge of the scan area by scanning a 200x200 pixels area at 600 dpi // from very top of scanner void CommandSetGl846::search_start_position(Genesys_Device* dev) const diff --git a/backend/genesys/gl846.h b/backend/genesys/gl846.h index 3995b1071..fb9d25b23 100644 --- a/backend/genesys/gl846.h +++ b/backend/genesys/gl846.h @@ -184,6 +184,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; bool has_rewind() const override { return false; } diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 7e901ed40..60a9d5d23 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -980,6 +980,12 @@ void CommandSetGl847::slow_back_home(Genesys_Device* dev, bool wait_until_home) scanner_slow_back_home(*dev, wait_until_home); } +void CommandSetGl847::slow_back_home_ta(Genesys_Device& dev) const +{ + (void) dev; + throw SaneException("not implemented"); +} + // Automatically set top-left edge of the scan area by scanning a 200x200 pixels area at 600 dpi // from very top of scanner void CommandSetGl847::search_start_position(Genesys_Device* dev) const diff --git a/backend/genesys/gl847.h b/backend/genesys/gl847.h index 6e1db2178..073d03321 100644 --- a/backend/genesys/gl847.h +++ b/backend/genesys/gl847.h @@ -168,6 +168,7 @@ public: void wait_for_motor_stop(Genesys_Device* dev) const override; void slow_back_home(Genesys_Device* dev, bool wait_until_home) const override; + void slow_back_home_ta(Genesys_Device& dev) const override; void rewind(Genesys_Device* dev) const override; bool has_rewind() const override { return false; } From 4743a0235359ef9f5749aa9a38850b199a437368 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:19:19 +0200 Subject: [PATCH 2/4] genesys: Remove duplicate operation on a register init_regs_for_scan_session() already sets the value of the register to what we expect. --- backend/genesys/genesys.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index 87d99c83f..3b4fd4d4d 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -1024,11 +1024,6 @@ void scanner_slow_back_home(Genesys_Device& dev, bool wait_until_home) scanner_clear_scan_and_feed_counts(dev); - // FIXME: why we do differently than other asics here? - if (dev.model->asic_type == AsicType::GL843) { - local_reg.find_reg(gl843::REG_0x01).value &= ~gl843::REG_0x01_SCAN; - } - dev.interface->write_registers(local_reg); if (dev.model->asic_type == AsicType::GL124) { From 66a95875d402ef27ef49771f663f06a5a8cc4d60 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:19:20 +0200 Subject: [PATCH 3/4] genesys: Remove duplicate operation a register The same value is set just several lines above. --- backend/genesys/gl124.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index b32bcb7d4..65d2d3767 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -748,7 +748,6 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens } else { r->value |= REG_0x01_DVDSET; } - r->value &= ~REG_0x01_SCAN; r = sanei_genesys_get_address(reg, REG_0x03); if ((dev->model->sensor_id != SensorId::CIS_CANON_LIDE_120) && (session.params.xres>=600)) { From f98bec2afb2a093cfbc5b86cabcea478e907cb3e Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:19:21 +0200 Subject: [PATCH 4/4] genesys: Use full scan initialization in slow_back_home_ta() --- backend/genesys/gl843.cpp | 84 ++++++++++++++++++++------------------- backend/genesys/low.h | 2 + 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 0c3f81aeb..c4bf9b918 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -1727,63 +1727,67 @@ void CommandSetGl843::end_scan(Genesys_Device* dev, Genesys_Register_Set* reg, /** @brief park XPA lamp * park the XPA lamp if needed */ -void CommandSetGl843::slow_back_home_ta(Genesys_Device& devr) const +void CommandSetGl843::slow_back_home_ta(Genesys_Device& dev) const { - Genesys_Device* dev = &devr; - DBG_HELPER(dbg); - Genesys_Register_Set local_reg; - GenesysRegister *r; - int loop = 0; + Genesys_Register_Set local_reg = dev.reg; - /* copy scan settings */ - local_reg = dev->reg; + auto scan_method = ScanMethod::TRANSPARENCY; + unsigned resolution = dev.model->get_resolution_settings(scan_method).get_min_resolution_y(); - /* set a huge feedl and reverse direction */ - local_reg.set24(REG_FEEDL, 0xbdcd); + const auto& sensor = sanei_genesys_find_sensor(&dev, resolution, 1, scan_method); - // clear scan and feed count - dev->interface->write_register(REG_0x0D, REG_0x0D_CLRLNCNT | REG_0x0D_CLRMCNT); + ScanSession session; + session.params.xres = resolution; + session.params.yres = resolution; + session.params.startx = 100; + session.params.starty = 30000; + session.params.pixels = 100; + session.params.lines = 100; + session.params.depth = 8; + session.params.channels = 1; + session.params.scan_method = scan_method; + session.params.scan_mode = ScanColorMode::GRAY; + session.params.color_filter = ColorFilter::RED; + session.params.flags = ScanFlag::DISABLE_SHADING | + ScanFlag::DISABLE_GAMMA | + ScanFlag::IGNORE_LINE_DISTANCE | + ScanFlag::REVERSE; - /* set up for reverse and no scan */ - r = sanei_genesys_get_address (&local_reg, REG_0x02); - r->value |= REG_0x02_MTRREV; - r = sanei_genesys_get_address (&local_reg, REG_0x01); - r->value &= ~REG_0x01_SCAN; + compute_session(&dev, session, sensor); - // write to scanner and start action - dev->interface->write_registers(local_reg); - gl843_set_xpa_motor_power(dev, true); + dev.cmd_set->init_regs_for_scan_session(&dev, sensor, &local_reg, session); + + scanner_clear_scan_and_feed_counts(dev); + + dev.interface->write_registers(local_reg); + gl843_set_xpa_motor_power(&dev, true); try { - scanner_start_action(*dev, true); + scanner_start_action(dev, true); } catch (...) { - catch_all_exceptions(__func__, [&]() { gl843_stop_action(dev); }); + catch_all_exceptions(__func__, [&]() { scanner_stop_action(dev); }); // restore original registers - catch_all_exceptions(__func__, [&]() - { - dev->interface->write_registers(dev->reg); - }); + catch_all_exceptions(__func__, [&]() { dev.interface->write_registers(dev.reg); }); throw; } - while (loop < 600) /* do not wait longer then 60 seconds */ - { - auto status = scanner_read_status(*dev); + for (unsigned i = 0; i < 300; ++i) { + + auto status = scanner_read_status(dev); + if (status.is_at_home) { - DBG(DBG_info, "%s: reached home position\n", __func__); - DBG(DBG_proc, "%s: finished\n", __func__); - - gl843_set_xpa_motor_power(dev, false); - dev->needs_home_ta = false; - + dbg.log(DBG_info, "TA reached home position"); + scanner_stop_action(dev); + gl843_set_xpa_motor_power(&dev, false); + dev.needs_home_ta = false; return; - } - dev->interface->sleep_ms(100); - ++loop; + } + + dev.interface->sleep_ms(100); } - /* we are not parked here.... should we fail ? */ - DBG(DBG_info, "%s: XPA lamp is not parked\n", __func__); + // we are not parked here.... should we fail ? + dbg.log(DBG_info, "XPA lamp is not parked"); } /** @brief Moves the slider to the home (top) position slowly diff --git a/backend/genesys/low.h b/backend/genesys/low.h index f1372d3ad..c88610836 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -353,6 +353,7 @@ extern void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Se int width, int height); void scanner_slow_back_home(Genesys_Device& dev, bool wait_until_home); +void scanner_clear_scan_and_feed_counts(Genesys_Device& dev); extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length); @@ -411,6 +412,7 @@ extern void sanei_genesys_wait_for_home(Genesys_Device* dev); extern void sanei_genesys_asic_init(Genesys_Device* dev, bool cold); void scanner_start_action(Genesys_Device& dev, bool start_motor); +void scanner_stop_action(Genesys_Device& dev); const Motor_Profile& sanei_genesys_get_motor_profile(const std::vector& motors, MotorId motor_id, int exposure);