/**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
* File Name          : IRScan.h
* Author             : Billy Long Fortiortech  Market Dept
* Version            : V1.0
* Date               : 01/07/2015
* Description        : This file contains all the common data types used for Motor Control.
***************************************************************************************************
* All Rights Reserved
**************************************************************************************************/ 

/* Define to prevent recursive inclusion --------------------------------------------------------*/
#ifndef __IRSCAN_H_
#define __IRSCAN_H_

#define		ShortPressMode					(0)
#define		LongPressMode					(1)
#define		UserCodeStudyMode				(ShortPressMode)					//遥控学习模式：ShortPressMode:短按某个键执行学习；
																																						//LongPressMode：长按某个键学习
#define		StudyCode						(0x0FC0)						//对应执行学习功能的按键

#define 	UserCodeLength					(16)//(20)							//定义遥控地址码长度
#define 	DataCodeLength					(10)//(8)								//定义遥控数据码长度
#define		CheckCodeLengh					(0)//(4)
#define		AllCodeLength					(UserCodeLength+DataCodeLength+CheckCodeLengh)

#define		FrameCodeLength					(26)//(4)

/*IR Scan Parameter*/                         
#define 	IRBitValue1TimeMax				(1.0)							// 数据为1时高电平长度最大值，单位ms
#define 	IRBitValue1TimeMin				(0.55)							// 数据为1时高电平长度最小值，单位ms
#define 	IRBitValue0TimeMax				(0.54)							// 数据为0时高电平长度最大值，单位ms
#define 	IRBitValue0TimeMin				(0.1)							// 数据为0时高电平长度最小值，单位ms
#define 	IRLeadCodeTimeMax				(11.0)							// 引导码周期长度最大值，单位ms
#define 	IRLeadCodeTimeMin				(8.0)							// 引导码周期长度最小值，单位ms

/*IR Scan*/
#define TempBitValue1Max					(uint16)(IRBitValue1TimeMax*TIM3_Fre)
#define TempBitValue1Min					(uint16)(IRBitValue1TimeMin*TIM3_Fre)
#define TempBitValue0Max					(uint16)(IRBitValue0TimeMax*TIM3_Fre)
#define TempBitValue0Min               		(uint16)(IRBitValue0TimeMin*TIM3_Fre)
#define TempLeadCodeMax              		(uint16)(IRLeadCodeTimeMax*TIM3_Fre)
#define TempLeadCodeMin             		(uint16)(IRLeadCodeTimeMin*TIM3_Fre)

/*遥控码定义*/
#define IRONOFF                          	(0X16)

#define	IRLEVELMASK                         (0xF000)
#define	IRALLOFF							(0xF000)  //关机电源
#define IRSpeed1                         	(0XE000)
#define IRSpeed2                         	(0XD000)
#define IRSpeed3                         	(0XC000)
#define IRSpeed4                         	(0XB000)
#define IRSpeed5                         	(0XA000)
#define IRSpeed6                         	(0X9000)
#define IRSpeed7                         	(0X8000)
#define IRSpeed8                         	(0X7000)
#define IRSpeed9                         	(0X6000)
#define	IRNatureWind3						(0x4000)
#define	IRNatureWind6						(0x3000)
#define	IRNatureWind9						(0x2000)

#define IRDIRMASK                           (0X0C00)
#define IRFRCW                             	(0X0400)
#define IRFRCCW                             (0X0800)

#define IRDATAMASK                          (0X03C0)
#define	IRAUTOPOWER0H						(0X0180)
#define	IRAUTOPOWER1H						(0X0280)
#define	IRAUTOPOWER2H						(0X0200)
#define	IRAUTOPOWER4H						(0X00C0)
#define IRLEDDIM                            (0X02C0)//调光开关
#define IRLED                        		(0X0380)//无调光
#define IRDIMEERADD                         (0X0340)
#define IRDIMEERSUB                         (0X0300)

#define	IRLEARN						        (0x0FC0)

/* Exported types -------------------------------------------------------------------------------*/
typedef struct
{	
	uint32 BitValue;
	uint8  BitCnt;
	uint16 Bit0Cnt;
	uint32 ByteValue;
	
	uint32 UserCode;
	uint16 DataCode;
	uint32 CurrentUserCode;
	uint16 CurrentDataCode;

	uint8  IRReceiveFlag;
	uint8  OldDataCodeMixTimes;
	uint8  ValidDataCnt;
    uint8  DiffFlag;
    
	uint32 UserCodeLengthCover;
	uint32 DataCodeLengthCover;	
	
	uint8 OverFlowStatus;
	
	uint16 TempDataCode[4];
	uint8 DataCodeNum;
} IRScan_TypeDef;

typedef struct
{	
	uint8   FlagONOFF;
	uint8   ONOFFStatus;
	uint8   FlagFR;
	uint8   FlagSpeed;

	uint8	FlagNatureWind;
	uint8	FlagAutoPower;
	uint16  RunTimeLong;
	uint16  TargetSpeed;
	uint8	FlagUserCodeSave;	
	uint8   FlagUserCodeRead;
	uint16	SpeedLevel[10];
	
	uint16  SpeedInFlash;	
	uint8   FlagLED;
	uint8   LEDONOFFStatus;
	uint8   FlagLEDPWMUpdate;	
	uint16	LEDPWMDuty;	
} IRControl_TypeDef;

typedef struct
{	
	uint8   FlagAutoPower;
	uint16  Timer10sec;
	uint16  ShutDowntime;
	uint16  CurrentTime;
} IRControl_AutoPowerDef;

extern IRControl_AutoPowerDef AutoPowerState;
extern IRScan_TypeDef xdata IRScan;
extern IRControl_TypeDef xdata IRControl;
extern uint16 PowerUpTimeCount;
extern uint32  dimmer_cnt;
/* Exported functions ---------------------------------------------------------------------------*/
extern void IRInit(void);
extern void IRValue(void);
extern void RFValue(void);
extern void IRScanControl(void);
extern void AutoPowerControl(void);
extern uint8 GetUserCode(void);
extern void LEDDisplay(void);
extern void NatureWind(void);
extern void Dimmer_Control(void);
#endif