newtx/hardware/motor/motorboard.h

184 lines
5.1 KiB
C++

#pragma once
#include <string>
#include <memory>
#include <condition_variable>
#include <functional>
#include "autoevent.hpp"
class IRegsAccess;
class PinMonitor;
class Gpio;
class ICapturer;
typedef struct SMB_CONFIG
{
unsigned int enable : 1;
unsigned int color_mode : 1;
unsigned int paper : 1;
unsigned int double_paper : 1;
unsigned int staple_enable : 1; // 5
unsigned int error_clean : 1;
unsigned int status_init : 1;
unsigned int pick_paper : 1;
unsigned int skew_enable : 1;
unsigned int skew_parameter : 3; // 7
unsigned int key_staple_enable : 1;
unsigned int iic_config_addr : 7;
unsigned int iic_config : 1;
unsigned int v_setting : 2; // 11
unsigned int speed_set_enable : 1;
unsigned int scan_busy_motor_stop : 1;
unsigned int sleep_state : 1;
unsigned int sleep_parameter : 3; // 6
unsigned int _600dpi : 1;
unsigned int paper_auto_module : 1; // 2
unsigned int testbit : 1;
} SMBCONFIG;
typedef struct SMB_STATUS
{
unsigned int scan_pulse : 1;
unsigned int m1_paper_sin : 1;
unsigned int open_machine : 1;
unsigned int pick_failed : 1;
unsigned int stop_jam : 1; // 5
unsigned int double_paper : 1;
unsigned int staple : 1;
unsigned int papertilted : 1;
unsigned int count_pulse : 1;
unsigned int scan_mode_change : 1; // 5
unsigned int motor_status : 1;
unsigned int keep_last_paper : 1;
unsigned int sleep_set : 1;
unsigned int sleep_conf : 3;
unsigned int dsp_get_paper_error : 1;
unsigned int paper_check_result : 1;
unsigned int top_wuzhi : 1;
unsigned int ml_top_sin : 1; // 10
unsigned int paper_auto : 1;
unsigned int paper_left : 1;
} SMBSTATUS;
typedef struct SMB_MODE
{
unsigned int scan_num : 14;
unsigned int scan_mode : 2;
unsigned int feeding_paper_ready : 1;
unsigned int work_status : 1;
} SMBMODE;
typedef struct SMB_CONFIG_EXT
{
unsigned int paper_infor : 5;
unsigned int paper_size_check_en : 1;
unsigned int error_range_set : 15;
unsigned int cuo_speed : 7;
} SMBCONFIGEXT;
struct MotorBoardGlue
{
MotorBoardGlue(const std::function<void(unsigned int)> error_call,
const std::function<void()> scan_done_call,
const std::function<void(unsigned int)> os_mode_call,
const std::function<void(unsigned int)> set_sleepmode_call,
const std::function<void(unsigned int)> mltop_call,
std::function<void(unsigned int)> auto_paper)
: m_error_call(error_call),
m_scan_done_call(scan_done_call),
m_os_mode_call(os_mode_call),
m_set_sleepmode_call(set_sleepmode_call),
m_mltop_call(mltop_call),
m_auto_paper(auto_paper)
{
}
std::function<void(unsigned int)> m_error_call;
std::function<void()> m_scan_done_call;
std::function<void(unsigned int)> m_os_mode_call;
std::function<void(unsigned int)> m_set_sleepmode_call;
std::function<void(unsigned int)> m_mltop_call;
std::function<void(unsigned int)> m_auto_paper;
};
enum
{
PORT_CONFIG = 0,
PORT_STATUS,
PORT_MODE,
PORT_VERSION,
PORT_CONFIG_EX = 4,
};
enum
{
SPEED_PPM_BASE = 0,
SPEED_PPM_BASE_10,
SPEED_PPM_BASE_20,
SPEED_PPM_BASE_30,
};
class MotorBoard
{
public:
MotorBoard();
void start();
void stop();
void clear_error();
void pick_paper();
int os_mode();
bool paper_ready();
bool is_scanning();
int paper_counter();
bool set_long_paper(bool enable);
bool set_double_inpect(bool enable);
bool get_doublle_inpect();
bool set_staple_inpect(bool enable);
bool set_auto_paper(bool enable);
bool get_staple_inpect();
bool set_color_mode(int mode);
int get_color_mode();
int get_speed_mode();
bool set_speed_mode(int mode);
bool set_screw_inpect(bool enable);
bool get_screw_inpect();
bool set_screw_level(int level);
int get_screw_level();
bool wait_paper_out(int timeout_ms);
bool wait_paper_in(int timeout_ms);
bool wait_error(int timeout_ms);
bool wait_done(int timeout_ms);
bool read(unsigned int addr, unsigned int &val);
bool write(unsigned int addr, unsigned int val);
bool set_paper_inspect_param(unsigned int value = 1000);
bool set_paper_inpect_info(unsigned int value);
bool set_paper_inspect(bool enable = true);
bool set_cuospeed(unsigned int speed);
void set_callbacks(MotorBoardGlue glue);
bool get_keeplastpaper();
bool en_testbit(bool en);
std::shared_ptr<IRegsAccess> regs();
void release_statecontrol();
void init_statecontrol();
private:
void pin_call(unsigned int pinNum);
void scansensor_call(unsigned int pinNum);
const std::string devPort;
const unsigned int bauds = 921600;
const int readflag = 0x07;
const int writeflag = 0x87;
const unsigned int intport = 151;
std::shared_ptr<IRegsAccess> m_regsAccess;
std::shared_ptr<PinMonitor> m_intPinMonitor;
std::shared_ptr<Gpio> m_uartEnable;
AutoSemaphore cv_paper_out;
AutoSemaphore cv_paper_in;
AutoSemaphore cv_error;
AutoSemaphore cv_scan_done;
AutoSemaphore cv_os_mode;
unsigned int m_os_mode;
volatile bool keep_last_paper;
MotorBoardGlue m_glue;
bool b_paperin;
};