synchronize from G200

This commit is contained in:
gb 2023-05-02 09:50:55 +08:00
parent 2fe046b857
commit 262b4f0d5c
347 changed files with 19234 additions and 18066 deletions

BIN
device/gxx-linux/anlogic Normal file

Binary file not shown.

View File

@ -1,8 +1,8 @@
#include "applog.h"
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "stringex.hpp"
#include <iostream>
#include <algorithm>

View File

@ -8,68 +8,195 @@ CImageMerge::~CImageMerge()
}
cv::Mat CImageMerge::MergeImage(cv::Mat &srcMat, int dstwidth, int dstheight)
{
cv::Mat retMat(dstheight, dstwidth, CV_8UC3);
cv::Mat retMat(dstheight, dstwidth, CV_8UC3);
if (!srcMat.empty())
{
std::vector<cv::Mat> ch_mats;
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
if (!srcMat.empty())
{
std::vector<cv::Mat> ch_mats;
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
std::cout << " index " << (i * 3 + j) << " x " << spitWidth * (i * 3 + j) << " y " << 0 << " width " << spitWidth << " height " << dstheight << std::endl;
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + j), 0, spitWidth, dstheight)));
}
cv::merge(ch_mats, retMat(cv::Rect(spitWidth * i, 0, spitWidth, dstheight)));
ch_mats.clear();
}
return retMat;
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
std::cout << " index " << (i * 3 + j) << " x " << spitWidth * (i * 3 + j) << " y " << 0 << " width " << spitWidth << " height " << dstheight << std::endl;
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + j), 0, spitWidth, dstheight)));
}
cv::merge(ch_mats, retMat(cv::Rect(spitWidth * i, 0, spitWidth, dstheight)));
ch_mats.clear();
}
return retMat;
}
}
cv::Mat CImageMerge::MergeImage(bool iscolor, cv::Mat &srcMat, int dstwidth, int dstheight,std::uint32_t fpga_vs)
cv::Mat CImageMerge::MergeImage(bool iscolor, cv::Mat &srcMat, int dstwidth, int dstheight, unsigned int fgpaversion)
{
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
int abortwidth; // = spitWidth == 3888 ? 432 : (spitWidth == 2592 ? 216 : 144);
if (!iscolor) //灰度
{
abortwidth = spitWidth == 1296 ? 432 : (spitWidth == 648 ? 216 : 144);
}
else
{
abortwidth = spitWidth == 3888 ? 432 : (spitWidth == 1944 ? 216 : 144);
}
if (fgpaversion == 0x00090002)
{
int blockcnt = iscolor ? 18 : 6;
int spitWidth = srcMat.cols / blockcnt / 2; //一面的灰度图像宽度
int abortwidth = spitWidth == 1296 ? 432 : (spitWidth == 648 ? 216 : 144);
cv::Mat dst(dstheight, dstwidth - abortwidth * 2, CV_8UC(iscolor ? 3 : 1));
if (!iscolor)
{
for (int i = 0; i < 2; i++)
{
srcMat(cv::Rect((dstwidth / 2 + abortwidth) * i, 0, dstwidth / 2 - abortwidth, dstheight)).copyTo(dst(cv::Rect(dst.cols / 2 * i, 0, dst.cols / 2, dstheight)));
}
srcMat.release();
}
else
{
std::vector<cv::Mat> m_splits;
std::vector<int> m_index = {0, 3, 8, 11, 2, 5, 6, 9, 1, 4, 7, 10};
for (int i = 0; i < 3; i++)
{
int startindex = i == 0 ? 0 : (i == 1 ? 4 : 8);
cv::Mat t_mat(dstheight, dstwidth - abortwidth * 2, CV_8UC1);
srcMat(cv::Rect(spitWidth * m_index[startindex + 0], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(0, 0, spitWidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 1], 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 2] + abortwidth, 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 2 - abortwidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 3], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 3 - abortwidth * 2, 0, spitWidth, dstheight)));
m_splits.push_back(t_mat);
}
cv::merge(m_splits, dst);
m_splits.clear();
}
srcMat.release();
return dst;
}
std::cout << "image is color " << iscolor << std::endl;
cv::Mat dst(dstheight, dstwidth - 2 * abortwidth, CV_8UC(iscolor ? 3 : 1));
if (!iscolor)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 6; j++)
{
int index = i == 0 ? 5 : 11;
int bandindex = (i * 6 + j);
if (bandindex == 0 || bandindex == 11)
{
if (bandindex == 0)
srcMat(cv::Rect(bandindex * spitWidth, 0, spitWidth - abortwidth, srcMat.rows)).copyTo(dst(cv::Rect(spitWidth * (index - j), 0, spitWidth - abortwidth, srcMat.rows)));
else
srcMat(cv::Rect(bandindex * spitWidth + abortwidth, 0, spitWidth - abortwidth, srcMat.rows)).copyTo(dst(cv::Rect(spitWidth * (index - j) - abortwidth, 0, spitWidth - abortwidth, srcMat.rows)));
}
else
{
if (bandindex >= 6)
srcMat(cv::Rect(bandindex * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(dst(cv::Rect(spitWidth * (index - j) - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
else
srcMat(cv::Rect(bandindex * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(dst(cv::Rect(spitWidth * (index - j), 0, spitWidth, srcMat.rows)));
}
}
}
srcMat.release();
}
else
{
std::vector<cv::Mat> m_splits = {
cv::Mat(dstheight, dstwidth - 2 * abortwidth, CV_8UC1),
cv::Mat(dstheight, dstwidth - 2 * abortwidth, CV_8UC1),
cv::Mat(dstheight, dstwidth - 2 * abortwidth, CV_8UC1)};
int item_index[3][4] = {
{11, 2, 35, 26}, // R
{17, 8, 29, 20}, // B
{14, 5, 32, 23} // G
};
for (size_t j = 0; j < 3; j++)
{
// Front
srcMat(cv::Rect((item_index[j][0] - 0) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 0, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][0] - 1) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 1, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][0] - 2) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 2, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][1] - 0) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 3, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][1] - 1) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 4, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][1] - 2) * spitWidth, 0, spitWidth - abortwidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 5, 0, spitWidth - abortwidth, srcMat.rows)));
// Back
srcMat(cv::Rect((item_index[j][2] - 0) * spitWidth + abortwidth, 0, spitWidth - abortwidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 6 - abortwidth, 0, spitWidth - abortwidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][2] - 1) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 7 - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][2] - 2) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 8 - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][3] - 0) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 9 - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][3] - 1) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 10 - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
srcMat(cv::Rect((item_index[j][3] - 2) * spitWidth, 0, spitWidth, srcMat.rows)).copyTo(m_splits[j](cv::Rect(spitWidth * 11 - 2 * abortwidth, 0, spitWidth, srcMat.rows)));
}
cv::merge(m_splits, dst);
m_splits.clear();
}
srcMat.release();
// static int index=0;
// cv::imwrite(std::to_string(++index)+".bmp",dst);
return dst;
}
else if(fgpaversion == 0x00090001)
{
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
int abortwidth; // = spitWidth == 3888 ? 432 : (spitWidth == 2592 ? 216 : 144);
if (!iscolor) //灰度
{
abortwidth = spitWidth == 1296 ? 432 : (spitWidth == 648 ? 216 : 144);
}
else
{
abortwidth = spitWidth == 3888 ? 432 : (spitWidth == 1944 ? 216 : 144);
}
cv::Mat dst(dstheight, dstwidth - abortwidth * 2, CV_8UC(iscolor ? 3 : 1));
if (!iscolor)
{
for (int i = 0; i < 2; i++)
{
srcMat(cv::Rect((dstwidth / 2 + abortwidth) * i, 0, dstwidth / 2 - abortwidth, dstheight)).copyTo(dst(cv::Rect(dst.cols / 2 * i, 0, dst.cols / 2, dstheight)));
}
srcMat.release();
}
else
{
std::vector<cv::Mat> m_splits;
std::vector<int> m_index = {0, 3, 8, 11, 2, 5, 6, 9, 1, 4, 7, 10};
for (int i = 0; i < 3; i++)
{
int startindex = i == 0 ? 0 : (i == 1 ? 4 : 8);
cv::Mat t_mat(dstheight, dstwidth - abortwidth * 2, CV_8UC1);
srcMat(cv::Rect(spitWidth * m_index[startindex + 0], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(0, 0, spitWidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 1], 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 2] + abortwidth, 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 2 - abortwidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 3], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 3 - abortwidth * 2, 0, spitWidth, dstheight)));
m_splits.push_back(t_mat);
}
cv::merge(m_splits, dst);
m_splits.clear();
}
srcMat.release();
return dst;
}
else if(fgpaversion == 0x0009000a)
{
auto switchblock = [](std::vector<std::pair<int,int>> v,cv::Mat& src,cv::Mat& dst,int block_width,int block_height,int abortwidth){
int copyindex =0;
for(int i=0;i<v.size();i++){
if(v[i].second == 5 || v[i].second == 6){
src(cv::Rect( v[i].second == 6 ? block_width*v[i].first+abortwidth :block_width*v[i].first,0,block_width - abortwidth,block_height)).copyTo(dst(cv::Rect(copyindex,0,block_width - abortwidth,block_height)));
copyindex+= block_width - abortwidth;
}
else{
src(cv::Rect(block_width*v[i].first,0,block_width,block_height)).copyTo(dst(cv::Rect(copyindex,0,block_width,block_height)));
copyindex+= block_width ;
}
}
};
std::vector<std::pair<int,int>> v {{3,0},{5,1},{4,2},{1,3},{0,4},{2,5},{10,6},{9,7},{11,8},{6,9},{8,10},{7,11}};
if(!iscolor)
{
int abortwidth = srcMat.cols /12 == 1296 ? 432 :( srcMat.cols /12== 648 ? 216 :144);
cv::Mat dst(srcMat.rows, srcMat.cols - abortwidth*2, CV_8UC1);
switchblock(v,srcMat,dst,srcMat.cols /12,srcMat.rows,abortwidth);
return dst;
}
else
{
cv::Mat retMat(srcMat.rows, srcMat.cols / 3, CV_8UC3);
int spitWidth = srcMat.cols / 12 ;
for(int i=0;i<4;i++)
{
// 1 2 0
std::vector<cv::Mat> ch_mats;
if(i < 2){
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
}
else
{
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
}
cv::merge(ch_mats, retMat(cv::Rect(spitWidth * i, 0, spitWidth, srcMat.rows)));
ch_mats.clear();
}
int abortwidth = retMat.cols /12 == 1296 ? 432 :(retMat.cols /12 == 648 ? 216 :144);
cv::Mat dst(retMat.rows, retMat.cols - abortwidth*2, CV_8UC3);
switchblock(v,retMat,dst,retMat.cols /12,retMat.rows,abortwidth);
printf(" dst.cols = %d dst.rows = %d dst.channels = %d \n",dst.cols,dst.rows,dst.channels());
return dst;
}
}
return srcMat;
}

View File

@ -10,5 +10,5 @@ public:
~CImageMerge();
public:
cv::Mat MergeImage(cv::Mat& srcMat,int dstwidth,int dstheight);
cv::Mat MergeImage(bool iscolor,cv::Mat& srcMat,int dstwidth,int dstheight,std::uint32_t fpga_vs);
cv::Mat MergeImage(bool iscolor,cv::Mat& srcMat,int dstwidth,int dstheight,unsigned int fgpaversion=0x00090001);
};

View File

@ -12,7 +12,6 @@
#include "applog.h"
#include "stringex.hpp"
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
#include "filetools.h"
#include "CameraParam.h"
#include "correct_ultis.h"
@ -29,9 +28,12 @@ cv::Mat mBuffMat;
cv::Mat out;
Capturer::Capturer()
: reset_pin(new GpioOut(Fpga_Reset)),
initDone_pin(new Gpio(71)),
fpgaLoad(new GpioOut(70)),
: vdd_cis_3voff_pin(new GpioOut(CIS_3v3_Off)),
vdd_vis_5ven_pin(new GpioOut(CIS_5v_En)),
reset_pin(new GpioOut(Fpga_Reset)),
image_in_transfer_pin(new Gpio(Image_In_Transfer)),
initDone_pin(new Gpio(Fpga_InitDone)),
fpgaLoad(new GpioOut(Fpga_Load)),
bcorrecting(false)
{
LOG_INIT();
@ -47,6 +49,9 @@ Capturer::~Capturer()
{
}
void Capturer::Fpga_regsAccess_reset(bool enable){
}
void Capturer::open()
{
cisconfigs = getcisparams();
@ -97,7 +102,8 @@ void Capturer::open(HGScanConfig config,FPGAConfigParam fpgaparam)
if (exp_ratio > 2.0)
exp_ratio = 0.1;
cisconfigs = getcisparams();
int height = 1632;
auto hgsize = papersMap[(PaperSize)config.g200params.paper];
int height = hgsize.height;
fpgaComm->setColorMode(config.g200params.color ? 1 : 0);
auto info = jsonconfig().getscannerinfo();
//set_sp(config.g200params.color ? cisconfigs.color.sp : cisconfigs.gray.sp); //0x03fa : 0x0bf0
@ -300,12 +306,11 @@ void Capturer::configFPGAParam(bool iscorrect, int mode)
// val+=step;
// exp_ratio += 0.1;
// printf("\n\n\n----------------\n");
// for (int i = 0; i < 2; i++)
// {
// for (int j = 0; j < 6; j++)
// {
// offsets[i][j]=j==4?200:0;
// printf("gains[%d][%d] = %d \r\n", i, j, gains[i][j]);
// printf("offsets[%d][%d] = %d \r\n", i, j, offsets[i][j]);
// if (j < 3)
@ -348,6 +353,8 @@ void Capturer::setFGPAParmas(int exposures[2][3], int gains[2][6], int offsets[2
void *Capturer::readFrame(int timeout)
{
auto ret= video->read_frame(timeout);
unsigned int val;
//fpgaComm->update();
return ret;
}

View File

@ -11,7 +11,7 @@ class Capturer : public ICapturer
public:
Capturer();
virtual ~Capturer();
virtual void Fpga_regsAccess_reset(bool enable);
virtual void open();
virtual void open(HGScanConfig config,FPGAConfigParam fpgaparam);
virtual void close();

View File

@ -54,6 +54,7 @@ std::vector<FPGAConfigParam> CorrectParam::GetCorrectParams()
std::ifstream i(JSONPATH);
json j;
i >> j;
i.close();
std::vector<FPGAConfigParam> vct_param;
for (json::iterator it = j.begin(); it != j.end(); ++it)
{
@ -114,6 +115,7 @@ void CorrectParam::SaveCorrectParam(FPGAConfigParam& parms)
}
ofstream ofs(JSONPATH);
ofs << std::setw(4) << j << std::endl;
ofs.close();
}
void CorrectParam::initdefaultpapram()
@ -129,11 +131,7 @@ void CorrectParam::initdefaultpapram()
//彩色 300 dpi
param.ColorMode = 1;//彩色
param.DpiMode = 2;//300 dpi
#ifdef G200
param.MaxBright = 190;
#else
param.MaxBright = 200;
#endif
param.MaxExp = 1100;
param.HRatio = 1065353216;
param.VRatio = 1065353216;
@ -155,7 +153,7 @@ void CorrectParam::initdefaultpapram()
//灰度 300 dpi
param.ColorMode = 0;//灰度
param.MaxBright = 200;
param.MaxBright = 220;
param.LutPath = LUT300GRAYPATH;
param.TextLutPath = TEXTLUT300GRAYPATH;
param.Flat_BwPath = LUT300_GRAY_BLACKPATH;
@ -164,11 +162,7 @@ void CorrectParam::initdefaultpapram()
js.push_back(t_j);
//彩色 200 dpi
#ifdef G200
param.MaxBright = 190;
#else
param.MaxBright = 200;
#endif
param.ColorMode = 1;//彩色
param.DpiMode = 1;//200 dpi
param.LutPath = LUT200COLORPATH;
@ -186,7 +180,7 @@ void CorrectParam::initdefaultpapram()
js.push_back(t_j);
//灰度 200dpi
param.MaxBright = 200;
param.MaxBright = 220;
param.ColorMode = 0;//灰度
param.LutPath = LUT200GRAYPATH;
param.TextLutPath = TEXTLUT200GRAYPATH;
@ -196,11 +190,7 @@ void CorrectParam::initdefaultpapram()
js.push_back(t_j);
//彩色 600 dpi
#ifdef G200
param.MaxBright = 190;
#else
param.MaxBright = 200;
#endif
param.ColorMode = 1;//彩色
param.DpiMode = 0x03;//200 dpi
param.LutPath = LUT600COLORPATH;
@ -220,7 +210,7 @@ void CorrectParam::initdefaultpapram()
//灰度 600dpi
param.MaxBright = 200;
param.MaxBright = 220;
param.ColorMode = 0;//灰度
param.LutPath = LUT600GRAYPATH;
param.TextLutPath = TEXTLUT600GRAYPATH;
@ -231,6 +221,7 @@ void CorrectParam::initdefaultpapram()
std::ofstream ofs(JSONPATH);
ofs << std::setw(4) << js << std::endl;
ofs.close();
}
}
}

View File

@ -17,7 +17,7 @@
FpgaComm::FpgaComm()
{
m_regsAccess.reset(new UartRegsAccess(MOTOR_UART, 921600, 0x03, 0x83));
m_regsAccess.reset(new UartRegsAccess(FPGA_UART, 921600, 0x03, 0x83));
update(0);
Reg(AledR).sample = 256;
@ -29,7 +29,7 @@ void FpgaComm::regsAccess_reset(bool enable){
if(enable)
{
if(!m_regsAccess.get())
m_regsAccess.reset(new UartRegsAccess(MOTOR_UART, 921600, 0x03, 0x83));
m_regsAccess.reset(new UartRegsAccess(FPGA_UART, 921600, 0x03, 0x83));
update(0);
return;
}
@ -38,11 +38,15 @@ void FpgaComm::regsAccess_reset(bool enable){
}
bool FpgaComm::read(unsigned int addr, unsigned int& val) {
return m_regsAccess->read(addr, val);
if(m_regsAccess.get())
return m_regsAccess->read(addr, val);
return false;
}
bool FpgaComm::write(unsigned int addr, unsigned int val) {
return m_regsAccess->write(addr, val);
if(m_regsAccess.get())
return m_regsAccess->write(addr, val);
return false;
}
void FpgaComm::setFrameHeight(int height){
@ -377,14 +381,10 @@ void FpgaComm::setEnTestBit(bool en)
void FpgaComm::setVsp(unsigned int Aside,unsigned int BSide)
{
unsigned int regv;
CISVSP vsp;
read(13,regv);
vsp.value = regv;
vsp.bits.ASide_VSP = Aside;
vsp.bits.BSide_VSP = BSide;
vsp.bits.reserved=0;
printf("setVsp A side =%d B side=%d vspint=%08x \n", vsp.bits.ASide_VSP, vsp.bits.BSide_VSP,vsp.value);
write(13,vsp.value);
WR_Reg(AledR);
m_regsAccess->write(13,vsp.value);
}

View File

@ -93,7 +93,16 @@ typedef struct CIS_LED_UV
unsigned short int ledBSide;
} CisLedUv;
typedef union CIS_VSP
{
struct
{
unsigned int ASide_VSP:8;
unsigned int BSide_VSP:8;
unsigned int reserved : 16;
} bits;
int value;
} CISVSP;
typedef union Fpga_Params
{
@ -122,17 +131,6 @@ typedef union Fpga_Params
} FpgaParams;
typedef union CIS_VSP
{
struct
{
unsigned int ASide_VSP:8;
unsigned int BSide_VSP:8;
unsigned int reserved : 16;
} bits;
int value;
} CISVSP;
class FpgaComm : public IRegsAccess
{
public:
@ -189,10 +187,9 @@ public:
void update(int times);
void enableJamCheck(bool b);
void resetADC();
void setVsp(unsigned int Aside,unsigned int BSide);
virtual bool write(unsigned int addr, unsigned int val);
virtual bool read(unsigned int addr, unsigned int& val);
void setVsp(unsigned int Aside,unsigned int BSide);
private:
FpgaParams fpgaParams;
std::shared_ptr<IRegsAccess> m_regsAccess;

View File

@ -0,0 +1,105 @@
#pragma once
#include <memory>
#include <vector>
#include <opencv2/opencv.hpp>
std::vector<double> caculate_abcd(std::vector<std::pair<double, double>> point)
{
int MaxElement = point.size() - 1;
//计算常数f
double f = point[0].second;
//求解
int n, m;
std::vector<std::vector<double>> a;
for (int i = 0; i < MaxElement; i++)
{
std::vector<double> b;
b.resize(MaxElement + 1);
a.push_back(b);
}
for (int i = 0; i < MaxElement; i++)
{
for (int j = 0; j < MaxElement; j++)
a[i][j] = pow(point[i + 1].first, MaxElement - j);
a[i][MaxElement] = point[i + 1].second - f;
}
int i, j;
n = MaxElement;
for (j = 0; j < n; j++)
{
double max = 0;
double imax = 0;
for (i = j; i < n; i++)
{
if (imax < fabs(a[i][j])) {
imax = fabs(a[i][j]);
max = a[i][j];//得到各行中所在列最大元素
m = i;
}
}
if (fabs(a[j][j]) != max)
{
double b = 0;
for (int k = j; k < n + 1; k++) {
b = a[j][k];
a[j][k] = a[m][k];
a[m][k] = b;
}
}
for (int r = j; r < n + 1; r++)
{
a[j][r] = a[j][r] / max;//让该行的所在列除以所在列的第一个元素目的是让首元素为1
}
for (i = j + 1; i < n; i++)
{
double c = a[i][j];
if (c == 0.0) continue;
for (int s = j; s < n + 1; s++) {
a[i][s] = a[i][s] - a[j][s] * c;//前后行数相减使下一行或者上一行的首元素为0
}
}
}
for (i = n - 2; i >= 0; i--)
{
for (j = i + 1; j < n; j++)
{
a[i][n] = a[i][n] - a[j][n] * a[i][j];
}
}
std::vector<double> result;
for (int k = 0; k < n; k++)
result.push_back(a[k][n]);
result.push_back(f);
return result;
}
double caculate_value(const std::vector<double>& abcd, double x)
{
return abcd[0] * x * x * x + abcd[1] * x * x + abcd[2] * x + abcd[3];
}
void brightness(cv::Mat& lut, int alpha = 170)
{
std::vector<std::pair<double, double>> pos;
pos.push_back(std::pair<double, double>(0, 0));
pos.push_back(std::pair<double, double>(64, 64));
pos.push_back(std::pair<double, double>(alpha, 255));
pos.push_back(std::pair<double, double>(255, 255));
std::vector<double> abcd = caculate_abcd(pos);
uchar table[256];
for (int i = 0; i < 256; i++)
table[i] = static_cast<uchar>(caculate_value(abcd, i));
uchar* ptr = lut.data;
for (int i = 0, length = lut.total() * lut.channels(); i < length; i++)
ptr[i] = table[ptr[i]];
}

View File

@ -7,10 +7,12 @@
#include "commondef.h"
#include "CorrectParam.h"
class ICapturer
{
public:
virtual ~ICapturer() {}
virtual void Fpga_regsAccess_reset(bool enable) = 0;
virtual void open() = 0;
virtual void open(HGScanConfig config,FPGAConfigParam fpgaparam) = 0;
virtual void close() = 0;

View File

@ -10,9 +10,6 @@
#include "stringex.hpp"
#include "filetools.h"
#include "CImageMerge.h"
#include "commondef.h"
#include "hgutils.h"
#include "dailex.hpp"
#include "jsonconfig.h"
#include "ThreadPool.h"
@ -52,7 +49,8 @@ MonoCapturer::MonoCapturer() : vdd_cis_3voff_pin(new GpioOut(CIS_3v3_Off)),
fpgaLoad(new Gpio(70)),
fpga_conf_done(new Gpio(69)),//gpio init 导出 scanservice 仅操作IO
fpga_conf_initn(new Gpio(71)),//gpio init 导出 scanservice 仅操作IO
bcorrecting(false)
bcorrecting(false),
m_fpgaversion(0x00090001)
{
LOG_INIT();
fpga_conf_done->setDirection(Gpio::in);
@ -62,7 +60,7 @@ MonoCapturer::MonoCapturer() : vdd_cis_3voff_pin(new GpioOut(CIS_3v3_Off)),
fpgaComm->setDelayTime(0X3e8);
// fpgaComm->update();
video.reset(new VIDEO_CLASS());
// GetFpgaparam(0x01,0);
fpgaComm->read(15,m_fpgaversion);
}
MonoCapturer::~MonoCapturer()
@ -77,12 +75,16 @@ void MonoCapturer::open()
{
}
void MonoCapturer::Fpga_regsAccess_reset(bool enable){
if(fpgaComm.get())
fpgaComm->regsAccess_reset(enable);
fpgaComm->update(0);
}
void MonoCapturer::open(HGScanConfig config,FPGAConfigParam fpgaparam)
{
fpgaComm->update(1);
// reset_pin->setValue(Gpio::Low);
// std::this_thread::sleep_for(std::chrono::milliseconds(50));
// reset_pin->setValue(Gpio::High);
bool dunnancis = true;
int dpi;
if (dunnancis)
@ -95,6 +97,7 @@ void MonoCapturer::open(HGScanConfig config,FPGAConfigParam fpgaparam)
int channels = mode == 0x01 ? 3 : 1;
int width = channelwidth * channels;
auto phyHeight = paperHeight[(PaperSize)config.g200params.paper];
printf("\n ########## phyHeight = %d ",phyHeight);
int pixheight; // = ((int)((phyHeight / 25.4 * (dpi == 0x02 ? 300 : (dpi == 0x03 ? 600 : 200)) + 2) / 3)) * 3 * 2;
if (dunnancis)
{
@ -111,39 +114,18 @@ void MonoCapturer::open(HGScanConfig config,FPGAConfigParam fpgaparam)
int dstheight = pixheight;
int fpgaheight = mode == 0x1 ? dstheight / 2 * 3 : dstheight / 2; //彩色配置fpga 高度要为目标图像高度的3倍
//FPGAConfigParam fpgaparam = GetFpgaparam(config.g200params.dpi, mode);// == 0x02 ? 2 : (config.g200params.dpi == 0x03 ? 3 : 2)
//fpgaparam = GetFpgaparam(config.g200params.dpi, mode);// == 0x02 ? 2 : (config.g200params.dpi == 0x03 ? 3 : 2)
// FPGAConfigParam fpgaparam = GetFpgaparam(dpi, mode);
printf("dpi = %d fpgaparam.sp=%d exp=%d gain=%d offset=%d LUT=%s \n", dpi, fpgaparam.Sp, fpgaparam.ExposureB[0], fpgaparam.GainB[0], fpgaparam.OffsetB[0], fpgaparam.LutPath.c_str());
// int startsample= cistype.GetCisType()==CISVendor::DUNNAN_CIS_V0?205:262;
#ifdef G300
int startsample = 202;
dpi = 0;
width = 1728;
if (papersMap.count((PaperSize)config.g200params.paper) > 0)
{
dstheight = papersMap[(PaperSize)config.g200params.paper].height;
}
else
{
dstheight = papersMap[PaperSize::G400_A4].height; //不区分G300 G400
}
dstheight = config.g200params.color ? dstheight : dstheight /3;
if(config.g200params.dpi != 1)
dstheight = std::min(16002,dstheight*3/2);
fpgaheight = dstheight;
#else
int startsample = 208;
std::uint32_t m_fpgaversion = 0;
fpgaComm->read(15,m_fpgaversion);
if(Dail().GetValue().dails.in_voltage3 == 0)
startsample = 262;
int startsample = 205;
uint tmp_vs = 0;
fpgaComm->read(15,tmp_vs);
if(tmp_vs >= 0x90002)
startsample = 205;
else
startsample = m_fpgaversion == 0x90002? 205 : 208;
#endif
startsample = 208;
float v_ratio = *((float*)(&fpgaparam.VRatio));
fpgaparam.Sp /= v_ratio;
printf("\n apply sp = %d, v_ratio =%f",fpgaparam.Sp,v_ratio);
ModeFpga fpgamod = {
.colorMode = mode,
.dpi = dpi,
@ -155,15 +137,14 @@ void MonoCapturer::open(HGScanConfig config,FPGAConfigParam fpgaparam)
.sp = fpgaparam.Sp}; // 600DPI 0x1450 300DPI 0xe10
fpgaComm->setRegs(0x01, *((int *)(&fpgamod)));
fpgaComm->setSample(startsample);
if(tmp_vs != 0x9000a)
fpgaComm->setVsp(2,2);
else{
fpgaComm->setVsp(80,120);
}
fpgaComm->enableLed(true);
fpgaComm->setEnTestCol(false);
fpgaComm->setEnTestBit(false);
auto vsp_value = jsonconfig().getscannerinfo();
if(vsp_value.clr_maxbright > 20 || vsp_value.clr_maxbright < 1)
vsp_value.clr_maxbright = 2;
if(vsp_value.gray_maxbright > 20 || vsp_value.gray_maxbright < 1)
vsp_value.gray_maxbright = 2;
fpgaComm->setVsp(vsp_value.clr_maxbright,vsp_value.gray_maxbright);
// fpgaComm->update(2);
configFPGAParam(mode, config.g200params.dpi);
// fpgaComm->update(3);
@ -195,11 +176,6 @@ void MonoCapturer::close()
//fpga_reload();
}
void MonoCapturer::Fpga_regsAccess_reset(bool enable){
if(fpgaComm.get())
fpgaComm->regsAccess_reset(enable);
}
void MonoCapturer::start()
{
if (video.get())
@ -232,32 +208,25 @@ int MonoCapturer::getautosizeheight()
unsigned int reg8 = 0;
fpgaComm->read(8, reg8);
// std::cout << "1 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
// fpgaComm->update(4);
fpgaComm->read(14, val);
int regv = val;
val &= 0x0000ffff;
// std::cout << string_format("ONE height = %d reg[14] = %d \n", val, regv);
// fpgaComm->update(5);
fpgaComm->write(8, reg8 & 0xfffffff7);
// std::cout << string_format("ONE reg[8] = %d \n", reg8 & 0xfffffff7);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
// fpgaComm->update(6);
fpgaComm->read(14, val);
regv = val;
val &= 0x0000ffff;
fpgaComm->read(8, reg8);
// std::cout << "2 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
std::cout << string_format("TWO height = %d reg[14] = %d \n", val, regv);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
fpgaComm->write(8, reg8 | 0x8);
// fpgaComm->write(8,0x02260008);
// fpgaComm->update(7);
// fpgaComm->read(8, reg8);
// std::cout << "2 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
return val;
// return fpgaComm->getFrameHeight();
return val;
}
void MonoCapturer::set_size(int width, int height)
{
@ -343,15 +312,11 @@ void MonoCapturer::reset()
int MonoCapturer::width()
{
#ifdef G300
return 1728;
#else
int dpi = fpgaComm->getDpi();
int channel = 1;
int width = dpi == 0x02 ? 1296 * channel : (dpi == 0x03 ? (2592 * channel) : (864 * channel));
// printf("get width = %d \n", width);
return width;
#endif
}
int MonoCapturer::height()
@ -366,14 +331,15 @@ int MonoCapturer::color()
void MonoCapturer::init_autocorrect(int colormode)
{
std::thread t_correctthread = std::thread(&MonoCapturer::correctcolor, this);
std::thread t_correctthread = std::thread(&MonoCapturer::correctcolor, this,colormode);
t_correctthread.detach();
}
void MonoCapturer::configFPGAParam(int mode, int dpi)
{
printf("dpi = %d mode = %d \n", dpi, mode);
//fpgaComm->resetADC();
fpgaComm->resetADC();
FPGAConfigParam fpgaparam = GetFpgaparam(dpi, mode);
// int offF[6]={0,0,0,0,0,200};
// int offB[6]={0,0,0,0,0,0};
@ -390,7 +356,7 @@ void MonoCapturer::configFPGAParam(int mode, int dpi)
printf("fpgaparam.ExposureB[%d] = %d \n", i, fpgaparam.ExposureB[i % 3]);
}
std::this_thread::sleep_for(std::chrono::milliseconds(3));
std::this_thread::sleep_for(std::chrono::milliseconds(2));
fpgaComm->setAOffset(i, fpgaparam.OffsetF[i]);
// fpgaComm->setAOffset(i,offF[i]);
printf("fpgaparam.setAOffset[%d] = %d \n", i, fpgaparam.OffsetF[i]);
@ -413,6 +379,7 @@ void MonoCapturer::openDevice(int dpi, int mode)
// reset_pin->setValue(Gpio::Low);
// std::this_thread::sleep_for(std::chrono::milliseconds(50));
// reset_pin->setValue(Gpio::High);
fpgaComm->read(15,m_fpgaversion);
int config_dpi = dpi == 1 ? 2 : dpi;
int channelwidth = config_dpi == 0x02 ? 1296 : (config_dpi == 0x03 ? 2592 : 864);
int channels = mode == 0x01 ? 3 : 1;
@ -421,26 +388,15 @@ void MonoCapturer::openDevice(int dpi, int mode)
int fpgaheight = mode == 0x1 ? dstheight / 2 * 3 : dstheight; //彩色配置fpga 高度要为目标图像高度的3倍
FPGAConfigParam fpgaparam = GetFpgaparam(dpi, mode);
#ifdef G300
int startsample = 202;
config_dpi = 0;
width = 1728;
dstheight = mode ? 6000 : 2000;
fpgaheight = dstheight;
#else
int startsample = 208;
std::uint32_t m_fpgaversion = 0;
fpgaComm->read(15,m_fpgaversion);
if(Dail().GetValue().dails.in_voltage3 == 0)
startsample = 262;
else
startsample = m_fpgaversion == 0x90002? 205 : 208;
#endif
printf("fpgaparam.sp=%d exp=%d gain=%d offset=%d LUT=%s", fpgaparam.Sp, fpgaparam.ExposureB[0], fpgaparam.GainB[0], fpgaparam.OffsetB[0], fpgaparam.LutPath.c_str());
// int startsample= cistype.GetCisType()==CISVendor::DUNNAN_CIS_V0?205:262;
float v_ratio = *((float*)(&fpgaparam.VRatio));
fpgaparam.Sp *= v_ratio;
printf("\n openDevice apply sp = %d, v_ratio =%f",fpgaparam.Sp,v_ratio);
int startsample = 205;
uint tmp_vs = 0;
fpgaComm->read(15,tmp_vs);
if(tmp_vs >= 0x90002)
startsample = 205;
else
startsample = 208;
ModeFpga fpgamod = {
.colorMode = mode,
.dpi = config_dpi,
@ -455,12 +411,24 @@ void MonoCapturer::openDevice(int dpi, int mode)
fpgaComm->enableLed(true);
fpgaComm->setEnTestCol(false);
fpgaComm->setEnTestBit(false);
auto vsp_value = jsonconfig().getscannerinfo();
if(vsp_value.clr_maxbright > 20 || vsp_value.clr_maxbright < 1)
vsp_value.clr_maxbright = 2;
if(vsp_value.gray_maxbright > 20 || vsp_value.gray_maxbright < 1)
vsp_value.gray_maxbright = 2;
fpgaComm->setVsp(vsp_value.clr_maxbright,vsp_value.gray_maxbright);
if(tmp_vs != 0x9000a)
fpgaComm->setVsp(2,2);
else
{
// ifstream iF("/home/vspF");
// ifstream iB("/home/vspB");
// int vspF,vspB;
// iF >> vspF;
// iB >> vspB;
// if(vspF ==0 || vspB == 0)
// {
// vspF = 75;
// vspB = 85;
// }
// printf("!!!!!!!!!!! vspF=%d vspB = %d \n",vspF,vspB);
// fpgaComm->setVsp(vspF,vspB);
fpgaComm->setVsp(80,120);
}
configFPGAParam(mode, dpi);
video->open(width, dstheight); // 300dpi 7344/2 600dpi 7344
@ -478,12 +446,11 @@ void MonoCapturer::openDevice(int dpi, int mode)
void MonoCapturer::creatcorrectconfig(int dpi, int mode)
{
printf(" opendevice");
openDevice(dpi, mode);
printf(" opendevice end ");
bool isDone = false;
int i = 1;
initStep1();
while (!isDone) //先暗场
{
string log = "==============================第" + to_string(i) + "次===============================";
@ -513,6 +480,7 @@ void MonoCapturer::creatcorrectconfig(int dpi, int mode)
i++;
}
printf("creatcorrectconfig %s \n", (mode == IMAGE_COLOR ? " Color" : " Gray"));
//creatLUTData(dpi, mode);
video->close();
}
@ -521,20 +489,12 @@ static int savelutindex = 0;
bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
{
int config_dpi = dpi == 1 ? 2 : dpi;
#ifdef G300
int offset_indexs[] = {3, 4, 5, 2, 1, 0, 0, 1, 2, 5, 4, 3};
#else
int offset_indexs[] = {0, 1, 2, 5, 4, 3, 3, 4, 5, 2, 1, 0};
#endif
int channels = mode == IMAGE_COLOR ? 3 : 1;
int height = 100;
int width = config_dpi == 0x02 ? 1296 : (config_dpi == 0x03 ? 2592 : 864);
int orgimgwidth = width * 2 * 3 * channels;
int dstwidth = width * 2 * 3;
#ifdef G300
orgimgwidth = 1728 * channels * 3;
height = 6000 / 9 *3 ;
#endif
bool isNeedSave = true;
string log;
void *data = video->read_frame(10000);
@ -548,14 +508,11 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
return isNeedSave;
}
cv::Mat src(height, orgimgwidth, CV_8UC1, data);
//cv::imwrite(std::to_string(savelutindex++) + ".jpg", src);
#ifdef G300
cv::Mat mrgmat = GetStitchMat(mode ==1?1:0,orgimgwidth,height,src);
#else
// cv::imwrite(std::to_string(savelutindex++) + ".jpg", src);
CImageMerge t_marge;
cv::Mat mrgmat = t_marge.MergeImage(mode == 0x01, src, dstwidth, height,0x90001);
#endif
cv::Mat mrgmat = t_marge.MergeImage(mode == 0x01, src, dstwidth, height,m_fpgaversion);
mrgmat = mrgmat(cv::Rect(0,20,mrgmat.cols,mrgmat.rows-20));
// cv::imwrite(std::to_string(savelutindex++) + "mrg.jpg", mrgmat);
// return false;
FPGAConfigParam param = GetFpgaparam(dpi, mode);
@ -563,11 +520,11 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
{
double offValues[12];
std::vector<bool> bflags;
for (volatile int n = 0; n < 2; n++)
for (int n = 0; n < 2; n++)
{
cv::Mat img = mrgmat(cv::Rect(mrgmat.cols * n / 2, 10, mrgmat.cols / 2, mrgmat.rows - 10)).clone();
int offset_total = 0;
for (volatile int s = 0; s < 6; s++) //
for (int s = 0; s < 6; s++) //
{
int k = n * 6 + s;
int offset_wdth;
@ -579,9 +536,7 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
{
offset_wdth = config_dpi == 0x03 ? 1296 : (config_dpi == 0x02 ? 648 : 432);
}
#ifdef G300
offset_wdth =432;
#endif
double min,max;
//auto t_mat= img(cv::Rect(offset_total, 10, offset_wdth, img.rows - 10));
//cv::minMaxLoc(t_mat,&min,&max);
@ -589,7 +544,6 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
//printf("AAAAAAAAAAAAAAAAAAAAAAAAAAA min = %.2f max= %.2f mean = %0.2f \n",min,max);
offset_total += offset_wdth;
offValues[k] = mean.val[0];
printf("\noffValues[%d] = %f",k,mean.val[0]);
bflags.push_back(false);
//offValues[k] = min;
}
@ -597,7 +551,7 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
// std::string clrmode = (mode == 0x01 ? "彩色" : " 灰度");
// log = "开始" + clrmode + "暗场校正 \n";
for (volatile int s = 0; s < 2; s++)
for (int s = 0; s < 2; s++)
{
int offsets[6]; // = (int *)(s == 0 ? &param.OffsetF[0] : &param.OffsetB[0]);
memcpy(offsets, (s == 0 ? &param.OffsetF[0] : &param.OffsetB[0]), sizeof(param.OffsetF));
@ -696,6 +650,7 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
log = "开始彩色明场校正 \r\n";
if (m_captureCallback)
m_captureCallback(mode, log);
double coefficient[3] ={ 1.2,0.6,1.2};
for (int s = 0; s < 2; s++)
{
int exposures[3]; // = (int *)(s == 0 ? param.ExposureF : param.ExposureB);
@ -704,12 +659,14 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
{
int k = (3 * s + x);
int diff = LIGHT_DIFF(param.MaxBright, *((double *)values + k));
//int diff = LIGHT_DIFF(param.MaxBright,((values[s][0]*coefficient[0]+values[s][1]*coefficient[1]+values[s][2]*coefficient[2])/3.0));
log += " 明场:" + std::to_string(k) + ";diff" + std::to_string(diff) + "\r\n";
if(abs(diff) > 30)
radio = 2;
else
radio = 1;
double step = diff * radio;
//double step = diff / coefficient[x];
int preStep = *((int *)expStep + k);
if (step * preStep < 0)
{
@ -752,6 +709,7 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
if (m_captureCallback)
m_captureCallback(mode, log);
// log ="";
//imwrite("/home/linaro/"+to_string(dpi)+"color.jpg", mrgmat);
imwrite(param.Flat_WhitePath, mrgmat);
}
}
@ -804,7 +762,8 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
if (exp >(param.Sp -5))
exp = (param.Sp -5);
float coffe[3] = {1, 1, 1}; // 0.2, 1,0.51
//float coffe[3] = {0.8, 1, 1}; // 0.2, 1,0.51
float coffe[3] = {1,1,1};
for (int k = 0; k < 3; k++)
{
*(exposures + k) = (int)(exp * coffe[k]);
@ -836,60 +795,88 @@ bool MonoCapturer::saveLutImg(int dpi, int mode, bool black)
return isNeedSave;
}
void MonoCapturer::correctcolor()
void MonoCapturer::correctcolor(int correctmode)
{
printf(" correctcolor start \n");
auto _start = std::chrono::steady_clock::now();
ThreadPool pool(2);
std::queue<std::future<void>> fu_correct;
std::string loginfo = "Start Correctcolor 200DPI COLOR \r\n";
// if (m_captureCallback)
// m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x01, IMAGE_COLOR);
auto param = GetFpgaparam(0x01,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x01,IMAGE_COLOR,param);}));
loginfo = "-----------200DPI COLOR Correct Done----------- \r\n\r\n Start Correctcolor 200DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x01, IMAGE_GRAY);
param = GetFpgaparam(0x01,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x01,IMAGE_GRAY,param);}));
loginfo = "-----------200DPI Gray Correct Done----------- \r\n\r\n Start Correctcolor 200DPI COLOR \r\n";
if (m_captureCallback)
m_captureCallback(0x02, loginfo);
creatcorrectconfig(0x02, IMAGE_COLOR);
param = GetFpgaparam(0x02,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x02,IMAGE_COLOR,param);}));
loginfo = "-----------300DPI COLOR Correct Done----------- \r\n\r\n Start Correctcolor 300DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x02, loginfo);
creatcorrectconfig(0x02, IMAGE_GRAY);
param = GetFpgaparam(0x02,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x02,IMAGE_GRAY,param);}));
loginfo = "-----------300DPI Gray Correct Done----------- \r\n\r\n Start Correctcolor 600DPI COLOR \r\n";
#ifndef G300
if((correctmode == 0) || (correctmode == 2)){
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x01, IMAGE_COLOR);
auto param = GetFpgaparam(0x01,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x01,IMAGE_COLOR,param);}));
loginfo = "-----------200DPI COLOR Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
}
if((correctmode == 0) || (correctmode == 1)){
loginfo = "Start Correctcolor 200DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x01, IMAGE_GRAY);
auto param = GetFpgaparam(0x01,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x01,IMAGE_GRAY,param);}));
loginfo = "-----------200DPI Gray Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x02, loginfo);
}
if((correctmode == 0) || (correctmode == 4)){
loginfo = "Start Correctcolor 300DPI COLOR \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x02, IMAGE_COLOR);
auto param = GetFpgaparam(0x02,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x02,IMAGE_COLOR,param);}));
loginfo = "-----------300DPI COLOR Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x02, loginfo);
}
if((correctmode == 0) || (correctmode == 3)){
loginfo = "Start Correctcolor 300DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x02, IMAGE_GRAY);
auto param = GetFpgaparam(0x02,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x02,IMAGE_GRAY,param);}));
loginfo = "-----------300DPI Gray Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
}
if((correctmode == 0) || (correctmode == 6)){
loginfo = "Start Correctcolor 600DPI COLOR \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x03, IMAGE_COLOR);
auto param = GetFpgaparam(0x03,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x03,IMAGE_COLOR,param);}));
loginfo = "-----------600DPI COLOR Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
}
if((correctmode == 0) || (correctmode == 5)){
loginfo = "Start Correctcolor 600DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x01, loginfo);
creatcorrectconfig(0x03, IMAGE_GRAY);
auto param = GetFpgaparam(0x03,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x03,IMAGE_GRAY,param);}));
loginfo = "-----------600DPI Gray Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
}
if((correctmode < 0) || (correctmode > 6)){
loginfo = "不支持的校正模式...\r\n";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
creatcorrectconfig(0x03, IMAGE_COLOR);
param = GetFpgaparam(0x03,IMAGE_COLOR);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x03,IMAGE_COLOR,param);}));
loginfo = "-----------600DPI COLOR Correct Done----------- \r\n\r\n Start Correctcolor 600DPI GRAY \r\n";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
creatcorrectconfig(0x03, IMAGE_GRAY);
param = GetFpgaparam(0x03,IMAGE_GRAY);
fu_correct.emplace(pool.enqueue([param](){creatLUTData(0x03,IMAGE_GRAY,param);}));
loginfo = "-----------600DPI Gray Correct Done----------- \r\n\r\n ";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
#endif
}
while(fu_correct.size())
{
fu_correct.front().get();
fu_correct.pop();
}
loginfo = "******Correct Done****** time " + std::to_string(std::chrono::duration<double>(std::chrono::steady_clock::now() - _start).count())+"s";
loginfo = "******Correct Done****** " +std::to_string( std::chrono::duration<double>(std::chrono::steady_clock::now() - _start).count()) +"s";
if (m_captureCallback)
m_captureCallback(0x03, loginfo);
}

View File

@ -41,12 +41,13 @@ public:
m_captureCallback = callback;
};
virtual void Fpga_regsAccess_reset(bool enable);
private:
void configFPGAParam(int mode, int dpi);
void openDevice(int dpi, int mode);
void creatcorrectconfig(int dpi, int mode);
bool saveLutImg(int dpi, int mode, bool black);
void correctcolor();
void correctcolor(int correctmode);
void fpga_reset();
void fpga_reload();
@ -64,4 +65,5 @@ private:
std::shared_ptr<Gpio> fpga_conf_done;
bool bcorrecting;
std::thread m_correctthread;
unsigned int m_fpgaversion;
};

View File

@ -149,8 +149,8 @@ std::string SysInforTool::GetSysInfo()
m_sysinfo.CPU = SCPU::CPU_3399;
printf("Machine = %s CPU = %s \n", "Sys_Linux_Debian","CPU_3399");
}
m_sysinfo.MtType = SMBType::MB_DRV_8825;
m_sysinfo.Cistype = HGCISType::CIS_DUNNAN_MONO_V0;
m_sysinfo.MtType = SMBType::MB_DRV_ANLU;
char output[512];
get_system_output("uname -a",output,sizeof(output));
std::string ver(output);
@ -160,6 +160,7 @@ std::string SysInforTool::GetSysInfo()
struct2json(j,m_sysinfo);
std::ofstream o("/usr/local/huago/sysinfo.json");
o << std::setw(4) << j << std::endl;
o.close();
return j.dump();
}

View File

@ -37,11 +37,7 @@ cv::Mat extractRepresentRow2(const cv::Mat &src)
return BWbalenceSrc;
}
#ifdef G300
#define CHANNEL 432
#else
#define CHANNEL 408
#endif
cv::Mat loadLUT(const std::string& file)
{
cv::Mat dataFile = cv::imread(file, cv::IMREAD_ANYCOLOR);
@ -56,7 +52,7 @@ cv::Mat loadLUT(const std::string& file)
else if (step == 14688 ||step== 22032 || step == 44064)
channel = 432; //486
#else
channel = CHANNEL;
channel = 408;
#endif
cv::Mat lut(step / channel, 256, CV_8UC(channel));
memcpy(lut.data, dataFile.data, total);
@ -108,6 +104,7 @@ void correctColor(cv::Mat& src, int dpi, int mode,bool isText)
if (access(path.c_str(), F_OK) != -1)
{
lutGrayMat = loadLUT(path);
//brightness(lutGrayMat);
}
else
{
@ -128,17 +125,12 @@ void correctColor(cv::Mat& src, int dpi, int mode,bool isText)
cv::LUT(image_temp(cv::Rect(i, 0, 1, image_temp.rows)), lutMat(cv::Rect(0, i, 256, 1)), image_temp(cv::Rect(i, 0, 1, image_temp.rows)));
}
void creatLUTData(int dpi , int mode,FPGAConfigParam param)
{
void creatLUTData(int dpi , int mode,FPGAConfigParam param){
printf("eneter creatLUTData \n");
auto colormode = mode == 1 ? IMREAD_COLOR : IMREAD_GRAYSCALE;
std::string blackPath = param.Flat_BwPath;
std::string whitePath = param.Flat_WhitePath;
std::string lutsavePath = param.LutPath;
printf("\n blackPath =%s \
whitePath =%s \
lutsavePath =%s \n",param.Flat_BwPath.c_str(),param.Flat_WhitePath.c_str(),param.LutPath.c_str());
cv::Mat lut;
cv::Mat twMat = cv::imread(whitePath, IMREAD_ANYCOLOR);
cv::Mat tbMat = cv::imread(blackPath, IMREAD_ANYCOLOR);
@ -244,6 +236,7 @@ void fittingLUT(const std::vector<uchar>& points, uchar min_value, uchar max_val
}
}
#define CHANNEL 408
cv::Mat calcLUT(const cv::Mat& black, const cv::Mat& white, bool isTextCorrection)
{
std::vector<cv::Mat> w;
@ -410,7 +403,7 @@ cv::Mat createLUT(const std::vector<cv::Mat>& mats, bool isTextCorrect)
}
if (isTextCorrect)
{
std::vector<double> points_x = { 0, 25, 230, 255 }, points_y = { 0, 0, 255, 255 };
std::vector<double> points_x = { 0, 25, 205, 255 }, points_y = { 0, 0, 230, 255 };
std::vector<double> coefficient = caculate(points_x, points_y);
uchar buffer[256];

View File

@ -29,5 +29,3 @@ FPGAConfigParam GetFpgaparam(int dpi,int mode);
void SaveFpgaparam(FPGAConfigParam& param);
cv::Mat create_lut(const cv::Mat& black, const cv::Mat& white,int dpi, bool colormode);
void correctColor(cv::Mat& src, int dpi, int mode,bool isText);

View File

@ -172,7 +172,6 @@ void* GVideoISP1::read_frame(int timeout) {
LOG_TRACE(string_format("VIDIOC_QBUF sucess"));
}
LOG_TRACE(string_format("buf.index = %d,buf.addr = %p\n",buf.index,buffers[buf.index].start));
printf("\n readframe size = %d ",buffers[buf.index].length);
return buffers[buf.index].start;
}

View File

@ -289,36 +289,10 @@ cv::Mat GetMergeMat(cv::Mat& mat, int width, int height, int type)
return mat;
}
cv::Mat GetStitchMat(int pixtype,int width,int height,cv::Mat& mat){
cv::Mat dst;
cv::Mat ch_mats[3];
int dstwidth, dstheight;
width = width /3 /(pixtype == 1? 3:1);
height *=3;
dstwidth = width * 3;
dstheight = height / 3;
if (pixtype == IMAGE_COLOR)
{
//mat = cv::Mat(m_height / 3, m_width * 9, CV_8UC1, imgdata);
dst = cv::Mat(dstheight, dstwidth, CV_8UC3);
ch_mats[2] = mat(cv::Rect(width * 3 * 1, 0, width * 3, height / 3)); //R 对应红通道
ch_mats[1] = mat(cv::Rect(width * 3 * 2, 0, width * 3, height / 3)); //G 对应绿通道
ch_mats[0] = mat(cv::Rect(width * 3 * 0, 0, width * 3, height / 3)); //B 对应蓝通道
cv::merge(ch_mats, 3, dst);
for (int i = 0; i < 3; i++)
ch_mats[i].release();
return dst.clone();
}
else
{ //gray
return mat;
}
}
//3399 敦南cis 300 600 拼接算法
cv::Mat GetMergeMat(int dstwidth ,int dstheight,int type,cv::Mat& mat,std::uint32_t fpga_vs)
cv::Mat GetMergeMat(int dstwidth ,int dstheight,int type,cv::Mat& mat,unsigned int fpgaversion)
{
return CImageMerge().MergeImage(type==CV_8UC3,mat,dstwidth,dstheight,0x90001);
return CImageMerge().MergeImage(type==CV_8UC3,mat,dstwidth,dstheight,fpgaversion);
}
void savescannerinfo(ScannerNativeParam params)

View File

@ -19,9 +19,8 @@ cv::Mat GetMergeMat(void* data,int width ,int height,int type);
cv::Mat GetMergeMat(cv::Mat& mat,int width ,int height,int type);
cv::Mat GetMergeMat(int dstwidth ,int dstheight,int type,cv::Mat& mat,std::uint32_t fpga_vs);
cv::Mat GetStitchMat(int pixtype,int width,int height,cv::Mat& mat);
cv::Mat GetMergeMat(int dstwidth ,int dstheight,int type,cv::Mat& mat,unsigned int fpgaversion=0x00090001);
void correctColor(cv::Mat src, bool enhance);

View File

@ -77,6 +77,7 @@ void jsonconfig::savecisconfig(HGCorrectConfigs configs)
std::ofstream o(JSON_CORRECTFILE_PATH);
o << std::setw(4) << m_json << std::endl;
o.close();
}
HGCorrectConfigs jsonconfig::getcorrectconfigs()
@ -111,7 +112,7 @@ HGCorrectConfigs jsonconfig::getcorrectconfigs()
i.seekg(pos);
json m_json;
i >> m_json;
i.close();
cfs.colorCorrect.sp = cfs.color.sp = SP_COLOR_DEFAULT;
cfs.grayCorrect.sp = cfs.gray.sp = SP_GRAY_DEFAULT;
std::cout <<"GET GET GET GET GET GET" <<m_json << std::endl;
@ -226,15 +227,21 @@ void jsonconfig::savescannerinfo(ScannerNativeParam param)
m_json[S_INFO_SPEEDMODE] = (param.speedmode);
m_json[S_INFO_VID] = (param.Vid);
m_json[S_INFO_PID] = (param.Pid);
m_json[S_INFO_CHUZHI_MOTOR_SPEED_200] = (param.chu_motor_speed_200);
m_json[S_INFO_CHUZHI_MOTOR_SPEED_300] = (param.chu_motor_speed_300);
m_json[S_INFO_CHUZHI_MOTOR_SPEED_600] = (param.chu_motor_speed_600);
std::ofstream o(JSON_SCANNER_INFO_FILE);
o << std::setw(4) << m_json << std::endl;
//printf("\n %s speedmode value = %d",JSON_SCANNER_INFO_FILE,param.speedmode);
o.close();
printf("\n %s speedmode value = %d",JSON_SCANNER_INFO_FILE,param.speedmode);
}
ScannerNativeParam jsonconfig::getscannerinfo()
{
std::lock_guard<std::mutex> lc(mtx);
ScannerNativeParam snp;
if (access(JSON_SCANNER_INFO_DIR, 0) == -1)
{
auto ret = mkdir(JSON_SCANNER_INFO_DIR, 0777);
@ -243,14 +250,13 @@ ScannerNativeParam jsonconfig::getscannerinfo()
printf("make dir failed .path=%s \n", JSON_SCANNER_INFO_DIR);
}
}
if (access(JSON_SCANNER_INFO_FILE, F_OK) != 0)
if (access(JSON_SCANNER_INFO_FILE, 0) == -1)
{
printf("\nerror !!! file no exist");
snp = getdefaultscannerinfo();
savescannerinfo(snp);
return snp;
}
std::ifstream i(JSON_SCANNER_INFO_FILE);
auto pos = i.tellg();
@ -260,6 +266,7 @@ ScannerNativeParam jsonconfig::getscannerinfo()
//printf("file length =%d ", i.tellg());
if (i.tellg() <= 2)
{
printf("\nerror !!! file data error");
snp = getdefaultscannerinfo();
savescannerinfo(snp);
return snp;
@ -352,9 +359,9 @@ ScannerNativeParam jsonconfig::getscannerinfo()
if(!m_json[S_INFO_SPEEDMODE].is_null())
m_json[S_INFO_SPEEDMODE].get_to(snp.speedmode);
m_json[S_INFO_SPEEDMODE].get_to(snp.speedmode),printf("\n %s Get speedmode value = %d",JSON_SCANNER_INFO_FILE,snp.speedmode);
else
snp.speedmode=0;
snp.speedmode=0,printf("\n %s Get speedmode failed ",JSON_SCANNER_INFO_FILE);
if(!m_json[S_INFO_PID].is_null())
m_json[S_INFO_PID].get_to(snp.Pid);
@ -362,12 +369,8 @@ ScannerNativeParam jsonconfig::getscannerinfo()
{
#ifdef G100
snp.Pid = 0x139;
#elif defined G200
snp.Pid = 0x239;
#elif defined G300
snp.Pid = 0x339;
#else
snp.Pid = 0x439;
snp.Pid = 0x239;
#endif
}
@ -375,6 +378,21 @@ ScannerNativeParam jsonconfig::getscannerinfo()
m_json[S_INFO_VID].get_to(snp.Vid);
else
snp.Vid = 0x3072;
if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_200].is_null())
m_json[S_INFO_CHUZHI_MOTOR_SPEED_200].get_to(snp.chu_motor_speed_200);
else
snp.chu_motor_speed_200 = 300;
if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_300].is_null())
m_json[S_INFO_CHUZHI_MOTOR_SPEED_300].get_to(snp.chu_motor_speed_300);
else
snp.chu_motor_speed_300 = 200;
if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_600].is_null())
m_json[S_INFO_CHUZHI_MOTOR_SPEED_600].get_to(snp.chu_motor_speed_600);
else
snp.chu_motor_speed_600 = 100;
//printf("vid = %d pid =%d \n",snp.Vid,snp.Pid );
return snp;
@ -396,25 +414,17 @@ ScannerNativeParam jsonconfig::getdefaultscannerinfo()
param.color_sp=0x27C;
param.speedmode = 100;
param.Pid = 0x0239;
#elif defined G100
#else
param.gray_sp=0x822; //G200 140 ppm 0x27c 0x781 G100 100 ppm 0x2B6 0x822
param.color_sp=0x2B6;
param.speedmode = 70;
param.Pid = 0x0139;
#elif defined G300
param.gray_sp=0x822;
param.color_sp=0x2B6;
param.speedmode = 40;
param.Pid = 0x0339;
#else
param.gray_sp=0x822;
param.color_sp=0x2B6;
param.speedmode = 50;
param.Pid = 0x0439;
#endif
param.Vid = 0x3072;
param.sleeptime=10800;
param.clr_maxbright = param.gray_maxbright = 200;
param.chu_motor_speed_200 = 300;
param.chu_motor_speed_300 = 200;
param.chu_motor_speed_600 = 100;
return param;
}

View File

@ -2,7 +2,6 @@
#include "json.hpp"
#include "commondef.h"
#include <mutex>
using json = nlohmann::json;
class jsonconfig

View File

@ -1,6 +1,6 @@
#pragma once
#include <sstream>
#include "commondef.h"
enum class SysType
{
Sys_Linux_Debian=1,

View File

@ -5,6 +5,6 @@ target("capimage")
add_files("*.cpp")
add_deps("regs", "deviceio", "conf", "applog", {public = true})
add_includedirs(".", { public = true})
add_links("opencv_core", "opencv_imgcodecs", "opencv_highgui", "opencv_imgproc", { public = true })
add_links("opencv_core", "opencv_highgui", "opencv_imgproc", { public = true })
add_syslinks("pthread")
add_packages("common")

View File

@ -3,6 +3,7 @@
#include <fstream>
#include <memory>
#define G300
template <typename T>
void write_dev(std::string path, T value)
@ -20,7 +21,7 @@ enum PORTS
Start = 171,
Stop = 49,
Power = 5,
Fpga_Load = 8,
Fpga_Load = 70,
#ifndef G300
Power_12v_Off = 12,

View File

@ -4,6 +4,10 @@
#include "Gpio.h"
#include "DevUtil.h"
#include "stringex.hpp"
#include <sys/stat.h>
#include <unistd.h>
#include <linux/gpio.h>
#include <fcntl.h>
#define IOPATH "%s/gpio%d/%s"
@ -22,8 +26,16 @@ Gpio::Gpio(int port)
path_edge = string_format(IOPATH, path_gpiobase.c_str(), port, path_edge.c_str());
path_direction = string_format(IOPATH, path_gpiobase.c_str(), port, path_direction.c_str());
path_active_low = string_format(IOPATH, path_gpiobase.c_str(), port, path_active_low.c_str());
char fpath[128]{};
sprintf(fpath,"/sys/class/gpio/gpio%d/value",port);
printf("Gpio::Gpio(int port = %d) \n",port);
gpio_fd = open(fpath,O_RDWR);
}
Gpio::~Gpio()
{
close(gpio_fd);
}
int Gpio::getPort()
{
return port;
@ -31,7 +43,13 @@ int Gpio::getPort()
void Gpio::setValue(GpioLevel level)
{
write_dev(path_value, level);
//write_dev(path_value, level);
if(port == 153 || port == 150)
printf("\n Gpio %d setvalue %d ",port,level==Low?0:1);
if(level == Low)
write(gpio_fd,"0\n",2);
else
write(gpio_fd,"1\n",2);
}
Gpio::GpioLevel Gpio::getValue() {
@ -45,6 +63,8 @@ std::string Gpio::getDirection()
void Gpio::setDirection(std::string direction)
{
if(port == 153 || port == 150)
printf("\n Gpio %d setDirection %s ",port,direction.c_str());
write_dev(path_direction, direction);
}

View File

@ -11,6 +11,7 @@ public:
};
Gpio(int port);
~Gpio();
int getPort();
void setValue(GpioLevel level);
GpioLevel getValue();
@ -41,6 +42,7 @@ private:
std::string path_edge = "edge";
std::string path_direction = "direction";
std::string path_active_low = "active_low";
int gpio_fd;
};
class GpioOut : public Gpio

View File

@ -15,18 +15,6 @@ PinMonitor::PinMonitor(unsigned int pinNum, std::function<void(int)> call_back)
this->call_back = call_back;
thread_monitor = std::thread(&PinMonitor::monitor, this);
//printf("PinMonitor threadid = %d \n",thread_monitor.get_id());
sched_param thparm;
int priority=sched_get_priority_max(SCHED_FIFO);
if(priority==-1)
{
printf("sched_get_priority_max error \n");
}
thparm.sched_priority = priority;
if(pthread_setschedparam(thread_monitor.native_handle(),SCHED_FIFO,&thparm))
{
printf("failed to error set pthread_setschedparam \n");
}
}
PinMonitor::~PinMonitor()

View File

@ -11,7 +11,7 @@ public:
private:
void monitor();
//sched_param thparm;
Gpio pin;
std::function<void(unsigned int)> call_back;
std::thread thread_monitor;

View File

@ -5,5 +5,4 @@ target("deviceio")
add_syslinks("pthread")
add_files("*.cpp")
add_includedirs(".", { public = true})
add_deps("applog")
add_packages("common")

View File

@ -0,0 +1,56 @@
#include "DisplayCenter.h"
#include "LCDDisplay.h"
DisplayCenter::DisplayCenter():m_lcd(new LCDDisplay())
,brun(false)
{
m_showthread.reset(new std::thread(&DisplayCenter::runloop,this));
m_distype = DisType::Dis_Idel;
}
DisplayCenter::~DisplayCenter()
{
brun = false;
if(m_showthread.get()&& m_showthread->joinable())
{
m_showthread->join();
m_showthread.reset();
}
if(!m_msgs.IsShutDown())
m_msgs.ShutDown();
m_lcd.reset();
}
void DisplayCenter::PutMsg(DisType distype,int pagenum,ClearScreen clearscreen)
{
m_msgs.Put({distype,clearscreen,(unsigned int )pagenum,""});
m_distype = distype;
printf("\n ----- distype = %d ",distype);
}
void DisplayCenter::ResetMsgQueue()
{
m_msgs.Clear();
}
void DisplayCenter::runloop()
{
brun = true;
while (brun)
{
if(m_msgs.Size()>0)
{
auto msg= m_msgs.Take();
m_lcd->DisplayState(msg.distype,msg.pagenum,msg.clearscree);
}
else
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
}
DisType DisplayCenter::getcurdistype()
{
return m_distype;
}

View File

@ -0,0 +1,31 @@
#pragma once
#include <thread>
#include "BlockingQueue.h"
#include "Displaydef.h"
class LCDDisplay;
class DisplayCenter
{
public:
DisplayCenter();
~DisplayCenter();
void PutMsg(DisType distype,int pagenum,ClearScreen clearscreen);
void ResetMsgQueue();
DisType getcurdistype();
private:
struct MsgPair{
DisType distype;
ClearScreen clearscree;
unsigned int pagenum;
std::string infomsg;
};
void runloop();
private:
BlockingQueue<MsgPair> m_msgs;
std::shared_ptr<std::thread> m_showthread;
std::shared_ptr<LCDDisplay> m_lcd;
volatile DisType m_distype;
bool brun;
};

View File

@ -0,0 +1,114 @@
#pragma once
#include <map>
#include <vector>
#include "HgLCDfont.h"
enum class DisType{
Dis_Unkown,
Dis_Init,//启动欢迎界面
Dis_Welcome,
Dis_Idel,//就绪
Dis_Scan,
Dis_Err_JamIn,
Dis_Err_DoubleFeed,
Dis_Err_PaperScrew,
Dis_Err_Stable,
Dis_Err_AqrImgTimeout,
Dis_Err_CoverOpen,
Dis_Err_JamOut,
Dis_Err_HandModeJam,
Dis_Err_FeedError,
Dis_Err_NoPaper,
Dis_Err_DogEar,
Dis_Err_Size,
Dis_Set_PollPaperIntensity,
Dis_Set_PollPI_High,
Dis_Set_PollPI_Mid,
Dis_Set_PollPI_Low,
Dis_Count_Page,
Dis_Scan_Page,
Dis_Set_ClearPaperPass,
Dis_Set_Count,
Dis_Set_SleepMode,
Dis_Set_SleepMode_5M,
Dis_Set_SleepMode_10M,
Dis_Set_SleepMode_20M,
Dis_Set_SleepMode_30M,
Dis_Set_SleepMode_1H,
Dis_Set_SleepMode_2H,
Dis_Set_SleepMode_4H,
Dis_Set_SleepMode_NEVER,
Dis_Set_Poweroff,
Dis_Set_Return,
Dis_HandMode,
Dis_Set_Item_Return,
Dis_Set_TrayPosition,
Dis_Set_TrayPosition_Low,
Dis_Set_TrayPosition_Mid,
Dis_Set_TrayPosition_High,
Dis_Device_Lock,
};
enum class DisDrawtype
{
DD_All,
DD_TopLeft,
DD_BotRight
};
enum class ClearScreen
{
All,
TOP,
BOT,
};
struct DisInfo{
unsigned char page;
unsigned char col;
DisDrawtype drawtype;
std::vector<unsigned char> str;
};
static std::map<DisType,DisInfo> map_Display={
{DisType::Dis_Welcome,{1,1,DisDrawtype::DD_All,std::vector<unsigned char>(f_logo,f_logo+sizeof(f_logo))}},
{DisType::Dis_Init,{1,1,DisDrawtype::DD_All,std::vector<unsigned char>(f_welcome,f_welcome+sizeof(f_welcome))}},
{DisType::Dis_Idel,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_ready,f_ready+sizeof(f_ready))}},
{DisType::Dis_Scan,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_scan,f_scan+sizeof(f_scan))}},
{DisType::Dis_Set_ClearPaperPass,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_clearpaperpass,f_clearpaperpass+sizeof(f_clearpaperpass))}},
{DisType::Dis_Set_Count,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_countmode,f_countmode+sizeof(f_countmode))}},
{DisType::Dis_Err_DoubleFeed,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_doublefeed,f_doublefeed+sizeof(f_doublefeed))}},
{DisType::Dis_Err_Stable,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_stable,f_stable+sizeof(f_stable))}},
{DisType::Dis_Err_CoverOpen,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_coveropen,f_coveropen+sizeof(f_coveropen))}},
{DisType::Dis_Err_JamIn,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_paperjam,f_paperjam+sizeof(f_paperjam))}},
{DisType::Dis_Err_JamOut,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_paperjam,f_paperjam+sizeof(f_paperjam))}},
{DisType::Dis_Err_HandModeJam,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_handmodepaperjam,f_handmodepaperjam+sizeof(f_handmodepaperjam))}},
{DisType::Dis_Err_PaperScrew,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_paperscrew,f_paperscrew+sizeof(f_paperscrew))}},
{DisType::Dis_Err_FeedError,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_feederror,f_feederror+sizeof(f_feederror))}},
{DisType::Dis_Err_AqrImgTimeout,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_aqrimgtimeout,f_aqrimgtimeout+sizeof(f_aqrimgtimeout))}},
{DisType::Dis_Err_DogEar,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_dogear,f_dogear+sizeof(f_dogear))}},
{DisType::Dis_Err_Size,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_size,f_size+sizeof(f_size))}},
{DisType::Dis_Set_PollPaperIntensity,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_pollpaperintensity,f_pollpaperintensity+sizeof(f_pollpaperintensity))}},
{DisType::Dis_Set_PollPI_High,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_intensityHigh,f_intensityHigh+sizeof(f_intensityHigh))}},
{DisType::Dis_Set_PollPI_Mid,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_intensityMid,f_intensityMid+sizeof(f_intensityMid))}},
{DisType::Dis_Set_PollPI_Low,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_intensityLow,f_intensityLow+sizeof(f_intensityLow))}},
{DisType::Dis_Set_TrayPosition,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_trayposition,f_trayposition+sizeof(f_trayposition))}},
{DisType::Dis_Set_TrayPosition_High,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_intensityHigh,f_intensityHigh+sizeof(f_intensityHigh))}},
{DisType::Dis_Set_TrayPosition_Mid,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_intensityMid,f_intensityMid+sizeof(f_intensityMid))}},
{DisType::Dis_Set_TrayPosition_Low,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_traypositionLow,f_traypositionLow+sizeof(f_traypositionLow))}},
{DisType::Dis_Count_Page,{3,112,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_page,f_page+sizeof(f_page))}},
{DisType::Dis_Scan_Page,{3,112,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_page,f_page+sizeof(f_page))}},
{DisType::Dis_Err_NoPaper,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_nopaper,f_nopaper+sizeof(f_nopaper))}},
{DisType::Dis_Set_SleepMode,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_sleepmode,f_sleepmode+sizeof(f_sleepmode))}},
// {DisType::Dis_Set_SleepMode_30M,{3,64,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_30min,f_30min+sizeof(f_30min))}},
// {DisType::Dis_Set_SleepMode_1H,{3,80,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_1hour,f_1hour+sizeof(f_1hour))}},
// {DisType::Dis_Set_SleepMode_2H,{3,80,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_2hour,f_2hour+sizeof(f_2hour))}},
{DisType::Dis_Set_SleepMode_NEVER,{3,80,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_never,f_never+sizeof(f_never))}},
{DisType::Dis_Set_Return,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_return,f_return+sizeof(f_return))}},
{DisType::Dis_Set_Poweroff,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_powerof,f_powerof+sizeof(f_powerof))}},
{DisType::Dis_HandMode,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_handmode,f_handmode+sizeof(f_handmode))}},
{DisType::Dis_Set_Item_Return,{3,96,DisDrawtype::DD_BotRight,std::vector<unsigned char>(f_return,f_return+sizeof(f_return))}},
{DisType::Dis_Device_Lock,{1,1,DisDrawtype::DD_TopLeft,std::vector<unsigned char>(f_deviceLock,f_deviceLock+sizeof(f_deviceLock))}},
};

View File

@ -0,0 +1,433 @@
#pragma once
/*就绪*/
static unsigned char f_ready[]={
0x04,0xE4,0x25,0x26,0x24,0xE4,0x04,0x20,0x20,0xFF,0x20,0xE2,0x2C,0x20,0x20,0x00,
0x10,0x4B,0x82,0x7E,0x02,0x0B,0x90,0x60,0x1C,0x03,0x00,0x3F,0x40,0x40,0x70,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x10,0x20,0x24,0x24,0xA4,0x7F,0x24,0x34,0x28,0x26,0x20,0x00,
0x22,0x67,0x22,0x12,0x12,0x04,0x02,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00
};
/*图标*/
static unsigned char f_logo[]={
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x03,
0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xFC,0xFC,
0x3C,0x3F,0x3F,0x3F,0x3C,0x3C,0x3C,0x00,0x00,0x00,0x00,0xC0,0xF0,0xFC,0xFC,0x3C,
0x3F,0x3F,0x3C,0xFC,0xFC,0xF0,0xC0,0x00,0x00,0x00,0x00,0xF0,0xFC,0x3C,0x3F,0x3F,
0x3F,0x3C,0x3C,0x3C,0x00,0x00,0x00,0xC0,0xF0,0xFC,0xFC,0x3F,0x3F,0x3F,0x3F,0x3C,
0x3C,0xFC,0x30,0x00,0x00,0x00,0x00,0x00,0xC3,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFC,0xC0,0x00,0x00,0x00,0x03,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xF0,0xC0,0xC0,0xC0,0xC0,0xF0,0xFF,0xFF,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xC0,0xFC,
0xFF,0x3F,0x00,0x03,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x0F,0x00,
0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x03,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xF0,0x00,0x00,0x0F,0xFF,0xFF,0xF0,0xF0,0xC0,
0xC0,0xC0,0x00,0x00,0x00,0x00,0xFC,0xFF,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x03,0x00,0x00,0x3F,0xFF,0xFF,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0x03,0x0F,0x3F,0xFF,0xFC,0x00,0x00,0x00,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x07,0x01,0x01,0x01,0x01,0x07,0xFF,0xFF,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x7F,0x00,0x00,0x80,0xFF,0xFF,
0xF9,0xE0,0xE0,0xE0,0xE0,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0xFF,0xFF,0xFF,0xE0,0x00,
0x00,0x00,0x07,0x07,0x07,0xFF,0xFF,0x00,0x00,0x00,0x01,0xFF,0xFF,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0x01,0x01,0x07,0x07,
0x1F,0xFF,0xFF,0xF8,0x00,0x00,0x7F,0xFF,0xF8,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0xFE,0xFF,0xFF,0xE0,0xE0,0xE0,0xE0,0xF9,0xFF,0xFE,
0x80,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x1F,0xF8,0x80,0x80,0xFF,0xFF,
0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,
0x01,0x1F,0x7F,0x7E,0x78,0x78,0x7E,0x7E,0x1F,0x07,0x00,0x00,0x60,0x7F,0x1F,0x07,
0x01,0x01,0x01,0x01,0x01,0x01,0x07,0x7F,0x7F,0x60,0x00,0x01,0x07,0x1F,0x1F,0x7E,
0x7E,0x78,0x78,0x78,0x78,0x7F,0x7F,0x00,0x00,0x00,0x00,0x07,0x1F,0x1F,0x7E,0x7E,
0x78,0x78,0x7E,0x7E,0x7F,0x1F,0x01,0x00,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x7E,
0x7E,0x7F,0x1F,0x01,0x00,0x00,0x00,0x01,0x1F,0x7F,0x7E,0x7E,0x78,0x78,0x78,0x7E,
0x7E,0x1E,0x18,0x00,0x78,0x7F,0x7F,0x07,0x01,0x01,0x01,0x01,0x01,0x01,0x07,0x7F,
0x7F,0x78,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x1F,0x7F,0x7F,0x7F,0x7F
};
/*欢迎使用*/
static unsigned char f_welcome[] = {
0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00,
0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x4F,0x44,0x42,0x40,0x7F,0x42,0x44,0x43,0x40,0x00,
0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0xE4,0x04,0x00,
0x00,0x00,0xFF,0x00,0x80,0x81,0x45,0x29,0x11,0x2F,0x41,0x41,0x81,0x81,0x80,0x00,
0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,
};
/*清理纸道*/
static unsigned char f_clearpaperpass[]={
0x10,0x60,0x02,0x8C,0x00,0x44,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x44,0x40,0x00,
0x04,0x04,0x7E,0x01,0x00,0x00,0xFF,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00,
0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0xFE,0x00,0x00,
0x20,0x60,0x20,0x1F,0x10,0x10,0x40,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x40,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x40,0x40,0x42,0xCC,0x00,0x08,0xE9,0xAA,0xB8,0xA8,0xA8,0xAA,0xE9,0x08,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x4A,0x4A,0x4A,0x4A,0x4A,0x5F,0x40,0x40,0x00
};
/*计数*/
static unsigned char f_countmode[] = {
0x40,0x40,0x42,0xCC,0x00,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,
0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00
};
static unsigned char f_dogear[] = {
0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0xFC,0x44,0x44,0x44,0xC2,0x43,0x42,0x40,0x00,
0x04,0x44,0x82,0x7F,0x01,0x80,0x60,0x1F,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x10,0xE8,0x24,0x27,0x24,0x24,0xE4,0x24,0x34,0x2C,0x20,0xE0,0x00,0x00,0x00,
0x80,0x60,0x1F,0x09,0x09,0x09,0x09,0x7F,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,
};
static unsigned char f_size[] = {
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x7E,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,
0x00,0x00,0x00,0x01,0x06,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x02,0x00,0x00,
0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x02,0x0C,0x00,0x00,
0x10,0x08,0x04,0x87,0x6C,0x14,0x84,0x94,0x88,0x87,0x84,0xEC,0x94,0x84,0x84,0x00,
0x04,0x02,0x01,0xFF,0x00,0x00,0x00,0x02,0x0C,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,
};
/*双张*/
static unsigned char f_doublefeed[] = {
0x04,0x34,0xC4,0x04,0xC4,0x3C,0x00,0x04,0xFC,0x04,0x04,0x04,0xC4,0x3C,0x00,0x00,
0x40,0x30,0x0C,0x03,0x0C,0x30,0x80,0x40,0x20,0x13,0x0C,0x13,0x20,0x40,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0xE2,0x22,0x22,0x3E,0x80,0x80,0xFF,0x80,0xA0,0x90,0x88,0x86,0x80,0x80,0x00,
0x00,0x43,0x82,0x42,0x3E,0x00,0x00,0xFF,0x40,0x21,0x06,0x08,0x10,0x20,0x40,0x00
};
/*订书针*/
static unsigned char f_stable[] = {
0x10,0x10,0xD0,0xFF,0x90,0x50,0x20,0x50,0x4C,0x43,0x4C,0x50,0x20,0x40,0x40,0x00,
0x04,0x03,0x00,0xFF,0x00,0x41,0x44,0x58,0x41,0x4E,0x60,0x58,0x47,0x40,0x40,0x00,
0x10,0x60,0x02,0x8C,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0xFF,0x00,0x00,
0x04,0x04,0x7E,0x01,0x80,0x47,0x30,0x0F,0x10,0x27,0x00,0x47,0x80,0x7F,0x00,0x00,
0x42,0x62,0x52,0x4A,0xC6,0x42,0x52,0x62,0xC2,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,
0x40,0xC4,0x44,0x44,0x7F,0x24,0x24,0x24,0x20,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,
0x40,0x40,0x42,0xCC,0x00,0x00,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,
0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0xF9,0x02,0x04,0x00,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x21,0x41,0x21,0x1F,0x00,0x00,
0x40,0x20,0x38,0xE7,0x24,0x24,0x44,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x00,
0x01,0x01,0x01,0x7F,0x21,0x11,0x09,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,
};
/*开盖*/
static unsigned char f_coveropen[] = {
0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00,
0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00,
0x80,0x90,0x90,0x48,0x4C,0x57,0x24,0x24,0x24,0x54,0x4C,0x44,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00,
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x24,0x24,0x25,0x26,0x24,0xFC,0x24,0x26,0x25,0x24,0x24,0x04,0x00,0x00,
0x81,0x81,0xF9,0x89,0x89,0xF9,0x89,0x89,0x89,0xF9,0x89,0x89,0xF9,0x81,0x81,0x00
};
/*手动模式卡纸*/
static unsigned char f_handmodepaperjam[] = {
0x00,0x00,0x24,0x24,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x23,0x22,0x00,0x00,0x00,
0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,/*"手",0*/
0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"动",1*/
0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00,/*"模",2*/
0x10,0x10,0x90,0x90,0x90,0x90,0x90,0x10,0x10,0xFF,0x10,0x10,0x11,0x16,0x10,0x00,
0x00,0x20,0x60,0x20,0x3F,0x10,0x10,0x10,0x00,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00,/*"式",3*/
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x04,0x08,0x10,0x00,0x00,0x00,/*"卡",4*/
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,/*"纸",5*/
};
/*手动模式*/
static unsigned char f_handmode[] = {
0x00,0x00,0x24,0x24,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x23,0x22,0x00,0x00,0x00,
0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,
0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,
0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00,
0x10,0x10,0x90,0x90,0x90,0x90,0x90,0x10,0x10,0xFF,0x10,0x10,0x11,0x16,0x10,0x00,
0x00,0x20,0x60,0x20,0x3F,0x10,0x10,0x10,0x00,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00,
};
/*纸张歪斜*/
static unsigned char f_paperscrew[] = {
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x02,0xE2,0x22,0x22,0x3E,0x80,0x80,0xFF,0x80,0xA0,0x90,0x88,0x86,0x80,0x80,0x00,
0x00,0x43,0x82,0x42,0x3E,0x00,0x00,0xFF,0x40,0x21,0x06,0x08,0x10,0x20,0x40,0x00,
0x00,0x42,0x42,0x22,0x22,0x12,0x0A,0x7E,0x02,0x12,0x12,0x22,0x22,0x42,0x00,0x00,
0x40,0x41,0x41,0x7D,0x41,0x41,0x41,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00,
0x20,0x10,0x28,0x24,0xE3,0x24,0x28,0x10,0x00,0x22,0xCC,0x00,0xFF,0x00,0x00,0x00,
0x20,0x11,0x4D,0x81,0x7F,0x01,0x05,0x19,0x00,0x02,0x02,0x02,0xFF,0x01,0x01,0x00
};
/*卡纸*/
static unsigned char f_paperjam[] = {
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x04,0x08,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00
};
/*卡纸001*/
static unsigned char f_paperjam001[] = {
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x04,0x08,0x10,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00
};
/*卡纸002*/
static unsigned char f_paperjam002[] = {
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x04,0x08,0x10,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00
};
/*卡纸003*/
static unsigned char f_paperjam003[] = {
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x04,0x08,0x10,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00
};
/*搓纸失败*/
static unsigned char f_feederror[] = {
0x10,0x10,0x10,0xFF,0x10,0x90,0x88,0xA9,0xAE,0xF8,0xA8,0xAC,0xAB,0x88,0x80,0x00,
0x04,0x44,0x82,0x7F,0x21,0x10,0x48,0x46,0x45,0x44,0x7C,0x44,0x44,0x44,0x40,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x00,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
0x81,0x81,0x41,0x21,0x11,0x0D,0x03,0x01,0x03,0x0D,0x11,0x21,0x41,0x81,0x81,0x00,
0x00,0xFE,0x02,0xFA,0x02,0xFE,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,
0x80,0x47,0x30,0x0F,0x10,0x67,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00
};
/*取图超时*/
static unsigned char f_aqrimgtimeout[] = {
0x02,0x02,0xFE,0x92,0x92,0x92,0xFE,0x02,0x06,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x08,0x18,0x0F,0x08,0x08,0x04,0xFF,0x04,0x84,0x40,0x27,0x18,0x27,0x40,0x80,0x00,
0x00,0xFE,0x02,0x42,0x22,0x32,0x5E,0x92,0x52,0x32,0x12,0x02,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x42,0x42,0x42,0x51,0x55,0x64,0x69,0x41,0x42,0x42,0x42,0xFF,0x00,0x00,
0x40,0x48,0x48,0x48,0xFF,0x48,0x48,0x42,0xA2,0x9E,0x82,0xA2,0xC2,0xBE,0x00,0x00,
0x80,0x60,0x1F,0x20,0x7F,0x44,0x44,0x40,0x4F,0x48,0x48,0x48,0x48,0x4F,0x40,0x00,
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00
};
/*分纸强度*/
static unsigned char f_pollpaperintensity[] = {
0x80,0x40,0x20,0x90,0x88,0x86,0x80,0x80,0x80,0x83,0x8C,0x10,0x20,0x40,0x80,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00,
0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00,
0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00,
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,
};
/*高*/
static unsigned char f_intensityHigh[] = {
0x04,0x04,0x04,0x04,0xF4,0x94,0x95,0x96,0x94,0x94,0xF4,0x04,0x04,0x04,0x04,0x00,
0x00,0xFE,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x82,0xFE,0x00,0x00
};
/*中*/
static unsigned char f_intensityMid[] = {
0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00
};
/*弱*/
static unsigned char f_intensityLow[] = {
0x00,0xF2,0x92,0x92,0x92,0x92,0x9E,0x00,0xF2,0x92,0x92,0x92,0x92,0x9E,0x00,0x00,
0x00,0x10,0x11,0x4A,0x88,0x44,0x3F,0x00,0x10,0x11,0x4A,0x88,0x44,0x3F,0x00,0x00
};
/*低*/
static unsigned char f_traypositionLow[] = {
0x00,0x80,0x60,0xF8,0x07,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0xFF,0x40,0x20,0x00,0x41,0x8E,0x30,0x40,0xF8,0x00
};
/*张*/
static unsigned char f_page[] = {
0x02,0xE2,0x22,0x22,0x3E,0x80,0x80,0xFF,0x80,0xA0,0x90,0x88,0x86,0x80,0x80,0x00,
0x00,0x43,0x82,0x42,0x3E,0x00,0x00,0xFF,0x40,0x21,0x06,0x08,0x10,0x20,0x40,0x00
};
/*扫描*/
static unsigned char f_scan[] = {
0x10,0x10,0x10,0xFF,0x10,0x90,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0xFC,0x00,0x00,
0x04,0x44,0x82,0x7F,0x01,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x10,0x10,0xFF,0x10,0x90,0x04,0xC4,0x5F,0x44,0xC4,0x44,0x5F,0xC4,0x04,0x00,
0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x44,0x44,0x7F,0x44,0x44,0xFF,0x00,0x00
};
/*返回*/
static unsigned char f_back[] = {
0x40,0x40,0x42,0xCE,0xCC,0x00,0xFC,0xFC,0xA4,0xA4,0x26,0x22,0xA3,0xE3,0x62,0x00,
0x00,0x40,0x60,0x3F,0x3F,0x78,0x5F,0x57,0x58,0x4D,0x47,0x47,0x4D,0x58,0x50,0x40,
0x00,0x00,0xFE,0xFE,0x02,0xF2,0xF2,0x12,0x12,0xF2,0xF2,0x02,0xFE,0xFE,0x00,0x00,
0x00,0x00,0x7F,0x7F,0x20,0x27,0x27,0x24,0x24,0x27,0x27,0x20,0x7F,0x7F,0x00,0x00
};
/*确认*/
static unsigned char f_confirm[] = {
0x04,0x84,0xE4,0x5C,0x44,0xC4,0x20,0x10,0xE8,0x27,0x24,0xE4,0x34,0x2C,0xE0,0x00,
0x02,0x01,0x7F,0x10,0x10,0x3F,0x80,0x60,0x1F,0x09,0x09,0x3F,0x49,0x89,0x7F,0x00,
0x40,0x40,0x42,0xCC,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x90,0x48,0x20,0x18,0x07,0x00,0x07,0x18,0x20,0x40,0x80,0x00
};
/*开*/
static unsigned char f_opened[] = {
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00
};
/*关*/
static unsigned char f_closed[] = {
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00
};
/*无纸*/
static unsigned char f_nopaper[] = {
0x00,0x40,0x42,0x42,0x42,0xC2,0x7E,0x42,0xC2,0x42,0x42,0x42,0x40,0x40,0x00,0x00,
0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0xFF,0x40,0x20,0x00,0x01,0x0E,0x30,0x40,0xF8,0x00
};
/*休眠模式*/
static unsigned char f_sleepmode[] = {
0x00,0x80,0x60,0xF8,0x07,0x10,0x10,0x10,0xD0,0xFF,0xD0,0x10,0x10,0x10,0x10,0x00,
0x01,0x00,0x00,0xFF,0x10,0x08,0x04,0x03,0x00,0xFF,0x00,0x03,0x04,0x08,0x10,0x00,
0x00,0xFC,0x24,0x24,0x24,0xFC,0x00,0xFE,0x22,0x22,0xE2,0x22,0x22,0x3E,0x00,0x00,
0x00,0x3F,0x11,0x11,0x11,0x3F,0x00,0xFF,0x41,0x21,0x07,0x19,0x21,0x41,0xF1,0x00,
0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00,
0x10,0x10,0x90,0x90,0x90,0x90,0x90,0x10,0x10,0xFF,0x10,0x10,0x11,0x16,0x10,0x00,
0x00,0x20,0x60,0x20,0x3F,0x10,0x10,0x10,0x00,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00
};
/*三十分钟*/
static unsigned char f_30min[] = {
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x40,0x20,0x90,0x88,0x86,0x80,0x80,0x80,0x83,0x8C,0x10,0x20,0x40,0x80,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xF0,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,
0x01,0x01,0x01,0x7F,0x21,0x11,0x00,0x07,0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00,
};
/*一小时*/
static unsigned char f_1hour[] = {
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x20,0x40,0x80,0x00,0x00,
0x08,0x04,0x03,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x00,
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00
};
/*二小时*/
static unsigned char f_2hour[] = {
0x02,0xE2,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0xE2,0x02,0x00,
0x00,0xFF,0x00,0x08,0x06,0x01,0x16,0x08,0x06,0x01,0x02,0x4C,0x80,0x7F,0x00,0x00,
0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x20,0x40,0x80,0x00,0x00,
0x08,0x04,0x03,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x00,
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00
};
/*不休眠*/
static unsigned char f_never[] = {
0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x02,0x00,0x00,
0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x02,0x0C,0x00,0x00,
0x00,0x80,0x60,0xF8,0x07,0x10,0x10,0x10,0xD0,0xFF,0xD0,0x10,0x10,0x10,0x10,0x00,
0x01,0x00,0x00,0xFF,0x10,0x08,0x04,0x03,0x00,0xFF,0x00,0x03,0x04,0x08,0x10,0x00,
0x00,0xFC,0x24,0x24,0x24,0xFC,0x00,0xFE,0x22,0x22,0xE2,0x22,0x22,0x3E,0x00,0x00,
0x00,0x3F,0x11,0x11,0x11,0x3F,0x00,0xFF,0x41,0x21,0x07,0x19,0x21,0x41,0xF1,0x00
};
/*返回*/
static unsigned char f_return[] = {
0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x24,0xA4,0x24,0x22,0x22,0xA3,0x62,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x58,0x47,0x50,0x48,0x45,0x42,0x45,0x48,0x50,0x40,0x00,
0x00,0x00,0xFE,0x02,0x02,0xF2,0x12,0x12,0x12,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,
0x00,0x00,0x7F,0x20,0x20,0x27,0x24,0x24,0x24,0x27,0x20,0x20,0x7F,0x00,0x00,0x00
};
/*关机*/
static unsigned char f_powerof[] = {
0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,
0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00,
0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x83,0x60,0x1F,0x00,0x00,0x00,0x3F,0x40,0x40,0x78,0x00
};
/*托盘位置*/
static unsigned char f_trayposition[] = {
0x10,0x10,0x10,0xFF,0x10,0x90,0x04,0x04,0x04,0xFC,0x82,0x82,0x83,0x82,0x80,0x00,
0x04,0x44,0x82,0x7F,0x01,0x00,0x01,0x01,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,
0x20,0x20,0x20,0xFC,0x24,0x26,0xA5,0x2C,0x34,0x24,0x24,0xFC,0x20,0x20,0x20,0x00,
0x40,0x42,0x7D,0x44,0x44,0x7C,0x44,0x45,0x44,0x7D,0x46,0x45,0x7C,0x40,0x40,0x00,
0x00,0x80,0x60,0xF8,0x07,0x10,0x90,0x10,0x11,0x16,0x10,0x10,0xD0,0x10,0x00,0x00,
0x01,0x00,0x00,0xFF,0x40,0x40,0x41,0x5E,0x40,0x40,0x70,0x4E,0x41,0x40,0x40,0x00,
0x00,0x17,0x15,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x15,0x17,0x00,0x00,
0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x40,0x40,0x00
};
/*设备已锁定*/
static unsigned char f_deviceLock[] = {
0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00,
0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00,/*"设",0*/
0x80,0x90,0x90,0x48,0x4C,0x57,0x24,0x24,0x24,0x54,0x4C,0x44,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00,/*"备",1*/
0x00,0x00,0xE2,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x78,0x00,0x00,/*"已",2*/
0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xE2,0x2C,0x20,0xBF,0x20,0x28,0xE6,0x00,0x00,
0x01,0x01,0x01,0x7F,0x21,0x11,0x80,0x4F,0x20,0x10,0x0F,0x10,0x20,0x4F,0x80,0x00,/*"锁",3*/
0x10,0x0C,0x44,0x44,0x44,0x44,0x45,0xC6,0x44,0x44,0x44,0x44,0x44,0x14,0x0C,0x00,
0x80,0x40,0x20,0x1E,0x20,0x40,0x40,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,/*"定",4*/
};

View File

@ -0,0 +1,152 @@
#include "LCDDisplay.h"
#include "Lcd.h"
#include <StopWatch.h>
#include <iostream>
#include <thread>
#include "stringex.hpp"
using namespace std;
LCDDisplay::LCDDisplay()
{
lcd.reset(new Lcd());
lcd->Lcd_Initial_Lcd(false);
// lcd->Lcd_Clear_screen();
// lcd->Lcd_Display_Graphic_16x16(map_Display[DisType::Dis_Init].page, map_Display[DisType::Dis_Init].col, map_Display[DisType::Dis_Init].str.data(),map_Display[DisType::Dis_Init].str.size()/32);
}
LCDDisplay::~LCDDisplay()
{
lcd->Lcd_Clear_screen();
lcd.reset();
}
void LCDDisplay::DisplayState(DisType ds, unsigned int pagenum,ClearScreen clearscree)
{
if(clearscree == ClearScreen::All)
lcd->Lcd_Clear_screen();
if(clearscree == ClearScreen::TOP)
lcd->Lcd_Clear_Half_Screen(true);
if(clearscree == ClearScreen::BOT)
lcd->Lcd_Clear_Half_Screen(false);
if (map_Display.count(ds) > 0)
{
m_status = ds;
StopWatch sw;
auto dsinfo = map_Display[ds];
if (ds == DisType::Dis_Welcome)//show logo
{
lcd->Lcd_Display_Graphic_128x64(dsinfo.page, dsinfo.col, dsinfo.str.data());
}
else
{
lcd->Lcd_Display_Graphic_16x16(dsinfo.page, dsinfo.col, dsinfo.str.data(), dsinfo.str.size() / 32);
//if (ds == DisType::Dis_Scan || ds == DisType::Dis_Set_Count) //扫描或者计数 更新下半部分内容
//{
//lcd->Lcd_Clear_Half_Screen(false);
//lcd->Lcd_Display_String_8x16(3, 96, "0");
//lcd->Lcd_Display_Graphic_16x16(map_Display[DisType::Dis_Scan_Page].page, map_Display[DisType::Dis_Scan_Page].col, map_Display[DisType::Dis_Scan_Page].str.data(), map_Display[DisType::Dis_Scan_Page].str.size() / 32);
//}
}
switch (ds)
{
case DisType::Dis_Count_Page:
case DisType::Dis_Scan_Page:
{
//std::string val = std::to_string(pagenum);
//auto offsetdot = bitnum(pagenum) - 1;
std::string val = string_format("%04d",pagenum);
int offsetdot = val.length();
//printf("\n val = %s lenght = %d",val.c_str(),val.size());
lcd->Lcd_Display_String_8x16(3, 112 - offsetdot * 8, val.c_str()); //8 -> 一个数字所占点个数宽度
lcd->Lcd_Display_Graphic_16x16(map_Display[DisType::Dis_Scan_Page].page, map_Display[DisType::Dis_Scan_Page].col, map_Display[DisType::Dis_Scan_Page].str.data(), map_Display[DisType::Dis_Scan_Page].str.size() / 32);
break;
}
case DisType::Dis_Err_JamIn:
{
if(pagenum == 1)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 1"); //8 -> 一个数字所占点个数宽度
else if(pagenum == 2)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 2");
else if(pagenum == 3)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 3");
break;
}
case DisType::Dis_Err_AqrImgTimeout:
lcd->Lcd_Display_String_8x16(3, 56, "G p 0 0 1");
break;
case DisType::Dis_Err_CoverOpen:
lcd->Lcd_Display_String_8x16(3, 56, "C o 0 0 1");
break;
case DisType::Dis_Err_PaperScrew:
lcd->Lcd_Display_String_8x16(3, 56, "S K 0 0 1");
break;
case DisType::Dis_Err_DoubleFeed:
lcd->Lcd_Display_String_8x16(3, 56, "D b 0 0 1");
break;
case DisType::Dis_Err_NoPaper:
lcd->Lcd_Display_String_8x16(3, 56, "N o 0 0 1");
break;
case DisType::Dis_Err_Stable:
lcd->Lcd_Display_String_8x16(3, 56, "S T 0 0 1");
break;
case DisType::Dis_Err_FeedError:
lcd->Lcd_Display_String_8x16(3, 56, "P f 0 0 1");
break;
case DisType::Dis_Err_DogEar:
lcd->Lcd_Display_String_8x16(3, 56, "Z J 0 0 1");
break;
case DisType::Dis_Err_Size:
lcd->Lcd_Display_String_8x16(3, 56, "C C 0 0 1");
break;
default:
break;
}
}
else
{
switch (ds){
case DisType::Dis_Set_SleepMode_5M:
lcd->Lcd_Display_String_8x16(3, 112, "5M");
break;
case DisType::Dis_Set_SleepMode_10M:
lcd->Lcd_Display_String_8x16(3, 104, "10M");
break;
case DisType::Dis_Set_SleepMode_20M:
lcd->Lcd_Display_String_8x16(3, 104, "20M");
break;
case DisType::Dis_Set_SleepMode_30M:
lcd->Lcd_Display_String_8x16(3, 104, "30M");
break;
case DisType::Dis_Set_SleepMode_1H:
lcd->Lcd_Display_String_8x16(3, 112, "1H");
break;
case DisType::Dis_Set_SleepMode_2H:
lcd->Lcd_Display_String_8x16(3, 112, "2H");
break;
case DisType::Dis_Set_SleepMode_4H:
lcd->Lcd_Display_String_8x16(3, 112, "4H");
break;
default:
m_status= DisType::Dis_Unkown;
break;
}
}
}
int LCDDisplay::bitnum(unsigned int num)
{
int count = 0;
do
{
num = num / 10;
count++;
} while (num > 0);
return count;
}
DisType LCDDisplay::GetCurrentStatus() const
{
return m_status;
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <map>
#include <memory>
#include "Displaydef.h"
class Lcd;
class LCDDisplay
{
private:
/* data */
public:
LCDDisplay(/* args */);
~LCDDisplay();
void DisplayState(DisType ds,unsigned int pagenum,ClearScreen clearscree);
DisType GetCurrentStatus() const;
private:
int bitnum(unsigned int num);
private:
std::shared_ptr<Lcd> lcd;
DisType m_status;
};

View File

@ -0,0 +1,780 @@
#include "Lcd.h"
#include <thread>
#include <iostream>
#include <fstream>
#include "DevUtil.h"
using namespace std;
#define IOEXPORTPATH "/sys/class/gpio/export"
#define DELAY_US(t) this_thread::sleep_for(chrono::microseconds((t)))
#define DELAY_MS(t) this_thread::sleep_for(chrono::milliseconds((t)))
static unsigned char ascii_table_8x16[95][16] = {
/*-- 文字: --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: ! --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00,
/*-- 文字: " --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: # --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x40, 0xC0, 0x78, 0x40, 0xC0, 0x78, 0x40, 0x00, 0x04, 0x3F, 0x04, 0x04, 0x3F, 0x04, 0x04, 0x00,
/*-- 文字: $ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x70, 0x88, 0xFC, 0x08, 0x30, 0x00, 0x00, 0x00, 0x18, 0x20, 0xFF, 0x21, 0x1E, 0x00, 0x00,
/*-- 文字: % --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xF0, 0x08, 0xF0, 0x00, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x21, 0x1C, 0x03, 0x1E, 0x21, 0x1E, 0x00,
/*-- 文字: & --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0xF0, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x1E, 0x21, 0x23, 0x24, 0x19, 0x27, 0x21, 0x10,
/*-- 文字: ' --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x10, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: ( --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0x40, 0x00,
/*-- 文字: ) --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00,
/*-- 文字: * --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x40, 0x40, 0x80, 0xF0, 0x80, 0x40, 0x40, 0x00, 0x02, 0x02, 0x01, 0x0F, 0x01, 0x02, 0x02, 0x00,
/*-- 文字: + --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x01, 0x01, 0x01, 0x00,
/*-- 文字: , --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: - --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
/*-- 文字: . --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: / --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00,
/*-- 文字: 0 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x10, 0x0F, 0x00,
/*-- 文字: 1 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x10, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: 2 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x70, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x30, 0x00,
/*-- 文字: 3 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x30, 0x08, 0x88, 0x88, 0x48, 0x30, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: 4 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0xC0, 0x20, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x07, 0x04, 0x24, 0x24, 0x3F, 0x24, 0x00,
/*-- 文字: 5 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0xF8, 0x08, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x19, 0x21, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: 6 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0xE0, 0x10, 0x88, 0x88, 0x18, 0x00, 0x00, 0x00, 0x0F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: 7 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x38, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: 8 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x70, 0x88, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x1C, 0x22, 0x21, 0x21, 0x22, 0x1C, 0x00,
/*-- 文字: 9 --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x00, 0x31, 0x22, 0x22, 0x11, 0x0F, 0x00,
/*-- 文字: : --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00,
/*-- 文字: ; --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: < --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
/*-- 文字: = --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00,
/*-- 文字: > --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00,
/*-- 文字: ? --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x70, 0x48, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x36, 0x01, 0x00, 0x00,
/*-- 文字: @ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xC0, 0x30, 0xC8, 0x28, 0xE8, 0x10, 0xE0, 0x00, 0x07, 0x18, 0x27, 0x24, 0x23, 0x14, 0x0B, 0x00,
/*-- 文字: A --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0xC0, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x20, 0x3C, 0x23, 0x02, 0x02, 0x27, 0x38, 0x20,
/*-- 文字: B --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: C --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xC0, 0x30, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x07, 0x18, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00,
/*-- 文字: D --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00,
/*-- 文字: E --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x23, 0x20, 0x18, 0x00,
/*-- 文字: F --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00,
/*-- 文字: G --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xC0, 0x30, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x07, 0x18, 0x20, 0x20, 0x22, 0x1E, 0x02, 0x00,
/*-- 文字: H --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x21, 0x3F, 0x20,
/*-- 文字: I --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: J --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, 0x00,
/*-- 文字: K --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x88, 0xC0, 0x28, 0x18, 0x08, 0x00, 0x20, 0x3F, 0x20, 0x01, 0x26, 0x38, 0x20, 0x00,
/*-- 文字: L --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00,
/*-- 文字: M --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0xF8, 0x00, 0xF8, 0xF8, 0x08, 0x00, 0x20, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x20, 0x00,
/*-- 文字: N --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x30, 0xC0, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x20, 0x00, 0x07, 0x18, 0x3F, 0x00,
/*-- 文字: O --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00,
/*-- 文字: P --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x08, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x01, 0x00, 0x00,
/*-- 文字: Q --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x18, 0x24, 0x24, 0x38, 0x50, 0x4F, 0x00,
/*-- 文字: R --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x0C, 0x30, 0x20,
/*-- 文字: S --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x70, 0x88, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x38, 0x20, 0x21, 0x21, 0x22, 0x1C, 0x00,
/*-- 文字: T --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x18, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00,
/*-- 文字: U --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00,
/*-- 文字: V --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0x78, 0x88, 0x00, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x07, 0x38, 0x0E, 0x01, 0x00, 0x00,
/*-- 文字: W --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0xF8, 0x08, 0x00, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x03, 0x3C, 0x07, 0x00, 0x07, 0x3C, 0x03, 0x00,
/*-- 文字: X --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0x18, 0x68, 0x80, 0x80, 0x68, 0x18, 0x08, 0x20, 0x30, 0x2C, 0x03, 0x03, 0x2C, 0x30, 0x20,
/*-- 文字: Y --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0x38, 0xC8, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00,
/*-- 文字: Z --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x10, 0x08, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x20, 0x38, 0x26, 0x21, 0x20, 0x20, 0x18, 0x00,
/*-- 文字: [ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x00,
/*-- 文字: \ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x38, 0xC0, 0x00,
/*-- 文字: ] --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x00, 0x00, 0x00,
/*-- 文字: ^ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: _ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
/*-- 文字: ` --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: a --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x19, 0x24, 0x22, 0x22, 0x22, 0x3F, 0x20,
/*-- 文字: b --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: c --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x00,
/*-- 文字: d --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0xF8, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x10, 0x3F, 0x20,
/*-- 文字: e --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00,
/*-- 文字: f --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x18, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: g --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x6B, 0x94, 0x94, 0x94, 0x93, 0x60, 0x00,
/*-- 文字: h --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20,
/*-- 文字: i --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: j --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00,
/*-- 文字: k --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x08, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x24, 0x02, 0x2D, 0x30, 0x20, 0x00,
/*-- 文字: l --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x08, 0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: m --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x3F, 0x20, 0x00, 0x3F,
/*-- 文字: n --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20,
/*-- 文字: o --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00,
/*-- 文字: p --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xA1, 0x20, 0x20, 0x11, 0x0E, 0x00,
/*-- 文字: q --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0xA0, 0xFF, 0x80,
/*-- 文字: r --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x20, 0x3F, 0x21, 0x20, 0x00, 0x01, 0x00,
/*-- 文字: s --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x33, 0x24, 0x24, 0x24, 0x24, 0x19, 0x00,
/*-- 文字: t --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x00, 0x00,
/*-- 文字: u --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x10, 0x3F, 0x20,
/*-- 文字: v --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0E, 0x30, 0x08, 0x06, 0x01, 0x00,
/*-- 文字: w --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, 0x0F, 0x30, 0x0C, 0x03, 0x0C, 0x30, 0x0F, 0x00,
/*-- 文字: x --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x31, 0x2E, 0x0E, 0x31, 0x20, 0x00,
/*-- 文字: y --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x81, 0x8E, 0x70, 0x18, 0x06, 0x01, 0x00,
/*-- 文字: z --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x21, 0x30, 0x2C, 0x22, 0x21, 0x30, 0x00,
/*-- 文字: { --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0x80, 0x7C, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40,
/*-- 文字: | --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
/*-- 文字: } --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x02, 0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00,
/*-- 文字: ~ --*/
/*-- Comic Sans MS12; 此字体下对应的点阵为宽x高=8x16 --*/
0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static unsigned char ascii_table_5x8[95][5] = {
/*全体ASCII 列表:5x8点阵*/
0x00, 0x00, 0x00, 0x00, 0x00, //space
0x00, 0x00, 0x4f, 0x00, 0x00, //!
0x00, 0x07, 0x00, 0x07, 0x00, //"
0x14, 0x7f, 0x14, 0x7f, 0x14, //#
0x24, 0x2a, 0x7f, 0x2a, 0x12, //$
0x23, 0x13, 0x08, 0x64, 0x62, //%
0x36, 0x49, 0x55, 0x22, 0x50, //&
0x00, 0x05, 0x07, 0x00, 0x00, //]
0x00, 0x1c, 0x22, 0x41, 0x00, //(
0x00, 0x41, 0x22, 0x1c, 0x00, //)
0x14, 0x08, 0x3e, 0x08, 0x14, //*
0x08, 0x08, 0x3e, 0x08, 0x08, //+
0x00, 0x50, 0x30, 0x00, 0x00, //,
0x08, 0x08, 0x08, 0x08, 0x08, //-
0x00, 0x60, 0x60, 0x00, 0x00, //.
0x20, 0x10, 0x08, 0x04, 0x02, ///
0x3e, 0x51, 0x49, 0x45, 0x3e, //0
0x00, 0x42, 0x7f, 0x40, 0x00, //1
0x42, 0x61, 0x51, 0x49, 0x46, //2
0x21, 0x41, 0x45, 0x4b, 0x31, //3
0x18, 0x14, 0x12, 0x7f, 0x10, //4
0x27, 0x45, 0x45, 0x45, 0x39, //5
0x3c, 0x4a, 0x49, 0x49, 0x30, //6
0x01, 0x71, 0x09, 0x05, 0x03, //7
0x36, 0x49, 0x49, 0x49, 0x36, //8
0x06, 0x49, 0x49, 0x29, 0x1e, //9
0x00, 0x36, 0x36, 0x00, 0x00, //:
0x00, 0x56, 0x36, 0x00, 0x00, //;
0x08, 0x14, 0x22, 0x41, 0x00, //<
0x14, 0x14, 0x14, 0x14, 0x14, //=
0x00, 0x41, 0x22, 0x14, 0x08, //>
0x02, 0x01, 0x51, 0x09, 0x06, //?
0x32, 0x49, 0x79, 0x41, 0x3e, //@
0x7e, 0x11, 0x11, 0x11, 0x7e, //A
0x7f, 0x49, 0x49, 0x49, 0x36, //B
0x3e, 0x41, 0x41, 0x41, 0x22, //C
0x7f, 0x41, 0x41, 0x22, 0x1c, //D
0x7f, 0x49, 0x49, 0x49, 0x41, //E
0x7f, 0x09, 0x09, 0x09, 0x01, //F
0x3e, 0x41, 0x49, 0x49, 0x7a, //G
0x7f, 0x08, 0x08, 0x08, 0x7f, //H
0x00, 0x41, 0x7f, 0x41, 0x00, //I
0x20, 0x40, 0x41, 0x3f, 0x01, //J
0x7f, 0x08, 0x14, 0x22, 0x41, //K
0x7f, 0x40, 0x40, 0x40, 0x40, //L
0x7f, 0x02, 0x0c, 0x02, 0x7f, //M
0x7f, 0x04, 0x08, 0x10, 0x7f, //N
0x3e, 0x41, 0x41, 0x41, 0x3e, //O
0x7f, 0x09, 0x09, 0x09, 0x06, //P
0x3e, 0x41, 0x51, 0x21, 0x5e, //Q
0x7f, 0x09, 0x19, 0x29, 0x46, //R
0x46, 0x49, 0x49, 0x49, 0x31, //S
0x01, 0x01, 0x7f, 0x01, 0x01, //T
0x3f, 0x40, 0x40, 0x40, 0x3f, //U
0x1f, 0x20, 0x40, 0x20, 0x1f, //V
0x3f, 0x40, 0x38, 0x40, 0x3f, //W
0x63, 0x14, 0x08, 0x14, 0x63, //X
0x07, 0x08, 0x70, 0x08, 0x07, //Y
0x61, 0x51, 0x49, 0x45, 0x43, //Z
0x00, 0x7f, 0x41, 0x41, 0x00, //[
0x02, 0x04, 0x08, 0x10, 0x20, //\
0x00,0x41,0x41,0x7f,0x00,//]
0x04, 0x02, 0x01, 0x02, 0x04, //^
0x40, 0x40, 0x40, 0x40, 0x40, //_
0x01, 0x02, 0x04, 0x00, 0x00, //`
0x20, 0x54, 0x54, 0x54, 0x78, //a
0x7f, 0x48, 0x48, 0x48, 0x30, //b
0x38, 0x44, 0x44, 0x44, 0x44, //c
0x30, 0x48, 0x48, 0x48, 0x7f, //d
0x38, 0x54, 0x54, 0x54, 0x58, //e
0x00, 0x08, 0x7e, 0x09, 0x02, //f
0x48, 0x54, 0x54, 0x54, 0x3c, //g
0x7f, 0x08, 0x08, 0x08, 0x70, //h
0x00, 0x00, 0x7a, 0x00, 0x00, //i
0x20, 0x40, 0x40, 0x3d, 0x00, //j
0x7f, 0x20, 0x28, 0x44, 0x00, //k
0x00, 0x41, 0x7f, 0x40, 0x00, //l
0x7c, 0x04, 0x38, 0x04, 0x7c, //m
0x7c, 0x08, 0x04, 0x04, 0x78, //n
0x38, 0x44, 0x44, 0x44, 0x38, //o
0x7c, 0x14, 0x14, 0x14, 0x08, //p
0x08, 0x14, 0x14, 0x14, 0x7c, //q
0x7c, 0x08, 0x04, 0x04, 0x08, //r
0x48, 0x54, 0x54, 0x54, 0x24, //s
0x04, 0x04, 0x3f, 0x44, 0x24, //t
0x3c, 0x40, 0x40, 0x40, 0x3c, //u
0x1c, 0x20, 0x40, 0x20, 0x1c, //v
0x3c, 0x40, 0x30, 0x40, 0x3c, //w
0x44, 0x28, 0x10, 0x28, 0x44, //x
0x04, 0x48, 0x30, 0x08, 0x04, //y
0x44, 0x64, 0x54, 0x4c, 0x44, //z
0x08, 0x36, 0x41, 0x41, 0x00, //{
0x00, 0x00, 0x77, 0x00, 0x00, //|
0x00, 0x41, 0x41, 0x36, 0x08, //}
0x04, 0x02, 0x02, 0x02, 0x01, //~
};
Lcd::Lcd() : spi_sck(51), spi_sda(72), spi_cs(154), spi_reset(150), spi_rs(156),COM_BOOT0(153)
{
printf("Lcd()\n");
write_dev(IOEXPORTPATH,51);
write_dev(IOEXPORTPATH,72);
write_dev(IOEXPORTPATH,154);
write_dev(IOEXPORTPATH,150);
write_dev(IOEXPORTPATH,156);
write_dev(IOEXPORTPATH,153);
COM_BOOT0.setDirection(Gpio::out);
spi_sck.setDirection(Gpio::out);
spi_sda.setDirection(Gpio::out);
spi_cs.setDirection(Gpio::out);
spi_reset.setDirection(Gpio::out);
spi_rs.setDirection(Gpio::out);
COM_BOOT0.setValue(Gpio::Low);
spi_sck.setValue(Gpio::High);
spi_sda.setValue(Gpio::High);
spi_cs.setValue(Gpio::High);
spi_reset.setValue(Gpio::High);
spi_rs.setValue(Gpio::High);
}
/*=======写指令========*/
void Lcd::Lcd_Transfer_Command(int data1)
{
spi_cs.setValue(Gpio::Low);
spi_rs.setValue(Gpio::Low);
for (int i = 0; i < 8; i++)
{
spi_sck.setValue(Gpio::Low);
if (data1 & 0x80)
spi_sda.setValue(Gpio::High);
else
spi_sda.setValue(Gpio::Low);
spi_sck.setValue(Gpio::High);
data1 = data1 <<= 1;
}
spi_cs.setValue(Gpio::High);
}
/*--------写数据------------*/
void Lcd::Lcd_Transfer_data(int data1)
{
spi_cs.setValue(Gpio::Low);
spi_rs.setValue(Gpio::High);
for (int i = 0; i < 8; i++)
{
spi_sck.setValue(Gpio::Low);
if (data1 & 0x80)
spi_sda.setValue(Gpio::High);
else
spi_sda.setValue(Gpio::Low);
spi_sck.setValue(Gpio::High);
data1 = data1 <<= 1;
}
spi_cs.setValue(Gpio::High);
}
/*LCD模块初始化*/
void Lcd::Lcd_Initial_Lcd(bool biglcd)
{
spi_cs.setValue(Gpio::Low);
spi_reset.setValue(Gpio::Low); /*低电平复位*/
DELAY_MS(20);
spi_reset.setValue(Gpio::High); /*复位完毕*/
DELAY_MS(20);
Lcd_Transfer_Command(0xe2); /*软复位*/
DELAY_MS(50);
Lcd_Transfer_Command(0x2c); /*升压步聚1*/
DELAY_MS(50);
Lcd_Transfer_Command(0x2e); /*升压步聚2*/
DELAY_MS(50);
Lcd_Transfer_Command(0x2f); /*升压步聚3*/
DELAY_MS(50);
Lcd_Transfer_Command(biglcd?0x21:0x24); /*0X24粗调对比度可设置范围0x200x27*/
Lcd_Transfer_Command(0x81); /*微调对比度*/
Lcd_Transfer_Command(biglcd?0x28:0x15); /*45微调对比度的值可设置范围0x000x3f 1f*/ // 0~63
Lcd_Transfer_Command(0xa2); /*1/9偏压比bias0xa2 ,1/7bias 0xa3*/
Lcd_Transfer_Command(0xc8); /*行扫描顺序:从上到下*/ //原 c0 字体倒置 CF /////////////////////////////////////////////////////////////
Lcd_Transfer_Command(0xa0); /*列扫描顺序:从左到右*/ //原 a1 字体倒置 A0 ////////////////////////////////////////////////
Lcd_Transfer_Command(0x40); /*起始行:第一行开始*/
Lcd_Transfer_Command(0xaf); /*开显示*/
spi_cs.setValue(Gpio::High);
}
void Lcd::Lcd_Address(unsigned char page, unsigned char column)
{
spi_cs.setValue(Gpio::Low);
column = column - 1;
page = page - 1;
Lcd_Transfer_Command(0xb0 + page); //设置页地址。每页是8行。一个画面的64行被分成8个页。我们平常所说的第1页在LCD驱动IC里是第0页所以在这里减去1*/
Lcd_Transfer_Command(((column >> 4) & 0x0f) + 0x10); //设置列地址的高4位
Lcd_Transfer_Command(column & 0x0f); //设置列地址的低4位
}
/*全屏清屏*/
void Lcd::Lcd_Clear_screen()
{
unsigned char i, j;
spi_cs.setValue(Gpio::Low);
for (i = 0; i < 4; i++)
{
Lcd_Address(1 + i, 1);
for (j = 0; j < 132; j++)
{
Lcd_Transfer_data(0x00);
}
}
spi_cs.setValue(Gpio::High);
}
//===显示测试画面:例如全显示,隔行显示,隔列显示,雪花显示=====
void Lcd::Lcd_Test_Display(unsigned char data1, unsigned char data2)
{
int i, j;
for (j = 0; j < 8; j++)
{
spi_cs.setValue(Gpio::Low);
Lcd_Address(j + 1, 1);
for (i = 0; i < 128; i++)
{
Lcd_Transfer_data(data1);
Lcd_Transfer_data(data2);
}
}
}
/*显示128x64点阵图像*/
void Lcd::Lcd_Display_Graphic_128x64(unsigned char page, unsigned char column, unsigned char *dp)
{
int i, j;
for (j = 0; j < 8; j++)
{
spi_cs.setValue(Gpio::Low);
Lcd_Address(page + j, column);
for (i = 0; i < 128; i++)
{
Lcd_Transfer_data(*dp);
dp++;
}
}
}
/*显示32x32点阵图像、汉字、生僻字或32x32点阵的其他图标*/
void Lcd::Lcd_Display_graphic_32x32(unsigned char page, unsigned char column, unsigned char *dp)
{
unsigned char i, j;
spi_cs.setValue(Gpio::Low);
for (j = 0; j < 4; j++)
{
Lcd_Address(page + j, column);
for (i = 0; i < 31; i++)
{
Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
dp++;
}
}
}
/*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/
void Lcd::Lcd_Display_Graphic_16x16_2(unsigned char reverse, unsigned char page, unsigned char column, unsigned char *dp)
{
unsigned char i, j;
spi_cs.setValue(Gpio::Low);
for (j = 0; j < 2; j++)
{
Lcd_Address(page + j, column);
for (i = 0; i < 16; i++)
{
if (reverse == 1)
Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
else
Lcd_Transfer_data(~*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
dp++;
}
}
spi_cs.setValue(Gpio::High);
}
/*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/
void Lcd::Lcd_Display_Graphic_16x16(unsigned char page, unsigned char column, unsigned char *dp, unsigned int wordcount)
{
unsigned char i, j, k;
spi_cs.setValue(Gpio::Low);
for (k = 0; k < wordcount; k++)
{
for (j = 0; j < 2; j++)
{
Lcd_Address(page + j, column + 16 * k);
for (i = 0; i < 16; i++)
{
Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
dp++;
}
}
}
spi_cs.setValue(Gpio::High);
}
/*显示8x16点阵图像、ASCII, 或8x16点阵的自造字符、其他图标*/
void Lcd::Lcd_Display_Graphic_8x16(unsigned char page, unsigned char column, unsigned char *dp)
{
unsigned char i, j;
spi_cs.setValue(Gpio::Low);
for (j = 0; j < 2; j++)
{
Lcd_Address(page + j, column);
for (i = 0; i < 8; i++)
{
Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
dp++;
}
}
spi_cs.setValue(Gpio::High);
}
void Lcd::Lcd_Display_String_8x16(unsigned int page, unsigned int column, const char *text)
{
unsigned int i = 0, j, k, n;
spi_cs.setValue(Gpio::Low);
while (text[i] > 0x00)
{
if ((text[i] >= 0x20) && (text[i] <= 0x7e))
{
j = text[i] - 0x20;
for (n = 0; n < 2; n++)
{
Lcd_Address(page + n, column);
for (k = 0; k < 8; k++)
{
Lcd_Transfer_data(ascii_table_8x16[j][k + 8 * n]); /*显示5x7的ASCII字到LCD上y为页地址x为列地址最后为数据*/
}
}
i++;
column += 8;
}
else
i++;
}
}
void Lcd::Lcd_Display_String_5x8(unsigned int page, unsigned int column, const char *text)
{
unsigned int i = 0, j, k;
spi_cs.setValue(Gpio::Low);
while (text[i] > 0x00)
{
if ((text[i] >= 0x20) && (text[i] < 0x7e))
{
j = text[i] - 0x20;
Lcd_Address(page, column);
for (k = 0; k < 5; k++)
{
Lcd_Transfer_data(ascii_table_5x8[j][k]); /*显示5x7的ASCII字到LCD上y为页地址x为列地址最后为数据*/
}
i++;
column += 6;
}
else
i++;
}
}
void Lcd::Lcd_Clear_Half_Screen(bool top)
{
int pageindex = top ? 0 : 2;
int pagemaxindex = top ? 2 : 4;
spi_cs.setValue(Gpio::Low);
for (int i = pageindex; i < pagemaxindex; i++)
{
Lcd_Address(1 + i, 1);
for (int j = 0; j < 132; j++)
{
Lcd_Transfer_data(0x00);
}
}
spi_cs.setValue(Gpio::High);
}

View File

@ -0,0 +1,61 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <time.h>
#include <unistd.h>
#include "Gpio.h"
class Lcd
{
private:
Gpio spi_sck;
Gpio spi_sda;
Gpio spi_cs;
Gpio spi_reset;
Gpio spi_rs;
Gpio COM_BOOT0;
public:
Lcd();
/*=======写指令========*/
void Lcd_Transfer_Command(int data1);
/*--------写数据------------*/
void Lcd_Transfer_data(int data1);
/*LCD模块初始化*/
void Lcd_Initial_Lcd(bool biglcd);
void Lcd_Address(unsigned char page, unsigned char column);
/*全屏清屏*/
void Lcd_Clear_screen();
void Lcd_Clear_Half_Screen(bool top);
//===显示测试画面:例如全显示,隔行显示,隔列显示,雪花显示=====
void Lcd_Test_Display(unsigned char data1, unsigned char data2);
/*显示128x64点阵图像*/
void Lcd_Display_Graphic_128x64(unsigned char page, unsigned char column, unsigned char *dp);
/*显示32x32点阵图像、汉字、生僻字或32x32点阵的其他图标*/
void Lcd_Display_graphic_32x32(unsigned char page, unsigned char column, unsigned char *dp);
/*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/
void Lcd_Display_Graphic_16x16_2(unsigned char reverse,unsigned char page,unsigned char column,unsigned char *dp);
/*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/
void Lcd_Display_Graphic_16x16(unsigned char page, unsigned char column, unsigned char *dp,unsigned int wordcount);
/*显示8x16点阵图像、ASCII, 或8x16点阵的自造字符、其他图标*/
void Lcd_Display_Graphic_8x16(unsigned char page, unsigned char column,unsigned char *dp);
void Lcd_Display_String_8x16(unsigned int page, unsigned int column, const char *text);
void Lcd_Display_String_5x8(unsigned int page, unsigned int column, const char *text);
};

View File

@ -0,0 +1,9 @@
add_rules("mode.debug", "mode.release")
target("display")
set_kind("static")
add_syslinks("pthread")
add_files("*.cpp")
add_packages("common")
add_deps("deviceio", {public = true})
add_includedirs(".", { public = true})

View File

@ -0,0 +1,6 @@
ch455_key:ch455_key.cpp
g++ $^ -o $@
clean:
rm ch455_key

Binary file not shown.

View File

@ -0,0 +1,334 @@
#include <iostream>
#include <iomanip>
#include <memory>
#include <thread>
#include <chrono>
#include <functional>
#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
#define I2C_SDA 43//GPIO1_B3
#define I2C_SCL 44//GPIO1_B4
#define I2C_INT 52
typedef unsigned char UINT8;
typedef unsigned short UINT16;
#define STATUS_SUCCESS 0
#define STATUS_FAILURE -1
#define CH455_GET_KEY 0x0700 // 获取按键,返回按键代码
#define CH455_SYSOFF 0x0400 // 关闭显示、关闭键盘
#define CH455_I2C_ADDR 0x40 // CH455的地址
#define CH455_I2C_MASK 0x3E // CH455的高字节命令掩码
#define CH455_BIT_ENABLE 0x01
//#define CH455_BIT_ENABLE 0x03 // 开启/关闭位
#define CH455_BIT_SLEEP 0x04 // 睡眠控制位
#define CH455_SYSON ( CH455_SYSOFF | CH455_BIT_ENABLE )
#define CH455_SLEEPOFF CH455_SYSOFF // 关闭睡眠
#define CH455_SLEEPON (CH455_SYSOFF|CH455_BIT_SLEEP) // 开启睡眠
static unsigned char TxBuf[24] = {0};
static unsigned char RxBuf[24] = {0};
void CH455_I2c_Stop(void);
void CH455_I2C_WrByte(unsigned char IIC_Byte);
void delay_us(int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<10;k++);
}
void initGpio(int addr)
{
//printf("开始创建GPIO%d节点\n", addr);
FILE * fp =fopen("/sys/class/gpio/export","w");
if (fp == NULL)
perror("export open filed");
else
fprintf(fp,"%d",addr);
fclose(fp);
//printf("结束创建GPIO%d节点\n", addr);
}
//设置为gpio方向
void setGpioDirection(int addr,char *direction)
{
//printf("设置第GPIO%d为out模式\n",addr);
char path[100] = {0};
sprintf(path,"/sys/class/gpio/gpio%d/direction",addr);
FILE * fp =fopen(path,"w");
if (fp == NULL)
perror("direction open filed");
else
fprintf(fp,"%s",direction);
fclose(fp);
//printf("结束设置第GPIO%d为out模式\n",addr);
}
//设置gpio的电平
void set_gpioValue(int addr, int value)
{
//printf("设置GPIO%d为%d\n", addr, value);
char path[64];
snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d/value", addr);
FILE *fp = fopen(path, "w");
if (fp == NULL)
perror("direction open filed");
else
fprintf(fp, "%d", value);
fclose(fp);
//printf("结束设置GPIO%d位置为%d\n", addr, value);
}
void IOWR_OUT(int addr, int val)
{
initGpio(addr);
setGpioDirection(addr, "out");
set_gpioValue(addr, val);
}
void IOWR_IN(int addr, int val)
{
initGpio(addr);
setGpioDirection(addr, "in");
set_gpioValue(addr, val);
}
//读gpio节点状态
int IORD(int addr)
{
char path[64];
char value_str[3];
snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d/value",addr);
//printf("/sys/class/gpio/gpio%d/value", addr);
FILE *fp = fopen(path, "r");
//fd = open(path, O_RDONLY);
if (fp == NULL)
{
printf("Failed to open gpio value for reading!");
return -1;
}
if (fread(value_str,sizeof(char),3,fp) < 0)
{
perror("Failed to read value!");
return -1;
}
fclose(fp);
//printf("读取GPIO状态结束\n");
return (atoi(value_str));
}
//开始位
void CH455_I2c_Start(void)
{
IOWR_OUT(I2C_SDA, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
IOWR_OUT(I2C_SDA, 0);
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
}
//结束位
void CH455_I2c_Stop(void)
{
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
IOWR_OUT(I2C_SDA, 0);
delay_us(5);
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
IOWR_OUT(I2C_SDA, 1);
delay_us(5);
}
//主控端写入一个字节到从机
void CH455_I2C_WrByte(unsigned char IIC_Byte)
{
unsigned char i;
for(i=0; i<8; i++)
{
//IOWR(I2C_SCL, 0); //钳住I2C总线准备发送数据
if(IIC_Byte & 0x80)
IOWR_OUT(I2C_SDA, 1);
else
IOWR_OUT(I2C_SDA, 0);
delay_us(5);
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
IIC_Byte<<=1;
}
delay_us(5);
IOWR_OUT(I2C_SDA, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
}
//主控端对从机读取一个字节
static unsigned char CH455_I2C_RdByte(void) //读取一个字节数据
{
unsigned char i = 0;
unsigned char bytedata = 0;
delay_us(5);
//将数据设置为输入模式
IOWR_IN(I2C_SDA, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
for(i=0; i<8; i++)
{
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
bytedata <<= 1;
delay_us(5);
bytedata = bytedata | (IORD(I2C_SDA));
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
}
IOWR_OUT(I2C_SDA, 1); //数据线设置回输出模式
delay_us(5);
IOWR_OUT(I2C_SCL, 1);
delay_us(5);
IOWR_OUT(I2C_SCL, 0);
delay_us(5);
return (bytedata);//返回数据
}
//写命令
static unsigned char CH455_Write( UINT16 cmd)
{
printf("CH455_Write start...\n");
CH455_I2c_Start();//启动总线
printf("CH455_Write first byte= %02x\n",((UINT8)(cmd>>7)&CH455_I2C_MASK)|CH455_I2C_ADDR);
printf("CH455_Write second byte= %02x\n",(UINT8)cmd);
CH455_I2C_WrByte(((UINT8)(cmd>>7)&CH455_I2C_MASK)|CH455_I2C_ADDR);
CH455_I2C_WrByte((UINT8)cmd); //发送数据
CH455_I2c_Stop();//结束总线
printf("CH455_Write end...\n");
printf("\n");
return 1;
}
static unsigned char CH455_Read(void)//读取按键值
{
printf("CH455_Read start...\n");
UINT8 keycode;
CH455_I2c_Start(); //启动总线
printf("write byte= %02x\n",(UINT8)(CH455_GET_KEY>>7)&CH455_I2C_MASK|0x01|CH455_I2C_ADDR);
CH455_I2C_WrByte((UINT8)(CH455_GET_KEY>>7)&CH455_I2C_MASK|0x01|CH455_I2C_ADDR);
keycode = CH455_I2C_RdByte(); //读取数据
printf("read byte= %02x\n",keycode);
CH455_I2c_Stop(); //结束总线
printf("CH455_Read end...\n");
printf("\n");
return keycode;
}
void key_Inter(void)
{
int ret;
int val = 0;
char buf[8];
int num;
UINT16 key_value;
pollfd pfd;
pfd.fd = -1;
pfd.fd = open("/sys/class/gpio/gpio52/value", O_RDONLY);
if (pfd.fd > 0)
printf("huagao::open sucess,fd = %d\n",pfd.fd);
else
printf("huagao::open failed,fd = %d\n",pfd.fd);
pfd.events = POLLPRI;
num = read(pfd.fd, buf, 8); // This is to clear the avaible read
for(int i=0;i<8;i++)
printf("huagao::buf[%d] = %d\n",i,buf[i]);
ret = CH455_Write(CH455_SYSON);
printf("CH455_SYSON = %02x\n",(CH455_SYSON));
printf("CH455_Read() = %02x\n", CH455_Read());
key_value = 0xff;
while(1) {
ret = poll(&pfd, 1, 1000);
if (ret > 0)
{
printf("--------------------------------------------\n");
printf("huagao::poll get date.\n");
printf("huagao::poll ret = %d\n",ret);
/*
POLLIN:
POLLRDNORM:
POLLRDBAND:
POLLPRI:
POLLOUT:
POLLWRNORM:
POLLWRBAND:
POLLERR:
POLLHUP:
POLLNVAL:
*/
if (pfd.revents & POLLPRI)
{
lseek(pfd.fd, 0, SEEK_SET);
num = read(pfd.fd, buf, 8);
buf[num - 1] = '\0';
ret = atoi(buf);
for(int i=0;i<8;i++)
printf("huagao::buf[%d] = %d\n",i,buf[i]);
printf("huagao::atoi(buf) ret = %d\n",ret);
}
key_value = CH455_Read();
printf("CH455_Read() = %02x\n", key_value);
printf("--------------------------------------------\n");
printf("\n");
}
else if(ret == 0)
{
printf("--------------------------------------------\n");
printf("huagao::ret = %d\n",ret);
printf("huagao::poll time out.\n");
printf("--------------------------------------------\n");
printf("\n");
}
else
{
printf("--------------------------------------------\n");
printf("huagao::ret = %d\n",ret);
printf("huagao::poll err.\n");
printf("--------------------------------------------\n");
printf("\n");
}
}
}
int main(void)
{
system("echo 52 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio52/direction");
system("echo falling > /sys/class/gpio/gpio52/edge");
key_Inter();
return 0;
}

View File

@ -1,7 +1,5 @@
#include "CSizedetect.h"
#include <opencv2/opencv.hpp>
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include "ImageProcess_Public.h"
#include "commondef.h"
@ -134,8 +132,7 @@ int CSizedetect::preprocess(cv::Mat &mat, void *unused)
{
if(!mat.empty())
{
float width, height;
float width, height;
cv::Mat thre;
hg::threshold_Mat(mat, thre, 40);
cv::Mat element = getStructuringElement(cv::MORPH_RECT, cv::Size(8, 1));

View File

@ -26,15 +26,16 @@ private:
{PaperSize::G400_A5R,HGSize{1653,1165}},
{PaperSize::G400_A6,HGSize{826,1165}},
{PaperSize::G400_A6R,HGSize{1165,826}},
{PaperSize::G400_B4,HGSize{2023,2866}},
{PaperSize::G400_B4,HGSize{1969,2780}},
{PaperSize::G400_B5,HGSize{1385,1968}},
{PaperSize::G400_B5R,HGSize{1968,1385}},
{PaperSize::G400_B6R,HGSize{1433,1007}},
{PaperSize::G400_B6,HGSize{1007,1433}},
{PaperSize::G400_DOUBLELETTER,HGSize{2200,3400}},
{PaperSize::G400_LEGAL,HGSize{1700,2800}},
{PaperSize::G400_LETTER,HGSize{1700,2640}},
{PaperSize::G400_LETTER,HGSize{1700,2198}},
{PaperSize::G400_LETTERR,HGSize{2198,1700}},
{PaperSize::G400_LONGLETTER,HGSize{2040,2640}},
{PaperSize::G400_MAXSIZE,HGSize{2338,6614}}
{PaperSize::G400_MAXSIZE,HGSize{2338,8189}}
};
};

View File

@ -28,31 +28,55 @@ JpegImageEncode::JpegImageEncode(bool bwimg, int dpi)
{
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);
compression_params.push_back(/*cv::CV_IMWRITE_JPEG_RESOLUTION_X*/7);
compression_params.push_back(cv::IMWRITE_RESOLUTION_X);
compression_params.push_back(dpi);
compression_params.push_back(/*cv::CV_IMWRITE_JPEG_RESOLUTION_Y*/8);
compression_params.push_back(cv::IMWRITE_RESOLUTION_Y);
compression_params.push_back(dpi);
}
else{
compression_params.push_back(/*CV_IMWRITE_PNG_STRATEGY*/17);
compression_params.push_back(CV_IMWRITE_PNG_STRATEGY);
compression_params.push_back(cv::IMWRITE_PNG_STRATEGY_FIXED);
}
m_bwimg = bwimg;
}
JpegImageEncode::JpegImageEncode(const char* fmt, int dpi) : fmt_(fmt ? fmt : "")
{
if(fmt_ == "PNG")
{
compression_params.push_back(CV_IMWRITE_PNG_STRATEGY);
compression_params.push_back(cv::IMWRITE_PNG_STRATEGY_FIXED);
}
else
{
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);
compression_params.push_back(cv::IMWRITE_RESOLUTION_X);
compression_params.push_back(dpi);
compression_params.push_back(cv::IMWRITE_RESOLUTION_Y);
compression_params.push_back(dpi);
}
}
JpegImageEncode::~JpegImageEncode()
{
}
MemoryPtr JpegImageEncode::encode(cv::Mat &image)
{
VectorMemroyPtr mem = VectorMemroyPtr(new VectorMemroy());
// StopWatch sw;
printf("encode image(%d * %d): %p - %p\n", image.cols, image.rows, image.data, image.dataend);
// cv::imwrite("beforcompress.jpg",image);
// cv::imencode(m_bwimg ? ".png" : ".jpg", image, mem->buf(), compression_params);
cv::imencode(".jpg", image, mem->buf(), compression_params);
StopWatch sw;
std::string type(m_bwimg ? ".png" : ".jpg");
//printf("encode time = %0.2f \n", sw.elapsed_ms());
if(fmt_ == "PNG")
type = ".png";
else if(fmt_ == "TIFF")
type = ".tiff";
else
type = ".jpg";
cv::imencode(type.c_str(), image, mem->buf(), compression_params);
printf("encode time = %0.2f \n", sw.elapsed_ms());
return mem;
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "iimageencode.h"
#include <vector>
#include <string>
// typedef struct tagBITMAPFILEHEADER {
// WORD bfType;
@ -20,8 +21,11 @@ public:
class JpegImageEncode : public IImageEncode
{
std::string fmt_;
public:
JpegImageEncode(bool bwimg, int dpi);
JpegImageEncode(const char* fmt, int dpi);
virtual ~JpegImageEncode();
virtual MemoryPtr encode(cv::Mat& image);

View File

@ -4,10 +4,11 @@ target("gimgproc")
set_kind("static")
add_syslinks("pthread")
add_files("*.cpp")
add_files("ImageProcess/*.cpp")
del_files("ImageProcess/ImageApplyBarCodeRecognition.cpp")
add_includedirs("ImageProcess", {public = true})
add_links("opencv_core", "opencv_imgproc", "opencv_imgcodecs", "FreeImage",{ public = true})
add_files("imageprocess/*.cpp")
--del_files("imageprocess/ImageApplyBarCodeRecognition.cpp")
remove_files("imageprocess/ImageApplyBarCodeRecognition.cpp")
add_includedirs("imageprocess", {public = true})
add_links("opencv_core", "opencv_imgproc", "opencv_imgcodecs", "freeimageplus", "freeimage",{ public = true})
add_includedirs(".", { public = true})
add_defines("_DIRECT_BUILD")
add_packages("common")

View File

@ -0,0 +1,204 @@
#include "keymonitor.h"
#include "Gpio.h"
#include "PinMonitor.h"
#include <iostream>
#define STATUS_SUCCESS 0
#define STATUS_FAILURE -1
#define CH455_GET_KEY 0x0700 // 获取按键,返回按键代码
#define CH455_SYSOFF 0x0400 // 关闭显示、关闭键盘
#define CH455_I2C_ADDR 0x40 // CH455的地址
#define CH455_I2C_MASK 0x3E // CH455的高字节命令掩码
#define CH455_BIT_ENABLE 0x01
//#define CH455_BIT_ENABLE 0x03 // 开启/关闭位
#define CH455_BIT_SLEEP 0x04 // 睡眠控制位
#define CH455_SYSON ( CH455_SYSOFF | CH455_BIT_ENABLE )
#define CH455_SLEEPOFF CH455_SYSOFF // 关闭睡眠
#define CH455_SLEEPON (CH455_SYSOFF|CH455_BIT_SLEEP) // 开启睡眠
KeyMonitor::KeyMonitor(std::function<void(int)> keycall) : m_keycall(keycall)
{
m_gpioi2c_SCL = std::make_shared<Gpio>(44); //I2C_SCL
m_gpioi2c_SCL->setDirection(Gpio::out);
m_gpioi2c_SDA = std::make_shared<Gpio>(43); //I2C_SDA
m_gpioi2c_SDA->setDirection(Gpio::out);
write_cmd(CH455_SYSON);
printf("read_key = %02x\n", read_key());
setled(HGLed::Led_All_close);
auto pincall=[&](int pin)
{
auto value= read_key();
printf("Key = %02x pin value = %d \n",value,pin);
if(m_keycall)
m_keycall(value);
};
m_keymonitor = std::make_shared<PinMonitor>(52,pincall);
}
KeyMonitor::~KeyMonitor()
{
if(m_gpioi2c_SCL.get())
m_gpioi2c_SCL.reset();
if(m_gpioi2c_SDA.get())
m_gpioi2c_SDA.reset();
if(m_keymonitor.get())
m_keymonitor.reset();
}
void KeyMonitor::init()
{
}
void KeyMonitor::i2c_start()
{
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
}
void KeyMonitor::i2c_write(unsigned char cmd)
{
unsigned char i;
for(i=0; i<8; i++)
{
//IOWR(I2C_SCL, 0); //钳住I2C总线准备发送数据
if(cmd & 0x80)
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);
else
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
cmd<<=1;
}
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
}
unsigned char KeyMonitor::i2c_read()
{
unsigned char bytedata = 0;
m_gpioi2c_SDA->setDirection(Gpio::in);//将数据设置为输入模式
//m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
for(int i=0; i<8; i++)
{
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
bytedata <<= 1;
bytedata = bytedata | (m_gpioi2c_SDA->getValue());
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
}
m_gpioi2c_SDA->setDirection(Gpio::out);
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);////数据线设置回输出模式
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
return bytedata;
}
void KeyMonitor::i2c_stop()
{
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::Low);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SCL->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
m_gpioi2c_SDA->setValue(Gpio::GpioLevel::High);
std::this_thread::sleep_for(std::chrono::microseconds(5));
}
void KeyMonitor::write_cmd(unsigned short cmd)
{
i2c_start();
i2c_write(((unsigned char)(cmd>>7)&CH455_I2C_MASK)|CH455_I2C_ADDR);
i2c_write(cmd);
i2c_stop();
}
unsigned char KeyMonitor::read_key()
{
unsigned char key=0;
i2c_start();
i2c_write((unsigned char)(CH455_GET_KEY>>7)&CH455_I2C_MASK|0x01|CH455_I2C_ADDR);
key = i2c_read();
i2c_stop();
return key;
}
std::uint8_t KeyMonitor::getledstate()
{
return m_ledstate;
}
void KeyMonitor::setled(HGLed value)
{
switch (value)
{
case HGLed::Led_All_close:
m_ledstate = 0;
break;
#ifdef G200
case HGLed::Led_All_open:
m_ledstate = 0xf8;
break;
case HGLed::Led_Count_close:
m_ledstate = m_ledstate & 0xef;
break;
case HGLed::Led_Count_open:
m_ledstate = m_ledstate | 0x10;
break;
case HGLed::Led_DoubleFeed_close:
m_ledstate = m_ledstate & 0xbf;
break;
case HGLed::Led_DoubleFeed_open:
m_ledstate = m_ledstate | 0x40;
break;
case HGLed::Led_Enter_close:
m_ledstate = m_ledstate & 0xf7;
break;
case HGLed::Led_Enter_open:
m_ledstate = m_ledstate | 0x8;
break;
case HGLed::Led_Handle_close:
m_ledstate = m_ledstate & 0xdf;
break;
case HGLed::Led_Handle_open:
m_ledstate = m_ledstate | 0x20;
break;
#endif
default:
break;
}
i2c_start();
i2c_write(0x6e);
i2c_write(m_ledstate);
i2c_stop();
}

View File

@ -0,0 +1,71 @@
#pragma once
#include <memory>
#include <functional>
#include "commondef.h"
class PinMonitor;
class Gpio;
class KeyMonitor
{
public:
#ifdef G200
enum class HGKey
{
Key_Enter = 69,
Key_Cancle = 70,
Key_Count = 78,
Key_Handle = 77,
Key_DoubleFeed = 68,
Key_Left = 86,
Key_Menu = 85,
Key_Right = 76,
Key_Clear = 84
};
#else
enum class HGKey
{
Key_Enter = 70,
Key_Cancle = 69,
Key_Count = 78,
Key_Menu = 76,
Key_Right = 77,
Key_Clear = 68,
Key_Handle = 3331,
Key_DoubleFeed = 3332,
Key_Left = 3333
};
#endif
enum class HGLed
{
Led_Enter_open = 0,
Led_Enter_close,
Led_Count_open,
Led_Count_close,
Led_DoubleFeed_open,
Led_DoubleFeed_close,
Led_Handle_open,
Led_Handle_close,
Led_All_open,
Led_All_close
};
public:
KeyMonitor(std::function<void(int)> keycall);
void setled(HGLed value);
std::uint8_t getledstate();
~KeyMonitor();
private:
void init();
void i2c_start();
void i2c_write(unsigned char cmd);
unsigned char i2c_read();
void i2c_stop();
void write_cmd(unsigned short cmd);
unsigned char read_key();
private:
std::shared_ptr<PinMonitor> m_keymonitor;
std::shared_ptr<Gpio> m_gpioi2c_SDA;
std::shared_ptr<Gpio> m_gpioi2c_SCL;
std::function<void(int)> m_keycall;
volatile std::uint8_t m_ledstate;
};

View File

@ -0,0 +1,9 @@
add_rules("mode.debug", "mode.release")
target("keymonitor")
set_kind("static")
add_files("*.cpp")
add_syslinks("pthread")
add_deps("deviceio")
add_packages("common")
add_includedirs(".", { public = true})

Binary file not shown.

View File

@ -1,64 +0,0 @@
#include "CuoZhiMotor.h"
#include <iostream>
CuoZhiMotor::CuoZhiMotor() : Motor(motorPorts_Cuozhi)
{
m_cfg.GetParams(0,MotorConfig::MTBDType::MT_DRV);
if(Dail().GetValue().dails.in_voltage4 == 0)
m_mttype = MotorConfig::MTBDType::MT_DRV;
else
m_mttype = MotorConfig::MTBDType::MT_TMC;
speedChange(0,1,1);
printf("\nCuo speed = %d ",m_mttype);
}
CuoZhiMotor::~CuoZhiMotor()
{
std::cout << "CuoZhiMotor::~CuoZhiMotor()" << std::endl;
}
void CuoZhiMotor::speedChange(int speed,int dpi ,int iscolor)
{
printf("\nCuo speed = %d dpi = %d iscolor = %d",speed,dpi,iscolor);
if(speed == 0xff)
{
if(m_mttype == MotorConfig::MTBDType::MT_DRV)
mspCuozhiForward = { .finalPeriod = 1427500,.Fmin = 2027500 ,.stepnum = 30 ,.a = 100 ,
.offset = 4 ,.finalDelay = 3000 };
else
mspCuozhiForward = { .finalPeriod = 1427500/4,.Fmin = 2027500/4 ,.stepnum = 30 ,.a = 100 ,
.offset = 4 ,.finalDelay = 3000 };
}
else{
auto params = m_cfg.GetMotorSpeedParams(false,m_mttype);
m_speedmode = speed;
for (int i = 0; i < params.size(); i++)
{
if (params[i].dpi == dpi &&
params[i].colormode == iscolor &&
params[i].speed == (speed+1))
{
mspCuozhiForward = { .finalPeriod = params[i].mt_param.finalPeriod,.Fmin = params[i].mt_param.Fmin,.stepnum = params[i].mt_param.stepnum,.a = params[i].mt_param.a,
.offset = params[i].mt_param.offset,.finalDelay = params[i].mt_param.finalDelay };
}
}
}
printf("\n mspCuozhiForward.finalPeriod %d, mspCuozhiForward.Fmin %d, mspCuozhiForward.stepnum %f , mspCuozhiForward.a %f, mspCuozhiForward.offset %f , mspCuozhiForward.finalDelay %f",
mspCuozhiForward.finalPeriod, mspCuozhiForward.Fmin, mspCuozhiForward.stepnum, mspCuozhiForward.a, mspCuozhiForward.offset, mspCuozhiForward.finalDelay);
delays_forward = speedup_cfg(mspCuozhiForward.finalPeriod, mspCuozhiForward.Fmin, mspCuozhiForward.stepnum, mspCuozhiForward.a, mspCuozhiForward.offset, mspCuozhiForward.finalDelay);
// if(cuoZhiForwardFinalPeriod.find(dpi) == cuoZhiForwardFinalPeriod.end())
// dpi = 1;
// mspCuozhiForward = { .finalPeriod = cuoZhiForwardFinalPeriod.at(dpi)[m_speedmode],.Fmin = cuoZhiFmin.at(dpi)[m_speedmode],
// .stepnum = cuoZhiStepNum.at(dpi)[m_speedmode],.a = cuoZhiA.at(dpi)[m_speedmode],.offset = cuoZhiOffset.at(dpi)[m_speedmode],
// .finalDelay = cuoZhiFinalDelay.at(dpi)[m_speedmode] };
mspCuozhiBackward = { .finalPeriod = cuoZhiBackwardFinalPeriod.at(dpi)[m_speedmode],.Fmin = cuoZhiFmin.at(dpi)[m_speedmode],
.stepnum = cuoZhiStepNum.at(dpi)[m_speedmode],.a = cuoZhiA.at(dpi)[m_speedmode],.offset = cuoZhiOffset.at(dpi)[m_speedmode],
.finalDelay = cuoZhiFinalDelay.at(dpi)[m_speedmode] };
// delays_forward = speedup_cfg(mspCuozhiForward.finalPeriod, mspCuozhiForward.Fmin, mspCuozhiForward.stepnum, mspCuozhiForward.a,
// mspCuozhiForward.offset, mspCuozhiForward.finalDelay);
delays_backward = speedup_cfg(mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin, mspCuozhiBackward.stepnum, mspCuozhiBackward.a,
mspCuozhiBackward.offset, mspCuozhiBackward.finalDelay);
}

View File

@ -1,92 +0,0 @@
#pragma once
#include "Motor.h"
#include <thread>
class CuoZhiMotor : public Motor
{
public:
CuoZhiMotor();
~CuoZhiMotor();
void speedChange(int speed,int dpi ,int iscolor);
void reset() {
mspCuozhiBackward = {.finalPeriod = 827500, .Fmin = 1407750, .stepnum = 25, .a = 150, .offset = 8, .finalDelay = 3000};
mspCuozhiForward = {.finalPeriod = 627500, .Fmin = 1407750, .stepnum = 25, .a = 150, .offset = 8, .finalDelay = 3000};
if(m_mttype == MotorConfig::MTBDType::MT_TMC)
{
mspCuozhiBackward.finalPeriod /= 4;
mspCuozhiBackward.Fmin /= 4;
mspCuozhiForward.finalPeriod /= 4;
mspCuozhiForward.Fmin /= 4;
}
delays_forward = speedup_cfg(mspCuozhiForward.finalPeriod, mspCuozhiForward.Fmin, mspCuozhiForward.stepnum, mspCuozhiForward.a,
mspCuozhiForward.offset, mspCuozhiForward.finalDelay);
forward();
std::this_thread::sleep_for(std::chrono::milliseconds(300));
stop();
delays_backward = speedup_cfg(mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin, mspCuozhiBackward.stepnum, mspCuozhiBackward.a,
mspCuozhiBackward.offset, mspCuozhiBackward.finalDelay);
backward();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
stop();
}
virtual void start() {
forward();
}
void forward() {
setDirection(1);
Motor::start(delays_forward, mspCuozhiForward);
}
void backward() {
setDirection(0);
Motor::start(delays_backward, mspCuozhiBackward);
}
private:
MotorConfig m_cfg;
const std::map<int,std::vector<int>> cuoZhiStepNum = {
{1,{23,25,30,30,30 }},
{2,{23,25,30,30,30 }},
{3,{23,25,30,30,30 }},
};
const std::map<int,std::vector<int>> cuoZhiForwardFinalPeriod = {
{1,{607500,537500,477500,435500,435500}},
{2,{607500,537500,517500,497500,477500}},
{3,{607500,537500,527500,477500,307500}},
};//627500,607500,587500,567500,547500,527500
const std::map<int,std::vector<int>> cuoZhiBackwardFinalPeriod = {
{1,{607500,537500,477500,395500,307500}},
{2,{607500,587500,527500,477500,307500}},
{3,{607500,587500,527500,477500,307500}},
};//707500,607500,587500,567500,547500,527500
const std::map<int,std::vector<int>> cuoZhiFmin = {
{1,{ 1407750,1407750,1407750,1407750,1407750 }},
{2,{ 1407750,1407750,1407750,1407750,1407750 }},
{3,{ 1407750,1407750,1407750,1407750,1407750 }},
};
const std::map<int,std::vector<int>> cuoZhiA = {
{1,{ 180,150,150,130,130 }},
{2,{ 180,150,150,130,130 }},
{3,{ 180,150,150,150,150 }},
};
const std::map<int,std::vector<int>> cuoZhiOffset = {
{1,{ 7,7,7,12,12 }},
{2,{ 7,7,7,7,7 }},
{3,{ 7,7,7,7,7 }},
};
const std::map<int,std::vector<int>> cuoZhiFinalDelay = {
{1,{ 3000,3000,3000,3000,3000 }},
{2,{ 3000,3000,3000,3000,3000 }},
{3,{ 3000,3000,3000,3000,3000 }},
};
MotorSpeedParam mspCuozhiForward;
MotorSpeedParam mspCuozhiBackward;
std::vector<int> delays_forward;
std::vector<int> delays_backward;
int m_speedmode;
};

View File

@ -1,57 +0,0 @@
#pragma once
#include <string>
#include <fstream>
#include <memory>
#include "stringex.hpp"
template<typename T>
void write_dev(std::string path, T value) {
std::ofstream ofout(path);
ofout << value;
ofout.close();
}
extern int read_dev_i(std::string path);
extern std::string read_dev_s(std::string path);
enum PORTS
{
/* //RK3288 Motor GPIO
CuoZhiMotor_Reset = 56, // GPIO2_A0 MOTO_BOT_RESET_N
CuoZhiMotor_Sleep = 57, // GPIO2_A1 MOTO_BOT_SLEEP_N
CuoZhiMotor_Enable = 58, // GPIO2_A2 MOTO_BOT_ENBL_N
CuoZhiMotor_Direction = 62, // GPIO2_A6 MOTO_BOT_DIR
CuoZhiMotor_Home = 184, // GPIO6_A0 MOTO_BOT_HOME_N
CuoZhiMotor_Fault = 185, // GPIO6_A1 MOTO_BOT_FAULT_N
ZouZhiMotor_Reset = 64, // GPIO2_B0 MOTO_TOP_RESET_N
ZouZhiMotor_Sleep = 65, // GPIO2_B1 MOTO_TOP_SLEEP_N
ZouZhiMotor_Enable = 66, // GPIO2_B2 MOTO_TOP_ENBL_N
ZouZhiMotor_Direction = 70, // GPIO2_B6 MOTO_TOP_DIR
ZouZhiMotor_Home = 186, // GPIO6_A2
ZouZhiMotor_Fault = 187, // GPIO6_A3
*/
//RK3399 Motor GPIO
MotorPower = 157, // GPIO4_D5 motor power
CuoZhiMotor_Reset = 151, // GPIO4_C7 BOT
CuoZhiMotor_Enable = 153, // GPIO4_D1 BOT
CuoZhiMotor_Direction = 152, // GPIO4_D0 BOT
ZouZhiMotor_Reset = 155, // GPIO4_D3 TOP
ZouZhiMotor_Enable = 154, // GPIO4_D2 TOP
ZouZhiMotor_Direction = 52, // GPIO1_C4 TOP
};
class DeviceExport {
public:
DeviceExport();
private:
const int ports[7] = { MotorPower, CuoZhiMotor_Reset, CuoZhiMotor_Enable, CuoZhiMotor_Direction,
ZouZhiMotor_Reset, ZouZhiMotor_Enable, ZouZhiMotor_Direction,
};
const int pwms[2] = { 1, 2 };
};

View File

@ -1,69 +0,0 @@
#include "Motor.h"
#include "DevUtil.h"
#include <vector>
#include <cmath>
#include <iostream>
const MotorPorts motorPorts_Zouzhi = { .reset = ZouZhiMotor_Reset, .enable = ZouZhiMotor_Enable, .dir = ZouZhiMotor_Direction,
.pwm = 1};
const MotorPorts motorPorts_Cuozhi = {.reset = CuoZhiMotor_Reset, .enable = CuoZhiMotor_Enable, .dir = CuoZhiMotor_Direction,
.pwm = 2 };
std::vector<int> speedup_cfg(int finalPeriod, int Fmin, int stepnum, int a, int offset, int finalDelay) {
std::vector<int> freqs;
int period = 0;
double delay = ((double)finalDelay) / 1000000.0;
double b = stepnum * delay;
for (int i = 0; i < stepnum; i++) {
b = b - delay;
period = (int)(finalPeriod + (Fmin - finalPeriod) / (1 + exp(-a * b + offset)));
freqs.push_back(period);
//printf("\n period %d",period);
}
return freqs;
}
Motor::Motor(MotorPorts motorPorts)
: powerpin(MotorPower),resetPin(motorPorts.reset),enablePin(motorPorts.enable),dirPin(motorPorts.dir),pwm(motorPorts.pwm)
{
powerpin.setDirection(Gpio::out);
resetPin.setDirection(Gpio::out);
enablePin.setDirection(Gpio::out);
dirPin.setDirection(Gpio::out);
powerpin.setValue(Gpio::High);
resetPin.setValue(Gpio::High);
enablePin.setValue(Gpio::High);
std::cout << "Motor::Motor(MotorPorts motorPorts)" << std::endl;
}
Motor:: ~Motor()
{
stop();
std::cout << "Motor::~Motor()" << std::endl;
}
void Motor::start() {
enablePin.setValue(Gpio::Low);
pwm.enable(true);
}
void Motor::stop() {
enablePin.setValue(Gpio::High);
pwm.enable(false);
}
void Motor::pause() {
enablePin.setValue(Gpio::Low);
pwm.enable(false);
}
void Motor::setDirection(int dir) {
dirPin.setValue((Gpio::GpioLevel)dir);
}
void Motor::setSpeed(int value) {
pwm.setFreq(value);
}

View File

@ -1,72 +0,0 @@
#pragma once
#include <vector>
#include <thread>
#include <map>
#include "Gpio.h"
#include "Pwm.h"
#include "MotorConfig.h"
#include "commondef.h"
#include "dailex.hpp"
struct MotorPorts
{
int reset;
int enable;
int dir;
int pwm;
};
extern const MotorPorts motorPorts_Zouzhi;
extern const MotorPorts motorPorts_Cuozhi;
class Motor
{
public:
Motor(MotorPorts motorPorts);
virtual ~Motor();
protected:
Gpio powerpin;
Gpio resetPin;
//Gpio sleepPin;
Gpio enablePin;
Gpio dirPin;
//Gpio homePin;
//Gpio faultPin;
Pwm pwm;
MotorConfig::MTBDType m_mttype;
void start(std::vector<int>& delay_s, const MotorSpeedParam& msp)
{
if (!delay_s.empty()) {
std::vector<int>::iterator iter = delay_s.begin();
enablePin.setValue(Gpio::Low);
pwm.setFreq(PWM_PERIOD / (*iter));
pwm.enable(true);
std::this_thread::sleep_for(std::chrono::microseconds((int)msp.finalDelay));
while (++iter != delay_s.end()) {
pwm.setFreq(PWM_PERIOD / (*iter));
std::this_thread::sleep_for(std::chrono::microseconds((int)msp.finalDelay));
}
}
pwm.setFreq(PWM_PERIOD / msp.finalPeriod);
}
public:
virtual void start();
void stop();
void pause();
void setDirection(int dir);
void setSpeed(int value);
static void enablePower(bool bEnable);
};
extern std::vector<int> speedup_cfg(int finalPeriod, int Fmin, int stepnum, int a, int offset, int finalDelay);

View File

@ -1,367 +0,0 @@
#pragma once
#include <vector>
#include "json.hpp"
#include <tuple>
#include <commondef.h>
using json= nlohmann::json;
struct MotorSpeedParam
{
int finalPeriod;
int Fmin;
float stepnum;
float a;
float offset;
float finalDelay;
float acceleration_time;
};
struct MotorSpeedParamEx
{
MotorSpeedParam mt_param;
int speed;
int colormode;
int dpi;
int sp;
};
#ifndef WIN32
#define MT_DRV888_CUO_PATH "/usr/local/huago/drv888_cuo.json"
#define MT_DRV888_ZOU_PATH "/usr/local/huago/drv888_zou.json"
#define MT_TMC216_CUO_PATH "/usr/local/huago/tmc216_cuo.json"
#define MT_TMC216_ZOU_PATH "/usr/local/huago/tmc216_zou.json"
#else
#define MT_DRV888_CUO_PATH "drv888_cuo.json"
#define MT_DRV888_ZOU_PATH "drv888_zou.json"
#define MT_TMC216_CUO_PATH "tmc216_cuo.json"
#define MT_TMC216_ZOU_PATH "tmc216_zou.json"
#endif
#ifdef G300
static std::vector<MotorSpeedParamEx> m_motor_params{
//drv_888
{{.finalPeriod = 754200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 5910},//40 ppm 搓纸
{{.finalPeriod = 754200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 1970},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 3942},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1314},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 3942},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1314},
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 4509},//50 ppm 搓纸
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1503},
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 3009},
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1003},
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 3009},
{{.finalPeriod = 705300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1003},
{{.finalPeriod = 656200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 3702},//60 ppm 搓纸
{{.finalPeriod = 656200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1234},
{{.finalPeriod = 656300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 2446},
{{.finalPeriod = 656300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 822},
{{.finalPeriod = 656300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 2446},
{{.finalPeriod = 656300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 822},
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3129},//70 ppm 搓纸
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1043},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2446},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 859},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 2446},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 859},
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3129},//80 ppm 搓纸
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1043},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2446},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 859},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 2446},
{{.finalPeriod = 527300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 859},
{{.finalPeriod = 504200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 5910},//40 ppm 走纸
{{.finalPeriod = 504200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 1970},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 3942},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1314},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 3942},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1314},
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 4509},//50 ppm 走纸
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1503},
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 3009},
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1003},
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 3009},
{{.finalPeriod = 385300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1003},
{{.finalPeriod = 316200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 3702},//60 ppm 走纸
{{.finalPeriod = 316200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1234},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 822},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 822},
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3129},//70 ppm 走纸
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1043},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 822},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 822},
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3129},//80 ppm 走纸
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1043},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 822},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 2466},
{{.finalPeriod = 316300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 822},
//tmc
{{.finalPeriod = 184200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 5814},//40 ppm 搓纸
{{.finalPeriod = 184200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 1938},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 3879},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1293},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 3879},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1293},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 4455},//50 ppm 搓纸
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1485},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 2975},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 991},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 2972},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 991},
{{.finalPeriod = 166200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 3570},//60 ppm 搓纸
{{.finalPeriod = 166200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1190},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 815},
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3126},//70 ppm 搓纸
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1042},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 815},
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3126},//80 ppm 搓纸
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1042},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 166300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 815},
{{.finalPeriod = 124200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 5814},//40 ppm 走纸
{{.finalPeriod = 124200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 1938},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 3879},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1293},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 3879},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1293},
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 4455},//50 ppm 走纸
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1485},
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 2975},
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 991},
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 2975},
{{.finalPeriod = 95200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 991},
{{.finalPeriod = 76200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 3570},//60 ppm 走纸
{{.finalPeriod = 76200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1190},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 815},
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3126},//70 ppm 走纸
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1042},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 815},
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3126},//80 ppm 走纸
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1042},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 815},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 2445},
{{.finalPeriod = 78300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 815},
};
#else
static std::vector<MotorSpeedParamEx> m_motor_params{
//drv_888
{{.finalPeriod = 754200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 7290},//40 ppm 搓纸
{{.finalPeriod = 754200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 2430},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 4869},
{{.finalPeriod = 804300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1623},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 735200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 5870},//50 ppm 搓纸
{{.finalPeriod = 735200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1950},
{{.finalPeriod = 735300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 3909},
{{.finalPeriod = 735300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1303},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 686200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 5004},//60 ppm 搓纸
{{.finalPeriod = 686200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1688},
{{.finalPeriod = 706300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 3248},
{{.finalPeriod = 706300, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 1080},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3864},//70 ppm 搓纸
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1287},
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2580},
{{.finalPeriod = 527200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 859},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 508200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3735},//80 ppm 搓纸
{{.finalPeriod = 508200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1245},
{{.finalPeriod = 508200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2490},
{{.finalPeriod = 508200, .Fmin = 1407500, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 830},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 1006000, .Fmin = 1407500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 3000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 504200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 7290},//40 ppm 走纸
{{.finalPeriod = 504200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 2430},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 4869},
{{.finalPeriod = 504300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1623},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 385200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 6050},//50 ppm 走纸
{{.finalPeriod = 405200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 1950},
{{.finalPeriod = 405300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 3909},
{{.finalPeriod = 405300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1303},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 346200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 5004},//60 ppm 走纸
{{.finalPeriod = 346200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1688},
{{.finalPeriod = 336300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 3248},
{{.finalPeriod = 336300, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 1080},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3864},//70 ppm 走纸
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1287},
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2580},
{{.finalPeriod = 267200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 859},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 1583},
{{.finalPeriod = 258200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3735},//80 ppm 走纸
{{.finalPeriod = 258200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1245},
{{.finalPeriod = 258200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2490},
{{.finalPeriod = 258200, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 830},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 4749},
{{.finalPeriod = 656000, .Fmin = 1607500, .stepnum = 30, .a = 200, .offset = 7, .finalDelay = 3000, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 1583},
//tmc
{{.finalPeriod = 184200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 7200},//40 ppm 搓纸
{{.finalPeriod = 184200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 2400},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 4800},
{{.finalPeriod = 204300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1598},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 6050},//50 ppm 搓纸
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 2026},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 4053},
{{.finalPeriod = 185200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1350},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 176200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 4978},//60 ppm 搓纸
{{.finalPeriod = 176200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1659},
{{.finalPeriod = 176300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 3330},
{{.finalPeriod = 176300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 1110},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3858},//70 ppm 搓纸
{{.finalPeriod = 137200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1286},
{{.finalPeriod = 137300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2570},
{{.finalPeriod = 137300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 857},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 128200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3750},//80 ppm 搓纸
{{.finalPeriod = 128200, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1250},
{{.finalPeriod = 128300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2498},
{{.finalPeriod = 128300, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 832},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 251600, .Fmin = 351875, .stepnum = 30, .a = 150, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 124200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 1,.sp = 7200},//40 ppm 走纸
{{.finalPeriod = 124200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 1,.sp = 2400},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 2,.sp = 4800},
{{.finalPeriod = 124300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 2,.sp = 1598},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 1,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 105200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 1,.sp = 6050},//50 ppm 走纸
{{.finalPeriod = 105200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 1,.sp = 2026},
{{.finalPeriod = 105200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 2,.sp = 4053},
{{.finalPeriod = 105200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 2,.sp = 1350},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 2,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 86200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 1,.sp = 4978},//60 ppm 走纸
{{.finalPeriod = 86200, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 1,.sp = 1659},
{{.finalPeriod = 86300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 2,.sp = 3330},
{{.finalPeriod = 86300, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 2,.sp = 1110},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 3,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 1,.sp = 3858},//70 ppm 走纸
{{.finalPeriod = 66720, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 1,.sp = 1286},
{{.finalPeriod = 66730, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 2,.sp = 2572},
{{.finalPeriod = 66730, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 2,.sp = 857},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 4,.colormode = 1,.dpi = 3,.sp = 1586},
{{.finalPeriod = 64820, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 1,.sp = 3750},//80 ppm 走纸
{{.finalPeriod = 64820, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 1,.sp = 1250},
{{.finalPeriod = 64830, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 2,.sp = 2498},
{{.finalPeriod = 64830, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 2,.sp = 832},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 0,.dpi = 3,.sp = 4760},
{{.finalPeriod = 164600, .Fmin = 401875, .stepnum = 30, .a = 200, .offset = 9, .finalDelay = 2500, .acceleration_time =2},.speed = 5,.colormode = 1,.dpi = 3,.sp = 1586},
};
#endif
class MotorConfig
{
private:
std::vector<MotorSpeedParamEx> m_cuoParams;
std::vector<MotorSpeedParamEx> m_zouParams;
const std::vector<std::string> m_jsonpaths={
MT_DRV888_CUO_PATH,
MT_DRV888_ZOU_PATH,
MT_TMC216_CUO_PATH,
MT_TMC216_ZOU_PATH
};
public:
enum class MTBDType
{
MT_TMC,
MT_DRV
};
MotorConfig(/* args */);
~MotorConfig();
std::string GetParams(bool bzouzhi,MTBDType mttype);
void SetParams(bool bzouzhi,MTBDType mttype,MotorSpeedParamEx& param);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(bool bzouzhi,MTBDType mttype);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(const std::string& json_str);
void to_json(MotorSpeedParamEx& param,json& j);
void from_json(json& j,MotorSpeedParamEx& param);
void reset_json();
private:
void initconfigfile();
};

View File

@ -1,60 +0,0 @@
#pragma once
#include "CuoZhiMotor.h"
#include "ZouZhiMotor.h"
#include "MotorControl.h"
MotorControl::MotorControl()
{
m_zzm.reset(new ZouZhiMotor());
m_czm.reset(new CuoZhiMotor());
//m_czm->reset();
}
MotorControl::~MotorControl()
{
m_zzm->stop();
m_czm->stop();
m_czm.reset();
m_zzm.reset();
}
void MotorControl::MotorRun(MotorOption option)
{
switch (option)
{
case MotorOption::CZ_Reset :
m_czm->reset();
break;
case MotorOption::CZ_Forward :
m_czm->forward();
break;
case MotorOption::CZ_Backward :
m_czm->backward();
break;
case MotorOption::CZ_Pause:
m_czm->pause();
break;
case MotorOption::CZ_Stop :
m_czm->stop();
break;
case MotorOption::ZZ_Backward :
m_zzm->setDirection(1);
m_zzm->start();
break;
case MotorOption::ZZ_Forward :
m_zzm->setDirection(0);
m_zzm->start();
break;
case MotorOption::ZZ_Stop :
m_zzm->stop();
break;
default:
break;
}
}
void MotorControl::setzzspeed(int zuo_spmode,int dpi,int iscolor){
m_zzm->speedChange(zuo_spmode,dpi,iscolor);
}
void MotorControl::setczspeed(int cuo_spmode,int dpi,int iscolor){
m_czm->speedChange(cuo_spmode,dpi,iscolor);
}

View File

@ -1,28 +0,0 @@
#pragma once
class CuoZhiMotor;
class ZouZhiMotor;
struct MotorSpeedParam;
class MotorControl
{
public:
enum MotorOption : int{
CZ_Reset,
CZ_Forward,
CZ_Backward,
CZ_Pause,
CZ_Stop,
ZZ_Forward,
ZZ_Backward,
ZZ_Stop,
};
MotorControl();
~MotorControl();
void setzzspeed(int zuo_spmode,int dpi,int iscolor);
void setczspeed(int cuo_spmode,int dpi,int iscolor);
void MotorRun(MotorOption option);
private:
std::unique_ptr<CuoZhiMotor> m_czm;
std::unique_ptr<ZouZhiMotor> m_zzm;
};

View File

@ -1,40 +0,0 @@
#include "Pwm.h"
#include "DevUtil.h"
#include <iostream>
#define PWMPATH "%s%d/pwm0/%s"
Pwm::Pwm(int port)
{
path_enable = string_format(PWMPATH, path_base.c_str(), port, path_enable.c_str());
path_duty_cycle = string_format(PWMPATH, path_base.c_str(), port, path_duty_cycle.c_str());
path_period = string_format(PWMPATH, path_base.c_str(), port, path_period.c_str());
printf("Pwm::Pwm(int port = %d)\n",port);
}
Pwm::~Pwm()
{
std::cout << "Pwm::~Pwm()" << std::endl;
}
void Pwm::setFreq(int freq)
{
int value = PWM_PERIOD / freq;
write_dev(path_period, value);
write_dev(path_duty_cycle, value / 2);
}
int Pwm::getFreq()
{
return PWM_PERIOD/read_dev_i(path_period);
}
void Pwm::enable(bool bEnable)
{
write_dev(path_enable, bEnable);
}
bool Pwm::isEnable()
{
return (bool)read_dev_i(path_enable);
}

View File

@ -1,22 +0,0 @@
#pragma once
#include <string>
#define PWM_PERIOD 1000000000
class Pwm
{
public:
Pwm(int port);
~Pwm();
void setFreq(int freq);
int getFreq();
void enable(bool bEnable);
bool isEnable();
private:
const std::string path_base = "/sys/class/pwm/pwmchip";
std::string path_enable = "enable";
std::string path_duty_cycle = "duty_cycle";
std::string path_period = "period";
};

View File

@ -1,48 +0,0 @@
#include "ZouZhiMotor.h"
#include <thread>
#include <iostream>
ZouZhiMotor::ZouZhiMotor() : Motor(motorPorts_Zouzhi)
{
speedChange(0,1,1);
if(Dail().GetValue().dails.in_voltage4 == 0)
m_mttype = MotorConfig::MTBDType::MT_DRV;
else
m_mttype = MotorConfig::MTBDType::MT_TMC;
}
ZouZhiMotor::~ZouZhiMotor()
{
std::cout << "ZouZhiMotor::~ZouZhiMotor()" << std::endl;
}
void ZouZhiMotor::start()
{
Motor::start(delays, mspZhouzhi);
}
void ZouZhiMotor::speedChange(int speed,int dpi ,int iscolor)
{
// if(zouZhiFinalDelay.find(dpi)==zouZhiFinalDelay.end())
// dpi = 1;
// m_speedmode = speed;
// printf(" \n speed %d",speed);
// mspZhouzhi = { .finalPeriod = zouZhiFinalPeriod.at(dpi)[m_speedmode],.Fmin = zouZhiFmin.at(dpi)[m_speedmode],.stepnum = zouZhiStepNum.at(dpi)[m_speedmode],.a = zouZhiA.at(dpi)[m_speedmode],
// .offset = zouZhiOffset.at(dpi)[m_speedmode],.finalDelay = zouZhiFinalDelay.at(dpi)[m_speedmode] };
// std::cout<< ".finalPeriod = "<<zouZhiFinalPeriod.at(dpi)[m_speedmode]<<",.Fmin = "<<zouZhiFmin.at(dpi)[m_speedmode]<<",.stepnum = "<<zouZhiStepNum.at(dpi)[m_speedmode]<<",.a = "<<zouZhiA.at(dpi)[m_speedmode]<<
// ",.offset = "<< zouZhiOffset.at(dpi)[m_speedmode] <<",.finalDelay = "<<zouZhiFinalDelay.at(dpi)[m_speedmode]<<std::endl;
// printf("\nZuo speed = %d dpi = %d iscolor = %d",speed,dpi,iscolor);
auto params = m_cfg.GetMotorSpeedParams(true,m_mttype);
m_speedmode = speed;
for (int i = 0; i < params.size(); i++)
{
if (params[i].dpi == dpi &&
params[i].colormode == iscolor &&
params[i].speed == (speed+1))
{
mspZhouzhi = { .finalPeriod = params[i].mt_param.finalPeriod,.Fmin = params[i].mt_param.Fmin,.stepnum = params[i].mt_param.stepnum,.a = params[i].mt_param.a,
.offset = params[i].mt_param.offset,.finalDelay = params[i].mt_param.finalDelay };
}
}
delays = speedup_cfg(mspZhouzhi.finalPeriod, mspZhouzhi.Fmin, mspZhouzhi.stepnum, mspZhouzhi.a, mspZhouzhi.offset, mspZhouzhi.finalDelay);
}

View File

@ -1,51 +0,0 @@
#pragma once
#include "Motor.h"
class ZouZhiMotor : public Motor
{
public:
ZouZhiMotor();
virtual ~ZouZhiMotor();
virtual void start();
void speedChange(int speed,int dpi ,int iscolor);
private:
std::vector<int> delays;
MotorSpeedParam mspZhouzhi;
MotorConfig m_cfg;
int m_speedmode;
const std::map<int,std::vector<int>> zouZhiFinalPeriod ={
{1,{ 586500,420500,330000,245000,205000 }},
{2,{ 916500,656500,530500,386500,347000 }},
{3,{ 756500,756500,756500,756500,756500 }},
};//756500,556500,426500,336500,286500,230500 //265000
const std::map<int,std::vector<int>> zouZhiFmin ={
{1,{ 1607750,1607750,1607750,1607750,1607750 }},
{2,{ 1607750,1607750,1607750,1607750,1607750 }},
{3,{ 1607750,1607750,1607750,1607750,1607750 }},
};//1607750,1607750,1607750,1607750,1607750,1607750
const std::map<int,std::vector<int>> zouZhiStepNum ={
{ 1, { 23,23,30,30,30 }},
{ 2, { 30,30,30,30,30 }},
{ 3, { 30,30,30,30,30 }},
};
const std::map<int,std::vector<int>> zouZhiA = {
{1,{ 200,200,200,200,200 }},
{2,{ 200,200,200,200,200 }},
{3,{ 200,200,200,200,200 }},
};
const std::map<int,std::vector<int>> zouZhiOffset = {
{1,{ 7,7,7,7,9 }},
{2,{ 7,7,7,7,7 }},
{3,{ 7,7,7,7,7 }},
};
const std::map<int,std::vector<int>> zouZhiFinalDelay = {
{1,{ 2500,2500,2500,2500,2500 }},
{2,{ 2500,2500,2500,2500,2500 }},
{3,{ 2500,2500,2500,2500,2500 }},
};
};

View File

@ -1,56 +0,0 @@
#include <cstdio>
#include <iostream>
#include <thread>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include "DevUtil.h"
#include "Pwm.h"
#include "ZouZhiMotor.h"
#include "CuoZhiMotor.h"
int main(int argc,char **argv) {
//DeviceExport(); /*类里面的构造函数可以直接调用*/
DeviceExport d1;
ZouZhiMotor zzm;
CuoZhiMotor czm;
std::string instring;
do {
printf("1.cuozhi motor reset\n");
printf("2.cuozhi motor forward\n");
printf("3.cuozhi motor reverse\n");
printf("4.cuozhi motor stop\n");
printf("5.zouzhi motor forward\n");
printf("6.zouzhi motor reverse\n");
printf("7.zouzhi motor stop\n");
printf(":");
std::getline(std::cin, instring);
if (instring == "1") {
czm.reset();
}
if (instring == "2") {
czm.forward();
}
if (instring == "3") {
czm.backward();
}
if (instring == "4") {
czm.stop();
}
if (instring == "5") {
zzm.setDirection(0);
zzm.start();
}
if (instring == "6") {
zzm.setDirection(1);
zzm.start();
}
if (instring == "7") {
zzm.stop();
}
}while(1);
return 0;
}

View File

@ -1,89 +0,0 @@
add_rules("mode.debug", "mode.release")
target("motor_run")
set_kind("static")
add_files("Motor.cpp")
add_files("DevUtil.cpp")
add_files("ZouZhiMotor.cpp")
add_files("CuoZhiMotor.cpp")
add_files("Gpio.cpp")
add_files("Pwm.cpp")
add_files("MotorControl.cpp")
add_files("MotorConfig.cpp")
add_includedirs(".", { public = true})
add_includedirs("../packages/common.pkg/include", { public = true})
--add_packages("common")
target("main")
set_kind("binary")
add_files("main.cpp")
add_deps("motor_run")
--
-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
-- $ cd projectdir
--
-- 1. How to build project?
--
-- $ xmake
--
-- 2. How to configure project?
--
-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory?
--
-- The default output directory is `./build` and you can configure the output directory.
--
-- $ xmake f -o outputdir
-- $ xmake
--
-- 4. How to run and debug target after building project?
--
-- $ xmake run [targetname]
-- $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
-- $ xmake install
-- $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
-- -- add debug and release modes
-- add_rules("mode.debug", "mode.release")
--
-- -- add macro defination
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
--
-- -- set warning all as error
-- set_warnings("all", "error")
--
-- -- set language: c99, c++11
-- set_languages("c99", "c++11")
--
-- -- set optimization: none, faster, fastest, smallest
-- set_optimize("fastest")
--
-- -- add include search directories
-- add_includedirs("/usr/include", "/usr/local/include")
--
-- -- add link libraries and search directories
-- add_links("tbox")
-- add_linkdirs("/usr/local/lib", "/usr/lib")
--
-- -- add system link libraries
-- add_syslinks("z", "pthread")
--
-- -- add compilation and link flags
-- add_cxflags("-stdnolib", "-fno-strict-aliasing")
-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

View File

@ -0,0 +1,69 @@
#include "FeedControl.h"
#include <iostream>
#include <sstream>
FeedControl::FeedControl(/* args */) : m_thre(0.3)
{
}
FeedControl::~FeedControl()
{
}
FeedControl::FeedMode FeedControl::GetPredictFeedMode()
{
return calcFeedMode();
}
FeedControl::FeedMode FeedControl::calcFeedMode()
{
FeedMode mode = FeedMode::FMode_NOChange;
auto infos = m_sessioninfo.GetRecordInfo();
if (infos.size() < 10) //样本数量大于10了 才做分纸模式分析切换
return mode;
unsigned int nDoubleFeedTimes, nJamTimes, nFeedErrorTimes, nTotalScanned;
nDoubleFeedTimes = nJamTimes = nFeedErrorTimes = nTotalScanned = 0;
for (auto &item : infos)
{
if (!item.NormalDone)
{
if (item.DoubleFeed)
nDoubleFeedTimes++;
if (item.Jammed)
nJamTimes++;
if (item.FeedError)
nFeedErrorTimes++;
nTotalScanned += item.CurrentScaned;
}
}
double percentHigh = nDoubleFeedTimes / 10.0;
double percentLow = nFeedErrorTimes / 10.0;
printf("\n percentHigh : %f percentLow : %f" , percentHigh,percentLow);
if (percentHigh >= m_thre || percentLow >= m_thre)
{
mode = percentHigh >= percentLow ? FeedMode::FMode_High : FeedMode::FMode_Low;
if(fabs(percentHigh - percentLow) < 0.2)
mode = FeedMode::FMode_Mid;
ResetMode();
}
printf("\n Calc Feed Mode : %d" , (int)mode);
return mode;
}
void FeedControl::AppendPattern(MotorSessionInfo::MBTaskRecordInfo info)
{
m_sessioninfo.UpdateRecordInfo(info);
}
void FeedControl::SetThre(double thre)
{
m_thre = thre;
}
void FeedControl::ResetMode()
{
m_sessioninfo.RemoveInfos();
}

View File

@ -0,0 +1,31 @@
#pragma once
#include "MotorSessionInfo.h"
class FeedControl
{
public:
enum class FeedMode
{
FMode_Low,
FMode_Mid,
FMode_High,
FMode_NOChange,
};
public:
FeedControl(/* args */);
~FeedControl();
//设置搓纸模式匹配阈值
void SetThre(double thre);
//获取预测搓纸模式
FeedMode GetPredictFeedMode();
//搓纸模式变更时 清除配置记录信息
void ResetMode();
//更新走纸流程相关信息
void AppendPattern(MotorSessionInfo::MBTaskRecordInfo info);
private:
FeedMode calcFeedMode();
private:
MotorSessionInfo m_sessioninfo;
double m_thre;
};

View File

@ -1,16 +0,0 @@
#include <iostream>
#include "Imotorboard.h"
#include "PinMonitor.h"
#include "uartregsaccess.h"
#include <iomanip>
#include "stringex.hpp"
#include "config.h"
#include "StopWatch.h"
#include "applog.h"
#include "Capturer.h"
IMotorBoard::IMotorBoard() : mb_ev_cb_(std::function<void(uint32_t)>())
{}
IMotorBoard::~IMotorBoard(){
}

View File

@ -1,98 +0,0 @@
#pragma once
#include <string>
#include <memory>
#include <condition_variable>
#include <functional>
#include "autoevent.hpp"
#include "commondef.h"
#include "Led.h"
#include "StopWatch.h"
#include "ThreadPool.h"
class IRegsAccess;
class PinMonitor;
class Gpio;
class ICapturer;
#include "../usb/src/common/packet.h"
class IMotorBoard{
public:
IMotorBoard();
virtual ~IMotorBoard();
virtual void start() = 0;
virtual void stop() = 0;
virtual void clear_error() = 0;
virtual void pick_paper() = 0;
virtual void stop_pick_paper() = 0;
virtual int os_mode() = 0;
virtual bool paper_ready() = 0;
virtual bool is_converopen() = 0;
virtual bool is_scanning() = 0;
virtual bool is_jam() = 0;
virtual int paper_counter() = 0;
virtual bool set_long_paper(bool enable) = 0;
virtual bool set_double_inpect(bool enable) = 0;
virtual bool set_staple_inpect(bool enable) = 0;
virtual bool set_auto_paper(bool enable) = 0;
virtual bool set_color_mode(int mode) = 0;
virtual int get_speed_mode() = 0;
virtual bool set_speed_mode(int mode,int dpi,int iscolor) = 0;
virtual bool set_screw_inpect(bool enable) = 0;
virtual bool get_screw_inpect() = 0;
virtual bool set_screw_level(int level) = 0;
virtual int get_screw_level() = 0;
virtual bool wait_paper_out(int timeout_ms) = 0;
virtual bool wait_paper_in(int timeout_ms) = 0;
virtual bool read(unsigned int addr, unsigned int &val) = 0;
virtual bool write(unsigned int addr, unsigned int val) = 0;
virtual bool set_cuospeed(unsigned int speed,uint dpi,uint iscolor) = 0;
virtual void set_callbacks(MotorBoardGlue glue) = 0;
virtual bool get_keeplastpaper() = 0;
virtual std::shared_ptr<IRegsAccess> regs() = 0;
virtual void set_capture(std::shared_ptr<ICapturer> cap) = 0;
virtual void motor_reset() = 0;
virtual void LedControlOption(HG_LedOption option,uint32_t time) = 0;
virtual void clean_paper_road() = 0;
void set_error(int value){
mb_error = value;
}
void set_scancap(GScanCap cap)
{
m_scancap = cap;
}
void set_motorboard_event_callback(std::function<void(uint32_t)> cb)
{
mb_ev_cb_ = cb;
}
static scanner_status scanner_status_from_raw(int raw)
{
switch(raw)
{
case 1:
return SCANNER_STATUS_PAPER_JAMMED;
case 2:
return SCANNER_STATUS_NO_PAPER;
case 4:
return SCANNER_STATUS_COVER_OPENNED;
case 0x20:
return SCANNER_STATUS_DOUBLE_FEEDED;
case 0x2000000:
return SCANNER_STATUS_PAPER_ON;
case 0x4000000:
return SCANNER_STATUS_COVER_CLOSED;
case 0:
default:
return SCANNER_STATUS_READY; // jam has resolved
}
}
protected:
volatile int mb_error = 0;
GScanCap m_scancap;
std::function<void(uint32_t)> mb_ev_cb_;
};

View File

@ -0,0 +1,95 @@
#include "Jtag.h"
Jtag::Jtag():jtag_tms(152),jtag_tck(156),jtag_tdi(155),jtag_tdo(72),COM_BOOT0(153)
{
printf("Jtag()\n");
char fname[128];
write_dev("/sys/class/gpio/export", 152);
write_dev("/sys/class/gpio/export", 156);
write_dev("/sys/class/gpio/export", 155);
write_dev("/sys/class/gpio/export", 72);
write_dev("/sys/class/gpio/export", 153);
jtag_tms.setDirection(Gpio::out);
jtag_tck.setDirection(Gpio::out);
jtag_tdi.setDirection(Gpio::out);
jtag_tdo.setDirection(Gpio::in);
COM_BOOT0.setDirection(Gpio::out);
COM_BOOT0.setValue(Gpio::High);
jtag_tms.setValue(Gpio::Low);
jtag_tck.setValue(Gpio::Low);
jtag_tdi.setValue(Gpio::Low);
}
void Jtag::TMS_Wr(u8 value)
{
if(value == 1)
jtag_tms.setValue(Gpio::High);
else
jtag_tms.setValue(Gpio::Low);
}
u8 Jtag::TMS_RD()
{
return jtag_tms.getValue();
}
void Jtag::TCK_Wr(u8 value)
{
if(value == 1)
jtag_tck.setValue(Gpio::High);
else
jtag_tck.setValue(Gpio::Low);
}
u8 Jtag::TCK_RD()
{
return jtag_tck.getValue();
}
void Jtag::TDI_Wr(u8 value)
{
if(value == 1)
jtag_tdi.setValue(Gpio::High);
else
jtag_tdi.setValue(Gpio::Low);
}
u8 Jtag::TDI_RD()
{
return jtag_tdi.getValue();
}
u8 Jtag::TDO_RD()
{
return jtag_tdo.getValue();
}
void Jtag::Anlogic_Calibration(void)
{
/*Apply 2 pulses to TCK.*/
TCK_Wr(1);
TCK_Wr(1);
TCK_Wr(0);
TCK_Wr(1);
TCK_Wr(0);
TCK_Wr(1);
TCK_Wr(1);
/*Delay for 1 millisecond. Pass on 1000 = 1ms delay.*/
Anlogic_ProcessRunTestTck(10000) ;
/*Apply 2 pulses to TCK*/
TCK_Wr(1);
TCK_Wr(1);
TCK_Wr(0);
TCK_Wr(1);
TCK_Wr(0);
TCK_Wr(1);
TCK_Wr(1);
}

View File

@ -0,0 +1,41 @@
#ifndef HGSCANSERVICE_JTAG_H
#define HGSCANSERVICE_JTAG_H
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <time.h>
#include <unistd.h>
#include "DevUtil.h"
#include "Gpio.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
extern void Anlogic_ProcessRunTestTck(int num);
typedef unsigned int u32;
typedef unsigned char u8;
class Jtag
{
private:
Gpio jtag_tms;
Gpio jtag_tck;
Gpio jtag_tdi;
Gpio jtag_tdo;
Gpio COM_BOOT0;
public:
Jtag();
void TMS_Wr(u8 value);
u8 TMS_RD();
void TCK_Wr(u8 value);
u8 TCK_RD();
void TDI_Wr(u8 value);
u8 TDI_RD();
u8 TDO_RD();
void Anlogic_Calibration(void);
};
#endif

View File

@ -1,95 +0,0 @@
#include "Led.h"
#define LEDPATH "%s/%s/%s"
std::string Led::timer = "timer";
std::string Led::none = "none";
Led::Led(std::string name) {
path_brightness = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_brightness.c_str());
path_trigger = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_trigger.c_str());
path_delay_off = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_delay_off.c_str());
path_delay_on = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_delay_on.c_str());
}
Led::~Led() {
}
void Led::on(int time_ms) {
if (time_ms != 0) {
write_dev(path_trigger, timer);
write_dev(path_delay_off, time_ms);
write_dev(path_delay_on, time_ms);
} else {
//if (read_dev_s(path_trigger).find(none) == std::string::npos)
write_dev(path_trigger, none);
}
write_dev(path_brightness, 1);
}
void Led::off() {
write_dev(path_brightness, 0);
}
bool Led::isOn() {
return (bool)read_dev_i(path_brightness);
}
LedControl::LedControl():m_led_green(Led("green")),m_led_red(Led("red")),m_led_white(Led("white")){
}
LedControl::~LedControl(){
option(HG_LedOption::HG_OFF_ALL,0);
}
HG_LedOption LedControl::get_state(){
return m_state;
}
void LedControl::option(HG_LedOption option,uint32_t time){
m_state = option;
switch (option)
{
case HG_LedOption::HG_OFF_ALL:
m_led_red.off();
m_led_green.off();
m_led_white.off();
break;
case HG_LedOption::HG_ON_ALL:
m_led_green.on(time);
m_led_red.on(time);
m_led_white.on(time);
break;
case HG_LedOption::HG_RED_ON:
m_led_red.on(time);
m_led_green.off();
m_led_white.off();
break;
case HG_LedOption::HG_GREEN_ON:
m_led_green.on(time);
m_led_red.off();
m_led_white.off();
break;
case HG_LedOption::HG_WHITE_ON:
m_led_red.off();
m_led_green.off();
m_led_white.on(time);
break;
case HG_LedOption::HG_RED_WHITR_ON:
m_led_green.off();
m_led_red.on(time);
m_led_white.on(time);
break;
case HG_LedOption::HG_RED_GREEN_ON:
m_led_red.on(time);
m_led_green.on(time);
m_led_white.off();
break;
case HG_LedOption::HG_GREEN_WHITR_ON:
m_led_green.on(time);
m_led_red.off();
m_led_white.on(time);
break;
default:
break;
}
}

View File

@ -1,50 +0,0 @@
#pragma once
#include "DevUtil.h"
#include "stringex.hpp"
enum HG_LedOption : uint8_t{
HG_OFF_ALL = 0,
HG_RED_ON,
HG_GREEN_ON,
HG_WHITE_ON,
HG_RED_GREEN_ON,
HG_RED_WHITR_ON,
HG_GREEN_WHITR_ON,
HG_ON_ALL,
};
class Led
{
public:
static std::string timer;
static std::string none;
public:
Led(std::string name);
~Led();
void on(int time_ms = 0);
void off();
bool isOn();
private:
const std::string path_base = "/sys/class/leds";
std::string path_brightness = "brightness";
std::string path_trigger = "trigger";
std::string path_delay_off = "delay_off";
std::string path_delay_on = "delay_on";
};
class LedControl{
public:
LedControl();
~LedControl();
void option(HG_LedOption option,uint32_t time = 0);
HG_LedOption get_state();
private:
Led m_led_red;
Led m_led_green;
Led m_led_white;
HG_LedOption m_state;
};

View File

@ -23,12 +23,14 @@ std::string MotorConfig::GetParams(bool bzouzhi, MTBDType mttype)
std::ifstream i(bzouzhi ? MT_TMC216_ZOU_PATH : MT_TMC216_CUO_PATH);
i >> j;
j_str = j.dump();
i.close();
}
else
{
std::ifstream i(bzouzhi ? MT_DRV888_ZOU_PATH : MT_DRV888_CUO_PATH);
i >> j;
j_str = j.dump();
i.close();
}
return j_str;
}
@ -63,6 +65,7 @@ void MotorConfig::SetParams(bool bzouzhi, MTBDType mttype, MotorSpeedParamEx &pa
ofstream ofs(path);
ofs << std::setw(4) << j << std::endl;
ofs.close();
}
std::vector<MotorSpeedParamEx> MotorConfig::GetMotorSpeedParams(bool bzouzhi, MTBDType mttype)
@ -73,6 +76,7 @@ std::vector<MotorSpeedParamEx> MotorConfig::GetMotorSpeedParams(bool bzouzhi, MT
std::ifstream i(bzouzhi ? MT_TMC216_ZOU_PATH : MT_TMC216_CUO_PATH);
json j;
i >> j;
i.close();
for (json::iterator it = j.begin(); it != j.end(); ++it)
{
auto tmv = it.value();
@ -86,6 +90,7 @@ std::vector<MotorSpeedParamEx> MotorConfig::GetMotorSpeedParams(bool bzouzhi, MT
std::ifstream i(bzouzhi ? MT_DRV888_ZOU_PATH : MT_DRV888_CUO_PATH);
json j;
i >> j;
i.close();
for (json::iterator it = j.begin(); it != j.end(); ++it)
{
auto tmv = it.value();
@ -111,22 +116,21 @@ void MotorConfig::initconfigfile()
MotorSpeedParamEx param;
for (int k = 1; k < 4; k++)
{
// //float ratio = k == 1 ? 1 : (k == 2 ? 1.51 : 2.81);
// param.mt_param.finalPeriod = s >= 2 ? 586500 / 4 : 586500; // s < 2 drv888
// //param.mt_param.finalPeriod = s >= 2 ? 2000 / 4 : 2000; // s < 2 drv888
// param.mt_param.Fmin = s >= 2 ? 1607750 / 4 : 1607750;
// param.mt_param.stepnum = 30;
// param.mt_param.a = 200;
// param.mt_param.offset = 7;
// param.mt_param.finalDelay = 2500;
// param.mt_param.acceleration_time = 2;
// param.speed = i; // 0 gray 1 color
// param.dpi = k; // 1 200dpi 2 300dpi 3 600dpi
// param.sp = 1200;
float ratio = k == 1 ? 1 : (k == 2 ? 1.51 : 2.81);
param.mt_param.finalPeriod = s >= 2 ? 2000 / 4 *ratio: 2000*ratio; // s < 2 drv888
param.mt_param.finalPeriod = s >= 2 ? 2000 / 4 : 2000; // s < 2 drv888
param.mt_param.Fmin = s >= 2 ? 80000 / 4 : 80000;
param.mt_param.stepnum = 0.5;
param.mt_param.a = 0.35;
param.mt_param.offset = -5.7;
param.mt_param.finalDelay = 2500;
param.mt_param.acceleration_time = 2;
param.speed = i; // 0 gray 1 color
param.dpi = k; // 1 200dpi 2 300dpi 3 600dpi
param.sp = 1200;
for(int t = 0;t<2;t++)
{
//param.colormode = t;
param = m_motor_params[s*30+(i-1)*6+(k-1)*2+t];
param.colormode = t;
json t_j;
to_json(param, t_j);
j.push_back(t_j);
@ -135,16 +139,12 @@ void MotorConfig::initconfigfile()
}
ofstream ofs(m_jsonpaths[s]);
ofs << std::setw(4) << j << std::endl;
ofs.close();
}
}
}
}
void MotorConfig::reset_json(){
// for(int i =0;i<m_jsonpaths.size();i++)
// remove(m_jsonpaths[i].c_str());
initconfigfile();
}
std::vector<MotorSpeedParamEx> MotorConfig::GetMotorSpeedParams(const std::string& json_str)
{
std::vector<MotorSpeedParamEx> ret;

View File

@ -0,0 +1,68 @@
#pragma once
#include <vector>
#include "json.hpp"
using json= nlohmann::json;
struct MotorSpeedParam
{
int finalPeriod;
int Fmin;
float stepnum;
float a;
float offset;
float finalDelay;
float acceleration_time;
};
struct MotorSpeedParamEx
{
MotorSpeedParam mt_param;
int speed;
int colormode;
int dpi;
int sp;
};
#ifndef WIN32
#define MT_DRV888_CUO_PATH "/usr/local/huago/drv888_cuo.json"
#define MT_DRV888_ZOU_PATH "/usr/local/huago/drv888_zou.json"
#define MT_TMC216_CUO_PATH "/usr/local/huago/tmc216_cuo.json"
#define MT_TMC216_ZOU_PATH "/usr/local/huago/tmc216_zou.json"
#else
#define MT_DRV888_CUO_PATH "drv888_cuo.json"
#define MT_DRV888_ZOU_PATH "drv888_zou.json"
#define MT_TMC216_CUO_PATH "tmc216_cuo.json"
#define MT_TMC216_ZOU_PATH "tmc216_zou.json"
#endif
class MotorConfig
{
private:
std::vector<MotorSpeedParamEx> m_cuoParams;
std::vector<MotorSpeedParamEx> m_zouParams;
const std::vector<std::string> m_jsonpaths={
MT_DRV888_CUO_PATH,
MT_DRV888_ZOU_PATH,
MT_TMC216_CUO_PATH,
MT_TMC216_ZOU_PATH
};
public:
enum class MTBDType
{
MT_TMC,
MT_DRV
};
MotorConfig(/* args */);
~MotorConfig();
std::string GetParams(bool bzouzhi,MTBDType mttype);
void SetParams(bool bzouzhi,MTBDType mttype,MotorSpeedParamEx& param);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(bool bzouzhi,MTBDType mttype);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(const std::string& json_str);
private:
void initconfigfile();
void to_json(MotorSpeedParamEx& param,json& j);
void from_json(json& j,MotorSpeedParamEx& param);
};

View File

@ -0,0 +1,117 @@
#include "MotorSessionInfo.h"
#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
#define MBTASKPATH "/usr/local/huago/mbtaskinfos.json"
MotorSessionInfo::MotorSessionInfo(/* args */) : m_maxrecord(10)
{
}
MotorSessionInfo::~MotorSessionInfo()
{
}
//获取近十次的扫描情况汇总
std::vector<MotorSessionInfo::MBTaskRecordInfo> MotorSessionInfo::GetRecordInfo()
{
std::vector<MotorSessionInfo::MBTaskRecordInfo> infos;
json j = getjsonobj();
printf("\n -------------json = %s",j.dump().c_str());
for (json::iterator it = j.begin(); it != j.end(); ++it)
{
auto tmv = it.value();
MBTaskRecordInfo param;
js2struct(param, tmv);
infos.push_back(param);
}
//printf("\n -------------GetRecordInfo size");
return infos;
}
//仅记录最近十次的扫描情况,大于十次按照时间戳去除早前的记录
void MotorSessionInfo::UpdateRecordInfo(MotorSessionInfo::MBTaskRecordInfo info)
{
auto records = GetRecordInfo();
//std::sort(records.begin(), records.end());
printf("\n -------------GetRecordInfo size = %d",records.size());
if (records.size() > 10)
{
records.pop_back();
}
records.push_back(info);
savejsonobj(records);
}
void MotorSessionInfo::RemoveInfos()
{
std::lock_guard<std::mutex> mutex(m_mutex);
system("rm -f /usr/local/huago/mbtaskinfos.json");
}
void MotorSessionInfo::js2struct(MotorSessionInfo::MBTaskRecordInfo &info, const json &j)
{
j["CurrentScaned"].get_to(info.CurrentScaned);
j["DoubleFeed"].get_to(info.DoubleFeed);
j["FeedError"].get_to(info.FeedError);
j["Jammed"].get_to(info.Jammed);
j["NormalDone"].get_to(info.NormalDone);
j["TimeStampStart"].get_to(info.TimeStampStart);
j["TimeStampEnd"].get_to(info.TimeStampEnd);
}
void MotorSessionInfo::struct2js(const MotorSessionInfo::MBTaskRecordInfo info, json &j)
{
j["CurrentScaned"] = (info.CurrentScaned);
j["DoubleFeed"] = (info.DoubleFeed);
j["FeedError"] = (info.FeedError);
j["Jammed"] = (info.Jammed);
j["NormalDone"] = (info.NormalDone);
j["TimeStampStart"] = (info.TimeStampStart);
j["TimeStampEnd"] = (info.TimeStampEnd);
}
json MotorSessionInfo::getjsonobj()
{
std::lock_guard<std::mutex> mutex(m_mutex);
struct stat buff;
json j;
if (stat(MBTASKPATH, &buff) == 0) //存在
{
std::ifstream i(MBTASKPATH);
// std::string buf;
// buf.resize(buff.st_size);
// i.read(&buf[0],buff.st_size);
// j = json::parse(buf);
i >> j;
i.close();
//printf("\n ----json = %s ",j.dump().c_str());
}
return j;
}
void MotorSessionInfo::savejsonobj(std::vector<MBTaskRecordInfo> infos)
{
std::lock_guard<std::mutex> mutex(m_mutex);
json j= json::array();
printf("\n -------------infos size = %d",infos.size());
for (size_t i = 0; i < infos.size(); i++)
{
json jitem;
struct2js(infos[i],jitem);
j.push_back(jitem);
}
if(!j.empty())
{
std::ofstream ofs(MBTASKPATH);
ofs << std::setw(4) << j << std::endl;
ofs.close();
}
}

View File

@ -0,0 +1,54 @@
#pragma once
#include <vector>
#include <json.hpp>
#include <mutex>
using json = nlohmann::json;
class MotorSessionInfo
{
public:
struct MBTaskRecordInfo
{
unsigned int CurrentScaned;
bool NormalDone;
bool Jammed;
bool DoubleFeed;
bool FeedError;
long TimeStampStart;
long TimeStampEnd;
bool operator < (const MBTaskRecordInfo& info)
{
return this->TimeStampEnd > info.TimeStampEnd;
}
void Start()
{
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> tpMicro = \
std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
this->TimeStampStart = tpMicro.time_since_epoch().count();
}
void Stop()
{
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> tpMicro = \
std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
this->TimeStampEnd = tpMicro.time_since_epoch().count();
}
};
//nscanned / 300 nscanned∈[1,300] 即取值范围为[0,1.0]
public:
MotorSessionInfo(/* args */);
~MotorSessionInfo();
std::vector<MBTaskRecordInfo> GetRecordInfo();// m_mbtaskrecordInfos;
void UpdateRecordInfo(MBTaskRecordInfo info);
void RemoveInfos();
private:
void js2struct(MBTaskRecordInfo& info,const json& j);
void struct2js(const MBTaskRecordInfo info,json& j);
json getjsonobj();
void savejsonobj(std::vector<MBTaskRecordInfo> infos);
private:
int m_maxrecord;
std::mutex m_mutex;//避免读写冲突 json文件丢失
};

View File

@ -0,0 +1,918 @@
/*******************************************************************
* Copyright (c) 2011 -2021 Anlogic Inc.
* The Software is distributed in source code form and is open to
* re-distribution and modification where applicable
*******************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include "opcode.h"
#define AJE_DEBUG
/* jtag instruction macro list */
#define INS_REFRESH 0x01
#define INS_SAMPLE 0x05
#define INS_READ_STATUS 0x20
#define INS_BYPASS 0xFF
#define INS_PROG_SPI 0x39
extern unsigned int g_hdr_size;
extern unsigned int g_hir_size;
extern unsigned int g_tdr_size;
extern unsigned int g_tir_size;
extern unsigned char* g_hdr_data;
extern unsigned char* g_hir_data;
extern unsigned char* g_tdr_data;
extern unsigned char* g_tir_data;
/* some static & global variables */
static char s_compress = FULL_MODE; /* compress mode */
static long int s_cfg_start_pos = 0; /* the start cfg position in aje file */
static int s_done_status = 1; /* done pin status */
static int s_find_refresh_ins = 0; /* the flag that refresh instrcution has been found or not */
static int s_cur_level = 0; /* for daisy chain, current level */
static int s_total_level = 0; /* for daisy chain, total level */
FILE* g_aje_file;
char g_aje_crc[3];
long int g_freq = 0;
unsigned char s_idcode_pub = IDCODE_PUB;
static unsigned int s_cascade = 0; /* cascade flag */
/* function declared in decode.c */
extern unsigned char* Anlogic_BytesDecode(long bytes);
extern unsigned char* Anlogic_NibbleDecode(long bytes);
extern unsigned char* Anlogic_HuffmanDecode(long bytes);
extern unsigned char* Anlogic_LzwDecode(long bytes);
/* function declared in ajeutil.c */
extern int Anlogic_GetBit(unsigned char* data, int id);
extern void Anlogic_SetBit(unsigned char* data, int id, int val);
extern char* Anlogic_HexStrToBinStr(char* src_str, int bin_len);
/* function declared in vec.c */
extern enum TAP_STATE Anlogic_TapState(unsigned char opcode);
extern const char* Anlogic_TapState2Str(enum TAP_STATE tap_state);
extern void Anlogic_SetEndDRState(enum TAP_STATE end_st);
extern void Anlogic_SetEndIRState(enum TAP_STATE end_st);
extern int Anlogic_TapTransist(enum TAP_STATE state);
extern int Anlogic_ExeSirCommand(unsigned char command, int cur_lvl, int total_lvl);
extern int Anlogic_ExeSdrCommand(unsigned int data_size, int cur_lvl, int total_lvl,
unsigned char* tdi_data, unsigned char* tdo_data);
extern void Anlogic_Init(void);
extern void Anlogic_ProcessRunTestTck(int num);
extern int Anlogic_SendData(unsigned char* tdi_data, unsigned int data_size, int cascade);
extern int Anlogic_SaveData(unsigned char* tdi_data, unsigned int data_size, unsigned char** tdo_data);
extern int Anlogic_ProcessShiftCmd(unsigned int op_code, unsigned int cascade, unsigned int read, unsigned int data_size,
unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask);
/* function forward declaration */
int Anlogic_ExeSirCommands(unsigned int data_size, unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask);
int Anlogic_ExeSDRCommands(unsigned int cascade, unsigned int data_size,
unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask);
long Anlogic_ReadNumber()
{
long number = 0;
char byte = 0, cnt = 0;
do {
byte = fgetc(g_aje_file);
if (byte == EOF) { break; }
number += (byte & 0x007F) << (7 * cnt);
cnt ++;
} while (byte & 0x0080);
return number;
}
unsigned long Anlogic_ProcessRuntestCmd()
{
unsigned long ulTime = 0;
unsigned long num = 0;
char opcode = 0;
// char pre_opcode = 0;
char done = 0;
if (g_freq == 0) {
g_freq = 80000;
}
do {
//pre_opcode = opcode;
opcode = fgetc(g_aje_file);
switch (opcode) {
case TCK:
num = Anlogic_ReadNumber();
if (num > 0x8000) { num -= 0x8000; }
ulTime += num;
ulTime -= 10;
break;
case WAIT:
num = Anlogic_ReadNumber();
num -= 10;
if (num > 0x8000) {
num -= 0x8000;
num = g_freq * num / 1000;
} else {
num = g_freq * num / 1000000;
}
//if(TCK == pre_opcode){
// ulTime = 0;
//}
ulTime += num;
break;
case RUNTEST:
break;
default:
done = 1;
break;
}
} while (!done);
if (opcode == BEGINLINE) {
fseek(g_aje_file, -1, SEEK_CUR);
}
//ulTime = 1200;
return ulTime;
}
unsigned char* Anlogic_ProcessData(unsigned int byte_num) {
unsigned int index = 0;
unsigned char* data = NULL;
char mode = '\0';
if (s_compress == (char)FULL_MODE) {
data = (unsigned char*)calloc((byte_num+1), sizeof(unsigned char));
for(index = 0; index < byte_num; ++index) {
data[index] = fgetc(g_aje_file);
}
} else { // compress mode
mode = fgetc(g_aje_file);
if (mode == 0) { // no compress
data = (unsigned char*)calloc((byte_num+1), sizeof(unsigned char));
for(index = 0; index < byte_num; ++index) {
data[index] = fgetc(g_aje_file);
}
} else if (mode == 1) { // byte compress
data = Anlogic_BytesDecode(byte_num);
} else if (mode == 2) { // nibble compress
data = Anlogic_NibbleDecode(byte_num);
} else if (mode == 3) { // huffman compress
data = Anlogic_HuffmanDecode(byte_num);
} else if (mode == 4) { // LZW compress
data = Anlogic_LzwDecode(byte_num);
} else {
assert(0 && "Error: Unkown compress mode.");
}
}
return data;
}
void Anlogic_PrintData(unsigned int byte_size, unsigned char* data) {
int byte_id = 0;
unsigned int bit_id = 0;
unsigned char byte = '\0';
unsigned char flip_byte = '\0';
printf( " (" );
for(byte_id = byte_size-1; byte_id >=0; --byte_id) {
byte = data[byte_id];
flip_byte = 0x00;
for (bit_id = 0; bit_id < 8; bit_id++) {
flip_byte <<= 1;
if (byte & 0x1) {
flip_byte |= 0x1;
}
byte >>= 1;
}
printf("%02X", flip_byte);
}
printf(") ");
}
/* Get the SIR Instruction */
unsigned char Anlogic_ParseSirIns(unsigned int len, unsigned char* tdi_data) {
/* default value : bypass instruction */
unsigned char sir_ins = INS_BYPASS;
unsigned int byte_id = 0;
unsigned int bit_id = 0;
unsigned char byte = '\0';
unsigned char flip_byte = '\0';
if (len % 8 != 0) {
return sir_ins;
}
for(byte_id = 0; byte_id < len/8; ++byte_id) {
byte = tdi_data[byte_id];
flip_byte = 0x00;
for (bit_id = 0; bit_id < 8; bit_id++) {
flip_byte <<= 1;
if (byte & 0x1) {
flip_byte |= 0x1;
}
byte >>= 1;
}
if (flip_byte != INS_BYPASS) {
sir_ins = flip_byte;
break;
}
}
return sir_ins;
}
/* read the head and trailer bit number in sir instruction */
int Anlogic_ReadSirInfo(int* header_num, int* trailer_num) {
unsigned int bin_num = 0;
unsigned int flip_byte = 0;
unsigned int bit_id = 0;
int byte_id = 0;
int byte_num = 0;
int* tmp_val = trailer_num;
unsigned char* tdi = NULL;
char byte = '\0';
*header_num = 0;
*trailer_num = 0;
bin_num = Anlogic_ReadNumber();
byte_num = bin_num / 8;
if (bin_num % 8 != 0) {
byte_num++;
}
if (fgetc(g_aje_file) != TDI) {
printf("Error Invalid format when executing read sir information!\n");
fseek(g_aje_file, bin_num-1, SEEK_CUR);
return 0;
}
tdi = Anlogic_ProcessData(byte_num);
for(byte_id = byte_num-1; byte_id >= 0; --byte_id) {
byte = tdi[byte_id];
flip_byte = 0x00;
for (bit_id = 0; bit_id < 8; bit_id++) {
flip_byte <<= 1;
if (byte & 0x1) {
flip_byte |= 0x1;
}
byte >>= 1;
}
if (flip_byte == BYPASS) {
*tmp_val += 1;
} else if (flip_byte != BYPASS) {
tmp_val = header_num;
if(flip_byte == IDCODE_PUB_2) {
s_idcode_pub = IDCODE_PUB_2;
}
}
}
if (CONTINUE != fgetc(g_aje_file)) {
printf("Error Invalid format when executing read sir information!\n");
return 0;
}
return (tmp_val == trailer_num) ? 0 : 1;
}
int Anlogic_ProcessShiftCommand(char op_code)
{
int rtn_val = AJE_OK;
int id = 0;
unsigned int bin_num = 0;
unsigned int byte_num = 0;
unsigned char* tdi = NULL;
unsigned char* tdo = NULL;
unsigned char* msk = NULL;
unsigned char ins = 0xFF;
char byte = '\0';
bin_num = Anlogic_ReadNumber();
byte_num = bin_num / 8;
if (bin_num % 8 != 0) {
byte_num++;
}
while((byte = fgetc(g_aje_file)) != CONTINUE) {
switch (byte) {
case TDI:
tdi = Anlogic_ProcessData(byte_num);
break;
case TDO:
tdo = Anlogic_ProcessData(byte_num);
break;
case MASK:
msk = Anlogic_ProcessData(byte_num);
break;
default:
printf("Error: Invalid format when executing process sir or sdr instruction!\n");
return AJE_INVALID_COMMAND;
break;
}
}
/* exe sir or sdr instruction */
if (op_code == SIR) {
/* if done=0, 'refresh' must be executed before 'program_spi' */
if (s_done_status == 0 && s_find_refresh_ins == 0) {
ins = Anlogic_ParseSirIns(bin_num, tdi);
if (ins == INS_REFRESH) {
s_find_refresh_ins = 1;
} else if (ins == INS_PROG_SPI) {
#ifdef AJE_DEBUG
printf("SIR %d TDI (", s_total_level*8);
for (id = 1; id <= s_total_level; ++id) {
if (id == s_cur_level) {
printf("%02X", INS_REFRESH);
} else {
printf("FF");
}
}
printf(") ;\n");
printf("SIR %d TDI (", s_total_level*8);
for (id = 1; id <= s_total_level; ++id) {
printf("FF");
}
printf(") ;\n");
#endif
Anlogic_ExeSirCommand(INS_REFRESH, s_cur_level, s_total_level);
Anlogic_ExeSirCommand(INS_BYPASS, s_cur_level, s_total_level);
s_done_status = 1;
}
}
#ifdef AJE_DEBUG
printf("SIR %d TDI", bin_num);
Anlogic_PrintData(byte_num, tdi);
if (tdo != NULL) {
printf("TDO");
Anlogic_PrintData(byte_num, tdo);
}
if (msk != NULL) {
printf("MASK");
Anlogic_PrintData(byte_num, msk);
}
printf(";\n");
#endif
rtn_val = Anlogic_ExeSirCommands(bin_num, tdi, tdo, msk);
} else {
#ifdef AJE_DEBUG
printf("SDR %d TDI", bin_num);
Anlogic_PrintData(byte_num, tdi);
if (tdo != NULL) {
printf("TDO");
Anlogic_PrintData(byte_num, tdo);
}
if (msk != NULL) {
printf("MASK");
Anlogic_PrintData(byte_num, msk);
}
printf(";\n");
#endif
rtn_val = Anlogic_ExeSDRCommands(s_cascade, bin_num, tdi, tdo, msk);
}
//free tdi tdo msk
if (tdi != NULL) { free(tdi); tdi = NULL; }
if (tdo != NULL) { free(tdo); tdo = NULL; }
if (msk != NULL) { free(msk); msk = NULL; }
return rtn_val;
}
int Anlogic_ProcessBypassCommand(char op_code) {
unsigned int bin_num = 0;
unsigned int byte_num = 0;
unsigned int index = 0;
unsigned char* tdi = NULL;
char byte = '\0';
char* op_code_str = NULL;
bin_num = Anlogic_ReadNumber();
if (bin_num > 0) {
byte_num = bin_num / 8;
if (bin_num % 8 != 0) {
byte_num++;
}
byte = fgetc(g_aje_file);
if (byte == TDI) {
tdi = (unsigned char*)calloc((byte_num+1), sizeof(unsigned char));
for(index = 0; index < byte_num; ++index) {
tdi[index] = fgetc(g_aje_file);
}
}
}
switch (op_code)
{
case TIR: op_code_str = "TIR"; g_tir_size = bin_num; g_tir_data = tdi; break;
case TDR: op_code_str = "TDR"; g_tdr_size = bin_num; g_tdr_data = tdi; break;
case HIR: op_code_str = "HIR"; g_hir_size = bin_num; g_hir_data = tdi; break;
case HDR: op_code_str = "HDR"; g_hdr_size = bin_num; g_hdr_data = tdi; break;
default:
printf("Error: invalid Head/Trailer format, unkown opcode.\n\n");
return AJE_INVALID_COMMAND;
}
#ifdef AJE_DEBUG
printf("%s %d", op_code_str, bin_num);
if ( bin_num > 0) {
printf(" TDI ");
Anlogic_PrintData(byte_num, tdi);
}
printf(" ;\n");
#endif
if (bin_num > 0) { // Skip CONTINUE command
fgetc(g_aje_file);
}
return AJE_OK;
}
int Anlogic_ExeSirCommands(unsigned int data_size, unsigned char* tdi_data, unsigned char* tdo_data,
unsigned char* mask) {
unsigned int rtn_val = AJE_OK;
unsigned int op_code = SIR;
unsigned int cascade = 0; // no casecade
unsigned int read = 0; // send data only
rtn_val = Anlogic_ProcessShiftCmd(op_code, cascade, read, data_size, tdi_data, tdo_data, mask);
return rtn_val;
}
int Anlogic_ExeSDRCommands(unsigned int cascade, unsigned int data_size,
unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask) {
unsigned int rtn_val = AJE_OK;
unsigned int op_code = SDR;
unsigned int read = 0; // send data only
rtn_val = Anlogic_ProcessShiftCmd(op_code, cascade, read, data_size, tdi_data, tdo_data, mask);
return rtn_val;
}
/*
* read the aje header information,
* include crc, version, compress mode, maximum memory size and vendor
*/
int Anlogic_ReadAjeHeader()
{
char byte;
char buffer[100];
int i;
printf("Anlogic_ReadAjeHeader start.\n");
// crc bytes
if (fgetc(g_aje_file) != FILECRC) {
return AJE_FILE_INVALID;
}
if (fgets(g_aje_crc, 3, g_aje_file) == NULL) {
return AJE_FILE_INVALID;
}
else {
printf("g_aje_crc[0] = 0x%02x, g_aje_crc[1] = 0x%02x, g_aje_crc[2] = 0x%02x,\n",
g_aje_crc[0],g_aje_crc[1],g_aje_crc[2]);
}
// version
if (fgets(buffer, 9, g_aje_file) == NULL) {
return AJE_FILE_INVALID;
}
else
{
for(int i=0;i<9;i++)
printf("buffer[%d] = 0x%02x ",i,buffer[i]);
printf("\n");
}
// compress or full
byte = fgetc(g_aje_file);
if (byte != (char)COMP_MODE && byte != (char)FULL_MODE) {
return AJE_FILE_INVALID;
}
else
printf("byte = 0x%02x ",byte);
s_compress = byte;
// maximum memory size
if (MEM != fgetc(g_aje_file)) {
return AJE_FILE_INVALID;
}
Anlogic_ReadNumber();
// Vender
if (VENDOR != fgetc(g_aje_file )) {
return AJE_FILE_INVALID;
}
if (ANLOGIC != fgetc(g_aje_file)) {;
return AJE_FILE_INVALID;
}
s_cfg_start_pos = ftell(g_aje_file);
printf("Anlogic_ReadAjeHeader end.\n");
return AJE_OK;
}
/* read the chip id before processing data, need to get the chain information */
int Anlogic_ReadChipIdcode(void)
{
int rtn_val = AJE_OK;
int finish = 0;
/* get from HDR/TDR Command */
int hdr_num = 0;
int tdr_num = 0;
/* get from SIR Command */
int trailer_num = 0;
int header_num = 0;
long line_length = 0;
char op_code = 0x00;
printf("Anlogic_ReadChipIdcode start.\n");
while((finish == 0) && (fgetc(g_aje_file)) == BEGINLINE) {
line_length = Anlogic_ReadNumber()/8;
printf("Anlogic_ReadNumber()/8 = %d.\n",line_length);
op_code = fgetc(g_aje_file);
printf("op_code = 0x%02x.\n",op_code);
switch (op_code) {
case HDR:
printf("Acase HDR.\n");
hdr_num = Anlogic_ReadNumber();
if (hdr_num != 0) {
while (CONTINUE != fgetc(g_aje_file));
}
break;
case TDR:
printf("Acase TDR.\n");
tdr_num = Anlogic_ReadNumber();
if (tdr_num != 0) {
while (CONTINUE != fgetc(g_aje_file));
}
break;
case SIR:
printf("Acase SIR.\n");
finish = Anlogic_ReadSirInfo(&header_num, &trailer_num);
break;
default:
printf("Acase default.\n");
fseek(g_aje_file, line_length-1, SEEK_CUR);
break;
}
}
if (finish == 0) {
return AJE_WARNING;
}
s_cur_level = tdr_num+trailer_num+1;
s_total_level = tdr_num+trailer_num+1+header_num+hdr_num;
rtn_val = Anlogic_ExeSirCommand(s_idcode_pub, s_cur_level, s_total_level);
if (rtn_val != AJE_OK) {
return rtn_val;
}
unsigned char* tdo_data = (unsigned char*)malloc(5*sizeof(unsigned char));
tdo_data[4] = '\0';
rtn_val = Anlogic_ExeSdrCommand(32, s_cur_level, s_total_level, NULL, tdo_data);
if (rtn_val == AJE_OK) { /* print 32 bit chip id in terminal */
if (tdo_data[0] == 0 && tdo_data[1] == 0 &&
tdo_data[2] == 0 && tdo_data[3] == 0) {
printf("Error: Chip validation failed, please check the connection.\n");
rtn_val = AJE_ERROR;
} else {
printf("\n Chip Id : ");
Anlogic_PrintData(4, tdo_data);
printf("\n");
}
}
free(tdo_data);
tdo_data = NULL;
printf("Anlogic_ReadChipIdcode end.\n");
return rtn_val;
}
/* Loading Read chip io status instrcution and compare ref_io_status */
int Anlogic_LoadingReadChipIOStatusInstruction(unsigned int bit_size, unsigned char* ref_io_status) {
int rtn_val = AJE_OK;
int bit = 0;
unsigned int io_index = 0;
unsigned int byte = (bit_size+7)/8;
rtn_val = Anlogic_ExeSirCommand(SAMPLE, s_cur_level, s_total_level);
if (rtn_val != AJE_OK) {
return rtn_val;
}
unsigned char* tdo_data = (unsigned char*)malloc((byte+1)*sizeof(unsigned char));
tdo_data[byte] = '\0';
rtn_val = Anlogic_ExeSdrCommand(bit_size, s_cur_level, s_total_level, NULL, tdo_data);
if (rtn_val == AJE_OK) {
printf("\nIO Status: \n");
printf("Bs order\t\tRef\t\tRead\t\tVerify\n");
for (io_index = 0; io_index < bit_size; ++io_index) {
bit = Anlogic_GetBit(tdo_data, io_index);
printf("%8d\t\t%c\t\t%d\t\t", io_index, ref_io_status[io_index], bit);
if (ref_io_status[io_index] - '0' == bit) {
printf("true\n");
} else {
printf("false\n");
}
}
}
free(tdo_data);
tdo_data = NULL;
return rtn_val;
}
int Anlogic_ReadChipIOStatus(char* io_state_file) {
int rtn_val = AJE_OK;
FILE* io_stat_stream = NULL;
char line[LINE_MAX_SIZE];
char buf[10];
int sscanf_num = 0;
char sdr_tdi_str[DATA_MAX_SIZE];
char sdr_tdo_str[DATA_MAX_SIZE];
char sdr_mask_str[DATA_MAX_SIZE];
char* sdr_tdo_bin_str = NULL;
char* sdr_mask_bin_str = NULL;
unsigned char* ref_io_status = NULL;
int sir_num = 0;
int sir_val = 0;
int sdr_num = 0;
int str_idx = 0;
int find_sample_ins = 0; /* sample instruction flag */
char* p = strstr(io_state_file, ".svf");
if (p == NULL || strcmp(p, ".svf") != 0) {
printf("Error: %s is not a svf file\n", io_state_file);
return AJE_FILE_INVALID;
}
if ((io_stat_stream = fopen(io_state_file, "r")) == NULL) {
printf("Error: cannot read the svf file %s\n", io_state_file);
return AJE_FILE_OPEN_FAIL;
}
// Parse svf file
while (!feof(io_stat_stream)) {
fgets(line, LINE_MAX_SIZE, io_stat_stream);
// Find "Sample" instruction, E.G. SIR 8 TDI (05)
if (find_sample_ins == 0) {
sscanf_num = sscanf(line, "SIR %d TDI (%d)", &sir_num, &sir_val);
if (sscanf_num != 2) { continue; }
if (sir_num != 8 || sir_val != INS_SAMPLE) {
continue;
}
find_sample_ins = 1;
} else {
if (strncasecmp(line, "SDR", 3) != 0) {
continue;
}
// sample instruction
// E.G. SDR 426 TDI (3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
// TDO (3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBAFBFEAAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
// MASK (0000000000000000000000000000000000000000000000AAAAAAAA00000000000000000000000000000000000000000000000000000);
sscanf_num = sscanf(line, "SDR %d TDI (%[^)]) TDO (%[^)]) MASK (%[^)])", &sdr_num, sdr_tdi_str, sdr_tdo_str, sdr_mask_str);
if (sscanf_num == 2) { // for line feeds
fgets(line, LINE_MAX_SIZE, io_stat_stream);
sscanf_num = sscanf(line, "%s (%[^)])", buf, sdr_tdo_str);
assert(strcasecmp(buf, "TDO") == 0);
if (sscanf_num == 2) {
fgets(line, LINE_MAX_SIZE, io_stat_stream);
sscanf_num = sscanf(line, "%s (%[^ )])", buf, sdr_mask_str);
assert(strcasecmp(buf, "MASK") == 0);
}
}
if (sdr_num == 0 || sdr_tdi_str == NULL || sdr_tdo_str == NULL || sdr_mask_str == NULL) {
printf("Error: Invalid SDR string %s", line);
return AJE_FILE_INVALID;
}
ref_io_status = (unsigned char*)malloc((sdr_num+1)*sizeof(unsigned char));
memset(ref_io_status, 'x', sdr_num);
ref_io_status[sdr_num] = 0x00;
sdr_tdo_bin_str = Anlogic_HexStrToBinStr(sdr_tdo_str, sdr_num);
sdr_mask_bin_str = Anlogic_HexStrToBinStr(sdr_mask_str, sdr_num);
for(str_idx = 0; str_idx < sdr_num; ++str_idx) {
if (sdr_mask_bin_str[str_idx] == '1') { // the bit need verify
ref_io_status[sdr_num-1-str_idx] = sdr_tdo_bin_str[str_idx];
}
}
} // end read sdr instruction
} // end of read file
if (ref_io_status == NULL) {
printf("Error: Invalid svf file %s, cannot find the sample data", io_state_file);
return AJE_FILE_INVALID;
}
if (sdr_tdo_bin_str != NULL) { free(sdr_tdo_bin_str); sdr_tdo_bin_str = NULL; }
if (sdr_mask_bin_str != NULL) { free(sdr_mask_bin_str); sdr_mask_bin_str = NULL; }
rtn_val = Anlogic_LoadingReadChipIOStatusInstruction(sdr_num, ref_io_status);
return rtn_val;
}
int Anlogic_CheckDonePinStatus() {
int rtn_val = AJE_OK;
unsigned char* tdo_data = NULL;
s_done_status = 1;
rtn_val = Anlogic_ExeSirCommand(INS_READ_STATUS, s_cur_level, s_total_level);
tdo_data = (unsigned char*)malloc(5*sizeof(unsigned char));
tdo_data[4] = '\0';
rtn_val = Anlogic_ExeSdrCommand(32, s_cur_level, s_total_level, NULL, tdo_data);
if (rtn_val == AJE_OK) {
s_done_status = Anlogic_GetBit(tdo_data, 26);
}
free(tdo_data);
tdo_data = NULL;
return rtn_val;
}
/* core function, parse aje file and process data */
int Anlogic_ProcessCmd() {
int rtn_val = AJE_OK;
int tck_num = 0; /* for runtest num tck command */
int loop_num = 0; /* for loop command */
long cmd_length = 0;
long cur_pos = 0;
long freq = 0;
char op_code = '\0';
enum TAP_STATE tap_state = TAP_RESET;
fseek(g_aje_file, s_cfg_start_pos, SEEK_SET); /* restore to the start position of configuration */
while((fgetc(g_aje_file)) == BEGINLINE) {
cmd_length = Anlogic_ReadNumber()/8;
op_code = fgetc(g_aje_file);
switch (op_code) {
case STATE:
tap_state = Anlogic_TapState(fgetc(g_aje_file));
Anlogic_TapTransist(tap_state);
if (cmd_length == 2) {
printf("STATE %s;\n", Anlogic_TapState2Str(tap_state));
}
if (cmd_length >= 2 && tap_state == TAP_IDLE) {
tck_num = Anlogic_ProcessRuntestCmd();
if (tck_num > 0) {
Anlogic_ProcessRunTestTck(tck_num);
}
}
break;
case FREQUENCY:
freq = Anlogic_ReadNumber();
if (g_freq == 0 || g_freq > freq) {
g_freq = freq;
#ifdef AJE_DEBUG
printf("FREQUENCY %.2E HZ;\n", (float)g_freq);
#endif
}
break;
case SIR:
case SDR:
rtn_val = Anlogic_ProcessShiftCommand(op_code);
break;
case LOOP:
loop_num = Anlogic_ReadNumber();
cur_pos = ftell(g_aje_file);
break;
case ENDLOOP:
if (loop_num > 1) {
fseek(g_aje_file, cur_pos, SEEK_SET);
loop_num--;
}
break;
case TDR:
case TIR:
case HDR:
case HIR:
rtn_val = Anlogic_ProcessBypassCommand(op_code);
break;
case ENDIR:
tap_state = Anlogic_TapState(fgetc(g_aje_file));
Anlogic_SetEndIRState(tap_state);
break;
case ENDDR:
tap_state = Anlogic_TapState(fgetc(g_aje_file));
Anlogic_SetEndDRState(tap_state);
break;
case SETFLOW:
if (fgetc(g_aje_file) == CASCADE) {
s_cascade = 1;
}
break;
case RESETFLOW:
if (fgetc(g_aje_file) == CASCADE) {
s_cascade = 0;
}
break;
case TRST:
if (fgetc(g_aje_file) == ON) {
printf("TRST ON;\n");
} else {
printf("TRST OFF;\n");
}
break;
case RUNTEST:
{
fseek(g_aje_file, cmd_length-1, SEEK_CUR);
}
break;
default:
printf("Error: invalid file format, unkown opcode.\n\n");
return AJE_INVALID_COMMAND;
}
if (rtn_val != AJE_OK) {
return rtn_val;
}
}
return rtn_val;
}
int Anlogic_AjeToVec(const char* aje_file) {
int rtn_code = AJE_OK;
char* io_state_file = NULL; /* input svf file, use to read io status */
if ((g_aje_file = fopen(aje_file, "rb")) == NULL) {
return AJE_FILE_OPEN_FAIL;
}
else
printf("fopen %s sucess,file * = %p.\n",aje_file,g_aje_file);
/* read header content */
rtn_code = Anlogic_ReadAjeHeader();
if (rtn_code != AJE_OK) {
return rtn_code;
}
/* execute "state reset" first, 2019/12/20 */
Anlogic_Init();
/* read chip id code */
rtn_code = Anlogic_ReadChipIdcode();
if (rtn_code != AJE_OK) {
return rtn_code;
}
/* read io status */
if (io_state_file != NULL) {
rtn_code = Anlogic_ReadChipIOStatus(io_state_file);
if (rtn_code != AJE_OK) {
return rtn_code;
}
}
/* check done pin status */
Anlogic_CheckDonePinStatus();
/* core process function */
rtn_code = Anlogic_ProcessCmd();
fclose(g_aje_file);
return rtn_code;
}

View File

@ -0,0 +1,101 @@
/*******************************************************************
* Copyright (c) 2011 -2021 Anlogic Inc.
* The Software is distributed in source code form and is open to
* re-distribution and modification where applicable
*******************************************************************/
/*******************************************************************
Filename : ajeutil.c
Description: utility source file
Log: initial version, December 2019
*******************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int Anlogic_GetBit(unsigned char* data, int id) {
return (data[id/8] & (1 << (7-id%8))) ? 1 : 0;
}
void Anlogic_SetBit(unsigned char* data, int id, int val) {
unsigned char mask = 1 << (7-id%8);
if (val) {
data[id/8] |= mask;
} else {
data[id/8] &= ~mask;
}
}
/* reverse char data e.g. 8'b10001101 -> 8'b10110001 */
unsigned char Anlogic_ReverseChar(unsigned char byte) {
unsigned int bit_id = 0;
unsigned char flip_byte = 0x00;
for (bit_id = 0; bit_id < 8; ++bit_id) {
flip_byte <<= 1;
if (byte & 0x1) {
flip_byte |= 0x1;
}
byte >>= 1;
}
return flip_byte;
}
/* tranfer hex to bin data, e.g. char('A') -> char[4] = {'1', '0', '1', '0' } */
void Anlogic_HexTobin(char hex, char* char_s) {
switch(hex) {
case '0': strcpy(char_s ,"0000"); break;
case '1': strcpy(char_s ,"0001"); break;
case '2': strcpy(char_s ,"0010"); break;
case '3': strcpy(char_s ,"0011"); break;
case '4': strcpy(char_s ,"0100"); break;
case '5': strcpy(char_s ,"0101"); break;
case '6': strcpy(char_s ,"0110"); break;
case '7': strcpy(char_s ,"0111"); break;
case '8': strcpy(char_s ,"1000"); break;
case '9': strcpy(char_s ,"1001"); break;
case 'a':
case 'A': strcpy(char_s ,"1010"); break;
case 'b':
case 'B': strcpy(char_s ,"1011"); break;
case 'c':
case 'C': strcpy(char_s ,"1100"); break;
case 'd':
case 'D': strcpy(char_s ,"1101"); break;
case 'e':
case 'E': strcpy(char_s ,"1110"); break;
case 'f':
case 'F': strcpy(char_s ,"1111"); break;
default:
printf("Error: HexToChar Invalid Hex value %c", hex);
}
}
char* Anlogic_HexStrToBinStr(char* src_str, int bin_len) {
char* bin_value = NULL;
int hex_idx = 0;
int char_idx = 0;
char char_s[5] = { 0 };
int hex_size = strlen(src_str);
if (hex_size*4 < bin_len) {
return NULL;
}
bin_value = (char*)malloc((bin_len+1)*sizeof(char));
bin_value[bin_len] = 0x00;
for(hex_idx=hex_size-1; hex_idx>=0; --hex_idx) {
char c = src_str[hex_idx];
Anlogic_HexTobin(c, char_s);
for (char_idx = 0; char_idx<4; ++char_idx) {
bin_value[--bin_len] = char_s[3-char_idx];
if (bin_len == 0) {
return bin_value;
}
} // end char_idx
} // end hex_idx
return bin_value;
}

View File

@ -0,0 +1,155 @@
/*******************************************************************
* Copyright (c) 2011 -2021 Anlogic Inc.
* The Software is distributed in source code form and is open to
* re-distribution and modification where applicable
*******************************************************************/
/***********************************************************************
Filename: decode.c
Description: decode the data from aje file
Log: initial version, July 2019
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
extern FILE* g_aje_file;
/* Function delcared in lzw_lib.c */
extern int lzw_decompress (void (*dst)(int), int (*src)(void));
unsigned char* g_pWriteBuffer = NULL;
long int g_iWriteCount = 0;
void Anlogic_WriteBufferByte(int byte)
{
g_pWriteBuffer[g_iWriteCount++] = (unsigned char)byte;
}
int Anlogic_ReadAjeByte(void)
{
return fgetc(g_aje_file);
}
long Anlogic_NumberDecode(void) {
long number = 0;
char byte = '\0';
unsigned int count = 0;
do {
byte = fgetc(g_aje_file);
number += (byte & 0x7F) << (7 * count++);
} while (byte & 0x80);
return number;
}
unsigned char* Anlogic_BytesDecode(long bytes) {
long int i = 0;
long int key_count = 0;
unsigned char byte = 0, key = 0;
unsigned char* rtn_val = NULL;
rtn_val = (unsigned char*)malloc((bytes+1)*sizeof(unsigned char));
key = fgetc(g_aje_file);
for (i = 0; i < bytes; i++) {
if (key_count <= 0) {
byte = fgetc(g_aje_file);
rtn_val[i] = byte;
if (byte == key) {
key_count = Anlogic_NumberDecode(); // The number of key bytes
}
} else {
key_count--; // Use up the key chain first
rtn_val[i] = key;
}
}
return rtn_val;
}
unsigned char* Anlogic_NibbleDecode(long bytes) {
int i = 0, j = 0, byte_time = 0;
long int num_keys = 0, key_bytes, key_times;
unsigned char *buffer = 0;
unsigned char* rtn_val;
rtn_val = (unsigned char*)malloc((bytes+1)*sizeof(unsigned char));
num_keys = Anlogic_NumberDecode();
key_bytes = (num_keys + 1) / 2;
key_times = (bytes * 2) / num_keys;
buffer = (unsigned char*)calloc(key_bytes + 1 , sizeof(unsigned char));
if (!buffer) {
assert(0 && "nibble decode: calloc fail");
}
for (i = 0; i < key_bytes; i++ )
buffer[i] = fgetc(g_aje_file);
if (num_keys % 2 == 0) {
for ( i = 0; i < key_times; i++ ) {
for ( j = 0; j < key_bytes; j++ ) {
rtn_val[j+i*key_bytes] = buffer[j];
}
}
} else {
assert(key_times % 2 == 0);
buffer = (unsigned char*)realloc(buffer, key_bytes*2*sizeof(unsigned char));
if (!buffer) {
assert(0 && "nibble decode: realloc fail");
}
//buffer[key_bytes-2 : 0] keep no change
for(i = key_bytes-1; i < key_bytes*2-1; ++i) {
if (i == key_bytes-1)
buffer[i] = (buffer[i] & 0xF0) + (buffer[0] >> 4);
else
buffer[i] = ((buffer[i-key_bytes] << 4) & 0xF0) +
(buffer[i-key_bytes+1] >> 4);
}
byte_time = key_times / 2;
for(i = 0; i < byte_time; ++i) {
for(j = 0; j < (key_bytes*2-1); ++j) {
rtn_val[j+i*(key_bytes*2-1)] = buffer[j];
}
}
}
return rtn_val;
}
unsigned char* Anlogic_HuffmanDecode(long bytes) {
int i = 0, j = 0, m = 0, bits = 8;
unsigned char cur_char = 0, key = 0, byte = 0;
unsigned char* rtn_val;
rtn_val = (unsigned char*)malloc((bytes+1)*sizeof(unsigned char));
key = fgetc(g_aje_file);
for ( i = 0; i < bytes; i++ ) {
byte = 0x00;
if ( bits > 7 ) {
cur_char = fgetc(g_aje_file);
bits = 0;
}
if ( ( cur_char << bits++ ) & 0x80 ) {
m = 8;
for (j = 0; j < m; j++) {
if (bits > 7) {
cur_char = fgetc(g_aje_file);
bits = 0;
}
byte |= ( ( cur_char << bits++ ) & 0x80 ) >> j;
}
} else {
byte = key;
m = 0;
}
rtn_val[i] = byte;
}
return rtn_val;
}
unsigned char* Anlogic_LzwDecode(long bytes) {
g_pWriteBuffer = (unsigned char*)malloc((bytes+1)*sizeof(unsigned char));
g_iWriteCount = 0;
lzw_decompress(Anlogic_WriteBufferByte, Anlogic_ReadAjeByte);
return g_pWriteBuffer;
}

View File

@ -0,0 +1,26 @@
#include "jtagupdata.h"
#include "aje2vec.cpp"
JtagUp::JtagUp(std::string file):filepath(file){
m_state = 0;
}
JtagUp::~JtagUp(){
if(is_uping())
m_fu.get();
}
void JtagUp::startup(){
if(is_uping())
return;
m_state = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(20));
m_fu = std::async(std::launch::async,&JtagUp::upfc,this);
}
bool JtagUp::is_uping()
{
return m_fu.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout;
}
int JtagUp::getresult(){
return m_state;
}
void JtagUp::upfc(){
m_state = Anlogic_AjeToVec(filepath.c_str());
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "Jtag.h"
#include "opcode.h"
#include <iostream>
#include <future>
class JtagUp{
public:
JtagUp(std::string file);
~JtagUp();
void startup();
bool is_uping();
int getresult();
private:
void upfc();
volatile int m_state;
std::future<void> m_fu;
std::string filepath;
};

View File

@ -0,0 +1,353 @@
////////////////////////////////////////////////////////////////////////////
// **** LZW-AB **** //
// Adjusted Binary LZW Compressor/Decompressor //
// Copyright (c) 2016 David Bryant //
// All Rights Reserved //
// Distributed under the BSD Software License (see license.txt) //
////////////////////////////////////////////////////////////////////////////
//#define KERNEL_MODE
#ifdef KERNEL_MODE
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
/* This library implements the LZW general-purpose data compression algorithm.
* The algorithm was originally described as a hardware implementation by
* Terry Welsh here:
*
* Welch, T.A. A Technique for High-Performance Data Compression.
* IEEE Computer 17,6 (June 1984), pp. 8-19.
*
* Since then there have been enumerable refinements and variations on the
* basic technique, and this implementation is no different. The target of
* the present implementation is embedded systems, and so emphasis was placed
* on simplicity, fast execution, and minimal RAM usage.
*
* The symbols are stored in adjusted binary, which provides considerably
* better compression performance with virtually no speed penalty compared to
* the fixed sizes normally used. To ensure good performance on data with
* varying characteristics (like executable images) the encoder resets as
* soon as the dictionary is full. Also, worst-case performance is limited
* to about 8% inflation by catching poor performance and forcing an early
* reset before longer symbols are sent.
*
* The maximum symbol size is configurable on the encode side (from 9 bits
* to 12 bits) and determines the RAM footprint required by both sides and,
* to a large extent, the compression performance. This information is
* communicated to the decoder in the first stream byte so that it can
* allocate accordingly. The RAM requirements are as follows:
*
* maximum encoder RAM decoder RAM
* symbol size requirement requirement
* -----------------------------------------
* 9-bit 1792 bytes 1024 bytes
* 10-bit 4352 bytes 3072 bytes
* 11-bit 9472 bytes 7168 bytes
* 12-bit 19712 bytes 15360 bytes
*
* This implementation uses malloc(), but obviously an embedded version could
* use static arrays instead if desired (assuming that the maxbits was
* controlled outside).
*/
#define NULL_CODE -1 // indicates a NULL prefix
#define CLEAR_CODE 256 // code to flush dictionary and restart decoder
#define FIRST_STRING 257 // code of first dictionary string
/* This macro writes the adjusted-binary symbol "code" given the maximum
* symbol "maxcode". A macro is used here just to avoid the duplication in
* the lzw_compress() function. The idea is that if "maxcode" is not one
* less than a power of two (which it rarely will be) then this code can
* often send fewer bits that would be required with a fixed-sized code.
*
* For example, the first code we send will have a "maxcode" of 257, so
* every "code" would normally consume 9 bits. But with adjusted binary we
* can actually represent any code from 0 to 253 with just 8 bits -- only
* the 4 codes from 254 to 257 take 9 bits.
*/
#define WRITE_CODE(code,maxcode) do { \
int code_bits = (maxcode) < 1024 ? \
((maxcode) < 512 ? 8 : 9) : \
((maxcode) < 2048 ? 10 : 11); \
int extras = (1 << (code_bits + 1)) - (maxcode) - 1; \
if ((code) < extras) { \
shifter |= ((long)(code) << bits); \
bits += code_bits; \
} \
else { \
shifter |= ((long)(((code) + extras) >> 1) << bits); \
bits += code_bits; \
shifter |= ((long)(((code) + extras) & 1) << bits++); \
} \
do { (*dst)(shifter); shifter >>= 8; output_bytes++; \
} while ((bits -= 8) >= 8); \
} while (0)
/* LZW compression function. Bytes (8-bit) are read and written through callbacks and the
* "maxbits" parameter specifies the maximum symbol size (9-12), which in turn determines
* the RAM requirement and, to a large extent, the level of compression achievable. A return
* value of EOF from the "src" callback terminates the compression process. A non-zero return
* value indicates one of the two possible errors -- bad "maxbits" param or failed malloc().
*/
int lzw_compress (void (*dst)(int), int (*src)(void), int maxbits)
{
int next = FIRST_STRING, prefix = NULL_CODE, bits = 0, total_codes, c;
unsigned long input_bytes = 0, output_bytes = 0;
short *first_references, *next_references;
unsigned char *terminators;
unsigned long shifter = 0;
if (maxbits < 9 || maxbits > 12) // check for valid "maxbits" setting
return 1;
// based on the "maxbits" parameter, compute total codes and allocate dictionary storage
total_codes = 1 << maxbits;
#ifdef KERNEL_MODE
first_references = ( short int * ) kmalloc (total_codes * sizeof (first_references [0]));
next_references = ( short int * ) kmalloc ((total_codes - 256) * sizeof (next_references [0]));
terminators = ( unsigned char * ) kmalloc ((total_codes - 256) * sizeof (terminators [0]));
#else
first_references = ( short int * ) malloc (total_codes * sizeof (first_references [0]));
next_references = ( short int * ) malloc ((total_codes - 256) * sizeof (next_references [0]));
terminators = ( unsigned char * ) malloc ((total_codes - 256) * sizeof (terminators [0]));
#endif
if (!first_references || !next_references || !terminators)
return 1; // failed malloc()
// clear the dictionary
memset (first_references, 0, total_codes * sizeof (first_references [0]));
memset (next_references, 0, (total_codes - 256) * sizeof (next_references [0]));
memset (terminators, 0, (total_codes - 256) * sizeof (terminators [0]));
(*dst)(maxbits - 9); // first byte in output stream indicates the maximum symbol bits
// This is the main loop where we read input bytes and compress them. We always keep track of the
// "prefix", which represents a pending byte (if < 256) or string entry (if >= FIRST_STRING) that
// has not been sent to the decoder yet. The output symbols are kept in the "shifter" and "bits"
// variables and are sent to the output every time 8 bits are available (done in the macro).
while ((c = (*src)()) != EOF) {
int cti; // coding table index
input_bytes++;
if (prefix == NULL_CODE) { // this only happens the very first byte when we don't yet have a prefix
prefix = c;
continue;
}
if ((cti = first_references [prefix])) { // if any longer strings are built on the current prefix...
while (1)
if (terminators [cti - 256] == c) { // we found a matching string, so we just update the prefix
prefix = cti; // to that string and continue without sending anything
break;
}
else if (!next_references [cti - 256]) { // this string did not match the new character and
next_references [cti - 256] = next; // there aren't any more, so we'll add a new string
cti = 0; // and point to it with "next_reference"
break;
}
else
cti = next_references [cti - 256]; // there are more possible matches to check, so loop back
}
else // no longer strings are based on the current prefix, so now
first_references [prefix] = next; // the current prefix plus the new byte will be the next string
// If "cti" is zero, we could not simply extend our "prefix" to a longer string because we did not find a
// dictionary match, so we send the symbol representing the current "prefix" and add the new string to the
// dictionary. Since the current byte "c" was not included in the prefix, that now becomes our new prefix.
if (!cti) {
WRITE_CODE (prefix, next); // send symbol for current prefix (0 to next-1)
terminators [next - 256] = c; // newly created string has current byte as the terminator
prefix = c; // current byte also becomes new prefix for next string
// This is where we bump the next string index and decide whether to clear the dictionary and start over.
// The triggers for that are either the dictionary is full or we've been outputting too many bytes and
// decide to cut our losses before the symbols get any larger. Note that for the dictionary full case we
// do NOT send the CLEAR_CODE because the decoder knows about this and we don't want to be redundant.
if (++next == total_codes || output_bytes > 8 + input_bytes + (input_bytes >> 4)) {
if (next < total_codes)
WRITE_CODE (CLEAR_CODE, next);
// clear the dictionary and reset the byte counters -- basically everything starts over
// except that we keep the last pending "prefix" (which, of course, was never sent)
memset (first_references, 0, total_codes * sizeof (first_references [0]));
memset (next_references, 0, (total_codes - 256) * sizeof (next_references [0]));
memset (terminators, 0, (total_codes - 256) * sizeof (terminators [0]));
input_bytes = output_bytes = 0;
next = FIRST_STRING;
}
}
}
// we're done with input, so if we've received anything we still need to send that pesky pending prefix...
if (prefix != NULL_CODE) {
WRITE_CODE (prefix, next);
if (++next == total_codes) // watch for clearing to the first string to stay in step with the decoder!
next = FIRST_STRING; // (this was actually a corner-case bug that did not trigger often)
}
WRITE_CODE (next, next); // the maximum possible code is always reserved for our END_CODE
if (bits) // finally, flush any pending bits from the shifter
(*dst)(shifter);
#ifdef KERNEL_MODE
kfree (terminators); kfree (next_references); kfree (first_references);
#else
free (terminators); free (next_references); free (first_references);
#endif
return 0;
}
/* LZW decompression function. Bytes (8-bit) are read and written through callbacks. The
* "maxbits" parameter is read as the first byte in the stream and controls how much memory
* is allocated for decoding. A return value of EOF from the "src" callback terminates the
* compression process (although this should not normally occur). A non-zero return value
* indicates an error, which in this case can be a bad "maxbits" read from the stream, a
* failed malloc(), or if an EOF is read from the input stream before the compression
* terminates naturally with END_CODE.
*/
int lzw_decompress (void (*dst)(int), int (*src)(void))
{
int read_byte, next = FIRST_STRING, prefix = CLEAR_CODE, bits = 0, total_codes;
unsigned char *terminators, *reverse_buffer;
unsigned long shifter = 0;
short *prefixes;
if ((read_byte = ((*src)())) == EOF || (read_byte & 0xfc)) //sanitize first byte
return 1;
// based on the "maxbits" parameter, compute total codes and allocate dictionary storage
total_codes = 512 << (read_byte & 0x3);
#ifdef KERNEL_MODE
reverse_buffer = ( unsigned char *) kmalloc ((total_codes - 256) * sizeof (reverse_buffer [0]));
prefixes = ( short * ) kmalloc ((total_codes - 256) * sizeof (prefixes [0]));
terminators = ( unsigned char * ) kmalloc ((total_codes - 256) * sizeof (terminators [0]));
#else
reverse_buffer = ( unsigned char *) malloc ((total_codes - 256) * sizeof (reverse_buffer [0]));
prefixes = ( short * ) malloc ((total_codes - 256) * sizeof (prefixes [0]));
terminators = ( unsigned char * ) malloc ((total_codes - 256) * sizeof (terminators [0]));
#endif
if (!reverse_buffer || !prefixes || !terminators) // check for mallco() failure
return 1;
// This is the main loop where we read input symbols. The values range from 0 to the code value
// of the "next" string in the dictionary (although the actual "next" code cannot be used yet,
// and so we reserve that code for the END_CODE). Note that receiving an EOF from the input
// stream is actually an error because we should have gotten the END_CODE first.
while (1) {
int code_bits = next < 1024 ? (next < 512 ? 8 : 9) : (next < 2048 ? 10 : 11), code;
int extras = (1 << (code_bits + 1)) - next - 1;
do {
if ((read_byte = ((*src)())) == EOF) {
#ifdef KERNEL_MODE
kfree (terminators); kfree (prefixes); kfree (reverse_buffer);
#else
free (terminators); free (prefixes); free (reverse_buffer);
#endif
return 1;
}
shifter |= (long) read_byte << bits;
} while ((bits += 8) < code_bits);
// first we assume the code will fit in the minimum number of required bits
code = (int) shifter & ((1 << code_bits) - 1);
shifter >>= code_bits;
bits -= code_bits;
// but if code >= extras, then we need to read another bit to calculate the real code
// (this is the "adjusted binary" part)
if (code >= extras) {
if (!bits) {
if ((read_byte = ((*src)())) == EOF) {
#ifdef KERNEL_MODE
kfree (terminators); kfree (prefixes); kfree (reverse_buffer);
#else
free (terminators); free (prefixes); free (reverse_buffer);
#endif
return 1;
}
shifter = (long) read_byte;
bits = 8;
}
code = (code << 1) - extras + (shifter & 1);
shifter >>= 1;
bits--;
}
if (code == next) // sending the maximum code is reserved for the end of the file
break;
else if (code == CLEAR_CODE) // otherwise check for a CLEAR_CODE to start over early
next = FIRST_STRING;
else if (prefix == CLEAR_CODE) { // this only happens at the first symbol which is always sent
(*dst)(code); // literally and becomes our initial prefix
next++;
}
// Otherwise we have a valid prefix so we step through the string from end to beginning storing the
// bytes in the "reverse_buffer", and then we send them out in the proper order. One corner-case
// we have to handle here is that the string might be the same one that is actually being defined
// now (code == next-1). Also, the first 256 entries of "terminators" and "prefixes" are fixed and
// not allocated, so that messes things up a bit.
else {
int cti = (code == next-1) ? prefix : code;
unsigned char *rbp = reverse_buffer, c;
do *rbp++ = cti < 256 ? cti : terminators [cti - 256]; // step backward through string...
while ((cti = (cti < 256) ? NULL_CODE : prefixes [cti - 256]) != NULL_CODE);
c = *--rbp; // the first byte in this string is the terminator for the last string, which is
// the one that we'll create a new dictionary entry for this time
do (*dst)(*rbp); // send string in corrected order (except for the terminator
while (rbp-- != reverse_buffer); // which we don't know yet)
if (code == next-1)
(*dst)(c);
prefixes [next - 1 - 256] = prefix; // now update the next dictionary entry with the new string
terminators [next - 1 - 256] = c; // (but we're always one behind, so it's not the string just sent)
if (++next == total_codes) // check for full dictionary, which forces a reset (and, BTW,
next = FIRST_STRING; // means we'll never use the dictionary entry we just wrote)
}
prefix = code; // the code we just received becomes the prefix for the next dictionary string entry
// (which we'll create once we find out the terminator)
}
#ifdef KERNEL_MODE
kfree (terminators); kfree (prefixes); kfree (reverse_buffer);
#else
free (terminators); free (prefixes); free (reverse_buffer);
#endif
return 0;
}

View File

@ -7,31 +7,48 @@
#include "config.h"
#include "StopWatch.h"
#include "applog.h"
#include "Capturer.h"
#include "StateControl.h"
#include "Displaydef.h"
#include "MotorConfig.h"
#include "DisplayCenter.h"
static const std::string loggername = "MotorBoard";
MotorBoard::MotorBoard()
MotorBoard::MotorBoard(std::shared_ptr<WakeUp> wake)
: devPort(MOTOR_UART),
m_glue({nullptr, nullptr, nullptr,nullptr,nullptr,nullptr})
m_glue({nullptr, nullptr, nullptr,nullptr,nullptr,nullptr,nullptr})
{
LOG_INIT();
m_uartEnable.reset(new GpioOut(152));
m_uartEnable->setDirection(Gpio::out);
// m_uartEnable->setEdge(Gpio::rising);
//m_uartEnable.reset(new GpioOut(149));
//m_uartEnable->setValue(Gpio::Low);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
m_regsAccess.reset(new UartRegsAccess(devPort, bauds, 0x07, 0x87));
m_intPinMonitor.reset(new PinMonitor(intport, std::bind(&MotorBoard::pin_call, this, std::placeholders::_1)));
//m_scansensorMonitor.reset(new PinMonitor(149, std::bind(&MotorBoard::scansensor_call, this, std::placeholders::_1)));
//m_uartEnable->setValue(Gpio::High);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
m_os_mode = os_mode();
m_statecontrol.reset(new StateControl(m_regsAccess,wake));
m_wake = wake;
}
static int paperinnum = 0;
void MotorBoard::start()
void MotorBoard::start(HGScanConfig cfg)
{
m_config = cfg;
keep_last_paper=false;
paperinnum = 0;
m_paperout_count = 0;
clear_error();
set_time_error(120);
set_double_inpect(m_config.g200params.double_feed_enbale);
set_staple_inpect(m_config.g200params.stable_enbale);
set_paper_inspect(0);
set_auto_paper(m_config.g200params.is_autopaper,m_config.g200params.en_anlogic_key);
set_screw_inpect(m_config.g200params.screw_detect_enable);
set_screw_level(m_config.g200params.screw_detect_level);
set_long_paper(true);
unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0, val);
@ -39,18 +56,29 @@ void MotorBoard::start()
write(0, val);
smbc->enable = 1;
write(0, val);
paperinnum =0 ;
en_lifter();
}
void MotorBoard::stop()
{
printf("MotorBoard Stop \n");
unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0, val);
smbc->enable = 0;
write(0, val);
}
bool MotorBoard::en_lifter()
{
unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0x00, val);
smbc->lifter_en = 1;
write(0x00, val);
smbc->lifter_en = 0;
return write(0x00, val);
}
void MotorBoard::pick_paper(void)
{
@ -59,74 +87,14 @@ void MotorBoard::pick_paper(void)
read(0x00, val);
smbc->pick_paper = 0;
write(0x00, val);
std::this_thread::sleep_for(std::chrono::microseconds(500));
smbc->pick_paper = 1;
write(0x00, val);
// smbc->pick_paper = 0;
// write(0x00, val);
}
void MotorBoard::clear_error()
{
unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0, val);
smbc->error_clean = 1;
write(0, val);
smbc->error_clean = 0;
write(0, val);
}
bool MotorBoard::wait_paper_in(int timeout_ms)
{
return cv_paper_in.wait(timeout_ms);
}
bool MotorBoard::wait_paper_out(int timeout_ms)
{
return cv_paper_out.wait(timeout_ms);
}
int MotorBoard::os_mode()
{
unsigned int val;
read(0x02, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->scan_mode;
}
bool MotorBoard::paper_ready()
{
unsigned int val;
read(0x02, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->feeding_paper_ready;
}
bool MotorBoard::is_converopen()
{
unsigned int val;
read(0x02, val);
SMBSTATUS *smb_mode = (SMBSTATUS *)&val;
return smb_mode->open_machine;
}
bool MotorBoard::is_scanning()
{
unsigned int val;
read(0x02, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->work_status;
}
bool MotorBoard::is_jam()
{
return false;
}
void MotorBoard::motor_reset(){
}
void MotorBoard::clean_paper_road()
{
void MotorBoard::clean_paper_road(){
unsigned int val;
SMB_FUNC *smbc = (SMB_FUNC *)(&val);
read(6, val);
@ -140,6 +108,83 @@ void MotorBoard::clean_paper_road()
else{
printf("\n 非空闲模式不允许清理纸道!!!!");
}
}
void MotorBoard::clear_error()
{
unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0, val);
smbc->error_clean = 1;
write(0, val);
smbc->error_clean = 0;
write(0, val);
}
bool MotorBoard::wait_arrival_top(int timeout_ms)
{
return cv_arrival_top.wait(timeout_ms);
}
bool MotorBoard::wait_paper_in(int timeout_ms)
{
return cv_paper_in.wait(timeout_ms);
}
bool MotorBoard::wait_error(int timeout_ms)
{
return cv_error.wait(timeout_ms);
}
bool MotorBoard::wait_paper_out(int timeout_ms)
{
// StopWatch sw;
// LOG_TRACE("wait_paper_out ");
// while(sw.elapsed_ms()<timeout_ms)
// {
// if(m_paperout_count > 0)
// {
// m_paperout_count--;
// return true;
// }
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
// }
// return false;
return cv_paper_out.wait(timeout_ms);
}
bool MotorBoard::wait_done(int timeout_ms)
{
return cv_scan_done.wait(timeout_ms);
}
int MotorBoard::os_mode()
{
// unsigned int val;
// read(0x02, val);
// SMB_MODE *smb_mode = (SMB_MODE *)&val;
// return smb_mode->scan_mode;
unsigned int val;
read(0x06,val);
SMB_FUNC smb_func = *(SMB_FUNC*)&val;
return smb_func.param.work_mode == 1;
}
bool MotorBoard::paper_ready()
{
unsigned int val;
read(0x02, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->feeding_paper_ready;
}
bool MotorBoard::is_scanning()
{
unsigned int val;
read(0x02, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->work_status;
}
int MotorBoard::paper_counter()
@ -150,31 +195,54 @@ int MotorBoard::paper_counter()
return smb_mode->scan_num;
}
bool MotorBoard::set_paper_inspect_param(unsigned int value /* = 1000 */)
{
unsigned int val;
if (!read(0x04, val))
return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->error_range_set = value;
return write(0x04, val);
}
bool MotorBoard::get_keeplastpaper(){
return keep_last_paper;
}
bool MotorBoard::set_paper_inpect_info(unsigned int value)
{
unsigned int val;
if (!read(0x04, val))
return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->paper_infor = value;
return write(0x04, val);
}
bool MotorBoard::set_paper_inspect(bool enable /* = true */)
{
unsigned int val;
if (!read(0x04, val))
return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->paper_size_check_en = enable;
return write(0x04, val);
}
bool MotorBoard::set_double_inpect(bool enable)
{
unsigned int val;
if (!read(0x00, val))
return false;
enable?m_statecontrol->lcdcontrol(4):m_statecontrol->lcdcontrol(5);
SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->double_paper = enable;
return write(0x00, val);
}
bool MotorBoard::set_auto_paper(bool enable){
unsigned int val;
if (!read(0x00, val))
return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->autofeed_mode = enable;
return write(0x00, val);
bool MotorBoard::get_doublle_inpect()
{
return 0;
}
bool MotorBoard::set_staple_inpect(bool enable)
{
unsigned int val;
@ -184,8 +252,30 @@ bool MotorBoard::set_staple_inpect(bool enable)
smb_config->staple_enable = enable;
return write(0x00, val);
}
bool MotorBoard::get_staple_inpect()
{
return 0;
}
bool MotorBoard::set_cuospeed(int value)
{
unsigned int val;
if (!read(0x4, val))
return false;
SMBCONFIGEXT *smb_config = (SMBCONFIGEXT *)&val;
smb_config->cuo_speed = value;
return write(0x04, val);
}
bool MotorBoard::set_en600DPI(bool en)
{
unsigned int val;
if (!read(0x00, val))
return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->dpi600 = en?1:0;
return write(0x00, val);
}
bool MotorBoard::set_color_mode(int mode)
{
unsigned int val;
@ -195,8 +285,12 @@ bool MotorBoard::set_color_mode(int mode)
smb_config->color_mode = mode;
return write(0x00, val);
}
int MotorBoard::get_color_mode()
{
return 0;
}
bool MotorBoard::set_speed_mode(int mode,int dpi,int iscolor)
bool MotorBoard::set_speed_mode(int mode)
{
unsigned int val;
if (!read(0x00, val))
@ -219,47 +313,34 @@ int MotorBoard::get_speed_mode()
return smb_config->v_setting;
}
bool MotorBoard::set_cuospeed(unsigned int speed,uint dpi,uint iscolor)
{
unsigned int val;
if (!read(0x04, val))
return -1;
SMB_CONFIG_EXT *smb_config = (SMB_CONFIG_EXT *)&val;
smb_config->cuo_speed = speed;
return write(0x04,val);
}
std::shared_ptr<IRegsAccess> MotorBoard::regs()
{
return m_regsAccess;
}
static int pinindex=0;
static int countindex =0;
void MotorBoard::pin_call(unsigned int pinNum)
{
static int index = 0;
LOG_TRACE(string_format("pin %d", index++));
int os_m = os_mode();
if (m_os_mode != os_m)
{
m_os_mode = os_m;
if (m_glue.m_os_mode_call)
m_glue.m_os_mode_call(m_os_mode);
}
// int os_m = os_mode(); //安路屏蔽计数 扫描过程中无法操作按键
// if (m_os_mode != os_m)
// {
// m_os_mode = os_m;
// cv_os_mode.notify_all();
// if (m_glue.m_os_mode_call)
// m_glue.m_os_mode_call(m_os_mode);
// }
if (m_os_mode)
{
LOG_TRACE("not scan mode");
return;
}
// if (m_os_mode) //安路屏蔽计数返回 以刷新计数状态
// {
// LOG_TRACE("not scan mode");
// return;
// }
unsigned int val;
SMBSTATUS *smb_status = (SMBSTATUS *)&val;
if (!read(0x01, val))
LOG_TRACE("read error");
LOG_TRACE(string_format("status %08x", val));
//printf("\n reg 1 val =%d",val);
if(val & 0x800){
//printf("\n keep_last_paper ");
keep_last_paper=true;
@ -279,11 +360,38 @@ void MotorBoard::pin_call(unsigned int pinNum)
if(m_glue.m_auto_paper)
m_glue.m_auto_paper(1);
}
if (val & 0xAFE)
if (val & 0x7c003FE)
{
SetKeyState(false);
cv_error.notify_all();
if (m_glue.m_error_call)
m_glue.m_error_call(val & 0x30efe); //0xefe index of 16:aquireimage error index of bit 17 :size check error
if(val & 0x30efe){
cv_paper_out.notify_all();
m_paperout_count++;
}
errormsg(val & 0x1c003fa);
if((val & 0x4) ||(val & 0x02000000))
{
if(m_glue.m_coveropen_call)
m_glue.m_coveropen_call((val & 0x4));//cover open & 0x04
if(val & 0x4){
PutMsg(DisType::Dis_Err_CoverOpen,0,ClearScreen::All);
set_auto_paper(false,false);
autopaperkeystop?autopaperkeystop():void(0);
if(m_statecontrol){
m_statecontrol->setcoverstate(true);
m_statecontrol->setmenuindex(0);
}
}
else{
PutMsg(DisType::Dis_Idel,0,ClearScreen::All);
m_statecontrol?m_statecontrol->setcoverstate(false):void();
}
return;
}
if(smb_status->double_clean_f)
PutMsg(DisType::Dis_Idel,0,ClearScreen::All);
LOG_TRACE("error");
return;
}
@ -292,48 +400,56 @@ void MotorBoard::pin_call(unsigned int pinNum)
if (!smb_status->scan_pulse)
{
cv_paper_in.notify_all();
LOG_TRACE("paper in");
printf("\n paper pulse num = %d ", paperinnum++);
unsigned int papercount = 0;
read(0x02,papercount);
SMBMODE smbmode = *(SMBMODE*)&papercount;
printf("paper in arm count = %d ,motorcount = %d time = %s\n",++countindex,smbmode.scan_num);
startcapimage(true);
PutMsg(DisType::Dis_Scan_Page, smbmode.scan_num,ClearScreen::BOT);
}
if(smb_status->paper_left)
{
cv_paper_out.notify_all();
LOG_TRACE("paper left");
m_paperout_count++;
//printf("paper out time = %s \n",GetCurrentTimeStamp(2).c_str());
startcapimage(true);
LOG_TRACE(string_format("m_paperout_count %s",to_string(m_paperout_count)));
}
}
if (val & 0x400)
{
LOG_TRACE("done");
cv_scan_done.notify_all();
if (m_glue.m_scan_done_call)
m_glue.m_scan_done_call();
cv_paper_out.notify_all();
clear_error();
SetKeyState(false);
if(m_wake.get())
m_wake->setsleepfalg(false);
}
}
void MotorBoard::set_capture(std::shared_ptr<ICapturer> cap)
{
m_cap= cap;
}
void MotorBoard::scansensor_call(unsigned int pinNum)
{
// static int indexscansensor=0;
// m_uartEnable->setValue(Gpio::High);
// LOG_TRACE(string_format(" gpio149 call times -%d ", indexscansensor++));
// cv_paper_in.notify_all();
// m_uartEnable->setValue(Gpio::Low);
}
bool MotorBoard::write(unsigned int addr, unsigned int val)
{
return m_regsAccess->write(addr, val);
return m_regsAccess.get()?m_regsAccess->write(addr, val):false;
}
bool MotorBoard::read(unsigned int addr, unsigned int &val)
{
return m_regsAccess->read(addr, val);
return m_regsAccess.get()?m_regsAccess->read(addr, val):false;
}
bool MotorBoard::set_time_error(int value){
unsigned int val;
if (!read(0x05, val))
return false;
SMBCONFIGTIME *smb_config = (SMBCONFIGTIME *)&val;
smb_config->error_time_set = value;
return write(0x05, val);
}
void MotorBoard::set_callbacks(MotorBoardGlue glue)
{
m_glue = glue;
@ -366,6 +482,16 @@ bool MotorBoard::set_screw_level(int level)
return write(0x00, val);
}
bool MotorBoard::set_auto_paper(bool enable,bool enkey){
unsigned int val;
if (!read(0x00, val))
return false;
m_statecontrol?m_statecontrol->setautopaperflag(enable,enkey):void(0);
SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->autofeed_mode = enable;
return write(0x00, val);
}
bool MotorBoard::set_long_paper(bool enable)
{
unsigned int val;
@ -385,3 +511,180 @@ int MotorBoard::get_screw_level()
SMBCONFIG *smb_mode = (SMBCONFIG *)&val;
return smb_mode->skew_parameter;
}
void MotorBoard::start_countmode()
{
unsigned int regval=0;
read(0x06,regval);
LOG_TRACE(string_format("func6 regval = %08x",regval));
SMBFUNC func = *(SMBFUNC*)&regval;
func.param.work_mode =1;
func.param.func_feed_mid = 1;
func.param.func_clear_count = 1;
LOG_TRACE(string_format("func6 value = %08x",func.value));
write(0x06,func.value);
func.param.func_encount = 1;
func.param.key_sound = 1;
func.param.func_clear_count = 0;
LOG_TRACE(string_format("func6 value = %08x",func.value));
write(0x06,func.value);
func.param.func_encount = 0;
func.param.key_sound = 0;
LOG_TRACE(string_format("func6 value = %08x",func.value));
write(0x06,func.value);
}
void MotorBoard::PutMsg(DisType type,int value,ClearScreen clearscreen)
{
if(m_statecontrol.get())
m_statecontrol->PutMsg(type,value,clearscreen);
}
void MotorBoard::errormsg(uint value)
{
if (value & 0x2)
PutMsg(DisType::Dis_Err_NoPaper,0,ClearScreen::All);
else if (value & 0x8)
PutMsg(DisType::Dis_Err_FeedError,0,ClearScreen::All);
// else if (value & 0x10)
// PutMsg(DisType::Dis_Err_JamIn,0,ClearScreen::All);
else if (value & 0x20)
PutMsg(DisType::Dis_Err_DoubleFeed,0,ClearScreen::All);
else if (value & 0x40)
PutMsg(DisType::Dis_Err_Stable,0,ClearScreen::All);
else if (value & 0x80)
PutMsg(DisType::Dis_Err_PaperScrew,0,ClearScreen::All);
else if (value & 0x00010000)
PutMsg(DisType::Dis_Err_AqrImgTimeout,0,ClearScreen::All);
else if((value & 0x1000010) == 0x1000010)
PutMsg(DisType::Dis_Err_JamIn,3,ClearScreen::All);
else if((value & 0x800010) == 0x800010)
PutMsg(DisType::Dis_Err_JamIn,2,ClearScreen::All);
else if((value & 0x400010) == 0x400010)
PutMsg(DisType::Dis_Err_JamIn,1,ClearScreen::All);
}
void MotorBoard::SetKeyState(bool value)
{
if(m_statecontrol)
m_statecontrol->setrunstate(value);
}
void MotorBoard::set_keystopenable(bool value){
unsigned int regval=0;
read(0x06,regval);
LOG_TRACE(string_format("func6 regval = %08x",regval));
SMBFUNC func = *(SMBFUNC*)&regval;
func.param.key_stop_enable = value;
write(0x06,regval);
}
void MotorBoard::set_freq(int motor_choose,int speedmode,int colormode,int dpi)
{
MotorConfig cf;
auto params = cf.GetMotorSpeedParams(motor_choose == 1?0:1,MotorConfig::MTBDType::MT_DRV);
MotorSpeedParam param;
//printf("\n---node.dpi ==%d && node.colormode == %d && node.speed == %d----- ",dpi,colormode,speedmode);
for(auto &node : params)
{
if(node.dpi == dpi && node.colormode == colormode && node.speed == speedmode)
{
param = node.mt_param;
//printf("\n-------------------------------------------------");
break;
}
}
std::vector<std::uint32_t> table;
if(motor_choose == 0)
{
int x = (dpi == 1?(jsonconfig().getscannerinfo().chu_motor_speed_200):(dpi == 2?jsonconfig().getscannerinfo().chu_motor_speed_300 : jsonconfig().getscannerinfo().chu_motor_speed_600));
unsigned int regval=0;
read(0x06,regval);
SMBFUNC func = *(SMBFUNC*)&regval;
func.param.motor_choose = motor_choose;
func.param.wr_en = 1;
write(0x06,func.value);
write(0x04,x);
//func.param.wr_en = 0;
//write(0x06,func.value);
return ;
}
if(motor_choose == 1)
table = frep_cfg(param.finalPeriod,param.Fmin,param.stepnum,param.a,param.offset,param.finalDelay,param.acceleration_time);
if(motor_choose == 2)
table = frep_cfg(param.finalPeriod,param.Fmin,param.stepnum,param.a,param.offset,param.finalDelay,param.acceleration_time);
if(motor_choose == 3)
table = frep_cfg(param.finalPeriod,param.Fmin,param.stepnum,param.a,param.offset,param.finalDelay,param.acceleration_time);
unsigned int regval=0;
read(0x06,regval);
SMBFUNC func = *(SMBFUNC*)&regval;
int start_addr_cuo = 0;
#ifdef G200
if(motor_choose ==1 && speedmode > 1 && dpi <3)
start_addr_cuo = 63;
if(motor_choose ==1 && dpi ==3)
start_addr_cuo = 127;
#endif
printf("\nstart_addr_cuo =%d ",start_addr_cuo);
for(int i =0;i<256;i++)
{
func.param.motor_choose = motor_choose;
func.param.wr_en = 1;
func.param.motor_addr =i;
write(0x06,func.value);
write(0x04,i<start_addr_cuo?0:table[i-start_addr_cuo]);
//printf("\nfreq= %x addr =%d ",table[i-start_addr_cuo],i);
}
func.param.wr_en = 0;
write(0x06,func.value);
}
void MotorBoard::init_statecontrol()
{
m_regsAccess.reset(new UartRegsAccess(devPort, bauds, 0x07, 0x87));
m_intPinMonitor.reset(new PinMonitor(intport, std::bind(&MotorBoard::pin_call, this, std::placeholders::_1)));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
m_os_mode = os_mode();
m_statecontrol.reset(new StateControl(m_regsAccess,m_wake));
m_statecontrol->setautopaperstopcallback([&]{
autopaperkeystop?autopaperkeystop():void(0);
if(m_config.g200params.is_autopaper)
set_auto_paper(false,false);
});
PutMsg(DisType::Dis_Idel,0,ClearScreen::All);
}
void MotorBoard::release_statecontrol()
{
autopaperkeystop?autopaperkeystop():void(0);
set_auto_paper(false,false);
m_statecontrol.reset();
m_regsAccess.reset();
m_intPinMonitor.reset();
}
void MotorBoard::setautopaperkeystopcallback(std::function<void()> func){
if(func)
autopaperkeystop = func;
m_statecontrol?m_statecontrol->setautopaperstopcallback([&]{
autopaperkeystop?autopaperkeystop():void(0);
set_auto_paper(false,false);
}):void(0);
}
void MotorBoard::startcapimage(bool value)
{
// if(m_config.g200params.is_fixedpaper)
// return;
// FILE *fp = fopen("/sys/class/tty/ttyUSB0/device/huagao_scanner", "w");
// if (fp == NULL)
// perror("startcapimage open filed");
// else{
// fprintf(fp, "%d", value ? 1 : 0);
// fclose(fp);
// }
}

View File

@ -1,6 +1,40 @@
#pragma once
#include "Imotorboard.h"
#include <string>
#include <memory>
#include <condition_variable>
#include <functional>
#include "autoevent.hpp"
#include "commondef.h"
#include <math.h>
#include <vector>
#include "wakeup.hpp"
//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
*/
typedef struct SMB_CONFIG
{
@ -33,22 +67,27 @@ typedef struct SMB_STATUS
unsigned int m1_paper_sin : 1;
unsigned int open_machine : 1;
unsigned int pick_failed : 1;
unsigned int stop_jam : 1; // 5
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 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 sleep_conf : 3;//6
unsigned int dsp_get_paper_error : 1;
unsigned int paper_check_result : 1;
unsigned int arrival_top:1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ
unsigned int arrival_top_int:1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
unsigned int arrival_top:1;//顶部无纸
unsigned int arrival_top_int:1;//到达顶部中断
unsigned int auto_feed:1;//4
unsigned int paper_left:1;
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
@ -95,49 +134,64 @@ typedef union SMB_FUNC
unsigned int value;
} SMBFUNC;
class MotorBoard : public IMotorBoard
class MotorBoard
{
public:
MotorBoard();
void start() override;
void stop() override;
void clear_error() override;
void pick_paper() override;
void stop_pick_paper() override{};
int os_mode() override;
bool paper_ready() override;
bool is_scanning() override;
bool is_jam() override;
int paper_counter() override;
bool is_converopen() override;
bool set_long_paper(bool enable) override;
bool set_double_inpect(bool enable) override;
bool set_staple_inpect(bool enable) override;
bool set_auto_paper(bool enable) override;
bool set_color_mode(int mode) override;
int get_speed_mode() override;
bool set_speed_mode(int mode,int dpi,int iscolor) override;
bool set_screw_inpect(bool enable) override;
bool get_screw_inpect() override;
bool set_screw_level(int level) override;
int get_screw_level() override;
bool wait_paper_out(int timeout_ms) override;
bool wait_paper_in(int timeout_ms) override;
bool read(unsigned int addr, unsigned int &val) override;
bool write(unsigned int addr, unsigned int val) override;
bool set_cuospeed(unsigned int speed,uint dpi = 0,uint iscolor = 1) override;
void set_callbacks(MotorBoardGlue glue) override;
bool get_keeplastpaper() override;
std::shared_ptr<IRegsAccess> regs() override;
void set_capture(std::shared_ptr<ICapturer> cap) override;
void motor_reset() override;
void LedControlOption(HG_LedOption option,uint32_t time) override{};
void clean_paper_road() override;
MotorBoard(std::shared_ptr<WakeUp> 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_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();
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;
@ -145,12 +199,18 @@ private:
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;
std::shared_ptr<StateControl> m_statecontrol;
std::shared_ptr<WakeUp> 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::shared_ptr<ICapturer> m_cap;
bool b_paperin;
std::function<void()> autopaperkeystop;
};

View File

@ -1,320 +0,0 @@
#include "motormanager.h"
#include "MotorControl.h"
#include "sensormonitor.h"
#include <future>
#include "Led.h"
MotorManager::MotorManager():m_motorcontrol(new MotorControl()),
m_ledcontrol(new LedControl()),
is_usb_connect(false),
is_sleeping(false),
is_autopaper(false),
is_motor_run(false),
autopaper_state_change(false),
autopaperthread(1),
m_glue({nullptr,nullptr,nullptr,nullptr,nullptr,nullptr})
{
GetorSetSysClassValue(false,HG_PWM_FAN,false);
GetorSetSysClassValue(false,HG_MOTOR_FAN,false);
m_sensormonitor.reset(new SensorMonitor([&](int value){pincall(value);}));
m_ledcontrol->option(HG_WHITE_ON,300);
}
MotorManager::~MotorManager()
{
}
bool MotorManager::GetOrSetUsbConnectFlag(bool isGet,bool value){
if(isGet)
return is_usb_connect;
if(value == false)
m_ledcontrol->option(HG_LedOption::HG_WHITE_ON,300);
return is_usb_connect = value;
}
bool MotorManager::GetOrSetSleepFlag(bool isGet,bool value){
if(isGet)
return is_sleeping;
if(value == false)
{
if(!(m_sensormonitor->Is_ConverOpen()||m_sensormonitor->Is_Jam()))
{
if(!m_sensormonitor->Is_PaperOn())
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Reset);
m_ledcontrol->option(HG_WHITE_ON,0);
}
else{
if(m_sensormonitor->Is_ConverOpen())
m_ledcontrol->option(HG_RED_ON,300);
else
m_ledcontrol->option(HG_RED_ON,0);
}
}
else
is_autopaper = false;
if(mb_ev_cb_)
mb_ev_cb_(value ? SCANNER_STATUS_SLEEPING : SCANNER_STATUS_WAKED_UP);
return is_sleeping = value;
}
void MotorManager::set_capture(std::shared_ptr<ICapturer> cap)
{
m_cap = cap;
}
std::shared_ptr<IRegsAccess> MotorManager::regs()
{
return nullptr;
}
int MotorManager::os_mode(){
return 0;
}
bool MotorManager::paper_ready(){
return m_sensormonitor->Is_PaperOn();
}
void MotorManager::clear_error(){
mb_error = 0;
}
void MotorManager::start(){
is_motor_run = true;
m_papperout_time = std::chrono::steady_clock::now();
m_motorcontrol->MotorRun(MotorControl::MotorOption::ZZ_Forward);
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Forward);
GetorSetSysClassValue(false,HG_PWM_FAN,true);
GetorSetSysClassValue(false,HG_MOTOR_FAN,true);
m_ledcontrol->option(HG_WHITE_ON,0);
}
void MotorManager::stop(){
is_motor_run = false;
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Stop);
m_motorcontrol->MotorRun(MotorControl::MotorOption::ZZ_Stop);
GetorSetSysClassValue(false,HG_PWM_FAN,false);
GetorSetSysClassValue(false,HG_MOTOR_FAN,false);
}
bool MotorManager::wait_paper_out(int timeout_ms){
return cv_paperout.wait(timeout_ms);
}
bool MotorManager::wait_paper_in(int timeout_ms){
bool ret = cv_paperin.wait(timeout_ms);
std::cout<<"wait_paper_in timeout:"<<timeout_ms <<"ret :"<<ret<<std::endl;
if(ret)
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Pause);
return ret;
}
void MotorManager::pick_paper(){
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Forward);
}
void MotorManager::stop_pick_paper(){
m_motorcontrol->MotorRun(MotorControl::MotorOption::CZ_Pause);
}
bool MotorManager::is_scanning(){
return false;
}
bool MotorManager::is_jam(){
return GetorSetSysClassValue(true,"/sys/class/gpio/gpio54/value",true);
}
int MotorManager::paper_counter(){
return -1;
}
bool MotorManager::set_long_paper(bool enable){
return false;
}
bool MotorManager::set_double_inpect(bool enable){
if(enable)
//system("echo 1 > /sys/class/gpio/gpio139/value");
GetorSetSysClassValue(false,"/sys/class/gpio/gpio139/value",true);
else
//system("echo 0 > /sys/class/gpio/gpio139/value");
GetorSetSysClassValue(false,"/sys/class/gpio/gpio139/value",false);
return true;
}
bool MotorManager::set_staple_inpect(bool enable){
return false;
}
bool MotorManager::set_auto_paper(bool enable){
is_autopaper = enable;
return false;
}
bool MotorManager::set_color_mode(int mode){
return false;
}
int MotorManager::get_speed_mode(){
return -1;
}
bool MotorManager::set_speed_mode(int mode,int dpi,int iscolor){
m_motorcontrol->setczspeed(mode,dpi,iscolor);
m_motorcontrol->setzzspeed(mode,dpi,iscolor);
return true;
}
bool MotorManager::set_screw_inpect(bool enable){
return false;
}
bool MotorManager::get_screw_inpect(){
return false;
}
bool MotorManager::set_screw_level(int level){
return false;
}
int MotorManager::get_screw_level(){
return -1;
}
bool MotorManager::read(unsigned int addr, unsigned int &val){
return false;
}
bool MotorManager::write(unsigned int addr, unsigned int val){
return false;
}
bool MotorManager::set_cuospeed(unsigned int speed,uint dpi,uint iscolor){
m_motorcontrol->setczspeed(speed,dpi,iscolor);
return true;
}
void MotorManager::set_callbacks(MotorBoardGlue glue){
m_glue = glue;
}
bool MotorManager::get_keeplastpaper(){
return false;
}
void MotorManager::motor_reset(){
m_motorcontrol->MotorRun(MotorControl::CZ_Reset);
}
void MotorManager::pincall(int value){
if(mb_ev_cb_)
{
mb_ev_cb_(IMotorBoard::scanner_status_from_raw(value));
}
if(is_sleeping || !is_usb_connect)
return;
printf("\npin call value %d",value);
if(value == 1){
cv_paperin.notify_all();
if(std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now() - m_papperout_time).count() < 60)
m_glue.m_error_call?m_glue.m_error_call(0x40000):void(0);
printf("\n-------------- paper out time %f ---------------------------",std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now() - m_papperout_time).count());
m_papperout_time = std::chrono::steady_clock::now();
}
else if(value == 0){
cv_paperout.notify_all();
m_papperout_time = std::chrono::steady_clock::now();
}
if(value &0x24)
{
if(m_glue.m_error_call)
m_glue.m_error_call(value);
cv_paperin.notify_all();
cv_paperout.notify_all();
}
if(value == 0x20)
{
this->stop();
set_double_inpect(false);
}
if(value == 4 && is_converopen())
m_ledcontrol->option(HG_RED_ON,300);
if(value ==0x4000000 && !is_motor_run)
{
f_motorreset = std::async(std::launch::async,[&](){
std::this_thread::sleep_for(std::chrono::milliseconds(200));
if(is_usb_connect && !is_converopen() && (!paper_ready()))
motor_reset(),printf("\n conver reset");
});
printf("\n conver ******************************");
if(is_jam())
m_ledcontrol->option(HG_RED_ON,0);
else if(!is_usb_connect)
m_ledcontrol->option(HG_WHITE_ON,500);
else
m_ledcontrol->option(HG_WHITE_ON,0);
}
if(is_autopaper && value == 0x2000000 && !is_motor_run)
{
printf("\n ---------------------------------------------------");
autopaper_state_change = true;
autopaperthread.enqueue([&]{
StopWatch sw;
while (sw.elapsed_ms()<1000)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
if(!autopaper_state_change)
return;
}
m_glue.m_auto_paper(true);
printf("\n -----------------m_glue.m_auto_paper(true);----------------------------------");
});
}
if(is_autopaper && value == 2 && !is_motor_run)
{
autopaper_state_change = false;
}
if(value == 2){
if(is_motor_run == false && is_converopen() == false && is_jam() == false && m_ledcontrol->get_state() == HG_LedOption::HG_RED_ON)
{
m_ledcontrol->option(HG_WHITE_ON,0);
if(mb_error == 8 || mb_error == 79 || mb_error == 82)
motor_reset(),mb_error = 0;
}
}
}
bool MotorManager::is_converopen()
{
return m_sensormonitor->Is_ConverOpen();
}
void MotorManager::LedControlOption(HG_LedOption option,uint32_t time){
m_ledcontrol?m_ledcontrol->option(option,time):void(1);
}
void MotorManager::clean_paper_road(){
set_speed_mode(1,2,0);
StopWatch sw;
m_motorcontrol->MotorRun(MotorControl::MotorOption::ZZ_Forward);
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
bool b_clean_ = false;
while(sw.elapsed_s() < 5)
{
if(!is_jam())
{
b_clean_ = true;
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(700));
}
m_motorcontrol->MotorRun(MotorControl::MotorOption::ZZ_Stop);
if(is_sleeping || !is_usb_connect)
return;
if(is_motor_run == false && is_converopen() == false && is_jam() == false && m_ledcontrol->get_state() == HG_LedOption::HG_RED_ON || b_clean_)
{
m_ledcontrol->option(HG_WHITE_ON,0);
}
}
bool MotorManager::GetorSetSysClassValue(bool isGet,std::string path,bool value){
if(isGet)
{
FILE *fp = fopen(path.c_str(),"r");
if(fp != NULL)
{
fscanf(fp,"%d",&value);
fclose(fp);
return value;
}
return false;
}
else{
FILE *fp = fopen(path.c_str(),"w");
if(fp != NULL)
{
fprintf(fp,"%d",value);
fclose(fp);
return true;
}
return false;
}
}

View File

@ -1,72 +0,0 @@
#pragma once
#include "Imotorboard.h"
#include "autoevent.hpp"
const std::string HG_PWM_FAN = "/sys/class/fv_en_class/fv_en/pwm_fan";
const std::string HG_MOTOR_FAN = "/sys/class/fv_en_class/fv_en/motor_fan";
class MotorControl;
class SensorMonitor;
class LedControl;
enum HG_LedOption : uint8_t;
class MotorManager : public IMotorBoard
{
public:
MotorManager();
virtual ~MotorManager();
void start() override;
void stop() override;
void clear_error() override;
void pick_paper() override;
void stop_pick_paper() override;
int os_mode() override;
bool paper_ready() override;
bool is_converopen() override;
bool is_scanning() override;
bool is_jam() override;
int paper_counter() override;
bool set_long_paper(bool enable) override;
bool set_double_inpect(bool enable) override;
bool set_staple_inpect(bool enable) override;
bool set_auto_paper(bool enable) override;
bool set_color_mode(int mode) override;
int get_speed_mode() override;
bool set_speed_mode(int mode,int dpi,int iscolor) override;
bool set_screw_inpect(bool enable) override;
bool get_screw_inpect() override;
bool set_screw_level(int level) override;
int get_screw_level() override;
bool wait_paper_out(int timeout_ms) override;
bool wait_paper_in(int timeout_ms) override;
bool read(unsigned int addr, unsigned int &val) override;
bool write(unsigned int addr, unsigned int val) override;
bool set_cuospeed(unsigned int speed,uint dpi,uint iscolor) override;
void set_callbacks(MotorBoardGlue glue) override;
bool get_keeplastpaper() override;
std::shared_ptr<IRegsAccess> regs() override;
void set_capture(std::shared_ptr<ICapturer> cap) override;
void motor_reset() override;
bool GetOrSetUsbConnectFlag(bool isGet,bool value);
bool GetOrSetSleepFlag(bool isGet,bool value);
void LedControlOption(HG_LedOption option,uint32_t time) override;
void clean_paper_road() override;
private:
void pincall(int value);
bool GetorSetSysClassValue(bool isGet,std::string path,bool value);
std::unique_ptr<MotorControl> m_motorcontrol;
std::unique_ptr<SensorMonitor> m_sensormonitor;
std::unique_ptr<LedControl> m_ledcontrol;
MotorBoardGlue m_glue;
volatile bool is_usb_connect;
volatile bool is_sleeping;
volatile bool is_autopaper;
volatile bool is_motor_run;
volatile bool autopaper_state_change;
std::shared_ptr<ICapturer> m_cap;
ThreadPool autopaperthread;
AutoSemaphore cv_paperin;
AutoSemaphore cv_paperout;
std::future<void> f_motorreset;
std::chrono::steady_clock::time_point m_papperout_time;
};

View File

@ -0,0 +1,142 @@
/*******************************************************************
* Copyright (c) 2011 -2021 Anlogic Inc.
* The Software is distributed in source code form and is open to
* re-distribution and modification where applicable
*******************************************************************/
#ifndef OPCODE_H
#define OPCODE_H
#define AJE_DEBUG
// SVF OpCode
#define UNKNOWN 0x00
#define TRST 0x01
#define ON 0x02
#define OFF 0x03
#define STATE 0x04
#define ENDIR 0x05
#define ENDDR 0x06
#define FREQUENCY 0x07
#define HZ 0x08
#define TDR 0x09
#define TIR 0x0A
#define HDR 0x0B
#define HIR 0x0C
#define SDR 0x0D
#define SIR 0x0E
#define TDI 0x0F
#define TDO 0x10
#define MASK 0x11
#define SMASK 0x12
#define RUNTEST 0x13
#define TCK 0x14
#define ENDCMD 0x15
#define LEFTPAREN 0x16
#define CONTINUE 0x17
#define WAIT 0x18
#define XSDR 0x19
#define XTDI 0x1A
#define XTDO 0x1B
#define RSDR 0x1C /* It means two SDRs and TDI data of second SDR is the same as TDO of first SDR */
#define HEADER 0x20 /* Add the specified header to AJE file */
#define COMMENT 0x21 /* Write comments in SVF file into AJE file */
#define SETFLOW 0x22 /* Change the flow control register. */
#define RESETFLOW 0x23 /* Clear the flow control register. */
#define LOOP 0x24
#define ENDLOOP 0x25
// Header
#define FILECRC 0x61
#define MEM 0x62 // The maximum memory needed to allocate in order hold one row of data.
#define ENDFILE 0x7F // End of the file
#define BEGINLINE 0x5E // Begining of line
#define ENDLINE 0x24 // End of line
// JTAG OpCode
#define RESET 0x00
#define IDLE 0x01
#define IRSHIFT 0x02
#define DRSHIFT 0x03
#define DRPAUSE 0x04
#define IRPAUSE 0x05
#define DRSELECT 0x06
#define IRSELECT 0x07
#define DRCAPTURE 0x08
#define IRCAPTURE 0x09
#define DREXIT1 0x10
#define IREXIT1 0x11
#define DREXIT2 0x12
#define IREXIT2 0x13
#define DRUPDATE 0x14
#define IRUPDATE 0x15
// Flow control register bit definitions.
// A set bit indicates that the register currently exhibits the corresponding mode.
#define INTEL_PRGM 0x0001 /* Intelligent programming is in effect. */
#define CASCADE 0x0002 /* Currently splitting large SDR. */
#define REPEATLOOP 0x0008 /* Currently executing a repeat loop. */
#define SHIFTRIGHT 0x0080 /* The next data stream needs a right shift. */
#define SHIFTLEFT 0x0100 /* The next data stream needs a left shift. */
#define VERIFYUES 0x0200 /* Continue if fail is in effect. */
// Vendor Code
#define VENDOR 0x56
#define ANLOGIC 0x01
#define XILINX 0x02
#define ALTERA 0x03
#define LATTICE 0x04
// Mode Code
#define COMP_MODE 0xF1 // compress mode
#define FULL_MODE 0xF2 // full mode
// SIR Command
#define BYPASS 0xFF
#define SAMPLE 0x05
#define IDCODE_PUB 0x06
#define IDCODE_PUB_2 0xE0
// Reading IO Status
#define LINE_MAX_SIZE 1000 /* max size of a line when reading svf file */
#define DATA_MAX_SIZE 300 /* max size of tdi/tdo/mask hex str in svf file */
// return type
#define AJE_OK 0
#define AJE_WARNING -1
#define AJE_ERROR -2
#define AJE_FILE_OPEN_FAIL -6
#define AJE_FILE_INVALID -7
#define AJE_INVALID_COMMAND -10
#define AJE_INVALID_VALUE -11
#define AJE_INVALID_TAP_STATE -12
#define AJE_TRANSFER_FAIL -16
#define AJE_VERIFY_FAIL -17
/* TAP STATE Enumerate */
enum TAP_STATE {
TAP_RESET = 0, /* Initialization state */
TAP_IDLE = 1,
TAP_DRSELECT = 2, /* DR STATE: 2~8 */
TAP_DRCAPTURE = 3,
TAP_DRSHIFT = 4,
TAP_DREXIT1 = 5,
TAP_DRPAUSE = 6,
TAP_DREXIT2 = 7,
TAP_DRUPDATE = 8,
TAP_IRSELECT = 9, /* IR STATE: 9~15 */
TAP_IRCAPTURE = 10,
TAP_IRSHIFT = 11,
TAP_IREXIT1 = 12,
TAP_IRPAUSE = 13,
TAP_IREXIT2 = 14,
TAP_IRUPDATE = 15,
};
#endif // OPCODE_H

View File

@ -1,127 +0,0 @@
#include "sensormonitor.h"
#include <iostream>
#include <poll.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/epoll.h>
#include <thread>
#include <iostream>
#include <errno.h>
#include <stdlib.h>
SensorMonitor::SensorMonitor(std::function<void(int)> callback):m_callback(callback),
_C6(54),//扫描传感器
_A4(36),//有无纸传感器
_C7(55),//开盖传感器
Double_out0(137)//超声波传感器
{
_C6.setDirection(Gpio::in);
_A4.setDirection(Gpio::in);
_C7.setDirection(Gpio::in);
Double_out0.setDirection(Gpio::in);
_C7.setEdge(Gpio::both);
_A4.setEdge(Gpio::both);
_C6.setEdge(Gpio::both);
Double_out0.setEdge(Gpio::rising);
is_paperon = _A4.getValue() == Gpio::GpioLevel::High ? false : true;
is_converopen = _C7.getValue() == Gpio::GpioLevel::High ? false : true;
is_jam = _C6.getValue() == Gpio::GpioLevel::High? true : false;
b_monitor = true;
m_monitor = std::thread(&SensorMonitor::monitor,this);
}
SensorMonitor::~SensorMonitor()
{
b_monitor =false;
if(m_monitor.joinable())
m_monitor.join();
}
bool SensorMonitor::Is_PaperOn()
{
return is_paperon;
}
bool SensorMonitor::Is_ConverOpen()
{
return is_converopen;
}
bool SensorMonitor::Is_Jam()
{
return is_jam;
}
void SensorMonitor::monitor(){
pollfd fds[4]{};
fds[0].fd = open(_C6.getValuePath().c_str(),O_RDONLY);
fds[1].fd = open(_A4.getValuePath().c_str(),O_RDONLY);
fds[2].fd = open(_C7.getValuePath().c_str(),O_RDONLY);
fds[3].fd = open(Double_out0.getValuePath().c_str(),O_RDONLY);
int ret=0;
char buf[8]{};
int num =0;
num = read(fds[0].fd, buf, 8);
num = read(fds[1].fd, buf, 8);
num = read(fds[2].fd, buf, 8);
num = read(fds[3].fd, buf, 8);
while(b_monitor)
{
ret = poll(fds,4,1000);
if(ret>0)
{
if(fds[0].revents)
{
if(ret = readfile(fds[0].fd,num,buf)){
if(m_callback)
m_callback(true);
is_jam = true;
}
else{
if(m_callback)
m_callback(false);
is_jam = false;
}
printf("\n 扫描传感器 %d ",ret);
}
if(fds[1].revents)
{
if(readfile(fds[1].fd,num,buf)){
is_paperon = false;
m_callback(2);
}
else{
is_paperon = true;
m_callback(0x2000000);
}
printf("\n 有无纸传感器 %d ",!is_paperon);
}
if(fds[2].revents)
{
if(readfile(fds[2].fd,num,buf)){
is_converopen = false;
m_callback(0x4000000);
}
else{
is_converopen = true;
m_callback(4);
}
printf("\n 开盖传感器 %d ",!is_converopen);
}
if(fds[3].revents)
{
if(ret = readfile(fds[3].fd,num,buf)){
m_callback(0x20);
}
printf("\n 双张 %d ",ret);
}
}
}
}
int SensorMonitor::readfile(int fd,int num , char* buf){
lseek(fd, 0, SEEK_SET);
num = read(fd, buf, 8);
buf[num - 1] = '\0';
return atoi(buf);
}

View File

@ -1,29 +0,0 @@
#pragma once
#include "Gpio.h"
#include <thread>
#include <condition_variable>
#include <functional>
class SensorMonitor
{
public:
SensorMonitor(std::function<void(int)> callback);
~SensorMonitor();
bool Is_PaperOn();
bool Is_ConverOpen();
bool Is_Jam();
private:
void monitor();
int readfile(int fd,int num , char* buf);
Gpio _C6;
Gpio _A4;
Gpio _C7;
Gpio Double_out0;
std::thread m_monitor;
std::function<void(int)> m_callback;
volatile bool b_monitor;
volatile bool is_converopen;
volatile bool is_paperon;
volatile bool is_jam;
};

View File

@ -0,0 +1,521 @@
/*******************************************************************
* Copyright (c) 2011 -2021 Anlogic Inc.
* This file is strictly confidential. All rights reserved.
*******************************************************************/
/***********************************************************************
Filename: vec.c
Description: generate vec
Log: initial version, July 2019
***********************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "Jtag.h"
#include "opcode.h"
/* global variables about hdr/hir/tdr/tir */
unsigned int g_hdr_size = 0;
unsigned int g_hir_size = 0;
unsigned int g_tdr_size = 0;
unsigned int g_tir_size = 0;
unsigned char* g_hdr_data = NULL;
unsigned char* g_hir_data = NULL;
unsigned char* g_tdr_data = NULL;
unsigned char* g_tir_data = NULL;
static Jtag jtag_burning;
/* function declared in ajeutil.c */
extern int Anlogic_GetBit(unsigned char* data, int id);
extern void Anlogic_SetBit(unsigned char* data, int id, int val);
extern unsigned char Anlogic_ReverseChar(unsigned char byte);
/* Function forward declaration */
void Anlogic_WritePulseTck(void);
/* Tap Opcode To TAP_STATE */
enum TAP_STATE Anlogic_TapState(unsigned char opcode) {
enum TAP_STATE state = TAP_RESET;
switch (opcode) {
case RESET: state = TAP_RESET; break;
case IDLE: state = TAP_IDLE; break;
case DRSELECT: state = TAP_DRSELECT; break;
case DRCAPTURE: state = TAP_DRCAPTURE; break;
case DRSHIFT: state = TAP_DRSHIFT; break;
case DREXIT1: state = TAP_DREXIT1; break;
case DRPAUSE: state = TAP_DRPAUSE; break;
case DREXIT2: state = TAP_DREXIT2; break;
case DRUPDATE: state = TAP_DRUPDATE; break;
case IRSELECT: state = TAP_IRSELECT; break;
case IRCAPTURE: state = TAP_IRCAPTURE; break;
case IRSHIFT: state = TAP_IRSHIFT; break;
case IREXIT1: state = TAP_IREXIT1; break;
case IRPAUSE: state = TAP_IRPAUSE; break;
case IREXIT2: state = TAP_IREXIT2; break;
case IRUPDATE: state = TAP_IRUPDATE; break;
default:
printf("Error: Illegal tap state opcode %u\n", (unsigned int)opcode);
}
return state;
}
/* TAP_STATE to TapState String */
const char* Anlogic_TapState2Str(enum TAP_STATE tap_state) {
#define X(_w) if (tap_state == TAP_ ## _w) return #_w
X(RESET);
X(IDLE);
X(DRSELECT);
X(DRCAPTURE);
X(DRSHIFT);
X(DREXIT1);
X(DRPAUSE);
X(DREXIT2);
X(DRUPDATE);
X(IRSELECT);
X(IRCAPTURE);
X(IRSHIFT);
X(IREXIT1);
X(IRPAUSE);
X(IREXIT2);
X(IRUPDATE);
#undef X
return "TapState2Str: unkown state";
}
static enum TAP_STATE cur_tap_state = TAP_RESET; /* current tap state */
static enum TAP_STATE end_dr_state = TAP_IDLE; /* the tap state that device goes after sdr */
static enum TAP_STATE end_ir_state = TAP_IDLE; /* the tap state that device goes after sir */
/* Tap State Transistions */
int Anlogic_TapTransist(enum TAP_STATE state) {
int id = 0;
int count = 0;
// printf("Anlogic_TapTransist start...\n");
if (cur_tap_state == state && state == TAP_RESET) {
for (id = 0; id < 6; ++id) {
jtag_burning.TMS_Wr(1);
Anlogic_WritePulseTck();
}
// printf("Anlogic_TapTransist 107 end...\n");
return 0;
}
while (cur_tap_state != state) {
switch (cur_tap_state) {
case TAP_RESET:
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IDLE;
break;
case TAP_IDLE:
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DRSELECT;
break;
/* DR STATE Transistion */
case TAP_DRSELECT:
if (state >= TAP_IRSELECT || state == TAP_RESET) {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IRSELECT;
} else {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_DRCAPTURE;
}
break;
case TAP_DRCAPTURE:
if (state == TAP_DRSHIFT) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_DRSHIFT;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DREXIT1;
}
break;
case TAP_DRSHIFT:
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DREXIT1;
break;
case TAP_DREXIT1:
if (state == TAP_DRPAUSE) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_DRPAUSE;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DRUPDATE;
}
break;
case TAP_DRPAUSE:
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DREXIT2;
break;
case TAP_DREXIT2:
if (state == TAP_DRSHIFT) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_DRSHIFT;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DRUPDATE;
}
break;
case TAP_DRUPDATE:
if (state == TAP_IDLE) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IDLE;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_DRSELECT;
}
break;
/* IR STATE Transistion */
case TAP_IRSELECT:
if (state == TAP_RESET) {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_RESET;
} else {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IRCAPTURE;
}
break;
case TAP_IRCAPTURE:
if (state == TAP_IRSHIFT) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IRSHIFT;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IREXIT1;
}
break;
case TAP_IRSHIFT:
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IREXIT1;
break;
case TAP_IREXIT1:
if (state == TAP_IRPAUSE) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IRPAUSE;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IRUPDATE;
}
break;
case TAP_IRPAUSE:
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IREXIT2;
break;
case TAP_IREXIT2:
if (state == TAP_IRSHIFT) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IRSHIFT;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IRUPDATE;
}
break;
case TAP_IRUPDATE:
if (state == TAP_IDLE) {
jtag_burning.TMS_Wr(0);
cur_tap_state = TAP_IDLE;
} else {
jtag_burning.TMS_Wr(1);
cur_tap_state = TAP_IRSELECT;
}
break;
default:
printf("Error: invalid tap sate.\n");
return -1;
}
Anlogic_WritePulseTck();
if (++count > 10) {
printf("Error: Loop in Tap Transistion.");
return -1;
}
}
jtag_burning.TDI_Wr(0);
// printf("Anlogic_TapTransist 240 end...\n");
return 0;
}
/* Init function, set current tap state to reset */
void Anlogic_Init(void) {
cur_tap_state = TAP_RESET;
Anlogic_TapTransist(TAP_RESET);
}
/* set the tap state that deevice goes after sdr */
void Anlogic_SetEndDRState(enum TAP_STATE end_st) {
end_dr_state = end_st;
#ifdef AJE_DEBUG
printf("ENDDR %s;\n", Anlogic_TapState2Str(end_st));
#endif
}
/* set the tap state that deevice goes after sir */
void Anlogic_SetEndIRState(enum TAP_STATE end_st) {
end_ir_state = end_st;
#ifdef AJE_DEBUG
printf("ENDIR %s;\n", Anlogic_TapState2Str(end_st));
#endif
}
/* Send HIR/HDR/TIR/TDR data to device */
void Anlogic_SendBypassData(unsigned int op_code) {
unsigned char* data = NULL;
unsigned int size = 0;
unsigned int index = 0;
unsigned int bit = 0;
switch (op_code) {
case HIR: size = g_hir_size; data = g_hir_data; break;
case HDR: size = g_hdr_size; data = g_hdr_data; break;
case TIR: size = g_tir_size; data = g_tir_data; break;
case TDR: size = g_tdr_size; data = g_tdr_data; break;
default: break;
}
/* no value set, use default */
if (data == NULL) {
bit = (op_code == HIR || op_code == TIR) ? 1 : 0;
}
for (index = 0; index < size-1; ++index) {
if (data != NULL) {
bit = Anlogic_GetBit(data, index);
}
jtag_burning.TDI_Wr(bit);
Anlogic_WritePulseTck();
}
bit = Anlogic_GetBit(data, index);
jtag_burning.TDI_Wr(bit);
}
/* Send TDI data to device */
int Anlogic_SendData(unsigned char* tdi_data, unsigned int bin_size, int cascade) {
unsigned int index = 0;
unsigned int bit = 0;
for (index = 0; index < bin_size-1; ++index) {
bit = Anlogic_GetBit(tdi_data, index);
jtag_burning.TDI_Wr(bit);
Anlogic_WritePulseTck();
}
bit = Anlogic_GetBit(tdi_data, index);
jtag_burning.TDI_Wr(bit);
if (cascade == 1) {
Anlogic_WritePulseTck();
}
return 0;
}
/* Send TDI data and read TDO, Verify */
int Anlogic_ReadData(unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask, unsigned int data_size, int cascade) {
unsigned int index = 0;
int tdi_bit = 0;
int tdo_bit = 0;
int mask_bit = 0;
for (index = 0; index < data_size-1; ++index) {
tdi_bit = Anlogic_GetBit(tdi_data, index);
tdo_bit = Anlogic_GetBit(tdo_data, index);
mask_bit = Anlogic_GetBit(mask, index);
if (mask_bit == 1 && tdo_bit != jtag_burning.TDO_RD()) {
return AJE_VERIFY_FAIL;
}
jtag_burning.TDI_Wr(tdi_bit);
Anlogic_WritePulseTck();
}
tdi_bit = Anlogic_GetBit(tdi_data, index);
tdo_bit = Anlogic_GetBit(tdo_data, index);
mask_bit = Anlogic_GetBit(mask, index);
if (mask_bit == 1 && tdo_bit != jtag_burning.TDO_RD()) {
return AJE_VERIFY_FAIL;
}
jtag_burning.TDI_Wr(tdi_bit);
if (cascade == 1) {
Anlogic_WritePulseTck();
}
return AJE_OK;
}
/* Send TDI Data and Save TDO */
int Anlogic_SaveData(unsigned char* tdi_data, unsigned int data_size, unsigned char** tdo_data) {
unsigned int index = 0;
unsigned int tdi_bit = 0;
unsigned int tdo_bit = 0;
for (index = 0; index < data_size-1; ++index) {
tdo_bit = jtag_burning.TDO_RD();
Anlogic_SetBit(*tdo_data, index, tdo_bit);
tdi_bit = Anlogic_GetBit(tdi_data, index);
jtag_burning.TDI_Wr(tdi_bit);
Anlogic_WritePulseTck();
}
tdo_bit = jtag_burning.TDO_RD();
Anlogic_SetBit(*tdo_data, index, tdo_bit);
tdi_bit = Anlogic_GetBit(tdi_data, index);
jtag_burning.TDI_Wr(tdi_bit);
return AJE_OK;
}
/* Process SIR/SDR */
int Anlogic_ProcessShiftCmd(unsigned int op_code, unsigned int cascade, unsigned int read, unsigned int data_size,
unsigned char* tdi_data, unsigned char* tdo_data, unsigned char* mask) {
int rtn_val = AJE_OK;
// process header data
switch (op_code) {
case SIR:
if (cascade != 1) {
Anlogic_TapTransist(TAP_IRSHIFT);
if (g_hir_size > 0) {
Anlogic_SendBypassData(HIR);
Anlogic_WritePulseTck();
}
}
break;
case SDR:
if (cascade != 1) {
Anlogic_TapTransist(TAP_DRSHIFT);
if (g_hdr_size > 0) {
Anlogic_SendBypassData(HDR);
Anlogic_WritePulseTck();
}
}
break;
default:
break;
}
if (read == 1) {
rtn_val =Anlogic_SaveData(tdi_data, data_size, &tdo_data);
} else if (mask == NULL) {
rtn_val =Anlogic_SendData(tdi_data, data_size, cascade);
} else {
rtn_val =Anlogic_ReadData(tdi_data, tdo_data, mask, data_size, cascade);
}
// process tailer data
switch (op_code) {
case SIR:
if (cascade != 1) {
if (g_tir_size > 0) {
Anlogic_WritePulseTck();
Anlogic_SendBypassData(TIR);
}
Anlogic_TapTransist(end_ir_state);
}
break;
case SDR:
if (cascade != 1) {
if (g_tdr_size > 0) {
Anlogic_WritePulseTck();
Anlogic_SendBypassData(TDR);
}
Anlogic_TapTransist(end_dr_state);
}
break;
default:
break;
}
return rtn_val;
}
/* process single sir command, do not use bypass data (hir/tir) */
int Anlogic_ExeSirCommand(unsigned char command, int cur_lvl, int total_lvl) {
int rtn_val = AJE_OK;
unsigned char* tdi_data = NULL;
int id = 0;
Anlogic_TapTransist(TAP_IRSHIFT);
tdi_data = (unsigned char*)calloc((total_lvl*8+1), sizeof(unsigned char));
for(id = 0; id < total_lvl; ++id) {
if (id == (total_lvl - cur_lvl)) {
tdi_data[id] = Anlogic_ReverseChar(command);
} else {
tdi_data[id] = 0xFF;
}
}
rtn_val = Anlogic_SendData(tdi_data, total_lvl*8, 0 /*cascade*/);
Anlogic_TapTransist(end_ir_state);
return rtn_val;
}
/* process sdr command, do not use bypass data (hdr/tdr) */
int Anlogic_ExeSdrCommand(unsigned int bit_size, int cur_lvl, int total_lvl,
unsigned char* tdi_data, unsigned char* tdo_data) {
int rtn_val = AJE_OK;
int head_num = total_lvl - cur_lvl;
int tailer_num = cur_lvl-1;
int id = 0;
unsigned int byte_size = (bit_size + 7)/8;
Anlogic_TapTransist(TAP_DRSHIFT);
if (head_num > 0) {
for (id = 0; id < head_num; ++id) {
jtag_burning.TDI_Wr(0);
Anlogic_WritePulseTck();
}
}
if (tdi_data == NULL) {
tdi_data = (unsigned char*)calloc((byte_size+1), sizeof(unsigned char));
}
if (tdo_data == NULL) {
rtn_val = Anlogic_SendData(tdi_data, bit_size, 0 /*cascade*/);
} else { /* read and save tdo readback data */
rtn_val = Anlogic_SaveData(tdi_data, bit_size, &tdo_data /*cascade*/);
}
if (tailer_num > 0) {
for (id = 0; id < tailer_num; ++id) {
Anlogic_WritePulseTck();
jtag_burning.TDI_Wr(0);
}
}
Anlogic_TapTransist(end_dr_state);
return rtn_val;
}
/* process runtest num tck */
void Anlogic_ProcessRunTestTck(int num) {
volatile int i = 0;
jtag_burning.TDI_Wr(0);
jtag_burning.TMS_Wr(0);
for(i = 0; i < num; ++i) {
jtag_burning.TCK_Wr(1);
jtag_burning.TCK_Wr(0);
}
#ifdef AJE_DEBUG
printf("RUNTEST %d TCK;\n", num);
#endif
}
void Anlogic_WritePulseTck(void) {
static unsigned int i = 0;
jtag_burning.TCK_Wr(1);
jtag_burning.TCK_Wr(0);
}

View File

@ -4,6 +4,7 @@ target("motorboard")
set_kind("static")
add_syslinks("pthread")
add_files("*.cpp")
add_deps("regs", "motor_run" ,"deviceio", "conf", "applog", "capimage",{public = true})
add_deps("regs", "deviceio","motorcontroller","keymonitor" ,"conf", "applog", {public = true})
add_includedirs(".", { public = true})
add_includedirs("../scanner",{public = true})
add_packages("common")

View File

@ -0,0 +1,32 @@
#pragma once
#include <sstream>
#include <thread>
#include <memory>
#include <atomic>
#include <functional>
#include "Statedef.h"
#include "BlockingQueue.h"
#include "LCDDisplay.h"
class IState
{
public:
IState(/* args */){
display = std::make_unique<LCDDisplay>();
}
virtual ~IState(){}
virtual void InitState(int state=0) =0;
virtual IState* OnState(StateInfo state) = 0;
virtual void SetBtnCall(std::function<void()> call) = 0;
std::string typeName = "FsmState";
static void SetConfirmCall(std::function<void()> confirmcall)
{
m_confirmcall = confirmcall;
}
private:
static std::function<void()> m_confirmcall;
protected:
std::unique_ptr<LCDDisplay> display;
};

View File

@ -0,0 +1,51 @@
#include "Menu.h"
Menu::Menu(const char *const name,DisType dt) : name_(name)
{
}
Menu::~Menu()
{
std::cout << "Menu " << name_ << " destroyed" << std::endl;
for (auto &item : menu_items)
{
item.reset();
}
}
string Menu::get_name()
{
return name_;
}
int Menu::select()
{
int ret = -1;
int choice;
int count = 0;
for (auto &item : menu_items)
{
std::cout << item->get_name() << " : " << count++ << std::endl;
}
if (choice >= 0 && choice <= menu_items.size())
{
ret = menu_items[choice]->select();
// if(!ret)
// g_call();
}
count = 0;
choice = 0;
return ret;
}
void Menu::add_menu_item(unique_ptr<Selectable> menu_item)
{
menu_items.push_back(std::move(menu_item));
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Selectable.h"
class Menu : public Selectable
{
private:
std::string name_;
vector<unique_ptr<Selectable>> menu_items;
public:
Menu(const char *const name,DisType dt);
virtual ~Menu();
virtual string get_name() override;
virtual int select() override;
void add_menu_item(unique_ptr<Selectable> menu_item);
};

View File

@ -0,0 +1,135 @@
#include "MenuComponent.h"
#include "Menu.h"
#include "Menu_Item.h"
#include "commondef.h"
MenuComponent::MenuComponent()
{
if (!m_menu.get())
m_menu.reset(new Menu("Menu",DisType::Dis_Idel));
current_distype = DisType::Dis_Idel;
cur_index = 0;
}
MenuComponent::~MenuComponent()
{
if (m_menu.get())
m_menu.reset();
}
void MenuComponent::initmenu()
{
m_keytable.push_back({0,0,1,DisType::Dis_Idel}); //0
m_keytable.push_back({6,2,0,DisType::Dis_Set_ClearPaperPass}); //1
m_keytable.push_back({1,3,7,DisType::Dis_Set_PollPaperIntensity}); //2
#ifdef G200
m_keytable.push_back({2,4,11,DisType::Dis_Set_SleepMode}); //3
m_keytable.push_back({3,5,20,DisType::Dis_Set_TrayPosition}); //4
m_keytable.push_back({4,6,0,DisType::Dis_Set_Poweroff}); //5
#else
m_keytable.push_back({2,5,11,DisType::Dis_Set_SleepMode}); //3
m_keytable.push_back({3,5,20,DisType::Dis_Set_TrayPosition}); //4
m_keytable.push_back({3,6,0,DisType::Dis_Set_Poweroff}); //5
#endif
m_keytable.push_back({5,1,0,DisType::Dis_Set_Return});//6
m_keytable.push_back({10,8,2,DisType::Dis_Set_PollPI_High}); //7
m_keytable.push_back({7,9,2,DisType::Dis_Set_PollPI_Mid}); //8
m_keytable.push_back({8,10,2,DisType::Dis_Set_PollPI_Low}); //9
m_keytable.push_back({9,7,2,DisType::Dis_Set_Item_Return}); //10
m_keytable.push_back({19,12,3,DisType::Dis_Set_SleepMode_5M}); //11
m_keytable.push_back({11,13,3,DisType::Dis_Set_SleepMode_10M}); //12
m_keytable.push_back({12,14,3,DisType::Dis_Set_SleepMode_20M}); //13
m_keytable.push_back({13,15,3,DisType::Dis_Set_SleepMode_30M}); //14
m_keytable.push_back({14,16,3,DisType::Dis_Set_SleepMode_1H}); //15
m_keytable.push_back({15,17,3,DisType::Dis_Set_SleepMode_2H}); //16
m_keytable.push_back({16,18,3,DisType::Dis_Set_SleepMode_4H}); //17
m_keytable.push_back({17,19,3,DisType::Dis_Set_SleepMode_NEVER}); //18
m_keytable.push_back({18,11,3,DisType::Dis_Set_Item_Return});//19
m_keytable.push_back({23,21,4,DisType::Dis_Set_TrayPosition_High}); //20
m_keytable.push_back({20,22,4,DisType::Dis_Set_TrayPosition_Mid}); //21
m_keytable.push_back({21,23,4,DisType::Dis_Set_TrayPosition_Low});//22
m_keytable.push_back({22,20,4,DisType::Dis_Set_Item_Return});//23
// if (m_menu.get())
// {
// unique_ptr<Menu_Item> menu_clearpass = std::make_unique<Menu_Item>("clearpass",DisType::Dis_Set_ClearPaperPass);
// m_menu->add_menu_item(std::move(menu_clearpass));
// unique_ptr<Menu> submenu_feedstrength = std::make_unique<Menu>("feedstrenth",DisType::Dis_Set_PollPaperIntensity);
// std::unique_ptr<Menu_Item> feeditemH = std::make_unique<Menu_Item>("feedhigh",DisType::Dis_Set_PollPI_High);
// std::unique_ptr<Menu_Item> feeditemM = std::make_unique<Menu_Item>("feedmid",DisType::Dis_Set_PollPI_Mid);
// std::unique_ptr<Menu_Item> feeditemL = std::make_unique<Menu_Item>("feedlow",DisType::Dis_Set_PollPI_Low);
// submenu_feedstrength->add_menu_item(std::move(feeditemH));
// submenu_feedstrength->add_menu_item(std::move(feeditemM));
// submenu_feedstrength->add_menu_item(std::move(feeditemL));
// m_menu->add_menu_item(std::move(submenu_feedstrength));
// unique_ptr<Menu> submenu_sleep = std::make_unique<Menu>("sleepset",DisType::Dis_Set_SleepMode);
// std::unique_ptr<Menu_Item> sleep30 = std::make_unique<Menu_Item>("30min",DisType::Dis_Set_SleepMode_30M);
// std::unique_ptr<Menu_Item> sleep60 = std::make_unique<Menu_Item>("60min",DisType::Dis_Set_SleepMode_1H);
// std::unique_ptr<Menu_Item> sleep120 = std::make_unique<Menu_Item>("120min",DisType::Dis_Set_SleepMode_2H);
// std::unique_ptr<Menu_Item> sleepnever = std::make_unique<Menu_Item>("never",DisType::Dis_Set_SleepMode_NEVER);
// submenu_sleep->add_menu_item(std::move(sleep30));
// submenu_sleep->add_menu_item(std::move(sleep60));
// submenu_sleep->add_menu_item(std::move(sleep120));
// submenu_sleep->add_menu_item(std::move(sleepnever));
// m_menu->add_menu_item(std::move(submenu_sleep));
// unique_ptr<Menu_Item> submenu_poweroff = std::make_unique<Menu_Item>("poweroff",DisType::Dis_Set_Poweroff);
// m_menu->add_menu_item(std::move(submenu_poweroff));
// }
}
void MenuComponent::select()
{
if (m_menu.get())
{
m_menu->select();
}
}
void MenuComponent::option(int key)
{
switch (key)
{
#ifdef G200
case 85: //Key_Menu
cur_index = m_keytable[cur_index].enter;
break;
case 86: //Key_Left
cur_index = m_keytable[cur_index].up;
break;
case 76: //Key_Right
cur_index = m_keytable[cur_index].down;
break;
#else
case 76: //Key_Menu
cur_index = m_keytable[cur_index].enter;
break;
case 77: //Key_Right
cur_index = m_keytable[cur_index].down;
break;
#endif
default:
break;
}
}
DisType MenuComponent::getcurtype()
{
return m_keytable[cur_index].m_type;
}
void MenuComponent::setcurindex(int x)
{
if(x < 0 || x >= m_keytable.size())
return ;
cur_index = x;
printf("\n MenuComponent setcurindex %d",x);
}
int MenuComponent::getcurindex()
{
return cur_index;
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <memory>
#include "Displaydef.h"
class Menu;
class Menu_Item;
struct keypause{
int up;
int down;
int enter;
DisType m_type;
};
class MenuComponent
{
private:
/* data */
public:
MenuComponent(/* args */);
~MenuComponent();
void initmenu();
void select();
void option(int key);
DisType getcurtype();
void setcurindex(int x);
int getcurindex();
private:
std::shared_ptr<Menu> m_menu;
DisType current_distype;
std::vector<keypause> m_keytable;
int cur_index;
};

View File

@ -0,0 +1,24 @@
#include "Menu_Item.h"
Menu_Item::Menu_Item(const char *const name,DisType dt) : name_{name}
{
}
Menu_Item::~Menu_Item()
{
std::cout<<"Menu_Item Name "<<name_<<" destroyed "<<std::endl;
}
int Menu_Item::select()
{
std::cout<<"Menu_Item Name "<<name_<<"select "<<std::endl;
int status = -1;
return status;
}
string Menu_Item::get_name()
{
return name_;
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "Selectable.h"
class Menu_Item : public Selectable
{
private:
string name_;
public:
Menu_Item(const char *const name,DisType dt);
virtual ~Menu_Item();
virtual int select() override;
virtual string get_name() override;
};

View File

@ -0,0 +1,76 @@
#include "MotorController.h"
#include "Mt_Count.h"
#include "Mt_Error.h"
#include "Mt_Idel.h"
#include "Mt_Scan.h"
#include "Mt_Set.h"
#include "Mt_Welcome.h"
#include "applog.h"
#include "keymonitor.h"
static const std::string loggername = "motorcontroller";
using namespace std;
MotorController::MotorController():
m_bloop(false)
{
LOG_INIT();
m_threadmsgloop = make_shared<thread>(&MotorController::runloop,this);
auto keycall=[&](int key)
{
auto iter = m_keystats.find((HgBtn)key);
if(iter!=m_keystats.end())
{
m_msg.Put(iter->second);
}
};
m_keyMinitor= make_shared<KeyMonitor>(keycall);
}
MotorController::~MotorController()
{
if(m_threadmsgloop.get() && m_threadmsgloop->joinable())
{
m_bloop = false;
m_threadmsgloop->join();
m_threadmsgloop.reset();
}
LOG_TRACE("MotorController ~ctor exit \n");
}
void MotorController::runloop()
{
m_bloop = true;
IState* mtstate = StateManager<Mt_Welcome>::GetState();
m_msg.Put({HGScannerStatus::Mode_Idel,0});
while (m_bloop)
{
auto msg = m_msg.Take();
printf("\n msg status = %d ",msg.status);
if(msg.status == HGScannerStatus::Mode_Scan_Start)
mtstate = StateManager<Mt_Scan>::GetState();
if(msg.status == HGScannerStatus::Mode_Count)
mtstate = StateManager<Mt_Count>::GetState(msg.value);
if(msg.status == HGScannerStatus::Mode_Set_Key_Manual)
mtstate = StateManager<Mt_Set>::GetState();
if(msg.status >= HGScannerStatus::Mode_Error_Jam && msg.status <= HGScannerStatus::Mode_Error_DogEar || msg.status == HGScannerStatus::Mode_Error_FeedError)
mtstate = StateManager<Mt_Error>::GetState((int)msg.status);
if(msg.status == HGScannerStatus::Mode_Idel)
mtstate = StateManager<Mt_Idel>::GetState();
//mtstate = mtstate->OnState(msg);
}
}
void MotorController::PutMsg(StateInfo mode)
{
m_msg.Put(mode);
}
void MotorController::SendMsg()
{
}

View File

@ -0,0 +1,36 @@
#pragma once
#include "StateManager.h"
#include "IState.h"
#include "BlockingQueue.h"
#include "keymonitor.h"
using HgBtn = KeyMonitor::HGKey;
class MotorController
{
public:
MotorController(/* args */);
~MotorController();
void PutMsg(StateInfo mode);
private:
void runloop();
void SendMsg();
void procmsg();
private:
std::atomic<bool> m_bloop;
BlockingQueue<StateInfo> m_msg;
std::shared_ptr<std::thread> m_threadmsgloop;
std::shared_ptr<KeyMonitor> m_keyMinitor;
const std::map<HgBtn,StateInfo> m_keystats={
{HgBtn::Key_Enter,{HGScannerStatus::Mode_Set_Key_Enter,0}},
{HgBtn::Key_Cancle,{HGScannerStatus::Mode_Set_Key_Back,0}},
{HgBtn::Key_Count,{HGScannerStatus::Mode_Set_Key_Count,0}},
{HgBtn::Key_Handle,{HGScannerStatus::Mode_Set_HandMode,0}},
{HgBtn::Key_DoubleFeed,{HGScannerStatus::Mode_Set_Key_EnDoubleFeed,0}},
{HgBtn::Key_Left,{HGScannerStatus::Mode_Set_Key_Left,0}},
{HgBtn::Key_Menu,{HGScannerStatus::Mode_Set_Key_Manual,0}},
{HgBtn::Key_Right,{HGScannerStatus::Mode_Set_Key_Right,0}},
{HgBtn::Key_Clear,{HGScannerStatus::Mode_Set_Key_ClearCount,0}}
};
};

Some files were not shown because too many files have changed in this diff Show More