1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4 
5    This file is part of the SANE package.
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef BACKEND_GENESYS_TEST_SCANNER_INTERFACE_H
22 #define BACKEND_GENESYS_TEST_SCANNER_INTERFACE_H
23 
24 #include "scanner_interface.h"
25 #include "register_cache.h"
26 #include "test_usb_device.h"
27 #include "test_settings.h"
28 
29 #include <map>
30 
31 namespace genesys {
32 
33 class TestScannerInterface : public ScannerInterface
34 {
35 public:
36     TestScannerInterface(Genesys_Device* dev, std::uint16_t vendor_id, std::uint16_t product_id,
37                          std::uint16_t bcd_device);
38 
39     ~TestScannerInterface() override;
40 
41     bool is_mock() const override;
42 
cached_regs() const43     const RegisterCache<std::uint8_t>& cached_regs() const { return cached_regs_; }
cached_fe_regs() const44     const RegisterCache<std::uint16_t>& cached_fe_regs() const { return cached_fe_regs_; }
45 
46     std::uint8_t read_register(std::uint16_t address) override;
47     void write_register(std::uint16_t address, std::uint8_t value) override;
48     void write_registers(const Genesys_Register_Set& regs) override;
49 
50     void write_0x8c(std::uint8_t index, std::uint8_t value) override;
51     void bulk_read_data(std::uint8_t addr, std::uint8_t* data, std::size_t size) override;
52     void bulk_write_data(std::uint8_t addr, std::uint8_t* data, std::size_t size) override;
53 
54     void write_buffer(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
55                       std::size_t size) override;
56     void write_gamma(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
57                      std::size_t size) override;
58     void write_ahb(std::uint32_t addr, std::uint32_t size, std::uint8_t* data) override;
59 
60     std::uint16_t read_fe_register(std::uint8_t address) override;
61     void write_fe_register(std::uint8_t address, std::uint16_t value) override;
62 
63     IUsbDevice& get_usb_device() override;
64 
65     void sleep_us(unsigned microseconds) override;
66 
67     void record_progress_message(const char* msg) override;
68 
69     const std::string& last_progress_message() const;
70 
71     void record_slope_table(unsigned table_nr, const std::vector<std::uint16_t>& steps) override;
72 
73     std::map<unsigned, std::vector<std::uint16_t>>& recorded_slope_tables();
74 
75     void record_key_value(const std::string& key, const std::string& value) override;
76 
77     std::map<std::string, std::string>& recorded_key_values();
78 
79     void test_checkpoint(const std::string& name) override;
80 
81     void set_checkpoint_callback(TestCheckpointCallback callback);
82 
83 private:
84     Genesys_Device* dev_;
85 
86     RegisterCache<std::uint8_t> cached_regs_;
87     RegisterCache<std::uint16_t> cached_fe_regs_;
88     TestUsbDevice usb_dev_;
89 
90     TestCheckpointCallback checkpoint_callback_;
91 
92     std::map<unsigned, std::vector<std::uint16_t>> slope_tables_;
93 
94     std::string last_progress_message_;
95     std::map<std::string, std::string> key_values_;
96 };
97 
98 } // namespace genesys
99 
100 #endif
101