#ifndef KEYPAD_H_
#define KEYPAD_H_

#include "gType.h"

typedef union
{
	unsigned int D32;
	volatile unsigned char state_val[4];
	struct
	{
		volatile unsigned int shield 			: 2; /* [1-0] */
		volatile unsigned int take_charge         : 2; /* [3-2] */
		volatile unsigned int feedback            : 2; /* [5-4] */
		volatile unsigned int start_delay         : 2; /* [7-6] */
		volatile unsigned int start               : 2; /* [9-8] */
		volatile unsigned int mute             	: 2; /* [11-10] */
		volatile unsigned int fault               : 2; /* [13-12] */
		volatile unsigned int alarm               : 2; /* [15-14] */
		volatile unsigned int auto_state          : 1; /* [16] */
		volatile unsigned int manual_state        : 1; /* [17] */
		volatile unsigned int self_check          : 2; /* [19-18] */
		volatile unsigned int ScreenSave          : 2; /* [21-20] */
		volatile unsigned int normal_check        : 2; /* [23-22] */
		volatile unsigned int alarm_fault         : 2; /* [25-24] */
		volatile unsigned int alarm_start         : 2; /* [27-26] */
		volatile unsigned int buzzer              : 4; /* [31-28] */
	}state;
}TSys_State_Struct;


typedef enum{
	Off = 0,
	Flicker = 1,
	FullOn =2
}TKeyPadLedState;

class TKeyPad{
	public:
		TSys_State_Struct LedState;
		unsigned int FbMissCountOld;
		unsigned int IsReqPowerSuplyCount;
		unsigned int IsSendPowerSuplyCount;
	
		int SilenceTick;
		int IsOffline;
	private:
		
	
	public:
		TKeyPad(){
			LedState.D32 = 0;
			IsReqPowerSuplyCount = 0;
			IsSendPowerSuplyCount = 0;
			SilenceTick = 0;
			IsOffline = 0;
		}
		void Init();
		void InitKeyPad();
		
		void SendResetCmd();
		void SendSelfCheckCmd();
		void SendPowerSuplyCount();
		void KeyPadLedSetSuperSv(TKeyPadLedState	aSta);
		void KeyPadLedSetFeedBack(TKeyPadLedState	aSta);
		void KeyPadLedSetStartDelay(TKeyPadLedState	aSta);
		void KeyPadLedSetStart(TKeyPadLedState	aSta);
		void KeyPadLedSetMute(TKeyPadLedState	aSta);
		void KeyPadLedSetFault(TKeyPadLedState	aSta);
		void KeyPadLedSetAlarm(TKeyPadLedState	aSta);
		void KeyPadLedSetLinkage(TKeyPadLedState	aSta);
		void KeyPadLedSetSelfCheck(TKeyPadLedState	aSta);

		void KeyPadLedSetNormalCheck(TKeyPadLedState	aSta);
		void KeyPadLedSetAlarmFault(TKeyPadLedState	aSta);
		void KeyPadLedSetAlarmStart(TKeyPadLedState	aSta);
		void KeyPadLedSetMask(TKeyPadLedState	aSta);
		
		void SetLedStateViaInteger(unsigned int);
		unsigned int GetLedStateViaInteger();

		static void sInit(TSys_State_Struct *fState);
		static void sInitKeyPad(TSys_State_Struct *fState);
		static void sKeyPadLedSetSuperSv(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetFeedBack(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetStartDelay(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetStart(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetMute(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetFault(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetAlarm(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetLinkage(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetNormalCheck(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetAlarmFault(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetAlarmStart(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetSelfCheck(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetMask(TSys_State_Struct *fState, TKeyPadLedState	aSta);
		static void sKeyPadLedSetBuz(TSys_State_Struct *fState, unsigned char aSta);
		
		static void sKeyPadLedSetAutoAllowState(TSys_State_Struct *fState, unsigned char aSta);
		static void sKeyPadLedSetManualAllowState(TSys_State_Struct *fState, unsigned char aSta);
		
		static void sKeyPadLedSetScreenSaveState(TSys_State_Struct *fState, unsigned char aSta);
		
		void sSendState();
		void SendDumpCmd();
		
		void CheckKeyPadOffline();
		void ForceClearSysErrLed();
};


























#endif


