252 lines
6.1 KiB
C++
252 lines
6.1 KiB
C++
#pragma once
|
|
#include <memory>
|
|
#include <functional>
|
|
#include "CuoZhiMotor.h"
|
|
#include "ZouZhiMotor.h"
|
|
#include "Sensor.h"
|
|
#include "PanelLeds.h"
|
|
#include "BlockingQueue.h"
|
|
#include "FsmState.h"
|
|
|
|
|
|
#include "MultiFrameCapture.h"
|
|
#include "scanservices_utils.h"
|
|
#include "Keyboard.h"
|
|
#include "utilsfunc.h"
|
|
#include "filetools.h"
|
|
#include "SysInforTool.h"
|
|
#include "MotorConfig.h"
|
|
#include "correct_ultis.h"
|
|
#include "FpgaComm.h"
|
|
class ICapturer;
|
|
class MemoryInfo;
|
|
// class SysInforTool;
|
|
|
|
class Scanner
|
|
{
|
|
public:
|
|
Scanner(ScannerGlue glue);
|
|
~Scanner();
|
|
|
|
public:
|
|
bool isRested = false;
|
|
void startScan();
|
|
void emergency_stop(int id)
|
|
{
|
|
|
|
sensor->cancelWaitPaper();
|
|
m_DstScannum = 0;
|
|
if (id == 1) //双张
|
|
m_glue.m_deviceevent(16, "double feed");
|
|
|
|
motorCuozhi.stop();
|
|
motorZouzhi.stop();
|
|
//capturer->close();
|
|
put(S_EVT_SCAN_STOPPED);
|
|
SaveScaninfo(m_scaninfo);
|
|
start_enter_lowpwoer();
|
|
printf("emergency_stop capturer->close() \n");
|
|
|
|
|
|
//sensor->enableDoubleSensor(false);
|
|
}
|
|
|
|
void stop_scan()
|
|
{
|
|
printf("!!!!!!!!!!!!!!!!!!!!!stop_scan() waitting snap session done \n");
|
|
//sensor->enableDoubleSensor(false);
|
|
sensor->cancelWaitPaper();
|
|
m_DstScannum = 0;
|
|
//LOG("!!!!!!!!!!!!!!!!!!!!!!!!!!stop_scan() waitting snap session done \n");
|
|
if (threadRunScan.joinable())
|
|
threadRunScan.join();
|
|
motorZouzhi.stop();
|
|
motorCuozhi.stop();
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
//capturer->close();
|
|
put(S_EVT_SCAN_STOPPED);
|
|
SaveScaninfo(m_scaninfo);
|
|
start_enter_lowpwoer();
|
|
LOG("stop_scan() exit22222222 \n");
|
|
}
|
|
|
|
Sensor &getSensor() { return *sensor.get(); }
|
|
PanelLeds &getPanelLeds() { return panelLeds; }
|
|
int readreg(int addr) { return capturer->read(addr); }
|
|
void put(ScanEvent evt) { sysEvent.Put(evt); }
|
|
void reset()
|
|
{
|
|
if (!sensor->isPaperStandby())
|
|
{
|
|
motorCuozhi.reset();
|
|
isRested = true;
|
|
isPaperInit = false;
|
|
LOG("Scanner->motorCuozhi is reseted \n");
|
|
}
|
|
}
|
|
void paperReady()
|
|
{
|
|
LOG("paperReady 22222222 \n");
|
|
motorZouzhi.start();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
motorZouzhi.stop();
|
|
}
|
|
bool isFeederLoaded() { return sensor->isPaperStandby(); }
|
|
void ConfigScanParam(HG_ScanConfiguration config)
|
|
{
|
|
// if (config.params.dpi == 0)
|
|
// config.params.dpi = 1;
|
|
|
|
m_config = config;
|
|
LOG("m_config.params.dpi = %d \n \
|
|
m_config.params.isColor = %d \n \
|
|
m_config.params.pageSize = %d \n \
|
|
m_config.params.isCorrect = %d \n",
|
|
m_config.params.dpi,
|
|
m_config.params.isColor,
|
|
m_config.params.pageSize,
|
|
m_config.params.isCorrect);
|
|
capturer->UpdateScanParam(config);
|
|
}
|
|
|
|
void CreatCorrectData(int correctmode);
|
|
void SetDstScanNum(int scannum) { m_DstScannum = scannum; }
|
|
void paper_pullout()
|
|
{
|
|
LOG("paper_pullout 22222222 \n");
|
|
if (!m_isPulling)
|
|
m_isPulling = true;
|
|
|
|
motorCuozhi.stop();
|
|
motorZouzhi.speedChange(1);
|
|
motorZouzhi.setDirection(1);
|
|
motorZouzhi.start();
|
|
if (sensor->waitPaperOut(5000))
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
motorZouzhi.stop();
|
|
motorZouzhi.speedRecover();
|
|
m_isPulling = false;
|
|
}
|
|
|
|
void SetIsDoublePaper(bool isdoublepaper)
|
|
{
|
|
m_isDoublePaper = isdoublepaper;
|
|
}
|
|
|
|
bool GetIsDoublePaper()
|
|
{
|
|
return m_isDoublePaper;
|
|
}
|
|
|
|
bool GetIsJamPaper()
|
|
{
|
|
return m_jamPaper;
|
|
}
|
|
|
|
bool GetIsJamIn()
|
|
{
|
|
return m_jamIn;
|
|
}
|
|
|
|
void ResetJamIn()
|
|
{
|
|
m_jamIn = false;
|
|
}
|
|
bool IsScanning()
|
|
{
|
|
return !capturer->IsImageQueueEmpty();
|
|
}
|
|
|
|
void close_v4l2()
|
|
{
|
|
capturer->close();
|
|
}
|
|
|
|
void writeParamars(std::string type, int *value)
|
|
{
|
|
// capturer->m_configprop->writeParamars(type, value);
|
|
}
|
|
|
|
void UpdateScanInfo()
|
|
{
|
|
m_scaninfo = GetScanInfoFromJson();
|
|
MotorConfig::MTBDType smbtype = GetSMBType() == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC;
|
|
auto params = MotorConfig().GetMotorSpeedParams(true, smbtype);
|
|
for (int i = 0; i < params.size(); i++)
|
|
{
|
|
if (params[i].speed == m_scaninfo.SpeedMode)
|
|
{
|
|
// auto fpgaparam = GetFpgaparam(params[i].dpi, params[i].colormode);
|
|
// fpgaparam.Sp = params[i].sp;
|
|
// SaveFpgaparam(fpgaparam);
|
|
}
|
|
}
|
|
printf(" UpdateScanInfo speed mode = %d \n",m_scaninfo.SpeedMode);
|
|
updateSpeedMode(m_scaninfo.SpeedMode);
|
|
}
|
|
CaptureParams GetCaptureParams()
|
|
{
|
|
CaptureParams param;
|
|
return param;
|
|
// return capturer->m_configprop->captureParmars;
|
|
}
|
|
|
|
ScannerScanInfo &GetScanInfo()
|
|
{
|
|
return m_scaninfo;
|
|
}
|
|
void updateSpeedMode(int speed);
|
|
void ResetCorrectflags() { m_correctting = false; }
|
|
void StopScan(int Evt)
|
|
{
|
|
put(S_EVT_STOP_SCAN);
|
|
//capturer->clearimages();
|
|
//capturer->resetimageremain();
|
|
//m_glue.m_deviceevent(70, "Scan done");
|
|
}
|
|
std::string GetSysInfo();
|
|
|
|
ScannerSysInfo &GetSysinfoStruct() { return m_scansysinfo->GetInfo(); }
|
|
|
|
private:
|
|
//处理事件
|
|
void processevent(FsmState *fsmState, ScanEvent event);
|
|
void startZouzhi() { motorZouzhi.start(); }
|
|
void stopZouzhi() { motorZouzhi.stop(); }
|
|
void startCuozhi() { motorCuozhi.start(); }
|
|
void stopCuozhi() { motorCuozhi.stop(); }
|
|
//运行消息循环
|
|
void runMessageLoop();
|
|
void runScan();
|
|
void preFeed();
|
|
|
|
private:
|
|
ZouZhiMotor motorZouzhi;
|
|
CuoZhiMotor motorCuozhi;
|
|
std::shared_ptr<Sensor> sensor;
|
|
PanelLeds panelLeds;
|
|
std::thread threadRunScan;
|
|
std::thread threadRunMessageLoop;
|
|
volatile bool bMsgLoop = true;
|
|
BlockingQueue<ScanEvent> sysEvent;
|
|
std::shared_ptr<ICapturer> capturer;
|
|
std::shared_ptr<huagao::Keyboard> m_keyboard;
|
|
ScannerGlue m_glue;
|
|
HG_ScanConfiguration m_config;
|
|
ScannerScanInfo m_scaninfo;
|
|
std::thread m_correctThread;
|
|
volatile int m_DstScannum = 500;
|
|
bool m_isPulling;
|
|
volatile bool m_isDoublePaper;
|
|
volatile bool m_jamPaper;
|
|
volatile bool m_jamIn;
|
|
bool isPaperInit;
|
|
volatile bool m_correctting;
|
|
int waitpapertime;
|
|
MemoryInfo *meminfo;
|
|
CISVendor cisvendor;
|
|
std::shared_ptr<SysInforTool> m_scansysinfo;
|
|
std::shared_ptr<ICapturer> m_capturer;
|
|
std::shared_ptr<FpgaComm> m_fpga;
|
|
};
|