add 增加流量和气压报警控制,串口屏关闭触摸屏
authorkyz <kongyuzhong@google.com>
Tue, 14 May 2024 07:10:06 +0000 (15:10 +0800)
committerkyz <kongyuzhong@google.com>
Fri, 17 May 2024 02:06:57 +0000 (10:06 +0800)
加流量和气压报警
串口屏更新,关触摸屏声音,第一屏不支持滑动
PC工具增加气路选择控制,增加报警阈值设置

50 files changed:
tools_v2/popup.py [new file with mode: 0644]
tools_v2/test.py
tools_v2/test.ui
tools_v2/yn_download.py
ui/48/485.jpg [deleted file]
ui/48/486.jpg [deleted file]
ui/48/487.jpg
ui/48/488.jpg
ui/48/600.jpg [new file with mode: 0644]
ui/48/601.jpg [new file with mode: 0644]
ui/48/602.jpg [new file with mode: 0644]
ui/48/603.jpg [new file with mode: 0644]
ui/48/700.jpg [new file with mode: 0644]
ui/48/701.jpg [new file with mode: 0644]
ui/DWIN_SET/10.png [new file with mode: 0644]
ui/DWIN_SET/13TouchFile.bin
ui/DWIN_SET/14ShowFile.bin
ui/DWIN_SET/22_Config.bin
ui/DWIN_SET/32.icl
ui/DWIN_SET/48.icl
ui/DWIN_SET/T5LCFG.CFG
ui/DWprj.hmi
ui/TFT/0.png.tft
ui/TFT/1.png.tft
ui/TFT/10.png.tft [new file with mode: 0644]
ui/TFT/2.png.tft
ui/TFT/20.jpg.tft
ui/TFT/21.jpg.tft
ui/TFT/22.jpg.tft
ui/TFT/23.jpg.tft
ui/TFT/3.png.tft
ui/TFT/4.png.tft
ui/TFT/5.png.tft
ui/TFT/6.png.tft
ui/TFT/7.png.tft
ui/raw/bg/10.png [new file with mode: 0644]
ui/raw/icon/485.png [deleted file]
ui/raw/icon/486.png [deleted file]
ui/raw/icon/600.png [new file with mode: 0644]
ui/raw/icon/601.png [new file with mode: 0644]
ui/raw/icon/602.png [new file with mode: 0644]
ui/raw/icon/603.png [new file with mode: 0644]
ui/raw/icon/700_bypass_off.png [new file with mode: 0644]
ui/raw/icon/701_pybass_on.png [new file with mode: 0644]
user/user.h
user/user_app.c
user/user_cdc_rx_2.c
user/user_flowmeter.c
user/user_ui.c
user/user_valve_ctrl.c

diff --git a/tools_v2/popup.py b/tools_v2/popup.py
new file mode 100644 (file)
index 0000000..83f918e
--- /dev/null
@@ -0,0 +1,94 @@
+# -*-  coding: utf-8 -*-
+ 
+#@author: daimashiren
+#@time:    2020/07/06
+from time import sleep
+from PyQt5.QtCore import  Qt,QRect,QPoint,QTimer
+from PyQt5.QtWidgets import QDialog,QLabel,QApplication,QHBoxLayout,QDesktopWidget
+ 
+ 
+class Msg(QDialog):
+    def __init__(self, master):
+        super(Msg, self).__init__()
+        self.master = master
+        self.ini_ui()
+  
+    def ini_ui(self):
+        self.setWindowModality(Qt.NonModal)
+        self.setWindowOpacity(0.8)  # 设置窗口透明度
+        self.setStyleSheet("""
+                QDialog{
+                border: none;
+                background:rgb(150,150,150,100);}
+                """)
+        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool)
+        win_center = QDesktopWidget().availableGeometry().center()
+        x = self.master.x()+self.master.width()/2
+        y = self.master.y()+self.master.height()/2
+        geo = QRect( x - 150, y- 50, 300, 100)
+        self.setGeometry(geo)
+        self.setContentsMargins(0, 0, 0, 0)
+        main_layout = QHBoxLayout()
+        self.setLayout(main_layout)
+        main_layout.setAlignment(Qt.AlignVCenter|Qt.AlignHCenter)
+        self.msg_label = QLabel()
+        self.msg_label.setStyleSheet("""
+        QLabel{
+            color:#7fccde;
+            text-align:left;
+            border:none;
+            border-image:none;
+            font-size:25px;
+            font-weight:300;
+            font-family: "黑体","Arial","Microsoft YaHei","宋体",sans-serif;
+        }
+        """)
+        main_layout.addWidget(self.msg_label)
+ 
+        self.fade_timer = QTimer()
+        self.fade_timer.setInterval(2000)
+        self.fade_timer.timeout.connect(self.faded_out)
+ 
+    # (中心展示)只能在show方法后调用
+    def center_show(self, offset):
+        geo = self.frameGeometry()
+        cp = QDesktopWidget().availableGeometry().center()  # 获取显示器分辨率,并找到中间点
+        if offset:
+            print("窗口偏置")
+            geo.moveCenter(cp + offset)  # 将窗口中点偏置
+        else:
+            geo.moveCenter(cp)  # 将窗口中点放在屏幕中间
+        self.move(geo.topLeft())
+ 
+    def show_msg(self,text):
+        self.fade_timer.start()
+        self.msg_label.setText(text)
+        self.msg_label.repaint()
+        self.raise_()
+        self.show()
+        self.center_show(QPoint(75,0))
+        self.exec_()  # 动画弹出
+        sleep(0.5)
+ 
+ 
+ 
+    def faded_out(self):
+        print("窗口渐隐")
+        for i in range(80,0,-1):
+            opacity = i/100
+            print("opacity:",opacity)
+            self.setWindowOpacity(opacity)  # 设置窗口透明度
+            self.repaint()
+            QApplication.processEvents()
+            sleep(0.05)
+ 
+        self.fade_timer.stop()
+        self.close()
+ 
+ 
+if __name__ == "__main__":
+    import sys
+    app = QApplication(sys.argv)
+    msg = Msg()
+    msg.show_msg("测试信息...")
+    sys.exit(app.exec_())
\ No newline at end of file
index 90bcd732f3fcaef0a8c40053184347199d448e55..f9e308725cd3dbc9e6760db440e2e5b07a6cac4d 100644 (file)
@@ -28,6 +28,8 @@ import struct
 import intelhex
 import yn_download
 import mk_ota_image
+import popup
+import serial
 
 #生成CRC16-MODBUS校验码
 #crc16 = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
@@ -37,20 +39,24 @@ gas_coefficient = [ (u'氩气(1000)',1000), (u'二氧化碳(570)', 570), (u'混
 
 class App( QDialog, ui_welding.Ui_Dialog ):
     trigger_rx_pkt = pyqtSignal( tuple )
+    trigger_ctrl_write = pyqtSignal( tuple )
     def __init__( self ):
         super().__init__()
         self.setupUi(self)
-        self.setWindowTitle( u"焊接控制器调试工具 V0.5")
+        self.setWindowTitle( u"焊接控制器调试工具 V0.6")
 
         self.trigger_rx_pkt.connect( self.on_rx_pkt )
+        self.trigger_ctrl_write.connect( self.on_ctrl_write_signal )
 
         self.ser_opened = False
         self.connected = 0 #0-disconnect 1-devinfo 2-curr 3-update
 
+        self.tabWidget.currentChanged.connect( self.on_tab_changed )
         self.btn_devinfo.released.connect( lambda:self.on_table_select(1) )
         self.btn_curr.released.connect( lambda:self.on_table_select(2) )
         self.btn_update.released.connect( lambda:self.on_table_select(3) )
         self.btn_cfg.released.connect( lambda:self.on_table_select(4) )
+        self.btn_ctrl.released.connect( lambda:self.on_table_select(5) )
         self.tabWidget.findChild( QTabBar).hide()
 
         self.btn_connect_devinfo.released.connect( lambda:self.on_btn_connect(1))
@@ -60,10 +66,14 @@ class App( QDialog, ui_welding.Ui_Dialog ):
 
         ###self.cbx_debug.release
         #self.cbx_debug.stateChanged.connect( lambda:self.on_cbx_debug() )
-        self.cb_debug_mode.currentIndexChanged.connect( self.on_cb_debug_mode )
+        self.cb_weld_curr_debug.stateChanged.connect( self.on_cb_weld_curr_debug )
+        #self.cb_debug_mode.currentIndexChanged.connect( self.on_cb_debug_mode )
         self.btn_debug_write.released.connect( self.on_btn_debug_write )
         self.debug_mode  = 0
-        self.on_cb_debug_mode(0)
+        self.on_cb_weld_curr_debug()
+
+        self.cfg_timer = QTimer()
+        self.cfg_timer.timeout.connect(self.on_cfg_timer)
 
         self.io_timer = QTimer()
         self.io_timer.timeout.connect(self.on_scan_timer)
@@ -103,6 +113,46 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         self.btn_gas_read.released.connect( self.on_btn_gas_read )
         self.btn_gas_write.released.connect( self.on_btn_gas_write )
 
+        self.btn_flow_alarm_read.released.connect( self.on_btn_alarm_read )
+        self.btn_flow_alarm_write.released.connect( self.on_btn_alarm_write )
+
+        self.btn_tig.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "tig" ) ))
+        self.btn_mig.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "mig" ) ))
+        self.btn_mag.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "mag" ) ))
+        self.btn_factor_add.released.connect( lambda: self.trigger_ctrl_write.emit(( "factor", "add" ) ))
+        self.btn_factor_sub.released.connect(  lambda: self.trigger_ctrl_write.emit(( "factor", "sub" ) ))
+        self.btn_prev_add.released.connect(  lambda: self.trigger_ctrl_write.emit(( "prev", "add" ) ))
+        self.btn_prev_sub.released.connect(  lambda: self.trigger_ctrl_write.emit(( "prev", "sub" ) ))
+        self.btn_bypass_on.released.connect( lambda: self.trigger_ctrl_write.emit(( "bypass", "on" ) ))
+        self.btn_bypass_off.released.connect( lambda: self.trigger_ctrl_write.emit(( "bypass", "off" ) ))
+
+    def on_ctrl_write_signal( self, cmd ):
+        if not self.ser_opened:
+            if not self.ser_open():
+                return
+
+        item, action = cmd
+        if item == "timer":
+            self.tx_cmd( cmd = 0x00B6, wait=False )
+        else:
+            #B6   read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存
+            method = factor = prev = comp = coeff = bypass_save = bypass = 0x7FFFFFFF
+            if item == "method" :
+                method = 0 if action == "tig" else  1 if action=="mig" else 2
+            elif item == "factor":
+                factor = int(self.label_factor.text())
+                factor += 1 if action == "add" else  -1 if action == "sub" else 0
+                factor =  100 if factor>100 else 0 if factor < 0 else factor
+            elif item == "prev":                    
+                prev = int(self.label_prev.text())
+                prev += 1 if action == "add" else  -1 if action == "sub" else 0
+                prev =  100 if prev>100 else 0 if prev < 0 else prev
+            elif item == "bypass":
+                bypass = 1 if action == "on" else  0 if action=="off" else bypass
+            else:
+                return
+            self.tx_cmd( cmd = 0x00B7, data=struct.pack( '>LLLlLLL', method, factor, prev, comp, coeff, bypass_save, bypass ), wait=False )
+
     def on_btn_mk_ota_img(self):
         file , check = QFileDialog.getOpenFileName(None, u"选择固件", "", "image (*hex *bin)")
         print("select fw file:{}, check:{}".format( file, check) )
@@ -114,13 +164,20 @@ class App( QDialog, ui_welding.Ui_Dialog ):
                 print( "save file:%s len:%d/%08X Bytes"%( save_name, len(img_data), len( img_data)))
                 ota_fd.write( img_data )
 
+    def on_btn_alarm_read( self ):
+        self.on_btn_gas_read()
+    def on_btn_alarm_write( self ):
+        if self.ser_open():
+            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", 0xFF, 0xFF, int( 1000*float(self.lineEdit_flow_low_alarm.text() ) ) ) )
+            self.ser_close()
+
     def on_btn_gas_read( self ):
         if self.ser_open():
             self.tx_cmd( cmd = 0xC0 )
             self.ser_close()
     def on_btn_gas_write( self ):
         if self.ser_open():
-            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BB", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex() ) )
+            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex(), 0xFFFFFFFF ) )
             self.ser_close()
 
     def on_btn_rpt_period_read( self ):
@@ -143,11 +200,14 @@ class App( QDialog, ui_welding.Ui_Dialog ):
             self.tx_cmd( cmd = 0x00BD, data=self.lineEdit_dev_sn.text().split()[0].encode("utf8") )
             self.ser_close()
 
+    def on_cfg_timer( self ):
+        self.trigger_ctrl_write.emit( ("timer", "read" ) )
+
     def on_btn_cfg_read( self, cfg ):
         if self.connected != 0 or self.ser_opened:
             return
         if cfg == 1 or cfg == 2:
-            #B6   read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B
+            #B6   read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypass_save 4B, bypass 4B
             cmd = 0x00B6
         elif cfg == 3:
             cmd = 0x00B8
@@ -164,26 +224,27 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         if cfg == 1:
             #B6   read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存
             cmd = 0x00B7
-            d = struct.pack( '>LLLlLL', 
+            d = struct.pack( '>LLLlLLL', 
                                #int(self.lineEdit_cfg_method.text()), 
                                self.cb_cfg_method.currentIndex(),
                                int(self.lineEdit_cfg_factor.text()), 
                                int(self.lineEdit_cfg_prev.text()), 
-                               100000, #填无效值
-                               100000,  #填无效值
-                               1 if self.cb_path_save.isChecked() else 0
+                               0x7FFFFFFF, #填无效值  comp
+                               0x7FFFFFFF,  #填无效值  coeff 修正系数
+                               1 if self.cb_path_save.isChecked() else 0,
+                               0x7FFFFFFF #填无效值 bypass
                                )
             print( "write cfg cmd:%04X"%cmd, d.hex())
         elif cfg == 2:
             cmd = 0x00B7
-            d = struct.pack( '>LLLlLL', 
-                               100000, #填无效值
-                               100000,  #填无效值
-                               100000, #填无效值
+            d = struct.pack( '>LLLlLLL', 
+                               0x7FFFFFFF, #填无效值
+                               0x7FFFFFFF,  #填无效值
+                               0x7FFFFFFF, #填无效值
                                int(self.lineEdit_flow_comp.text()), 
-                               #int(self.lineEdit_flow_coeff.text())
                                gas_coefficient[ self.cb_flow_coeff.currentIndex()][1],
-                               0xFFFFFFFF, #填无效值
+                               0x7FFFFFFF, #填无效值
+                               0x7FFFFFFF #填无效值
                                )
         elif cfg == 3:
             cmd = 0x00B9
@@ -320,18 +381,15 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         if self.ser_opened:
             print( "write cmd close debug_mode ")
             self.ser.write( self.wrap_close_debug_mode_pkt() )
-    def on_cb_debug_mode( self, idx ):
-        if idx == 0:
-            self.label_debug_curr_unit.setText( "A")
+    def on_cb_weld_curr_debug(self):
+        self.label_debug_curr_unit.setText( "A")
+        if self.cb_weld_curr_debug.isChecked():
+            self.btn_debug_write.setEnabled(1)
+            self.debug_mode = 1
+        else:
             self.close_debug_mode()
             self.btn_debug_write.setEnabled(0)
-        elif idx == 1:
-            self.label_debug_curr_unit.setText( "A")
-            self.btn_debug_write.setEnabled(1)
-        elif idx == 2:
-            self.label_debug_curr_unit.setText( "mA")
-            self.btn_debug_write.setEnabled(1)
-        self.debug_mode = idx
+            self.debug_mode = 0
     def on_btn_debug_write( self ):
         if self.ser_opened:
             curr = int( self.lineEdit_debug_value.text() )
@@ -342,20 +400,49 @@ class App( QDialog, ui_welding.Ui_Dialog ):
             elif self.debug_mode == 2:
                 cmd = self.wrap_valve_curr_pkt( curr )
                 self.ser.write( cmd  )
+
     def on_table_select( self, index ):
         print( "on table select ", index )
-        self.tabWidget.setCurrentIndex( index-1 )
+        curr_tab = self.tabWidget.currentIndex() +1 # tab : 1/2/3/4/5
+        if index == curr_tab:
+            return
+        if index == 5:
+            try:
+                if self.ser_opened:
+                    self.ser_close()
+                if self.ser_open():
+                    if self.connected:
+                        self.tx_cmd( 0x0022, struct.pack( '>L', 0 ))
+                    self.connected = index
+                    self.tabWidget.setCurrentIndex( index-1 )
+                    self.cfg_timer.start( 1000 )
+            except serial.serialutil.SerialException:
+                msg = popup.Msg( self )
+                msg.show_msg( text="打开串口失败...")
+
+        else:
+            if curr_tab == 5:
+                if self.ser_opened:
+                    self.ser_close()
+                self.connected = 0
+                self.cfg_timer.stop()
+            self.tabWidget.setCurrentIndex( index-1 )
+
+    def on_tab_changed( self ):
+        index = self.tabWidget.currentIndex()+1
         self.btn_devinfo.setStyleSheet( "background-color: green" if index==1 else "background-color: lightgray" )
         self.btn_curr.setStyleSheet( "background-color: green" if index==2 else "background-color: lightgray" )
         self.btn_update.setStyleSheet( "background-color: green" if index==3 else "background-color: lightgray" )
         self.btn_cfg.setStyleSheet( "background-color: green" if index==4 else "background-color: lightgray" )
+        self.btn_ctrl.setStyleSheet( "background-color: green" if index==5 else "background-color: lightgray" )
 
-    def tx_cmd( self, cmd, data=b'', resp_cb=None ):
+    def tx_cmd( self, cmd, data=b'', resp_cb=None, wait=True ):
         pkt = self.wrap_pkt( cmd, data )
         #print( "tx pkt[%04X]:"%cmd, pkt.hex() )
         self.ser.write( pkt )
-
         self.wait_resp = ( cmd, False, resp_cb ) # wait resp cmd, rx cmd, rx result
+        if not wait:
+            return True
         retry = 10
         while not self.wait_resp[1] and retry>0 :
             time.sleep( 0.1)
@@ -518,16 +605,25 @@ class App( QDialog, ui_welding.Ui_Dialog ):
             self.curve_valve_curr.setData( np.array( self.flow_x), np.array( self.valve_curr_y))
             self.curve_flow.setData( np.array( self.flow_x), np.array( self.flow_y))
             self.curve_flow_target.setData( np.array( self.flow_x), np.array( self.flow_target_y))
-        elif cmd == 0x00B6 and len(data)>=20: #参数读取
+        elif (cmd == 0x00B6 or cmd==0x10B7) and len(data)>=20: #参数读取
             print( "B6 resp:", data.hex() )
-            #//节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B
-            method, factor, prev, comp, coeff, bypass_save = struct.unpack( '>LLLlLL', data )
+            #//节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择断电保存4B, 气路选择4B
+            method, factor, prev, comp, coeff, bypass_save, bypass  = struct.unpack( '>LLLlLLL', data[:28] )
             #self.lineEdit_cfg_method.setText( "%d"%method )
             self.lineEdit_cfg_factor.setText( "%d"%factor )
             self.lineEdit_cfg_prev.setText( "%d"%prev )
             self.lineEdit_flow_comp.setText( "%d"%comp )
             self.lineEdit_flow_coeff.setText( "%d"%coeff)
             self.cb_cfg_method.setCurrentIndex( method )
+
+            self.btn_tig.setStyleSheet( "background-color: green" if method==0 else "background-color: lightgray" )
+            self.btn_mig.setStyleSheet( "background-color: green" if method==1 else "background-color: lightgray" )
+            self.btn_mag.setStyleSheet( "background-color: green" if method==2 else "background-color: lightgray" )
+            self.label_factor.setText( "%d"%factor )
+            self.label_prev.setText( "%d"%prev )
+            self.btn_bypass_on.setStyleSheet( "background-color: green" if bypass==1 else "background-color: lightgray" )
+            self.btn_bypass_off.setStyleSheet( "background-color: green" if bypass==0 else "background-color: lightgray" )
+
             for idx in range(len(gas_coefficient)):
                 if gas_coefficient[idx][1] == coeff:
                     self.cb_flow_coeff.setCurrentIndex(idx)
@@ -556,9 +652,13 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         elif cmd == 0x00BE and len(data)==4: #上报周期读取
             self.lineEdit_rpt_period.setText(  str( struct.unpack( '>L', data )[0] ) )
         elif cmd == 0x00C0 and len(data)>=2: #读取参数2
-            flow, gas = struct.unpack( ">BB", data )
+            flow, gas, alarm_x1000 = struct.unpack( ">BBL", data )
             self.cb_flow_sel.setCurrentIndex( flow )
             self.cb_gas_sel.setCurrentIndex( gas )
+            self.lineEdit_flow_low_alarm.setText( "%.1f"%(alarm_x1000/1000))
+        elif cmd == 0x00C2 and len(data)>=1: #读取参数2
+            self.btn_bypass_on.setStyleSheet( "background-color: green" if data[0]==1 else "background-color: lightgray" )
+            self.btn_bypass_off.setStyleSheet( "background-color: green" if data[0]==0 else "background-color: lightgray" )
 
         if cmd == self.wait_resp[0]:
             self.wait_resp = ( cmd, True, data[0] )
index d9912af7722995d9f92b962a6e7d4cddbc8e0c6f..7dfc2d085d847af7f0e82b90dae63074ffc1d531 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1535</width>
+    <width>1333</width>
     <height>845</height>
    </rect>
   </property>
@@ -32,7 +32,7 @@
     <property name="geometry">
      <rect>
       <x>10</x>
-      <y>20</y>
+      <y>280</y>
       <width>121</width>
       <height>81</height>
      </rect>
@@ -48,7 +48,7 @@
     <property name="geometry">
      <rect>
       <x>10</x>
-      <y>110</y>
+      <y>370</y>
       <width>121</width>
       <height>81</height>
      </rect>
     <property name="geometry">
      <rect>
       <x>10</x>
-      <y>300</y>
+      <y>100</y>
       <width>121</width>
       <height>81</height>
      </rect>
     </property>
     <property name="text">
-     <string>参数配置</string>
+     <string>参数读写</string>
     </property>
     <property name="autoDefault">
      <bool>false</bool>
@@ -80,7 +80,7 @@
     <property name="geometry">
      <rect>
       <x>10</x>
-      <y>210</y>
+      <y>10</y>
       <width>121</width>
       <height>81</height>
      </rect>
      <bool>false</bool>
     </property>
    </widget>
+   <widget class="QPushButton" name="btn_ctrl">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>190</y>
+      <width>121</width>
+      <height>81</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>在线操作</string>
+    </property>
+    <property name="autoDefault">
+     <bool>false</bool>
+    </property>
+   </widget>
   </widget>
   <widget class="QGroupBox" name="groupBox_2">
    <property name="geometry">
     <rect>
      <x>160</x>
      <y>10</y>
-     <width>1201</width>
+     <width>1171</width>
      <height>831</height>
     </rect>
    </property>
      </rect>
     </property>
     <property name="currentIndex">
-     <number>3</number>
+     <number>2</number>
     </property>
     <widget class="QWidget" name="tab">
      <attribute name="title">
         <enum>Qt::Horizontal</enum>
        </property>
       </widget>
-      <widget class="QComboBox" name="cb_debug_mode">
+      <widget class="QLabel" name="label_debug_curr_unit">
        <property name="geometry">
         <rect>
-         <x>10</x>
+         <x>200</x>
          <y>20</y>
-         <width>121</width>
+         <width>21</width>
          <height>31</height>
         </rect>
        </property>
-       <property name="editable">
-        <bool>true</bool>
-       </property>
-       <property name="duplicatesEnabled">
-        <bool>false</bool>
-       </property>
-       <property name="frame">
-        <bool>true</bool>
+       <property name="text">
+        <string>A</string>
        </property>
-       <item>
-        <property name="text">
-         <string>关闭模拟调试</string>
-        </property>
-       </item>
-       <item>
-        <property name="text">
-         <string>模拟焊接电流</string>
-        </property>
-       </item>
-       <item>
-        <property name="text">
-         <string>比例阀控制电流</string>
-        </property>
-       </item>
       </widget>
-      <widget class="QLabel" name="label_debug_curr_unit">
+      <widget class="QCheckBox" name="cb_weld_curr_debug">
        <property name="geometry">
         <rect>
-         <x>200</x>
-         <y>20</y>
-         <width>21</width>
-         <height>31</height>
+         <x>10</x>
+         <y>10</y>
+         <width>101</width>
+         <height>41</height>
         </rect>
        </property>
        <property name="text">
-        <string>A</string>
+        <string>模拟焊接电流</string>
        </property>
       </widget>
      </widget>
          </item>
         </widget>
        </widget>
+       <widget class="QGroupBox" name="groupBox_18">
+        <property name="geometry">
+         <rect>
+          <x>490</x>
+          <y>510</y>
+          <width>421</width>
+          <height>151</height>
+         </rect>
+        </property>
+        <property name="title">
+         <string>报警阈值</string>
+        </property>
+        <widget class="QPushButton" name="btn_flow_alarm_write">
+         <property name="geometry">
+          <rect>
+           <x>330</x>
+           <y>40</y>
+           <width>81</width>
+           <height>71</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>写入</string>
+         </property>
+        </widget>
+        <widget class="QPushButton" name="btn_flow_alarm_read">
+         <property name="geometry">
+          <rect>
+           <x>250</x>
+           <y>40</y>
+           <width>81</width>
+           <height>71</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>读取</string>
+         </property>
+        </widget>
+        <widget class="QLineEdit" name="lineEdit_flow_low_alarm">
+         <property name="geometry">
+          <rect>
+           <x>120</x>
+           <y>80</y>
+           <width>111</width>
+           <height>31</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>0</string>
+         </property>
+         <property name="readOnly">
+          <bool>false</bool>
+         </property>
+        </widget>
+        <widget class="QLabel" name="label_34">
+         <property name="geometry">
+          <rect>
+           <x>10</x>
+           <y>30</y>
+           <width>131</width>
+           <height>31</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>低流量报警值(L/min)</string>
+         </property>
+        </widget>
+        <widget class="QLabel" name="label_35">
+         <property name="geometry">
+          <rect>
+           <x>140</x>
+           <y>30</y>
+           <width>101</width>
+           <height>31</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>设为0则关闭报警</string>
+         </property>
+        </widget>
+       </widget>
       </widget>
      </widget>
     </widget>
+    <widget class="QWidget" name="tab_9">
+     <attribute name="title">
+      <string>页</string>
+     </attribute>
+     <widget class="QGroupBox" name="groupBox_20">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>30</y>
+        <width>251</width>
+        <height>91</height>
+       </rect>
+      </property>
+      <property name="title">
+       <string>焊接工艺</string>
+      </property>
+      <widget class="QPushButton" name="btn_tig">
+       <property name="geometry">
+        <rect>
+         <x>30</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>TIG</string>
+       </property>
+      </widget>
+      <widget class="QPushButton" name="btn_mig">
+       <property name="geometry">
+        <rect>
+         <x>100</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>MIG</string>
+       </property>
+      </widget>
+      <widget class="QPushButton" name="btn_mag">
+       <property name="geometry">
+        <rect>
+         <x>170</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>MAG</string>
+       </property>
+      </widget>
+     </widget>
+     <widget class="QGroupBox" name="groupBox_21">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>140</y>
+        <width>251</width>
+        <height>91</height>
+       </rect>
+      </property>
+      <property name="title">
+       <string>节气因子</string>
+      </property>
+      <widget class="QPushButton" name="btn_factor_sub">
+       <property name="geometry">
+        <rect>
+         <x>30</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>-</string>
+       </property>
+      </widget>
+      <widget class="QPushButton" name="btn_factor_add">
+       <property name="geometry">
+        <rect>
+         <x>170</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>+</string>
+       </property>
+      </widget>
+      <widget class="QLabel" name="label_factor">
+       <property name="geometry">
+        <rect>
+         <x>100</x>
+         <y>30</y>
+         <width>54</width>
+         <height>41</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>0</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </widget>
+     <widget class="QGroupBox" name="groupBox_22">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>250</y>
+        <width>251</width>
+        <height>91</height>
+       </rect>
+      </property>
+      <property name="title">
+       <string>前后气调节</string>
+      </property>
+      <widget class="QPushButton" name="btn_prev_sub">
+       <property name="geometry">
+        <rect>
+         <x>30</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>-</string>
+       </property>
+      </widget>
+      <widget class="QPushButton" name="btn_prev_add">
+       <property name="geometry">
+        <rect>
+         <x>170</x>
+         <y>30</y>
+         <width>51</width>
+         <height>51</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>+</string>
+       </property>
+       <property name="autoRepeat">
+        <bool>false</bool>
+       </property>
+      </widget>
+      <widget class="QLabel" name="label_prev">
+       <property name="geometry">
+        <rect>
+         <x>100</x>
+         <y>30</y>
+         <width>54</width>
+         <height>41</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>0</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </widget>
+     <widget class="QGroupBox" name="groupBox_23">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>360</y>
+        <width>251</width>
+        <height>91</height>
+       </rect>
+      </property>
+      <property name="title">
+       <string>气路选择</string>
+      </property>
+      <widget class="QPushButton" name="btn_bypass_off">
+       <property name="geometry">
+        <rect>
+         <x>30</x>
+         <y>20</y>
+         <width>71</width>
+         <height>61</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>智能节气</string>
+       </property>
+      </widget>
+      <widget class="QPushButton" name="btn_bypass_on">
+       <property name="geometry">
+        <rect>
+         <x>140</x>
+         <y>20</y>
+         <width>81</width>
+         <height>61</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string>旁路直通</string>
+       </property>
+      </widget>
+     </widget>
+    </widget>
+    <widget class="QWidget" name="tab_10">
+     <attribute name="title">
+      <string>页</string>
+     </attribute>
+    </widget>
    </widget>
   </widget>
  </widget>
index fd6a32cd969052ef9b5f52d4622cfff173cf6d8e..ccc07dc6203979bb89fb2b5791c7e3f28a8e265e 100644 (file)
@@ -150,7 +150,7 @@ class yn_download(QThread):
                        self.rx_pkt = pkt
                        self.rx_event.set()
 
-       def transmit(self,  tx,  timeout = 5,  retry=1  ):
+       def transmit(self,  tx,  timeout = 5,  retry=1, verbose=1  ):
                while retry>0:
                        retry -= 1
                        self.rx_event.clear()
@@ -160,52 +160,54 @@ class yn_download(QThread):
                                if  self.rx_event.wait( timeout= timeout ):
                                        print( "接收[%d]: %s ..."%( len(self.rx_pkt), self.rx_pkt[:64].hex() ) )
                                        return True
-                               else:
+                               elif verbose:
                                        self.log_add( '数据传输超时!',  'error')
                        except:
-                               self.log_add( '数据发送失败!',  'error')
-                               #TODO : raise excpection
+                               if verbose:
+                                       self.log_add( '数据发送失败!',  'error')
                return False
 
        def connect(self):
                self.log_add( u"连接设备 ... ")
                #read uuid
                print( "++++++++++++++++++++++++++++++++++")
-               resp = self.transmit( self.wrap_query_pkt(),  timeout = 2, retry = 5 )
-               if resp:
+               err = 0
+
+               if self.transmit( self.wrap_query_pkt(),  timeout = 2, retry = 3 ):
                        if  len(self.rx_pkt)>=32:
                                if self.rx_pkt[7]==0x42:
                                        self.log_add( u'连接成功', 'info')
                                        self.log_add( '-'*50 + '\n' )
-                                       return True
+                                       return 1
                                elif self.rx_pkt[7]==0x41:
                                        #app , reboot to download
                                        #resp = self.transmit( self.wrap_reboot_pkt( mode =0x544F4F42 ),  timeout = 2, retry = 5 )
                                        print( "reboot to download mode -------------------------------------")
-                                       resp = self.transmit( self.wrap_pkt( 0x00A0 ),  timeout = 2, retry = 5 )
-                                       pass
-                       else:
-                               self.log_add( u'连接错误', 'error' )
-               else:
-                       self.log_add( '连接超时',  'error')
-               return False
+                                       self.log_add( u'当前工作模式,切换到下载模式...', 'info')
+                                       resp = self.transmit( self.wrap_pkt( 0x00A0 ),  timeout = 2, retry = 1, verbose=0 )
+                                       return 0
+               self.log_add( '连接超时',  'error')
+               return -1
 
        def run(self ):
                self.log_clear()
                pkgs = self.parse_image()
                #if self.pbar:
                #       self.pbar['maximum'] = len(pkgs)
-               self.s = ser.ser()
-               try:
-                       self.s.open( self.port, self.baudrate, self.rx_handler)
-               except:
-                       self.log_add( '打开串口失败!',  'error')
-                       self.trigger_end.emit()
-                       return
-               if not self.connect():
-                       self.s.close()
-                       self.trigger_end.emit()
-                       return
+               connect_result = 0
+               while connect_result==0:
+                       self.s = ser.ser()
+                       try:
+                               self.s.open( self.port, self.baudrate, self.rx_handler)
+                       except:
+                               self.log_add( '打开串口失败!',  'error')
+                               self.trigger_end.emit()
+                               return
+                       connect_result = self.connect()
+                       if connect_result < 0: 
+                               self.s.close()
+                               self.trigger_end.emit()
+                               return
 
                self.log_add( '下载开始 ... %s'%(time.strftime('%H:%M:%S')), 'info' )
                t0 = time.time()
@@ -244,10 +246,11 @@ class yn_download(QThread):
                                self.log_add( "下载时间: \t%d 秒"%( time.time()-t0 ), 'info' )
                                self.transmit( self.wrap_readcrc_pkt(), timeout = 2 )
                                self.log_add( "重启系统 ... ", 'info' )
-                               if self.transmit( self.wrap_reboot_pkt(), timeout=2 ):
-                                       pass
-                               else:
-                                       pass
+                               self.transmit( self.wrap_reboot_pkt(), timeout=0, retry=1, verbose=0 )
+                               #       pass
+                               #else:
+                               #       pass
+                               print( "xxx" )
                        else:
                                self.log_add( "校验错误, 固件CRC:%04X, 读取CRC:%04X"%( img_crc, flash_crc),  "error"  )
                else:
diff --git a/ui/48/485.jpg b/ui/48/485.jpg
deleted file mode 100644 (file)
index 71a60f2..0000000
Binary files a/ui/48/485.jpg and /dev/null differ
diff --git a/ui/48/486.jpg b/ui/48/486.jpg
deleted file mode 100644 (file)
index 99a9a08..0000000
Binary files a/ui/48/486.jpg and /dev/null differ
index 5d472e3ec1e925b60a500c47e71ff42670c56f72..eca893f02016ddd43d492294c34ebd7e55d2fb98 100644 (file)
Binary files a/ui/48/487.jpg and b/ui/48/487.jpg differ
index d50b3caf1a408974fbce8d0efa534112446db497..c580f62eb98e4386f95891d236d6ec7f0e5832ad 100644 (file)
Binary files a/ui/48/488.jpg and b/ui/48/488.jpg differ
diff --git a/ui/48/600.jpg b/ui/48/600.jpg
new file mode 100644 (file)
index 0000000..d86cbea
Binary files /dev/null and b/ui/48/600.jpg differ
diff --git a/ui/48/601.jpg b/ui/48/601.jpg
new file mode 100644 (file)
index 0000000..1febc43
Binary files /dev/null and b/ui/48/601.jpg differ
diff --git a/ui/48/602.jpg b/ui/48/602.jpg
new file mode 100644 (file)
index 0000000..385a608
Binary files /dev/null and b/ui/48/602.jpg differ
diff --git a/ui/48/603.jpg b/ui/48/603.jpg
new file mode 100644 (file)
index 0000000..4121a5e
Binary files /dev/null and b/ui/48/603.jpg differ
diff --git a/ui/48/700.jpg b/ui/48/700.jpg
new file mode 100644 (file)
index 0000000..32e6fc7
Binary files /dev/null and b/ui/48/700.jpg differ
diff --git a/ui/48/701.jpg b/ui/48/701.jpg
new file mode 100644 (file)
index 0000000..1e5d681
Binary files /dev/null and b/ui/48/701.jpg differ
diff --git a/ui/DWIN_SET/10.png b/ui/DWIN_SET/10.png
new file mode 100644 (file)
index 0000000..c38837e
Binary files /dev/null and b/ui/DWIN_SET/10.png differ
index 64ed1e60ae3b47aef6691c89ec728535cf19afcb..b22de1c7057ae2c8dbb0ae565be14f3143b8bf13 100644 (file)
Binary files a/ui/DWIN_SET/13TouchFile.bin and b/ui/DWIN_SET/13TouchFile.bin differ
index c2d571193ffa55a6869c8e9cec3d9497bf7aee28..931617fd221267c78dd3a4f24b362479f40214e1 100644 (file)
Binary files a/ui/DWIN_SET/14ShowFile.bin and b/ui/DWIN_SET/14ShowFile.bin differ
index 839ee77d36246a08784bea93940b52203ce37451..75aa4442c8d151f037970565a91b915fdb6226a2 100644 (file)
Binary files a/ui/DWIN_SET/22_Config.bin and b/ui/DWIN_SET/22_Config.bin differ
index 7cbd09c2cf3917ec5bc02043b5baac70d0ef595a..faa943841f74f5f259962215c393ce8eaf398661 100644 (file)
Binary files a/ui/DWIN_SET/32.icl and b/ui/DWIN_SET/32.icl differ
index 9a6e3a9821cd6b8fda1020c0267fb6b5773e7279..1377e468e5b30e0f482829f003b09ee4885e838d 100644 (file)
Binary files a/ui/DWIN_SET/48.icl and b/ui/DWIN_SET/48.icl differ
index 375045493a6be1a39d245299cffb87507a5da2fa..b703877e27e5fae3e649580be9fa0451e60464f8 100644 (file)
Binary files a/ui/DWIN_SET/T5LCFG.CFG and b/ui/DWIN_SET/T5LCFG.CFG differ
index 2d4c35dc5adf7db5a5fe184a783f6eae94d85c4d..41f2559e37d3748ff345b9800ecfcba556347901 100644 (file)
@@ -6,15 +6,16 @@ ProVersion=647
 SCREENDSIZE=480X272
 SPADDRESS=5000
 [IMG]
-0=0.png
-1=1.png
-2=2.png
-3=3.png
-5=5.png
-20=20.jpg
-21=21.jpg
-22=22.jpg
-23=23.jpg
-6=6.png
-7=7.png
-4=4.png
+0=10.png
+1=0.png
+2=1.png
+3=2.png
+4=3.png
+5=4.png
+6=5.png
+7=6.png
+8=7.png
+9=20.jpg
+10=21.jpg
+11=22.jpg
+12=23.jpg
index b44d9c1d1c739617ecfa11c88866321b5ada5863..29c0022015569e0eee54e5b2b63628e5ebbe91c9 100644 (file)
Binary files a/ui/TFT/0.png.tft and b/ui/TFT/0.png.tft differ
index 75c73b2f229c7b6b6104420bbd5ba5b7734978c2..5c3e2108827f5fc42bbcfbf23d7639b6c988d156 100644 (file)
Binary files a/ui/TFT/1.png.tft and b/ui/TFT/1.png.tft differ
diff --git a/ui/TFT/10.png.tft b/ui/TFT/10.png.tft
new file mode 100644 (file)
index 0000000..2bc393f
Binary files /dev/null and b/ui/TFT/10.png.tft differ
index 953f3bc948b9c3c1cb51b3a6d8101cb501f36c80..f14f0a962efdac370903644d529e38279c7ae4a5 100644 (file)
Binary files a/ui/TFT/2.png.tft and b/ui/TFT/2.png.tft differ
index c130a6505befa5a62832ca461c6aeaa142e3f8d5..931afd6d0b9cddeeab5848e02feed9e774ec0404 100644 (file)
Binary files a/ui/TFT/20.jpg.tft and b/ui/TFT/20.jpg.tft differ
index 9394ef920d59a6994bf9f70054452ffadf9b4bba..4a8fe1aa1258779e9477f94e8332d7f81090e22c 100644 (file)
Binary files a/ui/TFT/21.jpg.tft and b/ui/TFT/21.jpg.tft differ
index 2de7780aa36daa83fe725508a6850c8929da5c10..d9a2a2b67717fbcee641b2bb191c546986643677 100644 (file)
Binary files a/ui/TFT/22.jpg.tft and b/ui/TFT/22.jpg.tft differ
index 770eb810299948c8e0454b9ce9640718680864a5..ac3ce58fff83bb7ebc00852fd66703d238f1c932 100644 (file)
Binary files a/ui/TFT/23.jpg.tft and b/ui/TFT/23.jpg.tft differ
index d0c50008bb0e2ba2476f60c25ee586e0cb42aacc..7cbe288611b4286440d3dd3d7ef57e1228334c2f 100644 (file)
Binary files a/ui/TFT/3.png.tft and b/ui/TFT/3.png.tft differ
index 9688f4e95f50fb7234526aed184e631c7ef83108..611aa0bbfc742e5857dc399f09e281831b454f2e 100644 (file)
Binary files a/ui/TFT/4.png.tft and b/ui/TFT/4.png.tft differ
index 0b0f6ed496a5c8d45177883a3baa3bac6f5368db..d3832c95477356ab926efec80c057a26fea1250d 100644 (file)
Binary files a/ui/TFT/5.png.tft and b/ui/TFT/5.png.tft differ
index ea78a33fde2c7806a7490a91df6516670b6a1fa7..bf6dd31414e101e23366ea06ba09ccaab75f3357 100644 (file)
Binary files a/ui/TFT/6.png.tft and b/ui/TFT/6.png.tft differ
index 34c0fdbe5b889cd7381ad6560914ac633e2f5aea..8458e85ace692026dd753ba3696979980ad8d5b4 100644 (file)
Binary files a/ui/TFT/7.png.tft and b/ui/TFT/7.png.tft differ
diff --git a/ui/raw/bg/10.png b/ui/raw/bg/10.png
new file mode 100644 (file)
index 0000000..c38837e
Binary files /dev/null and b/ui/raw/bg/10.png differ
diff --git a/ui/raw/icon/485.png b/ui/raw/icon/485.png
deleted file mode 100644 (file)
index 762f56e..0000000
Binary files a/ui/raw/icon/485.png and /dev/null differ
diff --git a/ui/raw/icon/486.png b/ui/raw/icon/486.png
deleted file mode 100644 (file)
index 9dc2286..0000000
Binary files a/ui/raw/icon/486.png and /dev/null differ
diff --git a/ui/raw/icon/600.png b/ui/raw/icon/600.png
new file mode 100644 (file)
index 0000000..d93700d
Binary files /dev/null and b/ui/raw/icon/600.png differ
diff --git a/ui/raw/icon/601.png b/ui/raw/icon/601.png
new file mode 100644 (file)
index 0000000..d3e2dd5
Binary files /dev/null and b/ui/raw/icon/601.png differ
diff --git a/ui/raw/icon/602.png b/ui/raw/icon/602.png
new file mode 100644 (file)
index 0000000..7df4771
Binary files /dev/null and b/ui/raw/icon/602.png differ
diff --git a/ui/raw/icon/603.png b/ui/raw/icon/603.png
new file mode 100644 (file)
index 0000000..319e6ba
Binary files /dev/null and b/ui/raw/icon/603.png differ
diff --git a/ui/raw/icon/700_bypass_off.png b/ui/raw/icon/700_bypass_off.png
new file mode 100644 (file)
index 0000000..9e24ca8
Binary files /dev/null and b/ui/raw/icon/700_bypass_off.png differ
diff --git a/ui/raw/icon/701_pybass_on.png b/ui/raw/icon/701_pybass_on.png
new file mode 100644 (file)
index 0000000..8736c94
Binary files /dev/null and b/ui/raw/icon/701_pybass_on.png differ
index 070ff01ed183fca9f59efd210fee33376c1793b4..343b59dc26f8d128439fcca372f8a20fd527c379 100644 (file)
 #include "gpio.h"
 //#include "fmc.h"
 //--------------------
+#define APP_VER_MAJOR 2
+#define APP_VER_MINOR 13
+
+
+#define  FLOW_SPEED_FS         50   //流量计满量程50L/min
+#define  PRESSURE_KPA_FS       700  //气压最大量程 700Kpa
+
 
 #define VALVE_CTRL_200MA   1 //比例阀控制电流最大按200mA ( 规格书定义为最大165mA)
+#if VALVE_CTRL_200MA
+#define VALVE_MAX_CURR_FLOAT  0.200f  //0.2A
+#else
+#define VALVE_MAX_CURR_FLOAT  0.165f  //0.165A
+#endif
 
 #define FLOWMETER_SCAN      0   //自动检查流量计
 #define FLOWMETER_AFM0750   1   //奥松流量计
@@ -40,9 +52,6 @@
 #define GAS_MAX       3
 
 
-#define APP_VER_MAJOR 2
-#define APP_VER_MINOR 13
-
 #define DEVICE_SN_DEFAULT  "A" "02" "01" "240506" "000001"
 #define DEVICE_SN_SIZE     17
 
@@ -83,6 +92,25 @@ void  debug_printf(char* str , ...);
 #define USER_LFS_PART_ADDR  0x00100000  //1M
 #define USER_LFS_PART_SIZE  0x00300000  //+3M
 
+/*
+2024/5/13  新增需求如下
+产品优化的几点建议:
+1、氩弧焊要求最低18L/min,考虑上位机增加最低流量参数设置;
+2、流量过低,增加报警提示音,控制比例阀仍达不到效果,考虑切换为直通模式;
+3、流量过大(超过95%FS),增加报警提示音,并控制比例阀将流量控制在95%FS以内,以保护流量计;
+4、气压过大(超过最大压力的95%,当前选型最大压力是0.7MPa),增加报警提示音(目前无法控制气压,后续产品规划再优化)
+
+软件设计:
+1. 增加报警阈值参数,单位0.001 L/min,  0忽略,不为0则生效
+2. 焊接时目标流量大于阈值,而实际流量低于阈值 10秒后报警,再10秒报警音后切换直通阀, 
+3. 流量超过 50L/min * 0.95,10秒后报警,不论节气或旁路,算法计算目标流量值按0.95*50L/min为上限最大值。
+4. 气压大于 0.7Mpa*.95 10秒后报警
+5. 报警音:
+       气压高报警:报警音  1长      --  响2秒,停0.5秒
+       流量高报警:报警音  1长 1短  --  响2秒,停0.2秒,响0.2秒,停0.5s
+       流量低报警:报警音  1长 2短  --  响2秒,停0.2秒,响0.2秒,停0.2s,响0.2秒,停0.5s
+  以上报警音优先级:气压报警  >  高流量报警 > 低流量报警 > 设备原来的故障报警
+*/
 
 typedef struct{
          uint32_t id;
@@ -131,21 +159,26 @@ typedef struct{
 }dev_cfg_t;
 
 #if  1
-//TODO 
 //新增配置项放到这个里面, 避免原配置结构修改,避免升级固件后原参数被清掉。
 
-
 #define  DEV_CFG_V2_FLAG  0xA0
 typedef struct{
-    uint32_t flowmeter; //流量计类型, 0:自动, 1:奥松, 2:MF   3:SMC   4: 其他
-    uint32_t gas;      //气体类型,   0:未指定, 1:氩气, 2:二氧化碳, 3: 混合气1, 4:混合气2, 5: 其他
+    uint32_t flow_low_alarm_x1000; //最低流量报警阈值, 单位0.001L/min
+    uint8_t flowmeter; //流量计类型, 0:自动, 1:奥松, 2:MF   3:SMC   4: 其他
+    uint8_t gas;      //气体类型,   0:未指定, 1:氩气, 2:二氧化碳, 3: 混合气1, 4:混合气2, 5: 其他
     uint8_t  bl;       //0-4  5级
-    uint8_t reserved[30];
+    uint8_t reserved[24];
     uint8_t flag;
 }dev_cfg_v2_t;
 
 #endif
 
+typedef struct{ //表示设备报警状态
+    uint32_t flow_low;      //1:流量低报警, 
+    uint32_t flow_high;     //1: 流量高报警
+    uint32_t pressure_high; //1:气压高报警
+}alarm_t;
+
 //故障码bit位定义
 #define CURR_SENSOR_ERR     ( 1<<0 ) //电流传感器故障
 #define FLOWMETER_ERR       ( 1<<1 ) //流量计故障
@@ -153,7 +186,7 @@ typedef struct{
 #define TEMP_ERR            ( 1<<3 ) //超温故障
 #define SFLASH_ERR          ( 1<<4 ) //spi flash 故障
 #define VALVE_CTRL_ERR      ( 1<<5 ) //比例阀电流控制 AD5245 故障
-#define WIFI_ERR            ( 1<<6 )
+#define WIFI_ERR            ( 1<<6 ) //WIFI模块故障
 
 
 typedef struct {
@@ -188,14 +221,14 @@ typedef struct {
     
     //调试功能
     uint32_t debug_report; //主动上报数据, 0:关闭, 1:上报控制信息, 2:上报焊接电流信息
-    uint32_t debug_curr;    //模拟数据, 0:关闭, 1:模拟焊接电流,2:设置比例阀输出电流 
+    uint32_t debug_curr;    //模拟数据, 0:关闭, 1:模拟焊接电流
     float debug_welding_curr; //模拟焊接电流 A
-    float debug_valve_curr;   //设置比例阀输出电流 A
-
+    
     uint32_t wifi_connected; //0:disconnect, 1:wifi connected, 2:tcp connected
     uint32_t eth_connected; //0: eth disconnect, 1:eth connected, 2::tcp connected
                
        char serial_number[32];
+    alarm_t alarm;
 }dev_info_t;
 
 extern TIM_HandleTypeDef htim2;   //htim2 用于触发DMA ADC采集
index e7274f3659c2cc76fcfd1211633a517e76ffaa50..b2d7bbdf2cc5c5f600ce2f52e1fc4c420ecab8f9 100644 (file)
@@ -58,7 +58,7 @@ dev_info_t g_dev;
 extern void debug_task_start( void );
 extern void wifi_task_start( void );
 extern void eth_task_start( void );
-    
+
 void StartDefaultTask(void *argument)
 {
     /* init code for USB_DEVICE */
@@ -251,13 +251,18 @@ int32_t dev_cfg_v2_load( dev_cfg_v2_t *cfg )
     if( cfg->gas > GAS_MAX ){
                                cfg->gas = GAS_DEFAULT;
     }
+
+    if( cfg->flow_low_alarm_x1000 == 0xffffffff ){
+        cfg->flow_low_alarm_x1000 = 0;
+    }
+
     return 0;
 }
 
 void user_beep_task( void* unused )
 {
     int i;
-  GPIO_InitTypeDef GPIO_InitStruct = {0};
+    GPIO_InitTypeDef GPIO_InitStruct = {0};
 #if 0      
     //beep off
     //无源蜂鸣器,PWM控制频率
@@ -265,7 +270,7 @@ void user_beep_task( void* unused )
     osDelay( 500);
     HAL_TIM_PWM_Stop( &htim13, TIM_CHANNEL_1 );
 #endif
-  
+
     //有源蜂鸣器,配置为输出脚
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
     GPIO_InitStruct.Pin = PF8_PWM_SPK_TIM13_CH1_Pin;
@@ -274,12 +279,51 @@ void user_beep_task( void* unused )
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, &GPIO_InitStruct);
 
+    //开机叫一下
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
     osDelay(50);
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
   
     //TODO: 实际使用有源, 待修改代码
     while(1){
+
+        //气压和流量报警优先,     以上报警音,优先级, 气压报警  >  高流量报警 > 低流量报警 
+        //有以上报警, 后面的故障报警,暂停输出
+        if( g_dev.alarm.pressure_high ){
+            //气压高报警:报警音  1长      --  响2秒,停0.5秒
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(2000);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(500);
+            continue;
+        }else if( g_dev.alarm.flow_high ){
+               //流量高报警:报警音  1长 1短  --  响2秒,停0.2秒,响0.2秒,停0.5s
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(2000);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(500);
+            continue;
+        }else if( g_dev.alarm.flow_low ){
+               //流量低报警:报警音  1长 2短  --  响2秒,停0.2秒,响0.2秒,停0.2s,响0.2秒,停0.5s
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(2000);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+            osDelay(200);
+            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+            osDelay(500);
+            continue;
+        }            
+
         //TODO: 按需要增加提示音管理
         if( g_dev.state & FLOWMETER_ERR ){
             HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
index 84852d30e2c646c0ee13f4f7339e713c2a2c8ff2..528bb800c7e3990e77b5ba2d22f431e8e7ef9068 100644 (file)
@@ -371,9 +371,9 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
             g_dev.debug_curr = 1;
             break;
         case 0x00f2:
-            //写比例阀控制电流
-            g_dev.debug_valve_curr = get_u32_big( pkt->pdata )/1000.0f;
-            g_dev.debug_curr = 2;
+            //写比例阀控制电流, 取消
+            //g_dev.debug_valve_curr = get_u32_big( pkt->pdata )/1000.0f;
+            //g_dev.debug_curr = 2;
             break;
         case 0x0022:
             if( pkt->data_len >=4 ){
@@ -499,17 +499,18 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
         case 0xB5: //焊接数据清0
             break;
         case 0xB6: //设备参数读取
-                                               //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B
+                                               //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B bypass 4B
                                          put_u32_big( &resp[0], g_dev.cfg.welding_method );
                                          put_u32_big( &resp[4], g_dev.cfg.save_gas_factor );
             put_u32_big( &resp[8], g_dev.cfg.valve_open_default );
             put_u32_big( &resp[12], g_dev.cfg.cal.flow_comp_x1000 );
             put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 );
                                    put_u32_big( &resp[20], g_dev.cfg.bypass_save );
-                                   tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 24 );
+                                               put_u32_big( &resp[24], g_dev.cfg.bypass );
+                                   tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 );
             break;
         case 0xB7: //设备参数写入
-                                               //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B
+                                               //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B, bypass 4B
                                {
                                          uint32_t method = get_u32_big( &pkt->pdata[0] );
                                          uint32_t factor = get_u32_big( &pkt->pdata[4] );
@@ -517,6 +518,7 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
                                          int32_t comp = get_u32_big( &pkt->pdata[12] );
                                          uint32_t coeff = get_u32_big( &pkt->pdata[16] );
                                          uint32_t bypass_save = get_u32_big( &pkt->pdata[20] );
+                                         uint32_t bypass = get_u32_big( &pkt->pdata[24] );
                                        
                                                if( factor >=2 && factor <= 30 )
                                                        g_dev.cfg.save_gas_factor = factor;
@@ -530,16 +532,20 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
                                                        g_dev.cfg.cal.flow_coeff_x1000 = coeff;
                                                if( bypass_save == 1 || bypass_save == 0 )
                                                        g_dev.cfg.bypass_save = bypass_save;
+                                               if( bypass == 1 || bypass == 0 )
+                                                       g_dev.cfg.bypass = bypass;
+                                               
                                                dev_cfg_store( &g_dev.cfg );
                                                ui_cfg_remote_update();
 
-                                         put_u32_big( &resp[0], g_dev.cfg.save_gas_factor );
-                                         put_u32_big( &resp[4], g_dev.cfg.welding_method );
+                                         put_u32_big( &resp[0], g_dev.cfg.welding_method );
+                                         put_u32_big( &resp[4], g_dev.cfg.save_gas_factor );
             put_u32_big( &resp[8], g_dev.cfg.valve_open_default );
             put_u32_big( &resp[12], g_dev.cfg.cal.flow_comp_x1000 );
             put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 );
-            put_u32_big( &resp[20], g_dev.cfg.bypass_save );
-                                   tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 24 );
+                                   put_u32_big( &resp[20], g_dev.cfg.bypass_save );
+                                               put_u32_big( &resp[24], g_dev.cfg.bypass );
+                                   tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 );
                                          break;
                                }
         case 0xB8: //WIFI参数读取
@@ -617,20 +623,40 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
                                    tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
                  break;
                                }
-        case 0xC0: //参数v2 读取  -- 流量计选择1B ...
+        case 0xC0: //参数v2 读取  -- 流量计选择1B 气体1B, 流量低报阈值 4B...
             resp[0] = g_dev.cfg2.flowmeter;
             resp[1] = g_dev.cfg2.gas;
-            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 2 );
+                                               put_u32_big( &resp[2], g_dev.cfg2.flow_low_alarm_x1000 );
+            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 6 );
             break;
-        case 0xC1: //参数v2 写入 -- 流量计选择1B,气体选择1B 背光 1B -- ... 
+        case 0xC1: //参数v2 写入 -- 流量计选择1B,气体选择1B 流量低报阈值 4B -- ... 
             if( pkt->pdata[0] <= FLOWMETER_MAX )
                 g_dev.cfg2.flowmeter = pkt->pdata[0];
             if( pkt->pdata[1] <= GAS_MAX )
                 g_dev.cfg2.gas = pkt->pdata[1];
+                                               if( get_u32_big( &pkt->pdata[2] ) != 0xFFFFFFFF )
+                                                         g_dev.cfg2.flow_low_alarm_x1000 = get_u32_big( &pkt->pdata[2] );
             dev_cfg_v2_store( &g_dev.cfg2 );
             resp[0] = 1;
             tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
             break;
+#if 0                                          
+        case 0xC2: //气路读取 1B   0:bypass_off, 1:bypass_on
+               resp[0] = g_dev.cfg.bypass;
+            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
+            break;
+        case 0xC3: //气路选择 1B   0:bypass_off, 1:bypass_on
+            if( pkt->pdata[0] == 1 || pkt->pdata[0] == 0 ){
+                g_dev.cfg.bypass = pkt->pdata[0];
+                dev_cfg_store( &g_dev.cfg );
+                resp[0] = 1;
+                lcd_update_cfg();
+            }else{
+                resp[0] = 0;
+            }
+            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
+            break;
+#endif
 #endif
 
     }
index fd946656b02babbfa9dffd454c9fdaffdbdfea51..99d15ed1b445a2544a4681e3e80318f5b9455e72 100644 (file)
@@ -368,6 +368,15 @@ void user_flowmeter_task( void* unused )
             if( g_dev.flowmeter.ad_vol > 0.5f &&  g_dev.flowmeter.ad_vol < 5.5f ){
                 flow_raw = g_dev.flowmeter.flow_speed_raw_ad;
                 total_raw = g_flow_total;
+                                                       
+                                                         //SMC启用气体修正系数, 2024/05/17
+                if( g_dev.cfg.cal.flow_coeff_x1000 > 100 && g_dev.cfg.cal.flow_coeff_x1000 < 3000 ){
+                    float flow_coeff = g_dev.cfg.cal.flow_coeff_x1000/1000.0f;
+                                                                         //瞬时流量进行修正,
+                    flow_raw *= flow_coeff;
+                                                                         //累计流量通过软件实现不需要修正
+                }
+
                 flow_err = 0;
             }else{
                 flow_err++;
index 43440f7dc418fc41a94484f077ec736bd51165c0..c1ace78481a0682b7fd6a6a0bd7bf955f2809210 100644 (file)
 #define lcd_tcp_port_size              6
 #define lcd_net_cfg_size     (lcd_wifi_ssid_size+lcd_wifi_passwd_size+lcd_tcp_server_size+lcd_tcp_port_size)
 
+#define lcd_eth_connected_addr     0x5300  //连接标志    0:未连接,   1: 以太网连接,  2:建立TCP连接
+#define lcd_msg_1_addr             0x5400  //预留通用信息
+#define lcd_msg_1_size                 32  //32Byte, 占16个变量
+#define lcd_msg_2_addr             0x5420  //预留通用信息
+#define lcd_msg_2_size                 32  //32Byte, 占16个变量
 typedef struct{
     uint8_t cmd;
     uint8_t addr[2];
index 8809faa5d0bcec28c915abffdf915ff643264ce9..748b1cd74639e4cacbb9b6f636efa17f61ea1826 100644 (file)
 #else
     #define valve_overheat( temp_v )  ( 0 )
 #endif
+
+//气压高报警
+static void pressure_alarm_check( void );
+//流量低报检查
+static void flow_low_alarm_check( void );
+//流量高报检查
+static void flow_high_alarm_check( void );
+
 //------------------------------------------------
 //比例阀电流计算方式更新
 //通过压力和流量计算对应控制电流
@@ -157,6 +165,8 @@ int32_t calc_target_flow( double *target_flowspeed )
 
     if( caculate( (WeldMethod)g_dev.cfg.welding_method, welding_current, g_dev.cfg.save_gas_factor, &flowspeed ) == 0 ){
         //控制流量输出, 按焊接电流和节气因子计算目标流量
+                               if( flowspeed > FLOW_SPEED_FS*0.95f )
+                                        flowspeed = FLOW_SPEED_FS*0.95f;
         *target_flowspeed = flowspeed;
         return 0;
     }
@@ -182,21 +192,14 @@ float calc_valve_open_default( uint8_t open_percent )
 
     //1. 按压力计算对应启动电流和流量最大值
     calc_valve_curr_range( g_dev.pressure, &curr_start, &flow_max );
-#if VALVE_CTRL_200MA
-    //按百分比计算比例阀控制电流
+
+    //按百分比计算比例阀控制电流, 这里最大值按200mA/165mA计算
     if( open_percent == 0 )
         curr = 0;
     else if( open_percent >= 99 )
-               curr = 0.200;
+               curr = VALVE_MAX_CURR_FLOAT;
        else
-               curr = curr_start + ( 0.200f-curr_start )*open_percent/100.0f;
-#else
-    //按百分比计算比例阀控制电流
-    if( open_percent == 0 )
-        curr = 0;
-    else
-        curr = curr_start + ( 0.165f-curr_start )*open_percent/100.0f;
-#endif
+               curr = curr_start + ( VALVE_MAX_CURR_FLOAT-curr_start )*open_percent/100.0f;
 
     return curr;
 }
@@ -281,21 +284,12 @@ void pid_ctrl_update( void )
             curr_add/=2.0f;
         }
         //加到原来控制值上输出
-#if  VALVE_CTRL_200MA
-        if( g_pidctrl.valve_current_out+curr_add > 0.200f )
-            g_pidctrl.valve_current_out = 0.200f; //max 200mA
+        if( g_pidctrl.valve_current_out+curr_add > VALVE_MAX_CURR_FLOAT )
+            g_pidctrl.valve_current_out =VALVE_MAX_CURR_FLOAT; //max 200mA/165mA
         else if( g_pidctrl.valve_current_out+curr_add < 0.06f-0.01f )
             g_pidctrl.valve_current_out = 0.06f-0.01f;
         else
             g_pidctrl.valve_current_out += curr_add;
-#else
-        if( g_pidctrl.valve_current_out+curr_add > 0.165f )
-            g_pidctrl.valve_current_out = 0.165f; //max 165mA
-        else if( g_pidctrl.valve_current_out+curr_add < 0.06f-0.01f )
-            g_pidctrl.valve_current_out = 0.06f-0.01f;
-        else
-            g_pidctrl.valve_current_out += curr_add;
-#endif
     }
 }
 
@@ -419,8 +413,7 @@ void user_valve_ctrl_task( void* unused )
     uint32_t tem_restore_tick=0;
     uint32_t  tem_err_state = 0;
     float valve_curr;
-
-//    float target_flowspeed = 0;
+    double target_flowspeed;
 
     uint32_t tem_state_last = 0;
     uint32_t now;
@@ -518,93 +511,172 @@ void user_valve_ctrl_task( void* unused )
             g_dev.state &= ~(TEMP_ERR);
         }
 #endif
-        if( !bypass && (g_dev.cfg.bypass || tem_err_state  ) ){
-            //屏上点击旁路或温度故障,开启旁路
-            bypass = 1;
-        }else if( bypass && !g_dev.cfg.bypass && !tem_err_state  ){
-            //恢复正常,关闭旁路
-            bypass = 0;
+        if( g_dev.cfg.remote_locked || welding_current < 10.0f ){  //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
+            //未开始焊接
+            //按比例阀开度设置电流, 最小0.7v  最大1.0v, 按开度百分比计算电流
+            static float dbg_curr = 0;
+
+            if( g_dev.cfg.valve_open_default > 0 ){
+                //g_dev.valve_curr_out =  g_dev.cfg.valve_open_default*(0.16f-0.06f)/100 + 0.06f;
+                g_dev.valve_curr_out = calc_valve_open_default(g_dev.cfg.valve_open_default );
+            }else{
+                g_dev.valve_curr_out = 0;
+            }
+
+            if( dbg_curr - g_dev.valve_curr_out > 0.001f || dbg_curr - g_dev.valve_curr_out < -0.001f  ){
+                printf( "open %d%%, curr:%0.3fA -> %0.3fA\n", g_dev.cfg.valve_open_default, dbg_curr, g_dev.valve_curr_out );
+                dbg_curr =  g_dev.valve_curr_out;
+            }                    
+            if( g_dev.welding_start == 1 ){
+                g_dev.welding_start = 0;
+                g_dev.welding_time = 0;
+            }
+            //未焊接,调用这个函数不存储记录仅通过USB发送数据到上位机
+//            welding_data_store( 0 );
+        }else{
+            //焊接状态
+            if( g_dev.welding_start == 0 ){
+                //焊接启动
+                g_dev.welding_start = 1;
+                pid_ctrl_init(); //pid 初始化
+                g_dev.welding_time = 0; //计时
+            }else{
+                g_dev.welding_time += 100; //0.1秒扫描一次
+            }
+
+            if( calc_target_flow( &target_flowspeed )== 0 ){
+                //控制流量输出, 按焊接电流和节气因子计算目标流量
+                g_dev.target_flowspeed = target_flowspeed;
+            }
+
+            //根据目标流量,和实际流量,使用pid调整比例阀
+            pid_ctrl_update();
+            g_dev.valve_curr_out =  g_pidctrl.valve_current_out;
+
+            //焊接中,记录数据到spiflash,0.1秒一条
+  //          welding_data_store( g_dev.welding_time/100 );
         }
 
-        if( bypass ){
-            //比例阀温度故障
+        if( g_dev.cfg.bypass || tem_err_state  ){
+            //屏上点击旁路或温度故障,开启旁路
             valve_bypass( 1 );           //旁路电磁阀开启
             g_dev.valve_curr_out =  0;   //比例电磁阀关闭
-
-                                       //旁路时也更新焊接状态,修复旁路时上报平台为未焊接状态的问题 2024/5/9
-            if( g_dev.cfg.remote_locked || welding_current < 10.0f ){  //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
-                //未开始焊接
-                if( g_dev.welding_start == 1 ){
-                    g_dev.welding_start = 0;
-                    g_dev.welding_time = 0;
-                }
-                                               }else{
-                if( g_dev.welding_start == 0 ){
-                    //焊接启动
-                    g_dev.welding_start = 1;
-                                                                               g_dev.welding_time = 0;
-                                                               }
-                                               }
-
-        }else{
+        }else if( !g_dev.cfg.bypass && !tem_err_state  ){
+            //恢复正常,关闭旁路
             valve_bypass( 0 );           //旁路电磁阀关闭
-            //检查焊接电流,判断是否开始焊接
-            if( g_dev.cfg.remote_locked || welding_current < 10.0f ){  //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
-                //未开始焊接
-
-                //按比例阀开度设置电流, 最小0.7v  最大1.0v, 按开度百分比计算电流
-                static float dbg_curr = 0;
-
-                if( g_dev.cfg.valve_open_default > 0 ){
-                    //g_dev.valve_curr_out =  g_dev.cfg.valve_open_default*(0.16f-0.06f)/100 + 0.06f;
-                    g_dev.valve_curr_out = calc_valve_open_default(g_dev.cfg.valve_open_default );
-                }else{
-                    g_dev.valve_curr_out = 0;
-                }
+        }
 
-                if( dbg_curr - g_dev.valve_curr_out > 0.001f || dbg_curr - g_dev.valve_curr_out < -0.001f  ){
-                    printf( "open %d%%, curr:%0.3fA -> %0.3fA\n", g_dev.cfg.valve_open_default, dbg_curr, g_dev.valve_curr_out );
-                    dbg_curr =  g_dev.valve_curr_out;
-                }                    
-                if( g_dev.welding_start == 1 ){
-                    g_dev.welding_start = 0;
-                    g_dev.welding_time = 0;
-                }
-                //未焊接,调用这个函数不存储记录仅通过USB发送数据到上位机
-                welding_data_store( 0 );
-            }else{
-                //焊接状态
-                if( g_dev.welding_start == 0 ){
-                    //焊接启动
-                    g_dev.welding_start = 1;
-                    pid_ctrl_init(); //pid 初始化
-                    g_dev.welding_time = 0; //计时
-                }else{
-                    g_dev.welding_time += 100; //0.1秒扫描一次
-                }
+        //更新比例阀驱动电流
+        user_valve_set_current( g_dev.valve_curr_out );
 
-                double target_flowspeed;
-                if( calc_target_flow( &target_flowspeed )== 0 ){
-                    //控制流量输出, 按焊接电流和节气因子计算目标流量
-                    g_dev.target_flowspeed = target_flowspeed;
-                }
+        welding_data_store( g_dev.welding_time/100 ); //上报usb调试。
 
-                //根据目标流量,和实际流量,使用pid调整比例阀
-                pid_ctrl_update();
-                g_dev.valve_curr_out =  g_pidctrl.valve_current_out;
+        {   //检查报警
+            static uint32_t  count = 0;
+            if( count++ >= 9 ){ //1秒扫描一次
+                count = 0;
+                pressure_alarm_check();
+                flow_high_alarm_check();
+                flow_low_alarm_check();
+            }
+        }
+    }
+}
 
-                //焊接中,记录数据到spiflash,0.1秒一条
-                welding_data_store( g_dev.welding_time/100 );
+//流量高报检查
+void flow_high_alarm_check( void )
+{
+    static uint32_t alarm = 0;  //0 不报警, 1 计时待报警, 2 报警
+    static uint32_t alarm_start;
+
+    //流量过大(超过95%FS)
+    if( !(g_dev.state & FLOWMETER_ERR ) && g_dev.flowmeter.flow_speed >  (FLOW_SPEED_FS)*0.95f ){
+        if( alarm == 0 ){
+            alarm = 1;
+            alarm_start = xTaskGetTickCount(); //开始计时
+        }else if( alarm == 1 ){
+            if( xTaskGetTickCount() - alarm_start > 10*1000 ){ //计时到10秒,报警
+                alarm = 2;
+                g_dev.alarm.flow_high = 1;
             }
         }
+    }else{
+        alarm = 0;
+        g_dev.alarm.flow_high = 0;
+    }
+}
 
-        if( g_dev.debug_curr == 2 ){
-             valve_curr = g_dev.debug_valve_curr;
+//流量低报检查
+void flow_low_alarm_check( void )
+{
+    //2. 焊接时比例阀电流达到最大值 10秒后流量低于阈值,报警音   1长     --  响2秒,停0.2秒
+    uint32_t now;
+    float low_alarm_value; //阈值
+    static uint32_t alarm = 0;  //0 不报警, 1 计时待报警, 2 报警
+    static uint32_t alarm_start;
+
+    if( !(g_dev.state & FLOWMETER_ERR) && g_dev.cfg2.flow_low_alarm_x1000  ){
+        low_alarm_value = g_dev.cfg2.flow_low_alarm_x1000/1000.0f;
+
+        //报警条件判断: 焊接中, 目标流量大于阈值, 实际流量小于阈值
+        if( g_dev.welding_start 
+                && g_dev.target_flowspeed > low_alarm_value 
+                && g_dev.flowmeter.flow_speed < low_alarm_value
+                && g_dev.target_flowspeed > g_dev.flowmeter.flow_speed+0.2f ){
+
+            now = xTaskGetTickCount();
+            if( alarm == 0 ){
+                alarm = 1;
+                alarm_start = now; //开始计时,等待10秒报警
+            }else if( alarm == 1 ){
+                if(  now - alarm_start > 10*1000 ){
+                    //计时到10秒,报警
+                    alarm = 2;
+                    g_dev.alarm.flow_low = 1;
+                    alarm_start = now; //开始计时,等待10秒开直通阀
+                }
+            }else if( alarm == 2){
+#if 0
+                if(  now - alarm_start > 10*1000 ){
+                        //计时到10秒,开直通阀
+                        alarm = 3;
+                        if( g_dev.cfg.bypass == 0 ){
+                            g_dev.cfg.bypass = 1;
+                            ui_cfg_remote_update(); //刷新lcd
+                        }
+                }
+#endif
+            }
         }else{
-            valve_curr = g_dev.valve_curr_out;
+            alarm = 0;
+            g_dev.alarm.flow_low = 0;
         }
+    }else{
+        alarm = 0;
+        g_dev.alarm.flow_low = 0;
+       }
+}
 
-        //更新比例阀驱动电流
-        user_valve_set_current( valve_curr );
+//气压高报警
+void pressure_alarm_check( void )
+{
+    static uint32_t alarm = 0;  //0 不报警, 1 计时待报警, 2 报警
+    static uint32_t alarm_start;
+
+    //4. 气压传感器正常,气压大于 0.7Mpa*.95 10秒后报警
+    if( !(g_dev.state & PRESSURE_SENSOR_ERR ) && g_dev.pressure >  (PRESSURE_KPA_FS)*0.95f ){
+        if( alarm == 0 ){
+            alarm = 1;
+            alarm_start = xTaskGetTickCount(); //开始计时
+        }else if( alarm == 1 ){
+            if(  xTaskGetTickCount() - alarm_start > 10*1000 ){ //计时到10秒,报警
+                alarm = 2;
+                g_dev.alarm.pressure_high = 1; 
+            }
+        }
+    }else{ //气压恢复,停止报警
+        alarm = 0;
+        g_dev.alarm.pressure_high = 0;
     }
 }
+ 
\ No newline at end of file