tx-gxx-linux/device/gxx-linux/motorboard/motorboard.h

216 lines
6.5 KiB
C
Raw Normal View History

2023-04-08 00:56:20 +00:00
#pragma once
2023-05-02 01:50:55 +00:00
#include <string>
#include <memory>
#include <condition_variable>
#include <functional>
#include "autoevent.hpp"
#include "commondef.h"
#include <math.h>
#include <vector>
#include "wakeup.hpp"
2023-04-08 00:56:20 +00:00
2023-05-02 01:50:55 +00:00
//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;
enum class DisType;
enum class ClearScreen;
/*
Arm
*/
2023-04-08 00:56:20 +00:00
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
2023-04-08 00:56:20 +00:00
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
2023-04-08 00:56:20 +00:00
unsigned int iic_config_addr : 7;
unsigned int iic_config : 1;
unsigned int v_setting : 2;//10
2023-04-08 00:56:20 +00:00
unsigned int speed_set_enable : 1;
unsigned int scan_busy_motor_stop : 1;
unsigned int dpi_mode : 2;
unsigned int sleep_parameter : 2;//6
unsigned int dpi600:1;
unsigned int autofeed_mode:1;
unsigned int lifter_en:1;
2023-04-08 00:56:20 +00:00
} 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;
2023-05-02 01:50:55 +00:00
unsigned int stop_jam : 1;//5
2023-04-08 00:56:20 +00:00
unsigned int double_paper : 1;
unsigned int staple : 1;
unsigned int papertilted : 1;
unsigned int count_pulse : 1;
2023-05-02 01:50:55 +00:00
unsigned int scan_mode_change : 1;//5
2023-04-08 00:56:20 +00:00
unsigned int motor_status : 1;
unsigned int keep_last_paper : 1;
unsigned int sleep_set : 1;
2023-05-02 01:50:55 +00:00
unsigned int sleep_conf : 3;//6
2023-04-08 00:56:20 +00:00
unsigned int dsp_get_paper_error : 1;
unsigned int paper_check_result : 1;
2023-05-02 01:50:55 +00:00
unsigned int arrival_top:1;//顶部无纸
unsigned int arrival_top_int:1;//到达顶部中断
unsigned int auto_feed:1;//4
2023-05-02 01:50:55 +00:00
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; //液晶双张错误清除
2023-04-08 00:56:20 +00:00
} 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;
typedef struct SMB_CONFIG_TIME
{
unsigned int error_time_set : 7;
} 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;
2023-05-02 01:50:55 +00:00
class MotorBoard
2023-04-08 00:56:20 +00:00
{
public:
2023-05-02 01:50:55 +00:00
MotorBoard(std::shared_ptr<WakeUp> wake);
2023-05-02 01:50:55 +00:00
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_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_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<IRegsAccess> 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();
void setautopaperkeystopcallback(std::function<void()> func);
void errormsg(uint value);
void startcapimage(bool value);
void clean_paper_road();
2023-04-08 00:56:20 +00:00
private:
void pin_call(unsigned int pinNum);
2023-05-02 01:50:55 +00:00
2023-04-08 00:56:20 +00:00
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;
2023-05-02 01:50:55 +00:00
std::shared_ptr<StateControl> m_statecontrol;
std::shared_ptr<WakeUp> m_wake;
std::atomic_uint m_paperout_count;
2023-04-08 00:56:20 +00:00
AutoSemaphore cv_paper_in;
2023-05-02 01:50:55 +00:00
AutoSemaphore cv_arrival_top;
AutoSemaphore cv_paper_out;
AutoSemaphore cv_error;
AutoSemaphore cv_scan_done;
AutoSemaphore cv_os_mode;
HGScanConfig m_config;
2023-04-08 00:56:20 +00:00
unsigned int m_os_mode;
volatile bool keep_last_paper;
MotorBoardGlue m_glue;
2023-05-02 01:50:55 +00:00
std::function<void()> autopaperkeystop;
2023-04-08 00:56:20 +00:00
};