]> sigrok.org Git - libsigrokdecode.git/blob - irmp/irmp.c
irmp: introduce (part of) upstream IRMP sources
[libsigrokdecode.git] / irmp / irmp.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2  * irmp.c - infrared multi-protocol decoder, supports several remote control protocols
3  *
4  * Copyright (c) 2009-2019 Frank Meyer - frank(at)fli4l.de
5  *
6  * Supported AVR mikrocontrollers:
7  *
8  * ATtiny87,  ATtiny167
9  * ATtiny45,  ATtiny85
10  * ATtiny44,  ATtiny84
11  * ATmega8,   ATmega16,  ATmega32
12  * ATmega162
13  * ATmega164, ATmega324, ATmega644,  ATmega644P, ATmega1284, ATmega1284P
14  * ATmega88,  ATmega88P, ATmega168,  ATmega168P, ATmega328P
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *---------------------------------------------------------------------------------------------------------------------------------------------------
21  */
22
23 #include "irmp.h"
24
25 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_IR60_PROTOCOL == 1
26 #  define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL  1
27 #else
28 #  define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL  0
29 #endif
30
31 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 || IRMP_SUPPORT_RUWIDO_PROTOCOL == 1
32 #  define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL   1
33 #else
34 #  define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL   0
35 #endif
36
37 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 ||                   \
38     IRMP_SUPPORT_RCII_PROTOCOL == 1 ||                  \
39     IRMP_SUPPORT_S100_PROTOCOL == 1 ||                  \
40     IRMP_SUPPORT_RC6_PROTOCOL == 1 ||                   \
41     IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 ||    \
42     IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 ||     \
43     IRMP_SUPPORT_IR60_PROTOCOL == 1 ||                  \
44     IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1 ||               \
45     IRMP_SUPPORT_MERLIN_PROTOCOL == 1 ||                \
46     IRMP_SUPPORT_ORTEK_PROTOCOL == 1
47 #  define IRMP_SUPPORT_MANCHESTER                   1
48 #else
49 #  define IRMP_SUPPORT_MANCHESTER                   0
50 #endif
51
52 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
53 #  define IRMP_SUPPORT_SERIAL                       1
54 #else
55 #  define IRMP_SUPPORT_SERIAL                       0
56 #endif
57
58 #define IRMP_KEY_REPETITION_LEN                 (uint_fast16_t)(F_INTERRUPTS * 150.0e-3 + 0.5)           // autodetect key repetition within 150 msec
59
60 #define MIN_TOLERANCE_00                        1.0                           // -0%
61 #define MAX_TOLERANCE_00                        1.0                           // +0%
62
63 #define MIN_TOLERANCE_02                        0.98                          // -2%
64 #define MAX_TOLERANCE_02                        1.02                          // +2%
65
66 #define MIN_TOLERANCE_03                        0.97                          // -3%
67 #define MAX_TOLERANCE_03                        1.03                          // +3%
68
69 #define MIN_TOLERANCE_05                        0.95                          // -5%
70 #define MAX_TOLERANCE_05                        1.05                          // +5%
71
72 #define MIN_TOLERANCE_10                        0.9                           // -10%
73 #define MAX_TOLERANCE_10                        1.1                           // +10%
74
75 #define MIN_TOLERANCE_15                        0.85                          // -15%
76 #define MAX_TOLERANCE_15                        1.15                          // +15%
77
78 #define MIN_TOLERANCE_20                        0.8                           // -20%
79 #define MAX_TOLERANCE_20                        1.2                           // +20%
80
81 #define MIN_TOLERANCE_30                        0.7                           // -30%
82 #define MAX_TOLERANCE_30                        1.3                           // +30%
83
84 #define MIN_TOLERANCE_40                        0.6                           // -40%
85 #define MAX_TOLERANCE_40                        1.4                           // +40%
86
87 #define MIN_TOLERANCE_50                        0.5                           // -50%
88 #define MAX_TOLERANCE_50                        1.5                           // +50%
89
90 #define MIN_TOLERANCE_60                        0.4                           // -60%
91 #define MAX_TOLERANCE_60                        1.6                           // +60%
92
93 #define MIN_TOLERANCE_70                        0.3                           // -70%
94 #define MAX_TOLERANCE_70                        1.7                           // +70%
95
96 #define SIRCS_START_BIT_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
97 #define SIRCS_START_BIT_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
98 #define SIRCS_START_BIT_PAUSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
99 #if IRMP_SUPPORT_NETBOX_PROTOCOL                // only 5% to avoid conflict with NETBOX:
100 #  define SIRCS_START_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
101 #else                                           // only 5% + 1 to avoid conflict with RC6:
102 #  define SIRCS_START_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
103 #endif
104 #define SIRCS_1_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
105 #define SIRCS_1_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
106 #define SIRCS_0_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
107 #define SIRCS_0_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
108 #define SIRCS_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
109 #define SIRCS_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
110
111 #define NEC_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
112 #define NEC_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
113 #define NEC_START_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
114 #define NEC_START_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
115 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
116 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
117 #define NEC_PULSE_LEN_MIN                       ((uint_fast8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
118 #define NEC_PULSE_LEN_MAX                       ((uint_fast8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
119 #define NEC_1_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
120 #define NEC_1_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
121 #define NEC_0_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
122 #define NEC_0_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
123 // autodetect nec repetition frame within 50 msec:
124 // NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms
125 #if 0
126 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX          (uint_fast16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
127 #else
128 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX          (uint_fast16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)
129 #endif
130
131 #define SAMSUNG_START_BIT_PULSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
132 #define SAMSUNG_START_BIT_PULSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
133 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
134 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
135 #define SAMSUNG_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
136 #define SAMSUNG_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
137 #define SAMSUNG_1_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
138 #define SAMSUNG_1_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
139 #define SAMSUNG_0_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
140 #define SAMSUNG_0_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
141
142 #define SAMSUNGAH_START_BIT_PULSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
143 #define SAMSUNGAH_START_BIT_PULSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
144 #define SAMSUNGAH_START_BIT_PAUSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
145 #define SAMSUNGAH_START_BIT_PAUSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
146 #define SAMSUNGAH_PULSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
147 #define SAMSUNGAH_PULSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
148 #define SAMSUNGAH_1_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
149 #define SAMSUNGAH_1_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
150 #define SAMSUNGAH_0_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
151 #define SAMSUNGAH_0_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * SAMSUNGAH_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
152
153 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
154 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
155 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
156 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
157 #define MATSUSHITA_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
158 #define MATSUSHITA_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
159 #define MATSUSHITA_1_PAUSE_LEN_MIN              ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
160 #define MATSUSHITA_1_PAUSE_LEN_MAX              ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
161 #define MATSUSHITA_0_PAUSE_LEN_MIN              ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
162 #define MATSUSHITA_0_PAUSE_LEN_MAX              ((uint_fast8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
163
164 #define KASEIKYO_START_BIT_PULSE_LEN_MIN        ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
165 #define KASEIKYO_START_BIT_PULSE_LEN_MAX        ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
166 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN        ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
167 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX        ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
168 #define KASEIKYO_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
169 #define KASEIKYO_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
170 #define KASEIKYO_1_PAUSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
171 #define KASEIKYO_1_PAUSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
172 #define KASEIKYO_0_PAUSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
173 #define KASEIKYO_0_PAUSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
174
175 #define MITSU_HEAVY_START_BIT_PULSE_LEN_MIN     ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
176 #define MITSU_HEAVY_START_BIT_PULSE_LEN_MAX     ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
177 #define MITSU_HEAVY_START_BIT_PAUSE_LEN_MIN     ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
178 #define MITSU_HEAVY_START_BIT_PAUSE_LEN_MAX     ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
179 #define MITSU_HEAVY_PULSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
180 #define MITSU_HEAVY_PULSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
181 #define MITSU_HEAVY_1_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
182 #define MITSU_HEAVY_1_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
183 #define MITSU_HEAVY_0_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
184 #define MITSU_HEAVY_0_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * MITSU_HEAVY_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
185
186 #define VINCENT_START_BIT_PULSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * VINCENT_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
187 #define VINCENT_START_BIT_PULSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * VINCENT_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
188 #define VINCENT_START_BIT_PAUSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * VINCENT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
189 #define VINCENT_START_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * VINCENT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
190 #define VINCENT_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * VINCENT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
191 #define VINCENT_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * VINCENT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
192 #define VINCENT_1_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * VINCENT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
193 #define VINCENT_1_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * VINCENT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
194 #define VINCENT_0_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * VINCENT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
195 #define VINCENT_0_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * VINCENT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
196
197 #define PANASONIC_START_BIT_PULSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
198 #define PANASONIC_START_BIT_PULSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
199 #define PANASONIC_START_BIT_PAUSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
200 #define PANASONIC_START_BIT_PAUSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
201 #define PANASONIC_PULSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
202 #define PANASONIC_PULSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
203 #define PANASONIC_1_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
204 #define PANASONIC_1_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
205 #define PANASONIC_0_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
206 #define PANASONIC_0_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * PANASONIC_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
207
208 #define RECS80_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
209 #define RECS80_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
210 #define RECS80_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
211 #define RECS80_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
212 #define RECS80_PULSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
213 #define RECS80_PULSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
214 #define RECS80_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
215 #define RECS80_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
216 #define RECS80_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
217 #define RECS80_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
218
219 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1 // BOSE conflicts with RC5, so keep tolerance for RC5 minimal here:
220 #define RC5_START_BIT_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
221 #define RC5_START_BIT_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
222 #else
223 #define RC5_START_BIT_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
224 #define RC5_START_BIT_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
225 #endif
226
227 #define RC5_BIT_LEN_MIN                         ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
228 #define RC5_BIT_LEN_MAX                         ((uint_fast8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
229
230 #define RCII_START_BIT_PULSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
231 #define RCII_START_BIT_PULSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
232 #define RCII_START_BIT_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
233 #define RCII_START_BIT_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
234 #define RCII_START_BIT2_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT2_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
235 #define RCII_START_BIT2_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * RCII_START_BIT2_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
236
237 #define RCII_BIT_LEN_MIN                        ((uint_fast8_t)(F_INTERRUPTS * RCII_BIT_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
238 #define RCII_BIT_LEN                            ((uint_fast8_t)(F_INTERRUPTS * RCII_BIT_TIME))
239 #define RCII_BIT_LEN_MAX                        ((uint_fast8_t)(F_INTERRUPTS * RCII_BIT_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
240
241 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1 // BOSE conflicts with S100, so keep tolerance for S100 minimal here:
242 #define S100_START_BIT_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
243 #define S100_START_BIT_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
244 #else
245 #define S100_START_BIT_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
246 #define S100_START_BIT_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
247 #endif
248
249 #define S100_BIT_LEN_MIN                         ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
250 #define S100_BIT_LEN_MAX                         ((uint_fast8_t)(F_INTERRUPTS * S100_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
251
252 #define DENON_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
253 #define DENON_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
254 #define DENON_1_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
255 #define DENON_1_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
256 // RUWIDO (see t-home-mediareceiver-15kHz.txt) conflicts here with DENON
257 #define DENON_0_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
258 #define DENON_0_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
259 #define DENON_AUTO_REPETITION_PAUSE_LEN         ((uint_fast16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
260
261 #define THOMSON_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
262 #define THOMSON_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
263 #define THOMSON_1_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
264 #define THOMSON_1_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
265 #define THOMSON_0_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
266 #define THOMSON_0_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
267
268 #define RC6_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
269 #define RC6_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
270 #define RC6_START_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
271 #define RC6_START_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
272 #define RC6_TOGGLE_BIT_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
273 #define RC6_TOGGLE_BIT_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
274 #define RC6_BIT_PULSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
275 #define RC6_BIT_PULSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_60 + 0.5) + 1)       // pulses: 300 - 800
276 #define RC6_BIT_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
277 #define RC6_BIT_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)       // pauses: 300 - 600
278
279 #define RECS80EXT_START_BIT_PULSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
280 #define RECS80EXT_START_BIT_PULSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
281 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
282 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
283 #define RECS80EXT_PULSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
284 #define RECS80EXT_PULSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
285 #define RECS80EXT_1_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
286 #define RECS80EXT_1_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
287 #define RECS80EXT_0_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
288 #define RECS80EXT_0_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
289
290 #define NUBERT_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
291 #define NUBERT_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
292 #define NUBERT_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
293 #define NUBERT_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
294 #define NUBERT_1_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
295 #define NUBERT_1_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
296 #define NUBERT_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
297 #define NUBERT_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
298 #define NUBERT_0_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
299 #define NUBERT_0_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
300 #define NUBERT_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
301 #define NUBERT_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
302
303 #define FAN_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * FAN_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
304 #define FAN_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * FAN_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
305 #define FAN_START_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * FAN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
306 #define FAN_START_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * FAN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
307 #define FAN_1_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FAN_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
308 #define FAN_1_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FAN_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
309 #define FAN_1_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FAN_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
310 #define FAN_1_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FAN_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
311 #define FAN_0_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FAN_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
312 #define FAN_0_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FAN_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
313 #define FAN_0_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FAN_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
314 #define FAN_0_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FAN_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
315
316 #define SPEAKER_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
317 #define SPEAKER_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
318 #define SPEAKER_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
319 #define SPEAKER_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
320 #define SPEAKER_1_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
321 #define SPEAKER_1_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
322 #define SPEAKER_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
323 #define SPEAKER_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
324 #define SPEAKER_0_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
325 #define SPEAKER_0_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
326 #define SPEAKER_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
327 #define SPEAKER_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * SPEAKER_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
328
329 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
330 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
331 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
332 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
333 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
334 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
335 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
336 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
337 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
338 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
339 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
340 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX   ((PAUSE_LEN)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // value must be below IRMP_TIMEOUT
341 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
342 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
343 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
344 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX   ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
345 #define BANG_OLUFSEN_PULSE_LEN_MIN              ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
346 #define BANG_OLUFSEN_PULSE_LEN_MAX              ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
347 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
348 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
349 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
350 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
351 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
352 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
353 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN  ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
354 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX  ((uint_fast8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
355
356 #define IR60_TIMEOUT_LEN                        ((uint_fast8_t)(F_INTERRUPTS * IR60_TIMEOUT_TIME * 0.5))
357 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN    ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
358 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX    ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
359 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
360 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
361 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN    ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1)
362 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX    ((uint_fast8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
363
364 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
365 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
366 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN       ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
367 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX       ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
368 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
369 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
370 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
371 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
372
373 #define FDC_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)   // 5%: avoid conflict with NETBOX
374 #define FDC_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5))
375 #define FDC_START_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
376 #define FDC_START_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
377 #define FDC_PULSE_LEN_MIN                       ((uint_fast8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
378 #define FDC_PULSE_LEN_MAX                       ((uint_fast8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
379 #define FDC_1_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
380 #define FDC_1_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
381 #if 0
382 #define FDC_0_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)   // could be negative: 255
383 #else
384 #define FDC_0_PAUSE_LEN_MIN                     (1)                                                                         // simply use 1
385 #endif
386 #define FDC_0_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
387
388 #define RCCAR_START_BIT_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
389 #define RCCAR_START_BIT_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
390 #define RCCAR_START_BIT_PAUSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
391 #define RCCAR_START_BIT_PAUSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
392 #define RCCAR_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
393 #define RCCAR_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
394 #define RCCAR_1_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
395 #define RCCAR_1_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
396 #define RCCAR_0_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
397 #define RCCAR_0_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
398
399 #define JVC_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
400 #define JVC_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
401 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MIN_TOLERANCE_40 + 0.5) - 1)  // HACK!
402 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MAX_TOLERANCE_70 + 0.5) - 1)  // HACK!
403 #define JVC_PULSE_LEN_MIN                       ((uint_fast8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
404 #define JVC_PULSE_LEN_MAX                       ((uint_fast8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
405 #define JVC_1_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
406 #define JVC_1_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
407 #define JVC_0_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
408 #define JVC_0_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
409 // autodetect JVC repetition frame within 50 msec:
410 #define JVC_FRAME_REPEAT_PAUSE_LEN_MAX          (uint_fast16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
411
412 #define NIKON_START_BIT_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
413 #define NIKON_START_BIT_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
414 #define NIKON_START_BIT_PAUSE_LEN_MIN           ((uint_fast16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
415 #define NIKON_START_BIT_PAUSE_LEN_MAX           ((uint_fast16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
416 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MIN    ((uint_fast8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
417 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MAX    ((uint_fast8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
418 #define NIKON_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
419 #define NIKON_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
420 #define NIKON_1_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
421 #define NIKON_1_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
422 #define NIKON_0_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
423 #define NIKON_0_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
424 #define NIKON_FRAME_REPEAT_PAUSE_LEN_MAX        (uint_fast16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
425
426 #define KATHREIN_START_BIT_PULSE_LEN_MIN        ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
427 #define KATHREIN_START_BIT_PULSE_LEN_MAX        ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
428 #define KATHREIN_START_BIT_PAUSE_LEN_MIN        ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
429 #define KATHREIN_START_BIT_PAUSE_LEN_MAX        ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
430 #define KATHREIN_1_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
431 #define KATHREIN_1_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
432 #define KATHREIN_1_PAUSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
433 #define KATHREIN_1_PAUSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
434 #define KATHREIN_0_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
435 #define KATHREIN_0_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
436 #define KATHREIN_0_PAUSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
437 #define KATHREIN_0_PAUSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
438 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
439 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
440
441 #define NETBOX_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
442 #define NETBOX_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
443 #define NETBOX_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
444 #define NETBOX_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
445 #define NETBOX_PULSE_LEN                        ((uint_fast8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME))
446 #define NETBOX_PAUSE_LEN                        ((uint_fast8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME))
447 #define NETBOX_PULSE_REST_LEN                   ((uint_fast8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4))
448 #define NETBOX_PAUSE_REST_LEN                   ((uint_fast8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4))
449
450 #define LEGO_START_BIT_PULSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
451 #define LEGO_START_BIT_PULSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
452 #define LEGO_START_BIT_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
453 #define LEGO_START_BIT_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
454 #define LEGO_PULSE_LEN_MIN                      ((uint_fast8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
455 #define LEGO_PULSE_LEN_MAX                      ((uint_fast8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
456 #define LEGO_1_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
457 #define LEGO_1_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
458 #define LEGO_0_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
459 #define LEGO_0_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
460
461 #define IRMP16_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * IRMP16_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
462 #define IRMP16_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * IRMP16_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
463 #define IRMP16_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * IRMP16_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
464 #define IRMP16_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * IRMP16_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
465 #define IRMP16_PULSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * IRMP16_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
466 #define IRMP16_PULSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * IRMP16_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
467 #define IRMP16_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * IRMP16_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
468 #define IRMP16_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * IRMP16_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
469 #define IRMP16_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * IRMP16_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
470 #define IRMP16_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * IRMP16_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
471
472 #define GREE_START_BIT_PULSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * GREE_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
473 #define GREE_START_BIT_PULSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * GREE_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
474 #define GREE_START_BIT_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * GREE_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
475 #define GREE_START_BIT_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * GREE_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
476 #define GREE_PULSE_LEN_MIN                      ((uint_fast8_t)(F_INTERRUPTS * GREE_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
477 #define GREE_PULSE_LEN_MAX                      ((uint_fast8_t)(F_INTERRUPTS * GREE_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
478 #define GREE_1_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * GREE_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
479 #define GREE_1_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * GREE_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
480 #define GREE_0_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * GREE_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
481 #define GREE_0_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * GREE_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
482
483 #define BOSE_START_BIT_PULSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * BOSE_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
484 #define BOSE_START_BIT_PULSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * BOSE_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
485 #define BOSE_START_BIT_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * BOSE_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
486 #define BOSE_START_BIT_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * BOSE_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
487 #define BOSE_PULSE_LEN_MIN                       ((uint_fast8_t)(F_INTERRUPTS * BOSE_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
488 #define BOSE_PULSE_LEN_MAX                       ((uint_fast8_t)(F_INTERRUPTS * BOSE_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
489 #define BOSE_1_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * BOSE_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
490 #define BOSE_1_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * BOSE_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
491 #define BOSE_0_PAUSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * BOSE_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
492 #define BOSE_0_PAUSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * BOSE_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
493 #define BOSE_FRAME_REPEAT_PAUSE_LEN_MAX          (uint_fast16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)
494
495 #define A1TVBOX_START_BIT_PULSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
496 #define A1TVBOX_START_BIT_PULSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
497 #define A1TVBOX_START_BIT_PAUSE_LEN_MIN         ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
498 #define A1TVBOX_START_BIT_PAUSE_LEN_MAX         ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
499 #define A1TVBOX_BIT_PULSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
500 #define A1TVBOX_BIT_PULSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
501 #define A1TVBOX_BIT_PAUSE_LEN_MIN               ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
502 #define A1TVBOX_BIT_PAUSE_LEN_MAX               ((uint_fast8_t)(F_INTERRUPTS * A1TVBOX_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
503
504 #define MERLIN_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
505 #define MERLIN_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * MERLIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
506 #define MERLIN_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
507 #define MERLIN_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * MERLIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
508 #define MERLIN_BIT_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * MERLIN_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
509 #define MERLIN_BIT_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * MERLIN_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
510 #define MERLIN_BIT_PAUSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * MERLIN_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
511 #define MERLIN_BIT_PAUSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * MERLIN_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
512
513 #define ORTEK_START_BIT_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * ORTEK_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
514 #define ORTEK_START_BIT_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * ORTEK_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
515 #define ORTEK_START_BIT_PAUSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * ORTEK_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
516 #define ORTEK_START_BIT_PAUSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * ORTEK_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
517 #define ORTEK_BIT_PULSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
518 #define ORTEK_BIT_PULSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
519 #define ORTEK_BIT_PAUSE_LEN_MIN                 ((uint_fast8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
520 #define ORTEK_BIT_PAUSE_LEN_MAX                 ((uint_fast8_t)(F_INTERRUPTS * ORTEK_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
521
522 #define TELEFUNKEN_START_BIT_PULSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
523 #define TELEFUNKEN_START_BIT_PULSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
524 #define TELEFUNKEN_START_BIT_PAUSE_LEN_MIN      ((uint_fast8_t)(F_INTERRUPTS * (TELEFUNKEN_START_BIT_PAUSE_TIME) * MIN_TOLERANCE_10 + 0.5) - 1)
525 #define TELEFUNKEN_START_BIT_PAUSE_LEN_MAX      ((uint_fast8_t)(F_INTERRUPTS * (TELEFUNKEN_START_BIT_PAUSE_TIME) * MAX_TOLERANCE_10 + 0.5) - 1)
526 #define TELEFUNKEN_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
527 #define TELEFUNKEN_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
528 #define TELEFUNKEN_1_PAUSE_LEN_MIN              ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
529 #define TELEFUNKEN_1_PAUSE_LEN_MAX              ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
530 #define TELEFUNKEN_0_PAUSE_LEN_MIN              ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
531 #define TELEFUNKEN_0_PAUSE_LEN_MAX              ((uint_fast8_t)(F_INTERRUPTS * TELEFUNKEN_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
532 // autodetect TELEFUNKEN repetition frame within 50 msec:
533 // #define TELEFUNKEN_FRAME_REPEAT_PAUSE_LEN_MAX   (uint_fast16_t)(F_INTERRUPTS * TELEFUNKEN_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
534
535 #define ROOMBA_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
536 #define ROOMBA_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
537 #define ROOMBA_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
538 #define ROOMBA_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
539 #define ROOMBA_1_PAUSE_LEN_EXACT                ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME + 0.5))
540 #define ROOMBA_1_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
541 #define ROOMBA_1_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
542 #define ROOMBA_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
543 #define ROOMBA_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
544 #define ROOMBA_0_PAUSE_LEN                      ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME))
545 #define ROOMBA_0_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
546 #define ROOMBA_0_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
547 #define ROOMBA_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
548 #define ROOMBA_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * ROOMBA_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
549
550 #define RCMM32_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RCMM32_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
551 #define RCMM32_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RCMM32_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
552 #define RCMM32_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RCMM32_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
553 #define RCMM32_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RCMM32_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
554 #define RCMM32_BIT_PULSE_LEN_MIN                ((uint_fast8_t)(F_INTERRUPTS * RCMM32_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
555 #define RCMM32_BIT_PULSE_LEN_MAX                ((uint_fast8_t)(F_INTERRUPTS * RCMM32_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
556 #define RCMM32_BIT_00_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_00_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
557 #define RCMM32_BIT_00_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_00_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
558 #define RCMM32_BIT_01_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_01_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
559 #define RCMM32_BIT_01_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_01_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
560 #define RCMM32_BIT_10_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_10_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
561 #define RCMM32_BIT_10_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_10_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
562 #define RCMM32_BIT_11_PAUSE_LEN_MIN             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_11_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
563 #define RCMM32_BIT_11_PAUSE_LEN_MAX             ((uint_fast8_t)(F_INTERRUPTS * RCMM32_11_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
564
565 #define PENTAX_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * PENTAX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
566 #define PENTAX_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * PENTAX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
567 #define PENTAX_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * PENTAX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
568 #define PENTAX_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * PENTAX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
569 #define PENTAX_1_PAUSE_LEN_EXACT                ((uint_fast8_t)(F_INTERRUPTS * PENTAX_1_PAUSE_TIME + 0.5))
570 #define PENTAX_PULSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * PENTAX_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
571 #define PENTAX_PULSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * PENTAX_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
572 #define PENTAX_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * PENTAX_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
573 #define PENTAX_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * PENTAX_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
574 #define PENTAX_0_PAUSE_LEN                      ((uint_fast8_t)(F_INTERRUPTS * PENTAX_0_PAUSE_TIME))
575 #define PENTAX_PULSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * PENTAX_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
576 #define PENTAX_PULSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * PENTAX_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
577 #define PENTAX_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * PENTAX_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
578 #define PENTAX_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * PENTAX_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
579
580 #define ACP24_START_BIT_PULSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * ACP24_START_BIT_PULSE_TIME * MIN_TOLERANCE_15 + 0.5) - 1)
581 #define ACP24_START_BIT_PULSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * ACP24_START_BIT_PULSE_TIME * MAX_TOLERANCE_15 + 0.5) + 1)
582 #define ACP24_START_BIT_PAUSE_LEN_MIN           ((uint_fast8_t)(F_INTERRUPTS * ACP24_START_BIT_PAUSE_TIME * MIN_TOLERANCE_15 + 0.5) - 1)
583 #define ACP24_START_BIT_PAUSE_LEN_MAX           ((uint_fast8_t)(F_INTERRUPTS * ACP24_START_BIT_PAUSE_TIME * MAX_TOLERANCE_15 + 0.5) + 1)
584 #define ACP24_PULSE_LEN_MIN                     ((uint_fast8_t)(F_INTERRUPTS * ACP24_PULSE_TIME * MIN_TOLERANCE_15 + 0.5) - 1)
585 #define ACP24_PULSE_LEN_MAX                     ((uint_fast8_t)(F_INTERRUPTS * ACP24_PULSE_TIME * MAX_TOLERANCE_15 + 0.5) + 1)
586 #define ACP24_1_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * ACP24_1_PAUSE_TIME * MIN_TOLERANCE_15 + 0.5) - 1)
587 #define ACP24_1_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * ACP24_1_PAUSE_TIME * MAX_TOLERANCE_15 + 0.5) + 1)
588 #define ACP24_0_PAUSE_LEN_MIN                   ((uint_fast8_t)(F_INTERRUPTS * ACP24_0_PAUSE_TIME * MIN_TOLERANCE_15 + 0.5) - 1)
589 #define ACP24_0_PAUSE_LEN_MAX                   ((uint_fast8_t)(F_INTERRUPTS * ACP24_0_PAUSE_TIME * MAX_TOLERANCE_15 + 0.5) + 1)
590
591 #define METZ_START_BIT_PULSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * METZ_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
592 #define METZ_START_BIT_PULSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * METZ_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
593 #define METZ_START_BIT_PAUSE_LEN_MIN            ((uint_fast8_t)(F_INTERRUPTS * METZ_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
594 #define METZ_START_BIT_PAUSE_LEN_MAX            ((uint_fast8_t)(F_INTERRUPTS * METZ_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
595 #define METZ_PULSE_LEN_MIN                      ((uint_fast8_t)(F_INTERRUPTS * METZ_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
596 #define METZ_PULSE_LEN_MAX                      ((uint_fast8_t)(F_INTERRUPTS * METZ_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
597 #define METZ_1_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * METZ_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
598 #define METZ_1_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * METZ_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
599 #define METZ_0_PAUSE_LEN_MIN                    ((uint_fast8_t)(F_INTERRUPTS * METZ_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
600 #define METZ_0_PAUSE_LEN_MAX                    ((uint_fast8_t)(F_INTERRUPTS * METZ_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
601 #define METZ_FRAME_REPEAT_PAUSE_LEN_MAX         (uint_fast16_t)(F_INTERRUPTS * METZ_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
602
603 #define RADIO1_START_BIT_PULSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RADIO1_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
604 #define RADIO1_START_BIT_PULSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RADIO1_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
605 #define RADIO1_START_BIT_PAUSE_LEN_MIN          ((uint_fast8_t)(F_INTERRUPTS * RADIO1_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
606 #define RADIO1_START_BIT_PAUSE_LEN_MAX          ((uint_fast8_t)(F_INTERRUPTS * RADIO1_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
607 #define RADIO1_1_PAUSE_LEN_EXACT                ((uint_fast8_t)(F_INTERRUPTS * RADIO1_1_PAUSE_TIME + 0.5))
608 #define RADIO1_1_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
609 #define RADIO1_1_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
610 #define RADIO1_1_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
611 #define RADIO1_1_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
612 #define RADIO1_0_PAUSE_LEN                      ((uint_fast8_t)(F_INTERRUPTS * RADIO1_0_PAUSE_TIME))
613 #define RADIO1_0_PULSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
614 #define RADIO1_0_PULSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
615 #define RADIO1_0_PAUSE_LEN_MIN                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
616 #define RADIO1_0_PAUSE_LEN_MAX                  ((uint_fast8_t)(F_INTERRUPTS * RADIO1_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
617
618 #define AUTO_FRAME_REPETITION_LEN               (uint_fast16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5)       // use uint_fast16_t!
619
620 #ifdef ANALYZE
621 #  define ANALYZE_PUTCHAR(a)                    { if (! silent)             { putchar (a);          } }
622 #  define ANALYZE_ONLY_NORMAL_PUTCHAR(a)        { if (! silent && !verbose) { putchar (a);          } }
623 #  define ANALYZE_PRINTF(...)                   { if (verbose)              { printf (__VA_ARGS__); } }
624 #  define ANALYZE_ONLY_NORMAL_PRINTF(...)       { if (! silent && !verbose) { printf (__VA_ARGS__); } }
625 #  define ANALYZE_NEWLINE()                     { if (verbose)              { putchar ('\n');       } }
626 static int                                      silent;
627 static int                                      time_counter;
628 static int                                      verbose;
629
630 /*******************************                not every PIC compiler knows variadic macros :-(
631 #else
632 #  define ANALYZE_PUTCHAR(a)
633 #  define ANALYZE_ONLY_NORMAL_PUTCHAR(a)
634 #  define ANALYZE_PRINTF(...)
635 #  define ANALYZE_ONLY_NORMAL_PRINTF(...)
636 #  endif
637 #  define ANALYZE_NEWLINE()
638 *********************************/
639 #endif
640
641 #if IRMP_USE_CALLBACK == 1
642 static void                                     (*irmp_callback_ptr) (uint_fast8_t);
643 #endif // IRMP_USE_CALLBACK == 1
644
645 #define PARITY_CHECK_OK                         1
646 #define PARITY_CHECK_FAILED                     0
647
648 /*---------------------------------------------------------------------------------------------------------------------------------------------------
649  *  Protocol names
650  *---------------------------------------------------------------------------------------------------------------------------------------------------
651  */
652 #if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1
653 static const char proto_unknown[]       PROGMEM = "UNKNOWN";
654 static const char proto_sircs[]         PROGMEM = "SIRCS";
655 static const char proto_nec[]           PROGMEM = "NEC";
656 static const char proto_samsung[]       PROGMEM = "SAMSUNG";
657 static const char proto_matsushita[]    PROGMEM = "MATSUSH";
658 static const char proto_kaseikyo[]      PROGMEM = "KASEIKYO";
659 static const char proto_recs80[]        PROGMEM = "RECS80";
660 static const char proto_rc5[]           PROGMEM = "RC5";
661 static const char proto_denon[]         PROGMEM = "DENON";
662 static const char proto_rc6[]           PROGMEM = "RC6";
663 static const char proto_samsung32[]     PROGMEM = "SAMSG32";
664 static const char proto_apple[]         PROGMEM = "APPLE";
665 static const char proto_recs80ext[]     PROGMEM = "RECS80EX";
666 static const char proto_nubert[]        PROGMEM = "NUBERT";
667 static const char proto_bang_olufsen[]  PROGMEM = "BANG OLU";
668 static const char proto_grundig[]       PROGMEM = "GRUNDIG";
669 static const char proto_nokia[]         PROGMEM = "NOKIA";
670 static const char proto_siemens[]       PROGMEM = "SIEMENS";
671 static const char proto_fdc[]           PROGMEM = "FDC";
672 static const char proto_rccar[]         PROGMEM = "RCCAR";
673 static const char proto_jvc[]           PROGMEM = "JVC";
674 static const char proto_rc6a[]          PROGMEM = "RC6A";
675 static const char proto_nikon[]         PROGMEM = "NIKON";
676 static const char proto_ruwido[]        PROGMEM = "RUWIDO";
677 static const char proto_ir60[]          PROGMEM = "IR60";
678 static const char proto_kathrein[]      PROGMEM = "KATHREIN";
679 static const char proto_netbox[]        PROGMEM = "NETBOX";
680 static const char proto_nec16[]         PROGMEM = "NEC16";
681 static const char proto_nec42[]         PROGMEM = "NEC42";
682 static const char proto_lego[]          PROGMEM = "LEGO";
683 static const char proto_thomson[]       PROGMEM = "THOMSON";
684 static const char proto_bose[]          PROGMEM = "BOSE";
685 static const char proto_a1tvbox[]       PROGMEM = "A1TVBOX";
686 static const char proto_ortek[]         PROGMEM = "ORTEK";
687 static const char proto_telefunken[]    PROGMEM = "TELEFUNKEN";
688 static const char proto_roomba[]        PROGMEM = "ROOMBA";
689 static const char proto_rcmm32[]        PROGMEM = "RCMM32";
690 static const char proto_rcmm24[]        PROGMEM = "RCMM24";
691 static const char proto_rcmm12[]        PROGMEM = "RCMM12";
692 static const char proto_speaker[]       PROGMEM = "SPEAKER";
693 static const char proto_lgair[]         PROGMEM = "LGAIR";
694 static const char proto_samsung48[]     PROGMEM = "SAMSG48";
695 static const char proto_merlin[]        PROGMEM = "MERLIN";
696 static const char proto_pentax[]        PROGMEM = "PENTAX";
697 static const char proto_fan[]           PROGMEM = "FAN";
698 static const char proto_s100[]          PROGMEM = "S100";
699 static const char proto_acp24[]         PROGMEM = "ACP24";
700 static const char proto_technics[]      PROGMEM = "TECHNICS";
701 static const char proto_panasonic[]     PROGMEM = "PANASONIC";
702 static const char proto_mitsu_heavy[]   PROGMEM = "MITSU_HEAVY";
703 static const char proto_vincent[]       PROGMEM = "VINCENT";
704 static const char proto_samsungah[]     PROGMEM = "SAMSUNGAH";
705 static const char proto_irmp16[]        PROGMEM = "IRMP16";
706 static const char proto_gree[]          PROGMEM = "GREE";
707 static const char proto_rcii[]          PROGMEM = "RCII";
708 static const char proto_metz[]          PROGMEM = "METZ";
709 static const char proto_onkyo[]         PROGMEM = "ONKYO";
710
711 static const char proto_radio1[]        PROGMEM = "RADIO1";
712
713 const char * const
714 irmp_protocol_names[IRMP_N_PROTOCOLS + 1] PROGMEM =
715 {
716     proto_unknown,
717     proto_sircs,
718     proto_nec,
719     proto_samsung,
720     proto_matsushita,
721     proto_kaseikyo,
722     proto_recs80,
723     proto_rc5,
724     proto_denon,
725     proto_rc6,
726     proto_samsung32,
727     proto_apple,
728     proto_recs80ext,
729     proto_nubert,
730     proto_bang_olufsen,
731     proto_grundig,
732     proto_nokia,
733     proto_siemens,
734     proto_fdc,
735     proto_rccar,
736     proto_jvc,
737     proto_rc6a,
738     proto_nikon,
739     proto_ruwido,
740     proto_ir60,
741     proto_kathrein,
742     proto_netbox,
743     proto_nec16,
744     proto_nec42,
745     proto_lego,
746     proto_thomson,
747     proto_bose,
748     proto_a1tvbox,
749     proto_ortek,
750     proto_telefunken,
751     proto_roomba,
752     proto_rcmm32,
753     proto_rcmm24,
754     proto_rcmm12,
755     proto_speaker,
756     proto_lgair,
757     proto_samsung48,
758     proto_merlin,
759     proto_pentax,
760     proto_fan,
761     proto_s100,
762     proto_acp24,
763     proto_technics,
764     proto_panasonic,
765     proto_mitsu_heavy,
766     proto_vincent,
767     proto_samsungah,
768     proto_irmp16,
769     proto_gree,
770     proto_rcii,
771     proto_metz,
772     proto_onkyo,
773
774     proto_radio1
775 };
776
777 #endif
778
779 /*---------------------------------------------------------------------------------------------------------------------------------------------------
780  *  Logging
781  *---------------------------------------------------------------------------------------------------------------------------------------------------
782  */
783 #if IRMP_LOGGING == 1                                                   // logging via UART
784
785 #if defined(ARM_STM32F4XX)
786 #  define  STM32_GPIO_CLOCK   RCC_AHB1Periph_GPIOA                      // UART2 on PA2
787 #  define  STM32_UART_CLOCK   RCC_APB1Periph_USART2
788 #  define  STM32_GPIO_PORT    GPIOA
789 #  define  STM32_GPIO_PIN     GPIO_Pin_2
790 #  define  STM32_GPIO_SOURCE  GPIO_PinSource2
791 #  define  STM32_UART_AF      GPIO_AF_USART2
792 #  define  STM32_UART_COM     USART2
793 #  define  STM32_UART_BAUD    115200                                    // 115200 Baud
794 #  include "stm32f4xx_usart.h"
795 #elif defined(ARM_STM32F10X)
796 #  define  STM32_UART_COM     USART3                                    // UART3 on PB10
797 #elif defined(ARDUINO)                                                  // Arduino Serial implementation
798 #  if defined(USB_SERIAL)
799 #    include "usb_serial.h"
800 #  else
801 #    error USB_SERIAL not defined in ARDUINO Environment
802 #  endif
803 #elif defined(_CHIBIOS_HAL_)                                            // ChibiOS HAL
804 #  if IRMP_EXT_LOGGING == 1
805 #    error IRMP_EXT_LOGGING not implemented for ChibiOS HAL, use regular logging instead
806 #  endif
807 #else
808 #  if IRMP_EXT_LOGGING == 1                                             // use external logging
809 #    include "irmpextlog.h"
810 #  else                                                                 // normal UART log (IRMP_EXT_LOGGING == 0)
811 #    define BAUD                                    9600L
812 #  ifndef UNIX_OR_WINDOWS
813 #    include <util/setbaud.h>
814 #  endif
815
816 #ifdef UBRR0H
817
818 #define UART0_UBRRH                             UBRR0H
819 #define UART0_UBRRL                             UBRR0L
820 #define UART0_UCSRA                             UCSR0A
821 #define UART0_UCSRB                             UCSR0B
822 #define UART0_UCSRC                             UCSR0C
823 #define UART0_UDRE_BIT_VALUE                    (1<<UDRE0)
824 #define UART0_UCSZ1_BIT_VALUE                   (1<<UCSZ01)
825 #define UART0_UCSZ0_BIT_VALUE                   (1<<UCSZ00)
826 #ifdef URSEL0
827 #define UART0_URSEL_BIT_VALUE                   (1<<URSEL0)
828 #else
829 #define UART0_URSEL_BIT_VALUE                   (0)
830 #endif
831 #define UART0_TXEN_BIT_VALUE                    (1<<TXEN0)
832 #define UART0_UDR                               UDR0
833 #define UART0_U2X                               U2X0
834
835 #else
836
837 #define UART0_UBRRH                             UBRRH
838 #define UART0_UBRRL                             UBRRL
839 #define UART0_UCSRA                             UCSRA
840 #define UART0_UCSRB                             UCSRB
841 #define UART0_UCSRC                             UCSRC
842 #define UART0_UDRE_BIT_VALUE                    (1<<UDRE)
843 #define UART0_UCSZ1_BIT_VALUE                   (1<<UCSZ1)
844 #define UART0_UCSZ0_BIT_VALUE                   (1<<UCSZ0)
845 #ifdef URSEL
846 #define UART0_URSEL_BIT_VALUE                   (1<<URSEL)
847 #else
848 #define UART0_URSEL_BIT_VALUE                   (0)
849 #endif
850 #define UART0_TXEN_BIT_VALUE                    (1<<TXEN)
851 #define UART0_UDR                               UDR
852 #define UART0_U2X                               U2X
853
854 #endif //UBRR0H
855 #endif //IRMP_EXT_LOGGING
856 #endif //ARM_STM32F4XX
857
858 /*---------------------------------------------------------------------------------------------------------------------------------------------------
859  *  Initialize  UART
860  *  @details  Initializes UART
861  *---------------------------------------------------------------------------------------------------------------------------------------------------
862  */
863 void
864 irmp_uart_init (void)
865 {
866 #ifndef UNIX_OR_WINDOWS
867 #if defined(ARM_STM32F4XX)
868     GPIO_InitTypeDef GPIO_InitStructure;
869     USART_InitTypeDef USART_InitStructure;
870
871     // Clock enable vom TX Pin
872     RCC_AHB1PeriphClockCmd(STM32_GPIO_CLOCK, ENABLE);
873
874     // Clock enable der UART
875     RCC_APB1PeriphClockCmd(STM32_UART_CLOCK, ENABLE);
876
877     // UART Alternative-Funktion mit dem IO-Pin verbinden
878     GPIO_PinAFConfig(STM32_GPIO_PORT,STM32_GPIO_SOURCE,STM32_UART_AF);
879
880     // UART als Alternative-Funktion mit PushPull
881     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
882     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
883     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
884     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
885
886     // TX-Pin
887     GPIO_InitStructure.GPIO_Pin = STM32_GPIO_PIN;
888     GPIO_Init(STM32_GPIO_PORT, &GPIO_InitStructure);
889
890     // Oversampling
891     USART_OverSampling8Cmd(STM32_UART_COM, ENABLE);
892
893     // init baud rate, 8 data bits, 1 stop bit, no parity, no RTS+CTS
894     USART_InitStructure.USART_BaudRate = STM32_UART_BAUD;
895     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
896     USART_InitStructure.USART_StopBits = USART_StopBits_1;
897     USART_InitStructure.USART_Parity = USART_Parity_No;
898     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
899     USART_InitStructure.USART_Mode = USART_Mode_Tx;
900     USART_Init(STM32_UART_COM, &USART_InitStructure);
901
902     // UART enable
903     USART_Cmd(STM32_UART_COM, ENABLE);
904
905 #elif defined(ARM_STM32F10X)
906     GPIO_InitTypeDef GPIO_InitStructure;
907     USART_InitTypeDef USART_InitStructure;
908
909     // Clock enable vom TX Pin
910     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // UART3 an PB10
911
912     // Clock enable der UART
913     RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
914
915     // UART als Alternative-Funktion mit PushPull
916     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
917     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
918
919     // TX-Pin
920     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
921     GPIO_Init(GPIOB, &GPIO_InitStructure);
922
923     // Oversampling
924     USART_OverSampling8Cmd(STM32_UART_COM, ENABLE);
925
926     // init baud rate, 8 data bits, 1 stop bit, no parity, no RTS+CTS
927     USART_InitStructure.USART_BaudRate = 115200;
928     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
929     USART_InitStructure.USART_StopBits = USART_StopBits_1;
930     USART_InitStructure.USART_Parity = USART_Parity_No;
931     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
932     USART_InitStructure.USART_Mode = USART_Mode_Tx;
933     USART_Init(STM32_UART_COM, &USART_InitStructure);
934
935     // UART enable
936     USART_Cmd(STM32_UART_COM, ENABLE);
937
938 #elif defined(ARDUINO)
939     // we use the Arduino Serial Imlementation
940     // you have to call Serial.begin(SER_BAUD); in Arduino setup() function
941
942 #elif defined (__AVR_XMEGA__)
943
944     PMIC.CTRL |= PMIC_HILVLEN_bm;
945
946     USARTC1.BAUDCTRLB = 0;
947     USARTC1.BAUDCTRLA = F_CPU / 153600 - 1;
948     USARTC1.CTRLA = USART_RXCINTLVL_HI_gc;                                                          // high INT level (receive)
949     USARTC1.CTRLB = USART_TXEN_bm | USART_RXEN_bm;                                                  // activated RX and TX
950     USARTC1.CTRLC = USART_CHSIZE_8BIT_gc;                                                           // 8 Bit
951     PORTC.DIR |= (1<<7);                                                                            // TXD is output
952     PORTC.DIR &= ~(1<<6);
953
954 #elif defined (_CHIBIOS_HAL_)
955     // we use the SD interface for logging, no need to init that here
956
957 #else
958
959 #if (IRMP_EXT_LOGGING == 0)                                                                         // use UART
960     UART0_UBRRH = UBRRH_VALUE;                                                                      // set baud rate
961     UART0_UBRRL = UBRRL_VALUE;
962
963 #if USE_2X
964     UART0_UCSRA |= (1<<UART0_U2X);
965 #else
966     UART0_UCSRA &= ~(1<<UART0_U2X);
967 #endif
968
969     UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;
970     UART0_UCSRB |= UART0_TXEN_BIT_VALUE;                                                            // enable UART TX
971 #else                                                                                               // other log method
972     initextlog();
973 #endif //IRMP_EXT_LOGGING
974 #endif //ARM_STM32F4XX
975 #endif // UNIX_OR_WINDOWS
976 }
977
978 /*---------------------------------------------------------------------------------------------------------------------------------------------------
979  *  Send character
980  *  @details  Sends character
981  *  @param    ch character to be transmitted
982  *---------------------------------------------------------------------------------------------------------------------------------------------------
983  */
984 void
985 irmp_uart_putc (unsigned char ch)
986 {
987 #ifndef UNIX_OR_WINDOWS
988 #if defined(ARM_STM32F4XX) || defined(ARM_STM32F10X)
989     // warten bis altes Byte gesendet wurde
990     while (USART_GetFlagStatus(STM32_UART_COM, USART_FLAG_TXE) == RESET)
991     {
992         ;
993     }
994
995     USART_SendData(STM32_UART_COM, ch);
996
997     if (ch == '\n')
998     {
999         while (USART_GetFlagStatus(STM32_UART_COM, USART_FLAG_TXE) == RESET);
1000         USART_SendData(STM32_UART_COM, '\r');
1001     }
1002
1003 #elif defined(ARDUINO)
1004     // we use the Arduino Serial Imlementation
1005     usb_serial_putchar(ch);
1006
1007 #elif defined(_CHIBIOS_HAL_)
1008     // use the SD interface from HAL, log to IRMP_LOGGING_SD which is defined in irmpconfig.h
1009     sdWriteI(&IRMP_LOGGING_SD,&ch,1);      // we are called from interrupt context, so use the ...I version of the function
1010
1011 #else
1012 #if (IRMP_EXT_LOGGING == 0)
1013
1014 #  if defined (__AVR_XMEGA__)
1015     while (!(USARTC1.STATUS & USART_DREIF_bm))
1016     {
1017         ;
1018     }
1019
1020     USARTC1.DATA = ch;
1021
1022 #  else // AVR_MEGA
1023     while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))
1024     {
1025         ;
1026     }
1027
1028     UART0_UDR = ch;
1029
1030 #  endif // __AVR_XMEGA__
1031
1032 #else
1033
1034     sendextlog(ch);                                                         // use external log
1035
1036 #endif // IRMP_EXT_LOGGING
1037 #endif // ARM_STM32F4XX
1038 #else
1039     fputc (ch, stderr);
1040 #endif // UNIX_OR_WINDOWS
1041 }
1042
1043 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1044  *  Log IR signal
1045  *---------------------------------------------------------------------------------------------------------------------------------------------------
1046  */
1047
1048 #define STARTCYCLES                       2                                 // min count of zeros before start of logging
1049 #define ENDBITS                        1000                                 // number of sequenced highbits to detect end
1050 #define DATALEN                         700                                 // log buffer size
1051
1052 static void
1053 irmp_log (uint_fast8_t val)
1054 {
1055     static uint8_t          buf[DATALEN];                                   // logging buffer
1056     static uint_fast16_t    buf_idx;                                        // index
1057     static uint_fast8_t     startcycles;                                    // current number of start-zeros
1058     static uint_fast16_t    cnt;                                            // counts sequenced highbits - to detect end
1059     static uint_fast8_t     last_val = 1;
1060
1061     if (! val && (startcycles < STARTCYCLES) && !buf_idx)                   // prevent that single random zeros init logging
1062     {
1063         startcycles++;
1064     }
1065     else
1066     {
1067         startcycles = 0;
1068
1069         if (! val || buf_idx != 0)                                          // start or continue logging on "0", "1" cannot init logging
1070         {
1071             if (last_val == val)
1072             {
1073                 cnt++;
1074
1075                 if (val && cnt > ENDBITS)                                   // if high received then look at log-stop condition
1076                 {                                                           // if stop condition is true, output on uart
1077                     uint_fast8_t     i8;
1078                     uint_fast16_t    i;
1079                     uint_fast16_t    j;
1080                     uint_fast8_t     v = '1';
1081                     uint_fast16_t    d;
1082
1083                     for (i8 = 0; i8 < STARTCYCLES; i8++)
1084                     {
1085                         irmp_uart_putc ('0');                               // the ignored starting zeros
1086                     }
1087
1088                     for (i = 0; i < buf_idx; i++)
1089                     {
1090                         d = buf[i];
1091
1092                         if (d == 0xff)
1093                         {
1094                             i++;
1095                             d = buf[i];
1096                             i++;
1097                             d |= ((uint_fast16_t) buf[i] << 8);
1098                         }
1099
1100                         for (j = 0; j < d; j++)
1101                         {
1102                             irmp_uart_putc (v);
1103                         }
1104
1105                         v = (v == '1') ? '0' : '1';
1106                     }
1107
1108                     for (i8 = 0; i8 < 20; i8++)
1109                     {
1110                         irmp_uart_putc ('1');
1111                     }
1112
1113                     irmp_uart_putc ('\n');
1114                     buf_idx = 0;
1115                     last_val = 1;
1116                     cnt = 0;
1117                 }
1118             }
1119             else if (buf_idx < DATALEN - 3)
1120             {
1121                 if (cnt >= 0xff)
1122                 {
1123                     buf[buf_idx++]  = 0xff;
1124                     buf[buf_idx++]  = (cnt & 0xff);
1125                     buf[buf_idx]    = (cnt >> 8);
1126                 }
1127                 else
1128                 {
1129                     buf[buf_idx] = cnt;
1130                 }
1131
1132                 buf_idx++;
1133                 cnt = 1;
1134                 last_val = val;
1135             }
1136         }
1137     }
1138 }
1139
1140 #else
1141 #define irmp_log(val)
1142 #endif //IRMP_LOGGING
1143
1144 typedef struct
1145 {
1146     uint_fast8_t    protocol;                                                // ir protocol
1147     uint_fast8_t    pulse_1_len_min;                                         // minimum length of pulse with bit value 1
1148     uint_fast8_t    pulse_1_len_max;                                         // maximum length of pulse with bit value 1
1149     uint_fast8_t    pause_1_len_min;                                         // minimum length of pause with bit value 1
1150     uint_fast8_t    pause_1_len_max;                                         // maximum length of pause with bit value 1
1151     uint_fast8_t    pulse_0_len_min;                                         // minimum length of pulse with bit value 0
1152     uint_fast8_t    pulse_0_len_max;                                         // maximum length of pulse with bit value 0
1153     uint_fast8_t    pause_0_len_min;                                         // minimum length of pause with bit value 0
1154     uint_fast8_t    pause_0_len_max;                                         // maximum length of pause with bit value 0
1155     uint_fast8_t    address_offset;                                          // address offset
1156     uint_fast8_t    address_end;                                             // end of address
1157     uint_fast8_t    command_offset;                                          // command offset
1158     uint_fast8_t    command_end;                                             // end of command
1159     uint_fast8_t    complete_len;                                            // complete length of frame
1160     uint_fast8_t    stop_bit;                                                // flag: frame has stop bit
1161     uint_fast8_t    lsb_first;                                               // flag: LSB first
1162     uint_fast8_t    flags;                                                   // some flags
1163 } IRMP_PARAMETER;
1164
1165 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1166
1167 static const PROGMEM IRMP_PARAMETER sircs_param =
1168 {
1169     IRMP_SIRCS_PROTOCOL,                                                // protocol:        ir protocol
1170     SIRCS_1_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1
1171     SIRCS_1_PULSE_LEN_MAX,                                              // pulse_1_len_max: maximum length of pulse with bit value 1
1172     SIRCS_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1173     SIRCS_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1174     SIRCS_0_PULSE_LEN_MIN,                                              // pulse_0_len_min: minimum length of pulse with bit value 0
1175     SIRCS_0_PULSE_LEN_MAX,                                              // pulse_0_len_max: maximum length of pulse with bit value 0
1176     SIRCS_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1177     SIRCS_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1178     SIRCS_ADDRESS_OFFSET,                                               // address_offset:  address offset
1179     SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN,                           // address_end:     end of address
1180     SIRCS_COMMAND_OFFSET,                                               // command_offset:  command offset
1181     SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN,                           // command_end:     end of command
1182     SIRCS_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1183     SIRCS_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
1184     SIRCS_LSB,                                                          // lsb_first:       flag: LSB first
1185     SIRCS_FLAGS                                                         // flags:           some flags
1186 };
1187
1188 #endif
1189
1190 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1191
1192 static const PROGMEM IRMP_PARAMETER nec_param =
1193 {
1194     IRMP_NEC_PROTOCOL,                                                  // protocol:        ir protocol
1195     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1
1196     NEC_PULSE_LEN_MAX,                                                  // pulse_1_len_max: maximum length of pulse with bit value 1
1197     NEC_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1198     NEC_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1199     NEC_PULSE_LEN_MIN,                                                  // pulse_0_len_min: minimum length of pulse with bit value 0
1200     NEC_PULSE_LEN_MAX,                                                  // pulse_0_len_max: maximum length of pulse with bit value 0
1201     NEC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1202     NEC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1203     NEC_ADDRESS_OFFSET,                                                 // address_offset:  address offset
1204     NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN,                               // address_end:     end of address
1205     NEC_COMMAND_OFFSET,                                                 // command_offset:  command offset
1206     NEC_COMMAND_OFFSET + NEC_COMMAND_LEN,                               // command_end:     end of command
1207     NEC_COMPLETE_DATA_LEN,                                              // complete_len:    complete length of frame
1208     NEC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1209     NEC_LSB,                                                            // lsb_first:       flag: LSB first
1210     NEC_FLAGS                                                           // flags:           some flags
1211 };
1212
1213 static const PROGMEM IRMP_PARAMETER nec_rep_param =
1214 {
1215     IRMP_NEC_PROTOCOL,                                                  // protocol:        ir protocol
1216     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1
1217     NEC_PULSE_LEN_MAX,                                                  // pulse_1_len_max: maximum length of pulse with bit value 1
1218     NEC_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1219     NEC_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1220     NEC_PULSE_LEN_MIN,                                                  // pulse_0_len_min: minimum length of pulse with bit value 0
1221     NEC_PULSE_LEN_MAX,                                                  // pulse_0_len_max: maximum length of pulse with bit value 0
1222     NEC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1223     NEC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1224     0,                                                                  // address_offset:  address offset
1225     0,                                                                  // address_end:     end of address
1226     0,                                                                  // command_offset:  command offset
1227     0,                                                                  // command_end:     end of command
1228     0,                                                                  // complete_len:    complete length of frame
1229     NEC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1230     NEC_LSB,                                                            // lsb_first:       flag: LSB first
1231     NEC_FLAGS                                                           // flags:           some flags
1232 };
1233
1234 #endif
1235
1236 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
1237
1238 static const PROGMEM IRMP_PARAMETER nec42_param =
1239 {
1240     IRMP_NEC42_PROTOCOL,                                                // protocol:        ir protocol
1241     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1
1242     NEC_PULSE_LEN_MAX,                                                  // pulse_1_len_max: maximum length of pulse with bit value 1
1243     NEC_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1244     NEC_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1245     NEC_PULSE_LEN_MIN,                                                  // pulse_0_len_min: minimum length of pulse with bit value 0
1246     NEC_PULSE_LEN_MAX,                                                  // pulse_0_len_max: maximum length of pulse with bit value 0
1247     NEC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1248     NEC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1249     NEC42_ADDRESS_OFFSET,                                               // address_offset:  address offset
1250     NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN,                           // address_end:     end of address
1251     NEC42_COMMAND_OFFSET,                                               // command_offset:  command offset
1252     NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN,                           // command_end:     end of command
1253     NEC42_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1254     NEC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1255     NEC_LSB,                                                            // lsb_first:       flag: LSB first
1256     NEC_FLAGS                                                           // flags:           some flags
1257 };
1258
1259 #endif
1260
1261 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
1262
1263 static const PROGMEM IRMP_PARAMETER lgair_param =
1264 {
1265     IRMP_LGAIR_PROTOCOL,                                                // protocol:        ir protocol
1266     NEC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1
1267     NEC_PULSE_LEN_MAX,                                                  // pulse_1_len_max: maximum length of pulse with bit value 1
1268     NEC_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1269     NEC_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1270     NEC_PULSE_LEN_MIN,                                                  // pulse_0_len_min: minimum length of pulse with bit value 0
1271     NEC_PULSE_LEN_MAX,                                                  // pulse_0_len_max: maximum length of pulse with bit value 0
1272     NEC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1273     NEC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1274     LGAIR_ADDRESS_OFFSET,                                               // address_offset:  address offset
1275     LGAIR_ADDRESS_OFFSET + LGAIR_ADDRESS_LEN,                           // address_end:     end of address
1276     LGAIR_COMMAND_OFFSET,                                               // command_offset:  command offset
1277     LGAIR_COMMAND_OFFSET + LGAIR_COMMAND_LEN,                           // command_end:     end of command
1278     LGAIR_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1279     NEC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1280     NEC_LSB,                                                            // lsb_first:       flag: LSB first
1281     NEC_FLAGS                                                           // flags:           some flags
1282 };
1283
1284 #endif
1285
1286 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1287
1288 static const PROGMEM IRMP_PARAMETER samsung_param =
1289 {
1290     IRMP_SAMSUNG_PROTOCOL,                                              // protocol:        ir protocol
1291     SAMSUNG_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1
1292     SAMSUNG_PULSE_LEN_MAX,                                              // pulse_1_len_max: maximum length of pulse with bit value 1
1293     SAMSUNG_1_PAUSE_LEN_MIN,                                            // pause_1_len_min: minimum length of pause with bit value 1
1294     SAMSUNG_1_PAUSE_LEN_MAX,                                            // pause_1_len_max: maximum length of pause with bit value 1
1295     SAMSUNG_PULSE_LEN_MIN,                                              // pulse_0_len_min: minimum length of pulse with bit value 0
1296     SAMSUNG_PULSE_LEN_MAX,                                              // pulse_0_len_max: maximum length of pulse with bit value 0
1297     SAMSUNG_0_PAUSE_LEN_MIN,                                            // pause_0_len_min: minimum length of pause with bit value 0
1298     SAMSUNG_0_PAUSE_LEN_MAX,                                            // pause_0_len_max: maximum length of pause with bit value 0
1299     SAMSUNG_ADDRESS_OFFSET,                                             // address_offset:  address offset
1300     SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN,                       // address_end:     end of address
1301     SAMSUNG_COMMAND_OFFSET,                                             // command_offset:  command offset
1302     SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN,                       // command_end:     end of command
1303     SAMSUNG_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame
1304     SAMSUNG_STOP_BIT,                                                   // stop_bit:        flag: frame has stop bit
1305     SAMSUNG_LSB,                                                        // lsb_first:       flag: LSB first
1306     SAMSUNG_FLAGS                                                       // flags:           some flags
1307 };
1308
1309 #endif
1310
1311 #if IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1
1312
1313 static const PROGMEM IRMP_PARAMETER samsungah_param =
1314 {
1315     IRMP_SAMSUNGAH_PROTOCOL,                                            // protocol:        ir protocol
1316     SAMSUNGAH_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1
1317     SAMSUNGAH_PULSE_LEN_MAX,                                            // pulse_1_len_max: maximum length of pulse with bit value 1
1318     SAMSUNGAH_1_PAUSE_LEN_MIN,                                          // pause_1_len_min: minimum length of pause with bit value 1
1319     SAMSUNGAH_1_PAUSE_LEN_MAX,                                          // pause_1_len_max: maximum length of pause with bit value 1
1320     SAMSUNGAH_PULSE_LEN_MIN,                                            // pulse_0_len_min: minimum length of pulse with bit value 0
1321     SAMSUNGAH_PULSE_LEN_MAX,                                            // pulse_0_len_max: maximum length of pulse with bit value 0
1322     SAMSUNGAH_0_PAUSE_LEN_MIN,                                          // pause_0_len_min: minimum length of pause with bit value 0
1323     SAMSUNGAH_0_PAUSE_LEN_MAX,                                          // pause_0_len_max: maximum length of pause with bit value 0
1324     SAMSUNGAH_ADDRESS_OFFSET,                                           // address_offset:  address offset
1325     SAMSUNGAH_ADDRESS_OFFSET + SAMSUNGAH_ADDRESS_LEN,                   // address_end:     end of address
1326     SAMSUNGAH_COMMAND_OFFSET,                                           // command_offset:  command offset
1327     SAMSUNGAH_COMMAND_OFFSET + SAMSUNGAH_COMMAND_LEN,                   // command_end:     end of command
1328     SAMSUNGAH_COMPLETE_DATA_LEN,                                        // complete_len:    complete length of frame
1329     SAMSUNGAH_STOP_BIT,                                                 // stop_bit:        flag: frame has stop bit
1330     SAMSUNGAH_LSB,                                                      // lsb_first:       flag: LSB first
1331     SAMSUNGAH_FLAGS                                                     // flags:           some flags
1332 };
1333
1334 #endif
1335
1336 #if IRMP_SUPPORT_TELEFUNKEN_PROTOCOL == 1
1337
1338 static const PROGMEM IRMP_PARAMETER telefunken_param =
1339 {
1340     IRMP_TELEFUNKEN_PROTOCOL,                                           // protocol:        ir protocol
1341     TELEFUNKEN_PULSE_LEN_MIN,                                           // pulse_1_len_min: minimum length of pulse with bit value 1
1342     TELEFUNKEN_PULSE_LEN_MAX,                                           // pulse_1_len_max: maximum length of pulse with bit value 1
1343     TELEFUNKEN_1_PAUSE_LEN_MIN,                                         // pause_1_len_min: minimum length of pause with bit value 1
1344     TELEFUNKEN_1_PAUSE_LEN_MAX,                                         // pause_1_len_max: maximum length of pause with bit value 1
1345     TELEFUNKEN_PULSE_LEN_MIN,                                           // pulse_0_len_min: minimum length of pulse with bit value 0
1346     TELEFUNKEN_PULSE_LEN_MAX,                                           // pulse_0_len_max: maximum length of pulse with bit value 0
1347     TELEFUNKEN_0_PAUSE_LEN_MIN,                                         // pause_0_len_min: minimum length of pause with bit value 0
1348     TELEFUNKEN_0_PAUSE_LEN_MAX,                                         // pause_0_len_max: maximum length of pause with bit value 0
1349     TELEFUNKEN_ADDRESS_OFFSET,                                          // address_offset:  address offset
1350     TELEFUNKEN_ADDRESS_OFFSET + TELEFUNKEN_ADDRESS_LEN,                 // address_end:     end of address
1351     TELEFUNKEN_COMMAND_OFFSET,                                          // command_offset:  command offset
1352     TELEFUNKEN_COMMAND_OFFSET + TELEFUNKEN_COMMAND_LEN,                 // command_end:     end of command
1353     TELEFUNKEN_COMPLETE_DATA_LEN,                                       // complete_len:    complete length of frame
1354     TELEFUNKEN_STOP_BIT,                                                // stop_bit:        flag: frame has stop bit
1355     TELEFUNKEN_LSB,                                                     // lsb_first:       flag: LSB first
1356     TELEFUNKEN_FLAGS                                                    // flags:           some flags
1357 };
1358
1359 #endif
1360
1361 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1362
1363 static const PROGMEM IRMP_PARAMETER matsushita_param =
1364 {
1365     IRMP_MATSUSHITA_PROTOCOL,                                           // protocol:        ir protocol
1366     MATSUSHITA_PULSE_LEN_MIN,                                           // pulse_1_len_min: minimum length of pulse with bit value 1
1367     MATSUSHITA_PULSE_LEN_MAX,                                           // pulse_1_len_max: maximum length of pulse with bit value 1
1368     MATSUSHITA_1_PAUSE_LEN_MIN,                                         // pause_1_len_min: minimum length of pause with bit value 1
1369     MATSUSHITA_1_PAUSE_LEN_MAX,                                         // pause_1_len_max: maximum length of pause with bit value 1
1370     MATSUSHITA_PULSE_LEN_MIN,                                           // pulse_0_len_min: minimum length of pulse with bit value 0
1371     MATSUSHITA_PULSE_LEN_MAX,                                           // pulse_0_len_max: maximum length of pulse with bit value 0
1372     MATSUSHITA_0_PAUSE_LEN_MIN,                                         // pause_0_len_min: minimum length of pause with bit value 0
1373     MATSUSHITA_0_PAUSE_LEN_MAX,                                         // pause_0_len_max: maximum length of pause with bit value 0
1374     MATSUSHITA_ADDRESS_OFFSET,                                          // address_offset:  address offset
1375     MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN,                 // address_end:     end of address
1376     MATSUSHITA_COMMAND_OFFSET,                                          // command_offset:  command offset
1377     MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN,                 // command_end:     end of command
1378     MATSUSHITA_COMPLETE_DATA_LEN,                                       // complete_len:    complete length of frame
1379     MATSUSHITA_STOP_BIT,                                                // stop_bit:        flag: frame has stop bit
1380     MATSUSHITA_LSB,                                                     // lsb_first:       flag: LSB first
1381     MATSUSHITA_FLAGS                                                    // flags:           some flags
1382 };
1383
1384 #endif
1385
1386 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1387
1388 static const PROGMEM IRMP_PARAMETER kaseikyo_param =
1389 {
1390     IRMP_KASEIKYO_PROTOCOL,                                             // protocol:        ir protocol
1391     KASEIKYO_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1
1392     KASEIKYO_PULSE_LEN_MAX,                                             // pulse_1_len_max: maximum length of pulse with bit value 1
1393     KASEIKYO_1_PAUSE_LEN_MIN,                                           // pause_1_len_min: minimum length of pause with bit value 1
1394     KASEIKYO_1_PAUSE_LEN_MAX,                                           // pause_1_len_max: maximum length of pause with bit value 1
1395     KASEIKYO_PULSE_LEN_MIN,                                             // pulse_0_len_min: minimum length of pulse with bit value 0
1396     KASEIKYO_PULSE_LEN_MAX,                                             // pulse_0_len_max: maximum length of pulse with bit value 0
1397     KASEIKYO_0_PAUSE_LEN_MIN,                                           // pause_0_len_min: minimum length of pause with bit value 0
1398     KASEIKYO_0_PAUSE_LEN_MAX,                                           // pause_0_len_max: maximum length of pause with bit value 0
1399     KASEIKYO_ADDRESS_OFFSET,                                            // address_offset:  address offset
1400     KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN,                     // address_end:     end of address
1401     KASEIKYO_COMMAND_OFFSET,                                            // command_offset:  command offset
1402     KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN,                     // command_end:     end of command
1403     KASEIKYO_COMPLETE_DATA_LEN,                                         // complete_len:    complete length of frame
1404     KASEIKYO_STOP_BIT,                                                  // stop_bit:        flag: frame has stop bit
1405     KASEIKYO_LSB,                                                       // lsb_first:       flag: LSB first
1406     KASEIKYO_FLAGS                                                      // flags:           some flags
1407 };
1408
1409 #endif
1410
1411 #if IRMP_SUPPORT_PANASONIC_PROTOCOL == 1
1412
1413 static const PROGMEM IRMP_PARAMETER panasonic_param =
1414 {
1415     IRMP_PANASONIC_PROTOCOL,                                            // protocol:        ir protocol
1416     PANASONIC_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1
1417     PANASONIC_PULSE_LEN_MAX,                                            // pulse_1_len_max: maximum length of pulse with bit value 1
1418     PANASONIC_1_PAUSE_LEN_MIN,                                          // pause_1_len_min: minimum length of pause with bit value 1
1419     PANASONIC_1_PAUSE_LEN_MAX,                                          // pause_1_len_max: maximum length of pause with bit value 1
1420     PANASONIC_PULSE_LEN_MIN,                                            // pulse_0_len_min: minimum length of pulse with bit value 0
1421     PANASONIC_PULSE_LEN_MAX,                                            // pulse_0_len_max: maximum length of pulse with bit value 0
1422     PANASONIC_0_PAUSE_LEN_MIN,                                          // pause_0_len_min: minimum length of pause with bit value 0
1423     PANASONIC_0_PAUSE_LEN_MAX,                                          // pause_0_len_max: maximum length of pause with bit value 0
1424     PANASONIC_ADDRESS_OFFSET,                                           // address_offset:  address offset
1425     PANASONIC_ADDRESS_OFFSET + PANASONIC_ADDRESS_LEN,                   // address_end:     end of address
1426     PANASONIC_COMMAND_OFFSET,                                           // command_offset:  command offset
1427     PANASONIC_COMMAND_OFFSET + PANASONIC_COMMAND_LEN,                   // command_end:     end of command
1428     PANASONIC_COMPLETE_DATA_LEN,                                        // complete_len:    complete length of frame
1429     PANASONIC_STOP_BIT,                                                 // stop_bit:        flag: frame has stop bit
1430     PANASONIC_LSB,                                                      // lsb_first:       flag: LSB first
1431     PANASONIC_FLAGS                                                     // flags:           some flags
1432 };
1433
1434 #endif
1435
1436 #if IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
1437
1438 static const PROGMEM IRMP_PARAMETER mitsu_heavy_param =
1439 {
1440     IRMP_MITSU_HEAVY_PROTOCOL,                                          // protocol:        ir protocol
1441     MITSU_HEAVY_PULSE_LEN_MIN,                                          // pulse_1_len_min: minimum length of pulse with bit value 1
1442     MITSU_HEAVY_PULSE_LEN_MAX,                                          // pulse_1_len_max: maximum length of pulse with bit value 1
1443     MITSU_HEAVY_1_PAUSE_LEN_MIN,                                        // pause_1_len_min: minimum length of pause with bit value 1
1444     MITSU_HEAVY_1_PAUSE_LEN_MAX,                                        // pause_1_len_max: maximum length of pause with bit value 1
1445     MITSU_HEAVY_PULSE_LEN_MIN,                                          // pulse_0_len_min: minimum length of pulse with bit value 0
1446     MITSU_HEAVY_PULSE_LEN_MAX,                                          // pulse_0_len_max: maximum length of pulse with bit value 0
1447     MITSU_HEAVY_0_PAUSE_LEN_MIN,                                        // pause_0_len_min: minimum length of pause with bit value 0
1448     MITSU_HEAVY_0_PAUSE_LEN_MAX,                                        // pause_0_len_max: maximum length of pause with bit value 0
1449     MITSU_HEAVY_ADDRESS_OFFSET,                                         // address_offset:  address offset
1450     MITSU_HEAVY_ADDRESS_OFFSET + MITSU_HEAVY_ADDRESS_LEN,               // address_end:     end of address
1451     MITSU_HEAVY_COMMAND_OFFSET,                                         // command_offset:  command offset
1452     MITSU_HEAVY_COMMAND_OFFSET + MITSU_HEAVY_COMMAND_LEN,               // command_end:     end of command
1453     MITSU_HEAVY_COMPLETE_DATA_LEN,                                      // complete_len:    complete length of frame
1454     MITSU_HEAVY_STOP_BIT,                                               // stop_bit:        flag: frame has stop bit
1455     MITSU_HEAVY_LSB,                                                    // lsb_first:       flag: LSB first
1456     MITSU_HEAVY_FLAGS                                                   // flags:           some flags
1457 };
1458
1459 #endif
1460
1461 #if IRMP_SUPPORT_VINCENT_PROTOCOL == 1
1462
1463 static const PROGMEM IRMP_PARAMETER vincent_param =
1464 {
1465     IRMP_VINCENT_PROTOCOL,                                              // protocol:        ir protocol
1466     VINCENT_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1
1467     VINCENT_PULSE_LEN_MAX,                                              // pulse_1_len_max: maximum length of pulse with bit value 1
1468     VINCENT_1_PAUSE_LEN_MIN,                                            // pause_1_len_min: minimum length of pause with bit value 1
1469     VINCENT_1_PAUSE_LEN_MAX,                                            // pause_1_len_max: maximum length of pause with bit value 1
1470     VINCENT_PULSE_LEN_MIN,                                              // pulse_0_len_min: minimum length of pulse with bit value 0
1471     VINCENT_PULSE_LEN_MAX,                                              // pulse_0_len_max: maximum length of pulse with bit value 0
1472     VINCENT_0_PAUSE_LEN_MIN,                                            // pause_0_len_min: minimum length of pause with bit value 0
1473     VINCENT_0_PAUSE_LEN_MAX,                                            // pause_0_len_max: maximum length of pause with bit value 0
1474     VINCENT_ADDRESS_OFFSET,                                             // address_offset:  address offset
1475     VINCENT_ADDRESS_OFFSET + VINCENT_ADDRESS_LEN,                       // address_end:     end of address
1476     VINCENT_COMMAND_OFFSET,                                             // command_offset:  command offset
1477     VINCENT_COMMAND_OFFSET + VINCENT_COMMAND_LEN,                       // command_end:     end of command
1478     VINCENT_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame
1479     VINCENT_STOP_BIT,                                                   // stop_bit:        flag: frame has stop bit
1480     VINCENT_LSB,                                                        // lsb_first:       flag: LSB first
1481     VINCENT_FLAGS                                                       // flags:           some flags
1482 };
1483
1484 #endif
1485
1486 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1487
1488 static const PROGMEM IRMP_PARAMETER recs80_param =
1489 {
1490     IRMP_RECS80_PROTOCOL,                                               // protocol:        ir protocol
1491     RECS80_PULSE_LEN_MIN,                                               // pulse_1_len_min: minimum length of pulse with bit value 1
1492     RECS80_PULSE_LEN_MAX,                                               // pulse_1_len_max: maximum length of pulse with bit value 1
1493     RECS80_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
1494     RECS80_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
1495     RECS80_PULSE_LEN_MIN,                                               // pulse_0_len_min: minimum length of pulse with bit value 0
1496     RECS80_PULSE_LEN_MAX,                                               // pulse_0_len_max: maximum length of pulse with bit value 0
1497     RECS80_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
1498     RECS80_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
1499     RECS80_ADDRESS_OFFSET,                                              // address_offset:  address offset
1500     RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN,                         // address_end:     end of address
1501     RECS80_COMMAND_OFFSET,                                              // command_offset:  command offset
1502     RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN,                         // command_end:     end of command
1503     RECS80_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
1504     RECS80_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
1505     RECS80_LSB,                                                         // lsb_first:       flag: LSB first
1506     RECS80_FLAGS                                                        // flags:           some flags
1507 };
1508
1509 #endif
1510
1511 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1512
1513 static const PROGMEM IRMP_PARAMETER rc5_param =
1514 {
1515     IRMP_RC5_PROTOCOL,                                                  // protocol:        ir protocol
1516     RC5_BIT_LEN_MIN,                                                    // pulse_1_len_min: here: minimum length of short pulse
1517     RC5_BIT_LEN_MAX,                                                    // pulse_1_len_max: here: maximum length of short pulse
1518     RC5_BIT_LEN_MIN,                                                    // pause_1_len_min: here: minimum length of short pause
1519     RC5_BIT_LEN_MAX,                                                    // pause_1_len_max: here: maximum length of short pause
1520     0,                                                                  // pulse_0_len_min: here: not used
1521     0,                                                                  // pulse_0_len_max: here: not used
1522     0,                                                                  // pause_0_len_min: here: not used
1523     0,                                                                  // pause_0_len_max: here: not used
1524     RC5_ADDRESS_OFFSET,                                                 // address_offset:  address offset
1525     RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN,                               // address_end:     end of address
1526     RC5_COMMAND_OFFSET,                                                 // command_offset:  command offset
1527     RC5_COMMAND_OFFSET + RC5_COMMAND_LEN,                               // command_end:     end of command
1528     RC5_COMPLETE_DATA_LEN,                                              // complete_len:    complete length of frame
1529     RC5_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1530     RC5_LSB,                                                            // lsb_first:       flag: LSB first
1531     RC5_FLAGS                                                           // flags:           some flags
1532 };
1533
1534 #endif
1535
1536 #if IRMP_SUPPORT_RCII_PROTOCOL == 1
1537
1538 static const PROGMEM IRMP_PARAMETER rcii_param =
1539 {
1540     IRMP_RCII_PROTOCOL,                                                 // protocol:        ir protocol
1541     RCII_BIT_LEN_MIN,                                                   // pulse_1_len_min: here: minimum length of short pulse
1542     RCII_BIT_LEN_MAX,                                                   // pulse_1_len_max: here: maximum length of short pulse
1543     RCII_BIT_LEN_MIN,                                                   // pause_1_len_min: here: minimum length of short pause
1544     RCII_BIT_LEN_MAX,                                                   // pause_1_len_max: here: maximum length of short pause
1545     RCII_BIT_LEN_MIN,                                                                  // pulse_0_len_min: here: not used
1546     RCII_BIT_LEN_MAX,                                                                  // pulse_0_len_max: here: not used
1547     RCII_BIT_LEN_MIN,                                                                  // pause_0_len_min: here: not used
1548     RCII_BIT_LEN_MAX,                                                                  // pause_0_len_max: here: not used
1549     RCII_ADDRESS_OFFSET,                                                // address_offset:  address offset
1550     RCII_ADDRESS_OFFSET + RCII_ADDRESS_LEN,                             // address_end:     end of address
1551     RCII_COMMAND_OFFSET,                                                // command_offset:  command offset
1552     RCII_COMMAND_OFFSET + RCII_COMMAND_LEN,                             // command_end:     end of command
1553     RCII_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame
1554     RCII_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit
1555     RCII_LSB,                                                           // lsb_first:       flag: LSB first
1556     RCII_FLAGS                                                          // flags:           some flags
1557 };
1558
1559 #endif
1560
1561 #if IRMP_SUPPORT_S100_PROTOCOL == 1
1562
1563 static const PROGMEM IRMP_PARAMETER s100_param =
1564 {
1565     IRMP_S100_PROTOCOL,                                                 // protocol:        ir protocol
1566     S100_BIT_LEN_MIN,                                                   // pulse_1_len_min: here: minimum length of short pulse
1567     S100_BIT_LEN_MAX,                                                   // pulse_1_len_max: here: maximum length of short pulse
1568     S100_BIT_LEN_MIN,                                                   // pause_1_len_min: here: minimum length of short pause
1569     S100_BIT_LEN_MAX,                                                   // pause_1_len_max: here: maximum length of short pause
1570     0,                                                                  // pulse_0_len_min: here: not used
1571     0,                                                                  // pulse_0_len_max: here: not used
1572     0,                                                                  // pause_0_len_min: here: not used
1573     0,                                                                  // pause_0_len_max: here: not used
1574     S100_ADDRESS_OFFSET,                                                // address_offset:  address offset
1575     S100_ADDRESS_OFFSET + S100_ADDRESS_LEN,                             // address_end:     end of address
1576     S100_COMMAND_OFFSET,                                                // command_offset:  command offset
1577     S100_COMMAND_OFFSET + S100_COMMAND_LEN,                             // command_end:     end of command
1578     S100_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame
1579     S100_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit
1580     S100_LSB,                                                           // lsb_first:       flag: LSB first
1581     S100_FLAGS                                                          // flags:           some flags
1582 };
1583
1584 #endif
1585
1586 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1587
1588 static const PROGMEM IRMP_PARAMETER denon_param =
1589 {
1590     IRMP_DENON_PROTOCOL,                                                // protocol:        ir protocol
1591     DENON_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1
1592     DENON_PULSE_LEN_MAX,                                                // pulse_1_len_max: maximum length of pulse with bit value 1
1593     DENON_1_PAUSE_LEN_MIN,                                              // pause_1_len_min: minimum length of pause with bit value 1
1594     DENON_1_PAUSE_LEN_MAX,                                              // pause_1_len_max: maximum length of pause with bit value 1
1595     DENON_PULSE_LEN_MIN,                                                // pulse_0_len_min: minimum length of pulse with bit value 0
1596     DENON_PULSE_LEN_MAX,                                                // pulse_0_len_max: maximum length of pulse with bit value 0
1597     DENON_0_PAUSE_LEN_MIN,                                              // pause_0_len_min: minimum length of pause with bit value 0
1598     DENON_0_PAUSE_LEN_MAX,                                              // pause_0_len_max: maximum length of pause with bit value 0
1599     DENON_ADDRESS_OFFSET,                                               // address_offset:  address offset
1600     DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN,                           // address_end:     end of address
1601     DENON_COMMAND_OFFSET,                                               // command_offset:  command offset
1602     DENON_COMMAND_OFFSET + DENON_COMMAND_LEN,                           // command_end:     end of command
1603     DENON_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1604     DENON_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
1605     DENON_LSB,                                                          // lsb_first:       flag: LSB first
1606     DENON_FLAGS                                                         // flags:           some flags
1607 };
1608
1609 #endif
1610
1611 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1612
1613 static const PROGMEM IRMP_PARAMETER rc6_param =
1614 {
1615     IRMP_RC6_PROTOCOL,                                                  // protocol:        ir protocol
1616
1617     RC6_BIT_PULSE_LEN_MIN,                                              // pulse_1_len_min: here: minimum length of short pulse
1618     RC6_BIT_PULSE_LEN_MAX,                                              // pulse_1_len_max: here: maximum length of short pulse
1619     RC6_BIT_PAUSE_LEN_MIN,                                              // pause_1_len_min: here: minimum length of short pause
1620     RC6_BIT_PAUSE_LEN_MAX,                                              // pause_1_len_max: here: maximum length of short pause
1621     0,                                                                  // pulse_0_len_min: here: not used
1622     0,                                                                  // pulse_0_len_max: here: not used
1623     0,                                                                  // pause_0_len_min: here: not used
1624     0,                                                                  // pause_0_len_max: here: not used
1625     RC6_ADDRESS_OFFSET,                                                 // address_offset:  address offset
1626     RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN,                               // address_end:     end of address
1627     RC6_COMMAND_OFFSET,                                                 // command_offset:  command offset
1628     RC6_COMMAND_OFFSET + RC6_COMMAND_LEN,                               // command_end:     end of command
1629     RC6_COMPLETE_DATA_LEN_SHORT,                                        // complete_len:    complete length of frame
1630     RC6_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1631     RC6_LSB,                                                            // lsb_first:       flag: LSB first
1632     RC6_FLAGS                                                           // flags:           some flags
1633 };
1634
1635 #endif
1636
1637 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1638
1639 static const PROGMEM IRMP_PARAMETER recs80ext_param =
1640 {
1641     IRMP_RECS80EXT_PROTOCOL,                                            // protocol:        ir protocol
1642     RECS80EXT_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1
1643     RECS80EXT_PULSE_LEN_MAX,                                            // pulse_1_len_max: maximum length of pulse with bit value 1
1644     RECS80EXT_1_PAUSE_LEN_MIN,                                          // pause_1_len_min: minimum length of pause with bit value 1
1645     RECS80EXT_1_PAUSE_LEN_MAX,                                          // pause_1_len_max: maximum length of pause with bit value 1
1646     RECS80EXT_PULSE_LEN_MIN,                                            // pulse_0_len_min: minimum length of pulse with bit value 0
1647     RECS80EXT_PULSE_LEN_MAX,                                            // pulse_0_len_max: maximum length of pulse with bit value 0
1648     RECS80EXT_0_PAUSE_LEN_MIN,                                          // pause_0_len_min: minimum length of pause with bit value 0
1649     RECS80EXT_0_PAUSE_LEN_MAX,                                          // pause_0_len_max: maximum length of pause with bit value 0
1650     RECS80EXT_ADDRESS_OFFSET,                                           // address_offset:  address offset
1651     RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN,                   // address_end:     end of address
1652     RECS80EXT_COMMAND_OFFSET,                                           // command_offset:  command offset
1653     RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN,                   // command_end:     end of command
1654     RECS80EXT_COMPLETE_DATA_LEN,                                        // complete_len:    complete length of frame
1655     RECS80EXT_STOP_BIT,                                                 // stop_bit:        flag: frame has stop bit
1656     RECS80EXT_LSB,                                                      // lsb_first:       flag: LSB first
1657     RECS80EXT_FLAGS                                                     // flags:           some flags
1658 };
1659
1660 #endif
1661
1662 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1663
1664 static const PROGMEM IRMP_PARAMETER nubert_param =
1665 {
1666     IRMP_NUBERT_PROTOCOL,                                               // protocol:        ir protocol
1667     NUBERT_1_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1
1668     NUBERT_1_PULSE_LEN_MAX,                                             // pulse_1_len_max: maximum length of pulse with bit value 1
1669     NUBERT_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
1670     NUBERT_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
1671     NUBERT_0_PULSE_LEN_MIN,                                             // pulse_0_len_min: minimum length of pulse with bit value 0
1672     NUBERT_0_PULSE_LEN_MAX,                                             // pulse_0_len_max: maximum length of pulse with bit value 0
1673     NUBERT_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
1674     NUBERT_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
1675     NUBERT_ADDRESS_OFFSET,                                              // address_offset:  address offset
1676     NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN,                         // address_end:     end of address
1677     NUBERT_COMMAND_OFFSET,                                              // command_offset:  command offset
1678     NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN,                         // command_end:     end of command
1679     NUBERT_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
1680     NUBERT_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
1681     NUBERT_LSB,                                                         // lsb_first:       flag: LSB first
1682     NUBERT_FLAGS                                                        // flags:           some flags
1683 };
1684
1685 #endif
1686
1687 #if IRMP_SUPPORT_FAN_PROTOCOL == 1
1688
1689 static const PROGMEM IRMP_PARAMETER fan_param =
1690 {
1691     IRMP_FAN_PROTOCOL,                                                  // protocol:        ir protocol
1692     FAN_1_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1
1693     FAN_1_PULSE_LEN_MAX,                                                // pulse_1_len_max: maximum length of pulse with bit value 1
1694     FAN_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1695     FAN_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1696     FAN_0_PULSE_LEN_MIN,                                                // pulse_0_len_min: minimum length of pulse with bit value 0
1697     FAN_0_PULSE_LEN_MAX,                                                // pulse_0_len_max: maximum length of pulse with bit value 0
1698     FAN_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1699     FAN_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1700     FAN_ADDRESS_OFFSET,                                                 // address_offset:  address offset
1701     FAN_ADDRESS_OFFSET + FAN_ADDRESS_LEN,                               // address_end:     end of address
1702     FAN_COMMAND_OFFSET,                                                 // command_offset:  command offset
1703     FAN_COMMAND_OFFSET + FAN_COMMAND_LEN,                               // command_end:     end of command
1704     FAN_COMPLETE_DATA_LEN,                                              // complete_len:    complete length of frame
1705     FAN_STOP_BIT,                                                       // stop_bit:        flag: frame has NO stop bit
1706     FAN_LSB,                                                            // lsb_first:       flag: LSB first
1707     FAN_FLAGS                                                           // flags:           some flags
1708 };
1709
1710 #endif
1711
1712 #if IRMP_SUPPORT_SPEAKER_PROTOCOL == 1
1713
1714 static const PROGMEM IRMP_PARAMETER speaker_param =
1715 {
1716     IRMP_SPEAKER_PROTOCOL,                                              // protocol:        ir protocol
1717     SPEAKER_1_PULSE_LEN_MIN,                                            // pulse_1_len_min: minimum length of pulse with bit value 1
1718     SPEAKER_1_PULSE_LEN_MAX,                                            // pulse_1_len_max: maximum length of pulse with bit value 1
1719     SPEAKER_1_PAUSE_LEN_MIN,                                            // pause_1_len_min: minimum length of pause with bit value 1
1720     SPEAKER_1_PAUSE_LEN_MAX,                                            // pause_1_len_max: maximum length of pause with bit value 1
1721     SPEAKER_0_PULSE_LEN_MIN,                                            // pulse_0_len_min: minimum length of pulse with bit value 0
1722     SPEAKER_0_PULSE_LEN_MAX,                                            // pulse_0_len_max: maximum length of pulse with bit value 0
1723     SPEAKER_0_PAUSE_LEN_MIN,                                            // pause_0_len_min: minimum length of pause with bit value 0
1724     SPEAKER_0_PAUSE_LEN_MAX,                                            // pause_0_len_max: maximum length of pause with bit value 0
1725     SPEAKER_ADDRESS_OFFSET,                                             // address_offset:  address offset
1726     SPEAKER_ADDRESS_OFFSET + SPEAKER_ADDRESS_LEN,                       // address_end:     end of address
1727     SPEAKER_COMMAND_OFFSET,                                             // command_offset:  command offset
1728     SPEAKER_COMMAND_OFFSET + SPEAKER_COMMAND_LEN,                       // command_end:     end of command
1729     SPEAKER_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame
1730     SPEAKER_STOP_BIT,                                                   // stop_bit:        flag: frame has stop bit
1731     SPEAKER_LSB,                                                        // lsb_first:       flag: LSB first
1732     SPEAKER_FLAGS                                                       // flags:           some flags
1733 };
1734
1735 #endif
1736
1737 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1738
1739 static const PROGMEM IRMP_PARAMETER bang_olufsen_param =
1740 {
1741     IRMP_BANG_OLUFSEN_PROTOCOL,                                         // protocol:        ir protocol
1742     BANG_OLUFSEN_PULSE_LEN_MIN,                                         // pulse_1_len_min: minimum length of pulse with bit value 1
1743     BANG_OLUFSEN_PULSE_LEN_MAX,                                         // pulse_1_len_max: maximum length of pulse with bit value 1
1744     BANG_OLUFSEN_1_PAUSE_LEN_MIN,                                       // pause_1_len_min: minimum length of pause with bit value 1
1745     BANG_OLUFSEN_1_PAUSE_LEN_MAX,                                       // pause_1_len_max: maximum length of pause with bit value 1
1746     BANG_OLUFSEN_PULSE_LEN_MIN,                                         // pulse_0_len_min: minimum length of pulse with bit value 0
1747     BANG_OLUFSEN_PULSE_LEN_MAX,                                         // pulse_0_len_max: maximum length of pulse with bit value 0
1748     BANG_OLUFSEN_0_PAUSE_LEN_MIN,                                       // pause_0_len_min: minimum length of pause with bit value 0
1749     BANG_OLUFSEN_0_PAUSE_LEN_MAX,                                       // pause_0_len_max: maximum length of pause with bit value 0
1750     BANG_OLUFSEN_ADDRESS_OFFSET,                                        // address_offset:  address offset
1751     BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN,             // address_end:     end of address
1752     BANG_OLUFSEN_COMMAND_OFFSET,                                        // command_offset:  command offset
1753     BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN,             // command_end:     end of command
1754     BANG_OLUFSEN_COMPLETE_DATA_LEN,                                     // complete_len:    complete length of frame
1755     BANG_OLUFSEN_STOP_BIT,                                              // stop_bit:        flag: frame has stop bit
1756     BANG_OLUFSEN_LSB,                                                   // lsb_first:       flag: LSB first
1757     BANG_OLUFSEN_FLAGS                                                  // flags:           some flags
1758 };
1759
1760 #endif
1761
1762 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
1763
1764 static uint_fast8_t first_bit;
1765
1766 static const PROGMEM IRMP_PARAMETER grundig_param =
1767 {
1768     IRMP_GRUNDIG_PROTOCOL,                                              // protocol:        ir protocol
1769
1770     GRUNDIG_NOKIA_IR60_BIT_LEN_MIN,                                     // pulse_1_len_min: here: minimum length of short pulse
1771     GRUNDIG_NOKIA_IR60_BIT_LEN_MAX,                                     // pulse_1_len_max: here: maximum length of short pulse
1772     GRUNDIG_NOKIA_IR60_BIT_LEN_MIN,                                     // pause_1_len_min: here: minimum length of short pause
1773     GRUNDIG_NOKIA_IR60_BIT_LEN_MAX,                                     // pause_1_len_max: here: maximum length of short pause
1774     0,                                                                  // pulse_0_len_min: here: not used
1775     0,                                                                  // pulse_0_len_max: here: not used
1776     0,                                                                  // pause_0_len_min: here: not used
1777     0,                                                                  // pause_0_len_max: here: not used
1778     GRUNDIG_ADDRESS_OFFSET,                                             // address_offset:  address offset
1779     GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN,                       // address_end:     end of address
1780     GRUNDIG_COMMAND_OFFSET,                                             // command_offset:  command offset
1781     GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1,                   // command_end:     end of command (USE 1 bit MORE to STORE NOKIA DATA!)
1782     NOKIA_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame, here: NOKIA instead of GRUNDIG!
1783     GRUNDIG_NOKIA_IR60_STOP_BIT,                                        // stop_bit:        flag: frame has stop bit
1784     GRUNDIG_NOKIA_IR60_LSB,                                             // lsb_first:       flag: LSB first
1785     GRUNDIG_NOKIA_IR60_FLAGS                                            // flags:           some flags
1786 };
1787
1788 #endif
1789
1790 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
1791
1792 static const PROGMEM IRMP_PARAMETER ruwido_param =
1793 {
1794     IRMP_RUWIDO_PROTOCOL,                                               // protocol:        ir protocol
1795     SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN,                                // pulse_1_len_min: here: minimum length of short pulse
1796     SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,                                // pulse_1_len_max: here: maximum length of short pulse
1797     SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN,                                // pause_1_len_min: here: minimum length of short pause
1798     SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX,                                // pause_1_len_max: here: maximum length of short pause
1799     0,                                                                  // pulse_0_len_min: here: not used
1800     0,                                                                  // pulse_0_len_max: here: not used
1801     0,                                                                  // pause_0_len_min: here: not used
1802     0,                                                                  // pause_0_len_max: here: not used
1803     RUWIDO_ADDRESS_OFFSET,                                              // address_offset:  address offset
1804     RUWIDO_ADDRESS_OFFSET + RUWIDO_ADDRESS_LEN,                         // address_end:     end of address
1805     RUWIDO_COMMAND_OFFSET,                                              // command_offset:  command offset
1806     RUWIDO_COMMAND_OFFSET + RUWIDO_COMMAND_LEN,                         // command_end:     end of command
1807     SIEMENS_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame, here: SIEMENS instead of RUWIDO!
1808     SIEMENS_OR_RUWIDO_STOP_BIT,                                         // stop_bit:        flag: frame has stop bit
1809     SIEMENS_OR_RUWIDO_LSB,                                              // lsb_first:       flag: LSB first
1810     SIEMENS_OR_RUWIDO_FLAGS                                             // flags:           some flags
1811 };
1812
1813 #endif
1814
1815 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1816
1817 static const PROGMEM IRMP_PARAMETER fdc_param =
1818 {
1819     IRMP_FDC_PROTOCOL,                                                  // protocol:        ir protocol
1820     FDC_PULSE_LEN_MIN,                                                  // pulse_1_len_min: minimum length of pulse with bit value 1
1821     FDC_PULSE_LEN_MAX,                                                  // pulse_1_len_max: maximum length of pulse with bit value 1
1822     FDC_1_PAUSE_LEN_MIN,                                                // pause_1_len_min: minimum length of pause with bit value 1
1823     FDC_1_PAUSE_LEN_MAX,                                                // pause_1_len_max: maximum length of pause with bit value 1
1824     FDC_PULSE_LEN_MIN,                                                  // pulse_0_len_min: minimum length of pulse with bit value 0
1825     FDC_PULSE_LEN_MAX,                                                  // pulse_0_len_max: maximum length of pulse with bit value 0
1826     FDC_0_PAUSE_LEN_MIN,                                                // pause_0_len_min: minimum length of pause with bit value 0
1827     FDC_0_PAUSE_LEN_MAX,                                                // pause_0_len_max: maximum length of pause with bit value 0
1828     FDC_ADDRESS_OFFSET,                                                 // address_offset:  address offset
1829     FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN,                               // address_end:     end of address
1830     FDC_COMMAND_OFFSET,                                                 // command_offset:  command offset
1831     FDC_COMMAND_OFFSET + FDC_COMMAND_LEN,                               // command_end:     end of command
1832     FDC_COMPLETE_DATA_LEN,                                              // complete_len:    complete length of frame
1833     FDC_STOP_BIT,                                                       // stop_bit:        flag: frame has stop bit
1834     FDC_LSB,                                                            // lsb_first:       flag: LSB first
1835     FDC_FLAGS                                                           // flags:           some flags
1836 };
1837
1838 #endif
1839
1840 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1841
1842 static const PROGMEM IRMP_PARAMETER rccar_param =
1843 {
1844     IRMP_RCCAR_PROTOCOL,                                                // protocol:        ir protocol
1845     RCCAR_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1
1846     RCCAR_PULSE_LEN_MAX,                                                // pulse_1_len_max: maximum length of pulse with bit value 1
1847     RCCAR_1_PAUSE_LEN_MIN,                                              // pause_1_len_min: minimum length of pause with bit value 1
1848     RCCAR_1_PAUSE_LEN_MAX,                                              // pause_1_len_max: maximum length of pause with bit value 1
1849     RCCAR_PULSE_LEN_MIN,                                                // pulse_0_len_min: minimum length of pulse with bit value 0
1850     RCCAR_PULSE_LEN_MAX,                                                // pulse_0_len_max: maximum length of pulse with bit value 0
1851     RCCAR_0_PAUSE_LEN_MIN,                                              // pause_0_len_min: minimum length of pause with bit value 0
1852     RCCAR_0_PAUSE_LEN_MAX,                                              // pause_0_len_max: maximum length of pause with bit value 0
1853     RCCAR_ADDRESS_OFFSET,                                               // address_offset:  address offset
1854     RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN,                           // address_end:     end of address
1855     RCCAR_COMMAND_OFFSET,                                               // command_offset:  command offset
1856     RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN,                           // command_end:     end of command
1857     RCCAR_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1858     RCCAR_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
1859     RCCAR_LSB,                                                          // lsb_first:       flag: LSB first
1860     RCCAR_FLAGS                                                         // flags:           some flags
1861 };
1862
1863 #endif
1864
1865 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1866
1867 static const PROGMEM IRMP_PARAMETER nikon_param =
1868 {
1869     IRMP_NIKON_PROTOCOL,                                                // protocol:        ir protocol
1870     NIKON_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1
1871     NIKON_PULSE_LEN_MAX,                                                // pulse_1_len_max: maximum length of pulse with bit value 1
1872     NIKON_1_PAUSE_LEN_MIN,                                              // pause_1_len_min: minimum length of pause with bit value 1
1873     NIKON_1_PAUSE_LEN_MAX,                                              // pause_1_len_max: maximum length of pause with bit value 1
1874     NIKON_PULSE_LEN_MIN,                                                // pulse_0_len_min: minimum length of pulse with bit value 0
1875     NIKON_PULSE_LEN_MAX,                                                // pulse_0_len_max: maximum length of pulse with bit value 0
1876     NIKON_0_PAUSE_LEN_MIN,                                              // pause_0_len_min: minimum length of pause with bit value 0
1877     NIKON_0_PAUSE_LEN_MAX,                                              // pause_0_len_max: maximum length of pause with bit value 0
1878     NIKON_ADDRESS_OFFSET,                                               // address_offset:  address offset
1879     NIKON_ADDRESS_OFFSET + NIKON_ADDRESS_LEN,                           // address_end:     end of address
1880     NIKON_COMMAND_OFFSET,                                               // command_offset:  command offset
1881     NIKON_COMMAND_OFFSET + NIKON_COMMAND_LEN,                           // command_end:     end of command
1882     NIKON_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
1883     NIKON_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
1884     NIKON_LSB,                                                          // lsb_first:       flag: LSB first
1885     NIKON_FLAGS                                                         // flags:           some flags
1886 };
1887
1888 #endif
1889
1890 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
1891
1892 static const PROGMEM IRMP_PARAMETER kathrein_param =
1893 {
1894     IRMP_KATHREIN_PROTOCOL,                                             // protocol:        ir protocol
1895     KATHREIN_1_PULSE_LEN_MIN,                                           // pulse_1_len_min: minimum length of pulse with bit value 1
1896     KATHREIN_1_PULSE_LEN_MAX,                                           // pulse_1_len_max: maximum length of pulse with bit value 1
1897     KATHREIN_1_PAUSE_LEN_MIN,                                           // pause_1_len_min: minimum length of pause with bit value 1
1898     KATHREIN_1_PAUSE_LEN_MAX,                                           // pause_1_len_max: maximum length of pause with bit value 1
1899     KATHREIN_0_PULSE_LEN_MIN,                                           // pulse_0_len_min: minimum length of pulse with bit value 0
1900     KATHREIN_0_PULSE_LEN_MAX,                                           // pulse_0_len_max: maximum length of pulse with bit value 0
1901     KATHREIN_0_PAUSE_LEN_MIN,                                           // pause_0_len_min: minimum length of pause with bit value 0
1902     KATHREIN_0_PAUSE_LEN_MAX,                                           // pause_0_len_max: maximum length of pause with bit value 0
1903     KATHREIN_ADDRESS_OFFSET,                                            // address_offset:  address offset
1904     KATHREIN_ADDRESS_OFFSET + KATHREIN_ADDRESS_LEN,                     // address_end:     end of address
1905     KATHREIN_COMMAND_OFFSET,                                            // command_offset:  command offset
1906     KATHREIN_COMMAND_OFFSET + KATHREIN_COMMAND_LEN,                     // command_end:     end of command
1907     KATHREIN_COMPLETE_DATA_LEN,                                         // complete_len:    complete length of frame
1908     KATHREIN_STOP_BIT,                                                  // stop_bit:        flag: frame has stop bit
1909     KATHREIN_LSB,                                                       // lsb_first:       flag: LSB first
1910     KATHREIN_FLAGS                                                      // flags:           some flags
1911 };
1912
1913 #endif
1914
1915 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
1916
1917 static const PROGMEM IRMP_PARAMETER netbox_param =
1918 {
1919     IRMP_NETBOX_PROTOCOL,                                               // protocol:        ir protocol
1920     NETBOX_PULSE_LEN,                                                   // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value
1921     NETBOX_PULSE_REST_LEN,                                              // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value
1922     NETBOX_PAUSE_LEN,                                                   // pause_1_len_min: minimum length of pause with bit value 1, here: exact value
1923     NETBOX_PAUSE_REST_LEN,                                              // pause_1_len_max: maximum length of pause with bit value 1, here: rest value
1924     NETBOX_PULSE_LEN,                                                   // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value
1925     NETBOX_PULSE_REST_LEN,                                              // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value
1926     NETBOX_PAUSE_LEN,                                                   // pause_0_len_min: minimum length of pause with bit value 0, here: exact value
1927     NETBOX_PAUSE_REST_LEN,                                              // pause_0_len_max: maximum length of pause with bit value 0, here: rest value
1928     NETBOX_ADDRESS_OFFSET,                                              // address_offset:  address offset
1929     NETBOX_ADDRESS_OFFSET + NETBOX_ADDRESS_LEN,                         // address_end:     end of address
1930     NETBOX_COMMAND_OFFSET,                                              // command_offset:  command offset
1931     NETBOX_COMMAND_OFFSET + NETBOX_COMMAND_LEN,                         // command_end:     end of command
1932     NETBOX_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
1933     NETBOX_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
1934     NETBOX_LSB,                                                         // lsb_first:       flag: LSB first
1935     NETBOX_FLAGS                                                        // flags:           some flags
1936 };
1937
1938 #endif
1939
1940 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
1941
1942 static const PROGMEM IRMP_PARAMETER lego_param =
1943 {
1944     IRMP_LEGO_PROTOCOL,                                                 // protocol:        ir protocol
1945     LEGO_PULSE_LEN_MIN,                                                 // pulse_1_len_min: minimum length of pulse with bit value 1
1946     LEGO_PULSE_LEN_MAX,                                                 // pulse_1_len_max: maximum length of pulse with bit value 1
1947     LEGO_1_PAUSE_LEN_MIN,                                               // pause_1_len_min: minimum length of pause with bit value 1
1948     LEGO_1_PAUSE_LEN_MAX,                                               // pause_1_len_max: maximum length of pause with bit value 1
1949     LEGO_PULSE_LEN_MIN,                                                 // pulse_0_len_min: minimum length of pulse with bit value 0
1950     LEGO_PULSE_LEN_MAX,                                                 // pulse_0_len_max: maximum length of pulse with bit value 0
1951     LEGO_0_PAUSE_LEN_MIN,                                               // pause_0_len_min: minimum length of pause with bit value 0
1952     LEGO_0_PAUSE_LEN_MAX,                                               // pause_0_len_max: maximum length of pause with bit value 0
1953     LEGO_ADDRESS_OFFSET,                                                // address_offset:  address offset
1954     LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN,                             // address_end:     end of address
1955     LEGO_COMMAND_OFFSET,                                                // command_offset:  command offset
1956     LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN,                             // command_end:     end of command
1957     LEGO_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame
1958     LEGO_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit
1959     LEGO_LSB,                                                           // lsb_first:       flag: LSB first
1960     LEGO_FLAGS                                                          // flags:           some flags
1961 };
1962
1963 #endif
1964
1965 #if IRMP_SUPPORT_IRMP16_PROTOCOL == 1
1966
1967 static const PROGMEM IRMP_PARAMETER irmp16_param =
1968 {
1969     IRMP_IRMP16_PROTOCOL,                                               // protocol:        ir protocol
1970     IRMP16_PULSE_LEN_MIN,                                               // pulse_1_len_min: minimum length of pulse with bit value 1
1971     IRMP16_PULSE_LEN_MAX,                                               // pulse_1_len_max: maximum length of pulse with bit value 1
1972     IRMP16_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
1973     IRMP16_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
1974     IRMP16_PULSE_LEN_MIN,                                               // pulse_0_len_min: minimum length of pulse with bit value 0
1975     IRMP16_PULSE_LEN_MAX,                                               // pulse_0_len_max: maximum length of pulse with bit value 0
1976     IRMP16_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
1977     IRMP16_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
1978     IRMP16_ADDRESS_OFFSET,                                              // address_offset:  address offset
1979     IRMP16_ADDRESS_OFFSET + IRMP16_ADDRESS_LEN,                         // address_end:     end of address
1980     IRMP16_COMMAND_OFFSET,                                              // command_offset:  command offset
1981     IRMP16_COMMAND_OFFSET + IRMP16_COMMAND_LEN,                         // command_end:     end of command
1982     IRMP16_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
1983     IRMP16_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
1984     IRMP16_LSB,                                                         // lsb_first:       flag: LSB first
1985     IRMP16_FLAGS                                                        // flags:           some flags
1986 };
1987
1988 #endif
1989
1990 #if IRMP_SUPPORT_GREE_PROTOCOL == 1
1991
1992 static const PROGMEM IRMP_PARAMETER gree_param =
1993 {
1994     IRMP_GREE_PROTOCOL,                                               // protocol:        ir protocol
1995     GREE_PULSE_LEN_MIN,                                               // pulse_1_len_min: minimum length of pulse with bit value 1
1996     GREE_PULSE_LEN_MAX,                                               // pulse_1_len_max: maximum length of pulse with bit value 1
1997     GREE_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
1998     GREE_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
1999     GREE_PULSE_LEN_MIN,                                               // pulse_0_len_min: minimum length of pulse with bit value 0
2000     GREE_PULSE_LEN_MAX,                                               // pulse_0_len_max: maximum length of pulse with bit value 0
2001     GREE_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
2002     GREE_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
2003     GREE_ADDRESS_OFFSET,                                              // address_offset:  address offset
2004     GREE_ADDRESS_OFFSET + GREE_ADDRESS_LEN,                         // address_end:     end of address
2005     GREE_COMMAND_OFFSET,                                              // command_offset:  command offset
2006     GREE_COMMAND_OFFSET + GREE_COMMAND_LEN,                         // command_end:     end of command
2007     GREE_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2008     GREE_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2009     GREE_LSB,                                                         // lsb_first:       flag: LSB first
2010     GREE_FLAGS                                                        // flags:           some flags
2011 };
2012
2013 #endif
2014
2015 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2016
2017 static const PROGMEM IRMP_PARAMETER thomson_param =
2018 {
2019     IRMP_THOMSON_PROTOCOL,                                              // protocol:        ir protocol
2020     THOMSON_PULSE_LEN_MIN,                                              // pulse_1_len_min: minimum length of pulse with bit value 1
2021     THOMSON_PULSE_LEN_MAX,                                              // pulse_1_len_max: maximum length of pulse with bit value 1
2022     THOMSON_1_PAUSE_LEN_MIN,                                            // pause_1_len_min: minimum length of pause with bit value 1
2023     THOMSON_1_PAUSE_LEN_MAX,                                            // pause_1_len_max: maximum length of pause with bit value 1
2024     THOMSON_PULSE_LEN_MIN,                                              // pulse_0_len_min: minimum length of pulse with bit value 0
2025     THOMSON_PULSE_LEN_MAX,                                              // pulse_0_len_max: maximum length of pulse with bit value 0
2026     THOMSON_0_PAUSE_LEN_MIN,                                            // pause_0_len_min: minimum length of pause with bit value 0
2027     THOMSON_0_PAUSE_LEN_MAX,                                            // pause_0_len_max: maximum length of pause with bit value 0
2028     THOMSON_ADDRESS_OFFSET,                                             // address_offset:  address offset
2029     THOMSON_ADDRESS_OFFSET + THOMSON_ADDRESS_LEN,                       // address_end:     end of address
2030     THOMSON_COMMAND_OFFSET,                                             // command_offset:  command offset
2031     THOMSON_COMMAND_OFFSET + THOMSON_COMMAND_LEN,                       // command_end:     end of command
2032     THOMSON_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame
2033     THOMSON_STOP_BIT,                                                   // stop_bit:        flag: frame has stop bit
2034     THOMSON_LSB,                                                        // lsb_first:       flag: LSB first
2035     THOMSON_FLAGS                                                       // flags:           some flags
2036 };
2037
2038 #endif
2039
2040 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
2041
2042 static const PROGMEM IRMP_PARAMETER bose_param =
2043 {
2044     IRMP_BOSE_PROTOCOL,                                                 // protocol:        ir protocol
2045     BOSE_PULSE_LEN_MIN,                                                 // pulse_1_len_min: minimum length of pulse with bit value 1
2046     BOSE_PULSE_LEN_MAX,                                                 // pulse_1_len_max: maximum length of pulse with bit value 1
2047     BOSE_1_PAUSE_LEN_MIN,                                               // pause_1_len_min: minimum length of pause with bit value 1
2048     BOSE_1_PAUSE_LEN_MAX,                                               // pause_1_len_max: maximum length of pause with bit value 1
2049     BOSE_PULSE_LEN_MIN,                                                 // pulse_0_len_min: minimum length of pulse with bit value 0
2050     BOSE_PULSE_LEN_MAX,                                                 // pulse_0_len_max: maximum length of pulse with bit value 0
2051     BOSE_0_PAUSE_LEN_MIN,                                               // pause_0_len_min: minimum length of pause with bit value 0
2052     BOSE_0_PAUSE_LEN_MAX,                                               // pause_0_len_max: maximum length of pause with bit value 0
2053     BOSE_ADDRESS_OFFSET,                                                // address_offset:  address offset
2054     BOSE_ADDRESS_OFFSET + BOSE_ADDRESS_LEN,                             // address_end:     end of address
2055     BOSE_COMMAND_OFFSET,                                                // command_offset:  command offset
2056     BOSE_COMMAND_OFFSET + BOSE_COMMAND_LEN,                             // command_end:     end of command
2057     BOSE_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame
2058     BOSE_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit
2059     BOSE_LSB,                                                           // lsb_first:       flag: LSB first
2060     BOSE_FLAGS                                                          // flags:           some flags
2061 };
2062
2063 #endif
2064
2065 #if IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1
2066
2067 static const PROGMEM IRMP_PARAMETER a1tvbox_param =
2068 {
2069     IRMP_A1TVBOX_PROTOCOL,                                              // protocol:        ir protocol
2070
2071     A1TVBOX_BIT_PULSE_LEN_MIN,                                          // pulse_1_len_min: here: minimum length of short pulse
2072     A1TVBOX_BIT_PULSE_LEN_MAX,                                          // pulse_1_len_max: here: maximum length of short pulse
2073     A1TVBOX_BIT_PAUSE_LEN_MIN,                                          // pause_1_len_min: here: minimum length of short pause
2074     A1TVBOX_BIT_PAUSE_LEN_MAX,                                          // pause_1_len_max: here: maximum length of short pause
2075     0,                                                                  // pulse_0_len_min: here: not used
2076     0,                                                                  // pulse_0_len_max: here: not used
2077     0,                                                                  // pause_0_len_min: here: not used
2078     0,                                                                  // pause_0_len_max: here: not used
2079     A1TVBOX_ADDRESS_OFFSET,                                             // address_offset:  address offset
2080     A1TVBOX_ADDRESS_OFFSET + A1TVBOX_ADDRESS_LEN,                       // address_end:     end of address
2081     A1TVBOX_COMMAND_OFFSET,                                             // command_offset:  command offset
2082     A1TVBOX_COMMAND_OFFSET + A1TVBOX_COMMAND_LEN,                       // command_end:     end of command
2083     A1TVBOX_COMPLETE_DATA_LEN,                                          // complete_len:    complete length of frame
2084     A1TVBOX_STOP_BIT,                                                   // stop_bit:        flag: frame has stop bit
2085     A1TVBOX_LSB,                                                        // lsb_first:       flag: LSB first
2086     A1TVBOX_FLAGS                                                       // flags:           some flags
2087 };
2088
2089 #endif
2090
2091 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
2092
2093 static const PROGMEM IRMP_PARAMETER merlin_param =
2094 {
2095     IRMP_MERLIN_PROTOCOL,                                               // protocol:        ir protocol
2096
2097     MERLIN_BIT_PULSE_LEN_MIN,                                           // pulse_1_len_min: here: minimum length of short pulse
2098     MERLIN_BIT_PULSE_LEN_MAX,                                           // pulse_1_len_max: here: maximum length of short pulse
2099     MERLIN_BIT_PAUSE_LEN_MIN,                                           // pause_1_len_min: here: minimum length of short pause
2100     MERLIN_BIT_PAUSE_LEN_MAX,                                           // pause_1_len_max: here: maximum length of short pause
2101     0,                                                                  // pulse_0_len_min: here: not used
2102     0,                                                                  // pulse_0_len_max: here: not used
2103     0,                                                                  // pause_0_len_min: here: not used
2104     0,                                                                  // pause_0_len_max: here: not used
2105     MERLIN_ADDRESS_OFFSET,                                              // address_offset:  address offset
2106     MERLIN_ADDRESS_OFFSET + MERLIN_ADDRESS_LEN,                         // address_end:     end of address
2107     MERLIN_COMMAND_OFFSET,                                              // command_offset:  command offset
2108     MERLIN_COMMAND_OFFSET + MERLIN_COMMAND_LEN,                         // command_end:     end of command
2109     MERLIN_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2110     MERLIN_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2111     MERLIN_LSB,                                                         // lsb_first:       flag: LSB first
2112     MERLIN_FLAGS                                                        // flags:           some flags
2113 };
2114
2115 #endif
2116
2117 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
2118
2119 static const PROGMEM IRMP_PARAMETER ortek_param =
2120 {
2121     IRMP_ORTEK_PROTOCOL,                                                // protocol:        ir protocol
2122
2123     ORTEK_BIT_PULSE_LEN_MIN,                                            // pulse_1_len_min: here: minimum length of short pulse
2124     ORTEK_BIT_PULSE_LEN_MAX,                                            // pulse_1_len_max: here: maximum length of short pulse
2125     ORTEK_BIT_PAUSE_LEN_MIN,                                            // pause_1_len_min: here: minimum length of short pause
2126     ORTEK_BIT_PAUSE_LEN_MAX,                                            // pause_1_len_max: here: maximum length of short pause
2127     0,                                                                  // pulse_0_len_min: here: not used
2128     0,                                                                  // pulse_0_len_max: here: not used
2129     0,                                                                  // pause_0_len_min: here: not used
2130     0,                                                                  // pause_0_len_max: here: not used
2131     ORTEK_ADDRESS_OFFSET,                                               // address_offset:  address offset
2132     ORTEK_ADDRESS_OFFSET + ORTEK_ADDRESS_LEN,                           // address_end:     end of address
2133     ORTEK_COMMAND_OFFSET,                                               // command_offset:  command offset
2134     ORTEK_COMMAND_OFFSET + ORTEK_COMMAND_LEN,                           // command_end:     end of command
2135     ORTEK_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
2136     ORTEK_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
2137     ORTEK_LSB,                                                          // lsb_first:       flag: LSB first
2138     ORTEK_FLAGS                                                         // flags:           some flags
2139 };
2140
2141 #endif
2142
2143 #if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1
2144
2145 static const PROGMEM IRMP_PARAMETER roomba_param =
2146 {
2147     IRMP_ROOMBA_PROTOCOL,                                               // protocol:        ir protocol
2148     ROOMBA_1_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1
2149     ROOMBA_1_PULSE_LEN_MAX,                                             // pulse_1_len_max: maximum length of pulse with bit value 1
2150     ROOMBA_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
2151     ROOMBA_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
2152     ROOMBA_0_PULSE_LEN_MIN,                                             // pulse_0_len_min: minimum length of pulse with bit value 0
2153     ROOMBA_0_PULSE_LEN_MAX,                                             // pulse_0_len_max: maximum length of pulse with bit value 0
2154     ROOMBA_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
2155     ROOMBA_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
2156     ROOMBA_ADDRESS_OFFSET,                                              // address_offset:  address offset
2157     ROOMBA_ADDRESS_OFFSET + ROOMBA_ADDRESS_LEN,                         // address_end:     end of address
2158     ROOMBA_COMMAND_OFFSET,                                              // command_offset:  command offset
2159     ROOMBA_COMMAND_OFFSET + ROOMBA_COMMAND_LEN,                         // command_end:     end of command
2160     ROOMBA_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2161     ROOMBA_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2162     ROOMBA_LSB,                                                         // lsb_first:       flag: LSB first
2163     ROOMBA_FLAGS                                                        // flags:           some flags
2164 };
2165
2166 #endif
2167
2168 #if IRMP_SUPPORT_RCMM_PROTOCOL == 1
2169
2170 static const PROGMEM IRMP_PARAMETER rcmm_param =
2171 {
2172     IRMP_RCMM32_PROTOCOL,                                               // protocol:        ir protocol
2173
2174     RCMM32_BIT_PULSE_LEN_MIN,                                           // pulse_1_len_min: here: minimum length of short pulse
2175     RCMM32_BIT_PULSE_LEN_MAX,                                           // pulse_1_len_max: here: maximum length of short pulse
2176     0,                                                                  // pause_1_len_min: here: minimum length of short pause
2177     0,                                                                  // pause_1_len_max: here: maximum length of short pause
2178     RCMM32_BIT_PULSE_LEN_MIN,                                           // pulse_0_len_min: here: not used
2179     RCMM32_BIT_PULSE_LEN_MAX,                                           // pulse_0_len_max: here: not used
2180     0,                                                                  // pause_0_len_min: here: not used
2181     0,                                                                  // pause_0_len_max: here: not used
2182     RCMM32_ADDRESS_OFFSET,                                              // address_offset:  address offset
2183     RCMM32_ADDRESS_OFFSET + RCMM32_ADDRESS_LEN,                         // address_end:     end of address
2184     RCMM32_COMMAND_OFFSET,                                              // command_offset:  command offset
2185     RCMM32_COMMAND_OFFSET + RCMM32_COMMAND_LEN,                         // command_end:     end of command
2186     RCMM32_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2187     RCMM32_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2188     RCMM32_LSB,                                                         // lsb_first:       flag: LSB first
2189     RCMM32_FLAGS                                                        // flags:           some flags
2190 };
2191
2192 #endif
2193
2194 #if IRMP_SUPPORT_PENTAX_PROTOCOL == 1
2195
2196 static const PROGMEM IRMP_PARAMETER pentax_param =
2197 {
2198     IRMP_PENTAX_PROTOCOL,                                               // protocol:        ir protocol
2199     PENTAX_PULSE_LEN_MIN,                                               // pulse_1_len_min: minimum length of pulse with bit value 1
2200     PENTAX_PULSE_LEN_MAX,                                               // pulse_1_len_max: maximum length of pulse with bit value 1
2201     PENTAX_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
2202     PENTAX_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
2203     PENTAX_PULSE_LEN_MIN,                                               // pulse_0_len_min: minimum length of pulse with bit value 0
2204     PENTAX_PULSE_LEN_MAX,                                               // pulse_0_len_max: maximum length of pulse with bit value 0
2205     PENTAX_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
2206     PENTAX_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
2207     PENTAX_ADDRESS_OFFSET,                                              // address_offset:  address offset
2208     PENTAX_ADDRESS_OFFSET + PENTAX_ADDRESS_LEN,                         // address_end:     end of address
2209     PENTAX_COMMAND_OFFSET,                                              // command_offset:  command offset
2210     PENTAX_COMMAND_OFFSET + PENTAX_COMMAND_LEN,                         // command_end:     end of command
2211     PENTAX_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2212     PENTAX_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2213     PENTAX_LSB,                                                         // lsb_first:       flag: LSB first
2214     PENTAX_FLAGS                                                        // flags:           some flags
2215 };
2216
2217 #endif
2218
2219 #if IRMP_SUPPORT_ACP24_PROTOCOL == 1
2220
2221 static const PROGMEM IRMP_PARAMETER acp24_param =
2222 {
2223     IRMP_ACP24_PROTOCOL,                                                // protocol:        ir protocol
2224     ACP24_PULSE_LEN_MIN,                                                // pulse_1_len_min: minimum length of pulse with bit value 1
2225     ACP24_PULSE_LEN_MAX,                                                // pulse_1_len_max: maximum length of pulse with bit value 1
2226     ACP24_1_PAUSE_LEN_MIN,                                              // pause_1_len_min: minimum length of pause with bit value 1
2227     ACP24_1_PAUSE_LEN_MAX,                                              // pause_1_len_max: maximum length of pause with bit value 1
2228     ACP24_PULSE_LEN_MIN,                                                // pulse_0_len_min: minimum length of pulse with bit value 0
2229     ACP24_PULSE_LEN_MAX,                                                // pulse_0_len_max: maximum length of pulse with bit value 0
2230     ACP24_0_PAUSE_LEN_MIN,                                              // pause_0_len_min: minimum length of pause with bit value 0
2231     ACP24_0_PAUSE_LEN_MAX,                                              // pause_0_len_max: maximum length of pause with bit value 0
2232     ACP24_ADDRESS_OFFSET,                                               // address_offset:  address offset
2233     ACP24_ADDRESS_OFFSET + ACP24_ADDRESS_LEN,                           // address_end:     end of address
2234     ACP24_COMMAND_OFFSET,                                               // command_offset:  command offset
2235     ACP24_COMMAND_OFFSET + ACP24_COMMAND_LEN,                           // command_end:     end of command
2236     ACP24_COMPLETE_DATA_LEN,                                            // complete_len:    complete length of frame
2237     ACP24_STOP_BIT,                                                     // stop_bit:        flag: frame has stop bit
2238     ACP24_LSB,                                                          // lsb_first:       flag: LSB first
2239     ACP24_FLAGS                                                         // flags:           some flags
2240 };
2241
2242 #endif
2243
2244 #if IRMP_SUPPORT_METZ_PROTOCOL == 1
2245
2246 static const PROGMEM IRMP_PARAMETER metz_param =
2247 {
2248     IRMP_METZ_PROTOCOL,                                                 // protocol:        ir protocol
2249     METZ_PULSE_LEN_MIN,                                                 // pulse_1_len_min: minimum length of pulse with bit value 1
2250     METZ_PULSE_LEN_MAX,                                                 // pulse_1_len_max: maximum length of pulse with bit value 1
2251     METZ_1_PAUSE_LEN_MIN,                                               // pause_1_len_min: minimum length of pause with bit value 1
2252     METZ_1_PAUSE_LEN_MAX,                                               // pause_1_len_max: maximum length of pause with bit value 1
2253     METZ_PULSE_LEN_MIN,                                                 // pulse_0_len_min: minimum length of pulse with bit value 0
2254     METZ_PULSE_LEN_MAX,                                                 // pulse_0_len_max: maximum length of pulse with bit value 0
2255     METZ_0_PAUSE_LEN_MIN,                                               // pause_0_len_min: minimum length of pause with bit value 0
2256     METZ_0_PAUSE_LEN_MAX,                                               // pause_0_len_max: maximum length of pause with bit value 0
2257     METZ_ADDRESS_OFFSET,                                                // address_offset:  address offset
2258     METZ_ADDRESS_OFFSET + METZ_ADDRESS_LEN,                             // address_end:     end of address
2259     METZ_COMMAND_OFFSET,                                                // command_offset:  command offset
2260     METZ_COMMAND_OFFSET + METZ_COMMAND_LEN,                             // command_end:     end of command
2261     METZ_COMPLETE_DATA_LEN,                                             // complete_len:    complete length of frame
2262     METZ_STOP_BIT,                                                      // stop_bit:        flag: frame has stop bit
2263     METZ_LSB,                                                           // lsb_first:       flag: LSB first
2264     METZ_FLAGS                                                          // flags:           some flags
2265 };
2266
2267 #endif
2268
2269 #if IRMP_SUPPORT_RADIO1_PROTOCOL == 1
2270
2271 static const PROGMEM IRMP_PARAMETER radio1_param =
2272 {
2273     IRMP_RADIO1_PROTOCOL,                                               // protocol:        ir protocol
2274
2275     RADIO1_1_PULSE_LEN_MIN,                                             // pulse_1_len_min: minimum length of pulse with bit value 1
2276     RADIO1_1_PULSE_LEN_MAX,                                             // pulse_1_len_max: maximum length of pulse with bit value 1
2277     RADIO1_1_PAUSE_LEN_MIN,                                             // pause_1_len_min: minimum length of pause with bit value 1
2278     RADIO1_1_PAUSE_LEN_MAX,                                             // pause_1_len_max: maximum length of pause with bit value 1
2279     RADIO1_0_PULSE_LEN_MIN,                                             // pulse_0_len_min: minimum length of pulse with bit value 0
2280     RADIO1_0_PULSE_LEN_MAX,                                             // pulse_0_len_max: maximum length of pulse with bit value 0
2281     RADIO1_0_PAUSE_LEN_MIN,                                             // pause_0_len_min: minimum length of pause with bit value 0
2282     RADIO1_0_PAUSE_LEN_MAX,                                             // pause_0_len_max: maximum length of pause with bit value 0
2283     RADIO1_ADDRESS_OFFSET,                                              // address_offset:  address offset
2284     RADIO1_ADDRESS_OFFSET + RADIO1_ADDRESS_LEN,                         // address_end:     end of address
2285     RADIO1_COMMAND_OFFSET,                                              // command_offset:  command offset
2286     RADIO1_COMMAND_OFFSET + RADIO1_COMMAND_LEN,                         // command_end:     end of command
2287     RADIO1_COMPLETE_DATA_LEN,                                           // complete_len:    complete length of frame
2288     RADIO1_STOP_BIT,                                                    // stop_bit:        flag: frame has stop bit
2289     RADIO1_LSB,                                                         // lsb_first:       flag: LSB first
2290     RADIO1_FLAGS                                                        // flags:           some flags
2291 };
2292
2293 #endif
2294
2295 static uint_fast8_t                             irmp_bit;                   // current bit position
2296 static IRMP_PARAMETER                           irmp_param;
2297
2298 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2299 static IRMP_PARAMETER                           irmp_param2;
2300 #endif
2301
2302 static volatile uint_fast8_t                    irmp_ir_detected = FALSE;
2303 static volatile uint_fast8_t                    irmp_protocol;
2304 static volatile uint_fast16_t                   irmp_address;
2305 #if IRMP_32_BIT == 1
2306 static volatile uint_fast32_t                   irmp_command;
2307 #else
2308 static volatile uint_fast16_t                   irmp_command;
2309 #endif
2310 static volatile uint_fast16_t                   irmp_id;                // only used for SAMSUNG protocol
2311 static volatile uint_fast8_t                    irmp_flags;
2312 // static volatile uint_fast8_t                 irmp_busy_flag;
2313
2314 #if defined(__MBED__)
2315 // DigitalIn inputPin(IRMP_PIN, PullUp);                                // this requires mbed.h and source to be compiled as cpp
2316 gpio_t                                          gpioIRin;               // use low level c function instead
2317 #endif
2318
2319
2320 #ifdef ANALYZE
2321 #define input(x)                                (x)
2322 static uint_fast8_t                             IRMP_PIN;
2323 static uint_fast8_t                             radio;
2324 #endif
2325
2326 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2327  *  Initialize IRMP decoder
2328  *  @details  Configures IRMP input pin
2329  *---------------------------------------------------------------------------------------------------------------------------------------------------
2330  */
2331 #ifndef ANALYZE
2332 void
2333 irmp_init (void)
2334 {
2335 #if defined(PIC_CCS) || defined(PIC_C18)                                // PIC: do nothing
2336 #elif defined (ARM_STM32_HAL)                                           // STM32 with Hal Library: do nothing
2337 #elif defined (ARM_STM32)                                               // STM32
2338     GPIO_InitTypeDef     GPIO_InitStructure;
2339
2340     /* GPIOx clock enable */
2341 #  if defined (ARM_STM32L1XX)
2342     RCC_AHBPeriphClockCmd(IRMP_PORT_RCC, ENABLE);
2343 #  elif defined (ARM_STM32F10X)
2344     RCC_APB2PeriphClockCmd(IRMP_PORT_RCC, ENABLE);
2345 #  elif defined (ARM_STM32F4XX)
2346     RCC_AHB1PeriphClockCmd(IRMP_PORT_RCC, ENABLE);
2347 #  endif
2348
2349     /* GPIO Configuration */
2350     GPIO_InitStructure.GPIO_Pin = IRMP_BIT;
2351 #  if defined (ARM_STM32L1XX) || defined (ARM_STM32F4XX)
2352     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
2353     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
2354     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
2355     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
2356 #  elif defined (ARM_STM32F10X)
2357     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
2358     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
2359 #  endif
2360     GPIO_Init(IRMP_PORT, &GPIO_InitStructure);
2361
2362 #elif defined(STELLARIS_ARM_CORTEX_M4)
2363     // Enable the GPIO port
2364     ROM_SysCtlPeripheralEnable(IRMP_PORT_PERIPH);
2365
2366     // Set as an input
2367     ROM_GPIODirModeSet(IRMP_PORT_BASE, IRMP_PORT_PIN, GPIO_DIR_MODE_IN);
2368     ROM_GPIOPadConfigSet(IRMP_PORT_BASE, IRMP_PORT_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
2369
2370 #elif defined(__SDCC_stm8)                                              // STM8
2371     IRMP_GPIO_STRUCT->DDR &= ~(1<<IRMP_BIT);                            // pin is input
2372     IRMP_GPIO_STRUCT->CR1 |= (1<<IRMP_BIT);                             // activate pullup
2373
2374 #elif defined (TEENSY_ARM_CORTEX_M4)                                    // TEENSY
2375     pinMode(IRMP_PIN, INPUT);
2376
2377 #elif defined(__xtensa__)                                               // ESP8266
2378     pinMode(IRMP_BIT_NUMBER, INPUT);
2379                                                                         // select pin function
2380 #  if (IRMP_BIT_NUMBER == 12)
2381     PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
2382 //  doesn't work for me:
2383 //  # elif (IRMP_BIT_NUMBER == 13)
2384 //  PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U , FUNC_GPIO13);
2385 #  else
2386 #   warning Please add PIN_FUNC_SELECT when necessary.
2387 #  endif
2388     GPIO_DIS_OUTPUT(IRMP_BIT_NUMBER);
2389
2390 #elif defined(__MBED__)
2391     gpio_init_in_ex(&gpioIRin, IRMP_PIN, IRMP_PINMODE);                 // initialize input for IR diode
2392
2393 #elif defined(_CHIBIOS_HAL_)
2394     // ChibiOS HAL automatically initializes all pins according to the board config file, no need to repeat here
2395
2396 #else                                                                   // AVR
2397     IRMP_PORT &= ~(1<<IRMP_BIT);                                        // deactivate pullup
2398     IRMP_DDR &= ~(1<<IRMP_BIT);                                         // set pin to input
2399 #endif
2400
2401 #if IRMP_LOGGING == 1
2402     irmp_uart_init ();
2403 #endif
2404 }
2405 #endif
2406 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2407  *  Get IRMP data
2408  *  @details  gets decoded IRMP data
2409  *  @param    pointer in order to store IRMP data
2410  *  @return    TRUE: successful, FALSE: failed
2411  *---------------------------------------------------------------------------------------------------------------------------------------------------
2412  */
2413 uint_fast8_t
2414 irmp_get_data (IRMP_DATA * irmp_data_p)
2415 {
2416     uint_fast8_t   rtc = FALSE;
2417 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
2418     uint_fast8_t   cmd_len = 0;
2419 #endif
2420
2421     if (irmp_ir_detected)
2422     {
2423         switch (irmp_protocol)
2424         {
2425 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2426             case IRMP_SAMSUNG_PROTOCOL:
2427                 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
2428                 {
2429                     irmp_command &= 0xff;
2430                     irmp_command |= irmp_id << 8;
2431                     rtc = TRUE;
2432                 }
2433                 break;
2434
2435 #if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1
2436             case IRMP_SAMSUNG48_PROTOCOL:
2437                 irmp_command = (irmp_command & 0x00FF) | ((irmp_id & 0x00FF) << 8);
2438                 rtc = TRUE;
2439                 break;
2440 #endif
2441 #endif
2442
2443 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2444             case IRMP_NEC_PROTOCOL:
2445                 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
2446                 {
2447                     irmp_command &= 0xff;
2448                     rtc = TRUE;
2449                 }
2450                 else if (irmp_address == 0x87EE)
2451                 {
2452 #ifdef ANALYZE
2453                     ANALYZE_PRINTF ("Switching to APPLE protocol\n");
2454 #endif // ANALYZE
2455                     irmp_protocol = IRMP_APPLE_PROTOCOL;
2456                     irmp_address = (irmp_command & 0xFF00) >> 8;
2457                     irmp_command &= 0x00FF;
2458                     rtc = TRUE;
2459                 }
2460                 else
2461                 {
2462 #ifdef ANALYZE
2463                     ANALYZE_PRINTF ("Switching to ONKYO protocol\n");
2464 #endif // ANALYZE
2465                     irmp_protocol = IRMP_ONKYO_PROTOCOL;
2466                     rtc = TRUE;
2467                 }
2468                 break;
2469 #endif
2470
2471
2472 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2473             case IRMP_VINCENT_PROTOCOL:
2474                 if ((irmp_command >> 8) == (irmp_command & 0x00FF))
2475                 {
2476                     irmp_command &= 0xff;
2477                     rtc = TRUE;
2478                 }
2479                 break;
2480 #endif
2481
2482 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
2483             case IRMP_BOSE_PROTOCOL:
2484                 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
2485                 {
2486                     irmp_command &= 0xff;
2487                     rtc = TRUE;
2488                 }
2489                 break;
2490 #endif
2491
2492 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
2493             case IRMP_MERLIN_PROTOCOL:
2494                 if (irmp_bit == 10)
2495                 {
2496                     rtc = TRUE;
2497                 }
2498                 else if (irmp_bit >= 19 && ((irmp_bit - 3) % 8 == 0))
2499                 {
2500                     if (((irmp_command >> 1) & 1) != (irmp_command & 1))
2501                     {
2502                         irmp_command >>= 1;
2503                         irmp_command |= ((irmp_address & 1) << (irmp_bit - 12));
2504                         irmp_address >>= 1;
2505                         cmd_len = (irmp_bit - 11) >> 3;
2506                         rtc = TRUE;
2507                     }
2508                 }
2509                 break;
2510 #endif
2511
2512 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2513             case IRMP_SIEMENS_PROTOCOL:
2514             case IRMP_RUWIDO_PROTOCOL:
2515                 if (((irmp_command >> 1) & 0x0001) == (~irmp_command & 0x0001))
2516                 {
2517                     irmp_command >>= 1;
2518                     rtc = TRUE;
2519                 }
2520                 break;
2521 #endif
2522 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2523             case IRMP_KATHREIN_PROTOCOL:
2524                 if (irmp_command != 0x0000)
2525                 {
2526                     rtc = TRUE;
2527                 }
2528                 break;
2529 #endif
2530 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
2531             case IRMP_RC5_PROTOCOL:
2532                 irmp_address &= ~0x20;                              // clear toggle bit
2533                 rtc = TRUE;
2534                 break;
2535 #endif
2536 #if IRMP_SUPPORT_S100_PROTOCOL == 1
2537             case IRMP_S100_PROTOCOL:
2538                 irmp_address &= ~0x20;                              // clear toggle bit
2539                 rtc = TRUE;
2540                 break;
2541 #endif
2542 #if IRMP_SUPPORT_IR60_PROTOCOL == 1
2543             case IRMP_IR60_PROTOCOL:
2544                 if (irmp_command != 0x007d)                         // 0x007d (== 62<<1 + 1) is start instruction frame
2545                 {
2546                     rtc = TRUE;
2547                 }
2548                 else
2549                 {
2550 #ifdef ANALYZE
2551                     ANALYZE_PRINTF("Info IR60: got start instruction frame\n");
2552 #endif // ANALYZE
2553                 }
2554                 break;
2555 #endif
2556 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2557             case IRMP_RCCAR_PROTOCOL:
2558                 // frame in irmp_data:
2559                 // Bit 12 11 10 9  8  7  6  5  4  3  2  1  0
2560                 //     V  D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0   //         10 9  8  7  6  5  4  3  2  1  0
2561                 irmp_address = (irmp_command & 0x000C) >> 2;    // addr:   0  0  0  0  0  0  0  0  0  A1 A0
2562                 irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit:  V  0  0  0  0  0  0  0  0  0  0
2563                                ((irmp_command & 0x0003) << 8) | // C-Bits: 0  C1 C0 0  0  0  0  0  0  0  0
2564                                ((irmp_command & 0x0FF0) >> 4);  // D-Bits:          D7 D6 D5 D4 D3 D2 D1 D0
2565                 rtc = TRUE;                                     // Summe:  V  C1 C0 D7 D6 D5 D4 D3 D2 D1 D0
2566                 break;
2567 #endif
2568
2569 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1                           // squeeze code to 8 bit, upper bit indicates release-key
2570             case IRMP_NETBOX_PROTOCOL:
2571                 if (irmp_command & 0x1000)                      // last bit set?
2572                 {
2573                     if ((irmp_command & 0x1f) == 0x15)          // key pressed: 101 01 (LSB)
2574                     {
2575                         irmp_command >>= 5;
2576                         irmp_command &= 0x7F;
2577                         rtc = TRUE;
2578                     }
2579                     else if ((irmp_command & 0x1f) == 0x10)     // key released: 000 01 (LSB)
2580                     {
2581                         irmp_command >>= 5;
2582                         irmp_command |= 0x80;
2583                         rtc = TRUE;
2584                     }
2585                     else
2586                     {
2587 #ifdef ANALYZE
2588                         ANALYZE_PRINTF("error NETBOX: bit6/7 must be 0/1\n");
2589 #endif // ANALYZE
2590                     }
2591                 }
2592                 else
2593                 {
2594 #ifdef ANALYZE
2595                     ANALYZE_PRINTF("error NETBOX: last bit not set\n");
2596 #endif // ANALYZE
2597                 }
2598                 break;
2599 #endif
2600 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
2601             case IRMP_LEGO_PROTOCOL:
2602             {
2603                 uint_fast8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4);
2604
2605                 if ((irmp_command & 0x000F) == crc)
2606                 {
2607                     irmp_command >>= 4;
2608                     rtc = TRUE;
2609                 }
2610                 else
2611                 {
2612 #ifdef ANALYZE
2613                     ANALYZE_PRINTF ("CRC error in LEGO protocol\n");
2614 #endif // ANALYZE
2615                     // rtc = TRUE;                              // don't accept codes with CRC errors
2616                 }
2617                 break;
2618             }
2619 #endif
2620
2621 #if IRMP_SUPPORT_METZ_PROTOCOL == 1
2622             case IRMP_METZ_PROTOCOL:
2623                 irmp_address &= ~0x40;                              // clear toggle bit
2624                 if (((~irmp_address) & 0x07) == (irmp_address >> 3) && ((~irmp_command) & 0x3f) == (irmp_command >> 6))
2625                 {
2626                     irmp_address >>= 3;
2627                     irmp_command >>= 6;
2628                     rtc = TRUE;
2629                 }
2630                 break;
2631 #endif
2632             default:
2633             {
2634                 rtc = TRUE;
2635                 break;
2636             }
2637         }
2638
2639         if (rtc)
2640         {
2641             irmp_data_p->protocol = irmp_protocol;
2642             irmp_data_p->address  = irmp_address;
2643             irmp_data_p->command  = irmp_command;
2644             irmp_data_p->flags    = irmp_flags;
2645 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
2646             irmp_data_p->flags   |= cmd_len;
2647 #endif
2648         }
2649         else
2650         {
2651             irmp_protocol = IRMP_UNKNOWN_PROTOCOL;
2652         }
2653
2654         irmp_command  = 0;                                      // don't reset irmp_protocol here, needed for detection of NEC & JVC repetition frames!
2655         irmp_address  = 0;
2656         irmp_flags    = 0;
2657
2658         irmp_ir_detected = FALSE;
2659     }
2660
2661     return rtc;
2662 }
2663
2664 #if IRMP_USE_CALLBACK == 1
2665 void
2666 irmp_set_callback_ptr (void (*cb)(uint_fast8_t))
2667 {
2668     irmp_callback_ptr = cb;
2669 }
2670 #endif // IRMP_USE_CALLBACK == 1
2671
2672 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
2673 static uint_fast16_t irmp_tmp_address;                                      // ir address
2674 #if IRMP_32_BIT == 1
2675 static uint_fast32_t irmp_tmp_command;                                      // ir command
2676 #else
2677 static uint_fast16_t irmp_tmp_command;                                      // ir command
2678 #endif
2679
2680 #if (IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
2681 static uint_fast16_t irmp_tmp_address2;                                     // ir address
2682 static uint_fast16_t irmp_tmp_command2;                                     // ir command
2683 #endif
2684
2685 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
2686 static uint_fast16_t irmp_lgair_address;                                    // ir address
2687 static uint_fast16_t irmp_lgair_command;                                    // ir command
2688 #endif
2689
2690 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2691 static uint_fast16_t irmp_tmp_id;                                           // ir id (only SAMSUNG)
2692 #endif
2693 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
2694 static uint8_t      xor_check[6];                                           // check kaseikyo "parity" bits
2695 static uint_fast8_t genre2;                                                 // save genre2 bits here, later copied to MSB in flags
2696 #endif
2697
2698 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
2699 static uint_fast8_t  parity;                                                // number of '1' of the first 14 bits, check if even.
2700 #endif
2701
2702 #if IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
2703 static uint_fast8_t  check;                                                 // number of '1' of the first 14 bits, check if even.
2704 static uint_fast8_t  mitsu_parity;                                          // number of '1' of the first 14 bits, check if even.
2705 #endif
2706
2707 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2708  *  store bit
2709  *  @details  store bit in temp address or temp command
2710  *  @param    value to store: 0 or 1
2711  *---------------------------------------------------------------------------------------------------------------------------------------------------
2712  */
2713 // verhindert, dass irmp_store_bit() inline compiliert wird:
2714 // static void irmp_store_bit (uint_fast8_t) __attribute__ ((noinline));
2715
2716 static void
2717 irmp_store_bit (uint_fast8_t value)
2718 {
2719 #if IRMP_SUPPORT_ACP24_PROTOCOL == 1
2720     if (irmp_param.protocol == IRMP_ACP24_PROTOCOL)                                                 // squeeze 64 bits into 16 bits:
2721     {
2722         if (value)
2723         {
2724             // ACP24-Frame:
2725             //           1         2         3         4         5         6
2726             // 0123456789012345678901234567890123456789012345678901234567890123456789
2727             // N VVMMM    ? ???    t vmA x                 y                     TTTT
2728             //
2729             // irmp_data_p->command:
2730             //
2731             //         5432109876543210
2732             //         NAVVvMMMmtxyTTTT
2733
2734             switch (irmp_bit)
2735             {
2736                 case  0: irmp_tmp_command |= (1<<15); break;                                        // N
2737                 case  2: irmp_tmp_command |= (1<<13); break;                                        // V
2738                 case  3: irmp_tmp_command |= (1<<12); break;                                        // V
2739                 case  4: irmp_tmp_command |= (1<<10); break;                                        // M
2740                 case  5: irmp_tmp_command |= (1<< 9); break;                                        // M
2741                 case  6: irmp_tmp_command |= (1<< 8); break;                                        // M
2742                 case 20: irmp_tmp_command |= (1<< 6); break;                                        // t
2743                 case 22: irmp_tmp_command |= (1<<11); break;                                        // v
2744                 case 23: irmp_tmp_command |= (1<< 7); break;                                        // m
2745                 case 24: irmp_tmp_command |= (1<<14); break;                                        // A
2746                 case 26: irmp_tmp_command |= (1<< 5); break;                                        // x
2747                 case 44: irmp_tmp_command |= (1<< 4); break;                                        // y
2748                 case 66: irmp_tmp_command |= (1<< 3); break;                                        // T
2749                 case 67: irmp_tmp_command |= (1<< 2); break;                                        // T
2750                 case 68: irmp_tmp_command |= (1<< 1); break;                                        // T
2751                 case 69: irmp_tmp_command |= (1<< 0); break;                                        // T
2752             }
2753         }
2754     }
2755     else
2756 #endif // IRMP_SUPPORT_ACP24_PROTOCOL
2757
2758 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
2759     if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL)
2760     {
2761         if (irmp_bit < 14)
2762         {
2763             if (value)
2764             {
2765                 parity++;
2766             }
2767         }
2768         else if (irmp_bit == 14)
2769         {
2770             if (value)                                                                                      // value == 1: even parity
2771             {
2772                 if (parity & 0x01)
2773                 {
2774                     parity = PARITY_CHECK_FAILED;
2775                 }
2776                 else
2777                 {
2778                     parity = PARITY_CHECK_OK;
2779                 }
2780             }
2781             else
2782             {
2783                 if (parity & 0x01)                                                                          // value == 0: odd parity
2784                 {
2785                     parity = PARITY_CHECK_OK;
2786                 }
2787                 else
2788                 {
2789                     parity = PARITY_CHECK_FAILED;
2790                 }
2791             }
2792         }
2793     }
2794     else
2795 #endif
2796     {
2797         ;
2798     }
2799
2800 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2801     if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL)
2802     {
2803         first_bit = value;
2804     }
2805     else
2806 #endif
2807
2808     if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end)
2809     {
2810         if (irmp_param.lsb_first)
2811         {
2812             irmp_tmp_address |= (((uint_fast16_t) (value)) << (irmp_bit - irmp_param.address_offset));   // CV wants cast
2813         }
2814         else
2815         {
2816             irmp_tmp_address <<= 1;
2817             irmp_tmp_address |= value;
2818         }
2819     }
2820     else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end)
2821     {
2822         if (irmp_param.lsb_first)
2823         {
2824 #if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1
2825             if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit >= 32)
2826             {
2827                 irmp_tmp_id |= (((uint_fast16_t) (value)) << (irmp_bit - 32));   // CV wants cast
2828             }
2829             else
2830 #endif
2831             {
2832                 irmp_tmp_command |= (((uint_fast16_t) (value)) << (irmp_bit - irmp_param.command_offset));   // CV wants cast
2833             }
2834         }
2835         else
2836         {
2837             irmp_tmp_command <<= 1;
2838             irmp_tmp_command |= value;
2839         }
2840     }
2841
2842 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
2843     if (irmp_param.protocol == IRMP_NEC_PROTOCOL || irmp_param.protocol == IRMP_NEC42_PROTOCOL)
2844     {
2845         if (irmp_bit < 8)
2846         {
2847             irmp_lgair_address <<= 1;                                                               // LGAIR uses MSB
2848             irmp_lgair_address |= value;
2849         }
2850         else if (irmp_bit < 24)
2851         {
2852             irmp_lgair_command <<= 1;                                                               // LGAIR uses MSB
2853             irmp_lgair_command |= value;
2854         }
2855     }
2856     // NO else!
2857 #endif
2858
2859 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
2860     if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit >= 13 && irmp_bit < 26)
2861     {
2862         irmp_tmp_address2 |= (((uint_fast16_t) (value)) << (irmp_bit - 13));                             // CV wants cast
2863     }
2864     else
2865 #endif
2866
2867 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2868     if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
2869     {
2870         irmp_tmp_id |= (((uint_fast16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET));                    // store with LSB first
2871     }
2872     else
2873 #endif
2874
2875 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
2876     if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
2877     {
2878         if (irmp_bit >= 20 && irmp_bit < 24)
2879         {
2880             irmp_tmp_command |= (((uint_fast16_t) (value)) << (irmp_bit - 8));      // store 4 system bits (genre 1) in upper nibble with LSB first
2881         }
2882         else if (irmp_bit >= 24 && irmp_bit < 28)
2883         {
2884             genre2 |= (((uint_fast8_t) (value)) << (irmp_bit - 20));                // store 4 system bits (genre 2) in upper nibble with LSB first
2885         }
2886
2887         if (irmp_bit < KASEIKYO_COMPLETE_DATA_LEN)
2888         {
2889             if (value)
2890             {
2891                 xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8);
2892             }
2893             else
2894             {
2895                 xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8));
2896             }
2897         }
2898     }
2899     else
2900 #endif
2901
2902 #if IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
2903     if (irmp_param.protocol == IRMP_MITSU_HEAVY_PROTOCOL)                           // squeeze 64 bits into 16 bits:
2904     {
2905         if (irmp_bit == 72 )
2906         {                                                                           // irmp_tmp_address, irmp_tmp_command received: check parity & compress
2907             mitsu_parity = PARITY_CHECK_OK;
2908
2909             check = irmp_tmp_address >> 8;                                          // inverted upper byte == lower byte?
2910             check = ~ check;
2911
2912             if (check == (irmp_tmp_address & 0xFF))
2913             {                                                                       // ok:
2914                 irmp_tmp_address <<= 8;                                             // throw away upper byte
2915             }
2916             else
2917             {
2918                 mitsu_parity = PARITY_CHECK_FAILED;
2919             }
2920
2921             check = irmp_tmp_command >> 8;                                          // inverted upper byte == lower byte?
2922             check = ~ check;
2923             if (check == (irmp_tmp_command & 0xFF))
2924             {                                                                       // ok:  pack together
2925                 irmp_tmp_address |= irmp_tmp_command & 0xFF;                        // byte 1, byte2 in irmp_tmp_address, irmp_tmp_command can be used for byte 3
2926             }
2927             else
2928             {
2929                 mitsu_parity = PARITY_CHECK_FAILED;
2930             }
2931             irmp_tmp_command = 0;
2932         }
2933
2934         if (irmp_bit >= 72 )
2935         {                                                                           // receive 3. word in irmp_tmp_command
2936             irmp_tmp_command <<= 1;
2937             irmp_tmp_command |= value;
2938         }
2939     }
2940     else
2941 #endif // IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL
2942     {
2943         ;
2944     }
2945
2946     irmp_bit++;
2947 }
2948
2949 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2950  *  store bit
2951  *  @details  store bit in temp address or temp command
2952  *  @param    value to store: 0 or 1
2953  *---------------------------------------------------------------------------------------------------------------------------------------------------
2954  */
2955 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2956 static void
2957 irmp_store_bit2 (uint_fast8_t value)
2958 {
2959     uint_fast8_t irmp_bit2;
2960
2961     if (irmp_param.protocol)
2962     {
2963         irmp_bit2 = irmp_bit - 2;
2964     }
2965     else
2966     {
2967         irmp_bit2 = irmp_bit - 1;
2968     }
2969
2970     if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end)
2971     {
2972         irmp_tmp_address2 |= (((uint_fast16_t) (value)) << (irmp_bit2 - irmp_param2.address_offset));   // CV wants cast
2973     }
2974     else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end)
2975     {
2976         irmp_tmp_command2 |= (((uint_fast16_t) (value)) << (irmp_bit2 - irmp_param2.command_offset));   // CV wants cast
2977     }
2978 }
2979 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2980
2981 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2982  *  ISR routine
2983  *  @details  ISR routine, called 10000 times per second
2984  *---------------------------------------------------------------------------------------------------------------------------------------------------
2985  */
2986 uint_fast8_t
2987 irmp_ISR (void)
2988 {
2989     static uint_fast8_t     irmp_start_bit_detected;                                // flag: start bit detected
2990     static uint_fast8_t     wait_for_space;                                         // flag: wait for data bit space
2991     static uint_fast8_t     wait_for_start_space;                                   // flag: wait for start bit space
2992     static uint_fast8_t     irmp_pulse_time;                                        // count bit time for pulse
2993     static PAUSE_LEN        irmp_pause_time;                                        // count bit time for pause
2994     static uint_fast16_t    last_irmp_address = 0xFFFF;                             // save last irmp address to recognize key repetition
2995 #if IRMP_32_BIT == 1
2996     static uint_fast32_t    last_irmp_command = 0xFFFFFFFF;                         // save last irmp command to recognize key repetition
2997 #else
2998     static uint_fast16_t    last_irmp_command = 0xFFFF;                             // save last irmp command to recognize key repetition
2999 #endif
3000     static uint_fast16_t    key_repetition_len;                                     // SIRCS repeats frame 2-5 times with 45 ms pause
3001     static uint_fast8_t     repetition_frame_number;
3002 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
3003     static uint_fast16_t    last_irmp_denon_command;                                // save last irmp command to recognize DENON frame repetition
3004     static uint_fast16_t    denon_repetition_len = 0xFFFF;                          // denon repetition len of 2nd auto generated frame
3005 #endif
3006 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_S100_PROTOCOL == 1
3007     static uint_fast8_t     rc5_cmd_bit6;                                           // bit 6 of RC5 command is the inverted 2nd start bit
3008 #endif
3009 #if IRMP_SUPPORT_MANCHESTER == 1
3010     static PAUSE_LEN        last_pause;                                             // last pause value
3011 #endif
3012 #if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
3013     static uint_fast8_t     last_value;                                             // last bit value
3014 #endif
3015 #if IRMP_SUPPORT_RCII_PROTOCOL == 1
3016     static uint_fast8_t     waiting_for_2nd_pulse = 0;
3017 #endif
3018     uint_fast8_t            irmp_input;                                             // input value
3019
3020 #ifdef ANALYZE
3021
3022 #if 0 // only for test
3023     static uint_fast8_t     last_irmp_start_bit_detected = 0xFF;
3024     static uint_fast8_t     last_irmp_pulse_time = 0xFF;
3025
3026     if (last_irmp_start_bit_detected != irmp_start_bit_detected || last_irmp_pulse_time != irmp_pulse_time)
3027     {
3028         last_irmp_start_bit_detected    = irmp_start_bit_detected;
3029         last_irmp_pulse_time            = irmp_pulse_time;
3030
3031         printf ("%d %d %d\n", time_counter, irmp_start_bit_detected, irmp_pulse_time);
3032     }
3033 #endif // 0
3034
3035     time_counter++;
3036 #endif // ANALYZE
3037
3038 #if defined(__SDCC_stm8)
3039     irmp_input = input(IRMP_GPIO_STRUCT->IDR)
3040 #elif defined(__MBED__)
3041     //irmp_input = inputPin;
3042     irmp_input = gpio_read (&gpioIRin);
3043 #else
3044     irmp_input = input(IRMP_PIN);
3045 #endif
3046
3047 #if IRMP_USE_CALLBACK == 1
3048     if (irmp_callback_ptr)
3049     {
3050         static uint_fast8_t last_inverted_input;
3051
3052         if (last_inverted_input != !irmp_input)
3053         {
3054             (*irmp_callback_ptr) (! irmp_input);
3055             last_inverted_input = !irmp_input;
3056         }
3057     }
3058 #endif // IRMP_USE_CALLBACK == 1
3059
3060     irmp_log(irmp_input);                                                       // log ir signal, if IRMP_LOGGING defined
3061
3062     if (! irmp_ir_detected)                                                     // ir code already detected?
3063     {                                                                           // no...
3064         if (! irmp_start_bit_detected)                                          // start bit detected?
3065         {                                                                       // no...
3066             if (! irmp_input)                                                   // receiving burst?
3067             {                                                                   // yes...
3068 //              irmp_busy_flag = TRUE;
3069 #ifdef ANALYZE
3070                 if (! irmp_pulse_time)
3071                 {
3072                     ANALYZE_PRINTF("%8.3fms [starting pulse]\n", (double) (time_counter * 1000) / F_INTERRUPTS);
3073                 }
3074 #endif // ANALYZE
3075                 irmp_pulse_time++;                                              // increment counter
3076             }
3077             else
3078             {                                                                   // no...
3079                 if (irmp_pulse_time)                                            // it's dark....
3080                 {                                                               // set flags for counting the time of darkness...
3081                     irmp_start_bit_detected = 1;
3082                     wait_for_start_space    = 1;
3083                     wait_for_space          = 0;
3084                     irmp_tmp_command        = 0;
3085                     irmp_tmp_address        = 0;
3086 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3087                     genre2                  = 0;
3088 #endif
3089 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3090                     irmp_tmp_id = 0;
3091 #endif
3092
3093 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
3094                     irmp_tmp_command2       = 0;
3095                     irmp_tmp_address2       = 0;
3096 #endif
3097 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
3098                     irmp_lgair_command      = 0;
3099                     irmp_lgair_address      = 0;
3100 #endif
3101                     irmp_bit                = 0xff;
3102                     irmp_pause_time         = 1;                                // 1st pause: set to 1, not to 0!
3103 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_S100_PROTOCOL == 1
3104                     rc5_cmd_bit6            = 0;                                // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
3105 #endif
3106                 }
3107                 else
3108                 {
3109                     if (key_repetition_len < 0xFFFF)                            // avoid overflow of counter
3110                     {
3111                         key_repetition_len++;
3112
3113 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
3114                         if (denon_repetition_len < 0xFFFF)                      // avoid overflow of counter
3115                         {
3116                             denon_repetition_len++;
3117
3118                             if (denon_repetition_len >= DENON_AUTO_REPETITION_PAUSE_LEN && last_irmp_denon_command != 0)
3119                             {
3120 #ifdef ANALYZE
3121                                 ANALYZE_PRINTF ("%8.3fms warning: did not receive inverted command repetition\n",
3122                                                 (double) (time_counter * 1000) / F_INTERRUPTS);
3123 #endif // ANALYZE
3124                                 last_irmp_denon_command = 0;
3125                                 denon_repetition_len = 0xFFFF;
3126                             }
3127                         }
3128 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
3129                     }
3130                 }
3131             }
3132         }
3133         else
3134         {
3135             if (wait_for_start_space)                                           // we have received start bit...
3136             {                                                                   // ...and are counting the time of darkness
3137                 if (irmp_input)                                                 // still dark?
3138                 {                                                               // yes
3139                     irmp_pause_time++;                                          // increment counter
3140
3141 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
3142                     if (((irmp_pulse_time < NIKON_START_BIT_PULSE_LEN_MIN || irmp_pulse_time > NIKON_START_BIT_PULSE_LEN_MAX) && irmp_pause_time > IRMP_TIMEOUT_LEN) ||
3143                          irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN)
3144 #else
3145                     if (irmp_pause_time > IRMP_TIMEOUT_LEN)                     // timeout?
3146 #endif
3147                     {                                                           // yes...
3148 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3149                         if (irmp_protocol == IRMP_JVC_PROTOCOL)                 // don't show eror if JVC protocol, irmp_pulse_time has been set below!
3150                         {
3151                             ;
3152                         }
3153                         else
3154 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3155                         {
3156 #ifdef ANALYZE
3157                             ANALYZE_PRINTF ("%8.3fms error 1: pause after start bit pulse %d too long: %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time);
3158                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3159 #endif // ANALYZE
3160                         }
3161
3162                         irmp_start_bit_detected = 0;                            // reset flags, let's wait for another start bit
3163                         irmp_pulse_time         = 0;
3164                         irmp_pause_time         = 0;
3165                     }
3166                 }
3167                 else
3168                 {                                                               // receiving first data pulse!
3169                     IRMP_PARAMETER * irmp_param_p;
3170                     irmp_param_p = (IRMP_PARAMETER *) 0;
3171
3172 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
3173                     irmp_param2.protocol = 0;
3174 #endif
3175
3176 #ifdef ANALYZE
3177                     ANALYZE_PRINTF ("%8.3fms [start-bit: pulse = %2d, pause = %2d]\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time);
3178 #endif // ANALYZE
3179
3180 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
3181                     if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
3182                         irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
3183                     {                                                           // it's SIRCS
3184 #ifdef ANALYZE
3185                         ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3186                                         SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
3187                                         SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
3188 #endif // ANALYZE
3189                         irmp_param_p = (IRMP_PARAMETER *) &sircs_param;
3190                     }
3191                     else
3192 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
3193
3194 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3195                     if (irmp_protocol == IRMP_JVC_PROTOCOL &&                                                       // last protocol was JVC, awaiting repeat frame
3196                         irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX &&
3197                         irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX)
3198                     {
3199 #ifdef ANALYZE
3200                         ANALYZE_PRINTF ("protocol = NEC or JVC (type 1) repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3201                                         JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX,
3202                                         JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX);
3203 #endif // ANALYZE
3204                         irmp_param_p = (IRMP_PARAMETER *) &nec_param;
3205                     }
3206                     else
3207 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3208
3209 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3210                     if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
3211                         irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
3212                     {
3213 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
3214 #ifdef ANALYZE
3215                         ANALYZE_PRINTF ("protocol = NEC42, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3216                                         NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
3217                                         NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
3218 #endif // ANALYZE
3219                         irmp_param_p = (IRMP_PARAMETER *) &nec42_param;
3220 #else
3221 #ifdef ANALYZE
3222                         ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3223                                         NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
3224                                         NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
3225 #endif // ANALYZE
3226                         irmp_param_p = (IRMP_PARAMETER *) &nec_param;
3227 #endif
3228                     }
3229                     else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN        && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
3230                              irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
3231                     {                                                           // it's NEC
3232 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3233                         if (irmp_protocol == IRMP_JVC_PROTOCOL)                 // last protocol was JVC, awaiting repeat frame
3234                         {                                                       // some jvc remote controls use nec repetition frame for jvc repetition frame
3235 #ifdef ANALYZE
3236                             ANALYZE_PRINTF ("protocol = JVC repeat frame type 2, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3237                                             NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
3238                                             NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
3239 #endif // ANALYZE
3240                             irmp_param_p = (IRMP_PARAMETER *) &nec_param;
3241                         }
3242                         else
3243 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3244                         {
3245 #ifdef ANALYZE
3246                             ANALYZE_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3247                                             NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
3248                                             NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
3249 #endif // ANALYZE
3250
3251                             irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
3252                         }
3253                     }
3254                     else
3255
3256 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3257                     if (irmp_protocol == IRMP_JVC_PROTOCOL &&                   // last protocol was JVC, awaiting repeat frame
3258                         irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
3259                         irmp_pause_time >= NEC_0_PAUSE_LEN_MIN         && irmp_pause_time <= NEC_0_PAUSE_LEN_MAX)
3260                     {                                                           // it's JVC repetition type 3
3261 #ifdef ANALYZE
3262                         ANALYZE_PRINTF ("protocol = JVC repeat frame type 3, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3263                                         NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
3264                                         NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX);
3265 #endif // ANALYZE
3266                         irmp_param_p = (IRMP_PARAMETER *) &nec_param;
3267                     }
3268                     else
3269 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3270
3271 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
3272
3273 #if IRMP_SUPPORT_TELEFUNKEN_PROTOCOL == 1
3274                     if (irmp_pulse_time >= TELEFUNKEN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= TELEFUNKEN_START_BIT_PULSE_LEN_MAX &&
3275                         irmp_pause_time >= TELEFUNKEN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= TELEFUNKEN_START_BIT_PAUSE_LEN_MAX)
3276                     {
3277 #ifdef ANALYZE
3278                         ANALYZE_PRINTF ("protocol = TELEFUNKEN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3279                                         TELEFUNKEN_START_BIT_PULSE_LEN_MIN, TELEFUNKEN_START_BIT_PULSE_LEN_MAX,
3280                                         TELEFUNKEN_START_BIT_PAUSE_LEN_MIN, TELEFUNKEN_START_BIT_PAUSE_LEN_MAX);
3281 #endif // ANALYZE
3282                         irmp_param_p = (IRMP_PARAMETER *) &telefunken_param;
3283                     }
3284                     else
3285 #endif // IRMP_SUPPORT_TELEFUNKEN_PROTOCOL == 1
3286
3287 #if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1
3288                     if (irmp_pulse_time >= ROOMBA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_START_BIT_PULSE_LEN_MAX &&
3289                         irmp_pause_time >= ROOMBA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= ROOMBA_START_BIT_PAUSE_LEN_MAX)
3290                     {
3291 #ifdef ANALYZE
3292                         ANALYZE_PRINTF ("protocol = ROOMBA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3293                                         ROOMBA_START_BIT_PULSE_LEN_MIN, ROOMBA_START_BIT_PULSE_LEN_MAX,
3294                                         ROOMBA_START_BIT_PAUSE_LEN_MIN, ROOMBA_START_BIT_PAUSE_LEN_MAX);
3295 #endif // ANALYZE
3296                         irmp_param_p = (IRMP_PARAMETER *) &roomba_param;
3297                     }
3298                     else
3299 #endif // IRMP_SUPPORT_ROOMBA_PROTOCOL == 1
3300
3301 #if IRMP_SUPPORT_ACP24_PROTOCOL == 1
3302                     if (irmp_pulse_time >= ACP24_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= ACP24_START_BIT_PULSE_LEN_MAX &&
3303                         irmp_pause_time >= ACP24_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= ACP24_START_BIT_PAUSE_LEN_MAX)
3304                     {
3305 #ifdef ANALYZE
3306                         ANALYZE_PRINTF ("protocol = ACP24, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3307                                         ACP24_START_BIT_PULSE_LEN_MIN, ACP24_START_BIT_PULSE_LEN_MAX,
3308                                         ACP24_START_BIT_PAUSE_LEN_MIN, ACP24_START_BIT_PAUSE_LEN_MAX);
3309 #endif // ANALYZE
3310                         irmp_param_p = (IRMP_PARAMETER *) &acp24_param;
3311                     }
3312                     else
3313 #endif // IRMP_SUPPORT_ROOMBA_PROTOCOL == 1
3314
3315 #if IRMP_SUPPORT_PENTAX_PROTOCOL == 1
3316                     if (irmp_pulse_time >= PENTAX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= PENTAX_START_BIT_PULSE_LEN_MAX &&
3317                         irmp_pause_time >= PENTAX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= PENTAX_START_BIT_PAUSE_LEN_MAX)
3318                     {
3319 #ifdef ANALYZE
3320                         ANALYZE_PRINTF ("protocol = PENTAX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3321                                         PENTAX_START_BIT_PULSE_LEN_MIN, PENTAX_START_BIT_PULSE_LEN_MAX,
3322                                         PENTAX_START_BIT_PAUSE_LEN_MIN, PENTAX_START_BIT_PAUSE_LEN_MAX);
3323 #endif // ANALYZE
3324                         irmp_param_p = (IRMP_PARAMETER *) &pentax_param;
3325                     }
3326                     else
3327 #endif // IRMP_SUPPORT_PENTAX_PROTOCOL == 1
3328
3329 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
3330                     if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX &&
3331                         irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX)
3332                     {
3333 #ifdef ANALYZE
3334                         ANALYZE_PRINTF ("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3335                                         NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX,
3336                                         NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX);
3337 #endif // ANALYZE
3338                         irmp_param_p = (IRMP_PARAMETER *) &nikon_param;
3339                     }
3340                     else
3341 #endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1
3342
3343 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3344                     if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
3345                         irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
3346                     {                                                           // it's SAMSUNG
3347 #ifdef ANALYZE
3348                         ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3349                                         SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
3350                                         SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
3351 #endif // ANALYZE
3352                         irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
3353                     }
3354                     else
3355 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3356
3357 #if IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1
3358                     if (irmp_pulse_time >= SAMSUNGAH_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNGAH_START_BIT_PULSE_LEN_MAX &&
3359                         irmp_pause_time >= SAMSUNGAH_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNGAH_START_BIT_PAUSE_LEN_MAX)
3360                     {                                                           // it's SAMSUNGAH
3361 #ifdef ANALYZE
3362                         ANALYZE_PRINTF ("protocol = SAMSUNGAH, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3363                                         SAMSUNGAH_START_BIT_PULSE_LEN_MIN, SAMSUNGAH_START_BIT_PULSE_LEN_MAX,
3364                                         SAMSUNGAH_START_BIT_PAUSE_LEN_MIN, SAMSUNGAH_START_BIT_PAUSE_LEN_MAX);
3365 #endif // ANALYZE
3366                         irmp_param_p = (IRMP_PARAMETER *) &samsungah_param;
3367                     }
3368                     else
3369 #endif // IRMP_SUPPORT_SAMSUNGAH_PROTOCOL == 1
3370
3371 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
3372                     if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
3373                         irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
3374                     {                                                           // it's MATSUSHITA
3375 #ifdef ANALYZE
3376                         ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3377                                         MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
3378                                         MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
3379 #endif // ANALYZE
3380                         irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
3381                     }
3382                     else
3383 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
3384
3385 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3386                     if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
3387                         irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
3388                     {                                                           // it's KASEIKYO
3389 #ifdef ANALYZE
3390                         ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3391                                         KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
3392                                         KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
3393 #endif // ANALYZE
3394                         irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
3395                     }
3396                     else
3397 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3398
3399 #if IRMP_SUPPORT_PANASONIC_PROTOCOL == 1
3400                     if (irmp_pulse_time >= PANASONIC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= PANASONIC_START_BIT_PULSE_LEN_MAX &&
3401                         irmp_pause_time >= PANASONIC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= PANASONIC_START_BIT_PAUSE_LEN_MAX)
3402                     {                                                           // it's PANASONIC
3403 #ifdef ANALYZE
3404                         ANALYZE_PRINTF ("protocol = PANASONIC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3405                                         PANASONIC_START_BIT_PULSE_LEN_MIN, PANASONIC_START_BIT_PULSE_LEN_MAX,
3406                                         PANASONIC_START_BIT_PAUSE_LEN_MIN, PANASONIC_START_BIT_PAUSE_LEN_MAX);
3407 #endif // ANALYZE
3408                         irmp_param_p = (IRMP_PARAMETER *) &panasonic_param;
3409                     }
3410                     else
3411 #endif // IRMP_SUPPORT_PANASONIC_PROTOCOL == 1
3412
3413 #if IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
3414                     if (irmp_pulse_time >= MITSU_HEAVY_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MITSU_HEAVY_START_BIT_PULSE_LEN_MAX &&
3415                         irmp_pause_time >= MITSU_HEAVY_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MITSU_HEAVY_START_BIT_PAUSE_LEN_MAX)
3416                     {                                                           // it's MITSU_HEAVY
3417 #ifdef ANALYZE
3418                         ANALYZE_PRINTF ("protocol = MITSU_HEAVY, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3419                                         MITSU_HEAVY_START_BIT_PULSE_LEN_MIN, MITSU_HEAVY_START_BIT_PULSE_LEN_MAX,
3420                                         MITSU_HEAVY_START_BIT_PAUSE_LEN_MIN, MITSU_HEAVY_START_BIT_PAUSE_LEN_MAX);
3421 #endif // ANALYZE
3422                         irmp_param_p = (IRMP_PARAMETER *) &mitsu_heavy_param;
3423                     }
3424                     else
3425 #endif // IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
3426
3427 #if IRMP_SUPPORT_VINCENT_PROTOCOL == 1
3428                     if (irmp_pulse_time >= VINCENT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= VINCENT_START_BIT_PULSE_LEN_MAX &&
3429                         irmp_pause_time >= VINCENT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= VINCENT_START_BIT_PAUSE_LEN_MAX)
3430                     {                                                           // it's VINCENT
3431 #ifdef ANALYZE
3432                         ANALYZE_PRINTF ("protocol = VINCENT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3433                                         VINCENT_START_BIT_PULSE_LEN_MIN, VINCENT_START_BIT_PULSE_LEN_MAX,
3434                                         VINCENT_START_BIT_PAUSE_LEN_MIN, VINCENT_START_BIT_PAUSE_LEN_MAX);
3435 #endif // ANALYZE
3436                         irmp_param_p = (IRMP_PARAMETER *) &vincent_param;
3437                     }
3438                     else
3439 #endif // IRMP_SUPPORT_VINCENT_PROTOCOL == 1
3440
3441 #if IRMP_SUPPORT_METZ_PROTOCOL == 1
3442                     if (irmp_pulse_time >= METZ_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= METZ_START_BIT_PULSE_LEN_MAX &&
3443                         irmp_pause_time >= METZ_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= METZ_START_BIT_PAUSE_LEN_MAX)
3444                     {
3445 #ifdef ANALYZE
3446                         ANALYZE_PRINTF ("protocol = METZ, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3447                                         METZ_START_BIT_PULSE_LEN_MIN, METZ_START_BIT_PULSE_LEN_MAX,
3448                                         METZ_START_BIT_PAUSE_LEN_MIN, METZ_START_BIT_PAUSE_LEN_MAX);
3449 #endif // ANALYZE
3450                         irmp_param_p = (IRMP_PARAMETER *) &metz_param;
3451                     }
3452                     else
3453 #endif // IRMP_SUPPORT_METZ_PROTOCOL == 1
3454
3455 #if IRMP_SUPPORT_RADIO1_PROTOCOL == 1
3456                     if (irmp_pulse_time >= RADIO1_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RADIO1_START_BIT_PULSE_LEN_MAX &&
3457                         irmp_pause_time >= RADIO1_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RADIO1_START_BIT_PAUSE_LEN_MAX)
3458                     {
3459 #ifdef ANALYZE
3460                         ANALYZE_PRINTF ("protocol = RADIO1, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3461                                         RADIO1_START_BIT_PULSE_LEN_MIN, RADIO1_START_BIT_PULSE_LEN_MAX,
3462                                         RADIO1_START_BIT_PAUSE_LEN_MIN, RADIO1_START_BIT_PAUSE_LEN_MAX);
3463 #endif // ANALYZE
3464                         irmp_param_p = (IRMP_PARAMETER *) &radio1_param;
3465                     }
3466                     else
3467 #endif // IRMP_SUPPORT_RRADIO1_PROTOCOL == 1
3468
3469 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
3470                     if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
3471                         irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
3472                     {                                                           // it's RECS80
3473 #ifdef ANALYZE
3474                         ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3475                                         RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
3476                                         RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
3477 #endif // ANALYZE
3478                         irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
3479                     }
3480                     else
3481 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
3482
3483 #if IRMP_SUPPORT_S100_PROTOCOL == 1
3484                     if (((irmp_pulse_time >= S100_START_BIT_LEN_MIN     && irmp_pulse_time <= S100_START_BIT_LEN_MAX) ||
3485                          (irmp_pulse_time >= 2 * S100_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * S100_START_BIT_LEN_MAX)) &&
3486                         ((irmp_pause_time >= S100_START_BIT_LEN_MIN     && irmp_pause_time <= S100_START_BIT_LEN_MAX) ||
3487                          (irmp_pause_time >= 2 * S100_START_BIT_LEN_MIN && irmp_pause_time <= 2 * S100_START_BIT_LEN_MAX)))
3488                     {                                                           // it's S100
3489 #ifdef ANALYZE
3490                         ANALYZE_PRINTF ("protocol = S100, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n",
3491                                         S100_START_BIT_LEN_MIN, S100_START_BIT_LEN_MAX,
3492                                         2 * S100_START_BIT_LEN_MIN, 2 * S100_START_BIT_LEN_MAX,
3493                                         S100_START_BIT_LEN_MIN, S100_START_BIT_LEN_MAX,
3494                                         2 * S100_START_BIT_LEN_MIN, 2 * S100_START_BIT_LEN_MAX);
3495 #endif // ANALYZE
3496
3497                         irmp_param_p = (IRMP_PARAMETER *) &s100_param;
3498                         last_pause = irmp_pause_time;
3499
3500                         if ((irmp_pulse_time > S100_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * S100_START_BIT_LEN_MAX) ||
3501                             (irmp_pause_time > S100_START_BIT_LEN_MAX && irmp_pause_time <= 2 * S100_START_BIT_LEN_MAX))
3502                         {
3503                           last_value  = 0;
3504                           rc5_cmd_bit6 = 1<<6;
3505                         }
3506                         else
3507                         {
3508                           last_value  = 1;
3509                         }
3510                     }
3511                     else
3512 #endif // IRMP_SUPPORT_S100_PROTOCOL == 1
3513
3514 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
3515                     if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN     && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
3516                          (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) &&
3517                         ((irmp_pause_time >= RC5_START_BIT_LEN_MIN     && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
3518                          (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)))
3519                     {                                                           // it's RC5
3520 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
3521                         if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
3522                             irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
3523                         {
3524 #ifdef ANALYZE
3525                             ANALYZE_PRINTF ("protocol = RC5 or FDC\n");
3526                             ANALYZE_PRINTF ("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3527                                             FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
3528                                             FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
3529                             ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3530                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3531                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
3532 #endif // ANALYZE
3533                             memcpy_P (&irmp_param2, &fdc_param, sizeof (IRMP_PARAMETER));
3534                         }
3535                         else
3536 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
3537
3538 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
3539                         if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
3540                             irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
3541                         {
3542 #ifdef ANALYZE
3543                             ANALYZE_PRINTF ("protocol = RC5 or RCCAR\n");
3544                             ANALYZE_PRINTF ("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3545                                             RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
3546                                             RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
3547                             ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3548                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3549                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
3550 #endif // ANALYZE
3551                             memcpy_P (&irmp_param2, &rccar_param, sizeof (IRMP_PARAMETER));
3552                         }
3553                         else
3554 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
3555                         {
3556 #ifdef ANALYZE
3557                             ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n",
3558                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3559                                             2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX,
3560                                             RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3561                                             2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX);
3562 #endif // ANALYZE
3563                         }
3564
3565                         irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
3566                         last_pause = irmp_pause_time;
3567
3568                         if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) ||
3569                             (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))
3570                         {
3571                             last_value  = 0;
3572                             rc5_cmd_bit6 = 1<<6;
3573                         }
3574                         else
3575                         {
3576                             last_value  = 1;
3577                         }
3578                     }
3579                     else
3580 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
3581
3582 #if IRMP_SUPPORT_RCII_PROTOCOL == 1
3583                     if ((irmp_pulse_time >= RCII_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCII_START_BIT_PULSE_LEN_MAX) &&
3584                         (irmp_pause_time >= RCII_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCII_START_BIT_PAUSE_LEN_MAX))
3585                     {                                                           // it's RCII
3586 #ifdef ANALYZE
3587                         ANALYZE_PRINTF ("protocol = RCII, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3588                                         RCII_START_BIT_PULSE_LEN_MIN, RCII_START_BIT_PULSE_LEN_MAX,
3589                                         RCII_START_BIT_PAUSE_LEN_MIN, RCII_START_BIT_PAUSE_LEN_MAX)
3590 #endif // ANALYZE
3591                         irmp_param_p = (IRMP_PARAMETER *) &rcii_param;
3592                         last_pause = irmp_pause_time;
3593                         waiting_for_2nd_pulse = 1;
3594                         last_value  = 1;
3595                     }
3596                     else
3597 #endif // IRMP_SUPPORT_RCII_PROTOCOL == 1
3598
3599 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
3600                     if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
3601                         ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
3602                          (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
3603                     {                                                           // it's DENON
3604 #ifdef ANALYZE
3605                         ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
3606                                         DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
3607                                         DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
3608                                         DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
3609 #endif // ANALYZE
3610                         irmp_param_p = (IRMP_PARAMETER *) &denon_param;
3611                     }
3612                     else
3613 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
3614
3615 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
3616                     if ( (irmp_pulse_time >= THOMSON_PULSE_LEN_MIN && irmp_pulse_time <= THOMSON_PULSE_LEN_MAX) &&
3617                         ((irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) ||
3618                          (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)))
3619                     {                                                           // it's THOMSON
3620 #ifdef ANALYZE
3621                         ANALYZE_PRINTF ("protocol = THOMSON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
3622                                         THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX,
3623                                         THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX,
3624                                         THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX);
3625 #endif // ANALYZE
3626                         irmp_param_p = (IRMP_PARAMETER *) &thomson_param;
3627                     }
3628                     else
3629 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
3630
3631 #if IRMP_SUPPORT_BOSE_PROTOCOL == 1
3632                     if (irmp_pulse_time >= BOSE_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= BOSE_START_BIT_PULSE_LEN_MAX &&
3633                         irmp_pause_time >= BOSE_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BOSE_START_BIT_PAUSE_LEN_MAX)
3634                     {
3635 #ifdef ANALYZE
3636                         ANALYZE_PRINTF ("protocol = BOSE, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3637                                         BOSE_START_BIT_PULSE_LEN_MIN, BOSE_START_BIT_PULSE_LEN_MAX,
3638                                         BOSE_START_BIT_PAUSE_LEN_MIN, BOSE_START_BIT_PAUSE_LEN_MAX);
3639 #endif // ANALYZE
3640                         irmp_param_p = (IRMP_PARAMETER *) &bose_param;
3641                     }
3642                     else
3643 #endif // IRMP_SUPPORT_BOSE_PROTOCOL == 1
3644
3645 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
3646                     if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
3647                         irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
3648                     {                                                           // it's RC6
3649 #ifdef ANALYZE
3650                         ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3651                                         RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
3652                                         RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
3653 #endif // ANALYZE
3654                         irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
3655                         last_pause = 0;
3656                         last_value = 1;
3657                     }
3658                     else
3659 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
3660
3661 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
3662                     if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
3663                         irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
3664                     {                                                           // it's RECS80EXT
3665 #ifdef ANALYZE
3666                         ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3667                                         RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
3668                                         RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
3669 #endif // ANALYZE
3670                         irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
3671                     }
3672                     else
3673 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
3674
3675 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
3676                     if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
3677                         irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
3678                     {                                                           // it's NUBERT
3679 #ifdef ANALYZE
3680                         ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3681                                         NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
3682                                         NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
3683 #endif // ANALYZE
3684                         irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
3685                     }
3686                     else
3687 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
3688
3689 #if IRMP_SUPPORT_FAN_PROTOCOL == 1
3690                     if (irmp_pulse_time >= FAN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FAN_START_BIT_PULSE_LEN_MAX &&
3691                         irmp_pause_time >= FAN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FAN_START_BIT_PAUSE_LEN_MAX)
3692                     {                                                           // it's FAN
3693 #ifdef ANALYZE
3694                         ANALYZE_PRINTF ("protocol = FAN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3695                                         FAN_START_BIT_PULSE_LEN_MIN, FAN_START_BIT_PULSE_LEN_MAX,
3696                                         FAN_START_BIT_PAUSE_LEN_MIN, FAN_START_BIT_PAUSE_LEN_MAX);
3697 #endif // ANALYZE
3698                         irmp_param_p = (IRMP_PARAMETER *) &fan_param;
3699                     }
3700                     else
3701 #endif // IRMP_SUPPORT_FAN_PROTOCOL == 1
3702
3703 #if IRMP_SUPPORT_SPEAKER_PROTOCOL == 1
3704                     if (irmp_pulse_time >= SPEAKER_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SPEAKER_START_BIT_PULSE_LEN_MAX &&
3705                         irmp_pause_time >= SPEAKER_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SPEAKER_START_BIT_PAUSE_LEN_MAX)
3706                     {                                                           // it's SPEAKER
3707 #ifdef ANALYZE
3708                         ANALYZE_PRINTF ("protocol = SPEAKER, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3709                                         SPEAKER_START_BIT_PULSE_LEN_MIN, SPEAKER_START_BIT_PULSE_LEN_MAX,
3710                                         SPEAKER_START_BIT_PAUSE_LEN_MIN, SPEAKER_START_BIT_PAUSE_LEN_MAX);
3711 #endif // ANALYZE
3712                         irmp_param_p = (IRMP_PARAMETER *) &speaker_param;
3713                     }
3714                     else
3715 #endif // IRMP_SUPPORT_SPEAKER_PROTOCOL == 1
3716
3717 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
3718                     if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
3719                         irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
3720                     {                                                           // it's BANG_OLUFSEN
3721 #ifdef ANALYZE
3722                         ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n");
3723                         ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3724                                         BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
3725                                         BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
3726                         ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3727                                         BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
3728                                         BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
3729                         ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3730                                         BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
3731                                         BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
3732                         ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3733                                         BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
3734                                         BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
3735 #endif // ANALYZE
3736                         irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
3737                         last_value = 0;
3738                     }
3739                     else
3740 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
3741
3742 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
3743                     if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX &&
3744                         irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX)
3745                     {                                                           // it's GRUNDIG
3746 #ifdef ANALYZE
3747                         ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3748                                         GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
3749                                         GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX);
3750 #endif // ANALYZE
3751                         irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
3752                         last_pause = irmp_pause_time;
3753                         last_value  = 1;
3754                     }
3755                     else
3756 #endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
3757
3758 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1 // check MERLIN before RUWIDO!
3759                     if (irmp_pulse_time >= MERLIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MERLIN_START_BIT_PULSE_LEN_MAX &&
3760                         irmp_pause_time >= MERLIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MERLIN_START_BIT_PAUSE_LEN_MAX)
3761                     {                                                           // it's MERLIN
3762 #ifdef ANALYZE
3763                         ANALYZE_PRINTF ("protocol = MERLIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3764                                         MERLIN_START_BIT_PULSE_LEN_MIN, MERLIN_START_BIT_PULSE_LEN_MAX,
3765                                         MERLIN_START_BIT_PAUSE_LEN_MIN, MERLIN_START_BIT_PAUSE_LEN_MAX);
3766 #endif // ANALYZE
3767                         irmp_param_p = (IRMP_PARAMETER *) &merlin_param;
3768                         last_pause = irmp_pause_time;
3769                         last_value = 1;
3770                     }
3771                     else
3772 #endif // IRMP_SUPPORT_MERLIN_PROTOCOL == 1
3773
3774 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
3775                     if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) ||
3776                          (irmp_pulse_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX)) &&
3777                         ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) ||
3778                          (irmp_pause_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX)))
3779                     {                                                           // it's RUWIDO or SIEMENS
3780 #ifdef ANALYZE
3781                         ANALYZE_PRINTF ("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
3782                                         SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN,   SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
3783                                         2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
3784                                         SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN,   SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
3785                                         2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX);
3786 #endif // ANALYZE
3787                         irmp_param_p = (IRMP_PARAMETER *) &ruwido_param;
3788                         last_pause = irmp_pause_time;
3789                         last_value  = 1;
3790                     }
3791                     else
3792 #endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
3793
3794 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
3795                     if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
3796                         irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
3797                     {
3798 #ifdef ANALYZE
3799                         ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3800                                         FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
3801                                         FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
3802 #endif // ANALYZE
3803                         irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
3804                     }
3805                     else
3806 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
3807
3808 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
3809                     if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
3810                         irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
3811                     {
3812 #ifdef ANALYZE
3813                         ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3814                                         RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
3815                                         RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
3816 #endif // ANALYZE
3817                         irmp_param_p = (IRMP_PARAMETER *) &rccar_param;
3818                     }
3819                     else
3820 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
3821
3822 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
3823                     if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX &&
3824                         irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)
3825                     {                                                           // it's KATHREIN
3826 #ifdef ANALYZE
3827                         ANALYZE_PRINTF ("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3828                                         KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX,
3829                                         KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX);
3830 #endif // ANALYZE
3831                         irmp_param_p = (IRMP_PARAMETER *) &kathrein_param;
3832                     }
3833                     else
3834 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
3835
3836 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
3837                     if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX &&
3838                         irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX)
3839                     {                                                           // it's NETBOX
3840 #ifdef ANALYZE
3841                         ANALYZE_PRINTF ("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3842                                         NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX,
3843                                         NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX);
3844 #endif // ANALYZE
3845                         irmp_param_p = (IRMP_PARAMETER *) &netbox_param;
3846                     }
3847                     else
3848 #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1
3849
3850 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
3851                     if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX &&
3852                         irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX)
3853                     {
3854 #ifdef ANALYZE
3855                         ANALYZE_PRINTF ("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3856                                         LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX,
3857                                         LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX);
3858 #endif // ANALYZE
3859                         irmp_param_p = (IRMP_PARAMETER *) &lego_param;
3860                     }
3861                     else
3862 #endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1
3863
3864 #if IRMP_SUPPORT_IRMP16_PROTOCOL == 1
3865                     if (irmp_pulse_time >= IRMP16_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= IRMP16_START_BIT_PULSE_LEN_MAX &&
3866                         irmp_pause_time >= IRMP16_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= IRMP16_START_BIT_PAUSE_LEN_MAX)
3867                     {
3868 #ifdef ANALYZE
3869                         ANALYZE_PRINTF ("protocol = IRMP16, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3870                                         IRMP16_START_BIT_PULSE_LEN_MIN, IRMP16_START_BIT_PULSE_LEN_MAX,
3871                                         IRMP16_START_BIT_PAUSE_LEN_MIN, IRMP16_START_BIT_PAUSE_LEN_MAX);
3872 #endif // ANALYZE
3873                         irmp_param_p = (IRMP_PARAMETER *) &irmp16_param;
3874                     }
3875                     else
3876 #endif // IRMP_SUPPORT_IRMP16_PROTOCOL == 1
3877
3878 #if IRMP_SUPPORT_GREE_PROTOCOL == 1
3879                     if (irmp_pulse_time >= GREE_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= GREE_START_BIT_PULSE_LEN_MAX &&
3880                         irmp_pause_time >= GREE_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= GREE_START_BIT_PAUSE_LEN_MAX)
3881                     {
3882 #ifdef ANALYZE
3883                         ANALYZE_PRINTF ("protocol = GREE, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3884                                         GREE_START_BIT_PULSE_LEN_MIN, GREE_START_BIT_PULSE_LEN_MAX,
3885                                         GREE_START_BIT_PAUSE_LEN_MIN, GREE_START_BIT_PAUSE_LEN_MAX);
3886 #endif // ANALYZE
3887                         irmp_param_p = (IRMP_PARAMETER *) &gree_param;
3888                     }
3889                     else
3890 #endif // IRMP_SUPPORT_GREE_PROTOCOL == 1
3891
3892 #if IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1
3893                     if (irmp_pulse_time >= A1TVBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= A1TVBOX_START_BIT_PULSE_LEN_MAX &&
3894                         irmp_pause_time >= A1TVBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= A1TVBOX_START_BIT_PAUSE_LEN_MAX)
3895                     {                                                           // it's A1TVBOX
3896 #ifdef ANALYZE
3897                         ANALYZE_PRINTF ("protocol = A1TVBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3898                                         A1TVBOX_START_BIT_PULSE_LEN_MIN, A1TVBOX_START_BIT_PULSE_LEN_MAX,
3899                                         A1TVBOX_START_BIT_PAUSE_LEN_MIN, A1TVBOX_START_BIT_PAUSE_LEN_MAX);
3900 #endif // ANALYZE
3901                         irmp_param_p = (IRMP_PARAMETER *) &a1tvbox_param;
3902                         last_pause = 0;
3903                         last_value = 1;
3904                     }
3905                     else
3906 #endif // IRMP_SUPPORT_A1TVBOX_PROTOCOL == 1
3907
3908 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
3909                     if (irmp_pulse_time >= ORTEK_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= ORTEK_START_BIT_PULSE_LEN_MAX &&
3910                         irmp_pause_time >= ORTEK_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= ORTEK_START_BIT_PAUSE_LEN_MAX)
3911                     {                                                           // it's ORTEK (Hama)
3912 #ifdef ANALYZE
3913                         ANALYZE_PRINTF ("protocol = ORTEK, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3914                                         ORTEK_START_BIT_PULSE_LEN_MIN, ORTEK_START_BIT_PULSE_LEN_MAX,
3915                                         ORTEK_START_BIT_PAUSE_LEN_MIN, ORTEK_START_BIT_PAUSE_LEN_MAX);
3916 #endif // ANALYZE
3917                         irmp_param_p = (IRMP_PARAMETER *) &ortek_param;
3918                         last_pause  = 0;
3919                         last_value  = 1;
3920                         parity      = 0;
3921                     }
3922                     else
3923 #endif // IRMP_SUPPORT_ORTEK_PROTOCOL == 1
3924
3925 #if IRMP_SUPPORT_RCMM_PROTOCOL == 1
3926                     if (irmp_pulse_time >= RCMM32_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCMM32_START_BIT_PULSE_LEN_MAX &&
3927                         irmp_pause_time >= RCMM32_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCMM32_START_BIT_PAUSE_LEN_MAX)
3928                     {                                                           // it's RCMM
3929 #ifdef ANALYZE
3930                         ANALYZE_PRINTF ("protocol = RCMM, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
3931                                         RCMM32_START_BIT_PULSE_LEN_MIN, RCMM32_START_BIT_PULSE_LEN_MAX,
3932                                         RCMM32_START_BIT_PAUSE_LEN_MIN, RCMM32_START_BIT_PAUSE_LEN_MAX);
3933 #endif // ANALYZE
3934                         irmp_param_p = (IRMP_PARAMETER *) &rcmm_param;
3935                     }
3936                     else
3937 #endif // IRMP_SUPPORT_RCMM_PROTOCOL == 1
3938                     {
3939 #ifdef ANALYZE
3940                         ANALYZE_PRINTF ("protocol = UNKNOWN\n");
3941 #endif // ANALYZE
3942                         irmp_start_bit_detected = 0;                            // wait for another start bit...
3943                     }
3944
3945                     if (irmp_start_bit_detected)
3946                     {
3947                         memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
3948
3949                         if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
3950                         {
3951 #ifdef ANALYZE
3952                             ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
3953                             ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
3954 #endif // ANALYZE
3955                         }
3956                         else
3957                         {
3958 #ifdef ANALYZE
3959                             ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max,
3960                                             2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max);
3961                             ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max,
3962                                             2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max);
3963 #endif // ANALYZE
3964                         }
3965
3966 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
3967                         if (irmp_param2.protocol)
3968                         {
3969 #ifdef ANALYZE
3970                             ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max);
3971                             ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max);
3972                             ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max);
3973                             ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max);
3974 #endif // ANALYZE
3975                         }
3976 #endif
3977
3978
3979 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
3980                         if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
3981                         {
3982 #ifdef ANALYZE
3983                             ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
3984 #endif // ANALYZE
3985                         }
3986 #endif
3987
3988                         if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
3989                         {
3990 #ifdef ANALYZE
3991                             ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
3992                             ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
3993 #endif // ANALYZE
3994                         }
3995                         else
3996                         {
3997 #ifdef ANALYZE
3998                             ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max,
3999                                             2 * irmp_param.pulse_0_len_min, 2 * irmp_param.pulse_0_len_max);
4000                             ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max,
4001                                             2 * irmp_param.pause_0_len_min, 2 * irmp_param.pause_0_len_max);
4002 #endif // ANALYZE
4003                         }
4004
4005 #ifdef ANALYZE
4006 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
4007                         if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
4008                         {
4009                             ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
4010                             ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
4011                         }
4012 #endif
4013
4014                         ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
4015                         ANALYZE_PRINTF ("command_len:    %3d\n", irmp_param.command_end - irmp_param.command_offset);
4016                         ANALYZE_PRINTF ("complete_len:   %3d\n", irmp_param.complete_len);
4017                         ANALYZE_PRINTF ("stop_bit:       %3d\n", irmp_param.stop_bit);
4018 #endif // ANALYZE
4019                     }
4020
4021                     irmp_bit = 0;
4022
4023 #if IRMP_SUPPORT_MANCHESTER == 1
4024                     if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
4025                          irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO
4026                          irmp_param.protocol != IRMP_RC6_PROTOCOL /*** &&    // Manchester, but not RC6
4027                          irmp_param.protocol != IRMP_RCII_PROTOCOL ****/)     // Manchester, but not RCII
4028                     {
4029                         if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max)
4030                         {
4031 #ifdef ANALYZE
4032                             ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
4033                             ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
4034                             ANALYZE_NEWLINE ();
4035 #endif // ANALYZE
4036                             irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1);
4037                         }
4038                         else if (! last_value)  // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
4039                         {
4040 #ifdef ANALYZE
4041                             ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
4042                             ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
4043                             ANALYZE_NEWLINE ();
4044 #endif // ANALYZE
4045                             irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0);
4046                         }
4047                     }
4048                     else
4049 #endif // IRMP_SUPPORT_MANCHESTER == 1
4050
4051 #if IRMP_SUPPORT_SERIAL == 1
4052                     if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
4053                     {
4054                         ; // do nothing
4055                     }
4056                     else
4057 #endif // IRMP_SUPPORT_SERIAL == 1
4058
4059
4060 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
4061                     if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
4062                     {
4063 #ifdef ANALYZE
4064                         ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
4065 #endif // ANALYZE
4066
4067                         if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
4068                         {                                                       // pause timings correct for "1"?
4069 #ifdef ANALYZE
4070                             ANALYZE_PUTCHAR ('1');                                  // yes, store 1
4071                             ANALYZE_NEWLINE ();
4072 #endif // ANALYZE
4073                             irmp_store_bit (1);
4074                         }
4075                         else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
4076                         {                                                       // pause timings correct for "0"?
4077 #ifdef ANALYZE
4078                             ANALYZE_PUTCHAR ('0');                                  // yes, store 0
4079                             ANALYZE_NEWLINE ();
4080 #endif // ANALYZE
4081                             irmp_store_bit (0);
4082                         }
4083                     }
4084                     else
4085 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
4086 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
4087                     if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL)
4088                     {
4089 #ifdef ANALYZE
4090                         ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
4091 #endif // ANALYZE
4092
4093                         if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX)
4094                         {                                                       // pause timings correct for "1"?
4095 #ifdef ANALYZE
4096                           ANALYZE_PUTCHAR ('1');                                  // yes, store 1
4097                           ANALYZE_NEWLINE ();
4098 #endif // ANALYZE
4099                           irmp_store_bit (1);
4100                         }
4101                         else // if (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)
4102                         {                                                       // pause timings correct for "0"?
4103 #ifdef ANALYZE
4104                           ANALYZE_PUTCHAR ('0');                                  // yes, store 0
4105                           ANALYZE_NEWLINE ();
4106 #endif // ANALYZE
4107                           irmp_store_bit (0);
4108                         }
4109                     }
4110                     else
4111 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
4112                     {
4113                         ;                                                       // else do nothing
4114                     }
4115
4116                     irmp_pulse_time = 1;                                        // set counter to 1, not 0
4117                     irmp_pause_time = 0;
4118                     wait_for_start_space = 0;
4119                 }
4120             }
4121             else if (wait_for_space)                                            // the data section....
4122             {                                                                   // counting the time of darkness....
4123                 uint_fast8_t got_light = FALSE;
4124
4125                 if (irmp_input)                                                 // still dark?
4126                 {                                                               // yes...
4127                     if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
4128                     {
4129                         if (
4130 #if IRMP_SUPPORT_MANCHESTER == 1
4131                             (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) ||
4132 #endif
4133 #if IRMP_SUPPORT_SERIAL == 1
4134                             (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) ||
4135 #endif
4136                             (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max))
4137                         {
4138 #ifdef ANALYZE
4139                             if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
4140                             {
4141                                 ANALYZE_PRINTF ("stop bit detected\n");
4142                             }
4143 #endif // ANALYZE
4144                             irmp_param.stop_bit = 0;
4145                         }
4146                         else
4147                         {
4148 #ifdef ANALYZE
4149                             ANALYZE_PRINTF ("error: stop bit timing wrong, irmp_bit = %d, irmp_pulse_time = %d, pulse_0_len_min = %d, pulse_0_len_max = %d\n",
4150                                             irmp_bit, irmp_pulse_time, irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
4151 #endif // ANALYZE
4152                             irmp_start_bit_detected = 0;                        // wait for another start bit...
4153                             irmp_pulse_time         = 0;
4154                             irmp_pause_time         = 0;
4155                         }
4156                     }
4157                     else
4158                     {
4159                         irmp_pause_time++;                                                          // increment counter
4160
4161 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
4162                         if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL &&                           // Sony has a variable number of bits:
4163                             irmp_pause_time > SIRCS_PAUSE_LEN_MAX &&                                // minimum is 12
4164                             irmp_bit >= 12 - 1)                                                     // pause too long?
4165                         {                                                                           // yes, break and close this frame
4166                             irmp_param.complete_len = irmp_bit + 1;                                 // set new complete length
4167                             got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)
4168                             irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8;       // new: store number of additional bits in upper byte of address!
4169                             irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1;      // correct command length
4170                             irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1;                              // correct pause length
4171                         }
4172                         else
4173 #endif
4174 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
4175                         if (irmp_param.protocol == IRMP_MERLIN_PROTOCOL &&                          // Merlin has a variable number of bits:
4176                             irmp_pause_time > MERLIN_START_BIT_PAUSE_LEN_MAX &&                     // minimum is 8
4177                             irmp_bit >= 8 - 1)                                                      // pause too long?
4178                         {                                                                           // yes, break and close this frame
4179                             irmp_param.complete_len = irmp_bit;                                     // set new complete length
4180                             got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)
4181                             irmp_pause_time = MERLIN_BIT_PAUSE_LEN_MAX - 1;                         // correct pause length
4182                         }
4183                         else
4184 #endif
4185 #if IRMP_SUPPORT_FAN_PROTOCOL == 1
4186                         if (irmp_param.protocol == IRMP_FAN_PROTOCOL &&                             // FAN has no stop bit.
4187                             irmp_bit >= FAN_COMPLETE_DATA_LEN - 1)                                  // last bit in frame
4188                         {                                                                           // yes, break and close this frame
4189                             if (irmp_pulse_time <= FAN_0_PULSE_LEN_MAX && irmp_pause_time >= FAN_0_PAUSE_LEN_MIN)
4190                             {
4191 #ifdef ANALYZE
4192                                 ANALYZE_PRINTF ("Generating virtual stop bit\n");
4193 #endif // ANALYZE
4194                                 got_light = TRUE;                                                   // this is a lie, but helps (generates stop bit)
4195                             }
4196                             else if (irmp_pulse_time >= FAN_1_PULSE_LEN_MIN && irmp_pause_time >= FAN_1_PAUSE_LEN_MIN)
4197                             {
4198 #ifdef ANALYZE
4199                                 ANALYZE_PRINTF ("Generating virtual stop bit\n");
4200 #endif // ANALYZE
4201                                 got_light = TRUE;                                                   // this is a lie, but helps (generates stop bit)
4202                             }
4203                         }
4204                         else
4205 #endif
4206 #if IRMP_SUPPORT_SERIAL == 1
4207                         // NETBOX generates no stop bit, here is the timeout condition:
4208                         if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL &&
4209                             irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit))
4210                         {
4211                             got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)
4212                         }
4213                         else
4214 #endif
4215 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
4216                         if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)
4217                         {
4218                             if (irmp_pause_time > IR60_TIMEOUT_LEN && (irmp_bit == 5 || irmp_bit == 6))
4219                             {
4220 #ifdef ANALYZE
4221                                 ANALYZE_PRINTF ("Switching to IR60 protocol\n");
4222 #endif // ANALYZE
4223                                 got_light = TRUE;                                       // this is a lie, but generates a stop bit ;-)
4224                                 irmp_param.stop_bit = TRUE;                             // set flag
4225
4226                                 irmp_param.protocol         = IRMP_IR60_PROTOCOL;       // change protocol
4227                                 irmp_param.complete_len     = IR60_COMPLETE_DATA_LEN;   // correct complete len
4228                                 irmp_param.address_offset   = IR60_ADDRESS_OFFSET;
4229                                 irmp_param.address_end      = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN;
4230                                 irmp_param.command_offset   = IR60_COMMAND_OFFSET;
4231                                 irmp_param.command_end      = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN;
4232
4233                                 irmp_tmp_command <<= 1;
4234                                 irmp_tmp_command |= first_bit;
4235                             }
4236                             else if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2)
4237                             {                                                           // special manchester decoder
4238                                 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN;    // correct complete len
4239                                 got_light = TRUE;                                       // this is a lie, but generates a stop bit ;-)
4240                                 irmp_param.stop_bit = TRUE;                             // set flag
4241                             }
4242                             else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
4243                             {
4244 #ifdef ANALYZE
4245                                 ANALYZE_PRINTF ("Switching to NOKIA protocol, irmp_bit = %d\n", irmp_bit);
4246 #endif // ANALYZE
4247                                 irmp_param.protocol         = IRMP_NOKIA_PROTOCOL;      // change protocol
4248                                 irmp_param.address_offset   = NOKIA_ADDRESS_OFFSET;
4249                                 irmp_param.address_end      = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
4250                                 irmp_param.command_offset   = NOKIA_COMMAND_OFFSET;
4251                                 irmp_param.command_end      = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
4252
4253                                 if (irmp_tmp_command & 0x300)
4254                                 {
4255                                     irmp_tmp_address = (irmp_tmp_command >> 8);
4256                                     irmp_tmp_command &= 0xFF;
4257                                 }
4258                             }
4259                         }
4260                         else
4261 #endif
4262 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
4263                         if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit)
4264                         {
4265                             if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2)
4266                             {                                                           // special manchester decoder
4267                                 irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN;     // correct complete len
4268                                 got_light = TRUE;                                       // this is a lie, but generates a stop bit ;-)
4269                                 irmp_param.stop_bit = TRUE;                             // set flag
4270                             }
4271                             else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN)
4272                             {
4273 #ifdef ANALYZE
4274                                 ANALYZE_PRINTF ("Switching to SIEMENS protocol\n");
4275 #endif // ANALYZE
4276                                 irmp_param.protocol         = IRMP_SIEMENS_PROTOCOL;    // change protocol
4277                                 irmp_param.address_offset   = SIEMENS_ADDRESS_OFFSET;
4278                                 irmp_param.address_end      = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN;
4279                                 irmp_param.command_offset   = SIEMENS_COMMAND_OFFSET;
4280                                 irmp_param.command_end      = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN;
4281
4282                                 //                   76543210
4283                                 // RUWIDO:  AAAAAAAAACCCCCCCp
4284                                 // SIEMENS: AAAAAAAAAAACCCCCCCCCCp
4285                                 irmp_tmp_address <<= 2;
4286                                 irmp_tmp_address |= (irmp_tmp_command >> 6);
4287                                 irmp_tmp_command &= 0x003F;
4288 //                              irmp_tmp_command <<= 4;
4289                                 irmp_tmp_command |= last_value;
4290                             }
4291                         }
4292                         else
4293 #endif
4294 #if IRMP_SUPPORT_ROOMBA_PROTOCOL == 1
4295                         if (irmp_param.protocol == IRMP_ROOMBA_PROTOCOL &&                          // Roomba has no stop bit
4296                             irmp_bit >= ROOMBA_COMPLETE_DATA_LEN - 1)                               // it's the last data bit...
4297                         {                                                                           // break and close this frame
4298                             if (irmp_pulse_time >= ROOMBA_1_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_1_PULSE_LEN_MAX)
4299                             {
4300                                 irmp_pause_time = ROOMBA_1_PAUSE_LEN_EXACT;
4301                             }
4302                             else if (irmp_pulse_time >= ROOMBA_0_PULSE_LEN_MIN && irmp_pulse_time <= ROOMBA_0_PULSE_LEN_MAX)
4303                             {
4304                                 irmp_pause_time = ROOMBA_0_PAUSE_LEN;
4305                             }
4306
4307                             got_light = TRUE;                                                       // this is a lie, but helps (generates stop bit)
4308                         }
4309                         else
4310 #endif
4311 #if IRMP_SUPPORT_MANCHESTER == 1
4312                         if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
4313                             irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
4314                         {                                                       // special manchester decoder
4315                             got_light = TRUE;                                   // this is a lie, but generates a stop bit ;-)
4316                             irmp_param.stop_bit = TRUE;                         // set flag
4317                         }
4318                         else
4319 #endif // IRMP_SUPPORT_MANCHESTER == 1
4320                         if (irmp_pause_time > IRMP_TIMEOUT_LEN)                 // timeout?
4321                         {                                                       // yes...
4322                             if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
4323                             {
4324                                 irmp_bit++;
4325                             }
4326 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
4327                             else if ((irmp_param.protocol == IRMP_NEC_PROTOCOL || irmp_param.protocol == IRMP_NEC42_PROTOCOL) && irmp_bit == 0)
4328                             {                                                               // it was a non-standard repetition frame
4329 #ifdef ANALYZE                                                                              // with 4500us pause instead of 2250us
4330                                 ANALYZE_PRINTF ("Detected non-standard repetition frame, switching to NEC repetition\n");
4331 #endif // ANALYZE
4332                                 if (key_repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)
4333                                 {
4334                                     irmp_param.stop_bit     = TRUE;                         // set flag
4335                                     irmp_param.protocol     = IRMP_NEC_PROTOCOL;            // switch protocol
4336                                     irmp_param.complete_len = irmp_bit;                     // patch length: 16 or 17
4337                                     irmp_tmp_address = last_irmp_address;                   // address is last address
4338                                     irmp_tmp_command = last_irmp_command;                   // command is last command
4339                                     irmp_flags |= IRMP_FLAG_REPETITION;
4340                                     key_repetition_len = 0;
4341                                 }
4342                                 else
4343                                 {
4344 #ifdef ANALYZE
4345                                     ANALYZE_PRINTF ("ignoring NEC repetition frame: timeout occured, key_repetition_len = %d > %d\n",
4346                                                     key_repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);
4347 #endif // ANALYZE
4348                                     irmp_ir_detected = FALSE;
4349                                 }
4350                             }
4351 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
4352 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
4353                             else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17))      // it was a JVC stop bit
4354                             {
4355 #ifdef ANALYZE
4356                                 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
4357 #endif // ANALYZE
4358                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4359                                 irmp_param.protocol     = IRMP_JVC_PROTOCOL;                        // switch protocol
4360                                 irmp_param.complete_len = irmp_bit;                                 // patch length: 16 or 17
4361                                 irmp_tmp_command        = (irmp_tmp_address >> 4);                  // set command: upper 12 bits are command bits
4362                                 irmp_tmp_address        = irmp_tmp_address & 0x000F;                // lower 4 bits are address bits
4363                                 irmp_start_bit_detected = 1;                                        // tricky: don't wait for another start bit...
4364                             }
4365 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
4366 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
4367                             else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 28 || irmp_bit == 29))      // it was a LGAIR stop bit
4368                             {
4369 #ifdef ANALYZE
4370                                 ANALYZE_PRINTF ("Switching to LGAIR protocol, irmp_bit = %d\n", irmp_bit);
4371 #endif // ANALYZE
4372                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4373                                 irmp_param.protocol     = IRMP_LGAIR_PROTOCOL;                      // switch protocol
4374                                 irmp_param.complete_len = irmp_bit;                                 // patch length: 16 or 17
4375                                 irmp_tmp_command        = irmp_lgair_command;                       // set command: upper 8 bits are command bits
4376                                 irmp_tmp_address        = irmp_lgair_address;                       // lower 4 bits are address bits
4377                                 irmp_start_bit_detected = 1;                                        // tricky: don't wait for another start bit...
4378                             }
4379 #endif // IRMP_SUPPORT_LGAIR_PROTOCOL == 1
4380
4381 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
4382 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
4383                             else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 32)      // it was a NEC stop bit
4384                             {
4385 #ifdef ANALYZE
4386                                 ANALYZE_PRINTF ("Switching to NEC protocol\n");
4387 #endif // ANALYZE
4388                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4389                                 irmp_param.protocol     = IRMP_NEC_PROTOCOL;                        // switch protocol
4390                                 irmp_param.complete_len = irmp_bit;                                 // patch length: 16 or 17
4391
4392                                 //        0123456789ABC0123456789ABC0123456701234567
4393                                 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
4394                                 // NEC:   AAAAAAAAaaaaaaaaCCCCCCCCcccccccc
4395                                 irmp_tmp_address        |= (irmp_tmp_address2 & 0x0007) << 13;      // fm 2012-02-13: 12 -> 13
4396                                 irmp_tmp_command        = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10);
4397                             }
4398 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
4399 #if IRMP_SUPPORT_LGAIR_PROTOCOL == 1
4400                             else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 28)      // it was a NEC stop bit
4401                             {
4402 #ifdef ANALYZE
4403                                 ANALYZE_PRINTF ("Switching to LGAIR protocol\n");
4404 #endif // ANALYZE
4405                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4406                                 irmp_param.protocol     = IRMP_LGAIR_PROTOCOL;                      // switch protocol
4407                                 irmp_param.complete_len = irmp_bit;                                 // patch length: 16 or 17
4408                                 irmp_tmp_address        = irmp_lgair_address;
4409                                 irmp_tmp_command        = irmp_lgair_command;
4410                             }
4411 #endif // IRMP_SUPPORT_LGAIR_PROTOCOL == 1
4412 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
4413                             else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17))  // it was a JVC stop bit
4414                             {
4415 #ifdef ANALYZE
4416                                 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
4417 #endif // ANALYZE
4418                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4419                                 irmp_param.protocol     = IRMP_JVC_PROTOCOL;                        // switch protocol
4420                                 irmp_param.complete_len = irmp_bit;                                 // patch length: 16 or 17
4421
4422                                 //        0123456789ABC0123456789ABC0123456701234567
4423                                 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
4424                                 // JVC:   AAAACCCCCCCCCCCC
4425                                 irmp_tmp_command        = (irmp_tmp_address >> 4) | (irmp_tmp_address2 << 9);   // set command: upper 12 bits are command bits
4426                                 irmp_tmp_address        = irmp_tmp_address & 0x000F;                            // lower 4 bits are address bits
4427                             }
4428 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
4429 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
4430
4431 #if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1
4432                             else if (irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL && irmp_bit == 32)          // it was a SAMSUNG32 stop bit
4433                             {
4434 #ifdef ANALYZE
4435                                 ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");
4436 #endif // ANALYZE
4437                                 irmp_param.protocol         = IRMP_SAMSUNG32_PROTOCOL;
4438                                 irmp_param.command_offset   = SAMSUNG32_COMMAND_OFFSET;
4439                                 irmp_param.command_end      = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
4440                                 irmp_param.complete_len     = SAMSUNG32_COMPLETE_DATA_LEN;
4441                             }
4442 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
4443
4444 #if IRMP_SUPPORT_RCMM_PROTOCOL == 1
4445                             else if (irmp_param.protocol == IRMP_RCMM32_PROTOCOL && (irmp_bit == 12 || irmp_bit == 24))  // it was a RCMM stop bit
4446                             {
4447                                 if (irmp_bit == 12)
4448                                 {
4449                                     irmp_tmp_command = (irmp_tmp_address & 0xFF);                   // set command: lower 8 bits are command bits
4450                                     irmp_tmp_address >>= 8;                                         // upper 4 bits are address bits
4451
4452 #ifdef ANALYZE
4453                                     ANALYZE_PRINTF ("Switching to RCMM12 protocol, irmp_bit = %d\n", irmp_bit);
4454 #endif // ANALYZE
4455                                     irmp_param.protocol     = IRMP_RCMM12_PROTOCOL;                 // switch protocol
4456                                 }
4457                                 else // if ((irmp_bit == 24)
4458                                 {
4459 #ifdef ANALYZE
4460                                     ANALYZE_PRINTF ("Switching to RCMM24 protocol, irmp_bit = %d\n", irmp_bit);
4461 #endif // ANALYZE
4462                                     irmp_param.protocol     = IRMP_RCMM24_PROTOCOL;                 // switch protocol
4463                                 }
4464                                 irmp_param.stop_bit     = TRUE;                                     // set flag
4465                                 irmp_param.complete_len = irmp_bit;                                 // patch length
4466                             }
4467 #endif // IRMP_SUPPORT_RCMM_PROTOCOL == 1
4468
4469 #if IRMP_SUPPORT_TECHNICS_PROTOCOL == 1
4470                             else if (irmp_param.protocol == IRMP_MATSUSHITA_PROTOCOL && irmp_bit == 22)  // it was a TECHNICS stop bit
4471                             {
4472 #ifdef ANALYZE
4473                                 ANALYZE_PRINTF ("Switching to TECHNICS protocol, irmp_bit = %d\n", irmp_bit);
4474 #endif // ANALYZE
4475                                 // Situation:
4476                                 // The first 12 bits have been stored in irmp_tmp_command (LSB first)
4477                                 // The following 10 bits have been stored in irmp_tmp_address (LSB first)
4478                                 // The code of TECHNICS is:
4479                                 //   cccccccccccCCCCCCCCCCC (11 times c and 11 times C)
4480                                 //   ccccccccccccaaaaaaaaaa
4481                                 // where C is inverted value of c
4482
4483                                 irmp_tmp_address <<= 1;
4484                                 if (irmp_tmp_command & (1<<11))
4485                                 {
4486                                     irmp_tmp_address |= 1;
4487                                     irmp_tmp_command &= ~(1<<11);
4488                                 }
4489
4490                                 if (irmp_tmp_command == ((~irmp_tmp_address) & 0x07FF))
4491                                 {
4492                                     irmp_tmp_address = 0;
4493
4494                                     irmp_param.protocol     = IRMP_TECHNICS_PROTOCOL;                   // switch protocol
4495                                     irmp_param.complete_len = irmp_bit;                                 // patch length
4496                                 }
4497                                 else
4498                                 {
4499 #ifdef ANALYZE
4500                                     ANALYZE_PRINTF ("error 8: TECHNICS frame error\n");
4501                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4502 #endif // ANALYZE
4503                                     irmp_start_bit_detected = 0;                    // wait for another start bit...
4504                                     irmp_pulse_time         = 0;
4505                                     irmp_pause_time         = 0;
4506                                 }
4507                             }
4508 #endif // IRMP_SUPPORT_TECHNICS_PROTOCOL == 1
4509                             else
4510                             {
4511 #ifdef ANALYZE
4512                                 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
4513                                 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4514 #endif // ANALYZE
4515                                 irmp_start_bit_detected = 0;                    // wait for another start bit...
4516                                 irmp_pulse_time         = 0;
4517                                 irmp_pause_time         = 0;
4518                             }
4519                         }
4520                     }
4521                 }
4522                 else
4523                 {                                                               // got light now!
4524                     got_light = TRUE;
4525                 }
4526
4527                 if (got_light)
4528                 {
4529 #ifdef ANALYZE
4530                     ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time);
4531 #endif // ANALYZE
4532
4533 #if IRMP_SUPPORT_MANCHESTER == 1
4534                     if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))                                     // Manchester
4535                     {
4536 #if IRMP_SUPPORT_MERLIN_PROTOCOL == 1
4537                         if (irmp_param.complete_len == irmp_bit && irmp_param.protocol == IRMP_MERLIN_PROTOCOL)
4538                         {
4539                             if (last_value == 0)
4540                             {
4541                                 if (irmp_pulse_time >= 2 * irmp_param.pulse_1_len_min && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max &&
4542                                     last_pause >= irmp_param.pause_1_len_min && last_pause <= irmp_param.pulse_1_len_max)
4543                                 {
4544                                     irmp_param.complete_len += 2;
4545                                     irmp_store_bit(0);
4546                                     irmp_store_bit(1);
4547                                 }
4548                             }
4549                             else
4550                             {
4551                                 if (last_pause >= 2 * irmp_param.pause_1_len_min && last_pause <= 2 * irmp_param.pulse_1_len_max)
4552                                 {
4553                                     if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max)
4554                                     {
4555                                         irmp_param.complete_len++;
4556                                         irmp_store_bit(0);
4557                                     }
4558                                     else if (irmp_pulse_time >= 2 * irmp_param.pulse_1_len_min && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max)
4559                                     {
4560                                         irmp_param.complete_len += 2;
4561                                         irmp_store_bit(0);
4562                                         irmp_store_bit(1);
4563                                     }
4564                                 }
4565                             }
4566                         }
4567                         else
4568 #endif
4569 #if 1
4570                         if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max */)
4571 #else // better, but some IR-RCs use asymmetric timings :-/
4572                         if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max &&
4573                             irmp_pause_time <= 2 * irmp_param.pause_1_len_max)
4574 #endif
4575                         {
4576 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
4577                             if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN)         // RC6 toggle bit
4578                             {
4579 #ifdef ANALYZE
4580                                 ANALYZE_PUTCHAR ('T');
4581 #endif // ANALYZE
4582                                 if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG)                      // RC6 mode 6A
4583                                 {
4584                                     irmp_store_bit (1);
4585                                     last_value = 1;
4586                                 }
4587                                 else                                                                            // RC6 mode 0
4588                                 {
4589                                     irmp_store_bit (0);
4590                                     last_value = 0;
4591                                 }
4592 #ifdef ANALYZE
4593                                 ANALYZE_NEWLINE ();
4594 #endif // ANALYZE
4595                             }
4596                             else
4597 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
4598                             {
4599 #ifdef ANALYZE
4600                                 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
4601 #endif // ANALYZE
4602                                 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0  :  1 );
4603
4604 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
4605                                 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN)      // RC6 toggle bit
4606                                 {
4607 #ifdef ANALYZE
4608                                     ANALYZE_PUTCHAR ('T');
4609 #endif // ANALYZE
4610                                     irmp_store_bit (1);
4611
4612                                     if (irmp_pause_time > 2 * irmp_param.pause_1_len_max)
4613                                     {
4614                                         last_value = 0;
4615                                     }
4616                                     else
4617                                     {
4618                                         last_value = 1;
4619                                     }
4620 #ifdef ANALYZE
4621                                     ANALYZE_NEWLINE ();
4622 #endif // ANALYZE
4623                                 }
4624                                 else
4625 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
4626                                 {
4627 #ifdef ANALYZE
4628                                     ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
4629 #endif // ANALYZE
4630                                     irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 :   0 );
4631
4632 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCII_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
4633                                     if (! irmp_param2.protocol)
4634 #endif
4635                                     {
4636 #ifdef ANALYZE
4637                                         ANALYZE_NEWLINE ();
4638 #endif // ANALYZE
4639                                     }
4640                                     last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0;
4641                                 }
4642                             }
4643                         }
4644                         else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max
4645                                  /* && irmp_pause_time <= 2 * irmp_param.pause_1_len_max */)
4646                         {
4647                             uint_fast8_t manchester_value;
4648
4649                             if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max)
4650                             {
4651                                 manchester_value = last_value ? 0 : 1;
4652                                 last_value  = manchester_value;
4653                             }
4654                             else
4655                             {
4656                                 manchester_value = last_value;
4657                             }
4658
4659 #ifdef ANALYZE
4660                             ANALYZE_PUTCHAR (manchester_value + '0');
4661 #endif // ANALYZE
4662
4663 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
4664                             if (! irmp_param2.protocol)
4665 #endif
4666                             {
4667 #ifdef ANALYZE
4668                                 ANALYZE_NEWLINE ();
4669 #endif // ANALYZE
4670                             }
4671
4672 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
4673                             if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1)     // RC6 mode != 0 ???
4674                             {
4675 #ifdef ANALYZE
4676                                 ANALYZE_PRINTF ("Switching to RC6A protocol\n");
4677 #endif // ANALYZE
4678                                 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
4679                                 irmp_param.address_offset = 5;
4680                                 irmp_param.address_end = irmp_param.address_offset + 15;
4681                                 irmp_param.command_offset = irmp_param.address_end + 1;                                 // skip 1 system bit, changes like a toggle bit
4682                                 irmp_param.command_end = irmp_param.command_offset + 16 - 1;
4683                                 irmp_tmp_address = 0;
4684                             }
4685 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
4686
4687                             irmp_store_bit (manchester_value);
4688                         }
4689                         else
4690                         {
4691 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
4692                             if (irmp_param2.protocol == IRMP_FDC_PROTOCOL &&
4693                                 irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX &&
4694                                 ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) ||
4695                                  (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)))
4696                             {
4697 #ifdef ANALYZE
4698                                 ANALYZE_PUTCHAR ('?');
4699 #endif // ANALYZE
4700                                 irmp_param.protocol = 0;                // switch to FDC, see below
4701                             }
4702                             else
4703 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
4704 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
4705                             if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL &&
4706                                 irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX &&
4707                                 ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) ||
4708                                  (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)))
4709                             {
4710 #ifdef ANALYZE
4711                                 ANALYZE_PUTCHAR ('?');
4712 #endif // ANALYZE
4713                                 irmp_param.protocol = 0;                // switch to RCCAR, see below
4714                             }
4715                             else
4716 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
4717                             {
4718 #ifdef ANALYZE
4719                                 ANALYZE_PUTCHAR ('?');
4720                                 ANALYZE_NEWLINE ();
4721                                 ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
4722                                 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4723 #endif // ANALYZE
4724                                 irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit
4725                                 irmp_pause_time         = 0;
4726                             }
4727                         }
4728
4729 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
4730                         if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX)
4731                         {
4732                             if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX)
4733                             {
4734 #ifdef ANALYZE
4735                                 ANALYZE_PRINTF ("   1 (FDC)\n");
4736 #endif // ANALYZE
4737                                 irmp_store_bit2 (1);
4738                             }
4739                             else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)
4740                             {
4741 #ifdef ANALYZE
4742                                 ANALYZE_PRINTF ("   0 (FDC)\n");
4743 #endif // ANALYZE
4744                                 irmp_store_bit2 (0);
4745                             }
4746
4747                             if (! irmp_param.protocol)
4748                             {
4749 #ifdef ANALYZE
4750                                 ANALYZE_PRINTF ("Switching to FDC protocol\n");
4751 #endif // ANALYZE
4752                                 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
4753                                 irmp_param2.protocol = 0;
4754                                 irmp_tmp_address = irmp_tmp_address2;
4755                                 irmp_tmp_command = irmp_tmp_command2;
4756                             }
4757                         }
4758 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
4759 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
4760                         if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX)
4761                         {
4762                             if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX)
4763                             {
4764 #ifdef ANALYZE
4765                                 ANALYZE_PRINTF ("   1 (RCCAR)\n");
4766 #endif // ANALYZE
4767                                 irmp_store_bit2 (1);
4768                             }
4769                             else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)
4770                             {
4771 #ifdef ANALYZE
4772                                 ANALYZE_PRINTF ("   0 (RCCAR)\n");
4773 #endif // ANALYZE
4774                                 irmp_store_bit2 (0);
4775                             }
4776
4777                             if (! irmp_param.protocol)
4778                             {
4779 #ifdef ANALYZE
4780                                 ANALYZE_PRINTF ("Switching to RCCAR protocol\n");
4781 #endif // ANALYZE
4782                                 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
4783                                 irmp_param2.protocol = 0;
4784                                 irmp_tmp_address = irmp_tmp_address2;
4785                                 irmp_tmp_command = irmp_tmp_command2;
4786                             }
4787                         }
4788 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
4789
4790                         last_pause      = irmp_pause_time;
4791                         wait_for_space  = 0;
4792                     }
4793                     else
4794 #endif // IRMP_SUPPORT_MANCHESTER == 1
4795
4796 #if IRMP_SUPPORT_SERIAL == 1
4797                     if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
4798                     {
4799                         while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max)
4800                         {
4801 #ifdef ANALYZE
4802                             ANALYZE_PUTCHAR ('1');
4803 #endif // ANALYZE
4804                             irmp_store_bit (1);
4805
4806                             if (irmp_pulse_time >= irmp_param.pulse_1_len_min)
4807                             {
4808                                 irmp_pulse_time -= irmp_param.pulse_1_len_min;
4809                             }
4810                             else
4811                             {
4812                                 irmp_pulse_time = 0;
4813                             }
4814                         }
4815
4816                         while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max)
4817                         {
4818 #ifdef ANALYZE
4819                             ANALYZE_PUTCHAR ('0');
4820 #endif // ANALYZE
4821                             irmp_store_bit (0);
4822
4823                             if (irmp_pause_time >= irmp_param.pause_1_len_min)
4824                             {
4825                                 irmp_pause_time -= irmp_param.pause_1_len_min;
4826                             }
4827                             else
4828                             {
4829                                 irmp_pause_time = 0;
4830                             }
4831                         }
4832 #ifdef ANALYZE
4833                         ANALYZE_NEWLINE ();
4834 #endif // ANALYZE
4835                         wait_for_space = 0;
4836                     }
4837                     else
4838 #endif // IRMP_SUPPORT_SERIAL == 1
4839
4840 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
4841                     if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16)       // Samsung: 16th bit
4842                     {
4843                         if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
4844                             irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
4845                         {
4846 #ifdef ANALYZE
4847                             ANALYZE_PRINTF ("SYNC\n");
4848 #endif // ANALYZE
4849                             wait_for_space = 0;
4850                             irmp_bit++;
4851                         }
4852                         else  if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
4853                         {
4854 #if IRMP_SUPPORT_SAMSUNG48_PROTOCOL == 1
4855 #ifdef ANALYZE
4856                             ANALYZE_PRINTF ("Switching to SAMSUNG48 protocol ");
4857 #endif // ANALYZE
4858                             irmp_param.protocol         = IRMP_SAMSUNG48_PROTOCOL;
4859                             irmp_param.command_offset   = SAMSUNG48_COMMAND_OFFSET;
4860                             irmp_param.command_end      = SAMSUNG48_COMMAND_OFFSET + SAMSUNG48_COMMAND_LEN;
4861                             irmp_param.complete_len     = SAMSUNG48_COMPLETE_DATA_LEN;
4862 #else
4863 #ifdef ANALYZE
4864                             ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol ");
4865 #endif // ANALYZE
4866                             irmp_param.protocol         = IRMP_SAMSUNG32_PROTOCOL;
4867                             irmp_param.command_offset   = SAMSUNG32_COMMAND_OFFSET;
4868                             irmp_param.command_end      = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
4869                             irmp_param.complete_len     = SAMSUNG32_COMPLETE_DATA_LEN;
4870 #endif
4871                             if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
4872                             {
4873 #ifdef ANALYZE
4874                                 ANALYZE_PUTCHAR ('1');
4875                                 ANALYZE_NEWLINE ();
4876 #endif // ANALYZE
4877                                 irmp_store_bit (1);
4878                                 wait_for_space = 0;
4879                             }
4880                             else
4881                             {
4882 #ifdef ANALYZE
4883                                 ANALYZE_PUTCHAR ('0');
4884                                 ANALYZE_NEWLINE ();
4885 #endif // ANALYZE
4886                                 irmp_store_bit (0);
4887                                 wait_for_space = 0;
4888                             }
4889                         }
4890                         else
4891                         {                                                           // timing incorrect!
4892 #ifdef ANALYZE
4893                             ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
4894                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4895 #endif // ANALYZE
4896                             irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit
4897                             irmp_pause_time         = 0;
4898                         }
4899                     }
4900                     else
4901 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
4902
4903 #if IRMP_SUPPORT_NEC16_PROTOCOL
4904 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
4905                     if (irmp_param.protocol == IRMP_NEC42_PROTOCOL &&
4906 #else // IRMP_SUPPORT_NEC_PROTOCOL instead
4907                     if (irmp_param.protocol == IRMP_NEC_PROTOCOL &&
4908 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
4909                         irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
4910                     {
4911 #ifdef ANALYZE
4912                         ANALYZE_PRINTF ("Switching to NEC16 protocol\n");
4913 #endif // ANALYZE
4914                         irmp_param.protocol         = IRMP_NEC16_PROTOCOL;
4915                         irmp_param.address_offset   = NEC16_ADDRESS_OFFSET;
4916                         irmp_param.address_end      = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN;
4917                         irmp_param.command_offset   = NEC16_COMMAND_OFFSET;
4918                         irmp_param.command_end      = NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN;
4919                         irmp_param.complete_len     = NEC16_COMPLETE_DATA_LEN;
4920                         wait_for_space = 0;
4921                     }
4922                     else
4923 #endif // IRMP_SUPPORT_NEC16_PROTOCOL
4924
4925 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
4926                     if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
4927                     {
4928                         if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
4929                         {
4930                             if (irmp_bit == 1)                                      // Bang & Olufsen: 3rd bit
4931                             {
4932                                 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
4933                                 {
4934 #ifdef ANALYZE
4935                                     ANALYZE_PRINTF ("3rd start bit\n");
4936 #endif // ANALYZE
4937                                     wait_for_space = 0;
4938                                     irmp_bit++;
4939                                 }
4940                                 else
4941                                 {                                                   // timing incorrect!
4942 #ifdef ANALYZE
4943                                     ANALYZE_PRINTF ("error 3a B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
4944                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4945 #endif // ANALYZE
4946                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit
4947                                     irmp_pause_time         = 0;
4948                                 }
4949                             }
4950                             else if (irmp_bit == 19)                                // Bang & Olufsen: trailer bit
4951                             {
4952                                 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
4953                                 {
4954 #ifdef ANALYZE
4955                                     ANALYZE_PRINTF ("trailer bit\n");
4956 #endif // ANALYZE
4957                                     wait_for_space = 0;
4958                                     irmp_bit++;
4959                                 }
4960                                 else
4961                                 {                                                   // timing incorrect!
4962 #ifdef ANALYZE
4963                                     ANALYZE_PRINTF ("error 3b B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
4964                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
4965 #endif // ANALYZE
4966                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit
4967                                     irmp_pause_time         = 0;
4968                                 }
4969                             }
4970                             else
4971                             {
4972                                 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
4973                                 {                                                   // pulse & pause timings correct for "1"?
4974 #ifdef ANALYZE
4975                                     ANALYZE_PUTCHAR ('1');
4976                                     ANALYZE_NEWLINE ();
4977 #endif // ANALYZE
4978                                     irmp_store_bit (1);
4979                                     last_value = 1;
4980                                     wait_for_space = 0;
4981                                 }
4982                                 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
4983                                 {                                                   // pulse & pause timings correct for "0"?
4984 #ifdef ANALYZE
4985                                     ANALYZE_PUTCHAR ('0');
4986                                     ANALYZE_NEWLINE ();
4987 #endif // ANALYZE
4988                                     irmp_store_bit (0);
4989                                     last_value = 0;
4990                                     wait_for_space = 0;
4991                                 }
4992                                 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
4993                                 {
4994 #ifdef ANALYZE
4995                                     ANALYZE_PUTCHAR (last_value + '0');
4996                                     ANALYZE_NEWLINE ();
4997 #endif // ANALYZE
4998                                     irmp_store_bit (last_value);
4999                                     wait_for_space = 0;
5000                                 }
5001                                 else
5002                                 {                                                   // timing incorrect!
5003 #ifdef ANALYZE
5004                                     ANALYZE_PRINTF ("error 3c B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
5005                                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
5006 #endif // ANALYZE
5007                                     irmp_start_bit_detected = 0;                    // reset flags and wait for next start bit
5008                                     irmp_pause_time         = 0;
5009                                 }
5010                             }
5011                         }
5012                         else
5013                         {                                                           // timing incorrect!
5014 #ifdef ANALYZE
5015                             ANALYZE_PRINTF ("error 3d B&O: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
5016                             ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
5017 #endif // ANALYZE
5018                             irmp_start_bit_detected = 0;                            // reset flags and wait for next start bit
5019                             irmp_pause_time         = 0;
5020                         }
5021                     }
5022                     else
5023 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
5024
5025 #if IRMP_SUPPORT_RCMM_PROTOCOL == 1
5026                     if (irmp_param.protocol == IRMP_RCMM32_PROTOCOL)
5027                     {
5028                         if (irmp_pause_time >= RCMM32_BIT_00_PAUSE_LEN_MIN && irmp_pause_time <= RCMM32_BIT_00_PAUSE_LEN_MAX)
5029                         {
5030 #ifdef ANALYZE
5031                             ANALYZE_PUTCHAR ('0');
5032                             ANALYZE_PUTCHAR ('0');
5033 #endif // ANALYZE
5034                             irmp_store_bit (0);
5035                             irmp_store_bit (0);
5036                         }
5037                         else if (irmp_pause_time >= RCMM32_BIT_01_PAUSE_LEN_MIN && irmp_pause_time <= RCMM32_BIT_01_PAUSE_LEN_MAX)
5038                         {
5039 #ifdef ANALYZE
5040                             ANALYZE_PUTCHAR ('0');
5041                             ANALYZE_PUTCHAR ('1');
5042 #endif // ANALYZE
5043                             irmp_store_bit (0);
5044                             irmp_store_bit (1);
5045                         }
5046                         else if (irmp_pause_time >= RCMM32_BIT_10_PAUSE_LEN_MIN && irmp_pause_time <= RCMM32_BIT_10_PAUSE_LEN_MAX)
5047                         {
5048 #ifdef ANALYZE
5049                             ANALYZE_PUTCHAR ('1');
5050                             ANALYZE_PUTCHAR ('0');
5051 #endif // ANALYZE
5052                             irmp_store_bit (1);
5053                             irmp_store_bit (0);
5054                         }
5055                         else if (irmp_pause_time >= RCMM32_BIT_11_PAUSE_LEN_MIN && irmp_pause_time <= RCMM32_BIT_11_PAUSE_LEN_MAX)
5056                         {
5057 #ifdef ANALYZE
5058                             ANALYZE_PUTCHAR ('1');
5059                             ANALYZE_PUTCHAR ('1');
5060 #endif // ANALYZE
5061                             irmp_store_bit (1);
5062                             irmp_store_bit (1);
5063                         }
5064 #ifdef ANALYZE
5065                         ANALYZE_PRINTF ("\n");
5066 #endif // ANALYZE
5067                         wait_for_space = 0;
5068                     }
5069                     else
5070 #endif
5071
5072                     if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
5073                         irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
5074                     {                                                               // pulse & pause timings correct for "1"?
5075 #ifdef ANALYZE
5076                         ANALYZE_PUTCHAR ('1');
5077                         ANALYZE_NEWLINE ();
5078 #endif // ANALYZE
5079                         irmp_store_bit (1);
5080                         wait_for_space = 0;
5081                     }
5082                     else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
5083                              irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
5084                     {                                                               // pulse & pause timings correct for "0"?
5085 #ifdef ANALYZE
5086                         ANALYZE_PUTCHAR ('0');
5087                         ANALYZE_NEWLINE ();
5088 #endif // ANALYZE
5089                         irmp_store_bit (0);
5090                         wait_for_space = 0;
5091                     }
5092                     else
5093 #if IRMP_SUPPORT_KATHREIN_PROTOCOL
5094
5095                     if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL &&
5096                         irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX &&
5097                         (((irmp_bit == 8 || irmp_bit == 6) &&
5098                                 irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) ||
5099                          (irmp_bit == 12 &&
5100                                 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)))
5101
5102                     {
5103                         if (irmp_bit == 8)
5104                         {
5105                             irmp_bit++;
5106 #ifdef ANALYZE
5107                             ANALYZE_PUTCHAR ('S');
5108                             ANALYZE_NEWLINE ();
5109 #endif // ANALYZE
5110                             irmp_tmp_command <<= 1;
5111                         }
5112                         else
5113                         {
5114 #ifdef ANALYZE
5115                             ANALYZE_PUTCHAR ('S');
5116                             ANALYZE_NEWLINE ();
5117 #endif // ANALYZE
5118                             irmp_store_bit (1);
5119                         }
5120                         wait_for_space = 0;
5121                     }
5122                     else
5123 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL
5124                     {                                                               // timing incorrect!
5125 #ifdef ANALYZE
5126                         ANALYZE_PRINTF ("error 3: timing not correct: data bit %d,  pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
5127                         ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
5128 #endif // ANALYZE
5129                         irmp_start_bit_detected = 0;                                // reset flags and wait for next start bit
5130                         irmp_pause_time         = 0;
5131                     }
5132
5133                     irmp_pulse_time = 1;                                            // set counter to 1, not 0
5134                 }
5135             }
5136             else
5137             {                                                                       // counting the pulse length ...
5138                 if (! irmp_input)                                                   // still light?
5139                 {                                                                   // yes...
5140                     irmp_pulse_time++;                                              // increment counter
5141                 }
5142                 else
5143                 {                                                                   // now it's dark!
5144                     wait_for_space  = 1;                                            // let's count the time (see above)
5145                     irmp_pause_time = 1;                                            // set pause counter to 1, not 0
5146
5147 #if IRMP_SUPPORT_RCII_PROTOCOL == 1
5148                     if (irmp_param.protocol == IRMP_RCII_PROTOCOL && waiting_for_2nd_pulse)
5149                     {
5150 printf ("fm: %d %d\n", irmp_pulse_time * 1000000 / F_INTERRUPTS, RCII_BIT_LEN * 1000000 / F_INTERRUPTS); // fm: Ausgabe ist "1000 466" oder "1533 466"
5151 #if 0
5152                         if (irmp_pulse_time >= RCII_BIT_LEN)
5153                         {
5154                             irmp_pulse_time -= RCII_BIT_LEN;
5155                             last_value = 0;
5156                         }
5157                         else
5158                         {
5159                             last_value = 1;
5160                         }
5161 #else // fm: das reicht für RCII
5162                             irmp_pulse_time -= RCII_BIT_LEN;
5163                             last_value = 0;
5164 #endif
5165
5166 #ifdef ANALYZE
5167                         ANALYZE_PRINTF ("RCII: got 2nd pulse, irmp_pulse_time = %d\n", irmp_pulse_time);
5168 #endif
5169                         waiting_for_2nd_pulse = 0;
5170                     }
5171 #endif
5172                 }
5173             }
5174
5175             if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0)    // enough bits received?
5176             {
5177                 if (last_irmp_command == irmp_tmp_command && key_repetition_len < AUTO_FRAME_REPETITION_LEN)
5178                 {
5179                     repetition_frame_number++;
5180                 }
5181                 else
5182                 {
5183                     repetition_frame_number = 0;
5184                 }
5185
5186 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
5187                 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
5188                 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
5189                 {
5190 #ifdef ANALYZE
5191                     ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5192                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5193 #endif // ANALYZE
5194                     key_repetition_len = 0;
5195                 }
5196                 else
5197 #endif
5198
5199 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
5200                 // if ORTEK protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame
5201                 if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL && repetition_frame_number == 1)
5202                 {
5203 #ifdef ANALYZE
5204                     ANALYZE_PRINTF ("code skipped: ORTEK auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5205                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5206 #endif // ANALYZE
5207                     key_repetition_len = 0;
5208                 }
5209                 else
5210 #endif
5211
5212 #if 0 && IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1    // fm 2015-12-02: don't ignore every 2nd frame
5213                 // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame
5214                 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1)
5215                 {
5216 #ifdef ANALYZE
5217                     ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5218                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5219 #endif // ANALYZE
5220                     key_repetition_len = 0;
5221                 }
5222                 else
5223 #endif
5224
5225 #if 0 && IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1     // fm 2015-12-02: don't ignore every 2nd frame
5226                 // if SAMSUNG32 or SAMSUNG48 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
5227                 if ((irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL || irmp_param.protocol == IRMP_SAMSUNG48_PROTOCOL) && (repetition_frame_number & 0x01))
5228                 {
5229 #ifdef ANALYZE
5230                     ANALYZE_PRINTF ("code skipped: SAMSUNG32/SAMSUNG48 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5231                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5232 #endif // ANALYZE
5233                     key_repetition_len = 0;
5234                 }
5235                 else
5236 #endif
5237
5238 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
5239                 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
5240                 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
5241                 {
5242 #ifdef ANALYZE
5243                     ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5244                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5245 #endif // ANALYZE
5246                     key_repetition_len = 0;
5247                 }
5248                 else
5249 #endif
5250
5251 #if IRMP_SUPPORT_SPEAKER_PROTOCOL == 1
5252                 // if SPEAKER protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
5253                 if (irmp_param.protocol == IRMP_SPEAKER_PROTOCOL && (repetition_frame_number & 0x01))
5254                 {
5255 #ifdef ANALYZE
5256                     ANALYZE_PRINTF ("code skipped: SPEAKER auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
5257                                     repetition_frame_number + 1, key_repetition_len, AUTO_FRAME_REPETITION_LEN);
5258 #endif // ANALYZE
5259                     key_repetition_len = 0;
5260                 }
5261                 else
5262 #endif
5263
5264                 {
5265 #ifdef ANALYZE
5266                     ANALYZE_PRINTF ("%8.3fms code detected, length = %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit);
5267 #endif // ANALYZE
5268                     irmp_ir_detected = TRUE;
5269
5270 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
5271                     if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
5272                     {                                                               // check for repetition frame
5273                         if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
5274                         {
5275                             irmp_tmp_command = last_irmp_denon_command;             // use command received before!
5276                             last_irmp_denon_command = 0;
5277
5278                             irmp_protocol = irmp_param.protocol;                    // store protocol
5279                             irmp_address = irmp_tmp_address;                        // store address
5280                             irmp_command = irmp_tmp_command;                        // store command
5281                         }
5282                         else
5283                         {
5284                             if ((irmp_tmp_command & 0x01) == 0x00)
5285                             {
5286 #ifdef ANALYZE
5287                                 ANALYZE_PRINTF ("%8.3fms info Denon: waiting for inverted command repetition\n", (double) (time_counter * 1000) / F_INTERRUPTS);
5288 #endif // ANALYZE
5289                                 last_irmp_denon_command = irmp_tmp_command;
5290                                 denon_repetition_len = 0;
5291                                 irmp_ir_detected = FALSE;
5292                             }
5293                             else
5294                             {
5295 #ifdef ANALYZE
5296                                 ANALYZE_PRINTF ("%8.3fms warning Denon: got unexpected inverted command, ignoring it\n", (double) (time_counter * 1000) / F_INTERRUPTS);
5297 #endif // ANALYZE
5298                                 last_irmp_denon_command = 0;
5299                                 irmp_ir_detected = FALSE;
5300                             }
5301                         }
5302                     }
5303                     else
5304 #endif // IRMP_SUPPORT_DENON_PROTOCOL
5305
5306 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
5307                     if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
5308                     {                                                               // Grundig start frame?
5309 #ifdef ANALYZE
5310                         ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
5311 #endif // ANALYZE
5312                         irmp_ir_detected = FALSE;
5313                     }
5314                     else
5315 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
5316
5317 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
5318                     if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
5319                     {                                                               // Nokia start frame?
5320 #ifdef ANALYZE
5321                         ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n");
5322 #endif // ANALYZE
5323                         irmp_ir_detected = FALSE;
5324                     }
5325                     else
5326 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
5327                     {
5328 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
5329                         if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0)  // repetition frame
5330                         {
5331                             if (key_repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)
5332                             {
5333 #ifdef ANALYZE
5334                                 ANALYZE_PRINTF ("Detected NEC repetition frame, key_repetition_len = %d\n", key_repetition_len);
5335                                 ANALYZE_ONLY_NORMAL_PRINTF("REPETETION FRAME                ");
5336 #endif // ANALYZE
5337                                 irmp_tmp_address = last_irmp_address;                   // address is last address
5338                                 irmp_tmp_command = last_irmp_command;                   // command is last command
5339                                 irmp_flags |= IRMP_FLAG_REPETITION;
5340                                 key_repetition_len = 0;
5341                             }
5342                             else
5343                             {
5344 #ifdef ANALYZE
5345                                 ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, key_repetition_len = %d > %d\n",
5346                                                 key_repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);
5347 #endif // ANALYZE
5348                                 irmp_ir_detected = FALSE;
5349                             }
5350                         }
5351 #endif // IRMP_SUPPORT_NEC_PROTOCOL
5352
5353 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
5354                         if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
5355                         {
5356                             uint_fast8_t xor_value;
5357
5358                             xor_value = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4);
5359
5360                             if (xor_value != (xor_check[2] & 0x0F))
5361                             {
5362 #ifdef ANALYZE
5363                                 ANALYZE_PRINTF ("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor_value, xor_check[2] & 0x0F);
5364 #endif // ANALYZE
5365                                 irmp_ir_detected = FALSE;
5366                             }
5367
5368                             xor_value = xor_check[2] ^ xor_check[3] ^ xor_check[4];
5369
5370                             if (xor_value != xor_check[5])
5371                             {
5372 #ifdef ANALYZE
5373                                 ANALYZE_PRINTF ("error 5: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor_value, xor_check[5]);
5374 #endif // ANALYZE
5375                                 irmp_ir_detected = FALSE;
5376                             }
5377
5378                             irmp_flags |= genre2;       // write the genre2 bits into MSB of the flag byte
5379                         }
5380 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
5381
5382 #if IRMP_SUPPORT_ORTEK_PROTOCOL == 1
5383                         if (irmp_param.protocol == IRMP_ORTEK_PROTOCOL)
5384                         {
5385                             if (parity == PARITY_CHECK_FAILED)
5386                             {
5387 #ifdef ANALYZE
5388                                 ANALYZE_PRINTF ("error 6: parity check failed\n");
5389 #endif // ANALYZE
5390                                 irmp_ir_detected = FALSE;
5391                             }
5392
5393                             if ((irmp_tmp_address & 0x03) == 0x02)
5394                             {
5395 #ifdef ANALYZE
5396                                 ANALYZE_PRINTF ("code skipped: ORTEK end of transmission frame (key release)\n");
5397 #endif // ANALYZE
5398                                 irmp_ir_detected = FALSE;
5399                             }
5400                             irmp_tmp_address >>= 2;
5401                         }
5402 #endif // IRMP_SUPPORT_ORTEK_PROTOCOL == 1
5403
5404 #if IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL == 1
5405                         if (irmp_param.protocol == IRMP_MITSU_HEAVY_PROTOCOL)
5406                         {
5407                             check = irmp_tmp_command >> 8;                    // inverted upper byte == lower byte?
5408                             check = ~ check;
5409                             if (check == (irmp_tmp_command & 0xFF)) {         //ok:
5410                               irmp_tmp_command &= 0xFF;
5411                             }
5412                             else  mitsu_parity = PARITY_CHECK_FAILED;
5413                             if (mitsu_parity == PARITY_CHECK_FAILED)
5414                             {
5415 #ifdef ANALYZE
5416                                 ANALYZE_PRINTF ("error 7: parity check failed\n");
5417 #endif // ANALYZE
5418                                 irmp_ir_detected = FALSE;
5419                             }
5420                         }
5421 #endif // IRMP_SUPPORT_MITSU_HEAVY_PROTOCOL
5422
5423 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
5424                         if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG)     // RC6 mode = 6?
5425                         {
5426                             irmp_protocol = IRMP_RC6A_PROTOCOL;
5427                         }
5428                         else
5429 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
5430                         {
5431                             irmp_protocol = irmp_param.protocol;
5432                         }
5433
5434 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
5435                         if (irmp_param.protocol == IRMP_FDC_PROTOCOL)
5436                         {
5437                             if (irmp_tmp_command & 0x000F)                          // released key?
5438                             {
5439                                 irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80;  // yes, set bit 7
5440                             }
5441                             else
5442                             {
5443                                 irmp_tmp_command >>= 4;                             // no, it's a pressed key
5444                             }
5445                             irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00;   // 000000CCCCAAAAAA -> 0000CCCC00000000
5446                             irmp_tmp_address &= 0x003F;
5447                         }
5448 #endif
5449
5450                         irmp_address = irmp_tmp_address;                            // store address
5451 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
5452                         if (irmp_param.protocol == IRMP_NEC_PROTOCOL)
5453                         {
5454                             last_irmp_address = irmp_tmp_address;                   // store as last address, too
5455                         }
5456 #endif
5457
5458 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
5459                         if (irmp_param.protocol == IRMP_RC5_PROTOCOL)
5460                         {
5461                             irmp_tmp_command |= rc5_cmd_bit6;                       // store bit 6
5462                         }
5463 #endif
5464 #if IRMP_SUPPORT_S100_PROTOCOL == 1
5465                         if (irmp_param.protocol == IRMP_S100_PROTOCOL)
5466                         {
5467                             irmp_tmp_command |= rc5_cmd_bit6;                       // store bit 6
5468                         }
5469 #endif
5470                         irmp_command = irmp_tmp_command;                            // store command
5471
5472 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
5473                         irmp_id = irmp_tmp_id;
5474 #endif
5475                     }
5476                 }
5477
5478                 if (irmp_ir_detected)
5479                 {
5480                     if (last_irmp_command == irmp_tmp_command &&
5481                         last_irmp_address == irmp_tmp_address &&
5482                         key_repetition_len < IRMP_KEY_REPETITION_LEN)
5483                     {
5484                         irmp_flags |= IRMP_FLAG_REPETITION;
5485                     }
5486
5487                     last_irmp_address = irmp_tmp_address;                           // store as last address, too
5488                     last_irmp_command = irmp_tmp_command;                           // store as last command, too
5489
5490                     key_repetition_len = 0;
5491                 }
5492                 else
5493                 {
5494 #ifdef ANALYZE
5495                     ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
5496 #endif // ANALYZE
5497                 }
5498
5499                 irmp_start_bit_detected = 0;                                        // and wait for next start bit
5500                 irmp_tmp_command        = 0;
5501                 irmp_pulse_time         = 0;
5502                 irmp_pause_time         = 0;
5503
5504 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
5505                 if (irmp_protocol == IRMP_JVC_PROTOCOL)                             // the stop bit of JVC frame is also start bit of next frame
5506                 {                                                                   // set pulse time here!
5507                     irmp_pulse_time = ((uint_fast8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME));
5508                 }
5509 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
5510             }
5511         }
5512     }
5513
5514 #if defined(STELLARIS_ARM_CORTEX_M4)
5515     // Clear the timer interrupt
5516     TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
5517 #endif
5518
5519 #if (defined(_CHIBIOS_RT_) || defined(_CHIBIOS_NIL_)) && IRMP_USE_EVENT == 1
5520     if (IRMP_EVENT_THREAD_PTR != NULL && irmp_ir_detected)
5521         chEvtSignalI(IRMP_EVENT_THREAD_PTR,IRMP_EVENT_BIT);
5522 #endif
5523
5524 #if IRMP_USE_IDLE_CALL == 1
5525     // check if there is no ongoing transmission or repetition
5526     if (!irmp_start_bit_detected && !irmp_pulse_time
5527         && key_repetition_len > IRMP_KEY_REPETITION_LEN)
5528     {
5529         // no ongoing transmission
5530         // enough time passed since last decoded signal that a repetition won't affect our output
5531
5532         irmp_idle();
5533     }
5534 #endif // IRMP_USE_IDLE_CALL
5535
5536     return (irmp_ir_detected);
5537 }
5538
5539 #ifdef ANALYZE
5540
5541 /*---------------------------------------------------------------------------------------------------------------------------------------------------
5542  * main functions - for Unix/Linux + Windows only!
5543  *
5544  * AVR: see main.c!
5545  *
5546  * Compile it under linux with:
5547  * cc irmp.c -o irmp
5548  *
5549  * usage: ./irmp [-v|-s|-a|-l] < file
5550  *
5551  * options:
5552  *   -v verbose
5553  *   -s silent
5554  *   -a analyze
5555  *   -l list pulse/pauses
5556  *---------------------------------------------------------------------------------------------------------------------------------------------------
5557  */
5558
5559 void
5560 print_spectrum (char * text, int * buf, int is_pulse)
5561 {
5562     int     i;
5563     int     j;
5564     int     min;
5565     int     max;
5566     int     max_value = 0;
5567     int     value;
5568     int     sum = 0;
5569     int     counter = 0;
5570     double  average = 0;
5571     double  tolerance;
5572
5573     puts ("-----------------------------------------------------------------------------");
5574     printf ("%s:\n", text);
5575
5576     for (i = 0; i < 256; i++)
5577     {
5578         if (buf[i] > max_value)
5579         {
5580             max_value = buf[i];
5581         }
5582     }
5583
5584     for (i = 1; i < 200; i++)
5585     {
5586         if (buf[i] > 0)
5587         {
5588             printf ("%3d ", i);
5589             value = (buf[i] * 60) / max_value;
5590
5591             for (j = 0; j < value; j++)
5592             {
5593                 putchar ('o');
5594             }
5595             printf (" %d\n", buf[i]);
5596
5597             sum += i * buf[i];
5598             counter += buf[i];
5599         }
5600         else
5601         {
5602             max = i - 1;
5603
5604             if (counter > 0)
5605             {
5606                 average = (float) sum / (float) counter;
5607
5608                 if (is_pulse)
5609                 {
5610                     printf ("pulse ");
5611                 }
5612                 else
5613                 {
5614                     printf ("pause ");
5615                 }
5616
5617                 printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS);
5618                 printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS);
5619                 printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS);
5620
5621                 tolerance = (max - average);
5622
5623                 if (average - min > tolerance)
5624                 {
5625                     tolerance = average - min;
5626                 }
5627
5628                 tolerance = tolerance * 100 / average;
5629                 printf ("tol: %4.1f%%\n", tolerance);
5630             }
5631
5632             counter = 0;
5633             sum = 0;
5634             min = i + 1;
5635         }
5636     }
5637 }
5638
5639 #define STATE_LEFT_SHIFT    0x01
5640 #define STATE_RIGHT_SHIFT   0x02
5641 #define STATE_LEFT_CTRL     0x04
5642 #define STATE_LEFT_ALT      0x08
5643 #define STATE_RIGHT_ALT     0x10
5644
5645 #define KEY_ESCAPE          0x1B            // keycode = 0x006e
5646 #define KEY_MENUE           0x80            // keycode = 0x0070
5647 #define KEY_BACK            0x81            // keycode = 0x0071
5648 #define KEY_FORWARD         0x82            // keycode = 0x0072
5649 #define KEY_ADDRESS         0x83            // keycode = 0x0073
5650 #define KEY_WINDOW          0x84            // keycode = 0x0074
5651 #define KEY_1ST_PAGE        0x85            // keycode = 0x0075
5652 #define KEY_STOP            0x86            // keycode = 0x0076
5653 #define KEY_MAIL            0x87            // keycode = 0x0077
5654 #define KEY_FAVORITES       0x88            // keycode = 0x0078
5655 #define KEY_NEW_PAGE        0x89            // keycode = 0x0079
5656 #define KEY_SETUP           0x8A            // keycode = 0x007a
5657 #define KEY_FONT            0x8B            // keycode = 0x007b
5658 #define KEY_PRINT           0x8C            // keycode = 0x007c
5659 #define KEY_ON_OFF          0x8E            // keycode = 0x007c
5660
5661 #define KEY_INSERT          0x90            // keycode = 0x004b
5662 #define KEY_DELETE          0x91            // keycode = 0x004c
5663 #define KEY_LEFT            0x92            // keycode = 0x004f
5664 #define KEY_HOME            0x93            // keycode = 0x0050
5665 #define KEY_END             0x94            // keycode = 0x0051
5666 #define KEY_UP              0x95            // keycode = 0x0053
5667 #define KEY_DOWN            0x96            // keycode = 0x0054
5668 #define KEY_PAGE_UP         0x97            // keycode = 0x0055
5669 #define KEY_PAGE_DOWN       0x98            // keycode = 0x0056
5670 #define KEY_RIGHT           0x99            // keycode = 0x0059
5671 #define KEY_MOUSE_1         0x9E            // keycode = 0x0400
5672 #define KEY_MOUSE_2         0x9F            // keycode = 0x0800
5673
5674 static uint_fast8_t
5675 get_fdc_key (uint_fast16_t cmd)
5676 {
5677     static uint8_t key_table[128] =
5678     {
5679      // 0     1    2    3    4    5    6    7    8     9     A     B     C     D    E    F
5680          0,   '^', '1', '2', '3', '4', '5', '6', '7',  '8',  '9',  '0',  0xDF, '´', 0,   '\b',
5681         '\t', 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i',  'o',  'p',  0xFC, '+',   0,   0,   'a',
5682         's',  'd', 'f', 'g', 'h', 'j', 'k', 'l', 0xF6, 0xE4, '#',  '\r', 0,    '<', 'y', 'x',
5683         'c',  'v', 'b', 'n', 'm', ',', '.', '-', 0,    0,    0,    0,    0,    ' ', 0,   0,
5684
5685          0,   '°', '!', '"', '§', '$', '%', '&', '/',  '(',  ')',  '=',  '?',  '`', 0,   '\b',
5686         '\t', 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I',  'O',  'P',  0xDC, '*',  0,   0,   'A',
5687         'S',  'D', 'F', 'G', 'H', 'J', 'K', 'L', 0xD6, 0xC4, '\'', '\r', 0,    '>', 'Y', 'X',
5688         'C',  'V', 'B', 'N', 'M', ';', ':', '_', 0,    0,    0,    0,    0,    ' ', 0,   0
5689     };
5690     static uint_fast8_t state;
5691
5692     uint_fast8_t key = 0;
5693
5694     switch (cmd)
5695     {
5696         case 0x002C: state |=  STATE_LEFT_SHIFT;    break;              // pressed left shift
5697         case 0x00AC: state &= ~STATE_LEFT_SHIFT;    break;              // released left shift
5698         case 0x0039: state |=  STATE_RIGHT_SHIFT;   break;              // pressed right shift
5699         case 0x00B9: state &= ~STATE_RIGHT_SHIFT;   break;              // released right shift
5700         case 0x003A: state |=  STATE_LEFT_CTRL;     break;              // pressed left ctrl
5701         case 0x00BA: state &= ~STATE_LEFT_CTRL;     break;              // released left ctrl
5702         case 0x003C: state |=  STATE_LEFT_ALT;      break;              // pressed left alt
5703         case 0x00BC: state &= ~STATE_LEFT_ALT;      break;              // released left alt
5704         case 0x003E: state |=  STATE_RIGHT_ALT;     break;              // pressed left alt
5705         case 0x00BE: state &= ~STATE_RIGHT_ALT;     break;              // released left alt
5706
5707         case 0x006e: key = KEY_ESCAPE;              break;
5708         case 0x004b: key = KEY_INSERT;              break;
5709         case 0x004c: key = KEY_DELETE;              break;
5710         case 0x004f: key = KEY_LEFT;                break;
5711         case 0x0050: key = KEY_HOME;                break;
5712         case 0x0051: key = KEY_END;                 break;
5713         case 0x0053: key = KEY_UP;                  break;
5714         case 0x0054: key = KEY_DOWN;                break;
5715         case 0x0055: key = KEY_PAGE_UP;             break;
5716         case 0x0056: key = KEY_PAGE_DOWN;           break;
5717         case 0x0059: key = KEY_RIGHT;               break;
5718         case 0x0400: key = KEY_MOUSE_1;             break;
5719         case 0x0800: key = KEY_MOUSE_2;             break;
5720
5721         default:
5722         {
5723             if (!(cmd & 0x80))                      // pressed key
5724             {
5725                 if (cmd >= 0x70 && cmd <= 0x7F)     // function keys
5726                 {
5727                     key = cmd + 0x10;               // 7x -> 8x
5728                 }
5729                 else if (cmd < 64)                  // key listed in key_table
5730                 {
5731                     if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT))
5732                     {
5733                         switch (cmd)
5734                         {
5735                             case 0x0003: key = 0xB2;    break; // upper 2
5736                             case 0x0008: key = '{';     break;
5737                             case 0x0009: key = '[';     break;
5738                             case 0x000A: key = ']';     break;
5739                             case 0x000B: key = '}';     break;
5740                             case 0x000C: key = '\\';    break;
5741                             case 0x001C: key = '~';     break;
5742                             case 0x002D: key = '|';     break;
5743                             case 0x0034: key = 0xB5;    break; // Mu
5744                         }
5745                     }
5746                     else if (state & (STATE_LEFT_CTRL))
5747                     {
5748                         if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z')
5749                         {
5750                             key = key_table[cmd] - 'a' + 1;
5751                         }
5752                         else
5753                         {
5754                             key = key_table[cmd];
5755                         }
5756                     }
5757                     else
5758                     {
5759                         int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0);
5760
5761                         if (key_table[idx])
5762                         {
5763                             key = key_table[idx];
5764                         }
5765                     }
5766                 }
5767             }
5768             break;
5769         }
5770     }
5771
5772     return (key);
5773 }
5774
5775 static int         analyze = FALSE;
5776 static int         list = FALSE;
5777 static IRMP_DATA   irmp_data;
5778 static int         expected_protocol;
5779 static int         expected_address;
5780 static int         expected_command;
5781 static int         do_check_expected_values;
5782
5783 static void
5784 next_tick (void)
5785 {
5786     if (! analyze && ! list)
5787     {
5788         (void) irmp_ISR ();
5789
5790         if (irmp_get_data (&irmp_data))
5791         {
5792             uint_fast8_t key;
5793
5794             ANALYZE_ONLY_NORMAL_PUTCHAR (' ');
5795
5796             if (verbose)
5797             {
5798                 printf ("%8.3fms ", (double) (time_counter * 1000) / F_INTERRUPTS);
5799             }
5800
5801             if (irmp_data.protocol == IRMP_ACP24_PROTOCOL)
5802             {
5803                 uint16_t    temp = (irmp_data.command & 0x000F) + 15;
5804
5805                 printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, temp=%d",
5806                         irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, temp);
5807             }
5808             else if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0)
5809             {
5810                 if ((key >= 0x20 && key < 0x7F) || key >= 0xA0)
5811                 {
5812                     printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x, key='%c'",
5813                             irmp_data.protocol,  irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key, key);
5814                 }
5815                 else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F))                 // function keys
5816                 {
5817                     char * p = (char *) NULL;
5818
5819                     switch (key)
5820                     {
5821                         case '\t'                : p = "TAB";           break;
5822                         case '\r'                : p = "CR";            break;
5823                         case KEY_ESCAPE          : p = "ESCAPE";        break;
5824                         case KEY_MENUE           : p = "MENUE";         break;
5825                         case KEY_BACK            : p = "BACK";          break;
5826                         case KEY_FORWARD         : p = "FORWARD";       break;
5827                         case KEY_ADDRESS         : p = "ADDRESS";       break;
5828                         case KEY_WINDOW          : p = "WINDOW";        break;
5829                         case KEY_1ST_PAGE        : p = "1ST_PAGE";      break;
5830                         case KEY_STOP            : p = "STOP";          break;
5831                         case KEY_MAIL            : p = "MAIL";          break;
5832                         case KEY_FAVORITES       : p = "FAVORITES";     break;
5833                         case KEY_NEW_PAGE        : p = "NEW_PAGE";      break;
5834                         case KEY_SETUP           : p = "SETUP";         break;
5835                         case KEY_FONT            : p = "FONT";          break;
5836                         case KEY_PRINT           : p = "PRINT";         break;
5837                         case KEY_ON_OFF          : p = "ON_OFF";        break;
5838
5839                         case KEY_INSERT          : p = "INSERT";        break;
5840                         case KEY_DELETE          : p = "DELETE";        break;
5841                         case KEY_LEFT            : p = "LEFT";          break;
5842                         case KEY_HOME            : p = "HOME";          break;
5843                         case KEY_END             : p = "END";           break;
5844                         case KEY_UP              : p = "UP";            break;
5845                         case KEY_DOWN            : p = "DOWN";          break;
5846                         case KEY_PAGE_UP         : p = "PAGE_UP";       break;
5847                         case KEY_PAGE_DOWN       : p = "PAGE_DOWN";     break;
5848                         case KEY_RIGHT           : p = "RIGHT";         break;
5849                         case KEY_MOUSE_1         : p = "KEY_MOUSE_1";   break;
5850                         case KEY_MOUSE_2         : p = "KEY_MOUSE_2";   break;
5851                         default                  : p = "<UNKNWON>";     break;
5852                     }
5853
5854                     printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x, key=%s",
5855                             irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key, p);
5856                 }
5857                 else
5858                 {
5859                     printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x, asc=0x%02x",
5860                             irmp_data.protocol,  irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags, key);
5861                 }
5862             }
5863             else
5864             {
5865                 printf ("p=%2d (%s), a=0x%04x, c=0x%04x, f=0x%02x",
5866                         irmp_data.protocol, irmp_protocol_names[irmp_data.protocol], irmp_data.address, irmp_data.command, irmp_data.flags);
5867             }
5868
5869             if (do_check_expected_values)
5870             {
5871                 if (irmp_data.protocol != expected_protocol ||
5872                     irmp_data.address  != expected_address  ||
5873                     irmp_data.command  != expected_command)
5874                 {
5875                     printf ("\nerror 7: expected values differ: p=%2d (%s), a=0x%04x, c=0x%04x\n",
5876                             expected_protocol, irmp_protocol_names[expected_protocol], expected_address, expected_command);
5877                 }
5878                 else
5879                 {
5880                     printf (" checked!\n");
5881                 }
5882                 do_check_expected_values = FALSE;                           // only check 1st frame in a line!
5883             }
5884             else
5885             {
5886                 putchar ('\n');
5887             }
5888         }
5889     }
5890 }
5891
5892 int
5893 main (int argc, char ** argv)
5894 {
5895     int         i;
5896     int         ch;
5897     int         last_ch = 0;
5898     int         pulse = 0;
5899     int         pause = 0;
5900
5901     int         start_pulses[256];
5902     int         start_pauses[256];
5903     int         pulses[256];
5904     int         pauses[256];
5905
5906     int         first_pulse = TRUE;
5907     int         first_pause = TRUE;
5908
5909     if (argc == 2)
5910     {
5911         if (! strcmp (argv[1], "-v"))
5912         {
5913             verbose = TRUE;
5914         }
5915         else if (! strcmp (argv[1], "-l"))
5916         {
5917             list = TRUE;
5918         }
5919         else if (! strcmp (argv[1], "-a"))
5920         {
5921             analyze = TRUE;
5922         }
5923         else if (! strcmp (argv[1], "-s"))
5924         {
5925             silent = TRUE;
5926         }
5927         else if (! strcmp (argv[1], "-r"))
5928         {
5929             radio = TRUE;
5930         }
5931     }
5932
5933     for (i = 0; i < 256; i++)
5934     {
5935         start_pulses[i] = 0;
5936         start_pauses[i] = 0;
5937         pulses[i] = 0;
5938         pauses[i] = 0;
5939     }
5940
5941     IRMP_PIN = 0xFF;
5942
5943     while ((ch = getchar ()) != EOF)
5944     {
5945         if (ch == '_' || ch == '0')
5946         {
5947             if (last_ch != ch)
5948             {
5949                 if (pause > 0)
5950                 {
5951                     if (list)
5952                     {
5953                         printf ("pause: %d\n", pause);
5954                     }
5955
5956                     if (analyze)
5957                     {
5958                         if (first_pause)
5959                         {
5960                             if (pause < 256)
5961                             {
5962                                 start_pauses[pause]++;
5963                             }
5964                             first_pause = FALSE;
5965                         }
5966                         else
5967                         {
5968                             if (pause < 256)
5969                             {
5970                                 pauses[pause]++;
5971                             }
5972                         }
5973                     }
5974                 }
5975                 pause = 0;
5976             }
5977             pulse++;
5978             IRMP_PIN = 0x00;
5979         }
5980         else if (ch == 0xaf || ch == '-' || ch == '1')
5981         {
5982             if (last_ch != ch)
5983             {
5984                 if (list)
5985                 {
5986                     printf ("pulse: %d ", pulse);
5987                 }
5988
5989                 if (analyze)
5990                 {
5991                     if (first_pulse)
5992                     {
5993                         if (pulse < 256)
5994                         {
5995                             start_pulses[pulse]++;
5996                         }
5997                         first_pulse = FALSE;
5998                     }
5999                     else
6000                     {
6001                         if (pulse < 256)
6002                         {
6003                             pulses[pulse]++;
6004                         }
6005                     }
6006                 }
6007                 pulse = 0;
6008             }
6009
6010             pause++;
6011             IRMP_PIN = 0xff;
6012         }
6013         else if (ch == '\n')
6014         {
6015             IRMP_PIN = 0xff;
6016             time_counter = 0;
6017
6018             if (list && pause > 0)
6019             {
6020                 printf ("pause: %d\n", pause);
6021             }
6022             pause = 0;
6023
6024             if (! analyze)
6025             {
6026                 for (i = 0; i < (int) ((10000.0 * F_INTERRUPTS) / 10000); i++)               // newline: long pause of 10000 msec
6027                 {
6028                     next_tick ();
6029                 }
6030             }
6031             first_pulse = TRUE;
6032             first_pause = TRUE;
6033         }
6034         else if (ch == '#')
6035         {
6036             time_counter = 0;
6037
6038             if (analyze)
6039             {
6040                 while ((ch = getchar()) != '\n' && ch != EOF)
6041                 {
6042                     ;
6043                 }
6044             }
6045             else
6046             {
6047                 char            buf[1024];
6048                 char *          p;
6049                 int             idx = -1;
6050
6051                 puts ("----------------------------------------------------------------------");
6052                 putchar (ch);
6053
6054
6055                 while ((ch = getchar()) != '\n' && ch != EOF)
6056                 {
6057                     if (ch != '\r')                                                         // ignore CR in DOS/Windows files
6058                     {
6059                         if (ch == '[' && idx == -1)
6060                         {
6061                             idx = 0;
6062                         }
6063                         else if (idx >= 0)
6064                         {
6065                             if (ch == ']')
6066                             {
6067                                 do_check_expected_values = FALSE;
6068                                 buf[idx] = '\0';
6069                                 idx = -1;
6070
6071                                 expected_protocol = atoi (buf);
6072
6073                                 if (expected_protocol > 0)
6074                                 {
6075                                     p = buf;
6076                                     while (*p)
6077                                     {
6078                                         if (*p == 'x')
6079                                         {
6080                                             p++;
6081
6082                                             if (sscanf (p, "%x", &expected_address) == 1)
6083                                             {
6084                                                 do_check_expected_values = TRUE;
6085                                             }
6086                                             break;
6087                                         }
6088                                         p++;
6089                                     }
6090
6091                                     if (do_check_expected_values)
6092                                     {
6093                                         do_check_expected_values = FALSE;
6094
6095                                         while (*p)
6096                                         {
6097                                             if (*p == 'x')
6098                                             {
6099                                                 p++;
6100
6101                                                 if (sscanf (p, "%x", &expected_command) == 1)
6102                                                 {
6103                                                     do_check_expected_values = TRUE;
6104                                                 }
6105                                                 break;
6106                                             }
6107                                             p++;
6108                                         }
6109
6110                                         if (do_check_expected_values)
6111                                         {
6112                                             // printf ("!%2d %04x %04x!\n", expected_protocol, expected_address, expected_command);
6113                                         }
6114                                     }
6115                                 }
6116                             }
6117                             else if (idx < 1024 - 2)
6118                             {
6119                                 buf[idx++] = ch;
6120                             }
6121                         }
6122                         putchar (ch);
6123                     }
6124                 }
6125                 putchar ('\n');
6126             }
6127
6128         }
6129
6130         last_ch = ch;
6131
6132         next_tick ();
6133     }
6134
6135     if (analyze)
6136     {
6137         print_spectrum ("START PULSES", start_pulses, TRUE);
6138         print_spectrum ("START PAUSES", start_pauses, FALSE);
6139         print_spectrum ("PULSES", pulses, TRUE);
6140         print_spectrum ("PAUSES", pauses, FALSE);
6141         puts ("-----------------------------------------------------------------------------");
6142     }
6143     return 0;
6144 }
6145
6146 #endif // ANALYZE