|
#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 "deca_device_api.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();
|
#ifdef WORK_MODE_TAG
|
RTC_Configuration();
|
#endif
|
Led_Init();
|
Beep_Init();
|
DW_GPIO_Init();
|
Uart1_Init();
|
Spi_Init();
|
|
|
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
|
}
|
|
void Parameter_Init(void)
|
{
|
Usart1ParseDataCallback = UsartParseDataHandler;
|
}
|
|
/*! ------------------------------------------------------------------------------------------------------------------
|
* @fn main()
|
*
|
* @brief Application entry point.
|
*
|
* @param none
|
*
|
* @return none
|
*/
|
extern uint8_t send_start;
|
int main(void)
|
{
|
LPFilter_Frac* p_Dis_Filter;
|
|
Device_Init();
|
Parameter_Init();
|
Dw1000_Init();
|
p_Dis_Filter = New_LP_Frac(0.7);
|
|
#ifdef WORK_MODE_TAG
|
dwt_configuresleep(0x940, 0x7);
|
_dwt_aonarrayupload();
|
//dwt_entersleep();
|
#endif
|
|
/* Loop forever initiating ranging exchanges. */
|
while(1)
|
{
|
#ifdef WORK_MODE_TAG
|
|
if(send_start)
|
{send_start=0;
|
Tag_App();
|
}
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
|
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
|
#else
|
Anchor_App();
|
|
#endif
|
|
//³ýUWBÖ®ÍâµÄÆäËû´úÂë...
|
dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);
|
|
if(dis_after_filter <= g_alarm_dist)
|
{
|
// 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_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_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;
|
}
|
}
|
|
|
|
}
|
}
|