*\r
* Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de\r
*\r
- * $Id: irmp.c,v 1.73 2010/06/26 18:13:11 fm Exp $\r
+ * $Id: irmp.c,v 1.75 2010/07/01 09:00:16 fm Exp $\r
*\r
* ATMEGA88 @ 8 MHz\r
*\r
#endif\r
\r
#define IRMP_TIMEOUT_LEN (PAUSE_LEN)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)\r
-#define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec\r
+#define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec\r
\r
#define MIN_TOLERANCE_00 1.0 // -0%\r
#define MAX_TOLERANCE_00 1.0 // +0%\r
#define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)\r
#define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)\r
#define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)\r
+// autodetect nec repetition frame within 50 msec:\r
+// NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms\r
+#if 0\r
+#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)\r
+#else\r
+#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)\r
+#endif\r
\r
#define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
#define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
UART0_UBRRL = UBRRL_VALUE;\r
\r
#if USE_2X\r
- UART0_UCSRA = (1<<U2X);\r
+ UART0_UCSRA |= (1<<U2X);\r
#else\r
- UART0_UCSRA = 0;\r
+ UART0_UCSRA &= ~(1<<U2X);\r
#endif\r
\r
UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;\r
}\r
else\r
{\r
- repetition_counter++;\r
+ if (repetition_counter < 0xFFFF) // avoid overflow of counter\r
+ {\r
+ repetition_counter++;\r
+ }\r
}\r
}\r
}\r
#if IRMP_SUPPORT_NEC_PROTOCOL == 1\r
if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame\r
{\r
- irmp_tmp_address = last_irmp_address; // address is last address\r
- irmp_tmp_command = last_irmp_command; // command is last command\r
- irmp_flags |= IRMP_FLAG_REPETITION;\r
+ if (repetition_counter < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)\r
+ {\r
+ ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_counter = %d\n", repetition_counter);\r
+ irmp_tmp_address = last_irmp_address; // address is last address\r
+ irmp_tmp_command = last_irmp_command; // command is last command\r
+ irmp_flags |= IRMP_FLAG_REPETITION;\r
+ repetition_counter = 0;\r
+ }\r
+ else\r
+ {\r
+ ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_counter = %d > %d\n",\r
+ repetition_counter, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);\r
+ irmp_ir_detected = FALSE;\r
+ }\r
}\r
#endif // IRMP_SUPPORT_NEC_PROTOCOL\r
irmp_protocol = irmp_param.protocol;\r