guanjiao
2018-09-15 08187305f2971d0e46fc919bb16ffd7d0a27b81a
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
 
#include "Rcc_Nvic_Systick.h"
#include "Usart.h"
#include "Spi.h"
#include "led.h"
#include "beep.h"
#include "dw_driver.h"
#include "dw_app.h"
#include "filters.h"
#include "stm32f10x_it.h"
#include "serial_at_cmd_app.h"
#include "global_param.h"
 
//#define WORK_MODE_TAG
#define WORK_MODE_ANCHOR
#define START_ALARM_DIST_CM            200
#define BEEM_ON_TIME_MS                200
 
float dis_after_filter = 500;
 
void Device_Init(void)
{
//    Rcc_Init();
    SystemInit();
    Nvic_Init();
    Systick_Init();
    Led_Init();
    Beep_Init();
    DW_GPIO_Init();
    Uart1_Init();
    Spi_Init();
    
    
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
}
 
void Program_Init(void)
{
    Usart1ParseDataCallback = UsartParseDataHandler;
    parameter_init();
}
 
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn main()
 *
 * @brief Application entry point.
 *
 * @param  none
 *
 * @return none
 */
int main(void)
{
    LPFilter_Frac* p_Dis_Filter;
    
    Device_Init();
    Program_Init();
    Dw1000_Init();
    p_Dis_Filter = New_LP_Frac(0.7);
 
    /* Loop forever initiating ranging exchanges. */
    while(1)
    {
#ifdef WORK_MODE_TAG
        Tag_App();
#else 
        Anchor_App();
 
#endif
        
        //³ýUWBÖ®ÍâµÄÆäËû´úÂë...
        dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);
        
        if(dis_after_filter <= g_com_map[ALARM_DISTANCE])
        {
//            g_beep_off_time = (uint32_t)dis_after_filter * 10;
//            if(g_beep_off_time <= 0) 
//                g_beep_off_time = 0;
//            g_beep_on_time = BEEM_ON_TIME_MS;
            switch(g_com_map[ALARM_DEV]) 
            {
                case 0:
                    BEEP2_ON;
                    BEEP_OFF;
                    OUT2_OFF;
                    break;
                case 1:
                    BEEP_ON;
                    BEEP2_OFF;
                    OUT2_OFF;
                    break;
                case 2:
                    OUT2_ON;
                    BEEP_OFF;
                    BEEP2_OFF;
                    break;
                default:
                    BEEP2_ON;
                    BEEP_ON;
                    OUT2_ON;
                    break;
            }
        }
        else
        {
//            g_beep_on_time = 0;
//            g_beep_off_time = 0;
            switch(g_com_map[ALARM_DEV]) 
            {
                case 0:
                    BEEP2_OFF;
                    break;
                case 1:
                    BEEP_OFF;
                    break;
                case 2:
                    OUT2_OFF;
                    break;
                default:
                    BEEP2_OFF;
                    BEEP_OFF;
                    OUT2_OFF;
                    break;
            }
        }
        
 
        
    }
}