genesys: Add support for matching devices by bcdDevice

merge-requests/213/head^2
Povilas Kanapickas 2020-03-28 23:15:48 +02:00
rodzic 0bdce7928f
commit 9698bfece7
5 zmienionych plików z 50 dodań i 9 usunięć

Wyświetl plik

@ -4794,12 +4794,12 @@ check_present (SANE_String_Const devname) noexcept
} }
static Genesys_Device* attach_usb_device(const char* devname, static Genesys_Device* attach_usb_device(const char* devname,
std::uint16_t vendor_id, std::uint16_t product_id) std::uint16_t vendor_id, std::uint16_t product_id,
std::uint16_t bcd_device)
{ {
UsbDeviceEntry* found_usb_dev = nullptr; UsbDeviceEntry* found_usb_dev = nullptr;
for (auto& usb_dev : *s_usb_devices) { for (auto& usb_dev : *s_usb_devices) {
if (usb_dev.vendor_id() == vendor_id && if (usb_dev.matches(vendor_id, product_id, bcd_device))
usb_dev.product_id() == product_id)
{ {
found_usb_dev = &usb_dev; found_usb_dev = &usb_dev;
break; break;
@ -4847,6 +4847,10 @@ static Genesys_Device* attach_device_by_name(SANE_String_Const devname, bool may
int vendor, product; int vendor, product;
usb_dev.get_vendor_product(vendor, product); usb_dev.get_vendor_product(vendor, product);
// FIXME: enable when get_bcd_device call can be recorded and replayed
// auto bcd_device = usb_dev.get_bcd_device();
std::uint16_t bcd_device = 0xffff;
usb_dev.close(); usb_dev.close();
/* KV-SS080 is an auxiliary device which requires a master device to be here */ /* KV-SS080 is an auxiliary device which requires a master device to be here */
@ -4861,7 +4865,7 @@ static Genesys_Device* attach_device_by_name(SANE_String_Const devname, bool may
} }
} }
Genesys_Device* dev = attach_usb_device(devname, vendor, product); Genesys_Device* dev = attach_usb_device(devname, vendor, product, bcd_device);
DBG(DBG_info, "%s: found %s flatbed scanner %s at %s\n", __func__, dev->model->vendor, DBG(DBG_info, "%s: found %s flatbed scanner %s at %s\n", __func__, dev->model->vendor,
dev->model->model, dev->file_name.c_str()); dev->model->model, dev->file_name.c_str());
@ -4899,7 +4903,8 @@ static void probe_genesys_devices()
DBG_HELPER(dbg); DBG_HELPER(dbg);
if (is_testing_mode()) { if (is_testing_mode()) {
attach_usb_device(get_testing_device_name().c_str(), attach_usb_device(get_testing_device_name().c_str(),
get_testing_vendor_id(), get_testing_product_id()); get_testing_vendor_id(), get_testing_product_id(),
get_testing_bcd_device());
return; return;
} }

Wyświetl plik

@ -170,21 +170,44 @@ namespace genesys {
class UsbDeviceEntry { class UsbDeviceEntry {
public: public:
static constexpr std::uint16_t BCD_DEVICE_NOT_SET = 0xffff;
UsbDeviceEntry(std::uint16_t vendor_id, std::uint16_t product_id, UsbDeviceEntry(std::uint16_t vendor_id, std::uint16_t product_id,
const Genesys_Model& model) : const Genesys_Model& model) :
vendor_{vendor_id}, product_{product_id}, model_{model} vendor_{vendor_id}, product_{product_id},
bcd_device_{BCD_DEVICE_NOT_SET}, model_{model}
{}
UsbDeviceEntry(std::uint16_t vendor_id, std::uint16_t product_id, std::uint16_t bcd_device,
const Genesys_Model& model) :
vendor_{vendor_id}, product_{product_id},
bcd_device_{bcd_device}, model_{model}
{} {}
std::uint16_t vendor_id() const { return vendor_; } std::uint16_t vendor_id() const { return vendor_; }
std::uint16_t product_id() const { return product_; } std::uint16_t product_id() const { return product_; }
std::uint16_t bcd_device() const { return bcd_device_; }
const Genesys_Model& model() const { return model_; } const Genesys_Model& model() const { return model_; }
bool matches(std::uint16_t vendor_id, std::uint16_t product_id, std::uint16_t bcd_device)
{
if (vendor_ != vendor_id)
return false;
if (product_ != product_id)
return false;
if (bcd_device_ != BCD_DEVICE_NOT_SET && bcd_device_ != bcd_device)
return false;
return true;
}
private: private:
// USB vendor identifier // USB vendor identifier
std::uint16_t vendor_; std::uint16_t vendor_;
// USB product identifier // USB product identifier
std::uint16_t product_; std::uint16_t product_;
// USB bcdProduct identifier
std::uint16_t bcd_device_;
// Scanner model information // Scanner model information
Genesys_Model model_; Genesys_Model model_;
}; };

Wyświetl plik

@ -52,6 +52,7 @@ namespace {
bool s_testing_mode = false; bool s_testing_mode = false;
std::uint16_t s_vendor_id = 0; std::uint16_t s_vendor_id = 0;
std::uint16_t s_product_id = 0; std::uint16_t s_product_id = 0;
std::uint16_t s_bcd_device = 0;
TestCheckpointCallback s_checkpoint_callback; TestCheckpointCallback s_checkpoint_callback;
} // namespace } // namespace
@ -66,15 +67,17 @@ void disable_testing_mode()
s_testing_mode = false; s_testing_mode = false;
s_vendor_id = 0; s_vendor_id = 0;
s_product_id = 0; s_product_id = 0;
s_bcd_device = 0;
} }
void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id, void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id,
std::uint16_t bcd_device,
TestCheckpointCallback checkpoint_callback) TestCheckpointCallback checkpoint_callback)
{ {
s_testing_mode = true; s_testing_mode = true;
s_vendor_id = vendor_id; s_vendor_id = vendor_id;
s_product_id = product_id; s_product_id = product_id;
s_bcd_device = bcd_device;
s_checkpoint_callback = checkpoint_callback; s_checkpoint_callback = checkpoint_callback;
} }
@ -88,6 +91,11 @@ std::uint16_t get_testing_product_id()
return s_product_id; return s_product_id;
} }
std::uint16_t get_testing_bcd_device()
{
return s_bcd_device;
}
std::string get_testing_device_name() std::string get_testing_device_name()
{ {
std::string name; std::string name;

Wyświetl plik

@ -58,9 +58,11 @@ using TestCheckpointCallback = std::function<void(const Genesys_Device&,
bool is_testing_mode(); bool is_testing_mode();
void disable_testing_mode(); void disable_testing_mode();
void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id, void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id,
std::uint16_t bcd_device,
TestCheckpointCallback checkpoint_callback); TestCheckpointCallback checkpoint_callback);
std::uint16_t get_testing_vendor_id(); std::uint16_t get_testing_vendor_id();
std::uint16_t get_testing_product_id(); std::uint16_t get_testing_product_id();
std::uint16_t get_testing_bcd_device();
std::string get_testing_device_name(); std::string get_testing_device_name();
TestCheckpointCallback get_testing_checkpoint_callback(); TestCheckpointCallback get_testing_checkpoint_callback();

Wyświetl plik

@ -47,6 +47,7 @@ struct TestConfig
{ {
std::uint16_t vendor_id = 0; std::uint16_t vendor_id = 0;
std::uint16_t product_id = 0; std::uint16_t product_id = 0;
std::uint16_t bcd_device = 0;
std::string model_name; std::string model_name;
genesys::ScanMethod method = genesys::ScanMethod::FLATBED; genesys::ScanMethod method = genesys::ScanMethod::FLATBED;
genesys::ScanColorMode color_mode = genesys::ScanColorMode::COLOR_SINGLE_PASS; genesys::ScanColorMode color_mode = genesys::ScanColorMode::COLOR_SINGLE_PASS;
@ -246,7 +247,8 @@ void run_single_test_scan(const TestConfig& config, std::stringstream& out)
build_checkpoint(dev, iface, checkpoint_name, out); build_checkpoint(dev, iface, checkpoint_name, out);
}; };
genesys::enable_testing_mode(config.vendor_id, config.product_id, build_checkpoint_wrapper); genesys::enable_testing_mode(config.vendor_id, config.product_id, config.bcd_device,
build_checkpoint_wrapper);
SANE_Handle handle; SANE_Handle handle;
@ -423,6 +425,7 @@ std::vector<TestConfig> get_all_test_configs()
TestConfig config; TestConfig config;
config.vendor_id = usb_dev.vendor_id(); config.vendor_id = usb_dev.vendor_id();
config.product_id = usb_dev.product_id(); config.product_id = usb_dev.product_id();
config.bcd_device = usb_dev.bcd_device();
config.model_name = model.name; config.model_name = model.name;
config.method = method; config.method = method;
config.depth = depth; config.depth = depth;