//#include "main.h"
//#include "remote.h"
//#include "key.h"
#include "include.h"
const uint PULSE_SHORT_MIN=PULSE_SHORT_MIN_TIME/8/4; //1。8ms
const uint PULSE_SHORT_MAX=PULSE_SHORT_MAX_TIME/8/4; //3ms
const uint PULSE_LONG_MIN=PULSE_SHORT_MIN_TIME/8/4*3;
const uint PULSE_LONG_MAX=PULSE_SHORT_MAX_TIME/8/4*3;
const uint PULSE_SYN_MAX=PULSE_SHORT_MAX_TIME/8/4*35;
const uint PULSE_SYN_MIN=PULSE_SHORT_MIN_TIME/8/4*20;
const uint DT=(uint)((PULSE_SHORT_MIN_TIME/8/4+PULSE_SHORT_MIN_TIME/8/4)*0.1/2);
bank2 SharkFlagStruct SharkFlag={2};
bank1 ulong PassWord[2]; //waste 2B ram; 20bit
static bank1 RemindStateEnum RemindState=DOOR_OPEN;
static bank1 uchar PressUnlock=0;
static Timer16Struct GuardQuiet5s={0,1}; //延时5s进入警戒状态;
static bank1 AlarmGradeEnum AlarmGrade=Guard;
static bank1 OpenStepEnum OpenStep=OPEN_REMIND;
static EnergencyEnum Energency=PRESS_FIND;
static bank1 bit SystemGuardChangeFirstTime=0;
bank2 LearnStepEnum LearnStep=FRIST_DATA;
bank2 Timer16Struct AlarmSharkTimer={0,0};
bank1 Timer16Struct DoorOpenTimer={0,0};
bank1 uchar AlarmNoub=0;
bit remote_key_dither(ulong data)
{
static bank1 ulong LastRemote;
if(data==LastRemote)
{
if(RemoteKey.Flag.FirstPress==1)
{
RemoteKey.Flag.Press=1;
RemoteKey.Flag.FirstPress=0;
RemoteKey.Key=get_key(data);
RemoteKey.Rec=data;
}
RemotePressTimeOut.Interval=0;
RemoteKey.Time.Interval=RemotePressTime.Interval;
RemotePressTime.enable=1;
RemotePressTimeOut.enable=1;
LastRemote=data;
//RemoteKey.Key=get_key(data);
return 1;
}
else
{
//for error process;
RemoteKey.Flag.Release=0;
RemoteKey.Flag.Press=0;
RemoteKey.Flag.FirstPress=1;
RemotePressTime.Interval=0;
}
LastRemote=data;
return 0;
}
ulong get_password(ulong data)
{
//ulong pass;
//pass=(data&0x00ffffff)>>4;
//return(pass);
return((data&0x00ffffff)>>4);
}
uchar get_key(ulong data)
{
ulong pd;
uchar KeyValue;
pd=data&0x0f;
KeyValue=(uchar)(pd);
if(KeyValue==0x08) return KEY_LOCK;
else if(KeyValue==0x0c) return KEY_UNLOCK;
else if(KeyValue==0x03) return KEY_QUIET;
else if(KeyValue==0x0f) return KEY_FIND;
#ifdef BOOT_EN
else if(KeyValue==0x04) return KEY_BOOT;
#endif
else return KEY_UNKNOW;
}
bit decode(ulong data)
{
ulong Word;
Word=get_password(data);
if(PassWord[0]==Word||PassWord[1]==Word)
return 1;
else return 0;
}
//void remind_shutdown(void)
bit remind_shutdown(void)
{
static bank1 Timer16Struct DelayTime=0;
if(InState.SideDoor==DOOR_OPENED)
{
RemindState=DOOR_OPEN;
DelayTime.Interval=0;
}
switch(RemindState)
{
case DOOR_OPEN:
if(InState.SideDoor==DOOR_OPENED)
RemindState=DOOR_CLOSE;
break;
case DOOR_CLOSE:
if(InState.SideDoor==DOOR_CLOSED)
{
RemindState=DELAY_5S;
DelayTime.Interval=0;
}
break;
case DELAY_5S:
if(DelayTime.Interval++>=REMIND_SHUT_DELAY_TIME)
{
DelayTime.Interval=0;
RemindState=REMIND;
speak_act_precoss(0,0,0,RESET); //reset speak;
}
break;
case REMIND:
flash_trun_signal(120/TIME_BASE,1400/TIME_BASE,3);
if(speak_act_precoss(40/TIME_BASE,1480/TIME_BASE,3,SHORT))
{
RemindState=DELAY_60S;
flash_trun_signal(0,0,0);
speak_act_precoss(0,0,0,RESET);
}
break;
case DELAY_60S:
if(DelayTime.Interval++>=REMIND_DELAY_60S)
{
RemindState=CHANGE_STATE;
DelayTime.Interval=0;
}
break;
case CHANGE_STATE:
RemindState=STATE_END;
if(Jump.SlefThorth)
{
system_state_change(State,GUARD_QUIET,1);
return 1;
}
//PreState=State;
//State=GUARD_QUIET;
break;
case STATE_END:
break;
default:break;
}
return 0;
}
bit alarm_led_long_light(uchar LightTime,uchar DrownTime)
{
static Timer16Struct RunTime=0;
if(LightTime==0)
{
RunTime.Interval=0;
ALARM_LED=0;
}
else
{
if(++RunTime.Interval<=LightTime*125)
{
ALARM_LED=1;
}
else if(RunTime.Interval<=125*(LightTime+DrownTime))
ALARM_LED=0;
else
{
RunTime.Interval=0;
return 1;
}
}
return 0;
}
/*
////////////////////////////////////////////
// Times :125ms //
// Second: 1s //
////////////////////////////////////////////
void flash_alarm_led(uchar Times,uchar Second)
{
if(AlarmLed.Flag.ms125)
{
AlarmLed.Flag.ms125=0;
AlarmLed.Flag.Time++;
if(AlarmLed.Flag.Time<=Times)
ALARM_LED=!ALARM_LED;
else if(AlarmLed.Flag.Time<=Times+Second*8) //2s
ALARM_LED=0;
else
AlarmLed.Flag.Time=0;
}
}
*/
bit flash_alarm_led(uchar Times,uchar Second)
{
if(AlarmLed.Flag.ms125)
{
AlarmLed.Flag.ms125=0;
AlarmLed.Flag.Time++;
if(AlarmLed.Flag.Time<=Times)
ALARM_LED=!ALARM_LED;
//ALARM_LED=1;
else if(AlarmLed.Flag.Time<=Times+Second*8) //2s
ALARM_LED=0;
else
{
AlarmLed.Flag.Time=0;
return 1;
}
}
return 0;
}
void signal_led_alarm(AlarmGradeEnum state)
{
if(state==Guard)
flash_alarm_led(4,2);
else if(state==Shaked)
flash_alarm_led(6,2);
else if(state==Opened)
alarm_led_long_light(4,4);
else if(state==Unchain)
alarm_led_long_light(6,0);
}
uchar flash_trun_signal(uint PulseTime1,uint Interval1,uchar Times1)
{
static bank2 uint RunTime1=0;
static bank2 uchar CTime1=0; //continuance time;
Used.TrunSignal=1;
if((PulseTime1==0)&&(Interval1==0))
{
Used.TrunSignal=0;
RunTime1=0;
TRUN_SIGNAL=0;
CTime1=0;
return 1;
}
else
{
if(CTime1<Times1)
{
if(++RunTime1<=PulseTime1)
TRUN_SIGNAL=1;
else if(RunTime1<=(PulseTime1+Interval1))
TRUN_SIGNAL=0;
else
{
CTime1++;
RunTime1=0;
}
return 0;
}
else
{
CTime1=Times1;
TRUN_SIGNAL=0;