pdu_ctrl.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef PDU_CTRL_H
  2. #define PDU_CTRL_H
  3. #include <QObject>
  4. #include <QMutex>
  5. #include <QGraphicsProxyWidget>
  6. #include <QGraphicsView>
  7. #include "widget.h"
  8. #define hightSmartPDU
  9. #define Language_Zh
  10. //#define RS485Type
  11. //#define RS485IpType
  12. enum WidgetType
  13. {
  14. widgetType_Main=0, //轮询页面
  15. widgetType_Setting=1, //设置页面
  16. };
  17. enum WidgetMain_T_AC
  18. {
  19. WidgetMain_CH=0, //三项总
  20. WidgetMain_PHA=1, //A相
  21. WidgetMain_PHB=2, //B相
  22. WidgetMain_PHC=3, //C相
  23. };
  24. enum SettingMode
  25. {
  26. settingMode_Modbus=0,
  27. settingMode_LimitV=1,
  28. settingMode_LimitA=2,
  29. settingMode_IP=3,
  30. };
  31. enum BtnDownType
  32. {
  33. BtnDown_C=0,//点击
  34. BtnDown_D=1, //双击
  35. BtnDown_L=2, //长按
  36. BtnDown_Null=-1//清空
  37. };
  38. enum GPIOLED
  39. {
  40. GPIO_LED0=106,
  41. GPIO_LED1=105,
  42. #ifdef RS485Type
  43. GPIO_KEY1=160,
  44. GPIO_KEY2=161,
  45. GPIO_KEY3=162,
  46. GPIO_KEY4=103,
  47. #endif
  48. #ifdef hightSmartPDU
  49. GPIO_KEY1=102,
  50. GPIO_KEY2=101,
  51. GPIO_KEY3=104,
  52. GPIO_KEY4=103,
  53. GPIO_X=113,//方向传感器
  54. GPIO_Y=115//方向传感器
  55. #endif
  56. };
  57. class pdu_Ctrl : public QObject
  58. {
  59. Q_OBJECT
  60. public:
  61. //单例初始化
  62. static pdu_Ctrl* instance() {
  63. QMutexLocker locker(&mutex);
  64. if (!m_instance) {
  65. static QMutex mutex;
  66. if (!m_instance) {
  67. m_instance = new pdu_Ctrl();
  68. }
  69. }
  70. return m_instance;
  71. }
  72. static void distory()
  73. {
  74. QMutexLocker locker(&mutex);
  75. if (m_instance) {
  76. delete m_instance;
  77. m_instance = nullptr;
  78. }
  79. }
  80. void InitData(Widget* pWidget,QGraphicsProxyWidget* pProxy ,QGraphicsView* pView,int nWidth, int nHeight);
  81. void ReadModbusInit();
  82. void SaveModbusInit();
  83. private:
  84. //处理多个点
  85. void ButtonDown(int nButtonID, BtnDownType nDownType);
  86. //===================MAIN界面下按钮控制============================
  87. void Main_UPBtnSet(BtnDownType nbtnType);
  88. void Main_FunBtnSet(BtnDownType nbtnType);
  89. void Main_DownBtnSet(BtnDownType nbtnType);
  90. //===================SETTING界面下按钮控制=========================
  91. void Setting_UPBtnSet(BtnDownType nbtnType);
  92. void Setting_FunBtnSet(BtnDownType nbtnType);
  93. void Setting_DownBtnSet(BtnDownType nbtnType);
  94. //======切换视图=========
  95. void ChangeView(WidgetType widgetType,int nIndex);
  96. //======恢复出厂设置=========
  97. void ResetAll();
  98. void RestartSys();
  99. signals:
  100. public slots:
  101. void slot_setAngel(int nAngle);
  102. void slot_ClickBtn(int nButton);
  103. void slot_DClickBtn(int nButton);
  104. void slot_LClickBtn(int nButton);
  105. void slot_BtnClear(int nButton);
  106. private:
  107. //单例数据
  108. explicit pdu_Ctrl(QObject *parent = nullptr);
  109. static pdu_Ctrl* m_instance;
  110. static QMutex mutex;
  111. WidgetType nViewShowType;//
  112. int nSettingType;//设置页面
  113. //记录三个按钮的状态
  114. int nButtonStatus[3];//上中下
  115. //当前显示页面ID
  116. int nChidIndex;
  117. int nChidPHIndex;
  118. int m_nAngle;
  119. //其他界面指针
  120. QGraphicsProxyWidget* m_pAngleCtrl;
  121. QGraphicsView* m_pView;
  122. Widget* m_pWidget;
  123. int m_nWidth;
  124. int m_nHeight;
  125. //modbus设置
  126. public:
  127. int m_nModbusSelect;
  128. int m_nModbusAddress;//从机地址
  129. int m_nModbusMSType;//主从
  130. int m_nSaveData;
  131. QString strSqliteAddress;
  132. int isT_ACType;
  133. int lastACIndex;
  134. };
  135. #endif // PDU_CTRL_H