Merge branch 'genesys-select-by-bcddevice' into 'master'

genesys: Implement device filtering by bcdDevice value

See merge request sane-project/backends!383
merge-requests/213/head^2
Povilas Kanapickas 2020-03-28 21:31:29 +00:00
commit 47689131a4
13 zmienionych plików z 109 dodań i 36 usunięć

Wyświetl plik

@ -283,7 +283,7 @@ struct Genesys_Device
// acquiring the positions of the black and white strips and the actual scan area
bool ignore_offsets = false;
Genesys_Model *model = nullptr;
const Genesys_Model* model = nullptr;
// pointers to low level functions
std::unique_ptr<CommandSet> cmd_set;

Wyświetl plik

@ -86,7 +86,7 @@ struct Pixel;
struct RawPixel;
// low.h
struct Genesys_USB_Device_Entry;
struct UsbDeviceEntry;
// motor.h
struct Genesys_Motor;

Wyświetl plik

@ -4231,7 +4231,7 @@ static void init_options(Genesys_Scanner* s)
{
DBG_HELPER(dbg);
SANE_Int option;
Genesys_Model *model = s->dev->model;
const Genesys_Model* model = s->dev->model;
memset (s->opt, 0, sizeof (s->opt));
@ -4794,12 +4794,12 @@ check_present (SANE_String_Const devname) noexcept
}
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)
{
Genesys_USB_Device_Entry* found_usb_dev = nullptr;
UsbDeviceEntry* found_usb_dev = nullptr;
for (auto& usb_dev : *s_usb_devices) {
if (usb_dev.vendor == vendor_id &&
usb_dev.product == product_id)
if (usb_dev.matches(vendor_id, product_id, bcd_device))
{
found_usb_dev = &usb_dev;
break;
@ -4815,9 +4815,9 @@ static Genesys_Device* attach_usb_device(const char* devname,
Genesys_Device* dev = &s_devices->back();
dev->file_name = devname;
dev->model = &found_usb_dev->model;
dev->vendorId = found_usb_dev->vendor;
dev->productId = found_usb_dev->product;
dev->model = &found_usb_dev->model();
dev->vendorId = found_usb_dev->vendor_id();
dev->productId = found_usb_dev->product_id();
dev->usb_mode = 0; // i.e. unset
dev->already_initialized = false;
return dev;
@ -4847,6 +4847,10 @@ static Genesys_Device* attach_device_by_name(SANE_String_Const devname, bool may
int 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();
/* 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,
dev->model->model, dev->file_name.c_str());
@ -4899,7 +4903,8 @@ static void probe_genesys_devices()
DBG_HELPER(dbg);
if (is_testing_mode()) {
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;
}

Wyświetl plik

@ -168,18 +168,48 @@
namespace genesys {
struct Genesys_USB_Device_Entry {
class UsbDeviceEntry {
public:
static constexpr std::uint16_t BCD_DEVICE_NOT_SET = 0xffff;
Genesys_USB_Device_Entry(unsigned v, unsigned p, const Genesys_Model& m) :
vendor(v), product(p), model(m)
UsbDeviceEntry(std::uint16_t vendor_id, std::uint16_t product_id,
const Genesys_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 product_id() const { return product_; }
std::uint16_t bcd_device() const { return bcd_device_; }
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:
// USB vendor identifier
std::uint16_t vendor;
std::uint16_t vendor_;
// USB product identifier
std::uint16_t product;
std::uint16_t product_;
// USB bcdProduct identifier
std::uint16_t bcd_device_;
// Scanner model information
Genesys_Model model;
Genesys_Model model_;
};
/*--------------------------------------------------------------------------*/
@ -467,7 +497,7 @@ extern StaticInit<std::vector<Genesys_Frontend>> s_frontends;
extern StaticInit<std::vector<Genesys_Gpo>> s_gpo;
extern StaticInit<std::vector<MemoryLayout>> s_memory_layout;
extern StaticInit<std::vector<Genesys_Motor>> s_motors;
extern StaticInit<std::vector<Genesys_USB_Device_Entry>> s_usb_devices;
extern StaticInit<std::vector<UsbDeviceEntry>> s_usb_devices;
void genesys_init_sensor_tables();
void genesys_init_frontend_tables();

Wyświetl plik

@ -58,7 +58,7 @@
namespace genesys {
StaticInit<std::vector<Genesys_USB_Device_Entry>> s_usb_devices;
StaticInit<std::vector<UsbDeviceEntry>> s_usb_devices;
void genesys_init_usb_device_tables()
{
@ -2760,7 +2760,7 @@ void genesys_init_usb_device_tables()
void verify_usb_device_tables()
{
for (const auto& device : *s_usb_devices) {
const auto& model = device.model;
const auto& model = device.model();
if (model.x_size_calib_mm == 0.0f) {
throw SaneException("Calibration width can't be zero");

Wyświetl plik

@ -3651,7 +3651,7 @@ void verify_sensor_tables()
{
std::map<SensorId, AsicType> sensor_to_asic;
for (const auto& device : *s_usb_devices) {
sensor_to_asic[device.model.sensor_id] = device.model.asic_type;
sensor_to_asic[device.model().sensor_id] = device.model().asic_type;
}
for (const auto& sensor : *s_sensors) {
if (sensor_to_asic.count(sensor.sensor_id) == 0) {

Wyświetl plik

@ -52,6 +52,7 @@ namespace {
bool s_testing_mode = false;
std::uint16_t s_vendor_id = 0;
std::uint16_t s_product_id = 0;
std::uint16_t s_bcd_device = 0;
TestCheckpointCallback s_checkpoint_callback;
} // namespace
@ -66,15 +67,17 @@ void disable_testing_mode()
s_testing_mode = false;
s_vendor_id = 0;
s_product_id = 0;
s_bcd_device = 0;
}
void enable_testing_mode(std::uint16_t vendor_id, std::uint16_t product_id,
std::uint16_t bcd_device,
TestCheckpointCallback checkpoint_callback)
{
s_testing_mode = true;
s_vendor_id = vendor_id;
s_product_id = product_id;
s_bcd_device = bcd_device;
s_checkpoint_callback = checkpoint_callback;
}
@ -88,6 +91,11 @@ std::uint16_t get_testing_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 name;

Wyświetl plik

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

Wyświetl plik

@ -48,9 +48,11 @@
namespace genesys {
TestUsbDevice::TestUsbDevice(std::uint16_t vendor, std::uint16_t product) :
TestUsbDevice::TestUsbDevice(std::uint16_t vendor, std::uint16_t product,
std::uint16_t bcd_device) :
vendor_{vendor},
product_{product}
product_{product},
bcd_device_{bcd_device}
{
}
@ -102,6 +104,13 @@ void TestUsbDevice::get_vendor_product(int& vendor, int& product)
product = product_;
}
std::uint16_t TestUsbDevice::get_bcd_device()
{
DBG_HELPER(dbg);
assert_is_open();
return bcd_device_;
}
void TestUsbDevice::control_msg(int rtype, int reg, int value, int index, int length,
std::uint8_t* data)
{

Wyświetl plik

@ -50,7 +50,7 @@ namespace genesys {
class TestUsbDevice : public IUsbDevice {
public:
TestUsbDevice(std::uint16_t vendor, std::uint16_t product);
TestUsbDevice(std::uint16_t vendor, std::uint16_t product, std::uint16_t bcd_device);
TestUsbDevice() = default;
~TestUsbDevice() override;
@ -66,6 +66,7 @@ public:
void close() override;
void get_vendor_product(int& vendor, int& product) override;
std::uint16_t get_bcd_device() override;
void control_msg(int rtype, int reg, int value, int index, int length,
std::uint8_t* data) override;
@ -78,6 +79,7 @@ private:
bool is_open_ = false;
std::uint16_t vendor_ = 0;
std::uint16_t product_ = 0;
std::uint16_t bcd_device_ = 0;
};
} // namespace genesys

Wyświetl plik

@ -108,6 +108,15 @@ void UsbDevice::get_vendor_product(int& vendor, int& product)
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
}
std::uint16_t UsbDevice::get_bcd_device()
{
DBG_HELPER(dbg);
assert_is_open();
sanei_usb_dev_descriptor desc;
TIE(sanei_usb_get_descriptor(device_num_, &desc));
return desc.bcd_dev;
}
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length,
std::uint8_t* data)
{

Wyświetl plik

@ -72,6 +72,7 @@ public:
virtual void close() = 0;
virtual void get_vendor_product(int& vendor, int& product) = 0;
virtual std::uint16_t get_bcd_device() = 0;
virtual void control_msg(int rtype, int reg, int value, int index, int length,
std::uint8_t* data) = 0;
@ -97,6 +98,7 @@ public:
void close() override;
void get_vendor_product(int& vendor, int& product) override;
std::uint16_t get_bcd_device() override;
void control_msg(int rtype, int reg, int value, int index, int length,
std::uint8_t* data) override;

Wyświetl plik

@ -47,6 +47,7 @@ struct TestConfig
{
std::uint16_t vendor_id = 0;
std::uint16_t product_id = 0;
std::uint16_t bcd_device = 0;
std::string model_name;
genesys::ScanMethod method = genesys::ScanMethod::FLATBED;
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);
};
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;
@ -397,30 +399,34 @@ std::vector<TestConfig> get_all_test_configs()
std::unordered_set<std::string> model_names;
for (const auto& usb_dev : *genesys::s_usb_devices) {
if (genesys::has_flag(usb_dev.model.flags, genesys::ModelFlag::UNTESTED)) {
const auto& model = usb_dev.model();
if (genesys::has_flag(model.flags, genesys::ModelFlag::UNTESTED)) {
continue;
}
if (model_names.find(usb_dev.model.name) != model_names.end()) {
if (model_names.find(model.name) != model_names.end()) {
continue;
}
model_names.insert(usb_dev.model.name);
model_names.insert(model.name);
for (auto scan_mode : { genesys::ScanColorMode::LINEART,
genesys::ScanColorMode::GRAY,
genesys::ScanColorMode::COLOR_SINGLE_PASS }) {
auto depth_values = usb_dev.model.bpp_gray_values;
auto depth_values = model.bpp_gray_values;
if (scan_mode == genesys::ScanColorMode::COLOR_SINGLE_PASS) {
depth_values = usb_dev.model.bpp_color_values;
depth_values = model.bpp_color_values;
}
for (unsigned depth : depth_values) {
for (auto method_resolutions : usb_dev.model.resolutions) {
for (auto method_resolutions : model.resolutions) {
for (auto method : method_resolutions.methods) {
for (unsigned resolution : method_resolutions.get_resolutions()) {
TestConfig config;
config.vendor_id = usb_dev.vendor;
config.product_id = usb_dev.product;
config.model_name = usb_dev.model.name;
config.vendor_id = usb_dev.vendor_id();
config.product_id = usb_dev.product_id();
config.bcd_device = usb_dev.bcd_device();
config.model_name = model.name;
config.method = method;
config.depth = depth;
config.resolution = resolution;