
//红外线解码程序
//系统晶振: 11.0592MHz

//---------------------------------------------------
//设计时间: 2013年6月
//设计解码程序主体,并且加上了按键的码值转换(标准化)

//---------------------------------------------------
//更新时间: 2013年7月3日
//1 增加了按键按下/持续和松开保护,当解码异常时自动取消后边的按键持续和松开事件
//  通过 is_press 标志记录是否正确解码.如果 is_press = YES 表示解码正常.
//2 稍微增大了定时时间常数,不是标准的1106,解码误差小了些

//---------------------------------------------------
//更新时间: 2013年11月20日
//把事件调度接口改成了新版调度器兼容的形式

//---------------------------------------------------
//更新时间: 2016年1月21日
//去掉了按键持续按下事件

unit IR
{
	public const uint16 ID = 0;
	
	//[i] linkinterface_IRreceive receive;
	public link unit receive {}
	
	//[i] var_uint16 OS_EventFlag;
	public uint16 OS_EventFlag;
	//[i] event receive_event;
	//[i] event nodata_event;
	//[i] event POWER_event;
	//[i] event MENU_event;
	//[i] event TEST_event;
	//[i] event RETURN_event;
	//[i] event VOLINC_event;
	//[i] event VOLDEC_event;
	//[i] event PRE_event;
	//[i] event NEXT_event;
	//[i] event PLAY_event;
	//[i] event C_event;
	//[i] event NUMBER_event;
	
	//[i] var_int32 data;
	public int32 data;
	
	bool is_press; //按下标志,表示当前是否有键按下
	
	//------------------------------------------------------------
	//[i] var_uint16 OS_time;
	public uint8 OS_time;
	
	#include "$run$.txt"
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	void OS_init()
	{
		OS_EventFlag = 0;
		OS_time = 100;
		is_press = false;
		RunInit();
	}
	
	//---------------------------------------------------
	//[i] function_void OS_run;
	
	//...
	
	void SetFlag( int8 temp )
	{
		OS_EventFlag.0(bit) = 1;
		
		if( temp == POWER ) {
			OS_EventFlag.2(bit) = 1;
		}
		else if( temp == MENU ) {
			OS_EventFlag.3(bit) = 1;
		}
		else if( temp == TEST ) {
			OS_EventFlag.4(bit) = 1;
		}
		else if( temp == RETURN ) {
			OS_EventFlag.5(bit) = 1;
		}
		else if( temp == VOLINC ) {
			OS_EventFlag.6(bit) = 1;
		}
		else if( temp == VOLDEC ) {
			OS_EventFlag.7(bit) = 1;
		}
		else if( temp == PRE ) {
			OS_EventFlag.8(bit) = 1;
		}
		else if( temp == NEXT ) {
			OS_EventFlag.9(bit) = 1;
		}
		else if( temp == PLAY ) {
			OS_EventFlag.10(bit) = 1;
		}
		else if( temp == C ) {
			OS_EventFlag.11(bit) = 1;
		}
		else if( temp <= 9 ) {
			OS_EventFlag.12(bit) = 1;
		}
		else {
			//...
		}
		is_press = true;
		data = temp;
	}
		
	//下列常量表示遥控器上各个按键码
	//[i] const_int32 NONE;
	public const int8 NONE = -1;
	//[i] const_int32 NUM0;
	public const int8 NUM0 = 0;//0x16
	//[i] const_int32 NUM1;
	public const int8 NUM1 = 1;//0x0C
	//[i] const_int32 NUM2;
	public const int8 NUM2 = 2;//0x18
	//[i] const_int32 NUM3;
	public const int8 NUM3 = 3;//0x5E
	//[i] const_int32 NUM4;
	public const int8 NUM4 = 4;//0x08
	//[i] const_int32 NUM5;
	public const int8 NUM5 = 5;//0x1C
	//[i] const_int32 NUM6;
	public const int8 NUM6 = 6;//0x5A
	//[i] const_int32 NUM7;
	public const int8 NUM7 = 7;//0x42
	//[i] const_int32 NUM8;
	public const int8 NUM8 = 8;//0x52
	//[i] const_int32 NUM9;
	public const int8 NUM9 = 9;//0x4A
	//[i] const_int32 POWER;
	public const int8 POWER = 10;//0x45
	///[i] const_int32 CH;
	public const int8 CH = 11;//0x46
	//[i] const_int32 MENU;
	public const int8 MENU = 12;//0x47
	//[i] const_int32 TEST;
	public const int8 TEST = 13;//0x44
	//[i] const_int32 VOLINC;
	public const int8 VOLINC = 14;//0x40
	//[i] const_int32 RETURN;
	public const int8 RETURN = 15;//0x43
	//[i] const_int32 PRE;
	public const int8 PRE = 16;//0x07
	//[i] const_int32 PLAY;
	public const int8 PLAY = 17;//0x15
	//[i] const_int32 NEXT;
	public const int8 NEXT = 18;//0x09
	//[i] const_int32 VOLDEC;
	public const int8 VOLDEC = 19;//0x19
	//[i] const_int32 C;
	public const int8 C = 20;//0x0D
}




















