// hardware drivers // // Contains: CIS, MotorBoard, ... // // Date: 2023-12-18 #include #include #include #include #include #include #include // image handler callback proto // // dyn_mem_ptr: image data buffer, or be uint32_t if bool was false // // bool: true - image, dyn_mem_ptr is image data buffer; false - dyn_mem_ptr is an uint32_t code of hardware event // // LPPACKIMAGE: image information, or uint32_t event data when bool is false #define IMAGE_HANDLER_PROTO void(dyn_mem_ptr, bool, LPPACKIMAGE) #include "./cis/FpgaComm.h" class GVideoISP1; class gVideo; class MotorBoard; class scanner_hw : public sane_opt_provider { std::function img_handler_ = std::function(); volatile bool scanning_ = false; int time_to_exit_auto_scan_ = 60; // seconds std::unique_ptr img_controller_; std::unique_ptr camera_; std::unique_ptr motor_; std::unique_ptr scan_thread_; safe_fifo> mb_events_; enum { SIDE_FRONT = 0, SIDE_BACK, SIDE_COUNT, }; enum { COLOR_IND_BLUE = 0, COLOR_IND_GREEN, COLOR_IND_RED, COLOR_IND_COUNT, }; std::string mode_; std::string family_ = "G200"; PACKIMAGE img_base_; volatile bool auto_scan_ = false; int scan_count_ = -1; int cis_length_ = 3888; bool cis_led_ = true; int dpi_ = 300; int baud_ = 921600; int delay_ = 1000; int frame_h_ = 12; int sample_ = 256; int sp_ = 816; int exposure_[SIDE_COUNT][COLOR_IND_COUNT]; int gain_[SIDE_COUNT][FpgaComm::CIS_SECTOR_COUNT]; int off_[SIDE_COUNT][FpgaComm::CIS_SECTOR_COUNT]; double stretch_h_ = 1.0f; double stretch_v_ = 1.0f; std::string paper_ = "\345\214\271\351\205\215\345\216\237\345\247\213\345\260\272\345\257\270"; bool lateral_ = false; bool lateral_en_ = false; bool staple_chk_ = true; bool screw_chk_ = true; int screw_chk_level_ = 3; bool paper_on_ = false; bool double_chk_ = true; int motor_speed_ = /*SPEED_PPM_100*/0; std::map> opt_handler_; void init(void); void init_version(std::string& text); void thread_image_capture(void); bool is_scan_fatal(void); void retrieve_v4l2_mem(safe_fifo* mem, int* used); void set_gain_value(bool front, bool gain, int sector, int val); public: scanner_hw(); protected: ~scanner_hw(); // sane_opt_provider public: // return malloc(), real data size stored in parameter 'size'. invoker should free() the returned value virtual char* get_value(const char* name, void* value, size_t* size, int* err = nullptr) override; virtual int set_value(const char* name, void* val) override; virtual void enable(const char* name, bool able) override; // operation ... public: int open(std::function image_handler); int start_scan(void); int stop_scan(void); int close(void); bool is_scanning(void); };