diff --git a/backend/genesys/fwd.h b/backend/genesys/fwd.h index 229345778..80bb452c0 100644 --- a/backend/genesys/fwd.h +++ b/backend/genesys/fwd.h @@ -113,6 +113,7 @@ class ScannerInterfaceUsb; class TestScannerInterface; // sensor.h +class ScanMethodFilter; class ResolutionFilter; struct GenesysFrontendLayout; struct Genesys_Frontend; diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index d9d84b090..43ee5484f 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -856,7 +856,7 @@ void CommandSetGl124::init_regs_for_scan_session(Genesys_Device* dev, const Gene } else { exposure_time = sensor.exposure_lperiod; } - const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time); + const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time, session); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); DBG(DBG_info, "%s : scan_step_type=%d\n", __func__, static_cast(motor_profile.step_type)); diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 73f7b31fa..b6bf2d548 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -1179,7 +1179,7 @@ void CommandSetGl843::init_regs_for_scan_session(Genesys_Device* dev, const Gene if (exposure < 0) { throw std::runtime_error("Exposure not defined in sensor definition"); } - const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure); + const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure, session); DBG(DBG_info, "%s : exposure=%d pixels\n", __func__, exposure); DBG(DBG_info, "%s : scan_step_type=%d\n", __func__, diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index 0db91b13f..9f87b1a5b 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -705,7 +705,7 @@ void CommandSetGl846::init_regs_for_scan_session(Genesys_Device* dev, const Gene slope_dpi = slope_dpi * (1 + dummy); exposure_time = sensor.exposure_lperiod; - const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time); + const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time, session); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); DBG(DBG_info, "%s : scan_step_type=%d\n", __func__, diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 0544b1eff..76b0b22fc 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -712,7 +712,7 @@ void CommandSetGl847::init_regs_for_scan_session(Genesys_Device* dev, const Gene slope_dpi = slope_dpi * (1 + dummy); exposure_time = sensor.exposure_lperiod; - const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time); + const auto& motor_profile = get_motor_profile_by_exposure(dev->motor, exposure_time, session); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); DBG(DBG_info, "%s : scan_step_type=%d\n", __func__, diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index df6896844..76067e582 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -1729,13 +1729,21 @@ void sanei_genesys_wait_for_home(Genesys_Device* dev) * @param exposure exposure time * @return a pointer to a MotorProfile struct */ -const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure) +const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure, + const ScanSession& session) { int best_i = -1; for (unsigned i = 0; i < motor.profiles.size(); ++i) { const auto& profile = motor.profiles[i]; + if (!profile.resolutions.matches(session.params.yres)) { + continue; + } + if (!profile.scan_methods.matches(session.params.scan_method)) { + continue; + } + if (profile.max_exposure == exposure) { return profile; } diff --git a/backend/genesys/low.h b/backend/genesys/low.h index 5c0edcb0e..e7992d234 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -388,7 +388,8 @@ void scanner_stop_action_no_move(Genesys_Device& dev, Genesys_Register_Set& regs bool scanner_is_motor_stopped(Genesys_Device& dev); -const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure); +const MotorProfile& get_motor_profile_by_exposure(const Genesys_Motor& motor, unsigned exposure, + const ScanSession& session); MotorSlopeTable sanei_genesys_slope_table(AsicType asic_type, int dpi, int exposure, int base_dpi, unsigned step_multiplier, diff --git a/backend/genesys/motor.cpp b/backend/genesys/motor.cpp index d4f2ba7c9..44f7aa2da 100644 --- a/backend/genesys/motor.cpp +++ b/backend/genesys/motor.cpp @@ -168,13 +168,11 @@ std::ostream& operator<<(std::ostream& out, const MotorProfile& profile) { out << "MotorProfile{\n" << " max_exposure: " << profile.max_exposure << '\n' - << " step_type: " << profile.step_type << '\n'; - - if (profile.motor_vref != -1) { - out << " motor_vref: " << profile.motor_vref << '\n'; - } - - out << " slope: " << format_indent_braced_list(4, profile.slope) << '\n' + << " step_type: " << profile.step_type << '\n' + << " motor_vref: " << profile.motor_vref << '\n' + << " resolutions: " << format_indent_braced_list(4, profile.resolutions) << '\n' + << " scan_methods: " << format_indent_braced_list(4, profile.scan_methods) << '\n' + << " slope: " << format_indent_braced_list(4, profile.slope) << '\n' << '}'; return out; } diff --git a/backend/genesys/motor.h b/backend/genesys/motor.h index ed0aa1f7b..6c0ecf435 100644 --- a/backend/genesys/motor.h +++ b/backend/genesys/motor.h @@ -48,6 +48,7 @@ #include #include #include "enums.h" +#include "sensor.h" namespace genesys { @@ -148,6 +149,12 @@ struct MotorProfile MotorSlope slope; StepType step_type = StepType::FULL; int motor_vref = -1; + + // the resolutions this profile is good for + ResolutionFilter resolutions = ResolutionFilter::ANY; + // the scan method this profile is good for. If the list is empty, good for any method. + ScanMethodFilter scan_methods = ScanMethodFilter::ANY; + unsigned max_exposure = 0; // 0 - any exposure }; diff --git a/backend/genesys/sensor.cpp b/backend/genesys/sensor.cpp index e54af654d..b6fec0117 100644 --- a/backend/genesys/sensor.cpp +++ b/backend/genesys/sensor.cpp @@ -122,6 +122,16 @@ std::ostream& operator<<(std::ostream& out, const ResolutionFilter& resolutions) return out; } +std::ostream& operator<<(std::ostream& out, const ScanMethodFilter& methods) +{ + if (methods.matches_any()) { + out << "ANY"; + return out; + } + out << format_vector_unsigned(4, methods.methods()); + return out; +} + std::ostream& operator<<(std::ostream& out, const Genesys_Sensor& sensor) { out << "Genesys_Sensor{\n" diff --git a/backend/genesys/sensor.h b/backend/genesys/sensor.h index e70728e66..0906c3a3c 100644 --- a/backend/genesys/sensor.h +++ b/backend/genesys/sensor.h @@ -290,6 +290,46 @@ void serialize(Stream& str, ResolutionFilter& x) } +class ScanMethodFilter +{ +public: + struct Any {}; + static constexpr Any ANY{}; + + ScanMethodFilter() : matches_any_{false} {} + ScanMethodFilter(Any) : matches_any_{true} {} + ScanMethodFilter(std::initializer_list methods) : + matches_any_{false}, + methods_{methods} + {} + + bool matches(ScanMethod method) const + { + if (matches_any_) + return true; + auto it = std::find(methods_.begin(), methods_.end(), method); + return it != methods_.end(); + } + + bool operator==(const ScanMethodFilter& other) const + { + return matches_any_ == other.matches_any_ && methods_ == other.methods_; + } + + bool matches_any() const { return matches_any_; } + const std::vector& methods() const { return methods_; } + +private: + bool matches_any_ = false; + std::vector methods_; + + template + friend void serialize(Stream& str, ResolutionFilter& x); +}; + +std::ostream& operator<<(std::ostream& out, const ScanMethodFilter& methods); + + struct Genesys_Sensor { Genesys_Sensor() = default;