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_COMMAND_SET_H
22 #define BACKEND_GENESYS_COMMAND_SET_H
23 
24 #include "device.h"
25 #include "fwd.h"
26 #include <cstdint>
27 
28 namespace genesys {
29 
30 
31 /** Scanner command set description.
32 
33     This description contains parts which are common to all scanners with the
34     same command set, but may have different optical resolution and other
35     parameters.
36  */
37 class CommandSet
38 {
39 public:
40     virtual ~CommandSet() = default;
41 
42     virtual bool needs_home_before_init_regs_for_scan(Genesys_Device* dev) const = 0;
43 
44     virtual void init(Genesys_Device* dev) const = 0;
45 
46     virtual void init_regs_for_warmup(Genesys_Device* dev, const Genesys_Sensor& sensor,
47                                       Genesys_Register_Set* regs) const = 0;
48 
49     virtual void init_regs_for_shading(Genesys_Device* dev, const Genesys_Sensor& sensor,
50                                        Genesys_Register_Set& regs) const = 0;
51 
52     /** Set up registers for a scan. Similar to init_regs_for_scan except that the session is
53         already computed from the session
54     */
55     virtual void init_regs_for_scan_session(Genesys_Device* dev, const Genesys_Sensor& sensor,
56                                             Genesys_Register_Set* reg,
57                                             const ScanSession& session) const= 0;
58 
59     virtual void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const = 0;
60     virtual void set_powersaving(Genesys_Device* dev, int delay) const = 0;
61     virtual void save_power(Genesys_Device* dev, bool enable) const = 0;
62 
63     virtual void begin_scan(Genesys_Device* dev, const Genesys_Sensor& sensor,
64                             Genesys_Register_Set* regs, bool start_motor) const = 0;
65     virtual void end_scan(Genesys_Device* dev, Genesys_Register_Set* regs,
66                           bool check_stop) const = 0;
67 
68 
69     /**
70      * Send gamma tables to ASIC
71      */
72     virtual void send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor) const = 0;
73 
74     virtual void offset_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor,
75                                     Genesys_Register_Set& regs) const = 0;
76     virtual void coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor,
77                                          Genesys_Register_Set& regs, int dpi) const = 0;
78     virtual SensorExposure led_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor,
79                                            Genesys_Register_Set& regs) const = 0;
80 
81     virtual void wait_for_motor_stop(Genesys_Device* dev) const = 0;
82     virtual void move_back_home(Genesys_Device* dev, bool wait_until_home) const = 0;
83 
84     // Updates hardware sensor information in Genesys_Scanner.val[].
85     virtual void update_hardware_sensors(struct Genesys_Scanner* s) const = 0;
86 
87     /** Needed on some chipsets before reading the status of the home sensor as the sensor may be
88         controlled by additional GPIO registers.
89     */
90     virtual void update_home_sensor_gpio(Genesys_Device& dev) const = 0;
91 
92     // functions for sheetfed scanners
93 
94     // load document into scanner
95     virtual void load_document(Genesys_Device* dev) const = 0;
96 
97     /** Detects is the scanned document has left scanner. In this case it updates the amount of
98         data to read and set up flags in the dev struct
99      */
100     virtual void detect_document_end(Genesys_Device* dev) const = 0;
101 
102     /// eject document from scanner
103     virtual void eject_document(Genesys_Device* dev) const = 0;
104 
105     /// write shading data calibration to ASIC
106     virtual void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor,
107                                    std::uint8_t* data, int size) const = 0;
108 
has_send_shading_data() const109     virtual bool has_send_shading_data() const
110     {
111         return true;
112     }
113 
114     /// calculate an instance of ScanSession for scanning with the given settings
115     virtual ScanSession calculate_scan_session(const Genesys_Device* dev,
116                                                const Genesys_Sensor& sensor,
117                                                const Genesys_Settings& settings) const = 0;
118 
119     /// cold boot init function
120     virtual void asic_boot(Genesys_Device* dev, bool cold) const = 0;
121 
122     /// checks if specific scan head is at home position
123     virtual bool is_head_home(Genesys_Device& dev, ScanHeadId scan_head) const = 0;
124 
125     /// enables or disables XPA slider motor
126     virtual void set_xpa_lamp_power(Genesys_Device& dev, bool set) const = 0;
127 
128     /// enables or disables XPA slider motor
129     virtual void set_motor_mode(Genesys_Device& dev, Genesys_Register_Set& regs,
130                                 MotorMode mode) const = 0;
131 };
132 
133 } // namespace genesys
134 
135 #endif // BACKEND_GENESYS_COMMAND_SET_H
136