]> cloudbase.mooo.com Git - irmp.git/blobdiff - irmp.c
version 2.0.0-pre7: added support for ATtiny84, added ISR in main.c, corrected timer1...
[irmp.git] / irmp.c
diff --git a/irmp.c b/irmp.c
index 7e958183072679258199bc652ef43868e09d61a1..208e22d537bf47151dbfb010693e716d6ce62265 100644 (file)
--- a/irmp.c
+++ b/irmp.c
@@ -3,11 +3,20 @@
  *\r
  * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmp.c,v 1.104 2011/05/22 21:40:52 fm Exp $\r
+ * $Id: irmp.c,v 1.108 2011/09/09 11:59:39 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
- * Typical manufacturers:\r
+ * Supported mikrocontrollers:\r
+ *\r
+ * ATtiny45,  ATtiny85\r
+ * ATtiny84\r
+ * ATmega8,   ATmega16,  ATmega32\r
+ * ATmega162\r
+ * ATmega164, ATmega324, ATmega644,  ATmega644P, ATmega1284\r
+ * ATmega88,  ATmega88P, ATmega168,  ATmega168P, ATmega328P\r
+ *\r
+ * Typical manufacturers of remote controls:\r
  *\r
  * SIRCS        - Sony\r
  * NEC          - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers\r
@@ -316,8 +325,6 @@ typedef unsigned short  uint16_t;
 \r
 #else\r
 \r
-#ifndef CODEVISION\r
-\r
 #ifdef PIC_CCS_COMPILER\r
 \r
 #include <string.h>\r
@@ -336,7 +343,6 @@ typedef unsigned int16  uint16_t;
 #include <avr/pgmspace.h>\r
 \r
 #endif  // PIC_CCS_COMPILER\r
-#endif  // CODEVISION\r
 \r
 #endif // windows\r
 #endif // unix\r
@@ -368,9 +374,7 @@ typedef unsigned int16  uint16_t;
 #define IRMP_SUPPORT_MANCHESTER                 0\r
 #endif\r
 \r
-#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 ||                \\r
-    IRMP_SUPPORT_MERLIN_PROTOCOL == 1 ||                \\r
-    IRMP_SUPPORT_IMON_PROTOCOL == 1 \r
+#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1\r
 #define IRMP_SUPPORT_SERIAL                     1\r
 #else\r
 #define IRMP_SUPPORT_SERIAL                     0\r
@@ -678,34 +682,16 @@ typedef unsigned int16  uint16_t;
 #define LEGO_0_PAUSE_LEN_MIN                    ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)\r
 #define LEGO_0_PAUSE_LEN_MAX                    ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)\r
 \r
-#define MERLIN_START_BIT_PULSE_LEN_MIN          ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
-#define MERLIN_START_BIT_PULSE_LEN_MAX          ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
-#define MERLIN_START_BIT_PAUSE_LEN_MIN          ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
-#define MERLIN_START_BIT_PAUSE_LEN_MAX          ((uint8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
-#define MERLIN_PULSE_LEN                        ((uint8_t)(F_INTERRUPTS * MERLIN_PULSE_TIME))\r
-#define MERLIN_PAUSE_LEN                        ((uint8_t)(F_INTERRUPTS * MERLIN_PAUSE_TIME))\r
-#define MERLIN_PULSE_REST_LEN                   ((uint8_t)(F_INTERRUPTS * MERLIN_PULSE_TIME / 4))\r
-#define MERLIN_PAUSE_REST_LEN                   ((uint8_t)(F_INTERRUPTS * MERLIN_PAUSE_TIME / 4))\r
-\r
-#define IMON_START_BIT_PULSE_LEN_MIN            ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
-#define IMON_START_BIT_PULSE_LEN_MAX            ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
-#define IMON_START_BIT_PAUSE_LEN_MIN            ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)\r
-#define IMON_START_BIT_PAUSE_LEN_MAX            ((uint8_t)(F_INTERRUPTS * IMON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)\r
-#define IMON_PULSE_LEN                          ((uint8_t)(F_INTERRUPTS * IMON_PULSE_TIME))\r
-#define IMON_PAUSE_LEN                          ((uint8_t)(F_INTERRUPTS * IMON_PAUSE_TIME))\r
-#define IMON_PULSE_REST_LEN                     ((uint8_t)(F_INTERRUPTS * IMON_PULSE_TIME / 4))\r
-#define IMON_PAUSE_REST_LEN                     ((uint8_t)(F_INTERRUPTS * IMON_PAUSE_TIME / 4))\r
-\r
 #define AUTO_FRAME_REPETITION_LEN               (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5)       // use uint16_t!\r
 \r
 #ifdef ANALYZE\r
-#define ANALYZE_PUTCHAR(a)                        { if (! silent)             { putchar (a);          } }\r
-#define ANALYZE_ONLY_NORMAL_PUTCHAR(a)            { if (! silent && !verbose) { putchar (a);          } }\r
-#define ANALYZE_PRINTF(...)                       { if (verbose)              { printf (__VA_ARGS__); } }\r
-#define ANALYZE_NEWLINE()                         { if (verbose)              { putchar ('\n');       } }\r
-static int      silent;\r
-static int      time_counter;\r
-static int      verbose;\r
+#define ANALYZE_PUTCHAR(a)                      { if (! silent)             { putchar (a);          } }\r
+#define ANALYZE_ONLY_NORMAL_PUTCHAR(a)          { if (! silent && !verbose) { putchar (a);          } }\r
+#define ANALYZE_PRINTF(...)                     { if (verbose)              { printf (__VA_ARGS__); } }\r
+#define ANALYZE_NEWLINE()                       { if (verbose)              { putchar ('\n');       } }\r
+static int                                      silent;\r
+static int                                      time_counter;\r
+static int                                      verbose;\r
 #else\r
 #define ANALYZE_PUTCHAR(a)\r
 #define ANALYZE_ONLY_NORMAL_PUTCHAR(a)\r
@@ -713,6 +699,56 @@ static int      verbose;
 #define ANALYZE_NEWLINE()\r
 #endif\r
 \r
+#if IRMP_USE_CALLBACK == 1\r
+static void                                     (*irmp_callback_ptr) (uint8_t);\r
+#endif // IRMP_USE_CALLBACK == 1\r
+\r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ *  Protocol names\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
+#if IRMP_PROTOCOL_NAMES == 1\r
+char *\r
+irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =\r
+{\r
+    "UNKNOWN",\r
+    "SIRCS",\r
+    "NEC",\r
+    "SAMSUNG",\r
+    "MATSUSH",\r
+    "KASEIKYO",\r
+    "RECS80",\r
+    "RC5",\r
+    "DENON",\r
+    "RC6",\r
+    "SAMSG32",\r
+    "APPLE",\r
+    "RECS80EX",\r
+    "NUBERT",\r
+    "BANG OLU",\r
+    "GRUNDIG",\r
+    "NOKIA",\r
+    "SIEMENS",\r
+    "FDC",\r
+    "RCCAR",\r
+    "JVC",\r
+    "RC6A",\r
+    "NIKON",\r
+    "RUWIDO",\r
+    "IR60",\r
+    "KATHREIN",\r
+    "NETBOX",\r
+    "NEC16",\r
+    "NEC42",\r
+    "LEGO",\r
+    "THOMSON"\r
+};\r
+#endif\r
+\r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ *  Logging\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
 #if IRMP_LOGGING == 1\r
 #define BAUD                                    9600L\r
 #include <util/setbaud.h>\r
@@ -900,7 +936,7 @@ typedef struct
 \r
 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER sircs_param =\r
+static const PROGMEM IRMP_PARAMETER sircs_param =\r
 {\r
     IRMP_SIRCS_PROTOCOL,                                                // protocol:        ir protocol\r
     SIRCS_1_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -925,7 +961,7 @@ static PROGMEM IRMP_PARAMETER sircs_param =
 \r
 #if IRMP_SUPPORT_NEC_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER nec_param =\r
+static const PROGMEM IRMP_PARAMETER nec_param =\r
 {\r
     IRMP_NEC_PROTOCOL,                                                  // protocol:        ir protocol\r
     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -946,7 +982,7 @@ static PROGMEM IRMP_PARAMETER nec_param =
     NEC_FLAGS                                                           // flags:           some flags\r
 };\r
 \r
-static PROGMEM IRMP_PARAMETER nec_rep_param =\r
+static const PROGMEM IRMP_PARAMETER nec_rep_param =\r
 {\r
     IRMP_NEC_PROTOCOL,                                                  // protocol:        ir protocol\r
     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -971,7 +1007,7 @@ static PROGMEM IRMP_PARAMETER nec_rep_param =
 \r
 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER nec42_param =\r
+static const PROGMEM IRMP_PARAMETER nec42_param =\r
 {\r
     IRMP_NEC42_PROTOCOL,                                                // protocol:        ir protocol\r
     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -983,9 +1019,9 @@ static PROGMEM IRMP_PARAMETER nec42_param =
     NEC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0\r
     NEC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0\r
     NEC42_ADDRESS_OFFSET,                                               // address_offset:  address offset\r
-    NEC42_ADDRESS_OFFSET + NEC_ADDRESS_LEN,                             // address_end:     end of address\r
+    NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN,                           // address_end:     end of address\r
     NEC42_COMMAND_OFFSET,                                               // command_offset:  command offset\r
-    NEC42_COMMAND_OFFSET + NEC_COMMAND_LEN,                             // command_end:     end of command\r
+    NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN,                           // command_end:     end of command\r
     NEC42_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame\r
     NEC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit\r
     NEC_LSB,                                                            // lsb_first:       flag: LSB first\r
@@ -996,7 +1032,7 @@ static PROGMEM IRMP_PARAMETER nec42_param =
 \r
 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER samsung_param =\r
+static const PROGMEM IRMP_PARAMETER samsung_param =\r
 {\r
     IRMP_SAMSUNG_PROTOCOL,                                              // protocol:        ir protocol\r
     SAMSUNG_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1021,7 +1057,7 @@ static PROGMEM IRMP_PARAMETER samsung_param =
 \r
 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER matsushita_param =\r
+static const PROGMEM IRMP_PARAMETER matsushita_param =\r
 {\r
     IRMP_MATSUSHITA_PROTOCOL,                                           // protocol:        ir protocol\r
     MATSUSHITA_PULSE_LEN_MIN,                                           // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1046,7 +1082,7 @@ static PROGMEM IRMP_PARAMETER matsushita_param =
 \r
 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER kaseikyo_param =\r
+static const PROGMEM IRMP_PARAMETER kaseikyo_param =\r
 {\r
     IRMP_KASEIKYO_PROTOCOL,                                             // protocol:        ir protocol\r
     KASEIKYO_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1071,7 +1107,7 @@ static PROGMEM IRMP_PARAMETER kaseikyo_param =
 \r
 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER recs80_param =\r
+static const PROGMEM IRMP_PARAMETER recs80_param =\r
 {\r
     IRMP_RECS80_PROTOCOL,                                               // protocol:        ir protocol\r
     RECS80_PULSE_LEN_MIN,                                               // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1096,7 +1132,7 @@ static PROGMEM IRMP_PARAMETER recs80_param =
 \r
 #if IRMP_SUPPORT_RC5_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER rc5_param =\r
+static const PROGMEM IRMP_PARAMETER rc5_param =\r
 {\r
     IRMP_RC5_PROTOCOL,                                                  // protocol:        ir protocol\r
     RC5_BIT_LEN_MIN,                                                    // pulse_1_len_min: here: minimum length of short pulse\r
@@ -1121,7 +1157,7 @@ static PROGMEM IRMP_PARAMETER rc5_param =
 \r
 #if IRMP_SUPPORT_DENON_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER denon_param =\r
+static const PROGMEM IRMP_PARAMETER denon_param =\r
 {\r
     IRMP_DENON_PROTOCOL,                                                // protocol:        ir protocol\r
     DENON_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1146,7 +1182,7 @@ static PROGMEM IRMP_PARAMETER denon_param =
 \r
 #if IRMP_SUPPORT_RC6_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER rc6_param =\r
+static const PROGMEM IRMP_PARAMETER rc6_param =\r
 {\r
     IRMP_RC6_PROTOCOL,                                                  // protocol:        ir protocol\r
 \r
@@ -1172,7 +1208,7 @@ static PROGMEM IRMP_PARAMETER rc6_param =
 \r
 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER recs80ext_param =\r
+static const PROGMEM IRMP_PARAMETER recs80ext_param =\r
 {\r
     IRMP_RECS80EXT_PROTOCOL,                                            // protocol:        ir protocol\r
     RECS80EXT_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1197,7 +1233,7 @@ static PROGMEM IRMP_PARAMETER recs80ext_param =
 \r
 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER nubert_param =\r
+static const PROGMEM IRMP_PARAMETER nubert_param =\r
 {\r
     IRMP_NUBERT_PROTOCOL,                                               // protocol:        ir protocol\r
     NUBERT_1_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1222,7 +1258,7 @@ static PROGMEM IRMP_PARAMETER nubert_param =
 \r
 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER bang_olufsen_param =\r
+static const PROGMEM IRMP_PARAMETER bang_olufsen_param =\r
 {\r
     IRMP_BANG_OLUFSEN_PROTOCOL,                                         // protocol:        ir protocol\r
     BANG_OLUFSEN_PULSE_LEN_MIN,                                         // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1249,7 +1285,7 @@ static PROGMEM IRMP_PARAMETER bang_olufsen_param =
 \r
 static uint8_t first_bit;\r
 \r
-static PROGMEM IRMP_PARAMETER grundig_param =\r
+static const PROGMEM IRMP_PARAMETER grundig_param =\r
 {\r
     IRMP_GRUNDIG_PROTOCOL,                                              // protocol:        ir protocol\r
 \r
@@ -1275,7 +1311,7 @@ static PROGMEM IRMP_PARAMETER grundig_param =
 \r
 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER ruwido_param =\r
+static const PROGMEM IRMP_PARAMETER ruwido_param =\r
 {\r
     IRMP_RUWIDO_PROTOCOL,                                               // protocol:        ir protocol\r
     SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN,                                // pulse_1_len_min: here: minimum length of short pulse\r
@@ -1300,7 +1336,7 @@ static PROGMEM IRMP_PARAMETER ruwido_param =
 \r
 #if IRMP_SUPPORT_FDC_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER fdc_param =\r
+static const PROGMEM IRMP_PARAMETER fdc_param =\r
 {\r
     IRMP_FDC_PROTOCOL,                                                  // protocol:        ir protocol\r
     FDC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1325,7 +1361,7 @@ static PROGMEM IRMP_PARAMETER fdc_param =
 \r
 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER rccar_param =\r
+static const PROGMEM IRMP_PARAMETER rccar_param =\r
 {\r
     IRMP_RCCAR_PROTOCOL,                                                // protocol:        ir protocol\r
     RCCAR_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1350,7 +1386,7 @@ static PROGMEM IRMP_PARAMETER rccar_param =
 \r
 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER nikon_param =\r
+static const PROGMEM IRMP_PARAMETER nikon_param =\r
 {\r
     IRMP_NIKON_PROTOCOL,                                                // protocol:        ir protocol\r
     NIKON_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1375,7 +1411,7 @@ static PROGMEM IRMP_PARAMETER nikon_param =
 \r
 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER kathrein_param =\r
+static const PROGMEM IRMP_PARAMETER kathrein_param =\r
 {\r
     IRMP_KATHREIN_PROTOCOL,                                             // protocol:        ir protocol\r
     KATHREIN_1_PULSE_LEN_MIN,                                           // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1400,7 +1436,7 @@ static PROGMEM IRMP_PARAMETER kathrein_param =
 \r
 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER netbox_param =\r
+static const PROGMEM IRMP_PARAMETER netbox_param =\r
 {\r
     IRMP_NETBOX_PROTOCOL,                                               // protocol:        ir protocol\r
     NETBOX_PULSE_LEN,                                                   // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value\r
@@ -1425,7 +1461,7 @@ static PROGMEM IRMP_PARAMETER netbox_param =
 \r
 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER lego_param =\r
+static const PROGMEM IRMP_PARAMETER lego_param =\r
 {\r
     IRMP_LEGO_PROTOCOL,                                                 // protocol:        ir protocol\r
     LEGO_PULSE_LEN_MIN,                                                 // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1448,34 +1484,9 @@ static PROGMEM IRMP_PARAMETER lego_param =
 \r
 #endif\r
 \r
-#if IRMP_SUPPORT_MERLIN_PROTOCOL == 1\r
-\r
-static PROGMEM IRMP_PARAMETER merlin_param =\r
-{\r
-    IRMP_MERLIN_PROTOCOL,                                               // protocol:        ir protocol\r
-    MERLIN_PULSE_LEN,                                                   // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value\r
-    MERLIN_PULSE_REST_LEN,                                              // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value\r
-    MERLIN_PAUSE_LEN,                                                   // pause_1_len_min: minimum length of pause with bit value 1, here: exact value\r
-    MERLIN_PAUSE_REST_LEN,                                              // pause_1_len_max: maximum length of pause with bit value 1, here: rest value\r
-    MERLIN_PULSE_LEN,                                                   // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value\r
-    MERLIN_PULSE_REST_LEN,                                              // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value\r
-    MERLIN_PAUSE_LEN,                                                   // pause_0_len_min: minimum length of pause with bit value 0, here: exact value\r
-    MERLIN_PAUSE_REST_LEN,                                              // pause_0_len_max: maximum length of pause with bit value 0, here: rest value\r
-    MERLIN_ADDRESS_OFFSET,                                              // address_offset:  address offset\r
-    MERLIN_ADDRESS_OFFSET + MERLIN_ADDRESS_LEN,                         // address_end:     end of address\r
-    MERLIN_COMMAND_OFFSET,                                              // command_offset:  command offset\r
-    MERLIN_COMMAND_OFFSET + MERLIN_COMMAND_LEN,                         // command_end:     end of command\r
-    MERLIN_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame\r
-    MERLIN_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit\r
-    MERLIN_LSB,                                                         // lsb_first:       flag: LSB first\r
-    MERLIN_FLAGS                                                        // flags:           some flags\r
-};\r
-\r
-#endif\r
-\r
 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1\r
 \r
-static PROGMEM IRMP_PARAMETER thomson_param =\r
+static const PROGMEM IRMP_PARAMETER thomson_param =\r
 {\r
     IRMP_THOMSON_PROTOCOL,                                              // protocol:        ir protocol\r
     THOMSON_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1\r
@@ -1498,31 +1509,6 @@ static PROGMEM IRMP_PARAMETER thomson_param =
 \r
 #endif\r
 \r
-#if IRMP_SUPPORT_IMON_PROTOCOL == 1\r
-\r
-static PROGMEM IRMP_PARAMETER imon_param =\r
-{\r
-    IRMP_IMON_PROTOCOL,                                                 // protocol:        ir protocol\r
-    IMON_PULSE_LEN,                                                     // pulse_1_len_min: minimum length of pulse with bit value 1\r
-    IMON_PULSE_REST_LEN,                                                // pulse_1_len_max: maximum length of pulse with bit value 1\r
-    IMON_PAUSE_LEN,                                                     // pause_1_len_min: minimum length of pause with bit value 1\r
-    IMON_PAUSE_REST_LEN,                                                // pause_1_len_max: maximum length of pause with bit value 1\r
-    IMON_PULSE_LEN,                                                     // pulse_0_len_min: minimum length of pulse with bit value 0\r
-    IMON_PULSE_REST_LEN,                                                // pulse_0_len_max: maximum length of pulse with bit value 0\r
-    IMON_PAUSE_LEN,                                                     // pause_0_len_min: minimum length of pause with bit value 0\r
-    IMON_PAUSE_REST_LEN,                                                // pause_0_len_max: maximum length of pause with bit value 0\r
-    IMON_ADDRESS_OFFSET,                                                // address_offset:  address offset\r
-    IMON_ADDRESS_OFFSET + IMON_ADDRESS_LEN,                             // address_end:     end of address\r
-    IMON_COMMAND_OFFSET,                                                // command_offset:  command offset\r
-    IMON_COMMAND_OFFSET + IMON_COMMAND_LEN,                             // command_end:     end of command\r
-    IMON_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame\r
-    IMON_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit\r
-    IMON_LSB,                                                           // lsb_first:       flag: LSB first\r
-    IMON_FLAGS                                                          // flags:           some flags\r
-};\r
-\r
-#endif\r
-\r
 static uint8_t                              irmp_bit;                   // current bit position\r
 static IRMP_PARAMETER                       irmp_param;\r
 \r
@@ -1536,6 +1522,7 @@ static volatile uint16_t                    irmp_address;
 static volatile uint16_t                    irmp_command;\r
 static volatile uint16_t                    irmp_id;                    // only used for SAMSUNG protocol\r
 static volatile uint8_t                     irmp_flags;\r
+// static volatile uint8_t                     irmp_busy_flag;\r
 \r
 #ifdef ANALYZE\r
 static uint8_t                              IRMP_PIN;\r
@@ -1621,6 +1608,12 @@ irmp_get_data (IRMP_DATA * irmp_data_p)
                 }\r
                 break;\r
 #endif\r
+#if IRMP_SUPPORT_RC5_PROTOCOL == 1\r
+            case IRMP_RC5_PROTOCOL:\r
+                irmp_address &= ~0x20;                              // clear toggle bit\r
+                rtc = TRUE;\r
+                break;\r
+#endif\r
 #if IRMP_SUPPORT_IR60_PROTOCOL == 1\r
             case IRMP_IR60_PROTOCOL:\r
                 if (irmp_command != 0x007d)                         // 0x007d (== 62<<1 + 1) is start instruction frame\r
@@ -1708,6 +1701,20 @@ irmp_get_data (IRMP_DATA * irmp_data_p)
     return rtc;\r
 }\r
 \r
+// uint8_t\r
+// irmp_is_busy (void)\r
+// {\r
+//     return irmp_busy_flag;\r
+// }\r
+\r
+#if IRMP_USE_CALLBACK == 1\r
+void\r
+irmp_set_callback_ptr (void (*cb)(uint8_t))\r
+{\r
+    irmp_callback_ptr = cb;\r
+}\r
+#endif // IRMP_USE_CALLBACK == 1\r
+\r
 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()\r
 static uint16_t irmp_tmp_address;                                                       // ir address\r
 static uint16_t irmp_tmp_command;                                                       // ir command\r
@@ -1875,6 +1882,19 @@ irmp_ISR (void)
 \r
     irmp_input = input(IRMP_PIN);\r
 \r
+#if IRMP_USE_CALLBACK == 1\r
+    if (irmp_callback_ptr)\r
+    {\r
+        static uint8_t last_inverted_input;\r
+\r
+        if (last_inverted_input != !irmp_input)\r
+        {\r
+            (*irmp_callback_ptr) (! irmp_input);\r
+            last_inverted_input = !irmp_input;\r
+        }\r
+    }\r
+#endif // IRMP_USE_CALLBACK == 1\r
+\r
     irmp_log(irmp_input);                                                       // log ir signal, if IRMP_LOGGING defined\r
 \r
     if (! irmp_ir_detected)                                                     // ir code already detected?\r
@@ -1883,6 +1903,7 @@ irmp_ISR (void)
         {                                                                       // no...\r
             if (! irmp_input)                                                   // receiving burst?\r
             {                                                                   // yes...\r
+//              irmp_busy_flag = TRUE;\r
 #ifdef ANALYZE\r
                 if (! irmp_pulse_time)\r
                 {\r
@@ -1947,6 +1968,7 @@ irmp_ISR (void)
                             ANALYZE_PRINTF ("%8d error 1: pause after start bit pulse %d too long: %d\n", time_counter, irmp_pulse_time, irmp_pause_time);\r
                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
                         }\r
+//                      irmp_busy_flag = FALSE;\r
                         irmp_start_bit_detected = 0;                            // reset flags, let's wait for another start bit\r
                         irmp_pulse_time         = 0;\r
                         irmp_pause_time         = 0;\r
@@ -2307,18 +2329,6 @@ irmp_ISR (void)
                     else\r
 #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1\r
 \r
-#if IRMP_SUPPORT_MERLIN_PROTOCOL == 1\r
-                    if (irmp_pulse_time >= MERLIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MERLIN_START_BIT_PULSE_LEN_MAX &&\r
-                        irmp_pause_time >= MERLIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MERLIN_START_BIT_PAUSE_LEN_MAX)\r
-                    {                                                           // it's MERLIN\r
-                        ANALYZE_PRINTF ("protocol = MERLIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",\r
-                                        MERLIN_START_BIT_PULSE_LEN_MIN, MERLIN_START_BIT_PULSE_LEN_MAX,\r
-                                        MERLIN_START_BIT_PAUSE_LEN_MIN, MERLIN_START_BIT_PAUSE_LEN_MAX);\r
-                        irmp_param_p = (IRMP_PARAMETER *) &merlin_param;\r
-                    }\r
-                    else\r
-#endif // IRMP_SUPPORT_MERLIN_PROTOCOL == 1\r
-\r
 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1\r
                     if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX &&\r
                         irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX)\r
@@ -2331,20 +2341,9 @@ irmp_ISR (void)
                     else\r
 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1\r
 \r
-#if IRMP_SUPPORT_IMON_PROTOCOL == 1\r
-                    if (irmp_pulse_time >= IMON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= IMON_START_BIT_PULSE_LEN_MAX &&\r
-                        irmp_pause_time >= IMON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= IMON_START_BIT_PAUSE_LEN_MAX)\r
-                    {                                                           // it's IMON\r
-                        ANALYZE_PRINTF ("protocol = IMON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",\r
-                                        IMON_START_BIT_PULSE_LEN_MIN, IMON_START_BIT_PULSE_LEN_MAX,\r
-                                        IMON_START_BIT_PAUSE_LEN_MIN, IMON_START_BIT_PAUSE_LEN_MAX);\r
-                        irmp_param_p = (IRMP_PARAMETER *) &imon_param;\r
-                    }\r
-                    else\r
-#endif // IRMP_SUPPORT_IMON_PROTOCOL == 1\r
-\r
                     {\r
                         ANALYZE_PRINTF ("protocol = UNKNOWN\n");\r
+//                      irmp_busy_flag = FALSE;\r
                         irmp_start_bit_detected = 0;                            // wait for another start bit...\r
                     }\r
 \r
@@ -2518,6 +2517,7 @@ irmp_ISR (void)
                         {\r
                             ANALYZE_PRINTF ("error: stop bit timing wrong\n");\r
 \r
+//                          irmp_busy_flag = FALSE;\r
                             irmp_start_bit_detected = 0;                        // wait for another start bit...\r
                             irmp_pulse_time         = 0;\r
                             irmp_pause_time         = 0;\r
@@ -2548,15 +2548,6 @@ irmp_ISR (void)
                             got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)\r
                         }\r
                         else\r
-#if 1\r
-                        // MERLIN generates no stop bit, here is the timeout condition:\r
-                        if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_MERLIN_PROTOCOL &&\r
-                            irmp_pause_time >= MERLIN_PULSE_LEN * (MERLIN_COMPLETE_DATA_LEN - irmp_bit))\r
-                        {\r
-                            got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)\r
-                        }\r
-                        else\r
-#endif\r
 #endif\r
 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1\r
                         if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)\r
@@ -2696,6 +2687,7 @@ irmp_ISR (void)
                                 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);\r
                                 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
 \r
+//                              irmp_busy_flag = FALSE;\r
                                 irmp_start_bit_detected = 0;                    // wait for another start bit...\r
                                 irmp_pulse_time         = 0;\r
                                 irmp_pause_time         = 0;\r
@@ -2843,6 +2835,7 @@ irmp_ISR (void)
                                 ANALYZE_NEWLINE ();\r
                                 ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                                 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                              irmp_busy_flag = FALSE;\r
                                 irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit\r
                                 irmp_pause_time         = 0;\r
                             }\r
@@ -2980,6 +2973,7 @@ irmp_ISR (void)
                         {                                                           // timing incorrect!\r
                             ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                          irmp_busy_flag = FALSE;\r
                             irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit\r
                             irmp_pause_time         = 0;\r
                         }\r
@@ -2995,9 +2989,8 @@ irmp_ISR (void)
 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1\r
                         irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)\r
                     {\r
-printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);\r
                         ANALYZE_PRINTF ("Switching to NEC16 protocol\n");\r
-                        irmp_param.protocol = IRMP_NEC16_PROTOCOL;\r
+                        irmp_param.protocol         = IRMP_NEC16_PROTOCOL;\r
                         irmp_param.address_offset   = NEC16_ADDRESS_OFFSET;\r
                         irmp_param.address_end      = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN;\r
                         irmp_param.command_offset   = NEC16_COMMAND_OFFSET;\r
@@ -3025,6 +3018,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                                 {                                                   // timing incorrect!\r
                                     ANALYZE_PRINTF ("error 3a B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                                  irmp_busy_flag = FALSE;\r
                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit\r
                                     irmp_pause_time         = 0;\r
                                 }\r
@@ -3041,6 +3035,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                                 {                                                   // timing incorrect!\r
                                     ANALYZE_PRINTF ("error 3b B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                                  irmp_busy_flag = FALSE;\r
                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit\r
                                     irmp_pause_time         = 0;\r
                                 }\r
@@ -3074,6 +3069,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                                 {                                                   // timing incorrect!\r
                                     ANALYZE_PRINTF ("error 3c B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                                  irmp_busy_flag = FALSE;\r
                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit\r
                                     irmp_pause_time         = 0;\r
                                 }\r
@@ -3083,6 +3079,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                         {                                                           // timing incorrect!\r
                             ANALYZE_PRINTF ("error 3d B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                          irmp_busy_flag = FALSE;\r
                             irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit\r
                             irmp_pause_time         = 0;\r
                         }\r
@@ -3137,6 +3134,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                     {                                                               // timing incorrect!\r
                         ANALYZE_PRINTF ("error 3: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);\r
                         ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
+//                      irmp_busy_flag = FALSE;\r
                         irmp_start_bit_detected = 0;                                // reset flags and wait for next start bit\r
                         irmp_pause_time         = 0;\r
                     }\r
@@ -3328,7 +3326,10 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
 \r
                         irmp_address = irmp_tmp_address;                            // store address\r
 #if IRMP_SUPPORT_NEC_PROTOCOL == 1\r
-                        last_irmp_address = irmp_tmp_address;                       // store as last address, too\r
+                        if (irmp_param.protocol == IRMP_NEC_PROTOCOL)\r
+                        {\r
+                            last_irmp_address = irmp_tmp_address;                   // store as last address, too\r
+                        }\r
 #endif\r
 \r
 #if IRMP_SUPPORT_RC5_PROTOCOL == 1\r
@@ -3347,8 +3348,8 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
 \r
                 if (irmp_ir_detected)\r
                 {\r
-                    if (last_irmp_command == irmp_command &&\r
-                        last_irmp_address == irmp_address &&\r
+                    if (last_irmp_command == irmp_tmp_command &&\r
+                        last_irmp_address == irmp_tmp_address &&\r
                         repetition_len < IRMP_KEY_REPETITION_LEN)\r
                     {\r
                         irmp_flags |= IRMP_FLAG_REPETITION;\r
@@ -3364,6 +3365,7 @@ printf ("! %d %d !\n", irmp_pause_time, NEC_START_BIT_PAUSE_LEN_MAX);
                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');\r
                 }\r
 \r
+//              irmp_busy_flag          = FALSE;\r
                 irmp_start_bit_detected = 0;                                        // and wait for next start bit\r
                 irmp_tmp_command        = 0;\r
                 irmp_pulse_time         = 0;\r