📄 irremote.c
字号:
dbmsg_ftrace( DBM_KEY, "remote: mouse=%d x=%3d y=%3d key=%02x\r\n",
report.mouse, report.mouse_x, report.mouse_y, report.key );
guiKeycode( &report, newKey );
}
}
}
/****************************************************************************/
/* IR scanner. */
/* */
/* This function reads IR status and IR capture counter values */
/* and passes events to all protocol handlers. A protocol handler */
/* returns a NIL indication or a keycode. */
/* */
/* Only one code is returned per scan. If both port 0 and 1 are */
/* in use, a given protocol is expected to return the same code */
/* within one scan of each other if both received the message. Only */
/* one protocol will successfully decode a message, so there is */
/* no opportunity for protocols to collide on a message decode. */
/* */
/* Returns TRUE if keycode or mouse move detected, else returns FALSE. */
/****************************************************************************/
BOOL irScanEvent( UIREP *report, BOOL *newKey )
{
UIREP port0rep; /* port 0 report */
UIREP port1rep; /* port 1 report */
BOOL newKey0; /* assume no new key code */
BOOL newKey1; /* assume no new key code */
BOOL newReport = FALSE; /* new report seen */
port0rep.mouse = FALSE; /* assume no mouse */
port1rep.mouse = FALSE; /* assume no mouse */
msTimer += irDeltaMsTimer(); /* Update millisecond timer */
*newKey = FALSE; /* assume no new key will be decoded */
/****************************************************/
/* Scan port 0 if in use. */
/****************************************************/
if( 0x01 == ( 0x01 & config ))
{
newKey0 = irScanOne( IR_PORT0, &port0rep, overFlag0 );
*newKey |= newKey0;
overFlag0 = FALSE; /* reset flag if it was set*/
}
/****************************************************/
/* Scan port 1 if in use. */
/****************************************************/
if( 0x02 == ( 0x02 & config ))
{
newKey1 = irScanOne( IR_PORT1, &port1rep, overFlag1 );
*newKey |= newKey1;
overFlag1 = FALSE; /* reset flag if it was set*/
}
/****************************************************/
/* Examine mouse movement and key click. */
/****************************************************/
if( port0rep.mouse || newKey0 ) /* if mouse move or key */
{
newReport = TRUE;
report -> key = port0rep.key;
report -> mouse = port0rep.mouse;
report -> mouse_x = port0rep.mouse_x;
report -> mouse_y = port0rep.mouse_y;
}
else if( port1rep.mouse || newKey1 ) /* if mouse move or key */
{
newReport = TRUE;
report -> key = port1rep.key;
report -> mouse = port1rep.mouse;
report -> mouse_x = port1rep.mouse_x;
report -> mouse_y = port1rep.mouse_y;
}
/****************************************************/
/* Examine the time between reports. If the time is */
/* less than the minimum IR message transmission */
/* time, the same key code has been received from */
/* the front and back IR receivers. Do not report */
/* the second code. */
/****************************************************/
newReport = newReport && (( msTimer - priorTime ) > 15 );
if( newReport ) /* if a report is returned... */
{
dbmsg_ftrace( DBM_KEY, "\ndt=%d\r\n", msTimer - priorTime );
priorTime = msTimer; /* update time at which report was returned */
}
return newReport;
}
/****************************************************************************/
/* Scan all IR port protocols on the indicated port. */
/* */
/* Read all capture events from the indicated port and pass them to each of */
/* the protocol handlers. If a handler reports a key or mouse event, it */
/* will return TRUE and the event will be returned to the caller. */
/* */
/* If an overrun was setected, overFlag will be set and an IRMSGSYNC is */
/* sent to clear any fragment of an IR message that may have been in work. */
/****************************************************************************/
static BOOL irScanOne( IRPORT port, UIREP *report, BOOL overFlag )
{
int pindex; /* protocol index */
uint16 capEvent; /* IR receiver event */
BOOL empty = FALSE; /* assume FIFO not empty */
BOOL eventFlag = FALSE; /* message-event-seen flag */
/****************************************************/
/* Resync on overrun. */
/****************************************************/
if( overFlag ) /* if a FIFO overrun occurred */
for( pindex = 0; pindex < pCount; pindex++ )
(*irProto[ pindex ] -> eventFunc)( report, port, IRMSGSYNC );
/****************************************************/
/* Pass capture events to all protocol decoders. A */
/* decoder will write *report only when an event is */
/* detected. */
/****************************************************/
while(( !empty ) && ( PASS == IR_ReadData( port, &capEvent, &empty )))
{
capEvent ^= 0x8000; /* invert reported state */
for( pindex = 0; pindex < pCount; pindex++ )
{
eventFlag |=
(*irProto[ pindex ] -> eventFunc)( report, port, capEvent );
}
}
return eventFlag;
}
/****************************************************************************/
/* Return millisecond timer */
/* */
/* This timer functions without use of an ASIC hardware timer. The timer is */
/* updated in irScanEvent()by irDeltaMsTimer(), at the beginning of each IR */
/* scan. */
/****************************************************************************/
uint32 irfunc_MsecTime( void )
{
return msTimer;
}
/****************************************************************************/
/* Return number of milliseconds since last IR scan */
/* */
/* Calculated from free-running timer, accounting for truncation of timer */
/* ticks to milliseconds. */
/****************************************************************************/
static uint32 irDeltaMsTimer( void )
{
static uint32 ttimer = 0; /* last truncated timer value */
uint32 frt = TMR_GetTBCVal(); /* current free-running timer value */
uint32 delta = frt - ttimer; /* number of ticks between scans */
uint32 interval = delta / FRT_TICKS_PER_MILLISECOND;
ttimer = ttimer + interval * FRT_TICKS_PER_MILLISECOND;
return interval;
}
/****************************************************************************/
/* IR port interrupt handlers. */
/* - EOF or FIFO half-full interrupts signal the IR event. */
/* - Overflow interrupts clear the FIFO. */
/****************************************************************************/
static void irPortZeroHandler( uint08 index )
{
IRSTATUSDATA status;
IR_GetStatus( IR_PORT0, &status );
if( 0 != ( status.intr_stat & 0x02 )) /* if full asserted */
{
IR_FlushBuffer( IR_PORT0 );
IR_ClearInterrupt( IR_PORT0, 0xff );
overFlag0 = TRUE; /* signal FIFO overrun */
}
else /* is EOF or FIFO half-full */
{
IR_ClearInterrupt( IR_PORT0, 0xfd );
}
RTA_EventSetFromISR( irEventID );
}
/****************************************************************************/
static void irPortOneHandler( uint08 index )
{
IRSTATUSDATA status;
IR_GetStatus( IR_PORT1, &status );
if( 0 != ( status.intr_stat & 0x02 )) /* if full asserted */
{
IR_FlushBuffer( IR_PORT1 );
IR_ClearInterrupt( IR_PORT1, 0xff );
overFlag1 = TRUE; /* signal FIFO overrun */
}
else /* is EOF or FIFO half-full */
{
IR_ClearInterrupt( IR_PORT1, 0xfd );
}
RTA_EventSetFromISR( irEventID );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -