]> cloudbase.mooo.com Git - irmp.git/blobdiff - irsnd.c
Version 2.3.5: added A1TVBOX protocol.
[irmp.git] / irsnd.c
diff --git a/irsnd.c b/irsnd.c
index 17e78f51e9c66f11b345ac171acd48830cadac43..9fa491e1263bae7cc65bbce125eac5e4b61cb1a9 100644 (file)
--- a/irsnd.c
+++ b/irsnd.c
@@ -1,10 +1,11 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * @file irsnd.c\r
  *\r
- * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2012 Frank Meyer - frank(at)fli4l.de\r
  *\r
  * Supported mikrocontrollers:\r
  *\r
+ * ATtiny87,  ATtiny167\r
  * ATtiny45,  ATtiny85\r
  * ATtiny84\r
  * ATmega8,   ATmega16,  ATmega32\r
@@ -12,7 +13,7 @@
  * ATmega164, ATmega324, ATmega644,  ATmega644P, ATmega1284\r
  * ATmega88,  ATmega88P, ATmega168,  ATmega168P, ATmega328P\r
  *\r
- * $Id: irsnd.c,v 1.48 2012/02/24 14:24:28 fm Exp $\r
+ * $Id: irsnd.c,v 1.66 2012/12/12 15:50:03 fm Exp $\r
  *\r
  * This program is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
 \r
-#if defined(__18CXX)                     \r
-#define PIC_C18                                                             // Microchip C18\r
-#include <p18cxxx.h>                                                        // basic P18 lib\r
-#include "timers.h"                                                         // timer lib\r
-#include "pwm.h"                                                            // pwm lib\r
-#endif                                    \r
-\r
-#ifdef unix                                                                 // test/debug on linux/unix\r
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <inttypes.h>\r
-\r
-#define DEBUG\r
-#define F_CPU 8000000L\r
-\r
-#else // not unix:\r
-\r
-#ifdef WIN32                                                                 // test/debug on windows\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#define F_CPU 8000000L\r
-typedef unsigned char   uint8_t;\r
-typedef unsigned short  uint16_t;\r
-#define DEBUG\r
-\r
-#else\r
-\r
-#ifdef CODEVISION\r
-#define COM2A0 6\r
-#define WGM21  1\r
-#define CS20   0\r
-#elif defined(PIC_C18)\r
-    //nothing to do here\r
-#else\r
-#include <inttypes.h>\r
-#include <avr/io.h>\r
-#include <util/delay.h>\r
-#include <avr/pgmspace.h>\r
-#endif // CODEVISION\r
-\r
-#endif // WIN32\r
-#endif // unix\r
-\r
-#include "irmp.h"\r
-#include "irsndconfig.h"\r
 #include "irsnd.h"\r
 \r
+#ifndef F_CPU\r
+#  error F_CPU unkown\r
+#endif\r
+\r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  *  ATtiny pin definition of OC0A / OC0B\r
  *  ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
-#if defined (__AVR_ATtiny84__)                          // ATtiny84 uses OC0A = PB2 or OC0B = PA7\r
-#if IRSND_OCx == IRSND_OC0A                             // OC0A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               2       // OC0A\r
-#elif IRSND_OCx == IRSND_OC0B                           // OC0B\r
-#define IRSND_PORT                              PORTA   // port A\r
-#define IRSND_DDR                               DDRA    // ddr A\r
-#define IRSND_BIT                               7       // OC0B\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
-#elif defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__)  // ATtiny45/85 uses OC0A = PB0 or OC0B = PB1\r
-#if IRSND_OCx == IRSND_OC0A                             // OC0A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               0       // OC0A\r
-#elif IRSND_OCx == IRSND_OC0B                           // OC0B\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               1       // OC0B\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
-#elif defined (__AVR_ATmega8__)                         // ATmega8 uses only OC2 = PB3\r
-#if IRSND_OCx == IRSND_OC2                              // OC0A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               3       // OC0A\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
-\r
-#elif defined (__AVR_ATmega16__)    \\r
-  ||  defined (__AVR_ATmega32__)                        // ATmega16|32 uses OC2 = PD7\r
-#if IRSND_OCx == IRSND_OC2                              // OC2\r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               7       // OC2\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
-#elif defined (__AVR_ATmega162__)                       // ATmega162 uses OC2 = PB1 or OC0 = PB0\r
-#if IRSND_OCx == IRSND_OC2                              // OC2\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               1       // OC2\r
-\r
-#elif IRSND_OCx == IRSND_OC0                            // OC0\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               0       // OC0\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC2 or IRSND_OC0 in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
+#if defined (__AVR_ATtiny84__)                                      // ATtiny84 uses OC0A = PB2 or OC0B = PA7\r
+#  if IRSND_OCx == IRSND_OC0A                                       // OC0A\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        2\r
+#  elif IRSND_OCx == IRSND_OC0B                                     // OC0B\r
+#    define IRSND_PORT_LETTER                       A\r
+#    define IRSND_BIT_NUMBER                        7\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__)      // ATtiny45/85 uses OC0A = PB0 or OC0B = PB1\r
+#  if IRSND_OCx == IRSND_OC0A                                       // OC0A\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        0\r
+#  elif IRSND_OCx == IRSND_OC0B                                     // OC0B\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        1\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATtiny87__) || defined (__AVR_ATtiny167__)     // ATtiny87/167 uses OC0A = PA2\r
+#  if IRSND_OCx == IRSND_OC0A                                       // OC0A\r
+#    define IRSND_PORT_LETTER                       A\r
+#    define IRSND_BIT_NUMBER                        2\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC0A in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATmega8__)                                     // ATmega8 uses only OC2 = PB3\r
+#  if IRSND_OCx == IRSND_OC2                                        // OC0A\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        3\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)      // ATmega16|32 uses OC2 = PD7\r
+#  if IRSND_OCx == IRSND_OC2                                        // OC2\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        7\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATmega162__)                                   // ATmega162 uses OC2 = PB1 or OC0 = PB0\r
+#  if IRSND_OCx == IRSND_OC2                                        // OC2\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        1\r
+#  elif IRSND_OCx == IRSND_OC0                                      // OC0\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        0\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC2 or IRSND_OC0 in irsndconfig.h\r
+#  endif // IRSND_OCx\r
 #elif defined (__AVR_ATmega164__)   \\r
    || defined (__AVR_ATmega324__)   \\r
    || defined (__AVR_ATmega644__)   \\r
    || defined (__AVR_ATmega644P__)  \\r
    || defined (__AVR_ATmega1284__)  \\r
-   || defined (__AVR_ATmega1284P__)                     // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 or OC0A = PB3 or OC0B = PB4\r
-#if IRSND_OCx == IRSND_OC2A                             // OC2A\r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               7       // OC2A\r
-#elif IRSND_OCx == IRSND_OC2B                           // OC2B\r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               6       // OC2B\r
-#elif IRSND_OCx == IRSND_OC0A                           // OC0A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               3       // OC0A\r
-#elif IRSND_OCx == IRSND_OC0B                           // OC0B\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               4       // OC0B\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
+   || defined (__AVR_ATmega1284P__)                                 // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 or OC0A = PB3 or OC0B = PB4\r
+#  if IRSND_OCx == IRSND_OC2A                                       // OC2A\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        7\r
+#  elif IRSND_OCx == IRSND_OC2B                                     // OC2B\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        6\r
+#  elif IRSND_OCx == IRSND_OC0A                                     // OC0A\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        3\r
+#  elif IRSND_OCx == IRSND_OC0B                                     // OC0B\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        4\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h\r
+#  endif // IRSND_OCx\r
 #elif defined (__AVR_ATmega48__)    \\r
    || defined (__AVR_ATmega88__)    \\r
    || defined (__AVR_ATmega88P__)   \\r
    || defined (__AVR_ATmega168__)   \\r
    || defined (__AVR_ATmega168P__)  \\r
-   || defined (__AVR_ATmega328P__)                      // ATmega48|88|168|168|328 uses OC2A = PB3 or OC2B = PD3 or OC0A = PD6 or OC0B = PD5\r
-#if IRSND_OCx == IRSND_OC2A                             // OC2A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               3       // OC2A\r
-#elif IRSND_OCx == IRSND_OC2B                           // OC2B\r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               3       // OC2B\r
-#elif IRSND_OCx == IRSND_OC0A                           // OC0A\r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               6       // OC0A\r
-#elif IRSND_OCx == IRSND_OC0B                           // OC0B\r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               5       // OC0B\r
-#else\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h\r
-#endif // IRSND_OCx\r
-#elif defined (__AVR_ATmega8515__) \r
-#if IRSND_OCx == IRSND_OC0   \r
-#define IRSND_PORT                              PORTB   // port B\r
-#define IRSND_DDR                               DDRB    // ddr B\r
-#define IRSND_BIT                               0       // OC0\r
-#elif IRSND_OCx == IRSND_OC1A \r
-#define IRSND_PORT                              PORTD   // port D\r
-#define IRSND_DDR                               DDRD    // ddr D\r
-#define IRSND_BIT                               5       // OC1A\r
-#elif IRSND_OCx == IRSND_OC1B \r
-#define IRSND_PORT                              PORTE   // port E\r
-#define IRSND_DDR                               DDRE    // ddr E\r
-#define IRSND_BIT                               2       // OC1E\r
-#error Wrong value for IRSND_OCx, choose IRSND_OC0, IRSND_OC1A, or IRSND_OC1B in irsndconfig.h\r
-#endif // IRSND_OCx\r
-\r
+   || defined (__AVR_ATmega328P__)                                  // ATmega48|88|168|168|328 uses OC2A = PB3 or OC2B = PD3 or OC0A = PD6 or OC0B = PD5\r
+#  if IRSND_OCx == IRSND_OC2A                                       // OC2A\r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        3\r
+#  elif IRSND_OCx == IRSND_OC2B                                     // OC2B\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        3\r
+#  elif IRSND_OCx == IRSND_OC0A                                     // OC0A\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        6\r
+#  elif IRSND_OCx == IRSND_OC0B                                     // OC0B\r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        5\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h\r
+#  endif // IRSND_OCx\r
+#elif defined (__AVR_ATmega8515__)                                  // ATmega8515 uses OC0 = PB0 or OC1A = PD5 or OC1B = PE2\r
+#  if IRSND_OCx == IRSND_OC0   \r
+#    define IRSND_PORT_LETTER                       B\r
+#    define IRSND_BIT_NUMBER                        0\r
+#  elif IRSND_OCx == IRSND_OC1A \r
+#    define IRSND_PORT_LETTER                       D\r
+#    define IRSND_BIT_NUMBER                        5\r
+#  elif IRSND_OCx == IRSND_OC1B \r
+#    define IRSND_PORT_LETTER                       E\r
+#    define IRSND_BIT_NUMBER                        2\r
+#  else\r
+#    error Wrong value for IRSND_OCx, choose IRSND_OC0, IRSND_OC1A, or IRSND_OC1B in irsndconfig.h\r
+#  endif // IRSND_OCx\r
 #elif defined (PIC_C18)    //Microchip C18 compiler\r
     //Nothing here to do here -> See irsndconfig.h\r
-\r
+#elif defined (ARM_STM32)  //STM32\r
+    //Nothing here to do here -> See irsndconfig.h\r
 #else\r
-#if !defined (unix) && !defined (WIN32)\r
-#error mikrocontroller not defined, please fill in definitions here.\r
-#endif // unix, WIN32\r
+#  if !defined (unix) && !defined (WIN32)\r
+#    error mikrocontroller not defined, please fill in definitions here.\r
+#  endif // unix, WIN32\r
 #endif // __AVR...\r
 \r
+#if defined(ATMEL_AVR)\r
+#  define _CONCAT(a,b)                              a##b\r
+#  define CONCAT(a,b)                               _CONCAT(a,b)\r
+#  define IRSND_PORT                                CONCAT(PORT, IRSND_PORT_LETTER)\r
+#  define IRSND_DDR                                 CONCAT(DDR, IRSND_PORT_LETTER)\r
+#  define IRSND_BIT                                 IRSND_BIT_NUMBER\r
+#endif\r
+\r
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
     typedef uint16_t    IRSND_PAUSE_LEN;\r
 #else\r
@@ -334,23 +278,38 @@ typedef unsigned short  uint16_t;
 #define SIEMENS_BIT_LEN                         (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5)\r
 #define SIEMENS_FRAME_REPEAT_PAUSE_LEN          (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5)  // use uint16_t!\r
 \r
-\r
-#ifdef PIC_C18\r
-#define IRSND_FREQ_30_KHZ                       (uint8_t) ((F_CPU / 30000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_32_KHZ                       (uint8_t) ((F_CPU / 32000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_36_KHZ                       (uint8_t) ((F_CPU / 36000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_38_KHZ                       (uint8_t) ((F_CPU / 38000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_40_KHZ                       (uint8_t) ((F_CPU / 40000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_56_KHZ                       (uint8_t) ((F_CPU / 56000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#define IRSND_FREQ_455_KHZ                      (uint8_t) ((F_CPU / 455000 / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
-#else // AVR\r
-#define IRSND_FREQ_30_KHZ                       (uint8_t) ((F_CPU / 30000 / 2) - 1)\r
-#define IRSND_FREQ_32_KHZ                       (uint8_t) ((F_CPU / 32000 / 2) - 1)\r
-#define IRSND_FREQ_36_KHZ                       (uint8_t) ((F_CPU / 36000 / 2) - 1)\r
-#define IRSND_FREQ_38_KHZ                       (uint8_t) ((F_CPU / 38000 / 2) - 1)\r
-#define IRSND_FREQ_40_KHZ                       (uint8_t) ((F_CPU / 40000 / 2) - 1)\r
-#define IRSND_FREQ_56_KHZ                       (uint8_t) ((F_CPU / 56000 / 2) - 1)\r
-#define IRSND_FREQ_455_KHZ                      (uint8_t) ((F_CPU / 455000 / 2) - 1)\r
+#ifdef PIC_C18                                  // PIC C18\r
+#  define IRSND_FREQ_TYPE                       uint8_t\r
+#  define IRSND_FREQ_30_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 30000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_32_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 32000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_36_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 36000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_38_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 38000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_40_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 40000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_56_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 56000  / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#  define IRSND_FREQ_455_KHZ                    (IRSND_FREQ_TYPE) ((F_CPU / 455000 / 2 / Pre_Scaler / PIC_Scaler) - 1)\r
+#elif defined (ARM_STM32)                       // STM32\r
+#  define IRSND_FREQ_TYPE                       uint32_t\r
+#  define IRSND_FREQ_30_KHZ                     (IRSND_FREQ_TYPE) (30000)\r
+#  define IRSND_FREQ_32_KHZ                     (IRSND_FREQ_TYPE) (32000)\r
+#  define IRSND_FREQ_36_KHZ                     (IRSND_FREQ_TYPE) (36000)\r
+#  define IRSND_FREQ_38_KHZ                     (IRSND_FREQ_TYPE) (38000)\r
+#  define IRSND_FREQ_40_KHZ                     (IRSND_FREQ_TYPE) (40000)\r
+#  define IRSND_FREQ_56_KHZ                     (IRSND_FREQ_TYPE) (56000)\r
+#  define IRSND_FREQ_455_KHZ                    (IRSND_FREQ_TYPE) (455000)\r
+#else                                           // AVR\r
+#  if F_CPU >= 16000000L\r
+#    define AVR_PRESCALER                       8\r
+#  else\r
+#    define AVR_PRESCALER                       1\r
+#  endif\r
+#  define IRSND_FREQ_TYPE                       uint8_t\r
+#  define IRSND_FREQ_30_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 30000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_32_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 32000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_36_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 36000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_38_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 38000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_40_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 40000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_56_KHZ                     (IRSND_FREQ_TYPE) ((F_CPU / 56000 / AVR_PRESCALER / 2) - 1)\r
+#  define IRSND_FREQ_455_KHZ                    (IRSND_FREQ_TYPE) ((F_CPU / 455000 / AVR_PRESCALER / 2) - 1)\r
 #endif\r
 \r
 #define FDC_START_BIT_PULSE_LEN                 (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)\r
@@ -391,6 +350,13 @@ typedef unsigned short  uint16_t;
 #define LEGO_0_PAUSE_LEN                        (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5)\r
 #define LEGO_FRAME_REPEAT_PAUSE_LEN             (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5)               // use uint16_t!\r
 \r
+#define A1TVBOX_START_BIT_PULSE_LEN             (uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PULSE_TIME + 0.5)\r
+#define A1TVBOX_START_BIT_PAUSE_LEN             (uint8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PAUSE_TIME + 0.5)\r
+#define A1TVBOX_BIT_PULSE_LEN                   (uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PULSE_TIME + 0.5)\r
+#define A1TVBOX_BIT_PAUSE_LEN                   (uint8_t)(F_INTERRUPTS * A1TVBOX_BIT_PAUSE_TIME + 0.5)\r
+#define A1TVBOX_FRAME_REPEAT_PAUSE_LEN          (uint16_t)(F_INTERRUPTS * A1TVBOX_FRAME_REPEAT_PAUSE_TIME + 0.5)            // use uint16_t!\r
+#define A1TVBOX_FRAME_REPEAT_PAUSE_LEN          (uint16_t)(F_INTERRUPTS * A1TVBOX_FRAME_REPEAT_PAUSE_TIME + 0.5)            // use uint16_t!\r
+\r
 static volatile uint8_t                         irsnd_busy = 0;\r
 static volatile uint8_t                         irsnd_protocol = 0;\r
 static volatile uint8_t                         irsnd_buffer[6] = {0};\r
@@ -403,7 +369,6 @@ static void                                     (*irsnd_callback_ptr) (uint8_t);
 \r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  *  Switch PWM on\r
- *  @details  Switches PWM on with a narrow spike on all 3 channels -> leds glowing\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
 static void\r
@@ -412,38 +377,39 @@ irsnd_on (void)
     if (! irsnd_is_on)\r
     {\r
 #ifndef DEBUG\r
-\r
-#if defined(PIC_C18)\r
-        IRSND_PIN = 0; // output mode -> enable PWM outout pin (0=PWM on, 1=PWM off)\r
-#else\r
-\r
-#if   IRSND_OCx == IRSND_OC2                            // use OC2\r
-        TCCR2 |= (1<<COM20)|(1<<WGM21);                 // toggle OC2 on compare match,  clear Timer 2 at compare match OCR2\r
-#elif IRSND_OCx == IRSND_OC2A                           // use OC2A\r
-        TCCR2A |= (1<<COM2A0)|(1<<WGM21);               // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r
-#elif IRSND_OCx == IRSND_OC2B                           // use OC2B\r
-        TCCR2A |= (1<<COM2B0)|(1<<WGM21);               // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)\r
-#elif IRSND_OCx == IRSND_OC0                            // use OC0\r
-        TCCR0 |= (1<<COM00)|(1<<WGM01);                 // toggle OC0 on compare match,  clear Timer 0 at compare match OCR0\r
-#elif IRSND_OCx == IRSND_OC0A                           // use OC0A\r
-        TCCR0A |= (1<<COM0A0)|(1<<WGM01);               // toggle OC0A on compare match, clear Timer 0 at compare match OCR0A\r
-#elif IRSND_OCx == IRSND_OC0B                           // use OC0B\r
-        TCCR0A |= (1<<COM0B0)|(1<<WGM01);               // toggle OC0B on compare match, clear Timer 0 at compare match OCR0A (yes: A, not B!)\r
-#else\r
-#error wrong value of IRSND_OCx\r
-#endif // IRSND_OCx\r
-\r
-#endif //C18\r
+#  if defined(PIC_C18)                                  // PIC C18\r
+       IRSND_PIN = 0; // output mode -> enable PWM outout pin (0=PWM on, 1=PWM off)\r
+#  elif defined (ARM_STM32)                             // STM32\r
+       TIM_SelectOCxM(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_OCMode_PWM1); // enable PWM as OC-mode\r
+       TIM_CCxCmd(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_CCx_Enable);      // enable OC-output (is being disabled in TIM_SelectOCxM())\r
+       TIM_Cmd(IRSND_TIMER, ENABLE);                   // enable counter\r
+#  else                                                 // AVR\r
+#    if   IRSND_OCx == IRSND_OC2                        // use OC2\r
+       TCCR2 |= (1<<COM20)|(1<<WGM21);                 // toggle OC2 on compare match,  clear Timer 2 at compare match OCR2\r
+#    elif IRSND_OCx == IRSND_OC2A                       // use OC2A\r
+       TCCR2A |= (1<<COM2A0)|(1<<WGM21);               // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r
+#    elif IRSND_OCx == IRSND_OC2B                       // use OC2B\r
+       TCCR2A |= (1<<COM2B0)|(1<<WGM21);               // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)\r
+#    elif IRSND_OCx == IRSND_OC0                        // use OC0\r
+       TCCR0 |= (1<<COM00)|(1<<WGM01);                 // toggle OC0 on compare match,  clear Timer 0 at compare match OCR0\r
+#    elif IRSND_OCx == IRSND_OC0A                       // use OC0A\r
+       TCCR0A |= (1<<COM0A0)|(1<<WGM01);               // toggle OC0A on compare match, clear Timer 0 at compare match OCR0A\r
+#    elif IRSND_OCx == IRSND_OC0B                       // use OC0B\r
+       TCCR0A |= (1<<COM0B0)|(1<<WGM01);               // toggle OC0B on compare match, clear Timer 0 at compare match OCR0A (yes: A, not B!)\r
+#    else\r
+#      error wrong value of IRSND_OCx\r
+#    endif // IRSND_OCx\r
+#  endif // C18\r
 #endif // DEBUG\r
 \r
 #if IRSND_USE_CALLBACK == 1\r
-        if (irsnd_callback_ptr)\r
-        {\r
-            (*irsnd_callback_ptr) (TRUE);\r
-        }\r
+       if (irsnd_callback_ptr)\r
+       {\r
+           (*irsnd_callback_ptr) (TRUE);\r
+       }\r
 #endif // IRSND_USE_CALLBACK == 1\r
 \r
-        irsnd_is_on = TRUE;\r
+       irsnd_is_on = TRUE;\r
     }\r
 }\r
 \r
@@ -459,37 +425,42 @@ irsnd_off (void)
     {\r
 #ifndef DEBUG\r
     \r
-#if defined(PIC_C18)\r
-        IRSND_PIN = 1; //input mode -> disbale PWM output pin (0=PWM on, 1=PWM off)\r
-#else //AVR\r
-\r
-#if   IRSND_OCx == IRSND_OC2                                    // use OC2\r
-        TCCR2 &= ~(1<<COM20);                           // normal port operation, OC2 disconnected.\r
-#elif IRSND_OCx == IRSND_OC2A                                    // use OC2A\r
-        TCCR2A &= ~(1<<COM2A0);                         // normal port operation, OC2A disconnected.\r
-#elif IRSND_OCx == IRSND_OC2B                                    // use OC2B\r
-        TCCR2A &= ~(1<<COM2B0);                         // normal port operation, OC2B disconnected.\r
-#elif IRSND_OCx == IRSND_OC0                                    // use OC0\r
-        TCCR0 &= ~(1<<COM00);                           // normal port operation, OC0 disconnected.\r
-#elif IRSND_OCx == IRSND_OC0A                                    // use OC0A\r
-        TCCR0A &= ~(1<<COM0A0);                         // normal port operation, OC0A disconnected.\r
-#elif IRSND_OCx == IRSND_OC0B                                    // use OC0B\r
-        TCCR0A &= ~(1<<COM0B0);                         // normal port operation, OC0B disconnected.\r
-#else\r
-#error wrong value of IRSND_OCx\r
-#endif // IRSND_OCx\r
-        IRSND_PORT  &= ~(1<<IRSND_BIT);                 // set IRSND_BIT to low\r
-#endif //C18\r
+#  if defined(PIC_C18)                                  // PIC C18\r
+       IRSND_PIN = 1; //input mode -> disbale PWM output pin (0=PWM on, 1=PWM off)\r
+#  elif defined (ARM_STM32)                             // STM32\r
+       TIM_Cmd(IRSND_TIMER, DISABLE);                  // disable counter\r
+       TIM_SelectOCxM(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_ForcedAction_InActive);   // force output inactive\r
+       TIM_CCxCmd(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_CCx_Enable);      // enable OC-output (is being disabled in TIM_SelectOCxM())\r
+       TIM_SetCounter(IRSND_TIMER, 0);                 // reset counter value\r
+#  else //AVR\r
+\r
+#    if   IRSND_OCx == IRSND_OC2                        // use OC2\r
+       TCCR2 &= ~(1<<COM20);                           // normal port operation, OC2 disconnected.\r
+#    elif IRSND_OCx == IRSND_OC2A                       // use OC2A\r
+       TCCR2A &= ~(1<<COM2A0);                         // normal port operation, OC2A disconnected.\r
+#    elif IRSND_OCx == IRSND_OC2B                       // use OC2B\r
+       TCCR2A &= ~(1<<COM2B0);                         // normal port operation, OC2B disconnected.\r
+#    elif IRSND_OCx == IRSND_OC0                        // use OC0\r
+       TCCR0 &= ~(1<<COM00);                           // normal port operation, OC0 disconnected.\r
+#    elif IRSND_OCx == IRSND_OC0A                       // use OC0A\r
+       TCCR0A &= ~(1<<COM0A0);                         // normal port operation, OC0A disconnected.\r
+#    elif IRSND_OCx == IRSND_OC0B                       // use OC0B\r
+       TCCR0A &= ~(1<<COM0B0);                         // normal port operation, OC0B disconnected.\r
+#    else\r
+#      error wrong value of IRSND_OCx\r
+#    endif // IRSND_OCx\r
+       IRSND_PORT  &= ~(1<<IRSND_BIT);                 // set IRSND_BIT to low\r
+#  endif //C18\r
 #endif // DEBUG\r
 \r
 #if IRSND_USE_CALLBACK == 1\r
-        if (irsnd_callback_ptr)\r
-        {\r
-           (*irsnd_callback_ptr) (FALSE);\r
-        }\r
+       if (irsnd_callback_ptr)\r
+       {\r
+          (*irsnd_callback_ptr) (FALSE);\r
+       }\r
 #endif // IRSND_USE_CALLBACK == 1\r
 \r
-        irsnd_is_on = FALSE;\r
+       irsnd_is_on = FALSE;\r
     }\r
 }\r
 \r
@@ -499,31 +470,65 @@ irsnd_off (void)
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
 static void\r
-irsnd_set_freq (uint8_t freq)\r
+irsnd_set_freq (IRSND_FREQ_TYPE freq)\r
 {\r
 #ifndef DEBUG\r
-\r
-#if defined(PIC_C18)\r
-     OpenPWM(freq); \r
-     SetDCPWM( (uint16_t) freq * 2); // freq*2 = Duty cycles 50%\r
-#else //AVR\r
-\r
-#if IRSND_OCx == IRSND_OC2\r
-    OCR2 = freq;                                                                        // use register OCR2 for OC2\r
-#elif IRSND_OCx == IRSND_OC2A                                                                    // use OC2A\r
-    OCR2A = freq;                                                                       // use register OCR2A for OC2A and OC2B!\r
-#elif IRSND_OCx == IRSND_OC2B                                                                    // use OC2B\r
-    OCR2A = freq;                                                                       // use register OCR2A for OC2A and OC2B!\r
-#elif IRSND_OCx == IRSND_OC0                                                                    // use OC0\r
-    OCR0 = freq;                                                                        // use register OCR2 for OC2\r
-#elif IRSND_OCx == IRSND_OC0A                                                                    // use OC0A\r
-    OCR0A = freq;                                                                       // use register OCR0A for OC0A and OC0B!\r
-#elif IRSND_OCx == IRSND_OC0B                                                                    // use OC0B\r
-    OCR0A = freq;                                                                       // use register OCR0A for OC0A and OC0B!\r
-#else\r
-#error wrong value of IRSND_OCx\r
-#endif\r
-#endif //PIC_C18\r
+#  if defined(PIC_C18)                                                                      // PIC C18\r
+        OpenPWM(freq); \r
+        SetDCPWM( (uint16_t) freq * 2); // freq*2 = Duty cycles 50%\r
+#  elif defined (ARM_STM32)                                                                 // STM32\r
+        static uint32_t      TimeBaseFreq = 0;\r
+\r
+        if (TimeBaseFreq == 0)\r
+        {\r
+           RCC_ClocksTypeDef        RCC_ClocksStructure;\r
+           /* Get system clocks and store timer clock in variable */\r
+           RCC_GetClocksFreq(&RCC_ClocksStructure);\r
+#    if ((IRSND_TIMER_NUMBER >= 2) && (IRSND_TIMER_NUMBER <= 5)) || ((IRSND_TIMER_NUMBER >= 12) && (IRSND_TIMER_NUMBER <= 14))\r
+           if (RCC_ClocksStructure.PCLK1_Frequency == RCC_ClocksStructure.HCLK_Frequency)\r
+           {\r
+              TimeBaseFreq = RCC_ClocksStructure.PCLK1_Frequency;\r
+           }\r
+           else\r
+           {\r
+              TimeBaseFreq = RCC_ClocksStructure.PCLK1_Frequency * 2;\r
+           }\r
+#    else\r
+           if (RCC_ClocksStructure.PCLK2_Frequency == RCC_ClocksStructure.HCLK_Frequency)\r
+           {\r
+              TimeBaseFreq = RCC_ClocksStructure.PCLK2_Frequency;\r
+           }\r
+           else\r
+           {\r
+              TimeBaseFreq = RCC_ClocksStructure.PCLK2_Frequency * 2;\r
+           }\r
+#    endif\r
+        }\r
+\r
+        freq = TimeBaseFreq/freq;\r
+\r
+        /* Set frequency */\r
+        TIM_SetAutoreload(IRSND_TIMER, freq - 1);\r
+        /* Set duty cycle */\r
+        TIM_SetCompare1(IRSND_TIMER, (freq + 1) / 2);\r
+#  else                                                                                     // AVR\r
+\r
+#    if IRSND_OCx == IRSND_OC2\r
+       OCR2 = freq;                                                                        // use register OCR2 for OC2\r
+#    elif IRSND_OCx == IRSND_OC2A                                                           // use OC2A\r
+       OCR2A = freq;                                                                       // use register OCR2A for OC2A and OC2B!\r
+#    elif IRSND_OCx == IRSND_OC2B                                                           // use OC2B\r
+       OCR2A = freq;                                                                       // use register OCR2A for OC2A and OC2B!\r
+#    elif IRSND_OCx == IRSND_OC0                                                            // use OC0\r
+       OCR0 = freq;                                                                        // use register OCR2 for OC2\r
+#    elif IRSND_OCx == IRSND_OC0A                                                           // use OC0A\r
+       OCR0A = freq;                                                                       // use register OCR0A for OC0A and OC0B!\r
+#    elif IRSND_OCx == IRSND_OC0B                                                           // use OC0B\r
+       OCR0A = freq;                                                                       // use register OCR0A for OC0A and OC0B!\r
+#    else\r
+#      error wrong value of IRSND_OCx\r
+#    endif\r
+#  endif //PIC_C18\r
 #endif // DEBUG\r
 }\r
 \r
@@ -536,31 +541,103 @@ void
 irsnd_init (void)\r
 {\r
 #ifndef DEBUG\r
-#if defined(PIC_C18)\r
-    OpenTimer;\r
-    irsnd_set_freq (IRSND_FREQ_36_KHZ);   //default frequency\r
-    IRSND_PIN = 1; //default PWM output pin off (0=PWM on, 1=PWM off)\r
-#else\r
-    IRSND_PORT &= ~(1<<IRSND_BIT);                                                  // set IRSND_BIT to low\r
-    IRSND_DDR |= (1<<IRSND_BIT);                                                    // set IRSND_BIT to output\r
-\r
-#if IRSND_OCx == IRSND_OC2                                                                  // use OC2\r
-    TCCR2 = (1<<WGM21);                                                             // CTC mode\r
-    TCCR2 |= (1<<CS20);                                                             // 0x01, start Timer 2, no prescaling\r
-#elif IRSND_OCx == IRSND_OC2A || IRSND_OCx == IRSND_OC2B                                              // use OC2A or OC2B\r
-    TCCR2A = (1<<WGM21);                                                            // CTC mode\r
-    TCCR2B |= (1<<CS20);                                                            // 0x01, start Timer 2, no prescaling\r
-#elif IRSND_OCx == IRSND_OC0                                                                // use OC0\r
-    TCCR0 = (1<<WGM01);                                                             // CTC mode\r
-    TCCR0 |= (1<<CS00);                                                             // 0x01, start Timer 0, no prescaling\r
-#elif IRSND_OCx == IRSND_OC0A || IRSND_OCx == IRSND_OC0B                                              // use OC0A or OC0B\r
-    TCCR0A = (1<<WGM01);                                                            // CTC mode\r
-    TCCR0B |= (1<<CS00);                                                            // 0x01, start Timer 0, no prescaling\r
-#else\r
-#error wrong value of IRSND_OCx\r
-#endif\r
-    irsnd_set_freq (IRSND_FREQ_36_KHZ);                                             // default frequency\r
-#endif //PIC_C18\r
+#  if defined(PIC_C18)                                                      // PIC C18\r
+       OpenTimer;\r
+       irsnd_set_freq (IRSND_FREQ_36_KHZ);   //default frequency\r
+       IRSND_PIN = 1; //default PWM output pin off (0=PWM on, 1=PWM off)\r
+#  elif defined (ARM_STM32)                                                 // STM32\r
+       GPIO_InitTypeDef            GPIO_InitStructure;\r
+       TIM_TimeBaseInitTypeDef     TIM_TimeBaseStructure;\r
+       TIM_OCInitTypeDef           TIM_OCInitStructure;\r
+\r
+       /* GPIOx clock enable */\r
+#    if defined (ARM_STM32L1XX)\r
+       RCC_AHBPeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+#    elif defined (ARM_STM32F10X)\r
+       RCC_APB2PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+#    elif defined (ARM_STM32F4XX)\r
+       RCC_AHB1PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+#    endif\r
+\r
+       /* GPIO Configuration */\r
+       GPIO_InitStructure.GPIO_Pin = IRSND_BIT;\r
+#    if defined (ARM_STM32L1XX) || defined (ARM_STM32F4XX)\r
+       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
+       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;\r
+       GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\r
+       GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;\r
+       GPIO_Init(IRSND_PORT, &GPIO_InitStructure);\r
+       GPIO_PinAFConfig(IRSND_PORT, (uint8_t)IRSND_BIT_NUMBER, IRSND_GPIO_AF);\r
+#    elif defined (ARM_STM32F10X)\r
+       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;\r
+       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;\r
+       GPIO_Init(IRSND_PORT, &GPIO_InitStructure);\r
+       GPIO_PinRemapConfig(, ENABLE);         // TODO: remapping required\r
+#    endif\r
+\r
+       /* TIMx clock enable */\r
+#    if ((IRSND_TIMER_NUMBER >= 2) && (IRSND_TIMER_NUMBER <= 5)) || ((IRSND_TIMER_NUMBER >= 12) && (IRSND_TIMER_NUMBER <= 14))\r
+       RCC_APB1PeriphClockCmd(IRSND_TIMER_RCC, ENABLE);\r
+#    else\r
+       RCC_APB2PeriphClockCmd(IRSND_TIMER_RCC, ENABLE);\r
+#    endif\r
+\r
+       /* Time base configuration */\r
+       TIM_TimeBaseStructure.TIM_Period = -1;     // set dummy value (don't set to 0), will be initialized later\r
+       TIM_TimeBaseStructure.TIM_Prescaler = 0;\r
+       TIM_TimeBaseStructure.TIM_ClockDivision = 0;\r
+       TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;\r
+       TIM_TimeBaseInit(IRSND_TIMER, &TIM_TimeBaseStructure);\r
+\r
+       /* PWM1 Mode configuration */\r
+       TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;\r
+       TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;\r
+       TIM_OCInitStructure.TIM_Pulse = 0;         // will be initialized later\r
+       TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;\r
+       TIM_OC1Init(IRSND_TIMER, &TIM_OCInitStructure);\r
+\r
+       /* Preload configuration */\r
+       TIM_ARRPreloadConfig(IRSND_TIMER, ENABLE);\r
+       TIM_OC1PreloadConfig(IRSND_TIMER, TIM_OCPreload_Enable);\r
+\r
+       irsnd_set_freq (IRSND_FREQ_36_KHZ);                                         // set default frequency\r
+#  else                                                                             // AVR\r
+       IRSND_PORT &= ~(1<<IRSND_BIT);                                              // set IRSND_BIT to low\r
+       IRSND_DDR |= (1<<IRSND_BIT);                                                // set IRSND_BIT to output\r
+\r
+#    if   IRSND_OCx == IRSND_OC2                                                    // use OC2\r
+       TCCR2 = (1<<WGM21);                                                         // CTC mode\r
+#       if AVR_PRESCALER == 8\r
+         TCCR2 |= (1<<CS21);                                                       // start Timer 2, prescaler = 8\r
+#       else\r
+         TCCR2 |= (1<<CS20);                                                       // start Timer 2, prescaler = 1\r
+#       endif\r
+#    elif IRSND_OCx == IRSND_OC2A || IRSND_OCx == IRSND_OC2B                        // use OC2A or OC2B\r
+       TCCR2A = (1<<WGM21);                                                        // CTC mode\r
+#       if AVR_PRESCALER == 8\r
+         TCCR2B = (1<<CS21);                                                       // start Timer 2, prescaler = 8\r
+#       else\r
+         TCCR2B = (1<<CS20);                                                       // start Timer 2, prescaler = 1\r
+#       endif\r
+#    elif IRSND_OCx == IRSND_OC0                                                    // use OC0\r
+       TCCR0 = (1<<WGM01);                                                         // CTC mode\r
+#       if AVR_PRESCALER == 8\r
+         TCCR0 |= (1<<CS01);                                                       // start Timer 0, prescaler = 8\r
+#       else\r
+         TCCR0 |= (1<<CS00);                                                       // start Timer 0, prescaler = 1\r
+#       endif\r
+#    elif IRSND_OCx == IRSND_OC0A || IRSND_OCx == IRSND_OC0B                        // use OC0A or OC0B\r
+       TCCR0A = (1<<WGM01);                                                        // CTC mode\r
+#       if AVR_PRESCALER == 8\r
+         TCCR0B = (1<<CS01);                                                       // start Timer 0, prescaler = 8\r
+#       else\r
+         TCCR0B = (1<<CS00);                                                       // start Timer 0, prescaler = 1\r
+#       endif\r
+#    else\r
+#      error wrong value of IRSND_OCx\r
+#    endif\r
+       irsnd_set_freq (IRSND_FREQ_36_KHZ);                                         // default frequency\r
+#  endif //PIC_C18\r
 #endif // DEBUG\r
 }\r
 \r
@@ -585,13 +662,13 @@ bitsrevervse (uint16_t x, uint8_t len)
 \r
     while(len)\r
     {\r
-        xx <<= 1;\r
-        if (x & 1)\r
-        {\r
-            xx |= 1;\r
-        }\r
-        x >>= 1;\r
-        len--;\r
+       xx <<= 1;\r
+       if (x & 1)\r
+       {\r
+           xx |= 1;\r
+       }\r
+       x >>= 1;\r
+       len--;\r
     }\r
     return xx;\r
 }\r
@@ -624,14 +701,14 @@ irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)
 \r
     if (do_wait)\r
     {\r
-        while (irsnd_busy)\r
-        {\r
-            // do nothing;\r
-        }\r
+       while (irsnd_busy)\r
+       {\r
+           // do nothing;\r
+       }\r
     }\r
     else if (irsnd_busy)\r
     {\r
-        return (FALSE);\r
+       return (FALSE);\r
     }\r
 \r
     irsnd_protocol  = irmp_data_p->protocol;\r
@@ -640,385 +717,399 @@ irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)
     switch (irsnd_protocol)\r
     {\r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r
-        case IRMP_SIRCS_PROTOCOL:\r
-        {\r
-            uint8_t  sircs_additional_command_len;\r
-            uint8_t  sircs_additional_address_len;\r
-\r
-            sircs_additional_bitlen = (irmp_data_p->address & 0xFF00) >> 8;                             // additional bitlen\r
-\r
-            if (sircs_additional_bitlen > 15 - SIRCS_MINIMUM_DATA_LEN)\r
-            {\r
-                sircs_additional_command_len = 15 - SIRCS_MINIMUM_DATA_LEN;\r
-                sircs_additional_address_len = sircs_additional_bitlen - (15 - SIRCS_MINIMUM_DATA_LEN);\r
-            }\r
-            else\r
-            {\r
-                sircs_additional_command_len = sircs_additional_bitlen;\r
-                sircs_additional_address_len = 0;\r
-            }\r
-\r
-            command = bitsrevervse (irmp_data_p->command, 15);\r
-\r
-            irsnd_buffer[0] = (command & 0x7F80) >> 7;                                                  // CCCCCCCC\r
-            irsnd_buffer[1] = (command & 0x007F) << 1;                                                  // CCCC****\r
-\r
-            if (sircs_additional_address_len > 0)\r
-            {\r
-                address = bitsrevervse (irmp_data_p->address, 5);\r
-                irsnd_buffer[1] |= (address & 0x0010) >> 4;\r
-                irsnd_buffer[2] =  (address & 0x000F) << 4;\r
-            }\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_SIRCS_PROTOCOL:\r
+       {\r
+           // uint8_t  sircs_additional_command_len;\r
+           uint8_t  sircs_additional_address_len;\r
+\r
+           sircs_additional_bitlen = (irmp_data_p->address & 0xFF00) >> 8;                             // additional bitlen\r
+\r
+           if (sircs_additional_bitlen > 15 - SIRCS_MINIMUM_DATA_LEN)\r
+           {\r
+               // sircs_additional_command_len = 15 - SIRCS_MINIMUM_DATA_LEN;\r
+               sircs_additional_address_len = sircs_additional_bitlen - (15 - SIRCS_MINIMUM_DATA_LEN);\r
+           }\r
+           else\r
+           {\r
+               // sircs_additional_command_len = sircs_additional_bitlen;\r
+               sircs_additional_address_len = 0;\r
+           }\r
+\r
+           command = bitsrevervse (irmp_data_p->command, 15);\r
+\r
+           irsnd_buffer[0] = (command & 0x7F80) >> 7;                                                  // CCCCCCCC\r
+           irsnd_buffer[1] = (command & 0x007F) << 1;                                                  // CCCC****\r
+\r
+           if (sircs_additional_address_len > 0)\r
+           {\r
+               address = bitsrevervse (irmp_data_p->address, 5);\r
+               irsnd_buffer[1] |= (address & 0x0010) >> 4;\r
+               irsnd_buffer[2] =  (address & 0x000F) << 4;\r
+           }\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r
-        case IRMP_APPLE_PROTOCOL:\r
-        {\r
-            command = irmp_data_p->command | (irmp_data_p->address << 8);                               // store address as ID in upper byte of command\r
-            address = 0x87EE;                                                                           // set fixed NEC-lookalike address (customer ID of apple)\r
-\r
-            address = bitsrevervse (address, NEC_ADDRESS_LEN);\r
-            command = bitsrevervse (command, NEC_COMMAND_LEN);\r
-\r
-            irsnd_protocol = IRMP_NEC_PROTOCOL;                                                         // APPLE protocol is NEC with id instead of inverted command\r
-\r
-            irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
-            irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
-            irsnd_buffer[3] = 0x8B;                                                                             // 10001011 (id)\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
-        case IRMP_NEC_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, NEC_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, NEC_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
-            irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
-            irsnd_buffer[3] = ~((command & 0xFF00) >> 8);                                                       // cccccccc\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_APPLE_PROTOCOL:\r
+       {\r
+           command = irmp_data_p->command | (irmp_data_p->address << 8);                               // store address as ID in upper byte of command\r
+           address = 0x87EE;                                                                           // set fixed NEC-lookalike address (customer ID of apple)\r
+\r
+           address = bitsrevervse (address, NEC_ADDRESS_LEN);\r
+           command = bitsrevervse (command, NEC_COMMAND_LEN);\r
+\r
+           irsnd_protocol = IRMP_NEC_PROTOCOL;                                                         // APPLE protocol is NEC with id instead of inverted command\r
+\r
+           irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
+           irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
+           irsnd_buffer[3] = 0x8B;                                                                             // 10001011 (id)\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
+       case IRMP_NEC_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, NEC_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, NEC_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
+           irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
+           irsnd_buffer[3] = ~((command & 0xFF00) >> 8);                                                       // cccccccc\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1\r
-        case IRMP_NEC16_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, NEC16_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, NEC16_COMMAND_LEN);\r
+       case IRMP_NEC16_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, NEC16_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, NEC16_COMMAND_LEN);\r
 \r
-            irsnd_buffer[0] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_buffer[1] = (command & 0x00FF);                                                               // CCCCCCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_buffer[1] = (command & 0x00FF);                                                               // CCCCCCCC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1\r
-        case IRMP_NEC42_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, NEC42_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, NEC42_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = ( (address & 0x1FE0) >> 5);                                                       // AAAAAAAA\r
-            irsnd_buffer[1] = ( (address & 0x001F) << 3) | ((~address & 0x1C00) >> 10);                         // AAAAAaaa\r
-            irsnd_buffer[2] =                              ((~address & 0x03FC) >> 2);                          // aaaaaaaa\r
-            irsnd_buffer[3] = ((~address & 0x0003) << 6) | ( (command & 0x00FC) >> 2);                          // aaCCCCCC\r
-            irsnd_buffer[4] = ( (command & 0x0003) << 6) | ((~command & 0x00FC) >> 2);                          // CCcccccc\r
-            irsnd_buffer[5] = ((~command & 0x0003) << 6);                                                       // cc\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_NEC42_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, NEC42_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, NEC42_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = ( (address & 0x1FE0) >> 5);                                                       // AAAAAAAA\r
+           irsnd_buffer[1] = ( (address & 0x001F) << 3) | ((~address & 0x1C00) >> 10);                         // AAAAAaaa\r
+           irsnd_buffer[2] =                              ((~address & 0x03FC) >> 2);                          // aaaaaaaa\r
+           irsnd_buffer[3] = ((~address & 0x0003) << 6) | ( (command & 0x00FC) >> 2);                          // aaCCCCCC\r
+           irsnd_buffer[4] = ( (command & 0x0003) << 6) | ((~command & 0x00FC) >> 2);                          // CCcccccc\r
+           irsnd_buffer[5] = ((~command & 0x0003) << 6);                                                       // cc\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r
-        case IRMP_SAMSUNG_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, SAMSUNG_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] =  (address & 0xFF00) >> 8;                                                         // AAAAAAAA\r
-            irsnd_buffer[1] =  (address & 0x00FF);                                                              // AAAAAAAA\r
-            irsnd_buffer[2] =  (command & 0x00F0) | ((command & 0xF000) >> 12);                                 // IIIICCCC\r
-            irsnd_buffer[3] = ((command & 0x0F00) >> 4) | ((~(command & 0xF000) >> 12) & 0x0F);                 // CCCCcccc\r
-            irsnd_buffer[4] = (~(command & 0x0F00) >> 4) & 0xF0;                                                // cccc0000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
-        case IRMP_SAMSUNG32_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, SAMSUNG32_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
-            irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
-            irsnd_buffer[3] = (command & 0x00FF);                                                               // CCCCCCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_SAMSUNG_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, SAMSUNG_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] =  (address & 0xFF00) >> 8;                                                         // AAAAAAAA\r
+           irsnd_buffer[1] =  (address & 0x00FF);                                                              // AAAAAAAA\r
+           irsnd_buffer[2] =  (command & 0x00F0) | ((command & 0xF000) >> 12);                                 // IIIICCCC\r
+           irsnd_buffer[3] = ((command & 0x0F00) >> 4) | ((~(command & 0xF000) >> 12) & 0x0F);                 // CCCCcccc\r
+           irsnd_buffer[4] = (~(command & 0x0F00) >> 4) & 0xF0;                                                // cccc0000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
+       case IRMP_SAMSUNG32_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, SAMSUNG32_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
+           irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_buffer[2] = (command & 0xFF00) >> 8;                                                          // CCCCCCCC\r
+           irsnd_buffer[3] = (command & 0x00FF);                                                               // CCCCCCCC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
-        case IRMP_MATSUSHITA_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, MATSUSHITA_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, MATSUSHITA_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = (command & 0x0FF0) >> 4;                                                          // CCCCCCCC\r
-            irsnd_buffer[1] = ((command & 0x000F) << 4) | ((address & 0x0F00) >> 8);                            // CCCCAAAA\r
-            irsnd_buffer[2] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_MATSUSHITA_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, MATSUSHITA_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, MATSUSHITA_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = (command & 0x0FF0) >> 4;                                                          // CCCCCCCC\r
+           irsnd_buffer[1] = ((command & 0x000F) << 4) | ((address & 0x0F00) >> 8);                            // CCCCAAAA\r
+           irsnd_buffer[2] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1\r
-        case IRMP_KASEIKYO_PROTOCOL:\r
-        {\r
-            uint8_t xor;\r
-            uint16_t genre2;\r
+       case IRMP_KASEIKYO_PROTOCOL:\r
+       {\r
+           uint8_t xor_value;\r
+           uint16_t genre2;\r
 \r
-            address = bitsrevervse (irmp_data_p->address, KASEIKYO_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, KASEIKYO_COMMAND_LEN + 4);\r
-            genre2 = bitsrevervse ((irmp_data_p->flags & ~IRSND_REPETITION_MASK) >> 4, 4);\r
+           address = bitsrevervse (irmp_data_p->address, KASEIKYO_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, KASEIKYO_COMMAND_LEN + 4);\r
+           genre2 = bitsrevervse ((irmp_data_p->flags & ~IRSND_REPETITION_MASK) >> 4, 4);\r
 \r
-            xor = ((address & 0x000F) ^ ((address & 0x00F0) >> 4) ^ ((address & 0x0F00) >> 8) ^ ((address & 0xF000) >> 12)) & 0x0F;\r
+           xor_value = ((address & 0x000F) ^ ((address & 0x00F0) >> 4) ^ ((address & 0x0F00) >> 8) ^ ((address & 0xF000) >> 12)) & 0x0F;\r
 \r
-            irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
-            irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
-            irsnd_buffer[2] = xor << 4 | (command & 0x000F);                                                    // XXXXCCCC\r
-            irsnd_buffer[3] = (genre2 << 4) | (command & 0xF000) >> 12;                                         // ggggCCCC\r
-            irsnd_buffer[4] = (command & 0x0FF0) >> 4;                                                          // CCCCCCCC\r
+           irsnd_buffer[0] = (address & 0xFF00) >> 8;                                                          // AAAAAAAA\r
+           irsnd_buffer[1] = (address & 0x00FF);                                                               // AAAAAAAA\r
+           irsnd_buffer[2] = xor_value << 4 | (command & 0x000F);                                              // XXXXCCCC\r
+           irsnd_buffer[3] = (genre2 << 4) | (command & 0xF000) >> 12;                                         // ggggCCCC\r
+           irsnd_buffer[4] = (command & 0x0FF0) >> 4;                                                          // CCCCCCCC\r
 \r
-            xor = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4];\r
+           xor_value = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4];\r
 \r
-            irsnd_buffer[5] = xor;\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[5] = xor_value;\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r
-        case IRMP_RECS80_PROTOCOL:\r
-        {\r
-            toggle_bit_recs80 = toggle_bit_recs80 ? 0x00 : 0x40;\r
+       case IRMP_RECS80_PROTOCOL:\r
+       {\r
+           toggle_bit_recs80 = toggle_bit_recs80 ? 0x00 : 0x40;\r
 \r
-            irsnd_buffer[0] = 0x80 | toggle_bit_recs80 | ((irmp_data_p->address & 0x0007) << 3) |\r
-                              ((irmp_data_p->command & 0x0038) >> 3);                                           // STAAACCC\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x07) << 5;                                               // CCC00000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = 0x80 | toggle_bit_recs80 | ((irmp_data_p->address & 0x0007) << 3) |\r
+                             ((irmp_data_p->command & 0x0038) >> 3);                                           // STAAACCC\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x07) << 5;                                               // CCC00000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r
-        case IRMP_RECS80EXT_PROTOCOL:\r
-        {\r
-            toggle_bit_recs80ext = toggle_bit_recs80ext ? 0x00 : 0x40;\r
+       case IRMP_RECS80EXT_PROTOCOL:\r
+       {\r
+           toggle_bit_recs80ext = toggle_bit_recs80ext ? 0x00 : 0x40;\r
 \r
-            irsnd_buffer[0] = 0x80 | toggle_bit_recs80ext | ((irmp_data_p->address & 0x000F) << 2) |\r
-                                ((irmp_data_p->command & 0x0030) >> 4);                                         // STAAAACC\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4;                                               // CCCC0000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = 0x80 | toggle_bit_recs80ext | ((irmp_data_p->address & 0x000F) << 2) |\r
+                               ((irmp_data_p->command & 0x0030) >> 4);                                         // STAAAACC\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4;                                               // CCCC0000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r
-        case IRMP_RC5_PROTOCOL:\r
-        {\r
-            toggle_bit_rc5 = toggle_bit_rc5 ? 0x00 : 0x40;\r
+       case IRMP_RC5_PROTOCOL:\r
+       {\r
+           toggle_bit_rc5 = toggle_bit_rc5 ? 0x00 : 0x40;\r
 \r
-            irsnd_buffer[0] = ((irmp_data_p->command & 0x40) ? 0x00 : 0x80) | toggle_bit_rc5 |\r
-                                ((irmp_data_p->address & 0x001F) << 1) | ((irmp_data_p->command & 0x20) >> 5);  // CTAAAAAC\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x1F) << 3;                                               // CCCCC000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = ((irmp_data_p->command & 0x40) ? 0x00 : 0x80) | toggle_bit_rc5 |\r
+                               ((irmp_data_p->address & 0x001F) << 1) | ((irmp_data_p->command & 0x20) >> 5);  // CTAAAAAC\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x1F) << 3;                                               // CCCCC000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RC6_PROTOCOL == 1\r
-        case IRMP_RC6_PROTOCOL:\r
-        {\r
-            toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;\r
+       case IRMP_RC6_PROTOCOL:\r
+       {\r
+           toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;\r
 \r
-            irsnd_buffer[0] = 0x80 | toggle_bit_rc6 | ((irmp_data_p->address & 0x00E0) >> 5);                   // 1MMMTAAA, MMM = 000\r
-            irsnd_buffer[1] = ((irmp_data_p->address & 0x001F) << 3) | ((irmp_data_p->command & 0xE0) >> 5);    // AAAAACCC\r
-            irsnd_buffer[2] = (irmp_data_p->command & 0x1F) << 3;                                               // CCCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = 0x80 | toggle_bit_rc6 | ((irmp_data_p->address & 0x00E0) >> 5);                   // 1MMMTAAA, MMM = 000\r
+           irsnd_buffer[1] = ((irmp_data_p->address & 0x001F) << 3) | ((irmp_data_p->command & 0xE0) >> 5);    // AAAAACCC\r
+           irsnd_buffer[2] = (irmp_data_p->command & 0x1F) << 3;                                               // CCCCC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1\r
-        case IRMP_RC6A_PROTOCOL:\r
-        {\r
-            toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;\r
-\r
-            irsnd_buffer[0] = 0x80 | 0x60 | ((irmp_data_p->address & 0x3000) >> 12);                                                // 1MMMT0AA, MMM = 110\r
-            irsnd_buffer[1] = ((irmp_data_p->address & 0x0FFF) >> 4) ;                                                              // AAAAAAAA\r
-            irsnd_buffer[2] = ((irmp_data_p->address & 0x000F) << 4) | ((irmp_data_p->command & 0xF000) >> 12) | toggle_bit_rc6;    // AAAACCCC\r
-            irsnd_buffer[3] = (irmp_data_p->command & 0x0FF0) >> 4;                                                                 // CCCCCCCC\r
-            irsnd_buffer[4] = (irmp_data_p->command & 0x000F) << 4;                                                                 // CCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_RC6A_PROTOCOL:\r
+       {\r
+           toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;\r
+\r
+           irsnd_buffer[0] = 0x80 | 0x60 | ((irmp_data_p->address & 0x3000) >> 12);                                                // 1MMMT0AA, MMM = 110\r
+           irsnd_buffer[1] = ((irmp_data_p->address & 0x0FFF) >> 4) ;                                                              // AAAAAAAA\r
+           irsnd_buffer[2] = ((irmp_data_p->address & 0x000F) << 4) | ((irmp_data_p->command & 0xF000) >> 12) | toggle_bit_rc6;    // AAAACCCC\r
+           irsnd_buffer[3] = (irmp_data_p->command & 0x0FF0) >> 4;                                                                 // CCCCCCCC\r
+           irsnd_buffer[4] = (irmp_data_p->command & 0x000F) << 4;                                                                 // CCCC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
-        case IRMP_DENON_PROTOCOL:\r
-        {\r
-            irsnd_buffer[0] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x0380) >> 7);    // AAAAACCC (1st frame)\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x7F) << 1;                                               // CCCCCCC\r
-            irsnd_buffer[2] = ((irmp_data_p->address & 0x1F) << 3) | (((~irmp_data_p->command) & 0x0380) >> 7); // AAAAACCC (2nd frame)\r
-            irsnd_buffer[3] = (~(irmp_data_p->command) & 0x7F) << 1;                                            // CCCCCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_DENON_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x0380) >> 7);    // AAAAACCC (1st frame)\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x7F) << 1;                                               // CCCCCCC\r
+           irsnd_buffer[2] = ((irmp_data_p->address & 0x1F) << 3) | (((~irmp_data_p->command) & 0x0380) >> 7); // AAAAAccc (2nd frame)\r
+           irsnd_buffer[3] = (~(irmp_data_p->command) & 0x7F) << 1;                                            // ccccccc\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1\r
-        case IRMP_THOMSON_PROTOCOL:\r
-        {\r
-            toggle_bit_thomson = toggle_bit_thomson ? 0x00 : 0x08;\r
+       case IRMP_THOMSON_PROTOCOL:\r
+       {\r
+           toggle_bit_thomson = toggle_bit_thomson ? 0x00 : 0x08;\r
 \r
-            irsnd_buffer[0] = ((irmp_data_p->address & 0x0F) << 4) | toggle_bit_thomson | ((irmp_data_p->command & 0x0070) >> 4);   // AAAATCCC (1st frame)\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4;                                                                   // CCCC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_buffer[0] = ((irmp_data_p->address & 0x0F) << 4) | toggle_bit_thomson | ((irmp_data_p->command & 0x0070) >> 4);   // AAAATCCC (1st frame)\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4;                                                                   // CCCC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r
-        case IRMP_NUBERT_PROTOCOL:\r
-        {\r
-            irsnd_buffer[0] = irmp_data_p->command >> 2;                                                        // CCCCCCCC\r
-            irsnd_buffer[1] = (irmp_data_p->command & 0x0003) << 6;                                             // CC000000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_NUBERT_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = irmp_data_p->command >> 2;                                                        // CCCCCCCC\r
+           irsnd_buffer[1] = (irmp_data_p->command & 0x0003) << 6;                                             // CC000000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
-        case IRMP_BANG_OLUFSEN_PROTOCOL:\r
-        {\r
-            irsnd_buffer[0] = irmp_data_p->command >> 11;                                                       // SXSCCCCC\r
-            irsnd_buffer[1] = irmp_data_p->command >> 3;                                                        // CCCCCCCC\r
-            irsnd_buffer[2] = (irmp_data_p->command & 0x0007) << 5;                                             // CCC00000\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_BANG_OLUFSEN_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = irmp_data_p->command >> 11;                                                       // SXSCCCCC\r
+           irsnd_buffer[1] = irmp_data_p->command >> 3;                                                        // CCCCCCCC\r
+           irsnd_buffer[2] = (irmp_data_p->command & 0x0007) << 5;                                             // CCC00000\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r
-        case IRMP_GRUNDIG_PROTOCOL:\r
-        {\r
-            command = bitsrevervse (irmp_data_p->command, GRUNDIG_COMMAND_LEN);\r
+       case IRMP_GRUNDIG_PROTOCOL:\r
+       {\r
+           command = bitsrevervse (irmp_data_p->command, GRUNDIG_COMMAND_LEN);\r
 \r
-            irsnd_buffer[0] = 0xFF;                                                                             // S1111111 (1st frame)\r
-            irsnd_buffer[1] = 0xC0;                                                                             // 11\r
-            irsnd_buffer[2] = 0x80 | (command >> 2);                                                            // SCCCCCCC (2nd frame)\r
-            irsnd_buffer[3] = (command << 6) & 0xC0;                                                            // CC\r
+           irsnd_buffer[0] = 0xFF;                                                                             // S1111111 (1st frame)\r
+           irsnd_buffer[1] = 0xC0;                                                                             // 11\r
+           irsnd_buffer[2] = 0x80 | (command >> 2);                                                            // SCCCCCCC (2nd frame)\r
+           irsnd_buffer[3] = (command << 6) & 0xC0;                                                            // CC\r
 \r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_IR60_PROTOCOL == 1\r
-        case IRMP_IR60_PROTOCOL:\r
-        {\r
-            command = (bitsrevervse (0x7d, IR60_COMMAND_LEN) << 7) | bitsrevervse (irmp_data_p->command, IR60_COMMAND_LEN);\r
-            irsnd_buffer[0] = command >> 6 | 0x01;                                                              // 1011111S (start instruction frame)\r
-            irsnd_buffer[1] = (command & 0x7F) << 1;                                                            // CCCCCCC_ (2nd frame)\r
+       case IRMP_IR60_PROTOCOL:\r
+       {\r
+           command = (bitsrevervse (0x7d, IR60_COMMAND_LEN) << 7) | bitsrevervse (irmp_data_p->command, IR60_COMMAND_LEN);\r
+#if 0\r
+           irsnd_buffer[0] = command >> 6 | 0x01;                                                              // 1011111S (start instruction frame)\r
+           irsnd_buffer[1] = (command & 0x7F) << 1;                                                            // CCCCCCC_ (2nd frame)\r
+#else\r
+           irsnd_buffer[0] = ((command & 0x7F) << 1) | 0x01;                                                   // CCCCCCCS (1st frame)\r
+           irsnd_buffer[1] = command >> 6;                                                                     // 1011111_ (start instruction frame)\r
+#endif\r
 \r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-        case IRMP_NOKIA_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, NOKIA_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, NOKIA_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = 0xBF;                                                                             // S0111111 (1st + 3rd frame)\r
-            irsnd_buffer[1] = 0xFF;                                                                             // 11111111\r
-            irsnd_buffer[2] = 0x80;                                                                             // 1\r
-            irsnd_buffer[3] = 0x80 | command >> 1;                                                              // SCCCCCCC (2nd frame)\r
-            irsnd_buffer[4] = (command << 7) | (address >> 1);                                                  // CAAAAAAA\r
-            irsnd_buffer[5] = (address << 7);                                                                   // A\r
-\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_NOKIA_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, NOKIA_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, NOKIA_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = 0xBF;                                                                             // S0111111 (1st + 3rd frame)\r
+           irsnd_buffer[1] = 0xFF;                                                                             // 11111111\r
+           irsnd_buffer[2] = 0x80;                                                                             // 1\r
+           irsnd_buffer[3] = 0x80 | command >> 1;                                                              // SCCCCCCC (2nd frame)\r
+           irsnd_buffer[4] = (command << 7) | (address >> 1);                                                  // CAAAAAAA\r
+           irsnd_buffer[5] = (address << 7);                                                                   // A\r
+\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r
-        case IRMP_SIEMENS_PROTOCOL:\r
-        {\r
-            irsnd_buffer[0] = ((irmp_data_p->address & 0x0FFF) >> 5);                                           // SAAAAAAA\r
-            irsnd_buffer[1] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x7F) >> 5);      // AAAAA0CC\r
-            irsnd_buffer[2] = (irmp_data_p->command << 3) | ((~irmp_data_p->command & 0x01) << 2);              // CCCCCc\r
+       case IRMP_SIEMENS_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = ((irmp_data_p->address & 0x0FFF) >> 5);                                           // SAAAAAAA\r
+           irsnd_buffer[1] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x7F) >> 5);      // AAAAA0CC\r
+           irsnd_buffer[2] = (irmp_data_p->command << 3) | ((~irmp_data_p->command & 0x01) << 2);              // CCCCCc\r
 \r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
-        case IRMP_FDC_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);\r
-\r
-            irsnd_buffer[0] = (address & 0xFF);                                                                 // AAAAAAAA\r
-            irsnd_buffer[1] = 0;                                                                                // 00000000\r
-            irsnd_buffer[2] = 0;                                                                                // 0000RRRR\r
-            irsnd_buffer[3] = (command & 0xFF);                                                                 // CCCCCCCC\r
-            irsnd_buffer[4] = ~(command & 0xFF);                                                                // cccccccc\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_FDC_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);\r
+\r
+           irsnd_buffer[0] = (address & 0xFF);                                                                 // AAAAAAAA\r
+           irsnd_buffer[1] = 0;                                                                                // 00000000\r
+           irsnd_buffer[2] = 0;                                                                                // 0000RRRR\r
+           irsnd_buffer[3] = (command & 0xFF);                                                                 // CCCCCCCC\r
+           irsnd_buffer[4] = ~(command & 0xFF);                                                                // cccccccc\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
-        case IRMP_RCCAR_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, 2);                                                   //                            A0 A1\r
-            command = bitsrevervse (irmp_data_p->command, RCCAR_COMMAND_LEN - 2);                               // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V\r
-\r
-            irsnd_buffer[0] = ((command & 0x06) << 5) | ((address & 0x0003) << 4) | ((command & 0x0780) >> 7);  //          C0 C1 A0 A1 D0 D1 D2 D3\r
-            irsnd_buffer[1] = ((command & 0x78) << 1) | ((command & 0x0001) << 3);                              //          D4 D5 D6 D7 V  0  0  0\r
-                                                                                                                \r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_RCCAR_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, 2);                                                   //                            A0 A1\r
+           command = bitsrevervse (irmp_data_p->command, RCCAR_COMMAND_LEN - 2);                               // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V\r
+\r
+           irsnd_buffer[0] = ((command & 0x06) << 5) | ((address & 0x0003) << 4) | ((command & 0x0780) >> 7);  //          C0 C1 A0 A1 D0 D1 D2 D3\r
+           irsnd_buffer[1] = ((command & 0x78) << 1) | ((command & 0x0001) << 3);                              //          D4 D5 D6 D7 V  0  0  0\r
+                                                                                                               \r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_JVC_PROTOCOL == 1\r
-        case IRMP_JVC_PROTOCOL:\r
-        {\r
-            address = bitsrevervse (irmp_data_p->address, JVC_ADDRESS_LEN);\r
-            command = bitsrevervse (irmp_data_p->command, JVC_COMMAND_LEN);\r
+       case IRMP_JVC_PROTOCOL:\r
+       {\r
+           address = bitsrevervse (irmp_data_p->address, JVC_ADDRESS_LEN);\r
+           command = bitsrevervse (irmp_data_p->command, JVC_COMMAND_LEN);\r
 \r
-            irsnd_buffer[0] = ((address & 0x000F) << 4) | (command & 0x0F00) >> 8;                              // AAAACCCC\r
-            irsnd_buffer[1] = (command & 0x00FF);                                                               // CCCCCCCC\r
+           irsnd_buffer[0] = ((address & 0x000F) << 4) | (command & 0x0F00) >> 8;                              // AAAACCCC\r
+           irsnd_buffer[1] = (command & 0x00FF);                                                               // CCCCCCCC\r
 \r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
-        case IRMP_NIKON_PROTOCOL:\r
-        {\r
-            irsnd_buffer[0] = (irmp_data_p->command & 0x0003) << 6;                                             // CC\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
+       case IRMP_NIKON_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = (irmp_data_p->command & 0x0003) << 6;                                             // CC\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
 #endif\r
 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
-        case IRMP_LEGO_PROTOCOL:\r
-        {\r
-            uint8_t crc = 0x0F ^ ((irmp_data_p->command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F);\r
-\r
-            irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4;                                             // CCCCCCCC\r
-            irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc;                                     // CCCCcccc\r
-\r
-            irsnd_protocol = IRMP_LEGO_PROTOCOL;\r
-            irsnd_busy      = TRUE;\r
-            break;\r
-        }\r
-#endif\r
-        default:\r
-        {\r
-            break;\r
-        }\r
+       case IRMP_LEGO_PROTOCOL:\r
+       {\r
+           uint8_t crc = 0x0F ^ ((irmp_data_p->command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F);\r
+\r
+           irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4;                                             // CCCCCCCC\r
+           irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc;                                     // CCCCcccc\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
+#endif\r
+#if IRSND_SUPPORT_A1TVBOX_PROTOCOL == 1\r
+       case IRMP_A1TVBOX_PROTOCOL:\r
+       {\r
+           irsnd_buffer[0] = 0x80 | (irmp_data_p->address >> 2);                                               // 10AAAAAA\r
+           irsnd_buffer[1] = (irmp_data_p->address << 6) | (irmp_data_p->command >> 2);                        // AACCCCCC\r
+           irsnd_buffer[2] = (irmp_data_p->command << 6);                                                      // CC\r
+\r
+           irsnd_busy      = TRUE;\r
+           break;\r
+       }\r
+#endif\r
+       default:\r
+       {\r
+           break;\r
+       }\r
     }\r
 \r
     return irsnd_busy;\r
@@ -1063,1050 +1154,1120 @@ irsnd_ISR (void)
     static uint8_t              last_bit_value;\r
 #endif\r
     static uint8_t              pulse_len = 0xFF;\r
-    static IRSND_PAUSE_LEN              pause_len = 0xFF;\r
+    static IRSND_PAUSE_LEN      pause_len = 0xFF;\r
 \r
     if (irsnd_busy)\r
     {\r
-        if (current_bit == 0xFF && new_frame)                                       // start of transmission...\r
-        {\r
-            if (auto_repetition_counter > 0)\r
-            {\r
-                auto_repetition_pause_counter++;\r
-\r
-                if (auto_repetition_pause_counter >= auto_repetition_pause_len)\r
-                {\r
-                    auto_repetition_pause_counter = 0;\r
-\r
-                    if (irsnd_protocol == IRMP_DENON_PROTOCOL)                              // n'th denon frame\r
-                    {\r
-                        current_bit = 16;\r
-                        complete_data_len   = 2 * DENON_COMPLETE_DATA_LEN + 1;\r
-                    }\r
-                    else if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL)                       // n'th grundig frame\r
-                    {\r
-                        current_bit = 15;\r
-                        complete_data_len   = 16 + GRUNDIG_COMPLETE_DATA_LEN;\r
-                    }\r
-                    else if (irsnd_protocol == IRMP_IR60_PROTOCOL)                          // n'th IR60 frame\r
-                    {\r
-                        current_bit = 7;\r
-                        complete_data_len   = 2 * IR60_COMPLETE_DATA_LEN + 1;\r
-                    }\r
-                    else if (irsnd_protocol == IRMP_NOKIA_PROTOCOL)                         // n'th nokia frame\r
-                    {\r
-                        if (auto_repetition_counter + 1 < n_auto_repetitions)\r
-                        {\r
-                            current_bit = 23;\r
-                            complete_data_len   = 24 + NOKIA_COMPLETE_DATA_LEN;\r
-                        }\r
-                        else                                                                // nokia stop frame\r
-                        {\r
-                            current_bit = 0xFF;\r
-                            complete_data_len   = NOKIA_COMPLETE_DATA_LEN;\r
-                        }\r
-                    }\r
-                }\r
-                else\r
-                {\r
+       if (current_bit == 0xFF && new_frame)                                       // start of transmission...\r
+       {\r
+           if (auto_repetition_counter > 0)\r
+           {\r
+               auto_repetition_pause_counter++;\r
+\r
+#if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
+               if (repeat_frame_pause_len > 0)                                     // frame repeat distance counts from beginning of 1st frame!\r
+               {\r
+                   repeat_frame_pause_len--;\r
+               }\r
+#endif\r
+\r
+               if (auto_repetition_pause_counter >= auto_repetition_pause_len)\r
+               {\r
+                   auto_repetition_pause_counter = 0;\r
+\r
+#if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
+                   if (irsnd_protocol == IRMP_DENON_PROTOCOL)                              // n'th denon frame\r
+                   {\r
+                       current_bit = 16;\r
+                       complete_data_len   = 2 * DENON_COMPLETE_DATA_LEN + 1;\r
+                   }\r
+                   else\r
+#endif\r
+#if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r
+                   if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL)                            // n'th grundig frame\r
+                   {\r
+                       current_bit = 15;\r
+                       complete_data_len   = 16 + GRUNDIG_COMPLETE_DATA_LEN;\r
+                   }\r
+                   else\r
+#endif\r
+#if IRSND_SUPPORT_IR60_PROTOCOL == 1\r
+                   if (irsnd_protocol == IRMP_IR60_PROTOCOL)                               // n'th IR60 frame\r
+                   {\r
+                       current_bit = 7;\r
+                       complete_data_len   = 2 * IR60_COMPLETE_DATA_LEN + 1;\r
+                   }\r
+                   else\r
+#endif\r
+#if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
+                   if (irsnd_protocol == IRMP_NOKIA_PROTOCOL)                              // n'th nokia frame\r
+                   {\r
+                       if (auto_repetition_counter + 1 < n_auto_repetitions)\r
+                       {\r
+                           current_bit = 23;\r
+                           complete_data_len   = 24 + NOKIA_COMPLETE_DATA_LEN;\r
+                       }\r
+                       else                                                                // nokia stop frame\r
+                       {\r
+                           current_bit = 0xFF;\r
+                           complete_data_len   = NOKIA_COMPLETE_DATA_LEN;\r
+                       }\r
+                   }\r
+                   else\r
+#endif\r
+                   {\r
+                       ;\r
+                   }\r
+               }\r
+               else\r
+               {\r
 #ifdef DEBUG\r
-                    if (irsnd_is_on)\r
-                    {\r
-                        putchar ('0');\r
-                    }\r
-                    else\r
-                    {\r
-                        putchar ('1');\r
-                    }\r
-#endif\r
-                    return irsnd_busy;\r
-                }\r
-            }\r
+                   if (irsnd_is_on)\r
+                   {\r
+                       putchar ('0');\r
+                   }\r
+                   else\r
+                   {\r
+                       putchar ('1');\r
+                   }\r
+#endif\r
+                   return irsnd_busy;\r
+               }\r
+           }\r
 #if 0\r
-            else if (repeat_counter > 0 && packet_repeat_pause_counter < repeat_frame_pause_len)\r
+           else if (repeat_counter > 0 && packet_repeat_pause_counter < repeat_frame_pause_len)\r
 #else\r
-            else if (packet_repeat_pause_counter < repeat_frame_pause_len)\r
+           else if (packet_repeat_pause_counter < repeat_frame_pause_len)\r
 #endif\r
-            {\r
-                packet_repeat_pause_counter++;\r
+           {\r
+               packet_repeat_pause_counter++;\r
 \r
 #ifdef DEBUG\r
-                if (irsnd_is_on)\r
-                {\r
-                    putchar ('0');\r
-                }\r
-                else\r
-                {\r
-                    putchar ('1');\r
-                }\r
-#endif\r
-                return irsnd_busy;\r
-            }\r
-            else\r
-            {\r
-                \r
-                if (send_trailer)\r
-                {\r
-                    irsnd_busy = FALSE;\r
-                    send_trailer = FALSE;\r
-                    return irsnd_busy;\r
-                }\r
-                \r
-                n_repeat_frames             = irsnd_repeat;\r
-\r
-                if (n_repeat_frames == IRSND_ENDLESS_REPETITION)\r
-                {\r
-                    n_repeat_frames = 255;\r
-                }\r
-\r
-                packet_repeat_pause_counter = 0;\r
-                pulse_counter               = 0;\r
-                pause_counter               = 0;\r
-\r
-                switch (irsnd_protocol)\r
-                {\r
+               if (irsnd_is_on)\r
+               {\r
+                   putchar ('0');\r
+               }\r
+               else\r
+               {\r
+                   putchar ('1');\r
+               }\r
+#endif\r
+               return irsnd_busy;\r
+           }\r
+           else\r
+           {\r
+               if (send_trailer)\r
+               {\r
+                   irsnd_busy = FALSE;\r
+                   send_trailer = FALSE;\r
+                   return irsnd_busy;\r
+               }\r
+               \r
+               n_repeat_frames             = irsnd_repeat;\r
+\r
+               if (n_repeat_frames == IRSND_ENDLESS_REPETITION)\r
+               {\r
+                   n_repeat_frames = 255;\r
+               }\r
+\r
+               packet_repeat_pause_counter = 0;\r
+               pulse_counter               = 0;\r
+               pause_counter               = 0;\r
+\r
+               switch (irsnd_protocol)\r
+               {\r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r
-                    case IRMP_SIRCS_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = SIRCS_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = SIRCS_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = SIRCS_1_PULSE_LEN;\r
-                        pause_1_len                 = SIRCS_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = SIRCS_0_PULSE_LEN;\r
-                        pause_0_len                 = SIRCS_PAUSE_LEN - 1;\r
-                        has_stop_bit                = SIRCS_STOP_BIT;\r
-                        complete_data_len           = SIRCS_MINIMUM_DATA_LEN + sircs_additional_bitlen;\r
-                        n_auto_repetitions          = (repeat_counter == 0) ? SIRCS_FRAMES : 1;     // 3 frames auto repetition if first frame\r
-                        auto_repetition_pause_len   = SIRCS_AUTO_REPETITION_PAUSE_LEN;              // 25ms pause\r
-                        repeat_frame_pause_len      = SIRCS_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_40_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_SIRCS_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = SIRCS_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = SIRCS_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = SIRCS_1_PULSE_LEN;\r
+                       pause_1_len                 = SIRCS_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = SIRCS_0_PULSE_LEN;\r
+                       pause_0_len                 = SIRCS_PAUSE_LEN - 1;\r
+                       has_stop_bit                = SIRCS_STOP_BIT;\r
+                       complete_data_len           = SIRCS_MINIMUM_DATA_LEN + sircs_additional_bitlen;\r
+                       n_auto_repetitions          = (repeat_counter == 0) ? SIRCS_FRAMES : 1;     // 3 frames auto repetition if first frame\r
+                       auto_repetition_pause_len   = SIRCS_AUTO_REPETITION_PAUSE_LEN;              // 25ms pause\r
+                       repeat_frame_pause_len      = SIRCS_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_40_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r
-                    case IRMP_NEC_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
-\r
-                        if (repeat_counter > 0)\r
-                        {\r
-                            startbit_pause_len      = NEC_REPEAT_START_BIT_PAUSE_LEN - 1;\r
-                            complete_data_len       = 0;\r
-                        }\r
-                        else\r
-                        {\r
-                            startbit_pause_len      = NEC_START_BIT_PAUSE_LEN - 1;\r
-                            complete_data_len       = NEC_COMPLETE_DATA_LEN;\r
-                        }\r
-\r
-                        pulse_1_len                 = NEC_PULSE_LEN;\r
-                        pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = NEC_PULSE_LEN;\r
-                        pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = NEC_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NEC_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
+\r
+                       if (repeat_counter > 0)\r
+                       {\r
+                           startbit_pause_len      = NEC_REPEAT_START_BIT_PAUSE_LEN - 1;\r
+                           complete_data_len       = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                           startbit_pause_len      = NEC_START_BIT_PAUSE_LEN - 1;\r
+                           complete_data_len       = NEC_COMPLETE_DATA_LEN;\r
+                       }\r
+\r
+                       pulse_1_len                 = NEC_PULSE_LEN;\r
+                       pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = NEC_PULSE_LEN;\r
+                       pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = NEC_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1\r
-                    case IRMP_NEC16_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = NEC_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = NEC_PULSE_LEN;\r
-                        pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = NEC_PULSE_LEN;\r
-                        pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = NEC_STOP_BIT;\r
-                        complete_data_len           = NEC16_COMPLETE_DATA_LEN + 1;                  // 1 more: sync bit\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NEC16_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = NEC_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = NEC_PULSE_LEN;\r
+                       pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = NEC_PULSE_LEN;\r
+                       pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = NEC_STOP_BIT;\r
+                       complete_data_len           = NEC16_COMPLETE_DATA_LEN + 1;                  // 1 more: sync bit\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1\r
-                    case IRMP_NEC42_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = NEC_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = NEC_PULSE_LEN;\r
-                        pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = NEC_PULSE_LEN;\r
-                        pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = NEC_STOP_BIT;\r
-                        complete_data_len           = NEC42_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NEC42_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = NEC_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = NEC_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = NEC_PULSE_LEN;\r
+                       pause_1_len                 = NEC_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = NEC_PULSE_LEN;\r
+                       pause_0_len                 = NEC_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = NEC_STOP_BIT;\r
+                       complete_data_len           = NEC42_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = NEC_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r
-                    case IRMP_SAMSUNG_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = SAMSUNG_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = SAMSUNG_PULSE_LEN;\r
-                        pause_1_len                 = SAMSUNG_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = SAMSUNG_PULSE_LEN;\r
-                        pause_0_len                 = SAMSUNG_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = SAMSUNG_STOP_BIT;\r
-                        complete_data_len           = SAMSUNG_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = SAMSUNG_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
-\r
-                    case IRMP_SAMSUNG32_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = SAMSUNG_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = SAMSUNG_PULSE_LEN;\r
-                        pause_1_len                 = SAMSUNG_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = SAMSUNG_PULSE_LEN;\r
-                        pause_0_len                 = SAMSUNG_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = SAMSUNG_STOP_BIT;\r
-                        complete_data_len           = SAMSUNG32_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = SAMSUNG32_FRAMES;                             // 2 frames\r
-                        auto_repetition_pause_len   = SAMSUNG32_AUTO_REPETITION_PAUSE_LEN;          // 47 ms pause\r
-                        repeat_frame_pause_len      = SAMSUNG32_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_SAMSUNG_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = SAMSUNG_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = SAMSUNG_PULSE_LEN;\r
+                       pause_1_len                 = SAMSUNG_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = SAMSUNG_PULSE_LEN;\r
+                       pause_0_len                 = SAMSUNG_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = SAMSUNG_STOP_BIT;\r
+                       complete_data_len           = SAMSUNG_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = SAMSUNG_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
+\r
+                   case IRMP_SAMSUNG32_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = SAMSUNG_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = SAMSUNG_PULSE_LEN;\r
+                       pause_1_len                 = SAMSUNG_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = SAMSUNG_PULSE_LEN;\r
+                       pause_0_len                 = SAMSUNG_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = SAMSUNG_STOP_BIT;\r
+                       complete_data_len           = SAMSUNG32_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = SAMSUNG32_FRAMES;                             // 2 frames\r
+                       auto_repetition_pause_len   = SAMSUNG32_AUTO_REPETITION_PAUSE_LEN;          // 47 ms pause\r
+                       repeat_frame_pause_len      = SAMSUNG32_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
-                    case IRMP_MATSUSHITA_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = MATSUSHITA_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = MATSUSHITA_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = MATSUSHITA_PULSE_LEN;\r
-                        pause_1_len                 = MATSUSHITA_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = MATSUSHITA_PULSE_LEN;\r
-                        pause_0_len                 = MATSUSHITA_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = MATSUSHITA_STOP_BIT;\r
-                        complete_data_len           = MATSUSHITA_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = MATSUSHITA_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_MATSUSHITA_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = MATSUSHITA_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = MATSUSHITA_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = MATSUSHITA_PULSE_LEN;\r
+                       pause_1_len                 = MATSUSHITA_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = MATSUSHITA_PULSE_LEN;\r
+                       pause_0_len                 = MATSUSHITA_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = MATSUSHITA_STOP_BIT;\r
+                       complete_data_len           = MATSUSHITA_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = MATSUSHITA_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1\r
-                    case IRMP_KASEIKYO_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = KASEIKYO_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = KASEIKYO_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = KASEIKYO_PULSE_LEN;\r
-                        pause_1_len                 = KASEIKYO_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = KASEIKYO_PULSE_LEN;\r
-                        pause_0_len                 = KASEIKYO_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = KASEIKYO_STOP_BIT;\r
-                        complete_data_len           = KASEIKYO_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = (repeat_counter == 0) ? KASEIKYO_FRAMES : 1;  // 2 frames auto repetition if first frame\r
-                        auto_repetition_pause_len   = KASEIKYO_AUTO_REPETITION_PAUSE_LEN;           // 75 ms pause\r
-                        repeat_frame_pause_len      = KASEIKYO_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_KASEIKYO_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = KASEIKYO_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = KASEIKYO_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = KASEIKYO_PULSE_LEN;\r
+                       pause_1_len                 = KASEIKYO_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = KASEIKYO_PULSE_LEN;\r
+                       pause_0_len                 = KASEIKYO_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = KASEIKYO_STOP_BIT;\r
+                       complete_data_len           = KASEIKYO_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = (repeat_counter == 0) ? KASEIKYO_FRAMES : 1;  // 2 frames auto repetition if first frame\r
+                       auto_repetition_pause_len   = KASEIKYO_AUTO_REPETITION_PAUSE_LEN;           // 75 ms pause\r
+                       repeat_frame_pause_len      = KASEIKYO_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r
-                    case IRMP_RECS80_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RECS80_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = RECS80_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = RECS80_PULSE_LEN;\r
-                        pause_1_len                 = RECS80_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = RECS80_PULSE_LEN;\r
-                        pause_0_len                 = RECS80_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = RECS80_STOP_BIT;\r
-                        complete_data_len           = RECS80_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RECS80_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RECS80_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RECS80_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = RECS80_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = RECS80_PULSE_LEN;\r
+                       pause_1_len                 = RECS80_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = RECS80_PULSE_LEN;\r
+                       pause_0_len                 = RECS80_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = RECS80_STOP_BIT;\r
+                       complete_data_len           = RECS80_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RECS80_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r
-                    case IRMP_RECS80EXT_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RECS80EXT_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = RECS80EXT_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = RECS80EXT_PULSE_LEN;\r
-                        pause_1_len                 = RECS80EXT_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = RECS80EXT_PULSE_LEN;\r
-                        pause_0_len                 = RECS80EXT_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = RECS80EXT_STOP_BIT;\r
-                        complete_data_len           = RECS80EXT_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RECS80EXT_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RECS80EXT_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RECS80EXT_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = RECS80EXT_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = RECS80EXT_PULSE_LEN;\r
+                       pause_1_len                 = RECS80EXT_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = RECS80EXT_PULSE_LEN;\r
+                       pause_0_len                 = RECS80EXT_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = RECS80EXT_STOP_BIT;\r
+                       complete_data_len           = RECS80EXT_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RECS80EXT_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r
-                    case IRMP_RC5_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RC5_BIT_LEN;\r
-                        startbit_pause_len          = RC5_BIT_LEN;\r
-                        pulse_len                   = RC5_BIT_LEN;\r
-                        pause_len                   = RC5_BIT_LEN;\r
-                        has_stop_bit                = RC5_STOP_BIT;\r
-                        complete_data_len           = RC5_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RC5_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RC5_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RC5_BIT_LEN;\r
+                       startbit_pause_len          = RC5_BIT_LEN;\r
+                       pulse_len                   = RC5_BIT_LEN;\r
+                       pause_len                   = RC5_BIT_LEN;\r
+                       has_stop_bit                = RC5_STOP_BIT;\r
+                       complete_data_len           = RC5_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RC5_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RC6_PROTOCOL == 1\r
-                    case IRMP_RC6_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RC6_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = RC6_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_len                   = RC6_BIT_LEN;\r
-                        pause_len                   = RC6_BIT_LEN;\r
-                        has_stop_bit                = RC6_STOP_BIT;\r
-                        complete_data_len           = RC6_COMPLETE_DATA_LEN_SHORT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RC6_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RC6_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RC6_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = RC6_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_len                   = RC6_BIT_LEN;\r
+                       pause_len                   = RC6_BIT_LEN;\r
+                       has_stop_bit                = RC6_STOP_BIT;\r
+                       complete_data_len           = RC6_COMPLETE_DATA_LEN_SHORT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RC6_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1\r
-                    case IRMP_RC6A_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RC6_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = RC6_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_len                   = RC6_BIT_LEN;\r
-                        pause_len                   = RC6_BIT_LEN;\r
-                        has_stop_bit                = RC6_STOP_BIT;\r
-                        complete_data_len           = RC6_COMPLETE_DATA_LEN_LONG;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RC6_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RC6A_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RC6_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = RC6_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_len                   = RC6_BIT_LEN;\r
+                       pause_len                   = RC6_BIT_LEN;\r
+                       has_stop_bit                = RC6_STOP_BIT;\r
+                       complete_data_len           = RC6_COMPLETE_DATA_LEN_LONG;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RC6_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
-                    case IRMP_DENON_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = 0x00;\r
-                        startbit_pause_len          = 0x00;\r
-                        pulse_1_len                 = DENON_PULSE_LEN;\r
-                        pause_1_len                 = DENON_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = DENON_PULSE_LEN;\r
-                        pause_0_len                 = DENON_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = DENON_STOP_BIT;\r
-                        complete_data_len           = DENON_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = DENON_FRAMES;                                 // 2 frames, 2nd with inverted command\r
-                        auto_repetition_pause_len   = DENON_AUTO_REPETITION_PAUSE_LEN;              // 65 ms pause after 1st frame\r
-                        repeat_frame_pause_len      = DENON_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);                                         // in theory 32kHz, in practice 36kHz is better\r
-                        break;\r
-                    }\r
+                   case IRMP_DENON_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = 0x00;\r
+                       startbit_pause_len          = 0x00;\r
+                       pulse_1_len                 = DENON_PULSE_LEN;\r
+                       pause_1_len                 = DENON_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = DENON_PULSE_LEN;\r
+                       pause_0_len                 = DENON_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = DENON_STOP_BIT;\r
+                       complete_data_len           = DENON_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = DENON_FRAMES;                                 // 2 frames, 2nd with inverted command\r
+                       auto_repetition_pause_len   = DENON_AUTO_REPETITION_PAUSE_LEN;              // 65 ms pause after 1st frame\r
+                       repeat_frame_pause_len      = DENON_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);                                         // in theory 32kHz, in practice 36kHz is better\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1\r
-                    case IRMP_THOMSON_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = 0x00;\r
-                        startbit_pause_len          = 0x00;\r
-                        pulse_1_len                 = THOMSON_PULSE_LEN;\r
-                        pause_1_len                 = THOMSON_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = THOMSON_PULSE_LEN;\r
-                        pause_0_len                 = THOMSON_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = THOMSON_STOP_BIT;\r
-                        complete_data_len           = THOMSON_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = THOMSON_FRAMES;                               // only 1 frame\r
-                        auto_repetition_pause_len   = THOMSON_AUTO_REPETITION_PAUSE_LEN;\r
-                        repeat_frame_pause_len      = DENON_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_THOMSON_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = 0x00;\r
+                       startbit_pause_len          = 0x00;\r
+                       pulse_1_len                 = THOMSON_PULSE_LEN;\r
+                       pause_1_len                 = THOMSON_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = THOMSON_PULSE_LEN;\r
+                       pause_0_len                 = THOMSON_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = THOMSON_STOP_BIT;\r
+                       complete_data_len           = THOMSON_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = THOMSON_FRAMES;                               // only 1 frame\r
+                       auto_repetition_pause_len   = THOMSON_AUTO_REPETITION_PAUSE_LEN;\r
+                       repeat_frame_pause_len      = DENON_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r
-                    case IRMP_NUBERT_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = NUBERT_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = NUBERT_START_BIT_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = NUBERT_1_PULSE_LEN;\r
-                        pause_1_len                 = NUBERT_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = NUBERT_0_PULSE_LEN;\r
-                        pause_0_len                 = NUBERT_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = NUBERT_STOP_BIT;\r
-                        complete_data_len           = NUBERT_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = NUBERT_FRAMES;                                // 2 frames\r
-                        auto_repetition_pause_len   = NUBERT_AUTO_REPETITION_PAUSE_LEN;             // 35 ms pause\r
-                        repeat_frame_pause_len      = NUBERT_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NUBERT_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = NUBERT_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = NUBERT_START_BIT_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = NUBERT_1_PULSE_LEN;\r
+                       pause_1_len                 = NUBERT_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = NUBERT_0_PULSE_LEN;\r
+                       pause_0_len                 = NUBERT_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = NUBERT_STOP_BIT;\r
+                       complete_data_len           = NUBERT_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = NUBERT_FRAMES;                                // 2 frames\r
+                       auto_repetition_pause_len   = NUBERT_AUTO_REPETITION_PAUSE_LEN;             // 35 ms pause\r
+                       repeat_frame_pause_len      = NUBERT_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
-                    case IRMP_BANG_OLUFSEN_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = BANG_OLUFSEN_START_BIT1_PULSE_LEN;\r
-                        startbit_pause_len          = BANG_OLUFSEN_START_BIT1_PAUSE_LEN - 1;\r
-                        pulse_1_len                 = BANG_OLUFSEN_PULSE_LEN;\r
-                        pause_1_len                 = BANG_OLUFSEN_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = BANG_OLUFSEN_PULSE_LEN;\r
-                        pause_0_len                 = BANG_OLUFSEN_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = BANG_OLUFSEN_STOP_BIT;\r
-                        complete_data_len           = BANG_OLUFSEN_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN;\r
-                        last_bit_value              = 0;\r
-                        irsnd_set_freq (IRSND_FREQ_455_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_BANG_OLUFSEN_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = BANG_OLUFSEN_START_BIT1_PULSE_LEN;\r
+                       startbit_pause_len          = BANG_OLUFSEN_START_BIT1_PAUSE_LEN - 1;\r
+                       pulse_1_len                 = BANG_OLUFSEN_PULSE_LEN;\r
+                       pause_1_len                 = BANG_OLUFSEN_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = BANG_OLUFSEN_PULSE_LEN;\r
+                       pause_0_len                 = BANG_OLUFSEN_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = BANG_OLUFSEN_STOP_BIT;\r
+                       complete_data_len           = BANG_OLUFSEN_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN;\r
+                       last_bit_value              = 0;\r
+                       irsnd_set_freq (IRSND_FREQ_455_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r
-                    case IRMP_GRUNDIG_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
-                        pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
-                        complete_data_len           = GRUNDIG_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = GRUNDIG_FRAMES;                               // 2 frames\r
-                        auto_repetition_pause_len   = GRUNDIG_AUTO_REPETITION_PAUSE_LEN;            // 20m sec pause\r
-                        repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;    // 117 msec pause\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_GRUNDIG_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
+                       pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
+                       complete_data_len           = GRUNDIG_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = GRUNDIG_FRAMES;                               // 2 frames\r
+                       auto_repetition_pause_len   = GRUNDIG_AUTO_REPETITION_PAUSE_LEN;            // 20m sec pause\r
+                       repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;    // 117 msec pause\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_IR60_PROTOCOL == 1\r
-                    case IRMP_IR60_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
-                        pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
-                        complete_data_len           = IR60_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = IR60_FRAMES;                                  // 2 frames\r
-                        auto_repetition_pause_len   = IR60_AUTO_REPETITION_PAUSE_LEN;               // 20m sec pause\r
-                        repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;    // 117 msec pause\r
-                        irsnd_set_freq (IRSND_FREQ_30_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_IR60_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
+                       pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
+                       complete_data_len           = IR60_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = IR60_FRAMES;                                  // 2 frames\r
+                       auto_repetition_pause_len   = IR60_AUTO_REPETITION_PAUSE_LEN;               // 20m sec pause\r
+                       repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;    // 117 msec pause\r
+                       irsnd_set_freq (IRSND_FREQ_30_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-                    case IRMP_NOKIA_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
-                        pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                        has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
-                        complete_data_len           = NOKIA_COMPLETE_DATA_LEN;\r
-                        n_auto_repetitions          = NOKIA_FRAMES;                                             // 2 frames\r
-                        auto_repetition_pause_len   = NOKIA_AUTO_REPETITION_PAUSE_LEN;                          // 20 msec pause\r
-                        repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;                // 117 msec pause\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NOKIA_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       startbit_pause_len          = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;\r
+                       pulse_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       pause_len                   = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                       has_stop_bit                = GRUNDIG_NOKIA_IR60_STOP_BIT;\r
+                       complete_data_len           = NOKIA_COMPLETE_DATA_LEN;\r
+                       n_auto_repetitions          = NOKIA_FRAMES;                                 // 2 frames\r
+                       auto_repetition_pause_len   = NOKIA_AUTO_REPETITION_PAUSE_LEN;              // 20 msec pause\r
+                       repeat_frame_pause_len      = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;    // 117 msec pause\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r
-                    case IRMP_SIEMENS_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = SIEMENS_BIT_LEN;\r
-                        startbit_pause_len          = SIEMENS_BIT_LEN;\r
-                        pulse_len                   = SIEMENS_BIT_LEN;\r
-                        pause_len                   = SIEMENS_BIT_LEN;\r
-                        has_stop_bit                = SIEMENS_OR_RUWIDO_STOP_BIT;\r
-                        complete_data_len           = SIEMENS_COMPLETE_DATA_LEN - 1;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = SIEMENS_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_SIEMENS_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = SIEMENS_BIT_LEN;\r
+                       startbit_pause_len          = SIEMENS_BIT_LEN;\r
+                       pulse_len                   = SIEMENS_BIT_LEN;\r
+                       pause_len                   = SIEMENS_BIT_LEN;\r
+                       has_stop_bit                = SIEMENS_OR_RUWIDO_STOP_BIT;\r
+                       complete_data_len           = SIEMENS_COMPLETE_DATA_LEN - 1;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = SIEMENS_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_36_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
-                    case IRMP_FDC_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = FDC_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = FDC_START_BIT_PAUSE_LEN - 1;\r
-                        complete_data_len           = FDC_COMPLETE_DATA_LEN;\r
-                        pulse_1_len                 = FDC_PULSE_LEN;\r
-                        pause_1_len                 = FDC_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = FDC_PULSE_LEN;\r
-                        pause_0_len                 = FDC_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = FDC_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = FDC_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_FDC_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = FDC_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = FDC_START_BIT_PAUSE_LEN - 1;\r
+                       complete_data_len           = FDC_COMPLETE_DATA_LEN;\r
+                       pulse_1_len                 = FDC_PULSE_LEN;\r
+                       pause_1_len                 = FDC_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = FDC_PULSE_LEN;\r
+                       pause_0_len                 = FDC_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = FDC_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = FDC_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
-                    case IRMP_RCCAR_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = RCCAR_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = RCCAR_START_BIT_PAUSE_LEN - 1;\r
-                        complete_data_len           = RCCAR_COMPLETE_DATA_LEN;\r
-                        pulse_1_len                 = RCCAR_PULSE_LEN;\r
-                        pause_1_len                 = RCCAR_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = RCCAR_PULSE_LEN;\r
-                        pause_0_len                 = RCCAR_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = RCCAR_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = RCCAR_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_RCCAR_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = RCCAR_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = RCCAR_START_BIT_PAUSE_LEN - 1;\r
+                       complete_data_len           = RCCAR_COMPLETE_DATA_LEN;\r
+                       pulse_1_len                 = RCCAR_PULSE_LEN;\r
+                       pause_1_len                 = RCCAR_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = RCCAR_PULSE_LEN;\r
+                       pause_0_len                 = RCCAR_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = RCCAR_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = RCCAR_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_JVC_PROTOCOL == 1\r
-                    case IRMP_JVC_PROTOCOL:\r
-                    {\r
-                        if (repeat_counter != 0)                                                    // skip start bit if repetition frame\r
-                        {\r
-                            current_bit = 0;\r
-                        }\r
-\r
-                        startbit_pulse_len          = JVC_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = JVC_START_BIT_PAUSE_LEN - 1;\r
-                        complete_data_len           = JVC_COMPLETE_DATA_LEN;\r
-                        pulse_1_len                 = JVC_PULSE_LEN;\r
-                        pause_1_len                 = JVC_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = JVC_PULSE_LEN;\r
-                        pause_0_len                 = JVC_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = JVC_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = JVC_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_JVC_PROTOCOL:\r
+                   {\r
+                       if (repeat_counter != 0)                                                    // skip start bit if repetition frame\r
+                       {\r
+                           current_bit = 0;\r
+                       }\r
+\r
+                       startbit_pulse_len          = JVC_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = JVC_START_BIT_PAUSE_LEN - 1;\r
+                       complete_data_len           = JVC_COMPLETE_DATA_LEN;\r
+                       pulse_1_len                 = JVC_PULSE_LEN;\r
+                       pause_1_len                 = JVC_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = JVC_PULSE_LEN;\r
+                       pause_0_len                 = JVC_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = JVC_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = JVC_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
-                    case IRMP_NIKON_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = NIKON_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = 271 - 1; // NIKON_START_BIT_PAUSE_LEN;\r
-                        complete_data_len           = NIKON_COMPLETE_DATA_LEN;\r
-                        pulse_1_len                 = NIKON_PULSE_LEN;\r
-                        pause_1_len                 = NIKON_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = NIKON_PULSE_LEN;\r
-                        pause_0_len                 = NIKON_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = NIKON_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = NIKON_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
+                   case IRMP_NIKON_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = NIKON_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = NIKON_START_BIT_PAUSE_LEN;\r
+                       complete_data_len           = NIKON_COMPLETE_DATA_LEN;\r
+                       pulse_1_len                 = NIKON_PULSE_LEN;\r
+                       pause_1_len                 = NIKON_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = NIKON_PULSE_LEN;\r
+                       pause_0_len                 = NIKON_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = NIKON_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = NIKON_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
 #endif\r
 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
-                    case IRMP_LEGO_PROTOCOL:\r
-                    {\r
-                        startbit_pulse_len          = LEGO_START_BIT_PULSE_LEN;\r
-                        startbit_pause_len          = LEGO_START_BIT_PAUSE_LEN - 1;\r
-                        complete_data_len           = LEGO_COMPLETE_DATA_LEN;\r
-                        pulse_1_len                 = LEGO_PULSE_LEN;\r
-                        pause_1_len                 = LEGO_1_PAUSE_LEN - 1;\r
-                        pulse_0_len                 = LEGO_PULSE_LEN;\r
-                        pause_0_len                 = LEGO_0_PAUSE_LEN - 1;\r
-                        has_stop_bit                = LEGO_STOP_BIT;\r
-                        n_auto_repetitions          = 1;                                            // 1 frame\r
-                        auto_repetition_pause_len   = 0;\r
-                        repeat_frame_pause_len      = LEGO_FRAME_REPEAT_PAUSE_LEN;\r
-                        irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
-                        break;\r
-                    }\r
-#endif\r
-                    default:\r
-                    {\r
-                        irsnd_busy = FALSE;\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-        if (irsnd_busy)\r
-        {\r
-            new_frame = FALSE;\r
-\r
-            switch (irsnd_protocol)\r
-            {\r
+                   case IRMP_LEGO_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = LEGO_START_BIT_PULSE_LEN;\r
+                       startbit_pause_len          = LEGO_START_BIT_PAUSE_LEN - 1;\r
+                       complete_data_len           = LEGO_COMPLETE_DATA_LEN;\r
+                       pulse_1_len                 = LEGO_PULSE_LEN;\r
+                       pause_1_len                 = LEGO_1_PAUSE_LEN - 1;\r
+                       pulse_0_len                 = LEGO_PULSE_LEN;\r
+                       pause_0_len                 = LEGO_0_PAUSE_LEN - 1;\r
+                       has_stop_bit                = LEGO_STOP_BIT;\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = LEGO_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
+#endif\r
+#if IRSND_SUPPORT_A1TVBOX_PROTOCOL == 1\r
+                   case IRMP_A1TVBOX_PROTOCOL:\r
+                   {\r
+                       startbit_pulse_len          = A1TVBOX_BIT_PULSE_LEN;                        // don't use A1TVBOX_START_BIT_PULSE_LEN\r
+                       startbit_pause_len          = A1TVBOX_BIT_PAUSE_LEN;                        // don't use A1TVBOX_START_BIT_PAUSE_LEN\r
+                       pulse_len                   = A1TVBOX_BIT_PULSE_LEN;\r
+                       pause_len                   = A1TVBOX_BIT_PAUSE_LEN;\r
+                       has_stop_bit                = A1TVBOX_STOP_BIT;\r
+                       complete_data_len           = A1TVBOX_COMPLETE_DATA_LEN + 1;                // we send stop bit as data\r
+                       n_auto_repetitions          = 1;                                            // 1 frame\r
+                       auto_repetition_pause_len   = 0;\r
+                       repeat_frame_pause_len      = A1TVBOX_FRAME_REPEAT_PAUSE_LEN;\r
+                       irsnd_set_freq (IRSND_FREQ_38_KHZ);\r
+                       break;\r
+                   }\r
+#endif\r
+                   default:\r
+                   {\r
+                       irsnd_busy = FALSE;\r
+                       break;\r
+                   }\r
+               }\r
+           }\r
+       }\r
+\r
+       if (irsnd_busy)\r
+       {\r
+           new_frame = FALSE;\r
+\r
+           switch (irsnd_protocol)\r
+           {\r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r
-                case IRMP_SIRCS_PROTOCOL:\r
+               case IRMP_SIRCS_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r
-                case IRMP_NEC_PROTOCOL:\r
+               case IRMP_NEC_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1\r
-                case IRMP_NEC16_PROTOCOL:\r
+               case IRMP_NEC16_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1\r
-                case IRMP_NEC42_PROTOCOL:\r
+               case IRMP_NEC42_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r
-                case IRMP_SAMSUNG_PROTOCOL:\r
-                case IRMP_SAMSUNG32_PROTOCOL:\r
+               case IRMP_SAMSUNG_PROTOCOL:\r
+               case IRMP_SAMSUNG32_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r
-                case IRMP_MATSUSHITA_PROTOCOL:\r
+               case IRMP_MATSUSHITA_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1\r
-                case IRMP_KASEIKYO_PROTOCOL:\r
+               case IRMP_KASEIKYO_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r
-                case IRMP_RECS80_PROTOCOL:\r
+               case IRMP_RECS80_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r
-                case IRMP_RECS80EXT_PROTOCOL:\r
+               case IRMP_RECS80EXT_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
-                case IRMP_DENON_PROTOCOL:\r
+               case IRMP_DENON_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1\r
-                case IRMP_THOMSON_PROTOCOL:\r
+               case IRMP_THOMSON_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r
-                case IRMP_NUBERT_PROTOCOL:\r
+               case IRMP_NUBERT_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
-                case IRMP_BANG_OLUFSEN_PROTOCOL:\r
+               case IRMP_BANG_OLUFSEN_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
-                case IRMP_FDC_PROTOCOL:\r
+               case IRMP_FDC_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1\r
-                case IRMP_RCCAR_PROTOCOL:\r
+               case IRMP_RCCAR_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_JVC_PROTOCOL == 1\r
-                case IRMP_JVC_PROTOCOL:\r
+               case IRMP_JVC_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1\r
-                case IRMP_NIKON_PROTOCOL:\r
+               case IRMP_NIKON_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1\r
-                case IRMP_LEGO_PROTOCOL:\r
+               case IRMP_LEGO_PROTOCOL:\r
 #endif\r
 \r
-\r
 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1  || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_NEC16_PROTOCOL == 1 || IRSND_SUPPORT_NEC42_PROTOCOL == 1 || \\r
     IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 ||   \\r
     IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \\r
     IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 ||   \\r
     IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1 || IRSND_SUPPORT_THOMSON_PROTOCOL == 1 \r
-                {\r
-                    if (pulse_counter == 0)\r
-                    {\r
-                        if (current_bit == 0xFF)                                                    // send start bit\r
-                        {\r
-                            pulse_len = startbit_pulse_len;\r
-                            pause_len = startbit_pause_len;\r
-                        }\r
-                        else if (current_bit < complete_data_len)                                   // send n'th bit\r
-                        {\r
+               {\r
+#if IRSND_SUPPORT_DENON_PROTOCOL == 1\r
+                   if (irsnd_protocol == IRMP_DENON_PROTOCOL)\r
+                   {\r
+                       if (auto_repetition_pause_len > 0)                                          // 2nd frame distance counts from beginning of 1st frame!\r
+                       {\r
+                           auto_repetition_pause_len--;\r
+                       }\r
+\r
+                       if (repeat_frame_pause_len > 0)                                             // frame repeat distance counts from beginning of 1st frame!\r
+                       {\r
+                           repeat_frame_pause_len--;\r
+                       }\r
+                   }\r
+#endif\r
+\r
+                   if (pulse_counter == 0)\r
+                   {\r
+                       if (current_bit == 0xFF)                                                    // send start bit\r
+                       {\r
+                           pulse_len = startbit_pulse_len;\r
+                           pause_len = startbit_pause_len;\r
+                       }\r
+                       else if (current_bit < complete_data_len)                                   // send n'th bit\r
+                       {\r
 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r
-                            if (irsnd_protocol == IRMP_SAMSUNG_PROTOCOL)\r
-                            {\r
-                                if (current_bit < SAMSUNG_ADDRESS_LEN)                              // send address bits\r
-                                {\r
-                                    pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
-                                                    (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
-                                }\r
-                                else if (current_bit == SAMSUNG_ADDRESS_LEN)                        // send SYNC bit (16th bit)\r
-                                {\r
-                                    pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit < SAMSUNG_COMPLETE_DATA_LEN)                   // send n'th bit\r
-                                {\r
-                                    uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
-\r
-                                    pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
-                                                    (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
-                                }\r
-                            }\r
-                            else\r
+                           if (irsnd_protocol == IRMP_SAMSUNG_PROTOCOL)\r
+                           {\r
+                               if (current_bit < SAMSUNG_ADDRESS_LEN)                              // send address bits\r
+                               {\r
+                                   pulse_len = SAMSUNG_PULSE_LEN;\r
+                                   pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                                   (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
+                               }\r
+                               else if (current_bit == SAMSUNG_ADDRESS_LEN)                        // send SYNC bit (16th bit)\r
+                               {\r
+                                   pulse_len = SAMSUNG_PULSE_LEN;\r
+                                   pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit < SAMSUNG_COMPLETE_DATA_LEN)                   // send n'th bit\r
+                               {\r
+                                   uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
+\r
+                                   pulse_len = SAMSUNG_PULSE_LEN;\r
+                                   pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                                   (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
+                               }\r
+                           }\r
+                           else\r
 #endif\r
 \r
 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1\r
-                            if (irsnd_protocol == IRMP_NEC16_PROTOCOL)\r
-                            {\r
-                                if (current_bit < NEC16_ADDRESS_LEN)                                // send address bits\r
-                                {\r
-                                    pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
-                                                    (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
-                                }\r
-                                else if (current_bit == NEC16_ADDRESS_LEN)                          // send SYNC bit (8th bit)\r
-                                {\r
-                                    pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = NEC_START_BIT_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit < NEC16_COMPLETE_DATA_LEN + 1)                 // send n'th bit\r
-                                {\r
-                                    uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
-\r
-                                    pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
-                                                    (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
-                                }\r
-                            }\r
-                            else\r
+                           if (irsnd_protocol == IRMP_NEC16_PROTOCOL)\r
+                           {\r
+                               if (current_bit < NEC16_ADDRESS_LEN)                                // send address bits\r
+                               {\r
+                                   pulse_len = NEC_PULSE_LEN;\r
+                                   pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                                   (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
+                               }\r
+                               else if (current_bit == NEC16_ADDRESS_LEN)                          // send SYNC bit (8th bit)\r
+                               {\r
+                                   pulse_len = NEC_PULSE_LEN;\r
+                                   pause_len = NEC_START_BIT_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit < NEC16_COMPLETE_DATA_LEN + 1)                 // send n'th bit\r
+                               {\r
+                                   uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
+\r
+                                   pulse_len = NEC_PULSE_LEN;\r
+                                   pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                                   (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
+                               }\r
+                           }\r
+                           else\r
 #endif\r
 \r
 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r
-                            if (irsnd_protocol == IRMP_BANG_OLUFSEN_PROTOCOL)\r
-                            {\r
-                                if (current_bit == 0)                                               // send 2nd start bit\r
-                                {\r
-                                    pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r
-                                    pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit == 1)                                          // send 3rd start bit\r
-                                {\r
-                                    pulse_len = BANG_OLUFSEN_START_BIT3_PULSE_LEN;\r
-                                    pause_len = BANG_OLUFSEN_START_BIT3_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit == 2)                                          // send 4th start bit\r
-                                {\r
-                                    pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r
-                                    pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit == 19)                                          // send trailer bit\r
-                                {\r
-                                    pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
-                                    pause_len = BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN - 1;\r
-                                }\r
-                                else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN)              // send n'th bit\r
-                                {\r
-                                    uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;\r
-                                    pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
-\r
-                                    if (cur_bit_value == last_bit_value)\r
-                                    {\r
-                                        pause_len = BANG_OLUFSEN_R_PAUSE_LEN - 1;\r
-                                    }\r
-                                    else\r
-                                    {\r
-                                        pause_len = cur_bit_value ? (BANG_OLUFSEN_1_PAUSE_LEN - 1) : (BANG_OLUFSEN_0_PAUSE_LEN - 1);\r
-                                        last_bit_value = cur_bit_value;\r
-                                    }\r
-                                }\r
-                            }\r
-                            else\r
-#endif\r
-                            if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))\r
-                            {\r
-                                pulse_len = pulse_1_len;\r
-                                pause_len = pause_1_len;\r
-                            }\r
-                            else\r
-                            {\r
-                                pulse_len = pulse_0_len;\r
-                                pause_len = pause_0_len;\r
-                            }\r
-                        }\r
-                        else if (has_stop_bit)                                                                      // send stop bit\r
-                        {\r
-                            pulse_len = pulse_0_len;\r
-\r
-                            if (auto_repetition_counter < n_auto_repetitions)\r
-                            {\r
-                                pause_len = pause_0_len;\r
-                            }\r
-                            else\r
-                            {\r
-                                pause_len = 255;                                        // last frame: pause of 255\r
-                            }\r
-                        }\r
-                    }\r
-\r
-                    if (pulse_counter < pulse_len)\r
-                    {\r
-                        if (pulse_counter == 0)\r
-                        {\r
-                            irsnd_on ();\r
-                        }\r
-                        pulse_counter++;\r
-                    }\r
-                    else if (pause_counter < pause_len)\r
-                    {\r
-                        if (pause_counter == 0)\r
-                        {\r
-                            irsnd_off ();\r
-                        }\r
-                        pause_counter++;\r
-                    }\r
-                    else\r
-                    {\r
-                        current_bit++;\r
-\r
-                        if (current_bit >= complete_data_len + has_stop_bit)\r
-                        {\r
-                            current_bit = 0xFF;\r
-                            auto_repetition_counter++;\r
-\r
-                            if (auto_repetition_counter == n_auto_repetitions)\r
-                            {\r
-                                irsnd_busy = FALSE;\r
-                                auto_repetition_counter = 0;\r
-                            }\r
-                            new_frame = TRUE;\r
-                        }\r
-\r
-                        pulse_counter = 0;\r
-                        pause_counter = 0;\r
-                    }\r
-                    break;\r
-                }\r
+                           if (irsnd_protocol == IRMP_BANG_OLUFSEN_PROTOCOL)\r
+                           {\r
+                               if (current_bit == 0)                                               // send 2nd start bit\r
+                               {\r
+                                   pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r
+                                   pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit == 1)                                          // send 3rd start bit\r
+                               {\r
+                                   pulse_len = BANG_OLUFSEN_START_BIT3_PULSE_LEN;\r
+                                   pause_len = BANG_OLUFSEN_START_BIT3_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit == 2)                                          // send 4th start bit\r
+                               {\r
+                                   pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r
+                                   pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit == 19)                                          // send trailer bit\r
+                               {\r
+                                   pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
+                                   pause_len = BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN - 1;\r
+                               }\r
+                               else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN)              // send n'th bit\r
+                               {\r
+                                   uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;\r
+                                   pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
+\r
+                                   if (cur_bit_value == last_bit_value)\r
+                                   {\r
+                                       pause_len = BANG_OLUFSEN_R_PAUSE_LEN - 1;\r
+                                   }\r
+                                   else\r
+                                   {\r
+                                       pause_len = cur_bit_value ? (BANG_OLUFSEN_1_PAUSE_LEN - 1) : (BANG_OLUFSEN_0_PAUSE_LEN - 1);\r
+                                       last_bit_value = cur_bit_value;\r
+                                   }\r
+                               }\r
+                           }\r
+                           else\r
+#endif\r
+                           if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))\r
+                           {\r
+                               pulse_len = pulse_1_len;\r
+                               pause_len = pause_1_len;\r
+                           }\r
+                           else\r
+                           {\r
+                               pulse_len = pulse_0_len;\r
+                               pause_len = pause_0_len;\r
+                           }\r
+                       }\r
+                       else if (has_stop_bit)                                                                      // send stop bit\r
+                       {\r
+                           pulse_len = pulse_0_len;\r
+\r
+                           if (auto_repetition_counter < n_auto_repetitions)\r
+                           {\r
+                               pause_len = pause_0_len;\r
+                           }\r
+                           else\r
+                           {\r
+                               pause_len = 255;                                        // last frame: pause of 255\r
+                           }\r
+                       }\r
+                   }\r
+\r
+                   if (pulse_counter < pulse_len)\r
+                   {\r
+                       if (pulse_counter == 0)\r
+                       {\r
+                           irsnd_on ();\r
+                       }\r
+                       pulse_counter++;\r
+                   }\r
+                   else if (pause_counter < pause_len)\r
+                   {\r
+                       if (pause_counter == 0)\r
+                       {\r
+                           irsnd_off ();\r
+                       }\r
+                       pause_counter++;\r
+                   }\r
+                   else\r
+                   {\r
+                       current_bit++;\r
+\r
+                       if (current_bit >= complete_data_len + has_stop_bit)\r
+                       {\r
+                           current_bit = 0xFF;\r
+                           auto_repetition_counter++;\r
+\r
+                           if (auto_repetition_counter == n_auto_repetitions)\r
+                           {\r
+                               irsnd_busy = FALSE;\r
+                               auto_repetition_counter = 0;\r
+                           }\r
+                           new_frame = TRUE;\r
+                       }\r
+\r
+                       pulse_counter = 0;\r
+                       pause_counter = 0;\r
+                   }\r
+                   break;\r
+               }\r
 #endif\r
 \r
 #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r
-                case IRMP_RC5_PROTOCOL:\r
+               case IRMP_RC5_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_RC6_PROTOCOL == 1\r
-                case IRMP_RC6_PROTOCOL:\r
+               case IRMP_RC6_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1\r
-                case IRMP_RC6A_PROTOCOL:\r
+               case IRMP_RC6A_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r
-                case IRMP_SIEMENS_PROTOCOL:\r
+               case IRMP_SIEMENS_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r
-                case IRMP_GRUNDIG_PROTOCOL:\r
+               case IRMP_GRUNDIG_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_IR60_PROTOCOL == 1\r
-                case IRMP_IR60_PROTOCOL:\r
+               case IRMP_IR60_PROTOCOL:\r
 #endif\r
 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-                case IRMP_NOKIA_PROTOCOL:\r
+               case IRMP_NOKIA_PROTOCOL:\r
+#endif\r
+#if IRSND_SUPPORT_A1TVBOX_PROTOCOL == 1\r
+               case IRMP_A1TVBOX_PROTOCOL:\r
 #endif\r
 \r
 #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || \\r
-    IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-                {\r
-                    if (pulse_counter == pulse_len && pause_counter == pause_len)\r
-                    {\r
-                        current_bit++;\r
+    IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1 || IRSND_SUPPORT_A1TVBOX_PROTOCOL == 1\r
+               {\r
+                   if (pulse_counter == pulse_len && pause_counter == pause_len)\r
+                   {\r
+                       current_bit++;\r
 \r
-                        if (current_bit >= complete_data_len)\r
-                        {\r
-                            current_bit = 0xFF;\r
+                       if (current_bit >= complete_data_len)\r
+                       {\r
+                           current_bit = 0xFF;\r
 \r
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-                            if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r
-                            {\r
-                                auto_repetition_counter++;\r
-\r
-                                if (repeat_counter > 0)\r
-                                {                                       // set 117 msec pause time\r
-                                    auto_repetition_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;\r
-                                }\r
-\r
-                                if (repeat_counter < n_repeat_frames)       // tricky: repeat n info frames per auto repetition before sending last stop frame\r
-                                {\r
-                                    n_auto_repetitions++;                   // increment number of auto repetitions\r
-                                    repeat_counter++;\r
-                                }\r
-                                else if (auto_repetition_counter == n_auto_repetitions)\r
-                                {\r
-                                    irsnd_busy = FALSE;\r
-                                    auto_repetition_counter = 0;\r
-                                }\r
-                            }\r
-                            else\r
-#endif\r
-                            {\r
-                                irsnd_busy  = FALSE;\r
-                            }\r
-\r
-                            new_frame = TRUE;\r
-                            irsnd_off ();\r
-                        }\r
-\r
-                        pulse_counter = 0;\r
-                        pause_counter = 0;\r
-                    }\r
-\r
-                    if (! new_frame)\r
-                    {\r
-                        uint8_t first_pulse;\r
+                           if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r
+                           {\r
+                               auto_repetition_counter++;\r
+\r
+                               if (repeat_counter > 0)\r
+                               {                                       // set 117 msec pause time\r
+                                   auto_repetition_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;\r
+                               }\r
+\r
+                               if (repeat_counter < n_repeat_frames)       // tricky: repeat n info frames per auto repetition before sending last stop frame\r
+                               {\r
+                                   n_auto_repetitions++;                   // increment number of auto repetitions\r
+                                   repeat_counter++;\r
+                               }\r
+                               else if (auto_repetition_counter == n_auto_repetitions)\r
+                               {\r
+                                   irsnd_busy = FALSE;\r
+                                   auto_repetition_counter = 0;\r
+                               }\r
+                           }\r
+                           else\r
+#endif\r
+                           {\r
+                               irsnd_busy  = FALSE;\r
+                           }\r
+\r
+                           new_frame = TRUE;\r
+                           irsnd_off ();\r
+                       }\r
+\r
+                       pulse_counter = 0;\r
+                       pause_counter = 0;\r
+                   }\r
+\r
+                   if (! new_frame)\r
+                   {\r
+                       uint8_t first_pulse;\r
 \r
 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
-                        if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r
-                        {\r
-                            if (current_bit == 0xFF ||                                                                  // start bit of start-frame\r
-                                (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL && current_bit == 15) ||                       // start bit of info-frame (Grundig)\r
-                                (irsnd_protocol == IRMP_IR60_PROTOCOL && current_bit == 7) ||                           // start bit of data frame (IR60)\r
-                                (irsnd_protocol == IRMP_NOKIA_PROTOCOL && (current_bit == 23 || current_bit == 47)))    // start bit of info- or stop-frame (Nokia)\r
-                            {\r
-                                pulse_len = startbit_pulse_len;\r
-                                pause_len = startbit_pause_len;\r
-                                first_pulse = TRUE;\r
-                            }\r
-                            else                                                                        // send n'th bit\r
-                            {\r
-                                pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                                pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                                first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
-                            }\r
-                        }\r
-                        else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||\r
-                             //     irsnd_protocol == IRMP_SIEMENS_PROTOCOL)\r
-#endif\r
-                        {\r
-                            if (current_bit == 0xFF)                                                    // 1 start bit\r
-                            {\r
+                       if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r
+                       {\r
+                           if (current_bit == 0xFF ||                                                                  // start bit of start-frame\r
+                               (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL && current_bit == 15) ||                       // start bit of info-frame (Grundig)\r
+                               (irsnd_protocol == IRMP_IR60_PROTOCOL && current_bit == 7) ||                           // start bit of data frame (IR60)\r
+                               (irsnd_protocol == IRMP_NOKIA_PROTOCOL && (current_bit == 23 || current_bit == 47)))    // start bit of info- or stop-frame (Nokia)\r
+                           {\r
+                               pulse_len = startbit_pulse_len;\r
+                               pause_len = startbit_pause_len;\r
+                               first_pulse = TRUE;\r
+                           }\r
+                           else                                                                        // send n'th bit\r
+                           {\r
+                               pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                               pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
+                               first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
+                           }\r
+                       }\r
+                       else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||\r
+                            //     irsnd_protocol == IRMP_SIEMENS_PROTOCOL)\r
+#endif\r
+                       {\r
+                           if (current_bit == 0xFF)                                                    // 1 start bit\r
+                           {\r
 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1\r
-                                if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
-                                {\r
-                                    pulse_len = startbit_pulse_len;\r
-                                    pause_len = startbit_pause_len;\r
-                                }\r
-#endif\r
-                                first_pulse = TRUE;\r
-                            }\r
-                            else                                                                        // send n'th bit\r
-                            {\r
+                               if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
+                               {\r
+                                   pulse_len = startbit_pulse_len;\r
+                                   pause_len = startbit_pause_len;\r
+                               }\r
+                               else\r
+#endif\r
+#if IRSND_SUPPORT_A1TVBOX_PROTOCOL == 1\r
+                               if (irsnd_protocol == IRMP_A1TVBOX_PROTOCOL)\r
+                               {\r
+                                   current_bit = 0;\r
+                               }\r
+                               else\r
+#endif\r
+                               {\r
+                                   ;\r
+                               }\r
+\r
+                               first_pulse = TRUE;\r
+                           }\r
+                           else                                                                        // send n'th bit\r
+                           {\r
 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1\r
-                                if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
-                                {\r
-                                    pulse_len = RC6_BIT_LEN;\r
-                                    pause_len = RC6_BIT_LEN;\r
-\r
-                                    if (irsnd_protocol == IRMP_RC6_PROTOCOL)\r
-                                    {\r
-                                        if (current_bit == 4)                                           // toggle bit (double len)\r
-                                        {\r
-                                            pulse_len = 2 * RC6_BIT_LEN;\r
-                                            pause_len = 2 * RC6_BIT_LEN;\r
-                                        }\r
-                                    }\r
-                                    else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
-                                    {\r
-                                        if (current_bit == 4)                                           // toggle bit (double len)\r
-                                        {\r
-                                            pulse_len = 2 * RC6_BIT_LEN + RC6_BIT_LEN;                  // hack!\r
-                                            pause_len = 2 * RC6_BIT_LEN;\r
-                                        }\r
-                                        else if (current_bit == 5)                                      // toggle bit (double len)\r
-                                        {\r
-                                            pause_len = 2 * RC6_BIT_LEN;\r
-                                        }\r
-                                    }\r
-                                }\r
-#endif\r
-                                first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
-                            }\r
-\r
-                            if (irsnd_protocol == IRMP_RC5_PROTOCOL)\r
-                            {\r
-                                first_pulse = first_pulse ? FALSE : TRUE;\r
-                            }\r
-                        }\r
-\r
-                        if (first_pulse)\r
-                        {\r
-                            if (pulse_counter < pulse_len)\r
-                            {\r
-                                if (pulse_counter == 0)\r
-                                {\r
-                                    irsnd_on ();\r
-                                }\r
-                                pulse_counter++;\r
-                            }\r
-                            else // if (pause_counter < pause_len)\r
-                            {\r
-                                if (pause_counter == 0)\r
-                                {\r
-                                    irsnd_off ();\r
-                                }\r
-                                pause_counter++;\r
-                            }\r
-                        }\r
-                        else\r
-                        {\r
-                            if (pause_counter < pause_len)\r
-                            {\r
-                                if (pause_counter == 0)\r
-                                {\r
-                                    irsnd_off ();\r
-                                }\r
-                                pause_counter++;\r
-                            }\r
-                            else // if (pulse_counter < pulse_len)\r
-                            {\r
-                                if (pulse_counter == 0)\r
-                                {\r
-                                    irsnd_on ();\r
-                                }\r
-                                pulse_counter++;\r
-                            }\r
-                        }\r
-                    }\r
-                    break;\r
-                }\r
+                               if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
+                               {\r
+                                   pulse_len = RC6_BIT_LEN;\r
+                                   pause_len = RC6_BIT_LEN;\r
+\r
+                                   if (irsnd_protocol == IRMP_RC6_PROTOCOL)\r
+                                   {\r
+                                       if (current_bit == 4)                                           // toggle bit (double len)\r
+                                       {\r
+                                           pulse_len = 2 * RC6_BIT_LEN;\r
+                                           pause_len = 2 * RC6_BIT_LEN;\r
+                                       }\r
+                                   }\r
+                                   else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)\r
+                                   {\r
+                                       if (current_bit == 4)                                           // toggle bit (double len)\r
+                                       {\r
+                                           pulse_len = 2 * RC6_BIT_LEN + RC6_BIT_LEN;                  // hack!\r
+                                           pause_len = 2 * RC6_BIT_LEN;\r
+                                       }\r
+                                       else if (current_bit == 5)                                      // toggle bit (double len)\r
+                                       {\r
+                                           pause_len = 2 * RC6_BIT_LEN;\r
+                                       }\r
+                                   }\r
+                               }\r
+#endif\r
+                               first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
+                           }\r
+\r
+                           if (irsnd_protocol == IRMP_RC5_PROTOCOL)\r
+                           {\r
+                               first_pulse = first_pulse ? FALSE : TRUE;\r
+                           }\r
+                       }\r
+\r
+                       if (first_pulse)\r
+                       {\r
+                           // printf ("first_pulse: current_bit: %d  %d < %d  %d < %d\n", current_bit, pause_counter, pause_len, pulse_counter, pulse_len);\r
+\r
+                           if (pulse_counter < pulse_len)\r
+                           {\r
+                               if (pulse_counter == 0)\r
+                               {\r
+                                   irsnd_on ();\r
+                               }\r
+                               pulse_counter++;\r
+                           }\r
+                           else // if (pause_counter < pause_len)\r
+                           {\r
+                               if (pause_counter == 0)\r
+                               {\r
+                                   irsnd_off ();\r
+                               }\r
+                               pause_counter++;\r
+                           }\r
+                       }\r
+                       else\r
+                       {\r
+                           // printf ("first_pause: current_bit: %d  %d < %d  %d < %d\n", current_bit, pause_counter, pause_len, pulse_counter, pulse_len);\r
+\r
+                           if (pause_counter < pause_len)\r
+                           {\r
+                               if (pause_counter == 0)\r
+                               {\r
+                                   irsnd_off ();\r
+                               }\r
+                               pause_counter++;\r
+                           }\r
+                           else // if (pulse_counter < pulse_len)\r
+                           {\r
+                               if (pulse_counter == 0)\r
+                               {\r
+                                   irsnd_on ();\r
+                               }\r
+                               pulse_counter++;\r
+                           }\r
+                       }\r
+                   }\r
+                   break;\r
+               }\r
 #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 ||\r
        // IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r
 \r
-                default:\r
-                {\r
-                    irsnd_busy = FALSE;\r
-                    break;\r
-                }\r
-            }\r
-        }\r
-\r
-        if (! irsnd_busy)\r
-        {\r
-            if (repeat_counter < n_repeat_frames)\r
-            {\r
+               default:\r
+               {\r
+                   irsnd_busy = FALSE;\r
+                   break;\r
+               }\r
+           }\r
+       }\r
+\r
+       if (! irsnd_busy)\r
+       {\r
+           if (repeat_counter < n_repeat_frames)\r
+           {\r
 #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r
-                if (irsnd_protocol == IRMP_FDC_PROTOCOL)\r
-                {\r
-                    irsnd_buffer[2] |= 0x0F;\r
-                }\r
-#endif\r
-                repeat_counter++;\r
-                irsnd_busy = TRUE;\r
-            }\r
-            else\r
-            {\r
-                irsnd_busy = TRUE; //Rainer\r
-                send_trailer = TRUE;\r
-                n_repeat_frames = 0;\r
-                repeat_counter = 0;\r
-            }\r
-        }\r
+               if (irsnd_protocol == IRMP_FDC_PROTOCOL)\r
+               {\r
+                   irsnd_buffer[2] |= 0x0F;\r
+               }\r
+#endif\r
+               repeat_counter++;\r
+               irsnd_busy = TRUE;\r
+           }\r
+           else\r
+           {\r
+               irsnd_busy = TRUE; //Rainer\r
+               send_trailer = TRUE;\r
+               n_repeat_frames = 0;\r
+               repeat_counter = 0;\r
+           }\r
+       }\r
     }\r
 \r
 #ifdef DEBUG\r
     if (irsnd_is_on)\r
     {\r
-        putchar ('0');\r
+       putchar ('0');\r
     }\r
     else\r
     {\r
-        putchar ('1');\r
+       putchar ('1');\r
     }\r
 #endif\r
 \r
@@ -2132,42 +2293,53 @@ main (int argc, char ** argv)
 \r
     if (argc != 4 && argc != 5)\r
     {\r
-        fprintf (stderr, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv[0]);\r
-        return 1;\r
+       fprintf (stderr, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv[0]);\r
+       return 1;\r
     }\r
 \r
     if (sscanf (argv[1], "%d", &protocol) == 1 &&\r
-        sscanf (argv[2], "%x", &address) == 1 &&\r
-        sscanf (argv[3], "%x", &command) == 1)\r
+       sscanf (argv[2], "%x", &address) == 1 &&\r
+       sscanf (argv[3], "%x", &command) == 1)\r
     {\r
-        irmp_data.protocol = protocol;\r
-        irmp_data.address = address;\r
-        irmp_data.command = command;\r
+       irmp_data.protocol = protocol;\r
+       irmp_data.address = address;\r
+       irmp_data.command = command;\r
 \r
-        if (argc == 5)\r
-        {\r
-            irmp_data.flags = atoi (argv[4]);\r
-        }\r
-        else\r
-        {\r
-            irmp_data.flags = 0;\r
-        }\r
+       if (argc == 5)\r
+       {\r
+           irmp_data.flags = atoi (argv[4]);\r
+       }\r
+       else\r
+       {\r
+           irmp_data.flags = 0;\r
+       }\r
 \r
-        irsnd_init ();\r
+       irsnd_init ();\r
 \r
-        (void) irsnd_send_data (&irmp_data, TRUE);\r
+       (void) irsnd_send_data (&irmp_data, TRUE);\r
 \r
-        while (irsnd_busy)\r
-        {\r
-            irsnd_ISR ();\r
-        }\r
+       while (irsnd_busy)\r
+       {\r
+           irsnd_ISR ();\r
+       }\r
 \r
-        putchar ('\n');\r
+       putchar ('\n');\r
+\r
+#if 1 // enable here to send twice\r
+       (void) irsnd_send_data (&irmp_data, TRUE);\r
+\r
+       while (irsnd_busy)\r
+       {\r
+           irsnd_ISR ();\r
+       }\r
+\r
+       putchar ('\n');\r
+#endif\r
     }\r
     else\r
     {\r
-        fprintf (stderr, "%s: wrong arguments\n", argv[0]);\r
-        return 1;\r
+       fprintf (stderr, "%s: wrong arguments\n", argv[0]);\r
+       return 1;\r
     }\r
     return 0;\r
 }\r