newtx/hardware/hardware.h

130 lines
4.3 KiB
C
Raw Normal View History

// 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
//
// 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(dyn_mem_ptr, bool, LPPACKIMAGE)
#include "./cis/cis_param.h"
class GVideoISP1;
2024-01-11 07:23:05 +00:00
class gVideo;
class MotorBoard;
class FpgaComm;
class scanner_hw : public sane_opt_provider
{
2023-12-29 02:53:04 +00:00
std::function<IMAGE_HANDLER_PROTO> img_handler_ = std::function<IMAGE_HANDLER_PROTO>();
volatile bool scanning_ = false;
2023-12-19 09:11:41 +00:00
int time_to_exit_auto_scan_ = 60; // seconds
std::unique_ptr<FpgaComm> img_controller_;
2024-01-11 09:59:23 +00:00
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_;
2023-12-29 02:53:04 +00:00
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;
2024-01-11 07:23:05 +00:00
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;
2024-01-13 09:14:12 +00:00
int sp_ = 816;
2024-01-27 09:43:13 +00:00
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];
2024-01-13 09:14:12 +00:00
double stretch_h_ = 1.0f;
double stretch_v_ = 1.0f;
2024-01-24 04:05:05 +00:00
std::string paper_ = WORDS_PAPER_ORIGIN_SIZE;
2024-01-11 09:59:23 +00:00
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_;
int to_lifter_ = 5000; // timeout in ms of lifter arrived
int to_paper_out_ = 3000; // timeout in ms of paper passed
int to_stream_ = 5000; // timeout in ms of frame data can be read
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);
2024-01-03 09:39:16 +00:00
void retrieve_v4l2_mem(safe_fifo<int>* mem, int* used);
2024-01-13 09:14:12 +00:00
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;
2024-01-11 09:59:23 +00:00
virtual void enable(const char* name, bool able) override;
// operation ...
public:
int open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::string* cfgjson = nullptr, bool count_mode = false);
int start_scan(void);
int stop_scan(void);
int close(bool from_worker = false);
2024-01-27 09:43:13 +00:00
int trans_motorboard_err_2_hg_error(int mberr);
int hg_err_2_image_status(int hgerr);
bool is_scanning(void);
};