112 lines
3.5 KiB
C++
112 lines
3.5 KiB
C++
// hardware drivers
|
|
//
|
|
// Contains: CIS, MotorBoard, ...
|
|
//
|
|
// Date: 2023-12-18
|
|
|
|
#include <sane_opt_json/base_opt.h>
|
|
#include <functional>
|
|
#include <base/packet.h>
|
|
#include <base/data.h>
|
|
#include <memory>
|
|
#include <map>
|
|
#include <utility>
|
|
|
|
// 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<IMAGE_HANDLER_PROTO> img_handler_ = std::function<IMAGE_HANDLER_PROTO>();
|
|
volatile bool scanning_ = false;
|
|
int time_to_exit_auto_scan_ = 60; // seconds
|
|
std::unique_ptr<FpgaComm> img_controller_;
|
|
std::unique_ptr<gVideo> camera_;
|
|
std::unique_ptr<MotorBoard> motor_;
|
|
std::unique_ptr<std::thread> scan_thread_;
|
|
safe_fifo<std::pair<int, int>> 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<std::string, std::function<void(void*)>> opt_handler_;
|
|
|
|
|
|
void init(void);
|
|
void init_version(std::string& text);
|
|
void thread_image_capture(void);
|
|
int get_image_real_height(int minh);
|
|
bool is_scan_fatal(void);
|
|
void retrieve_v4l2_mem(safe_fifo<int>* 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_PROTO> image_handler);
|
|
int start_scan(void);
|
|
int stop_scan(void);
|
|
int close(void);
|
|
bool is_scanning(void);
|
|
};
|