hlp:状态机初版,统一管理回收槽状态,启动和停止打印时的状态
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
#define PRINTERSTATEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QVector>
|
||||
#include "SysPara.h"
|
||||
|
||||
enum class PrinterState {
|
||||
IDLE, // 空闲
|
||||
SELF_CHECK, // 自检中
|
||||
SELF_CHECK, // 自检完成
|
||||
READY, // 就绪
|
||||
PRINTING, // 打印中
|
||||
STOPPING, // 停止中
|
||||
@@ -20,6 +21,7 @@ enum class PrinterEvent {
|
||||
PowerOn,
|
||||
SelfCheckDone,
|
||||
SelfCheckFailed,
|
||||
ReSelfCheck,
|
||||
StartPrint,
|
||||
StopPrint,
|
||||
StopComplete,
|
||||
@@ -52,10 +54,21 @@ public:
|
||||
// 外部唯一接口:请求切换状态
|
||||
void requestTransition(PrinterEvent event);
|
||||
|
||||
// 检查状态
|
||||
void checkReadyState();
|
||||
signals:
|
||||
// 状态变化信号(外部监听执行具体业务)
|
||||
void sig_stateChanged(PrinterState newState, PrinterState oldState, QString reason);
|
||||
|
||||
//使能开始和停止打印按钮
|
||||
void sig_enableStartPrint(bool);
|
||||
void sig_enableStopPrint(bool);
|
||||
//使能开关回收槽
|
||||
void sig_enableOpenTank(bool);
|
||||
void sig_enableCloseTank(bool);
|
||||
|
||||
// 更新回收槽状态
|
||||
void sig_updateReclaimStatus();
|
||||
private:
|
||||
PrinterStateManager();
|
||||
~PrinterStateManager();
|
||||
@@ -66,6 +79,9 @@ private:
|
||||
PrinterState m_currentState = PrinterState::IDLE;
|
||||
PrinterState m_previousState = PrinterState::IDLE;
|
||||
|
||||
QTimer* m_updateUITimer = NULL;
|
||||
void initTimer();
|
||||
|
||||
// 状态转移表
|
||||
// 守卫条件函数类型
|
||||
using GuardFunc = std::function<bool()>;
|
||||
@@ -80,6 +96,9 @@ private:
|
||||
|
||||
QVector<Transition> m_transitions;
|
||||
|
||||
// 记录上一次回收槽状态
|
||||
unsigned char lastState = 0;
|
||||
|
||||
void initTransitions();
|
||||
Transition* findTransition(PrinterEvent event);
|
||||
|
||||
@@ -88,7 +107,7 @@ private:
|
||||
|
||||
QString stateNameFromEnum(PrinterState state) const;
|
||||
|
||||
// ============ 守卫条件函数 ============
|
||||
// ============ guard 守卫条件函数 ============
|
||||
// 检查回收槽是否已打开
|
||||
bool guardReclaimTankOpen();
|
||||
|
||||
@@ -110,5 +129,7 @@ private:
|
||||
// 检查是否满足所有打印条件
|
||||
bool guardCanStartPrint();
|
||||
|
||||
private slots:
|
||||
void slt_timeout();
|
||||
};
|
||||
#endif // PRINTERSTATEMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user