316 lines
9.2 KiB
C++
316 lines
9.2 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <memory>
|
|
#include <condition_variable>
|
|
#include <functional>
|
|
#include "autoevent.hpp"
|
|
// #include "commondef.h"
|
|
#include <math.h>
|
|
#include <vector>
|
|
#include <atomic>
|
|
#include <base/ui.h>
|
|
|
|
//static std::vector<std::uint32_t> frep_cfg(int a,int b,float k,int s)
|
|
static std::vector<std::uint32_t> frep_cfg(int finalPeriod, int Fmin, float stepnum, float a, float offset, float finalDelay,float acceleration_time)
|
|
{
|
|
std::vector<std::uint32_t> 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;
|
|
|
|
/*
|
|
注:
|
|
安路电机板已去除幅面检测以及休眠配置相关寄存器操作,
|
|
休眠将由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; // no paper
|
|
unsigned int open_machine : 1; // cover openned
|
|
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; //液晶双张错误清除
|
|
|
|
unsigned int reserved : 5;
|
|
} 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;
|
|
unsigned int paper_jammed_in : 2;
|
|
|
|
unsigned int paper_jammed_out : 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;
|
|
}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;
|
|
|
|
enum motor_board_port
|
|
{
|
|
MB_PORT_CONFIG = 0,
|
|
MB_PORT_STATUS,
|
|
MB_PORT_MODE,
|
|
MB_PORT_VERSION,
|
|
MB_PORT_CONFIG_EX,
|
|
MB_PORT_TIME, // ???
|
|
MB_PORT_FUNCTION,
|
|
MB_PORT_ULTROSONIC,
|
|
|
|
// I am the last
|
|
MB_PORT_COUNT
|
|
};
|
|
enum
|
|
{
|
|
MOTOR_BORD_EVENT_MODE = 1, // os mode changed, value = new mode
|
|
MOTOR_BORD_EVENT_SLEEP, //
|
|
MOTOR_BORD_EVENT_LIFTER_READY, //
|
|
MOTOR_BORD_EVENT_PAPER_READY,
|
|
MOTOR_BORD_EVENT_PAPER_PASSING, // value = 0: paper left, 1: paper is passing through the sensor
|
|
MOTOR_BORD_EVENT_SCAN_DONE,
|
|
MOTOR_BORD_EVENT_ERROR, // value = SMBSTATUS
|
|
};
|
|
enum
|
|
{
|
|
SPEED_PPM_BASE = 0,
|
|
SPEED_PPM_BASE_10,
|
|
SPEED_PPM_BASE_20,
|
|
SPEED_PPM_BASE_30,
|
|
};
|
|
|
|
class MotorBoard
|
|
{
|
|
std::function<void(int, unsigned int)> event_cb_;
|
|
|
|
public:
|
|
MotorBoard(std::function<void(int, unsigned int)> evcb = std::function<void(int, unsigned int)>());
|
|
|
|
void start(void);
|
|
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);
|
|
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<IRegsAccess> regs();
|
|
void PutMsg(int words, int align_v, int align_h, int font = 16, int clear_method = devui::CLEAR_ALL);
|
|
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<void()> 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();
|
|
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<IRegsAccess> m_regsAccess;
|
|
std::shared_ptr<PinMonitor> m_intPinMonitor;
|
|
// std::shared_ptr<StateControl> m_statecontrol;
|
|
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;
|
|
unsigned int m_os_mode;
|
|
volatile bool keep_last_paper;
|
|
std::function<void()> autopaperkeystop;
|
|
|
|
public:
|
|
// Function: wait given event in specified milliseconds
|
|
//
|
|
// Parameters: event - target event
|
|
//
|
|
// evdata - to receive the data of the event data or of fatal_ev
|
|
//
|
|
// to_ms - the max time in milliseconds to wait
|
|
//
|
|
// fatal_ev - to receive the fatal event if arrived before event
|
|
//
|
|
// fatal_msg - to receive the error message declared in words.h
|
|
//
|
|
// Return: wait event in to_ms return true, otherwise return false
|
|
bool wait_event(int event, int *evdata, int to_ms, int* fatal_ev, int* fatal_msg);
|
|
}; |