#pragma once #include #include #include #include #include "autoevent.hpp" #include "commondef.h" #include #include #include "wakeup.hpp" //static std::vector frep_cfg(int a,int b,float k,int s) static std::vector frep_cfg(int finalPeriod, int Fmin, float stepnum, float a, float offset, float finalDelay,float acceleration_time) { std::vector freq; int freq_word = 0; int pulse_word = 0; for(int i =1;i<=256;i++) { freq_word = 8000000/((Fmin+(finalPeriod-Fmin)/(1+exp((-1)*(offset+a*(double)(i)*stepnum))))*2); pulse_word = ((8000000/acceleration_time)/63)/freq_word; //printf("\nfreq_word = %d pulse_word = %d",freq_word,pulse_word); freq.push_back((pulse_word&0xffff)+((freq_word&0xffff)<<16)); } return freq; } class IRegsAccess; class PinMonitor; class Gpio; class StateControl; enum class DisType; enum class ClearScreen; /* 注: 安路电机板已去除幅面检测以及休眠配置相关寄存器操作, 休眠将由Arm 进行控制 */ 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; unsigned int key_staple_enable : 1;//8 unsigned int iic_config_addr : 7; unsigned int slow_moire : 1; unsigned int v_setting : 2;//10 unsigned int speed_set_enable : 1; unsigned int double_out_en : 1; unsigned int dpi_mode : 2; // unsigned int sleep_parameter : 2;//6 // unsigned int dpi600:1; unsigned int v_temp : 3; unsigned int autofeed_mode:1; unsigned int lifter_en: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;//6 unsigned int dsp_get_paper_error : 1; unsigned int paper_check_result : 1; unsigned int arrival_top:1;//顶部无纸 unsigned int arrival_top_int:1;//到达顶部中断 unsigned int auto_feed:1;//4 unsigned int paper_left:1; unsigned int jam_1 : 1; //进纸口 unsigned int jam_2 : 1; //纸道 unsigned int jam_3 : 1; //出纸口 unsigned int cover_closed : 1; //已关盖 unsigned int double_clean_f : 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; //Reg 4 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; //Reg 5 typedef struct SMB_CONFIG_TIME { unsigned int error_time_set : 7; unsigned int scan_ctr_en : 1; unsigned int skew_ctr_en_1 : 1; unsigned int skew_ctr_en_2 : 1; unsigned int open_machine_ctr_en : 1; unsigned int paper_out_ctr_en : 1; unsigned int paper_check_ctr_en : 1; unsigned int sen_duty_set_sel : 3; unsigned int duty_set : 10; } SMBCONFIGTIME; //Reg 6 typedef union SMB_FUNC { struct{ unsigned int work_mode : 3; unsigned int func_clean_passthro : 1; unsigned int func_feed_low : 1; unsigned int func_feed_mid : 1; unsigned int func_feed_high : 1; unsigned int key_sound : 1; unsigned int key_endouble_feed : 1; unsigned int func_encount : 1; unsigned int func_clear_count : 1; unsigned int motor_choose : 2; unsigned int wr_en : 1; unsigned int motor_addr : 8; unsigned int key_stop_enable : 1; unsigned int lift_init_set: 2; unsigned int unused: 3; unsigned int motor_disable : 1; }param; unsigned int value; } SMBFUNC; //Reg 7 typedef union SMB_Ultrasonic_Config { struct { unsigned int double_check_cyc : 4; unsigned int paper_check_cyc : 4; unsigned int double_max : 8; unsigned int single_max : 8; unsigned int rd_ver_en : 1; unsigned int send_cyc_en : 1; unsigned int reserved : 6; }param; unsigned int value; }SMBUltrasonicConfig; //Reg 10 typedef union SMB_JAM_Time { struct { unsigned int jam_time_1 : 8; unsigned int jam_time_2 : 8; unsigned int jam_time_3 : 8; unsigned int jam_time_4 : 8; }param; unsigned int value; }SMBJAMTime; class MotorBoard { public: MotorBoard(std::shared_ptr wake); void start(HGScanConfig cfg); void stop(); void clear_error(); void pick_paper(); int os_mode(); bool paper_ready(); bool is_scanning(); int paper_counter(); bool en_lifter(); bool set_long_paper(bool enable); bool set_double_inpect(bool enable); bool get_doublle_inpect(); bool set_double_out_en(bool enable); bool get_double_out_en(); bool set_staple_inpect(bool enable); bool get_staple_inpect(); bool set_color_mode(int mode); int get_color_mode(); int get_speed_mode(); bool set_auto_paper(bool enable,bool enkey); bool set_speed_mode(int mode); bool set_speed_mode_v_temp(int mode); bool set_screw_inpect(bool enable); bool get_screw_inpect(); bool set_screw_level(int level); int get_screw_level(); bool wait_arrival_top(int timeout_ms); bool wait_paper_in(int timeout_ms); bool wait_paper_out(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); void set_callbacks(MotorBoardGlue glue); bool set_cuospeed(int value); bool get_keeplastpaper(); //bool set_en600DPI(bool en); bool set_time_error(int value); void start_countmode(); std::shared_ptr regs(); void PutMsg(DisType type,int value,ClearScreen clearscreen); void SetKeyState(bool value); void set_freq(int motor_choose,int speedmode,int colormode,int dpi); void set_keystopenable(bool value); void init_statecontrol(); void release_statecontrol() __attribute__((optimize("O0"))); void setautopaperkeystopcallback(std::function func); void errormsg(uint value); void startcapimage(bool value); void clean_paper_road(); bool set_slowmoire(bool en); bool set_sensor_pwm_duty(int sensorid,int duty); bool enable_sensor_pwm(int sensorid,bool en); bool set_ultrasonic_param(int type,int value); void init_sensor_duty(); bool set_motor_stop(bool value); SMB_JAM_Time get_jam_param(); void set_jam_param(SMB_JAM_Time jam_time); std::uint32_t get_ultrasonic_version(); std::string getmbversion(); private: void pin_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; uint32_t m_version; std::shared_ptr m_regsAccess; std::shared_ptr m_intPinMonitor; std::shared_ptr m_statecontrol; std::shared_ptr m_wake; std::atomic_uint m_paperout_count; AutoSemaphore cv_paper_in; AutoSemaphore cv_arrival_top; AutoSemaphore cv_paper_out; AutoSemaphore cv_error; AutoSemaphore cv_scan_done; AutoSemaphore cv_os_mode; HGScanConfig m_config; unsigned int m_os_mode; volatile bool keep_last_paper; MotorBoardGlue m_glue; std::function autopaperkeystop; };