kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'genesys-fix-usb-id-init' into 'master'
genesys: Fix initialization of USB IDs See merge request sane-project/backends!393merge-requests/213/head^2
commit
14e9fb1877
|
@ -265,8 +265,8 @@ struct Genesys_Device
|
||||||
// frees commonly used data
|
// frees commonly used data
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
SANE_Word vendorId = 0; /**< USB vendor identifier */
|
std::uint16_t vendorId = 0; // USB vendor identifier
|
||||||
SANE_Word productId = 0; /**< USB product identifier */
|
std::uint16_t productId = 0; // USB product identifier
|
||||||
|
|
||||||
// USB mode:
|
// USB mode:
|
||||||
// 0: not set
|
// 0: not set
|
||||||
|
|
|
@ -4141,7 +4141,7 @@ static std::string calibration_filename(Genesys_Device *currdev)
|
||||||
/* count models of the same names if several scanners attached */
|
/* count models of the same names if several scanners attached */
|
||||||
if(s_devices->size() > 1) {
|
if(s_devices->size() > 1) {
|
||||||
for (const auto& dev : *s_devices) {
|
for (const auto& dev : *s_devices) {
|
||||||
if (dev.model->model_id == currdev->model->model_id) {
|
if (dev.vendorId == currdev->vendorId && dev.productId == currdev->productId) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4793,31 +4793,32 @@ check_present (SANE_String_Const devname) noexcept
|
||||||
return SANE_STATUS_GOOD;
|
return SANE_STATUS_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Genesys_Device* attach_usb_device(const char* devname,
|
const UsbDeviceEntry& get_matching_usb_dev(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)
|
std::uint16_t bcd_device)
|
||||||
{
|
{
|
||||||
UsbDeviceEntry* found_usb_dev = nullptr;
|
|
||||||
for (auto& usb_dev : *s_usb_devices) {
|
for (auto& usb_dev : *s_usb_devices) {
|
||||||
if (usb_dev.matches(vendor_id, product_id, bcd_device))
|
if (usb_dev.matches(vendor_id, product_id, bcd_device)) {
|
||||||
{
|
return usb_dev;
|
||||||
found_usb_dev = &usb_dev;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_usb_dev == nullptr) {
|
throw SaneException("vendor 0x%x product 0x%x (bcdDevice 0x%x) "
|
||||||
throw SaneException("vendor 0x%x product 0x%x is not supported by this backend",
|
"is not supported by this backend",
|
||||||
vendor_id, product_id);
|
vendor_id, product_id, bcd_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Genesys_Device* attach_usb_device(const char* devname,
|
||||||
|
std::uint16_t vendor_id, std::uint16_t product_id)
|
||||||
|
{
|
||||||
|
// verify that there's at least one entry for this vendor and product ids. We will check
|
||||||
|
// bcdDevice in open().
|
||||||
|
get_matching_usb_dev(vendor_id, product_id, UsbDeviceEntry::BCD_DEVICE_NOT_SET);
|
||||||
|
|
||||||
s_devices->emplace_back();
|
s_devices->emplace_back();
|
||||||
Genesys_Device* dev = &s_devices->back();
|
Genesys_Device* dev = &s_devices->back();
|
||||||
dev->file_name = devname;
|
dev->file_name = devname;
|
||||||
|
dev->vendorId = vendor_id;
|
||||||
dev->model = &found_usb_dev->model();
|
dev->productId = product_id;
|
||||||
dev->vendorId = found_usb_dev->vendor_id();
|
|
||||||
dev->productId = found_usb_dev->product_id();
|
|
||||||
dev->usb_mode = 0; // i.e. unset
|
dev->usb_mode = 0; // i.e. unset
|
||||||
dev->already_initialized = false;
|
dev->already_initialized = false;
|
||||||
return dev;
|
return dev;
|
||||||
|
@ -4845,28 +4846,25 @@ static Genesys_Device* attach_device_by_name(SANE_String_Const devname, bool may
|
||||||
usb_dev.open(devname);
|
usb_dev.open(devname);
|
||||||
DBG(DBG_info, "%s: device `%s' successfully opened\n", __func__, devname);
|
DBG(DBG_info, "%s: device `%s' successfully opened\n", __func__, devname);
|
||||||
|
|
||||||
int vendor, product;
|
auto vendor_id = usb_dev.get_vendor_id();
|
||||||
usb_dev.get_vendor_product(vendor, product);
|
auto product_id = usb_dev.get_product_id();
|
||||||
|
|
||||||
auto bcd_device = usb_dev.get_bcd_device();
|
|
||||||
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 */
|
||||||
if(vendor == 0x04da && product == 0x100f)
|
if (vendor_id == 0x04da && product_id == 0x100f) {
|
||||||
{
|
|
||||||
present = false;
|
present = false;
|
||||||
sanei_usb_find_devices (vendor, 0x1006, check_present);
|
sanei_usb_find_devices(vendor_id, 0x1006, check_present);
|
||||||
sanei_usb_find_devices (vendor, 0x1007, check_present);
|
sanei_usb_find_devices(vendor_id, 0x1007, check_present);
|
||||||
sanei_usb_find_devices (vendor, 0x1010, check_present);
|
sanei_usb_find_devices(vendor_id, 0x1010, check_present);
|
||||||
if (present == false) {
|
if (present == false) {
|
||||||
throw SaneException("master device not present");
|
throw SaneException("master device not present");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Genesys_Device* dev = attach_usb_device(devname, vendor, product, bcd_device);
|
Genesys_Device* dev = attach_usb_device(devname, vendor_id, product_id);
|
||||||
|
|
||||||
DBG(DBG_info, "%s: found %s flatbed scanner %s at %s\n", __func__, dev->model->vendor,
|
DBG(DBG_info, "%s: found %u flatbed scanner %u at %s\n", __func__, vendor_id, product_id,
|
||||||
dev->model->model, dev->file_name.c_str());
|
dev->file_name.c_str());
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
@ -4901,8 +4899,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5257,7 +5254,7 @@ static void sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
DBG(DBG_info, "%s: found `%s' in devlist\n", __func__, dev->model->name);
|
DBG(DBG_info, "%s: found `%s' in devlist\n", __func__, dev->file_name.c_str());
|
||||||
} else if (is_testing_mode()) {
|
} else if (is_testing_mode()) {
|
||||||
DBG(DBG_info, "%s: couldn't find `%s' in devlist, not attaching", __func__, devicename);
|
DBG(DBG_info, "%s: couldn't find `%s' in devlist, not attaching", __func__, devicename);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5279,15 +5276,6 @@ static void sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
|
||||||
throw SaneException("could not find the device to open: %s", devicename);
|
throw SaneException("could not find the device to open: %s", devicename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_flag(dev->model->flags, ModelFlag::UNTESTED)) {
|
|
||||||
DBG(DBG_error0, "WARNING: Your scanner is not fully supported or at least \n");
|
|
||||||
DBG(DBG_error0, " had only limited testing. Please be careful and \n");
|
|
||||||
DBG(DBG_error0, " report any failure/success to \n");
|
|
||||||
DBG(DBG_error0, " sane-devel@alioth-lists.debian.net. Please provide as many\n");
|
|
||||||
DBG(DBG_error0, " details as possible, e.g. the exact name of your\n");
|
|
||||||
DBG(DBG_error0, " scanner and what does (not) work.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
dbg.vstatus("open device '%s'", dev->file_name.c_str());
|
dbg.vstatus("open device '%s'", dev->file_name.c_str());
|
||||||
|
|
||||||
if (is_testing_mode()) {
|
if (is_testing_mode()) {
|
||||||
|
@ -5300,6 +5288,22 @@ static void sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
|
||||||
dev->interface->get_usb_device().open(dev->file_name.c_str());
|
dev->interface->get_usb_device().open(dev->file_name.c_str());
|
||||||
dbg.clear();
|
dbg.clear();
|
||||||
|
|
||||||
|
auto bcd_device = dev->interface->get_usb_device().get_bcd_device();
|
||||||
|
const auto& usb_dev = get_matching_usb_dev(dev->vendorId, dev->productId, bcd_device);
|
||||||
|
|
||||||
|
dev->model = &usb_dev.model();
|
||||||
|
|
||||||
|
dbg.vlog(DBG_info, "Opened device %s", dev->model->name);
|
||||||
|
|
||||||
|
if (has_flag(dev->model->flags, ModelFlag::UNTESTED)) {
|
||||||
|
DBG(DBG_error0, "WARNING: Your scanner is not fully supported or at least \n");
|
||||||
|
DBG(DBG_error0, " had only limited testing. Please be careful and \n");
|
||||||
|
DBG(DBG_error0, " report any failure/success to \n");
|
||||||
|
DBG(DBG_error0, " sane-devel@alioth-lists.debian.net. Please provide as many\n");
|
||||||
|
DBG(DBG_error0, " details as possible, e.g. the exact name of your\n");
|
||||||
|
DBG(DBG_error0, " scanner and what does (not) work.\n");
|
||||||
|
}
|
||||||
|
|
||||||
s_scanners->push_back(Genesys_Scanner());
|
s_scanners->push_back(Genesys_Scanner());
|
||||||
auto* s = &s_scanners->back();
|
auto* s = &s_scanners->back();
|
||||||
|
|
||||||
|
|
|
@ -196,8 +196,11 @@ public:
|
||||||
return false;
|
return false;
|
||||||
if (product_ != product_id)
|
if (product_ != product_id)
|
||||||
return false;
|
return false;
|
||||||
if (bcd_device_ != BCD_DEVICE_NOT_SET && bcd_device_ != bcd_device)
|
if (bcd_device_ != BCD_DEVICE_NOT_SET && bcd_device != BCD_DEVICE_NOT_SET &&
|
||||||
|
bcd_device_ != bcd_device)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,9 @@
|
||||||
|
|
||||||
namespace genesys {
|
namespace genesys {
|
||||||
|
|
||||||
TestScannerInterface::TestScannerInterface(Genesys_Device* dev) : dev_{dev}
|
TestScannerInterface::TestScannerInterface(Genesys_Device* dev) :
|
||||||
|
dev_{dev},
|
||||||
|
usb_dev_{get_testing_vendor_id(), get_testing_product_id(), get_testing_bcd_device()}
|
||||||
{
|
{
|
||||||
// initialize status registers
|
// initialize status registers
|
||||||
if (dev_->model->asic_type == AsicType::GL124) {
|
if (dev_->model->asic_type == AsicType::GL124) {
|
||||||
|
|
|
@ -96,12 +96,18 @@ void TestUsbDevice::close()
|
||||||
name_ = "";
|
name_ = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestUsbDevice::get_vendor_product(int& vendor, int& product)
|
std::uint16_t TestUsbDevice::get_vendor_id()
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
assert_is_open();
|
assert_is_open();
|
||||||
vendor = vendor_;
|
return vendor_;
|
||||||
product = product_;
|
}
|
||||||
|
|
||||||
|
std::uint16_t TestUsbDevice::get_product_id()
|
||||||
|
{
|
||||||
|
DBG_HELPER(dbg);
|
||||||
|
assert_is_open();
|
||||||
|
return product_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint16_t TestUsbDevice::get_bcd_device()
|
std::uint16_t TestUsbDevice::get_bcd_device()
|
||||||
|
|
|
@ -51,8 +51,6 @@ namespace genesys {
|
||||||
class TestUsbDevice : public IUsbDevice {
|
class TestUsbDevice : public IUsbDevice {
|
||||||
public:
|
public:
|
||||||
TestUsbDevice(std::uint16_t vendor, std::uint16_t product, std::uint16_t bcd_device);
|
TestUsbDevice(std::uint16_t vendor, std::uint16_t product, std::uint16_t bcd_device);
|
||||||
TestUsbDevice() = default;
|
|
||||||
|
|
||||||
~TestUsbDevice() override;
|
~TestUsbDevice() override;
|
||||||
|
|
||||||
bool is_open() const override { return is_open_; }
|
bool is_open() const override { return is_open_; }
|
||||||
|
@ -65,7 +63,8 @@ public:
|
||||||
void reset() override;
|
void reset() override;
|
||||||
void close() override;
|
void close() override;
|
||||||
|
|
||||||
void get_vendor_product(int& vendor, int& product) override;
|
std::uint16_t get_vendor_id() override;
|
||||||
|
std::uint16_t get_product_id() override;
|
||||||
std::uint16_t get_bcd_device() override;
|
std::uint16_t get_bcd_device() override;
|
||||||
|
|
||||||
void control_msg(int rtype, int reg, int value, int index, int length,
|
void control_msg(int rtype, int reg, int value, int index, int length,
|
||||||
|
|
|
@ -101,11 +101,24 @@ void UsbDevice::close()
|
||||||
sanei_usb_close(device_num);
|
sanei_usb_close(device_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbDevice::get_vendor_product(int& vendor, int& product)
|
std::uint16_t UsbDevice::get_vendor_id()
|
||||||
{
|
{
|
||||||
DBG_HELPER(dbg);
|
DBG_HELPER(dbg);
|
||||||
assert_is_open();
|
assert_is_open();
|
||||||
|
int vendor = 0;
|
||||||
|
int product = 0;
|
||||||
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
||||||
|
return static_cast<std::uint16_t>(vendor);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint16_t UsbDevice::get_product_id()
|
||||||
|
{
|
||||||
|
DBG_HELPER(dbg);
|
||||||
|
assert_is_open();
|
||||||
|
int vendor = 0;
|
||||||
|
int product = 0;
|
||||||
|
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
|
||||||
|
return static_cast<std::uint16_t>(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint16_t UsbDevice::get_bcd_device()
|
std::uint16_t UsbDevice::get_bcd_device()
|
||||||
|
|
|
@ -71,7 +71,8 @@ public:
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
|
|
||||||
virtual void get_vendor_product(int& vendor, int& product) = 0;
|
virtual std::uint16_t get_vendor_id() = 0;
|
||||||
|
virtual std::uint16_t get_product_id() = 0;
|
||||||
virtual std::uint16_t get_bcd_device() = 0;
|
virtual std::uint16_t get_bcd_device() = 0;
|
||||||
|
|
||||||
virtual void control_msg(int rtype, int reg, int value, int index, int length,
|
virtual void control_msg(int rtype, int reg, int value, int index, int length,
|
||||||
|
@ -97,7 +98,8 @@ public:
|
||||||
void reset() override;
|
void reset() override;
|
||||||
void close() override;
|
void close() override;
|
||||||
|
|
||||||
void get_vendor_product(int& vendor, int& product) override;
|
std::uint16_t get_vendor_id() override;
|
||||||
|
std::uint16_t get_product_id() override;
|
||||||
std::uint16_t get_bcd_device() override;
|
std::uint16_t get_bcd_device() override;
|
||||||
|
|
||||||
void control_msg(int rtype, int reg, int value, int index, int length,
|
void control_msg(int rtype, int reg, int value, int index, int length,
|
||||||
|
|
Ładowanie…
Reference in New Issue