📄 ir_main.c
字号:
return;
}
if (irState == COMEND)
{ /* all bits received */
group = (info >> 6) & 0x1c; /* mask for 5 bit address (GGG00) */
toggle = (info << 2) & 0x2000; /* toggle flag changed>new command(T)*/
com = (uint8_t)info; /* mask for 8 bit command (CCCCCCCC) */
}
else
return; /* not all bits received yet */
/* -------------------------- end ir receiver ------------------------------ */
//sl37 start
#if 0
if (globalState_g != STANDBYMODE) /* Start LED flashing */
API_Tvt_SetLed(SYS_ON);
else
API_Tvt_SetLed(SYS_OFF);
#endif
LEDCounter_g = 0; /* Reload flash-time register. */
/* check if there is an old command */
if (!CORE_PeekMsg(INFRARED))
{
irMessage_g.cmd = (group << 8) & 0x1f00; /*shift address to higher byte*/
/* extension 7 bit command */
irMessage_g.cmd = (irMessage_g.cmd | toggle | com);
if (irOldCommand == irMessage_g.cmd)
{
if (irMessage_g.param2++ == 255) /* counter repeated command */
irMessage_g.param2 = 200; /* don't set to 0 */
irMessage_g.param1 = BUTTONPRESSED; /* = 2 -> repeat command */
}
else
{
irMessage_g.param2 = 1; /* init counter */
irMessage_g.param1 = BUTTONDOWN; /* = 1 -> first command */
/* new command received, then allow menu left/right functions */
waitForFirstCommand_g = SYS_FALSE;
}
irOpenCounter_g = 0; /* keep zero while IR commands are received */
irOldCommand = irMessage_g.cmd;
convertRC5Message( &irMessage_g.cmd);
CORE_PostMsg(INFRARED, &irMessage_g);
MAIN_ResetOffTime(); /* reset Off-Timer to 180 minutes*/
}
}
#endif /* of __RC5__*/
#ifdef __RSTEP__
#ifdef __RSTEP_WITH_WD_TIMER__
/******************************************************************************/
/**
* @brief Decodes the infrared remote control commands.
* This decoding routine is for RSTEP protocol using Watchdog-Timer
*
* @param --
*
* @return --
******************************************************************************/
void IR_InterruptInfrared(void)
{
uint16_t data newTimerValue, DeltaTime;
newTimerValue = (WDT_HIGH << 8) + WDT_LOW;
if (irState == START1) /* start of protocol ? */
{ /* switch to capture compare mode */
SET_IR_INT_CHANGING_EDGE; /* EXT Interrupt activated by both
falling and changing edge */
irState++; /* and skip to 1. Group bit state */
info = 0x0001; /* prepare new decoding */
oldTimerValue = newTimerValue;
oldBitValue = 1; /* first Interrupt in Bitmiddle, first
Bit always "1" in R-Step */
bitStartIndicator = 0; /* first Interrupt in Bitmiddle */
return;
}
DeltaTime = newTimerValue - oldTimerValue;
oldTimerValue = newTimerValue;
/* start new decoder principle for VCTP test without reading IR-PortPin
(using R-Step, biphase encoded)
Principle: starting with rising edge triggered interrupt, first interrupt
will the occur at the middle of the Startbit, which is always
"1". Change Interrupt to changing edge and measure then the time
to the next interrupt. Is it half Bit time, the next Bit is
different to the last one, if it is Bit time, then the same
bitvalue was send again. Important: This logic works only if the
delta time is measured from the Bit-middle on
(bitStartIndicator == 0)! */
if ((DeltaTime > THALFMIN) && (DeltaTime < THALFMAX))
{
if (bitStartIndicator == 0)
{
irState++; /* prepare next state */
info <<= 1; /* shift previous bits */
bitStartIndicator = 1; /* new Interrupt occured at Bitstart */
if (oldBitValue==1)
{
info |= 0x0001; /* set actual bit */
oldBitValue = 1;
}
else
{
oldBitValue = 0;
}
}
else
{
bitStartIndicator = 0;
}
}
else if ((DeltaTime > TMIN) && (DeltaTime < TMAX))
{
if (bitStartIndicator==0)
{
irState++; /* prepare next state */
info <<= 1; /* shift previous bits */
if (oldBitValue==0)
{
info |= 0x0001; /* set actual bit */
oldBitValue = 1;
}
else
{
oldBitValue = 0;
}
}
else
{
bitStartIndicator = 0;
}
}
else
{ /* E R R O R ! invalid pulses, activate IR again */
SET_IR_INT_RISING_EDGE; /* set EXT Int. active edge */
IR_InitValues();
return;
}
if (irState != (COMEND)) /* all bits received */
return;
WordWithIRInfo_g = info;
/*mgtmp LED_PORT = !LED_PORT; */ /* Start LED flashing */
/* ---------------------------- end ir receiver ---------------------------- */
IrHandleMessage();
}
#else /* if defined __RSTEP__, but not defined __RSTEP_WITH_WD_TIMER__ */
/******************************************************************************/
/**
* @brief Decodes the infrared remote control commands.
* This decoding routine is for RSTEP protocol using CRT
*
* @param --
*
* @return --
******************************************************************************/
void IR_InterruptInfrared(void)
{
uint16_t data captnew;
captnew = (CRT_CAPH << 8) + CRT_CAPL;
/* difference = real value (elapsed time since last ir event): */
captnew -= RELOADMAXSSU;
if (irState == START1)
{ /* switch to capture compare mode */
SET_IR_INT_CHANGING_EDGE; /* EXT Interrupt activated by falling and rising edge */
CRT_CON1 &= 0xFE; /* bit 0: START: stop SSU */
INTSOURCE = 0; /* IRQ source is selected port pin for INT0 ( not SSU ) */
captnew = TNOM; /* start bit is 1. int. so save start bit immediately */
captold = 0; /* reset half bit time */
irState++; /* and skip to 1. Group bit state */
info = 0; /* prepare new decoding */
}
/* test if interrupt in the middle of bit time: */
if ((captnew > THALFMIN) && (captnew < THALFMAX))
{
if (!captold)
{
captold = captnew; /* store half bit time */
return;
}
else
{
captnew += captold; /* two half bit times? -> continue */
captold = 0; /* reset half bit time */
}
}
/* test if interrupt is bit time, valid bits have to be read and stored */
if ((captnew > TMIN) && (captnew < TMAX))
{
irState++; /* prepare next state */
info <<= 1; /* shift previous bits */
if (API_Tvt_GetInfraredPort())
info |= 0x0001; /* set actual bit */
}
else
{ /* E R R O R ! invalid pulses, activate SSU again */
/* SET_IR_INT_RISING_EDGE; set EXT Int. active edge */
SET_IR_INT_FALLING_EDGE;
IR_InitSsu();
return;
}
if (irState != COMEND) /* all bits received */
return;
#ifdef DEBUG_IN_OSD
WordWithIRInfo_g = info;
#endif
/* ---------------------------- end ir receiver ---------------------------- */
IrHandleMessage();
}
#endif /* of __RSTEP__ using CRT */
/******************************************************************************/
/**
* @brief Message queue handling of IR Command
*
* @param --
*
* @return --
******************************************************************************/
static void IrHandleMessage(void)
{
#if 0
if (globalState_g != STANDBYMODE) /* Start LED flashing */
API_Tvt_SetLed(SYS_ON);
else
API_Tvt_SetLed(SYS_OFF);
#endif
LEDCounter_g = 0; /* Reload flash-time register. */
/* check if the device ID corresponts to the transmitted one */
/* isolate device ID (range from 0 to 7) from received infrared information*/
deviceId_g = irMessage_g.param3 = ((info & 0x7000) >> 12) + 1;
if (!CORE_PeekMsg(INFRARED)) /* check if there is an old IR command */
{
/* Set Group and Command to message struct */
irMessage_g.cmd = info;
{
/* same command again? */
if (info & 0x0100) /* repeat Bit set? */
{
if (irMessage_g.param2++ == 255) /* counter repeated command */
irMessage_g.param2 = 200; /* don't set to 0 */
irMessage_g.param1 = BUTTONPRESSED; /* = 2 -> repeat command */
}
else /* prepare new command */
{
irMessage_g.param2 = 1; /* init counter */
irMessage_g.param1 = BUTTONDOWN; /* = 1 -> first command */
/* new command received, then allow menu left/right functions */
waitForFirstCommand_g = SYS_FALSE;
}
}
/* get event from conversion table: */
irOpenCounter_g = 0; /* keep zero while IR commands are received */
convertRSTEPMessage(&irMessage_g.cmd);
#ifdef __DEMO_LOOP__
if (demoSequenceStatus_g != DEMO_END) /* demo loop active */
{
if (irMessage_g.cmd == STOPKEY &&
irMessage_g.param1 == BUTTONDOWN)
{
demoSequenceStatus_g = DEMO_IR_END_PROCEDURE;
}
else if (irMessage_g.cmd == PAUSEKEY &&
irMessage_g.param1 == BUTTONDOWN)
{
if (demoSequenceStatus_g == DEMO_PAUSE)
{
demoSequenceStatus_g = DEMO_RUN;
}
else
{
demoSequenceStatus_g = DEMO_PAUSE;
}
}
return;
}
#endif
CORE_PostMsg((uint16_t)INFRARED, &irMessage_g);
MAIN_ResetOffTime(); /* reset Off-Timer to 180 minutes*/
}
}
#endif /* of __RSTEP__ */
/******************************************************************************/
/**
* LOCAL FUNCTIONS:
******************************************************************************/
/******************************************************************************/
/**
* @brief Converts IR remote control command into an event for
* the message queue.
*
* @param *pwCommand [in] received IR command
*
* @return --
******************************************************************************/
#ifdef __IR60__ /* infrared detection of IR60 code with TVText */
static void convertIR60Message(uint16_t *pCommand)
{
uint8_t group;
uint8_t com;
group = (uint8_t)((*pCommand >> 6) & 0x07); /* mask for 3 bit group */
com = (uint8_t)((*pCommand) & 0x3f); /* mask for 6 bit command */
switch (group)
{
case 0: /* normal address group (TV mode) */
*pCommand = convertIR60Table1[com];
break;
case 1: /* SAT address group */
*pCommand = convertIR60Table2[com];
break;
case 4:
/* next 3 lines to be enabled if wished by customer */
/* if (com == 55) */ /* address 4 command 55 = low battery */
/* *pCommand = CHECKBATTERY; */
/* break; */
default:
*pCommand = NOEVENT; /* NOEVENT */
}
}
#endif /* of __IR60__*/
/******************************************************************************/
/**
* @brief Converts IR remote control command into event for Message queue at
* the same address. The fieldbit selects between 2 tables of 64
* commands. Fieldbit is set:
* -> command is selected from part 2 of convertRC5Table1.
* Fieldbit is cleared:
* -> command is selected from part 1 of convertRC5Table1.
*
* @param *pwCommand [in] received IR command
*
* @return --
******************************************************************************/
#ifdef __RC5__ /* infrared detection of RC5 code with TVText */
static void convertRC5Message(uint16_t *pCommand)
{
uint8_t data group;
uint8_t data com;
group = (uint8_t)(*pCommand >> 8) & 0x01c; /* mask for 3 bit group */
com = (uint8_t)(*pCommand);
switch (group)
{
case 0: /* normal address group (TV mode) */
/*0 if (field == 1) */
*pCommand = convertRC5Table1[com]; /* convert commands 0 - 63 */
break;
case 1:
*pCommand = convertRC5Table2[com]; /* convert commands 0 - 127 */
break;
/* add other address groups here */
/* case 2:
break;
*/
default:
*pCommand = NOEVENT; /* NOEVENT */
}
}
#endif /* of __RC5__ */
#ifdef __NEC__ /* infrared detection of R2000 code */
static void convertNECMessage(uint16_t *pCommand)
{
uint8_t com;
com = (uint8_t)(*pCommand);
*pCommand = convertNECTable1[com];
}
#endif
/******************************************************************************/
/**
* @brief Converts IR remote control command into an event for
* the message queue.
*
* @param *pwCommand
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -