fp.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:5k
- #include "stpio.h"
- #include "string.h"
- #include "stdevice.h"
- #include "stcommon.h"
- #include "osp.h"
- #include "errors.h"
- #include "db.h"
- #include <gendef.h>
- #include <keydef.h>
- #include <ir.h>
- #include <stblast.h>
- #include <stcommon.h>
- #include <message.h>
- #include <task.h>
- #include "irp.h"
- void IRCEvtCallback
- (
- STEVT_CallReason_t Reason,
- const ST_DeviceName_t RegistrantName,
- STEVT_EventConstant_t Event,
- const void *EventData,
- const void *SubscriberData_p
- );
- static void IRCTask(void *Param_p);
- static UINT8 SwapByte(UINT8 data);
- KB_KeyCallBack gKeyCallBackFunc;
- extern UINT32 BlasterSemaphore_p;
- static UINT8 bIRCEnabled;
- extern STBLAST_Handle_t BLAST_Handle;
- RetValue KB_IRInit(void)
- {
- UINT32 error;
- UINT32 taskid;
-
- error = blaster_EvtInit();
- if ( error != RETOK )
- {
- STTBX_Print(("InitEvt for BLAST failn"));
- return error;
- }
- error = blaster_Init();
- if ( error != RETOK )
- {
- STTBX_Print(("InitBlast failn"));
- return error;
- }
-
- KB_OSPTaskInit("IRT", 0x2000, (void(*)(void *))IRCTask,
- IRC_PRIORITY, NULL, &taskid);
-
- bIRCEnabled = 1;
- gKeyCallBackFunc = NULL;
- return (RETOK);
- }
- KB_KeyCallBack KB_IRCallBack(KB_KeyCallBack callback)
- {
- KB_KeyCallBack tPreCallBack;
- tPreCallBack = gKeyCallBackFunc;
- gKeyCallBackFunc = callback;
- return tPreCallBack;
- }
- #if 1
- #define SCAN_FREQEN2 (1)
- #define IR_SCAN_INTERVAL_TIME (120)
- static U32 Cmd,oldCmd;
- static UINT8 oldCmdFlag = 0;
- static void IRCTask(void *Param_p)
- {
- U32 NumReceived;
- ST_ErrorCode_t ST_ErrorCode= ST_NO_ERROR;
- static UINT16 nScanTime = 0;
-
- while(1)
- {
- NumReceived = 0;
-
- ST_ErrorCode = STBLAST_Receive(BLAST_Handle, &Cmd, 1, &NumReceived, IR_SCAN_INTERVAL_TIME);
- printf("n[Han]:NumReceived 0x%x",NumReceived);
- KB_OSPSemGet(BlasterSemaphore_p, KB_Wait, 0);
-
- if(ST_ErrorCode == ST_NO_ERROR && NumReceived)
- {
- /**************** NEC Protocol Data Format ****************
- **
- ** Address and Command are transmitted twice.
- ** The second time all bits are inverted and
- ** can be used for verification of the received message
- ** |<---------->|<---------->|<---------->|<---------->|
- ** |LSB MSB|LSB MSB|LSB MSB|LSB MSB|
- ** Address ^Address Command ^Command
- **
- ** When we use, only keep the Command.
- ****************************************************************/
-
- /* Remove the Address and ^Address from the key code */
- Cmd &= 0xFFFF;
-
- /*
- ** Validate the Key ID by ensuring that the upper and lower
- ** bytes are complementary.
- */
- if( ((Cmd & 0xFF) ^ ((Cmd >>8) & 0xFF)) == 0xFF )
- {
- Cmd = (Cmd >> 8) & 0xFF;
- Cmd = SwapByte(Cmd);
- if (oldCmdFlag)
- {
- if (oldCmd == Cmd)
- {
-
- if(nScanTime >= SCAN_FREQEN2)
- {
- nScanTime = 0;
-
- if((gKeyCallBackFunc != NULL) && (bIRCEnabled == 1))
- {
- gKeyCallBackFunc(KEY_PRESS, Cmd);
- }
- }
- else
- {
- nScanTime++;
- }
- }
- else
- {
- oldCmd = Cmd;
- oldCmdFlag = 1;
- nScanTime = 0;
- }
- }
- else
- {
- oldCmd = Cmd;
- oldCmdFlag = 1;
- nScanTime = 0;
- if((gKeyCallBackFunc != NULL) && (bIRCEnabled == 1))
- {
- gKeyCallBackFunc(KEY_PRESS, Cmd);
-
- }
- }
- }
- }
- else if ((ST_ErrorCode == ST_NO_ERROR) && (! NumReceived))
- {
- if (oldCmdFlag)
- {
- if((gKeyCallBackFunc != NULL) && (bIRCEnabled == 1))
- {
- gKeyCallBackFunc(KEY_RELEASE, oldCmd);
- }
-
- oldCmd = 0;
- oldCmdFlag = 0;
- nScanTime = 0;
- }
- else
- {
- nScanTime = 0;
- }
- }
-
- }
- }
- #endif
- void IRCEvtCallback( STEVT_CallReason_t Reason,
- const ST_DeviceName_t RegistrantName,
- STEVT_EventConstant_t Event,
- const void *EventData,
- const void *SubscriberData_p)
- {
- switch (Event)
- {
- case STBLAST_READ_DONE_EVT:
- KB_OSPSemSet(BlasterSemaphore_p);
- break;
- default:
- break;
- }
- }
- /* 对一个字节的高低位互换 */
- static UINT8 SwapByte(UINT8 data)
- {
- int i;
- UINT8 tmp = 0;
- for(i=0; i<4; i++)
- {
- tmp |= ((data >> i) & 0x01) << (7-i);
- tmp |= ((data >> (7-i)) & 0x01) << i;
- }
- return tmp;
- }
- /* EOF */