genesys: Turn Genesys_USB_Device_Entry into a class

merge-requests/213/head^2
Povilas Kanapickas 2020-03-28 23:15:47 +02:00
rodzic b89751605f
commit 0bdce7928f
7 zmienionych plików z 38 dodań i 28 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));
@ -4796,10 +4796,10 @@ 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)
{
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.vendor_id() == vendor_id &&
usb_dev.product_id() == product_id)
{
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;

Wyświetl plik

@ -168,18 +168,25 @@
namespace genesys {
struct Genesys_USB_Device_Entry {
class UsbDeviceEntry {
public:
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}, model_{model}
{}
std::uint16_t vendor_id() const { return vendor_; }
std::uint16_t product_id() const { return product_; }
const Genesys_Model& model() const { return model_; }
private:
// USB vendor identifier
std::uint16_t vendor;
std::uint16_t vendor_;
// USB product identifier
std::uint16_t product;
std::uint16_t product_;
// Scanner model information
Genesys_Model model;
Genesys_Model model_;
};
/*--------------------------------------------------------------------------*/
@ -467,7 +474,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

@ -397,30 +397,33 @@ 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.model_name = model.name;
config.method = method;
config.depth = depth;
config.resolution = resolution;