133 lines
1.6 KiB
C
133 lines
1.6 KiB
C
#include "app.h"
|
|
|
|
volatile struct radval_t {
|
|
uint16_t aa;
|
|
uint16_t bb;
|
|
}radval;
|
|
|
|
uint8_t rad_status = 0;
|
|
uint8_t hhindex = 0;
|
|
uint8_t hhcount = 0;
|
|
|
|
uint16_t ttdata1[24];
|
|
uint16_t tttimes = 0;
|
|
uint16_t wwtimes = 0;
|
|
|
|
volatile uint32_t tt_count = 0;
|
|
volatile uint32_t hh_wait = 0;
|
|
volatile uint32_t rad_wait = 0;
|
|
|
|
void rad_init(void)
|
|
{
|
|
rad_sethh();
|
|
tt_count = SEC(6);
|
|
}
|
|
|
|
void rad_tick(void)
|
|
{
|
|
if(tt_count < 0xFFFFFFFF)
|
|
{
|
|
tt_count++;
|
|
}
|
|
}
|
|
|
|
void rad_loop(void)
|
|
{
|
|
api_radar_read((uint16_t *)&radval);
|
|
if(radval.bb >= param.cb.a)
|
|
{
|
|
rad_status = 1;
|
|
if(rad_wait > 0)
|
|
{
|
|
api_led_set(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rad_status = 0;
|
|
api_led_set(0);
|
|
}
|
|
|
|
if((rad_status != 0) && tt_count > SEC(10))
|
|
{
|
|
tt_count = 0;
|
|
light_set_trig();
|
|
ttdata1[hhindex]++;
|
|
if(mftest.status == 0)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//ÿ100msÖ´ÐÐÒ»´Î
|
|
void rad_100ms(void)
|
|
{
|
|
if(hh_wait > 0 && --hh_wait == 0)
|
|
{
|
|
|
|
}
|
|
if(wwtimes != 0)
|
|
{
|
|
wwtimes--;
|
|
|
|
}
|
|
if(rad_wait > 0)
|
|
{
|
|
rad_wait--;
|
|
}
|
|
}
|
|
|
|
void rad_minute(void)
|
|
{
|
|
if(++hhcount >= 60)
|
|
{
|
|
hhcount = 0;
|
|
tttimes = 0;
|
|
for(uint8_t i = 0, index = hhindex; i < 24; i++)
|
|
{
|
|
tttimes += ttdata1[index];
|
|
index = (index > 0) ? (index-1) : (23);
|
|
}
|
|
hhindex = (hhindex + 1) % 24;
|
|
ttdata1[hhindex] = 0;
|
|
}
|
|
}
|
|
|
|
void rad_sethh(void)
|
|
{
|
|
hh_wait = 600 + (api_random()%600);
|
|
}
|
|
|
|
void rad_setout(uint8_t type, uint8_t wait)
|
|
{
|
|
if(type == 0) //Í£Ö¹²¨ÐÎ
|
|
{
|
|
wwtimes = 0;
|
|
}
|
|
else if(wait < 100)
|
|
{
|
|
wwtimes = wait * 600;
|
|
}
|
|
else
|
|
{
|
|
wwtimes = 65535;
|
|
}
|
|
}
|
|
|
|
void rad_setled(uint16_t wait)
|
|
{
|
|
rad_wait = wait * 10;
|
|
}
|
|
|
|
uint8_t rad_getstat(void)
|
|
{
|
|
return rad_status;
|
|
}
|
|
|
|
uint32_t rad_getcount(void)
|
|
{
|
|
return tt_count;
|
|
}
|
|
|