#include "IOSTM8S103F3.h"
#include "main.h"
#include "Definition.h"
#include "menu.h"
#include "flash_eeprom.h"
#include "Buzzer.h"
#include "receive.h"
void OperationForArmMode(void);
void OperationForDisarmMode(void);
void PrepareFootLock(void);
void SirenForArm(void);
void PowerOnScanInput(void);
void BackToSystemMain(void);
void ComplexOperation(void);
extern struct Work_Register WRC;
INT8U InvalidBit = 0;
void (*p_MenuMode)(void) = powerOn;//系統模式,函數指針
void powerOn(void)
{
if (!g_System_ram.Initial)
{
g_System_ram.Initial = TRUE;
g_Time_ram.TimeBase_100ms = 0;
g_System_ram.SysStatus = SYS_POWERON;
P_EngineOffOut = FALSE;
WRC.LightCntTemp = 30;
g_Time_ram.CheckJump0Time = 0;
g_Time_ram.CheckJump1Time = 0;
g_Time_ram.CheckJump2Time = 0;
}
else
{
PowerOnScanInput();
if (g_Time_ram.TimeBase_100ms >= 5)
{
WRC.AccInLowGoingEdgeBit = 0;
WRC.AccInHiGoingEdgeBit = 0;
WRC.DoorInLowGoingEdgeBit = 0;
WRC.DoorInHiGoingEdgeBit = 0;
if (!P_ResetIn)
{
p_MenuMode = TestMode;
g_System_ram.Initial = FALSE;
}
else
{
if (WRC.AccInBit)
{
p_MenuMode = DisarmMode;
WRC.StopFlashBit = 1;
g_System_ram.Initial = TRUE;
}
else
{
p_MenuMode = ArmMode;
g_System_ram.Initial = FALSE;
}
}
}
}
}
void ArmMode(void)
{
static INT8U buzzerBit = 0;
if (!g_System_ram.Initial)
{
g_System_ram.AlarmStatus = AlarmForNone;
WRC.DoorInLowGoingEdgeBit = 0;
WRC.AccInHiGoingEdgeBit = 0;
WRC.DoorAlarmBit = 0;
WRC.AccAlarmBit = 0;
P_MidLockOut = TRUE;
P_MidOpenOut = FALSE;
WRC.DoorDelayBit = 0;
if (!buzzerBit)
{
buzzerBit = 1;
SirenForArm();
InvalidBit = 1;
g_Time_ram.TimeBase_100ms = 0;
}
if (!buzzer_ram.BuzzerCnt)
{
if (InvalidBit)
{
g_Time_ram.TimeBase_1ms = 0;
P_LampOut = TRUE;
InvalidBit= 0;
}
g_Time_ram.TimeBase_10ms = 0;
g_Time_ram.Timer_100ms = 0;
g_Time_ram.Timer_1000ms = 0;
g_Time_ram.Timer_10ms = 0;
g_System_ram.Initial = TRUE;
}
else
{
g_Time_ram.TimeBase_1ms = 0;
}
if (g_Time_ram.TimeBase_100ms >= 8)//电锁 0.8s
{
P_MidLockOut = FALSE;
g_Time_ram.TimeBase_100ms = 8;
}
if (g_Time_ram.TimeBase_1ms >= 214)//方向灯闪灯时间
{
P_LampOut = FALSE;
g_System_ram.Initial = TRUE;
if ((WRC.DoorInBit)||(!WRC.Jump0InBit))
{
P_EngineOffOut = TRUE;
}
}
else
{
g_System_ram.Initial = FALSE;
}
if (g_System_ram.Initial)
{
buzzerBit = 0;
}
}
else
{
if (g_Time_ram.TimeBase_100ms >= 8)//电锁 0.8s
{
P_MidLockOut = FALSE;
g_Time_ram.TimeBase_100ms = 8;
OperationForArmMode();
}
if (WRC.LightCntTemp < 30)
{
if ((g_Time_ram.Timer_10ms >= 41)&&(P_LampOut))
{
P_LampOut = FALSE;
WRC.LightCntTemp++;
g_Time_ram.Timer_10ms = 0;
}
if ((g_Time_ram.Timer_10ms >= 41)&&(!P_LampOut))
{
P_LampOut = TRUE;
g_Time_ram.Timer_10ms = 0;
}
}
if (WRC.DoorInBit)
{
P_EngineOffOut = TRUE;
}
if (P_EngineOffOut)
{
if (!WRC.SecondRelockBit)
{
WRC.SecondRelockLedStatus = 1;
}
if (g_Time_ram.TimeBase_10ms >= 50)
{
P_LedOut = !P_LedOut;
g_Time_ram.TimeBase_10ms = 0;
}
if (g_Time_ram.Timer_100ms >= 50)//设防后,5秒再去检查边门信号
{
if (!WRC.ShockSensorBit)
{
if ((!P_ShockIn)&&(g_Time_ram.CheckShockInTime >= 20))
{
p_MenuMode = SlightShockMode;
g_System_ram.Initial = FALSE;
}
else
{
if (P_ShockIn)
{
g_Time_ram.CheckShockInTime = 0;
}
}
}
if (((!WRC.DoorInBit&&!WRC.ArmStopBit))
||(WRC.AccInBit))
{
if (WRC.DoorDelayBit)
{
if ((WRC.DoorInLowGoingEdgeBit)||(WRC.AccInBit))
{
p_MenuMode = AlarmMode;
g_System_ram.Initial = FALSE;
}
}
else
{
p_MenuMode = AlarmMode;
g_System_ram.Initial = FALSE;
}
}
}
}
else
{
if (g_Time_ram.Timer_1000ms >= 20)
{
p_MenuMode = DoorOpenLockMode;
g_System_ram.Initial = FALSE;
}
if (WRC.AccInBit)
{
p_MenuMode = DoorOpenAlertMode;
g_System_ram.Initial = FALSE;
}
}
if (p_MenuMode != ArmMode)
{
g_System_ram.SysStatus = SYS_ARM;
WRC.ArmStopBit = 0;
}
}
}
void DisarmMode(void)
{
static INT8U LightCnt,buzzerBit = 0;
if (!g_System_ram.Initial)
{
WRC.AccInLowGoingEdgeBit = 0;
WRC.AccInHiGoingEdgeBit = 0;
WRC.DoorInLowGoingEdgeBit = 0;
WRC.DoorInHiGoingEdgeBit = 0;
WRC.FootEnableBit = 0;
WRC.ArmStopBit = 0;
P_MidLockOut = FALSE ;
P_MidOpenOut = TRUE;
WRC.DoorDelayBit = 0;
WRC.AnitHiJackBit = 0;
WRC.PrepareAnitHiJackBit = 0;
LightCnt = 0;
WRC.AccInLowBit = 0;
WRC.LightCntTemp = 30;
WRC.TrunkTempBit = 0;
if (WRC.SecondRelockBit)// 二次上锁
{
P_LedOut = FALSE;
}
if (!buzzerBit)
{
buzzerBit = 1;
g_Time_ram.TimeBase_100ms = 0;
if ((!WRC.ChirpBit)&&(g_System_ram.AlarmStatus == AlarmForNone))
{
if (!WRC.SilenceLockBit)
{
Buzzer_Bz_Bz();
}
}
else if (g_System_ram.AlarmStatus == AlarmForDoor)
{
Buzzer_Bz_Bz_Bz();
}
else if (g_System_ram.AlarmStatus == AlarmForSensor)
{
Buzzer_Bz_Bz_Bz_Bz();
}
else if (g_System_ram.AlarmStatus == AlarmForIgnition)
{
Buzzer_Bz_Bz_Bz_Bz_Bz();
}
}
if (!buzzer_ram.BuzzerCnt)
{
g_System_ram.Initial = TRUE;
g_Time_ram.TimeForAutoLock_100ms = 0;
g_Time_ram.Timer_1000ms = 0;
g_Time_ram.Timer_10ms = 0;
buzzerBit = 0;
P_LampOut = TRUE;
}