// 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 // // type: see cis_cb_type // // LPPACKIMAGE: image information, or uint32_t event data when bool is false // // NOTE: LPPACKIMAGE->channels always be 1 as gray bitmap! // // real channels(color mode) should judge by // // LPPACKIMAGE->width / 2 sides / cis::get_line_stream_length(LPPACKIMAGE->resolution_x, false) #define IMAGE_HANDLER_PROTO void(CIS_IMAGE_PROTO) #define LOG_CIS_TIME_PROTO std::string& log, int paper, const char* step, uint32_t ms, bool last #include "./cis/cis_param.h" class GVideoISP1; class gVideo; class MotorBoard; class FpgaComm; class scanner_hw : public sane_opt_provider { std::function img_handler_ = std::function(); CHK_RES_FUNC res_ = CHK_RES_FUNC(); 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; bool count_mode_ = true; bool scan_cntless_ = true; int scan_count_ = 1; int cis_length_ = 3888; bool cis_led_ = true; int dpi_ = 300; int dpi_y_ = 300; int baud_ = 921600; int delay_ = 1000; int frame_h_ = 12; int sample_ = 201; // 256; int sp_ = 816; int vsp_a_ = 66; int vsp_b_ = 67; int exposure_[SIDE_COUNT][COLOR_IND_COUNT]; int gain_[SIDE_COUNT][CIS_SECTOR_COUNT]; int off_[SIDE_COUNT][CIS_SECTOR_COUNT]; double stretch_h_ = 1.0f; double stretch_v_ = 1.0f; std::string paper_ = WORDS_PAPER_ORIGIN_SIZE; 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_; int to_lifter_ = 10000; // timeout in ms of lifter arrived int to_paper_out_ = 5000; // timeout in ms of paper passed int to_stream_ = 5000; // timeout in ms of frame data can be read bool log_debug_info_ = false; std::function dbg_print_; void init(void); void init_version(std::string& text); void load_correct_data(std::string& text); void thread_image_capture(bool paper_ready); int start_and_wait_lifter(int to_ms, int* ui_words_id = nullptr); int scan_one_turn(LPPACKIMAGE img, safe_fifo* cism, int* cism_cnt, int* ui_words, bool* mbstopped); int get_image_real_height(int minh); 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, CHK_RES_FUNC res, std::string* cfgjson = nullptr, bool count_mode = false); int start_scan(void); int stop_scan(bool from_ui = false); int close(bool from_worker = false); int trans_motorboard_err_2_hg_error(int mberr, int *ui_msg = nullptr); int hg_err_2_image_status(int hgerr); bool is_scanning(void); void clean_paper_passway(void); };