forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

wujiazhi
2024-06-11 65062d0d5b21f838aa0043a15ce54cfab8d72c43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "check_out.h"
#include "gpio.h"
 
#define                LOW_FLOW_CNT                3
#define                CHECK_PERIOD                250
#define                WORK_FLOW_PARA            14400
 
CHECK_CAL_INF     check_cal_g = {
    .device_type = G10
};
 
uint8_t    get_led_para_output_flag(void)
{
    return    check_cal_g.pluse_flag;
}
 
 
void set_led_para_output_flag(uint8_t flag)
{
    check_cal_g.pluse_flag = flag;
}
/*½øÈëϵͳ±ê¶¨Ö®Ç°µÄ³õʼ»¯¹¤×÷*/
void  led_para_output_init(void)
{
    
    switch (check_cal_g.device_type)
    {
        case G6:     check_cal_g.check_fre             = 0.005; 
                            check_cal_g.check_fre_low     = 0.001;
                            check_cal_g.check_fre_flow     = 0.9;
                            break;
        case G10:  check_cal_g.check_fre             = 0.01; 
                            check_cal_g.check_fre_low     = 0.005;
                            check_cal_g.check_fre_flow     = 1.45;
                            break;
        case G16: check_cal_g.check_fre             = 0.01; 
                            check_cal_g.check_fre_low     = 0.005;
                            check_cal_g.check_fre_flow     = 2.3;
                            break;
        case G25: check_cal_g.check_fre             = 0.01; 
                            check_cal_g.check_fre_low     = 0.005;
                            check_cal_g.check_fre_flow     = 3.70;
                            break;
    
        default:    break;
 
    }
    
    
        check_cal_g.check_utotal        = 0.1;
        check_cal_g.low_pluse_out     = check_cal_g.check_utotal;
        check_cal_g.pluse_flag            = 0;
        check_cal_g.low_pluse_cnt        =    0;
        check_cal_g.work_period            = CHECK_PERIOD;
        LED_LOW;
        //LOWER_PLUSE_LOW
    
}
 
 
uint16_t led_pluse_out(double flow)
{
    uint8_t        new_pluse;
    double        data_differ;
    double        led_data_delay;
    uint16_t   time;
    /*µÍƵÂö³åͨ¹ýÒ»¸ö¾ÃµÄÀۼƼǼԭÏȵÄÀÛ¼ÆÁ¿*/
    
    check_cal_g.uvol        =        flow;
    check_cal_g.check_utotal = check_cal_g.check_utotal + check_cal_g.uvol;//ÀÛ¼ÆÁ÷Á¿
    check_cal_g.workConInstantFlow = check_cal_g.uvol * WORK_FLOW_PARA;
    
    /*ÅжÏÁ÷Á¿ÓÃÓÚÉ趨µÆÉÁƵÂÊ,СÁ÷Á¿Çл»*/
    if(check_cal_g.workConInstantFlow < check_cal_g.check_fre_flow)
    {
        /*Ï໥»º³åÉèÖÃ*/
        if(check_cal_g.low_pluse_cnt == LOW_FLOW_CNT)
        {
            data_differ = check_cal_g.check_fre_low;
        }else
        {
            check_cal_g.low_pluse_cnt ++;
        }
    }else
    {
        /*Ï໥»º³åÉèÖÃ*/
        if(check_cal_g.low_pluse_cnt == 0)
        {
            data_differ = check_cal_g.check_fre;
        }else
        {
            check_cal_g.low_pluse_cnt --;
        }
    }
    
    //data_differ = cal_gas_struct_g.check_fre;
    if(check_cal_g.low_pluse_out <= 0)
    {
        check_cal_g.low_pluse_out = check_cal_g.check_utotal;
    }
    
    //Èç¹û¼ÓÆðÀ´ ±ÈËü´ó£¬ÄÇôÌáǰԤ²âÊä³öledµÄÐźš£
    if((check_cal_g.check_utotal) >= (check_cal_g.low_pluse_out + data_differ))
    {
        
            if(check_cal_g.uvol > data_differ)    //Òì³£Çé¿öÏ·µ»Ø,²»¼Æ±ê¶¨
            {
                check_cal_g.pluse_flag    = 0;
                return 0;
            }
            //Test_101_P
        //    if(check_cal_g.pluse_flag    == 0)
            {
                led_data_delay = check_cal_g.check_utotal - (check_cal_g.low_pluse_out + data_differ) ;
                led_data_delay = 1 - (led_data_delay / check_cal_g.uvol);
                led_data_delay = check_cal_g.work_period * led_data_delay;//Ô¤²âʱ¼ä¡£ÔÚ´ïµ½¼ÆËãʱ¼äʱÁÁµÆ¡£
                /*Ô¤²âʱ¼äÊÇ·ñ´ïµ½ÉÁµÆµÄÁ÷Á¿µã¡£*/
                //Test_001_P    
                if(led_data_delay <= 0)
                {
                    //    Test_011_P
                        LED_HIGH;
                        delay_ms(35);
                        LED_LOW;
                        time = 0;
                        //Test_011_P
                }else if(led_data_delay  < (double) (check_cal_g.work_period - 60))
                {
                    
                        
                        //Test_111_P
                        if(led_data_delay < 2)
                            time = 1;
                        else
                            time = (uint16_t)led_data_delay;
                        
                        delay_ms(time);
                        //Test_100_P
                        LED_HIGH;
                        delay_ms(35);
                        LED_LOW;
                        
                }else
                {
                        //Test_100_P
                        delay_ms(check_cal_g.work_period - 60);
                        LED_HIGH;
                        delay_ms(35);
                        LED_LOW;
                        time = check_cal_g.work_period - 60;
                        
                }
                //Test_110_P
                check_cal_g.low_pluse_out = check_cal_g.low_pluse_out + data_differ;
                check_cal_g.pluse_flag        = 1;//Èç¹ûÕâÒ»¸öÖÜÆÚ´ïµ½ÒªÇóÁË»òÕß³öÏÖ³¬¹ý10L/sÕâÖÖÇé¿öÏȲ»¿¼ÂÇ¡£
            
 
            }
            
                return (36 + time);
    }
    return 1;
    
}