]> cloudbase.mooo.com Git - irmp.git/blob - irmp.c
Version 1.6.5: merged FDC1 and FDC2 to FDC, renamed DEBUG preprocessor constant to...
[irmp.git] / irmp.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp.c - infrared multi-protocol decoder, supports several remote control protocols
3 *
4 * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: irmp.c,v 1.50 2010/06/14 22:00:51 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * Typical manufacturers:
11 *
12 * SIRCS - Sony
13 * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers
14 * SAMSUNG - Samsung
15 * SAMSUNG32 - Samsung
16 * MATSUSHITA - Matsushita
17 * KASEIKYO - Panasonic, Denon & other Japanese manufacturers (members of "Japan's Association for Electric Home Application")
18 * RECS80 - Philips, Nokia, Thomson, Nordmende, Telefunken, Saba
19 * RC5 - Philips and other European manufacturers
20 * DENON - Denon
21 * RC6 - Philips and other European manufacturers
22 * APPLE - Apple
23 * NUBERT - Nubert Subwoofer System
24 * B&O - Bang & Olufsen
25 * PANASONIC - Panasonic (older, yet not implemented)
26 * GRUNDIG - Grundig
27 * NOKIA - Nokia
28 * SIEMENS - Siemens, e.g. Gigaset M740AV
29 *
30 *---------------------------------------------------------------------------------------------------------------------------------------------------
31 *
32 * SIRCS
33 * -----
34 *
35 * frame: 1 start bit + 12-20 data bits + no stop bit
36 * data: 7 command bits + 5 address bits + 0 to 8 additional bits
37 *
38 * start bit: data "0": data "1": stop bit:
39 * -----------------_________ ------_____ ------------______
40 * 2400us 600us 600us 600us 1200us 600 us no stop bit
41 *
42 *---------------------------------------------------------------------------------------------------------------------------------------------------
43 *
44 * NEC + extended NEC
45 * -------------------------
46 *
47 * frame: 1 start bit + 32 data bits + 1 stop bit
48 * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits
49 * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits
50 *
51 * start bit: data "0": data "1": stop bit:
52 * -----------------_________ ------______ ------________________ ------______....
53 * 9000us 4500us 560us 560us 560us 1690 us 560us
54 *
55 *
56 * Repetition frame:
57 *
58 * -----------------_________------______ .... ~100ms Pause, then repeat
59 * 9000us 2250us 560us
60 *
61 *---------------------------------------------------------------------------------------------------------------------------------------------------
62 *
63 * SAMSUNG
64 * -------
65 *
66 * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit
67 * data(1): 16 address bits
68 * data(2): 4 ID bits + 8 command bits + 8 inverted command bits
69 *
70 * start bit: data "0": data "1": sync bit: stop bit:
71 * ----------______________ ------______ ------________________ ------______________ ------______....
72 * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us
73 *
74 *---------------------------------------------------------------------------------------------------------------------------------------------------
75 *
76 * SAMSUNG32
77 * ----------
78 *
79 * frame: 1 start bit + 32 data bits + 1 stop bit
80 * data: 16 address bits + 16 command bits
81 *
82 * start bit: data "0": data "1": stop bit:
83 * ----------______________ ------______ ------________________ ------______....
84 * 4500us 4500us 550us 450us 550us 1450us 550us
85 *
86 *---------------------------------------------------------------------------------------------------------------------------------------------------
87 *
88 * MATSUSHITA
89 * ----------
90 *
91 * frame: 1 start bit + 24 data bits + 1 stop bit
92 * data: 6 custom bits + 6 command bits + 12 address bits
93 *
94 * start bit: data "0": data "1": stop bit:
95 * ----------_________ ------______ ------________________ ------______....
96 * 3488us 3488us 872us 872us 872us 2616us 872us
97 *
98 *---------------------------------------------------------------------------------------------------------------------------------------------------
99 *
100 * KASEIKYO
101 * --------
102 *
103 * frame: 1 start bit + 48 data bits + 1 stop bit
104 * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits
105 *
106 * start bit: data "0": data "1": stop bit:
107 * ----------______ ------______ ------________________ ------______....
108 * 3380us 1690us 423us 423us 423us 1269us 423us
109 *
110 *---------------------------------------------------------------------------------------------------------------------------------------------------
111 *
112 * RECS80
113 * ------
114 *
115 * frame: 2 start bits + 10 data bits + 1 stop bit
116 * data: 1 toggle bit + 3 address bits + 6 command bits
117 *
118 * start bit: data "0": data "1": stop bit:
119 * -----_____________________ -----____________ -----______________ ------_______....
120 * 158us 7432us 158us 4902us 158us 7432us 158us
121 *
122 *---------------------------------------------------------------------------------------------------------------------------------------------------
123 *
124 * RECS80EXT
125 * ---------
126 *
127 * frame: 2 start bits + 11 data bits + 1 stop bit
128 * data: 1 toggle bit + 4 address bits + 6 command bits
129 *
130 * start bit: data "0": data "1": stop bit:
131 * -----_____________________ -----____________ -----______________ ------_______....
132 * 158us 3637us 158us 4902us 158us 7432us 158us
133 *
134 *---------------------------------------------------------------------------------------------------------------------------------------------------
135 *
136 * RC5 + RC5X
137 * ----------
138 *
139 * RC5 frame: 2 start bits + 12 data bits + no stop bit
140 * RC5 data: 1 toggle bit + 5 address bits + 6 command bits
141 * RC5X frame: 1 start bit + 13 data bits + no stop bit
142 * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits
143 *
144 * start bit: data "0": data "1":
145 * ______----- ------______ ______------
146 * 889us 889us 889us 889us 889us 889us
147 *
148 *---------------------------------------------------------------------------------------------------------------------------------------------------
149 *
150 * DENON
151 * -----
152 *
153 * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit
154 * data: 5 address bits + 10 command bits
155 *
156 * data "0": data "1":
157 * ------________________ ------______________
158 * 275us 775us 275us 1900us
159 *
160 *---------------------------------------------------------------------------------------------------------------------------------------------------
161 *
162 * RC6
163 * ---
164 *
165 * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 µs pause
166 * RC6 data: 8 address bits + 8 command bits
167 *
168 * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1":
169 * ____________------- _______------- -------_______ _______------- -------_______
170 * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us
171 *
172 *---------------------------------------------------------------------------------------------------------------------------------------------------
173 *
174 * APPLE
175 * -----
176 *
177 * frame: 1 start bit + 32 data bits + 1 stop bit
178 * data: 16 address bits + 11100000 + 8 command bits
179 *
180 * start bit: data "0": data "1": stop bit:
181 * -----------------_________ ------______ ------________________ ------______....
182 * 9000us 4500us 560us 560us 560us 1690 us 560us
183 *
184 *---------------------------------------------------------------------------------------------------------------------------------------------------
185 *
186 * NUBERT (subwoofer system)
187 * -------------------------
188 *
189 * frame: 1 start bit + 10 data bits + 1 stop bit
190 * data: 0 address bits + 10 command bits ?
191 *
192 * start bit: data "0": data "1": stop bit:
193 * ----------_____ ------______ ------________________ ------______....
194 * 1340us 340us 500us 1300us 1340us 340us 500us
195 *
196 *---------------------------------------------------------------------------------------------------------------------------------------------------
197 *
198 * BANG_OLUFSEN
199 * ------------
200 *
201 * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit
202 * data: 0 address bits + 16 command bits
203 *
204 * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit:
205 * -----________ -----________ -----_____________ -----________
206 * 210us 3000us 210us 3000us 210us 15000us 210us 3000us
207 *
208 * data "0": data "1": data "repeat bit": trailer bit: stop bit:
209 * -----________ -----_____________ -----___________ -----_____________ -----____...
210 * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us
211 *
212 *---------------------------------------------------------------------------------------------------------------------------------------------------
213 *
214 * GRUNDIG
215 * -------
216 *
217 * packet: 1 start frame + 19,968ms pause + N info frames + 117,76ms pause + 1 stop frame
218 * frame: 1 pre bit + 1 start bit + 9 data bits + no stop bit
219 * pause between info frames: 117,76ms
220 *
221 * data of start frame: 9 x 1
222 * data of info frame: 9 command bits
223 * data of stop frame: 9 x 1
224 *
225 * pre bit: start bit data "0": data "1":
226 * ------____________ ------______ ______------ ------______
227 * 528us 2639us 528us 528us 528us 528us 528us 528us
228 *
229 *---------------------------------------------------------------------------------------------------------------------------------------------------
230 *
231 * NOKIA:
232 * ------
233 *
234 * Timing similar to Grundig, but 16 data bits:
235 * frame: 1 pre bit + 1 start bit + 8 command bits + 8 address bits + no stop bit
236 *
237 *---------------------------------------------------------------------------------------------------------------------------------------------------
238 *
239 * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar)
240 * -----------------------------------------------------------------------------------------
241 *
242 * frame: 1 start bit + 22 data bits + 1 stop bit
243 * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits
244 *
245 * European version: T = 456us
246 * USA & Canada version: T = 422us
247 *
248 * start bit: data "0": data "1": stop bit:
249 * 8T 8T 2T 2T 2T 6T 2T
250 * -------------____________ ------_____ ------_____________ ------_______....
251 * 3648us 3648us 912us 912us 912us 2736us 912us (Europe)
252 * 3376us 3376us 844us 844us 844us 2532us 844us (US)
253 *
254 *---------------------------------------------------------------------------------------------------------------------------------------------------
255 *
256 * This program is free software; you can redistribute it and/or modify
257 * it under the terms of the GNU General Public License as published by
258 * the Free Software Foundation; either version 2 of the License, or
259 * (at your option) any later version.
260 *---------------------------------------------------------------------------------------------------------------------------------------------------
261 */
262
263 #if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR
264 #define PIC_CCS_COMPILER
265 #endif
266
267 #ifdef unix // test on linux/unix
268 #include <stdio.h>
269 #include <unistd.h>
270 #include <stdlib.h>
271 #include <string.h>
272 #include <inttypes.h>
273
274 #define ANALYZE
275 #define PROGMEM
276 #define memcpy_P memcpy
277
278 #else // not unix:
279
280 #ifdef WIN32
281 #include <stdio.h>
282 #include <string.h>
283 typedef unsigned char uint8_t;
284 typedef unsigned short uint16_t;
285 #define ANALYZE
286 #define PROGMEM
287 #define memcpy_P memcpy
288
289 #else
290
291 #ifndef CODEVISION
292
293 #ifdef PIC_CCS_COMPILER
294
295 #include <string.h>
296 typedef unsigned int8 uint8_t;
297 typedef unsigned int16 uint16_t;
298 #define PROGMEM
299 #define memcpy_P memcpy
300
301 #else // AVR:
302
303 #include <inttypes.h>
304 #include <stdio.h>
305 #include <string.h>
306 #include <avr/io.h>
307 #include <util/delay.h>
308 #include <avr/pgmspace.h>
309
310 #endif // PIC_CCS_COMPILER
311 #endif // CODEVISION
312
313 #endif // windows
314 #endif // unix
315
316 #include "irmp.h"
317 #include "irmpconfig.h"
318
319 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1
320 #define IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL 1
321 #else
322 #define IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL 0
323 #endif
324
325 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1 || IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
326 #define IRMP_SUPPORT_MANCHESTER 1
327 #else
328 #define IRMP_SUPPORT_MANCHESTER 0
329 #endif
330
331 #define IRMP_TIMEOUT_TIME 16000.0e-6 // timeout after 16 ms darkness
332 #define IRMP_TIMEOUT_TIME_MS 16L // timeout after 16 ms darkness
333
334 #if (F_INTERRUPTS * IRMP_TIMEOUT_TIME_MS) / 1000 >= 255
335 #define IRMP_TIMEOUT_LEN (uint16_t)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)
336 typedef uint16_t PAUSE_LEN;
337 #else
338 #define IRMP_TIMEOUT_LEN (uint8_t)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)
339 typedef uint8_t PAUSE_LEN;
340 #endif
341
342 #define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec
343
344 #define MIN_TOLERANCE_00 1.0 // -0%
345 #define MAX_TOLERANCE_00 1.0 // +0%
346
347 #define MIN_TOLERANCE_05 0.95 // -5%
348 #define MAX_TOLERANCE_05 1.05 // +5%
349
350 #define MIN_TOLERANCE_10 0.9 // -10%
351 #define MAX_TOLERANCE_10 1.1 // +10%
352
353 #define MIN_TOLERANCE_15 0.85 // -15%
354 #define MAX_TOLERANCE_15 1.15 // +15%
355
356 #define MIN_TOLERANCE_20 0.8 // -20%
357 #define MAX_TOLERANCE_20 1.2 // +20%
358
359 #define MIN_TOLERANCE_30 0.7 // -30%
360 #define MAX_TOLERANCE_30 1.3 // +30%
361
362 #define MIN_TOLERANCE_40 0.6 // -40%
363 #define MAX_TOLERANCE_40 1.4 // +40%
364
365 #define MIN_TOLERANCE_50 0.5 // -50%
366 #define MAX_TOLERANCE_50 1.5 // +50%
367
368 #define MIN_TOLERANCE_60 0.4 // -60%
369 #define MAX_TOLERANCE_60 1.6 // +60%
370
371 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
372 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
373 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
374 #define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // only 5% to avoid conflict with RC6
375 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
376 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
377 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
378 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
379 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
380 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
381
382 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
383 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
384 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
385 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
386 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
387 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
388 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
389 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
390 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
391 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
392 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
393 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
394
395 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
396 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
397 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
398 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
399 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
400 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
401 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
402 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
403 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
404 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
405
406 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
407 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
408 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
409 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
410 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
411 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
412 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
413 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
414 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
415 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
416
417 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
418 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
419 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
420 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
421 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
422 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_60 + 0.5) + 1)
423 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
424 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
425 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
426 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
427
428 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
429 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
430 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
431 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
432 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
433 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
434 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
435 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
436 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
437 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
438
439 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
440 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
441 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
442 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
443
444 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
445 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
446 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
447 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
448 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
449 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
450
451 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
452 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
453 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
454 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
455 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
456 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
457 #define RC6_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
458 #define RC6_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
459
460 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
461 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
462 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
463 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
464 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
465 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
466 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
467 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
468 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
469 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
470
471 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
472 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
473 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
474 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
475 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
476 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
477 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
478 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
479 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
480 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
481 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
482 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
483
484 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
485 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
486 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
487 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
488 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
489 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
490 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
491 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
492 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
493 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
494 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
495 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // 10% is too big (uint8_t)
496 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
497 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
498 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
499 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
500 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
501 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
502 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
503 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
504 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
505 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
506 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
507 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
508 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
509 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
510
511 #define GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
512 #define GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
513 #define GRUNDIG_OR_NOKIA_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
514 #define GRUNDIG_OR_NOKIA_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
515 #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1)
516 #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
517
518 #define SIEMENS_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) - 1)
519 #define SIEMENS_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) + 1)
520 #define SIEMENS_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) - 1)
521 #define SIEMENS_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) + 1)
522
523 #define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
524 #define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
525 #define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
526 #define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
527 #define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
528 #define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
529 #define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
530 #define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
531 #define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
532 #define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
533
534 #define RCCAR_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
535 #define RCCAR_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
536 #define RCCAR_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
537 #define RCCAR_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
538 #define RCCAR_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
539 #define RCCAR_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
540 #define RCCAR_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
541 #define RCCAR_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
542 #define RCCAR_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
543 #define RCCAR_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
544
545 #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t!
546
547 #ifdef ANALYZE
548 #define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } }
549 #define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } }
550 #define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } }
551 #define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } }
552 static int silent;
553 static int time_counter;
554 static int verbose;
555 #else
556 #define ANALYZE_PUTCHAR(a)
557 #define ANALYZE_ONLY_NORMAL_PUTCHAR(a)
558 #define ANALYZE_PRINTF(...)
559 #define ANALYZE_NEWLINE()
560 #endif
561
562 #if IRMP_LOGGING == 1
563 #define BAUD 9600L
564 #include <util/setbaud.h>
565
566 #ifdef UBRR0H
567
568 #define UART0_UBRRH UBRR0H
569 #define UART0_UBRRL UBRR0L
570 #define UART0_UCSRA UCSR0A
571 #define UART0_UCSRB UCSR0B
572 #define UART0_UCSRC UCSR0C
573 #define UART0_UDRE_BIT_VALUE (1<<UDRE0)
574 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ01)
575 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ00)
576 #ifdef URSEL0
577 #define UART0_URSEL_BIT_VALUE (1<<URSEL0)
578 #else
579 #define UART0_URSEL_BIT_VALUE (0)
580 #endif
581 #define UART0_TXEN_BIT_VALUE (1<<TXEN0)
582 #define UART0_UDR UDR0
583
584 #else
585
586 #define UART0_UBRRH UBRRH
587 #define UART0_UBRRL UBRRL
588 #define UART0_UCSRA UCSRA
589 #define UART0_UCSRB UCSRB
590 #define UART0_UCSRC UCSRC
591 #define UART0_UDRE_BIT_VALUE (1<<UDRE)
592 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ1)
593 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ0)
594 #ifdef URSEL
595 #define UART0_URSEL_BIT_VALUE (1<<URSEL)
596 #else
597 #define UART0_URSEL_BIT_VALUE (0)
598 #endif
599 #define UART0_TXEN_BIT_VALUE (1<<TXEN)
600 #define UART0_UDR UDR
601
602 #endif
603
604 /*---------------------------------------------------------------------------------------------------------------------------------------------------
605 * Initialize UART
606 * @details Initializes UART
607 *---------------------------------------------------------------------------------------------------------------------------------------------------
608 */
609 void
610 irmp_uart_init (void)
611 {
612 UART0_UBRRH = UBRRH_VALUE; // set baud rate
613 UART0_UBRRL = UBRRL_VALUE;
614
615 #if USE_2X
616 UART0_UCSRA = (1<<U2X);
617 #else
618 UART0_UCSRA = 0;
619 #endif
620
621 UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;
622 UART0_UCSRB |= UART0_TXEN_BIT_VALUE; // enable UART TX
623 }
624
625 /*---------------------------------------------------------------------------------------------------------------------------------------------------
626 * Send character
627 * @details Sends character
628 * @param ch character to be transmitted
629 *---------------------------------------------------------------------------------------------------------------------------------------------------
630 */
631 void
632 irmp_uart_putc (unsigned char ch)
633 {
634 while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))
635 {
636 ;
637 }
638
639 UART0_UDR = ch;
640 }
641
642 /*---------------------------------------------------------------------------------------------------------------------------------------------------
643 * Log IR signal
644 *---------------------------------------------------------------------------------------------------------------------------------------------------
645 */
646
647 #define STARTCYCLES 2 // min count of zeros before start of logging
648 #define ENDBITS 1000 // number of sequenced highbits to detect end
649 #define DATALEN 700 // log buffer size
650
651 static void
652 irmp_log (uint8_t val)
653 {
654 static uint8_t buf[DATALEN]; // logging buffer
655 static uint16_t buf_idx; // number of written bits
656 static uint8_t startcycles; // current number of start-zeros
657 static uint16_t cnt; // counts sequenced highbits - to detect end
658
659 if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging
660 {
661 startcycles++;
662 }
663 else
664 {
665 startcycles = 0;
666
667 if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging
668 {
669 if (buf_idx < DATALEN * 8) // index in range?
670 { // yes
671 if (val)
672 {
673 buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit
674 }
675 else
676 {
677 buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit
678 }
679
680 buf_idx++;
681 }
682
683 if (val)
684 { // if high received then look at log-stop condition
685 cnt++;
686
687 if (cnt > ENDBITS)
688 { // if stop condition is true, output on uart
689 uint16_t i;
690
691 for (i = 0; i < STARTCYCLES; i++)
692 {
693 irmp_uart_putc ('0'); // the ignored starting zeros
694 }
695
696 for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars
697 {
698 uint8_t d = buf[i];
699 uint8_t j;
700
701 for (j = 0; j < 8; j++)
702 {
703 irmp_uart_putc ((d & 1) + '0');
704 d >>= 1;
705 }
706 }
707
708 irmp_uart_putc ('\n');
709 buf_idx = 0;
710 }
711 }
712 else
713 {
714 cnt = 0;
715 }
716 }
717 }
718 }
719
720 #else
721 #define irmp_log(val)
722 #endif
723
724 typedef struct
725 {
726 uint8_t protocol; // ir protocol
727 uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1
728 uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1
729 uint8_t pause_1_len_min; // minimum length of pause with bit value 1
730 uint8_t pause_1_len_max; // maximum length of pause with bit value 1
731 uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0
732 uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0
733 uint8_t pause_0_len_min; // minimum length of pause with bit value 0
734 uint8_t pause_0_len_max; // maximum length of pause with bit value 0
735 uint8_t address_offset; // address offset
736 uint8_t address_end; // end of address
737 uint8_t command_offset; // command offset
738 uint8_t command_end; // end of command
739 uint8_t complete_len; // complete length of frame
740 uint8_t stop_bit; // flag: frame has stop bit
741 uint8_t lsb_first; // flag: LSB first
742 uint8_t flags; // some flags
743 } IRMP_PARAMETER;
744
745 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
746
747 static PROGMEM IRMP_PARAMETER sircs_param =
748 {
749 IRMP_SIRCS_PROTOCOL, // protocol: ir protocol
750 SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
751 SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
752 SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
753 SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
754 SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
755 SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
756 SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
757 SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
758 SIRCS_ADDRESS_OFFSET, // address_offset: address offset
759 SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address
760 SIRCS_COMMAND_OFFSET, // command_offset: command offset
761 SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command
762 SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
763 SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit
764 SIRCS_LSB, // lsb_first: flag: LSB first
765 SIRCS_FLAGS // flags: some flags
766 };
767
768 #endif
769
770 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
771
772 static PROGMEM IRMP_PARAMETER nec_param =
773 {
774 IRMP_NEC_PROTOCOL, // protocol: ir protocol
775 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
776 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
777 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
778 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
779 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
780 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
781 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
782 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
783 NEC_ADDRESS_OFFSET, // address_offset: address offset
784 NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address
785 NEC_COMMAND_OFFSET, // command_offset: command offset
786 NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command
787 NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
788 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
789 NEC_LSB, // lsb_first: flag: LSB first
790 NEC_FLAGS // flags: some flags
791 };
792
793 static PROGMEM IRMP_PARAMETER nec_rep_param =
794 {
795 IRMP_NEC_PROTOCOL, // protocol: ir protocol
796 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
797 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
798 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
799 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
800 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
801 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
802 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
803 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
804 0, // address_offset: address offset
805 0, // address_end: end of address
806 0, // command_offset: command offset
807 0, // command_end: end of command
808 0, // complete_len: complete length of frame
809 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
810 NEC_LSB, // lsb_first: flag: LSB first
811 NEC_FLAGS // flags: some flags
812 };
813
814 #endif
815
816 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
817
818 static PROGMEM IRMP_PARAMETER samsung_param =
819 {
820 IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol
821 SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
822 SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
823 SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
824 SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
825 SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
826 SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
827 SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
828 SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
829 SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset
830 SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address
831 SAMSUNG_COMMAND_OFFSET, // command_offset: command offset
832 SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command
833 SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame
834 SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit
835 SAMSUNG_LSB, // lsb_first: flag: LSB first
836 SAMSUNG_FLAGS // flags: some flags
837 };
838
839 #endif
840
841 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
842
843 static PROGMEM IRMP_PARAMETER matsushita_param =
844 {
845 IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol
846 MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
847 MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
848 MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
849 MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
850 MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
851 MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
852 MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
853 MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
854 MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset
855 MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address
856 MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset
857 MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command
858 MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame
859 MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit
860 MATSUSHITA_LSB, // lsb_first: flag: LSB first
861 MATSUSHITA_FLAGS // flags: some flags
862 };
863
864 #endif
865
866 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
867
868 static PROGMEM IRMP_PARAMETER kaseikyo_param =
869 {
870 IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol
871 KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
872 KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
873 KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
874 KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
875 KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
876 KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
877 KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
878 KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
879 KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset
880 KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address
881 KASEIKYO_COMMAND_OFFSET, // command_offset: command offset
882 KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command
883 KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
884 KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit
885 KASEIKYO_LSB, // lsb_first: flag: LSB first
886 KASEIKYO_FLAGS // flags: some flags
887 };
888
889 #endif
890
891 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
892
893 static PROGMEM IRMP_PARAMETER recs80_param =
894 {
895 IRMP_RECS80_PROTOCOL, // protocol: ir protocol
896 RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
897 RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
898 RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
899 RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
900 RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
901 RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
902 RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
903 RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
904 RECS80_ADDRESS_OFFSET, // address_offset: address offset
905 RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address
906 RECS80_COMMAND_OFFSET, // command_offset: command offset
907 RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command
908 RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame
909 RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit
910 RECS80_LSB, // lsb_first: flag: LSB first
911 RECS80_FLAGS // flags: some flags
912 };
913
914 #endif
915
916 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
917
918 static PROGMEM IRMP_PARAMETER rc5_param =
919 {
920 IRMP_RC5_PROTOCOL, // protocol: ir protocol
921 RC5_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
922 RC5_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
923 RC5_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
924 RC5_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
925 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
926 1, // pulse_0_len_max: maximum length of pulse with bit value 0
927 1, // pause_0_len_min: minimum length of pause with bit value 0
928 1, // pause_0_len_max: maximum length of pause with bit value 0
929 RC5_ADDRESS_OFFSET, // address_offset: address offset
930 RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address
931 RC5_COMMAND_OFFSET, // command_offset: command offset
932 RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command
933 RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame
934 RC5_STOP_BIT, // stop_bit: flag: frame has stop bit
935 RC5_LSB, // lsb_first: flag: LSB first
936 RC5_FLAGS // flags: some flags
937 };
938
939 #endif
940
941 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
942
943 static PROGMEM IRMP_PARAMETER denon_param =
944 {
945 IRMP_DENON_PROTOCOL, // protocol: ir protocol
946 DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
947 DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
948 DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
949 DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
950 DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
951 DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
952 DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
953 DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
954 DENON_ADDRESS_OFFSET, // address_offset: address offset
955 DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address
956 DENON_COMMAND_OFFSET, // command_offset: command offset
957 DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command
958 DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
959 DENON_STOP_BIT, // stop_bit: flag: frame has stop bit
960 DENON_LSB, // lsb_first: flag: LSB first
961 DENON_FLAGS // flags: some flags
962 };
963
964 #endif
965
966 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
967
968 static PROGMEM IRMP_PARAMETER rc6_param =
969 {
970 IRMP_RC6_PROTOCOL, // protocol: ir protocol
971 RC6_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
972 RC6_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
973 RC6_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
974 RC6_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
975 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
976 1, // pulse_0_len_max: maximum length of pulse with bit value 0
977 1, // pause_0_len_min: minimum length of pause with bit value 0
978 1, // pause_0_len_max: maximum length of pause with bit value 0
979 RC6_ADDRESS_OFFSET, // address_offset: address offset
980 RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address
981 RC6_COMMAND_OFFSET, // command_offset: command offset
982 RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command
983 RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame
984 RC6_STOP_BIT, // stop_bit: flag: frame has stop bit
985 RC6_LSB, // lsb_first: flag: LSB first
986 RC6_FLAGS // flags: some flags
987 };
988
989 #endif
990
991 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
992
993 static PROGMEM IRMP_PARAMETER recs80ext_param =
994 {
995 IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol
996 RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
997 RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
998 RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
999 RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1000 RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1001 RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1002 RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1003 RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1004 RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset
1005 RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address
1006 RECS80EXT_COMMAND_OFFSET, // command_offset: command offset
1007 RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command
1008 RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1009 RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit
1010 RECS80EXT_LSB, // lsb_first: flag: LSB first
1011 RECS80EXT_FLAGS // flags: some flags
1012 };
1013
1014 #endif
1015
1016 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1017
1018 static PROGMEM IRMP_PARAMETER nubert_param =
1019 {
1020 IRMP_NUBERT_PROTOCOL, // protocol: ir protocol
1021 NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1022 NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1023 NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1024 NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1025 NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1026 NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1027 NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1028 NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1029 NUBERT_ADDRESS_OFFSET, // address_offset: address offset
1030 NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address
1031 NUBERT_COMMAND_OFFSET, // command_offset: command offset
1032 NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command
1033 NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1034 NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit
1035 NUBERT_LSB, // lsb_first: flag: LSB first
1036 NUBERT_FLAGS // flags: some flags
1037 };
1038
1039 #endif
1040
1041 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1042
1043 static PROGMEM IRMP_PARAMETER bang_olufsen_param =
1044 {
1045 IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol
1046 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1047 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1048 BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1049 BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1050 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1051 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1052 BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1053 BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1054 BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset
1055 BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address
1056 BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset
1057 BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command
1058 BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1059 BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit
1060 BANG_OLUFSEN_LSB, // lsb_first: flag: LSB first
1061 BANG_OLUFSEN_FLAGS // flags: some flags
1062 };
1063
1064 #endif
1065
1066 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1067
1068 static PROGMEM IRMP_PARAMETER grundig_param =
1069 {
1070 IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol
1071 GRUNDIG_OR_NOKIA_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1072 GRUNDIG_OR_NOKIA_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1073 GRUNDIG_OR_NOKIA_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1074 GRUNDIG_OR_NOKIA_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1075 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
1076 1, // pulse_0_len_max: maximum length of pulse with bit value 0
1077 1, // pause_0_len_min: minimum length of pause with bit value 0
1078 1, // pause_0_len_max: maximum length of pause with bit value 0
1079 GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset
1080 GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address
1081 GRUNDIG_COMMAND_OFFSET, // command_offset: command offset
1082 GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!)
1083 NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG!
1084 GRUNDIG_OR_NOKIA_STOP_BIT, // stop_bit: flag: frame has stop bit
1085 GRUNDIG_OR_NOKIA_LSB, // lsb_first: flag: LSB first
1086 GRUNDIG_OR_NOKIA_FLAGS // flags: some flags
1087 };
1088
1089 #endif
1090
1091 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1092
1093 static PROGMEM IRMP_PARAMETER siemens_param =
1094 {
1095 IRMP_SIEMENS_PROTOCOL, // protocol: ir protocol
1096 SIEMENS_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1097 SIEMENS_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1098 SIEMENS_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1099 SIEMENS_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1100 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
1101 1, // pulse_0_len_max: maximum length of pulse with bit value 0
1102 1, // pause_0_len_min: minimum length of pause with bit value 0
1103 1, // pause_0_len_max: maximum length of pause with bit value 0
1104 SIEMENS_ADDRESS_OFFSET, // address_offset: address offset
1105 SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN, // address_end: end of address
1106 SIEMENS_COMMAND_OFFSET, // command_offset: command offset
1107 SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN, // command_end: end of command
1108 SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1109 SIEMENS_STOP_BIT, // stop_bit: flag: frame has stop bit
1110 SIEMENS_LSB, // lsb_first: flag: LSB first
1111 SIEMENS_FLAGS // flags: some flags
1112 };
1113
1114 #endif
1115
1116 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1117
1118 static PROGMEM IRMP_PARAMETER fdc_param =
1119 {
1120 IRMP_FDC_PROTOCOL, // protocol: ir protocol
1121 FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1122 FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1123 FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1124 FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1125 FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1126 FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1127 FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1128 FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1129 FDC_ADDRESS_OFFSET, // address_offset: address offset
1130 FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address
1131 FDC_COMMAND_OFFSET, // command_offset: command offset
1132 FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command
1133 FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1134 FDC_STOP_BIT, // stop_bit: flag: frame has stop bit
1135 FDC_LSB, // lsb_first: flag: LSB first
1136 FDC_FLAGS // flags: some flags
1137 };
1138
1139 #endif
1140
1141 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1142
1143 static PROGMEM IRMP_PARAMETER rccar_param =
1144 {
1145 IRMP_RCCAR_PROTOCOL, // protocol: ir protocol
1146 RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1147 RCCAR_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1148 RCCAR_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1149 RCCAR_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1150 RCCAR_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1151 RCCAR_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1152 RCCAR_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1153 RCCAR_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1154 RCCAR_ADDRESS_OFFSET, // address_offset: address offset
1155 RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN, // address_end: end of address
1156 RCCAR_COMMAND_OFFSET, // command_offset: command offset
1157 RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN, // command_end: end of command
1158 RCCAR_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1159 RCCAR_STOP_BIT, // stop_bit: flag: frame has stop bit
1160 RCCAR_LSB, // lsb_first: flag: LSB first
1161 RCCAR_FLAGS // flags: some flags
1162 };
1163
1164 #endif
1165
1166 static uint8_t irmp_bit; // current bit position
1167 static IRMP_PARAMETER irmp_param;
1168
1169 static volatile uint8_t irmp_ir_detected;
1170 static volatile uint8_t irmp_protocol;
1171 static volatile uint16_t irmp_address;
1172 static volatile uint16_t irmp_command;
1173 static volatile uint16_t irmp_id; // only used for SAMSUNG protocol
1174 static volatile uint8_t irmp_flags;
1175
1176 #ifdef ANALYZE
1177 static uint8_t IRMP_PIN;
1178 #endif
1179
1180 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1181 * Initialize IRMP decoder
1182 * @details Configures IRMP input pin
1183 *---------------------------------------------------------------------------------------------------------------------------------------------------
1184 */
1185 #ifndef ANALYZE
1186 void
1187 irmp_init (void)
1188 {
1189 #ifndef PIC_CCS_COMPILER
1190 IRMP_PORT &= ~(1<<IRMP_BIT); // deactivate pullup
1191 IRMP_DDR &= ~(1<<IRMP_BIT); // set pin to input
1192 #endif // PIC_CCS_COMPILER
1193
1194 #if IRMP_LOGGING == 1
1195 irmp_uart_init ();
1196 #endif
1197 }
1198 #endif
1199 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1200 * Get IRMP data
1201 * @details gets decoded IRMP data
1202 * @param pointer in order to store IRMP data
1203 * @return TRUE: successful, FALSE: failed
1204 *---------------------------------------------------------------------------------------------------------------------------------------------------
1205 */
1206 uint8_t
1207 irmp_get_data (IRMP_DATA * irmp_data_p)
1208 {
1209 uint8_t rtc = FALSE;
1210
1211 if (irmp_ir_detected)
1212 {
1213 switch (irmp_protocol)
1214 {
1215 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1216 case IRMP_SAMSUNG_PROTOCOL:
1217 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1218 {
1219 irmp_command &= 0xff;
1220 irmp_command |= irmp_id << 8;
1221 rtc = TRUE;
1222 }
1223 break;
1224 #endif
1225 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1226 case IRMP_NEC_PROTOCOL:
1227 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1228 {
1229 irmp_command &= 0xff;
1230 rtc = TRUE;
1231 }
1232 else if ((irmp_command & 0xFF00) == 0xD100)
1233 {
1234 ANALYZE_PRINTF ("Switching to APPLE protocol\n");
1235 irmp_protocol = IRMP_APPLE_PROTOCOL;
1236 irmp_command &= 0xff;
1237 rtc = TRUE;
1238 }
1239 break;
1240 #endif
1241 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1242 case IRMP_RCCAR_PROTOCOL:
1243 // frame in irmp_data:
1244 // Bit 12 11 10 9 8 7 6 5 4 3 2 1 0
1245 // V D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0 // 10 9 8 7 6 5 4 3 2 1 0
1246 irmp_address = (irmp_command & 0x000C) >> 2; // addr: 0 0 0 0 0 0 0 0 0 A1 A0
1247 irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit: V 0 0 0 0 0 0 0 0 0 0
1248 ((irmp_command & 0x0003) << 8) | // C-Bits: 0 C1 C0 0 0 0 0 0 0 0 0
1249 ((irmp_command & 0x0FF0) >> 4); // D-Bits: D7 D6 D5 D4 D3 D2 D1 D0
1250 rtc = TRUE; // Summe: V C1 C0 D7 D6 D5 D4 D3 D2 D1 D0
1251 break;
1252 #endif
1253 default:
1254 rtc = TRUE;
1255 }
1256
1257 if (rtc)
1258 {
1259 irmp_data_p->protocol = irmp_protocol;
1260 irmp_data_p->address = irmp_address;
1261 irmp_data_p->command = irmp_command;
1262 irmp_data_p->flags = irmp_flags;
1263 irmp_command = 0;
1264 irmp_address = 0;
1265 irmp_flags = 0;
1266 }
1267
1268 irmp_ir_detected = FALSE;
1269 }
1270
1271 return rtc;
1272 }
1273
1274 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1275 static uint16_t irmp_tmp_address; // ir address
1276 static uint16_t irmp_tmp_command; // ir command
1277 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1278 static uint16_t irmp_tmp_id; // ir id (only SAMSUNG)
1279 #endif
1280
1281 static uint8_t irmp_bit; // current bit position
1282
1283 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1284 * store bit
1285 * @details store bit in temp address or temp command
1286 * @param value to store: 0 or 1
1287 *---------------------------------------------------------------------------------------------------------------------------------------------------
1288 */
1289 static void
1290 irmp_store_bit (uint8_t value)
1291 {
1292 if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end)
1293 {
1294 if (irmp_param.lsb_first)
1295 {
1296 irmp_tmp_address |= (((uint16_t) (value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast
1297 }
1298 else
1299 {
1300 irmp_tmp_address <<= 1;
1301 irmp_tmp_address |= value;
1302 }
1303 }
1304 else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end)
1305 {
1306 if (irmp_param.lsb_first)
1307 {
1308 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast
1309 }
1310 else
1311 {
1312 irmp_tmp_command <<= 1;
1313 irmp_tmp_command |= value;
1314 }
1315 }
1316 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1317 else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
1318 {
1319 irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first
1320 }
1321 #endif
1322 irmp_bit++;
1323 }
1324
1325 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1326 * ISR routine
1327 * @details ISR routine, called 10000 times per second
1328 *---------------------------------------------------------------------------------------------------------------------------------------------------
1329 */
1330 uint8_t
1331 irmp_ISR (void)
1332 {
1333 static uint8_t irmp_start_bit_detected; // flag: start bit detected
1334 static uint8_t wait_for_space; // flag: wait for data bit space
1335 static uint8_t wait_for_start_space; // flag: wait for start bit space
1336 static uint8_t irmp_pulse_time; // count bit time for pulse
1337 static PAUSE_LEN irmp_pause_time; // count bit time for pause
1338 static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition
1339 static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition
1340 static uint16_t repetition_counter; // SIRCS repeats frame 2-5 times with 45 ms pause
1341 static uint8_t repetition_frame_number;
1342 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1343 static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition
1344 #endif
1345 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1346 static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit
1347 #endif
1348 #if IRMP_SUPPORT_MANCHESTER == 1
1349 static PAUSE_LEN last_pause; // last pause value
1350 #endif
1351 #if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1352 static uint8_t last_value; // last bit value
1353 #endif
1354 uint8_t irmp_input; // input value
1355
1356 #ifdef ANALYZE
1357 time_counter++;
1358 #endif
1359
1360 irmp_input = input(IRMP_PIN);
1361
1362 irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined
1363
1364 if (! irmp_ir_detected) // ir code already detected?
1365 { // no...
1366 if (! irmp_start_bit_detected) // start bit detected?
1367 { // no...
1368 if (! irmp_input) // receiving burst?
1369 { // yes...
1370 #ifdef ANALYZE
1371 if (! irmp_pulse_time)
1372 {
1373 ANALYZE_PRINTF("%8d [starting pulse]\n", time_counter);
1374 }
1375 #endif
1376 irmp_pulse_time++; // increment counter
1377 }
1378 else
1379 { // no...
1380 if (irmp_pulse_time) // it's dark....
1381 { // set flags for counting the time of darkness...
1382 irmp_start_bit_detected = 1;
1383 wait_for_start_space = 1;
1384 wait_for_space = 0;
1385 irmp_tmp_command = 0;
1386 irmp_tmp_address = 0;
1387 irmp_bit = 0xff;
1388 irmp_pause_time = 1; // 1st pause: set to 1, not to 0!
1389 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1390 rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1391 #endif
1392 }
1393 else
1394 {
1395 repetition_counter++;
1396 }
1397 }
1398 }
1399 else
1400 {
1401 if (wait_for_start_space) // we have received start bit...
1402 { // ...and are counting the time of darkness
1403 if (irmp_input) // still dark?
1404 { // yes
1405 irmp_pause_time++; // increment counter
1406
1407 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1408 { // yes...
1409 ANALYZE_PRINTF ("error 1: pause after start bit pulse %d too long: %d\n", irmp_pulse_time, irmp_pause_time);
1410 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1411 irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit
1412 irmp_pulse_time = 0;
1413 irmp_pause_time = 0;
1414 }
1415 }
1416 else
1417 { // receiving first data pulse!
1418 IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0;
1419
1420 ANALYZE_PRINTF ("start-bit: pulse = %d, pause = %d\n", irmp_pulse_time, irmp_pause_time);
1421
1422 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1423 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
1424 irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
1425 { // it's SIRCS
1426 ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1427 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
1428 SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
1429 irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param;
1430 }
1431 else
1432 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1433
1434 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1435 if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1436 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
1437 {
1438 ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1439 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1440 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
1441 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1442 }
1443 else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1444 irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1445 { // it's NEC
1446 ANALYZE_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1447 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1448 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1449
1450 irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
1451 }
1452 else
1453 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1454
1455 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1456 if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
1457 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
1458 { // it's SAMSUNG
1459 ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1460 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
1461 SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
1462 irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
1463 }
1464 else
1465 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1466
1467 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1468 if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
1469 irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
1470 { // it's MATSUSHITA
1471 ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1472 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
1473 MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
1474 irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
1475 }
1476 else
1477 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1478
1479 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1480 if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
1481 irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
1482 { // it's KASEIKYO
1483 ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1484 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
1485 KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
1486 irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
1487 }
1488 else
1489 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1490
1491 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1492 if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
1493 irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
1494 { // it's RECS80
1495 ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1496 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
1497 RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
1498 irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
1499 }
1500 else
1501 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1502
1503 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1504 if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
1505 (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) &&
1506 ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
1507 (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)))
1508 { // it's RC5
1509 ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1510 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1511 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1512 irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
1513 last_pause = irmp_pause_time;
1514
1515 if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) ||
1516 (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))
1517 {
1518 last_value = 0;
1519 rc5_cmd_bit6 = 1<<6;
1520 }
1521 else
1522 {
1523 last_value = 1;
1524 }
1525 }
1526 else
1527 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1528
1529 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1530 if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
1531 ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
1532 (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
1533 { // it's DENON
1534 ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
1535 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
1536 DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
1537 DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
1538 irmp_param_p = (IRMP_PARAMETER *) &denon_param;
1539 }
1540 else
1541 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1542
1543 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1544 if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
1545 irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
1546 { // it's RC6
1547 ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1548 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
1549 RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
1550 irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
1551 last_pause = 0;
1552 last_value = 0;
1553 }
1554 else
1555 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1556
1557 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1558 if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
1559 irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
1560 { // it's RECS80EXT
1561 ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1562 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
1563 RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
1564 irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
1565 }
1566 else
1567 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1568
1569 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1570 if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
1571 irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
1572 { // it's NUBERT
1573 ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1574 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
1575 NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
1576 irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
1577 }
1578 else
1579 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1580
1581 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1582 if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
1583 irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
1584 { // it's BANG_OLUFSEN
1585 ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n");
1586 ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1587 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
1588 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
1589 ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1590 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
1591 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
1592 ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1593 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
1594 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
1595 ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1596 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
1597 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
1598 irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
1599 last_value = 0;
1600 }
1601 else
1602 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1603
1604 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1605 if (irmp_pulse_time >= GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX &&
1606 irmp_pause_time >= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX)
1607 { // it's GRUNDIG
1608 ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1609 GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN, GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX,
1610 GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN, GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX);
1611 irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
1612 last_pause = irmp_pause_time;
1613 last_value = 1;
1614 }
1615 else
1616 #endif // IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1617
1618 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1619 if (((irmp_pulse_time >= SIEMENS_START_BIT_LEN_MIN && irmp_pulse_time <= SIEMENS_START_BIT_LEN_MAX) ||
1620 (irmp_pulse_time >= 2 * SIEMENS_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_START_BIT_LEN_MAX)) &&
1621 ((irmp_pause_time >= SIEMENS_START_BIT_LEN_MIN && irmp_pause_time <= SIEMENS_START_BIT_LEN_MAX) ||
1622 (irmp_pause_time >= 2 * SIEMENS_START_BIT_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_START_BIT_LEN_MAX)))
1623 { // it's SIEMENS
1624 ANALYZE_PRINTF ("protocol = SIEMENS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1625 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX,
1626 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX);
1627 irmp_param_p = (IRMP_PARAMETER *) &siemens_param;
1628 last_pause = irmp_pause_time;
1629 last_value = 1;
1630 }
1631 else
1632 #endif // IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1633 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1634 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
1635 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
1636 {
1637 ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1638 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
1639 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
1640 irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
1641 }
1642 else
1643 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
1644 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1645 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
1646 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
1647 {
1648 ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1649 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
1650 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
1651 irmp_param_p = (IRMP_PARAMETER *) &rccar_param;
1652 }
1653 else
1654 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1655 {
1656 ANALYZE_PRINTF ("protocol = UNKNOWN\n");
1657 irmp_start_bit_detected = 0; // wait for another start bit...
1658 }
1659
1660 if (irmp_start_bit_detected)
1661 {
1662 memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
1663
1664 #ifdef ANALYZE
1665 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
1666 {
1667 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
1668 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
1669 }
1670 else
1671 {
1672 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max,
1673 2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max);
1674 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max,
1675 2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max);
1676 }
1677
1678 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1679 if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
1680 {
1681 ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
1682 }
1683 #endif
1684
1685 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
1686 {
1687 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
1688 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
1689 }
1690
1691 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1692 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
1693 {
1694 ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
1695 ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
1696 }
1697 #endif
1698
1699 ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
1700 ANALYZE_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset);
1701 ANALYZE_PRINTF ("complete_len: %3d\n", irmp_param.complete_len);
1702 ANALYZE_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit);
1703 #endif // ANALYZE
1704 }
1705
1706 irmp_bit = 0;
1707
1708 #if IRMP_SUPPORT_MANCHESTER == 1
1709 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) && irmp_param.protocol != IRMP_RC6_PROTOCOL) // manchester, but not rc6
1710 {
1711 if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max)
1712 {
1713 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1714 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
1715 ANALYZE_NEWLINE ();
1716 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1);
1717 }
1718 else if (! last_value)
1719 {
1720 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1721
1722 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
1723 ANALYZE_NEWLINE ();
1724 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0);
1725 }
1726 }
1727 else
1728 #endif // IRMP_SUPPORT_MANCHESTER == 1
1729
1730 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1731 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
1732 {
1733 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1734
1735 if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
1736 { // pause timings correct for "1"?
1737 ANALYZE_PUTCHAR ('1'); // yes, store 1
1738 ANALYZE_NEWLINE ();
1739 irmp_store_bit (1);
1740 }
1741 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
1742 { // pause timings correct for "0"?
1743 ANALYZE_PUTCHAR ('0'); // yes, store 0
1744 ANALYZE_NEWLINE ();
1745 irmp_store_bit (0);
1746 }
1747 }
1748 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1749
1750 irmp_pulse_time = 1; // set counter to 1, not 0
1751 irmp_pause_time = 0;
1752 wait_for_start_space = 0;
1753 }
1754 }
1755 else if (wait_for_space) // the data section....
1756 { // counting the time of darkness....
1757 uint8_t got_light = FALSE;
1758
1759 if (irmp_input) // still dark?
1760 { // yes...
1761 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
1762 {
1763 if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max)
1764 {
1765 #ifdef ANALYZE
1766 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
1767 {
1768 ANALYZE_PRINTF ("stop bit detected\n");
1769 }
1770 #endif
1771 irmp_param.stop_bit = 0;
1772 }
1773 else
1774 {
1775 ANALYZE_PRINTF ("stop bit timing wrong\n");
1776
1777 irmp_start_bit_detected = 0; // wait for another start bit...
1778 irmp_pulse_time = 0;
1779 irmp_pause_time = 0;
1780 }
1781 }
1782 else
1783 {
1784 irmp_pause_time++; // increment counter
1785
1786 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1787 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits:
1788 irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12
1789 irmp_bit >= 12 - 1) // pause too long?
1790 { // yes, break and close this frame
1791 irmp_param.complete_len = irmp_bit + 1; // set new complete length
1792 got_light = TRUE; // this is a lie, but helps (generates stop bit)
1793 irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length
1794 irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length
1795 }
1796 else
1797 #endif
1798 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1799 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)
1800 {
1801 if (irmp_pause_time > 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2)
1802 { // special manchester decoder
1803 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len
1804 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1805 irmp_param.stop_bit = TRUE; // set flag
1806 }
1807 else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
1808 {
1809 ANALYZE_PRINTF ("Switching to NOKIA protocol\n");
1810 irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol
1811 irmp_param.address_offset = NOKIA_ADDRESS_OFFSET;
1812 irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
1813 irmp_param.command_offset = NOKIA_COMMAND_OFFSET;
1814 irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
1815
1816 if (irmp_tmp_command & 0x300)
1817 {
1818 irmp_tmp_address = (irmp_tmp_command >> 8);
1819 irmp_tmp_command &= 0xFF;
1820 }
1821 }
1822 }
1823 else
1824 #endif
1825 #if IRMP_SUPPORT_MANCHESTER == 1
1826 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
1827 irmp_pause_time > 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
1828 { // special manchester decoder
1829 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1830 irmp_param.stop_bit = TRUE; // set flag
1831 }
1832 else
1833 #endif // IRMP_SUPPORT_MANCHESTER == 1
1834 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1835 { // yes...
1836 if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
1837 {
1838 irmp_bit++;
1839 }
1840 else
1841 {
1842 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
1843 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1844
1845 irmp_start_bit_detected = 0; // wait for another start bit...
1846 irmp_pulse_time = 0;
1847 irmp_pause_time = 0;
1848 }
1849 }
1850 }
1851 }
1852 else
1853 { // got light now!
1854 got_light = TRUE;
1855 }
1856
1857 if (got_light)
1858 {
1859 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1860
1861 #if IRMP_SUPPORT_MANCHESTER == 1
1862 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // manchester
1863 {
1864 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1865 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit >= 3 && irmp_bit <= 5) // special bits of rc6
1866 {
1867 if (irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MAX && irmp_pause_time > RC6_TOGGLE_BIT_LEN_MAX)
1868 {
1869 ANALYZE_PUTCHAR ('1');
1870 irmp_store_bit (1);
1871 }
1872
1873 ANALYZE_PUTCHAR ('0');
1874 irmp_store_bit (0);
1875 last_value = 0;
1876 ANALYZE_NEWLINE ();
1877 }
1878 else
1879 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1880 if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max)
1881 {
1882 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
1883 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1 );
1884 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
1885 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0 );
1886 ANALYZE_NEWLINE ();
1887 last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0;
1888 }
1889 else // if (irmp_pulse_time >= irmp_param.pulse_1_len_max && irmp_pulse_time <= irmp_param.pulse_1_len_max)
1890 {
1891 uint8_t manchester_value;
1892
1893 if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max)
1894 {
1895 manchester_value = last_value ? 0 : 1;
1896 last_value = manchester_value;
1897 }
1898 else
1899 {
1900 manchester_value = last_value;
1901 }
1902
1903 #if 0
1904 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1905 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 0) // RC6 mode != 0 ???
1906 {
1907 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
1908 }
1909 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1910 #endif // 0
1911
1912 ANALYZE_PUTCHAR (manchester_value + '0');
1913 ANALYZE_NEWLINE ();
1914 irmp_store_bit (manchester_value);
1915 }
1916
1917 last_pause = irmp_pause_time;
1918 wait_for_space = 0;
1919 }
1920 else
1921 #endif // IRMP_SUPPORT_MANCHESTER == 1
1922
1923
1924 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1925 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit
1926 {
1927 if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
1928 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
1929 {
1930 ANALYZE_PRINTF ("SYNC\n");
1931 wait_for_space = 0;
1932 irmp_tmp_id = 0;
1933 irmp_bit++;
1934 }
1935 else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
1936 {
1937 irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;
1938 irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;
1939 irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
1940 irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;
1941
1942 if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
1943 {
1944 ANALYZE_PUTCHAR ('1');
1945 ANALYZE_NEWLINE ();
1946 irmp_store_bit (1);
1947 wait_for_space = 0;
1948 }
1949 else
1950 {
1951 ANALYZE_PUTCHAR ('0');
1952 ANALYZE_NEWLINE ();
1953 irmp_store_bit (0);
1954 wait_for_space = 0;
1955 }
1956
1957 ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");
1958 }
1959 else
1960 { // timing incorrect!
1961 ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
1962 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1963 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
1964 irmp_pause_time = 0;
1965 }
1966 }
1967 else
1968 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
1969
1970 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1971 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
1972 {
1973 if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
1974 {
1975 if (irmp_bit == 1) // Bang & Olufsen: 3rd bit
1976 {
1977 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
1978 {
1979 ANALYZE_PRINTF ("3rd start bit\n");
1980 wait_for_space = 0;
1981 irmp_tmp_id = 0;
1982 irmp_bit++;
1983 }
1984 else
1985 { // timing incorrect!
1986 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);
1987 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1988 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
1989 irmp_pause_time = 0;
1990 }
1991 }
1992 else if (irmp_bit == 19) // Bang & Olufsen: trailer bit
1993 {
1994 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
1995 {
1996 ANALYZE_PRINTF ("trailer bit\n");
1997 wait_for_space = 0;
1998 irmp_tmp_id = 0;
1999 irmp_bit++;
2000 }
2001 else
2002 { // timing incorrect!
2003 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);
2004 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2005 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2006 irmp_pause_time = 0;
2007 }
2008 }
2009 else
2010 {
2011 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
2012 { // pulse & pause timings correct for "1"?
2013 ANALYZE_PUTCHAR ('1');
2014 ANALYZE_NEWLINE ();
2015 irmp_store_bit (1);
2016 last_value = 1;
2017 wait_for_space = 0;
2018 }
2019 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
2020 { // pulse & pause timings correct for "0"?
2021 ANALYZE_PUTCHAR ('0');
2022 ANALYZE_NEWLINE ();
2023 irmp_store_bit (0);
2024 last_value = 0;
2025 wait_for_space = 0;
2026 }
2027 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
2028 {
2029 ANALYZE_PUTCHAR (last_value + '0');
2030 ANALYZE_NEWLINE ();
2031 irmp_store_bit (last_value);
2032 wait_for_space = 0;
2033 }
2034 else
2035 { // timing incorrect!
2036 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);
2037 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2038 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2039 irmp_pause_time = 0;
2040 }
2041 }
2042 }
2043 else
2044 { // timing incorrect!
2045 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);
2046 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2047 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2048 irmp_pause_time = 0;
2049 }
2050 }
2051 else
2052 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
2053
2054 if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
2055 irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2056 { // pulse & pause timings correct for "1"?
2057 ANALYZE_PUTCHAR ('1');
2058 ANALYZE_NEWLINE ();
2059 irmp_store_bit (1);
2060 wait_for_space = 0;
2061 }
2062 else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
2063 irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
2064 { // pulse & pause timings correct for "0"?
2065 ANALYZE_PUTCHAR ('0');
2066 ANALYZE_NEWLINE ();
2067 irmp_store_bit (0);
2068 wait_for_space = 0;
2069 }
2070 else
2071 { // timing incorrect!
2072 ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2073 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2074 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2075 irmp_pause_time = 0;
2076 }
2077
2078 irmp_pulse_time = 1; // set counter to 1, not 0
2079 }
2080 }
2081 else
2082 { // counting the pulse length ...
2083 if (! irmp_input) // still light?
2084 { // yes...
2085 irmp_pulse_time++; // increment counter
2086 }
2087 else
2088 { // now it's dark!
2089 wait_for_space = 1; // let's count the time (see above)
2090 irmp_pause_time = 1; // set pause counter to 1, not 0
2091 }
2092 }
2093
2094 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received?
2095 {
2096 if (last_irmp_command == irmp_tmp_command && repetition_counter < AUTO_FRAME_REPETITION_LEN)
2097 {
2098 repetition_frame_number++;
2099 }
2100 else
2101 {
2102 repetition_frame_number = 0;
2103 }
2104
2105 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2106 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
2107 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
2108 {
2109 ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2110 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2111 repetition_counter = 0;
2112 }
2113 else
2114 #endif
2115
2116 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2117 // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2118 if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))
2119 {
2120 ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2121 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2122 repetition_counter = 0;
2123 }
2124 else
2125 #endif
2126
2127 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2128 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2129 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
2130 {
2131 ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2132 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2133 repetition_counter = 0;
2134 }
2135 else
2136 #endif
2137
2138 {
2139 ANALYZE_PRINTF ("code detected, length = %d\n", irmp_bit);
2140 irmp_ir_detected = TRUE;
2141
2142 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2143 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2144 { // check for repetition frame
2145 if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
2146 {
2147 irmp_tmp_command = last_irmp_denon_command; // use command received before!
2148
2149 irmp_protocol = irmp_param.protocol; // store protocol
2150 irmp_address = irmp_tmp_address; // store address
2151 irmp_command = irmp_tmp_command ; // store command
2152 }
2153 else
2154 {
2155 ANALYZE_PRINTF ("waiting for inverted command repetition\n");
2156 irmp_ir_detected = FALSE;
2157 last_irmp_denon_command = irmp_tmp_command;
2158 }
2159 }
2160 else
2161 #endif // IRMP_SUPPORT_DENON_PROTOCOL
2162
2163 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
2164 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
2165 { // Grundig start frame?
2166 ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
2167 irmp_ir_detected = FALSE;
2168 }
2169 else
2170 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
2171
2172 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
2173 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
2174 { // Nokia start frame?
2175 ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n");
2176 irmp_ir_detected = FALSE;
2177 }
2178 else
2179 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
2180 {
2181 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2182 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame
2183 {
2184 irmp_tmp_address = last_irmp_address; // address is last address
2185 irmp_tmp_command = last_irmp_command; // command is last command
2186 irmp_flags |= IRMP_FLAG_REPETITION;
2187 }
2188 #endif // IRMP_SUPPORT_NEC_PROTOCOL
2189 irmp_protocol = irmp_param.protocol;
2190 irmp_address = irmp_tmp_address; // store address
2191 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2192 last_irmp_address = irmp_tmp_address; // store as last address, too
2193 #endif
2194
2195 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
2196 irmp_tmp_command |= rc5_cmd_bit6; // store bit 6
2197 #endif
2198 irmp_command = irmp_tmp_command; // store command
2199
2200 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2201 irmp_id = irmp_tmp_id;
2202 #endif
2203 }
2204 }
2205
2206 if (irmp_ir_detected)
2207 {
2208 if (last_irmp_command == irmp_command &&
2209 last_irmp_address == irmp_address &&
2210 repetition_counter < IRMP_KEY_REPETITION_LEN)
2211 {
2212 irmp_flags |= IRMP_FLAG_REPETITION;
2213 }
2214
2215 last_irmp_address = irmp_tmp_address; // store as last address, too
2216 last_irmp_command = irmp_tmp_command; // store as last command, too
2217
2218 repetition_counter = 0;
2219 }
2220 else
2221 {
2222 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2223 }
2224
2225 irmp_start_bit_detected = 0; // and wait for next start bit
2226 irmp_tmp_command = 0;
2227 irmp_pulse_time = 0;
2228 irmp_pause_time = 0;
2229 }
2230 }
2231 }
2232 return (irmp_ir_detected);
2233 }
2234
2235 #ifdef ANALYZE
2236
2237 // main function - for unix/linux + windows only!
2238 // AVR: see main.c!
2239 // Compile it under linux with:
2240 // cc irmp.c -o irmp
2241 //
2242 // usage: ./irmp [-v|-s|-a|-l|-p] < file
2243 // options:
2244 // -v verbose
2245 // -s silent
2246 // -a analyze
2247 // -l list pulse/pauses
2248 // -p print timings
2249
2250 static void
2251 print_timings (void)
2252 {
2253 printf ("PROTOCOL START BIT NO. START BIT PULSE START BIT PAUSE\n");
2254 printf ("====================================================================================\n");
2255 printf ("SIRCS 1 %3d - %3d %3d - %3d\n",
2256 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
2257 printf ("NEC 1 %3d - %3d %3d - %3d\n",
2258 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
2259 printf ("NEC (rep) 1 %3d - %3d %3d - %3d\n",
2260 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
2261 printf ("SAMSUNG 1 %3d - %3d %3d - %3d\n",
2262 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
2263 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d\n",
2264 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
2265 printf ("KASEIKYO 1 %3d - %3d %3d - %3d\n",
2266 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
2267 printf ("RECS80 1 %3d - %3d %3d - %3d\n",
2268 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
2269 printf ("RC5 1 %3d - %3d %3d - %3d\n",
2270 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
2271 printf ("DENON 1 %3d - %3d %3d - %3d or %3d - %3d\n",
2272 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
2273 printf ("RC6 1 %3d - %3d %3d - %3d\n",
2274 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
2275 printf ("RECS80EXT 1 %3d - %3d %3d - %3d\n",
2276 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
2277 printf ("NUBERT 1 %3d - %3d %3d - %3d\n",
2278 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
2279 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
2280 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
2281 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
2282 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
2283 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
2284 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
2285 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
2286 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
2287 printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d\n",
2288 GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN, GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX, GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN, GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX);
2289 printf ("SIEMENS 1 %3d - %3d %3d - %3d\n",
2290 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX, SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX);
2291 printf ("FDC 1 %3d - %3d %3d - %3d\n",
2292 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2293 printf ("RCCAR 1 %3d - %3d %3d - %3d\n",
2294 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
2295 }
2296
2297 void
2298 print_spectrum (char * text, int * buf, int is_pulse)
2299 {
2300 int i;
2301 int j;
2302 int min;
2303 int max;
2304 int max_value = 0;
2305 int value;
2306 int sum = 0;
2307 int counter = 0;
2308 double average = 0;
2309 double tolerance;
2310
2311 puts ("-------------------------------------------------------------------------------");
2312 printf ("%s:\n", text);
2313
2314 for (i = 0; i < 256; i++)
2315 {
2316 if (buf[i] > max_value)
2317 {
2318 max_value = buf[i];
2319 }
2320 }
2321
2322 for (i = 0; i < 100; i++)
2323 {
2324 if (buf[i] > 0)
2325 {
2326 printf ("%3d ", i);
2327 value = (buf[i] * 60) / max_value;
2328
2329 for (j = 0; j < value; j++)
2330 {
2331 putchar ('o');
2332 }
2333 printf (" %d\n", buf[i]);
2334
2335 sum += i * buf[i];
2336 counter += buf[i];
2337 }
2338 else
2339 {
2340 max = i - 1;
2341
2342 if (counter > 0)
2343 {
2344 average = (float) sum / (float) counter;
2345
2346 if (is_pulse)
2347 {
2348 printf ("pulse ");
2349 }
2350 else
2351 {
2352 printf ("pause ");
2353 }
2354
2355 printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS);
2356 printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS);
2357 printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS);
2358
2359 tolerance = (max - average);
2360
2361 if (average - min > tolerance)
2362 {
2363 tolerance = average - min;
2364 }
2365
2366 tolerance = tolerance * 100 / average;
2367 printf ("tol: %4.1f%%\n", tolerance);
2368 }
2369
2370 counter = 0;
2371 sum = 0;
2372 min = i + 1;
2373 }
2374 }
2375 }
2376
2377 int
2378 main (int argc, char ** argv)
2379 {
2380 int i;
2381 int analyze = FALSE;
2382 int list = FALSE;
2383 int ch;
2384 int last_ch = 0;
2385 int pulse = 0;
2386 int pause = 0;
2387
2388 int start_pulses[256];
2389 int start_pauses[256];
2390 int pulses[256];
2391 int pauses[256];
2392
2393 int first_pulse = TRUE;
2394 int first_pause = TRUE;
2395
2396 IRMP_DATA irmp_data;
2397
2398 if (argc == 2)
2399 {
2400 if (! strcmp (argv[1], "-v"))
2401 {
2402 verbose = TRUE;
2403 }
2404 else if (! strcmp (argv[1], "-l"))
2405 {
2406 list = TRUE;
2407 }
2408 else if (! strcmp (argv[1], "-a"))
2409 {
2410 analyze = TRUE;
2411 }
2412 else if (! strcmp (argv[1], "-s"))
2413 {
2414 silent = TRUE;
2415 }
2416 else if (! strcmp (argv[1], "-p"))
2417 {
2418 print_timings ();
2419 return (0);
2420 }
2421 }
2422
2423 for (i = 0; i < 256; i++)
2424 {
2425 start_pulses[i] = 0;
2426 start_pauses[i] = 0;
2427 pulses[i] = 0;
2428 pauses[i] = 0;
2429 }
2430
2431 IRMP_PIN = 0xFF;
2432
2433 while ((ch = getchar ()) != EOF)
2434 {
2435 if (ch == '_' || ch == '0')
2436 {
2437 if (last_ch != ch)
2438 {
2439 if (pause > 0)
2440 {
2441 if (list)
2442 {
2443 printf ("pause: %d\n", pause);
2444 }
2445
2446 if (analyze)
2447 {
2448 if (first_pause)
2449 {
2450 if (pause < 256)
2451 {
2452 start_pauses[pause]++;
2453 }
2454 first_pause = FALSE;
2455 }
2456 else
2457 {
2458 if (pause < 256)
2459 {
2460 pauses[pause]++;
2461 }
2462 }
2463 }
2464 }
2465 pause = 0;
2466 }
2467 pulse++;
2468 IRMP_PIN = 0x00;
2469 }
2470 else if (ch == 0xaf || ch == '-' || ch == '1')
2471 {
2472 if (last_ch != ch)
2473 {
2474 if (list)
2475 {
2476 printf ("pulse: %d ", pulse);
2477 }
2478
2479 if (analyze)
2480 {
2481 if (first_pulse)
2482 {
2483 if (pulse < 256)
2484 {
2485 start_pulses[pulse]++;
2486 }
2487 first_pulse = FALSE;
2488 }
2489 else
2490 {
2491 if (pulse < 256)
2492 {
2493 pulses[pulse]++;
2494 }
2495 }
2496 }
2497 pulse = 0;
2498 }
2499
2500 pause++;
2501 IRMP_PIN = 0xff;
2502 }
2503 else if (ch == '\n')
2504 {
2505 IRMP_PIN = 0xff;
2506
2507 if (list && pause > 0)
2508 {
2509 printf ("pause: %d\n", pause);
2510 }
2511 pause = 0;
2512
2513 if (! analyze)
2514 {
2515 for (i = 0; i < (int) ((8000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 800 msec
2516 {
2517 (void) irmp_ISR ();
2518 }
2519 }
2520 first_pulse = TRUE;
2521 first_pause = TRUE;
2522 }
2523 else if (ch == '#')
2524 {
2525 if (analyze)
2526 {
2527 while ((ch = getchar()) != '\n' && ch != EOF)
2528 {
2529 ;
2530 }
2531 }
2532 else
2533 {
2534 puts ("-------------------------------------------------------------------");
2535 putchar (ch);
2536
2537 while ((ch = getchar()) != '\n' && ch != EOF)
2538 {
2539 if (ch != '\r') // ignore CR in DOS/Windows files
2540 {
2541 putchar (ch);
2542 }
2543 }
2544 putchar ('\n');
2545 }
2546
2547 }
2548
2549 last_ch = ch;
2550
2551 if (! analyze && ! list)
2552 {
2553 (void) irmp_ISR ();
2554
2555 if (irmp_get_data (&irmp_data))
2556 {
2557 ANALYZE_ONLY_NORMAL_PUTCHAR (' ');
2558 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n",
2559 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags);
2560 }
2561 }
2562 }
2563
2564 if (analyze)
2565 {
2566 print_spectrum ("START PULSES", start_pulses, TRUE);
2567 print_spectrum ("START PAUSES", start_pauses, FALSE);
2568 print_spectrum ("PULSES", pulses, TRUE);
2569 print_spectrum ("PAUSES", pauses, FALSE);
2570 puts ("-------------------------------------------------------------------------------");
2571 }
2572 return 0;
2573 }
2574
2575 #endif // ANALYZE