Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 模擬IR輸出

android 模擬IR輸出

編輯:關於Android編程

\


#define IR_HEAD0 0
#define IR_HEAD1 1
#define IR_TIME_BASE 2
#define IR_CODE_0  3
#define IR_CODE_1  4
#define IR_CODE_END  5
#define TIMER_9000US  10500
#define TIMER_4500US  5710
#define TIMER_560US   720
#define TIMER_1680US  2135
SendIR(const U16 head, const U16 keycode,const BOOL outreverse)
{
	  S8 TranselateBitPos;
	  U8 Ir_trans_sta;
	  int count = 0;
	  U8 head0 = head >> 8;
	  U8 head1 = head &0x00ff;
	  Ir_trans_sta=IR_HEAD0;
	  TranselateBitPos=32;
	  printf("\n yanxi head:%d  keycode:%d  outreverse:%d",head,keycode,outreverse);
	  while(TranselateBitPos>=0)
	  {
	 	switch(Ir_trans_sta)
	 	{
		 case IR_HEAD0:	
			  Ir_trans_sta= IR_HEAD1; 
			  for(count=TIMER_9000US;count>0;count--)
				  SetGpioDeviceStatus(LED_WORK,!outreverse);
			  break;
		 case IR_HEAD1:		 			
			  Ir_trans_sta= IR_TIME_BASE; 
			  for(count=TIMER_4500US;count>0;count--)
				  SetGpioDeviceStatus(LED_WORK,outreverse);
			  break;
		 case IR_TIME_BASE:	
		 		if(TranselateBitPos>24)
				{
					 if( ((head0>>(32-TranselateBitPos)) && 0x1) == 0x1 )
					 	Ir_trans_sta= IR_CODE_1; 
					 else 
					 	Ir_trans_sta= IR_CODE_0; 						 
				}

				else if(TranselateBitPos>16)
				{
					 if( ((head1>>(24-TranselateBitPos)) && 0x1) == 0x1 )
					 	Ir_trans_sta= IR_CODE_1; 
					 else 
					 	Ir_trans_sta= IR_CODE_0; 						 
				}
				else if(TranselateBitPos>8)
				{
					 if( ((keycode>>(16-TranselateBitPos)) && 0x1) == 0x1 )
					 	Ir_trans_sta= IR_CODE_1; 
					 else 
					 	Ir_trans_sta= IR_CODE_0; 						 
				}
				else if(TranselateBitPos>0)
				{
					 if( ((keycode>>(8-TranselateBitPos)) && 0x1) == 0x1 )
					 	Ir_trans_sta= IR_CODE_0; 
					 else 
					 	Ir_trans_sta= IR_CODE_1; 						 
				}
				else
				{
					 Ir_trans_sta= IR_CODE_END; 	
				}
				
				for(count=TIMER_560US;count>0;count--)
					SetGpioDeviceStatus(LED_WORK,!outreverse);
				
				break;
		 case IR_CODE_0:		
				Ir_trans_sta= IR_TIME_BASE; 
				for(count=TIMER_560US;count>0;count--)
					SetGpioDeviceStatus(LED_WORK,outreverse);						
				TranselateBitPos--;
				break;
		 case IR_CODE_1:		
				Ir_trans_sta= IR_TIME_BASE; 
				for(count=TIMER_1680US;count>0;count--)
					SetGpioDeviceStatus(LED_WORK,outreverse);						
				TranselateBitPos--;
				break;
	 	 case IR_CODE_END:
				Ir_trans_sta= IR_HEAD0; 
				SetGpioDeviceStatus(LED_WORK,outreverse);						
				TranselateBitPos=-1;//force to exit.
				break;
		 default:break;
		}
	}

}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved