]> cloudbase.mooo.com Git - irmp.git/blob - irmp.c
Version 2.0.2: improved jvc decoder (type 2 and 3)
[irmp.git] / irmp.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp.c - infrared multi-protocol decoder, supports several remote control protocols
3 *
4 * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: irmp.c,v 1.110 2011/09/22 10:19:44 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * Supported mikrocontrollers:
11 *
12 * ATtiny45, ATtiny85
13 * ATtiny84
14 * ATmega8, ATmega16, ATmega32
15 * ATmega162
16 * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284
17 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P
18 *
19 * Typical manufacturers of remote controls:
20 *
21 * SIRCS - Sony
22 * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers
23 * SAMSUNG - Samsung
24 * SAMSUNG32 - Samsung
25 * MATSUSHITA - Matsushita
26 * KASEIKYO - Panasonic, Denon & other Japanese manufacturers (members of "Japan's Association for Electric Home Application")
27 * RECS80 - Philips, Nokia, Thomson, Nordmende, Telefunken, Saba
28 * RC5 - Philips and other European manufacturers
29 * DENON - Denon, Sharp
30 * RC6 - Philips and other European manufacturers
31 * APPLE - Apple
32 * NUBERT - Nubert Subwoofer System
33 * B&O - Bang & Olufsen
34 * PANASONIC - Panasonic (older, yet not implemented)
35 * GRUNDIG - Grundig
36 * NOKIA - Nokia
37 * SIEMENS - Siemens, e.g. Gigaset M740AV
38 * FDC - FDC IR keyboard
39 * RCCAR - IR remote control for RC cars
40 * JVC - JVC
41 * THOMSON - Thomson
42 * NIKON - Nikon cameras
43 * RUWIDO - T-Home
44 * KATHREIN - Kathrein
45 * LEGO - Lego Power Functions RC
46 *
47 *---------------------------------------------------------------------------------------------------------------------------------------------------
48 *
49 * SIRCS
50 * -----
51 *
52 * frame: 1 start bit + 12-20 data bits + no stop bit
53 * data: 7 command bits + 5 address bits + 0 to 8 additional bits
54 *
55 * start bit: data "0": data "1": stop bit:
56 * -----------------_________ ------_____ ------------______
57 * 2400us 600us 600us 600us 1200us 600 us no stop bit
58 *
59 *---------------------------------------------------------------------------------------------------------------------------------------------------
60 *
61 * NEC + extended NEC
62 * -------------------------
63 *
64 * frame: 1 start bit + 32 data bits + 1 stop bit
65 * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits
66 * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits
67 *
68 * start bit: data "0": data "1": stop bit:
69 * -----------------_________ ------______ ------________________ ------______....
70 * 9000us 4500us 560us 560us 560us 1690 us 560us
71 *
72 *
73 * Repetition frame:
74 *
75 * -----------------_________------______ .... ~100ms Pause, then repeat
76 * 9000us 2250us 560us
77 *
78 *---------------------------------------------------------------------------------------------------------------------------------------------------
79 *
80 * SAMSUNG
81 * -------
82 *
83 * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit
84 * data(1): 16 address bits
85 * data(2): 4 ID bits + 8 command bits + 8 inverted command bits
86 *
87 * start bit: data "0": data "1": sync bit: stop bit:
88 * ----------______________ ------______ ------________________ ------______________ ------______....
89 * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us
90 *
91 *---------------------------------------------------------------------------------------------------------------------------------------------------
92 *
93 * SAMSUNG32
94 * ----------
95 *
96 * frame: 1 start bit + 32 data bits + 1 stop bit
97 * data: 16 address bits + 16 command bits
98 *
99 * start bit: data "0": data "1": stop bit:
100 * ----------______________ ------______ ------________________ ------______....
101 * 4500us 4500us 550us 450us 550us 1450us 550us
102 *
103 *---------------------------------------------------------------------------------------------------------------------------------------------------
104 *
105 * MATSUSHITA
106 * ----------
107 *
108 * frame: 1 start bit + 24 data bits + 1 stop bit
109 * data: 6 custom bits + 6 command bits + 12 address bits
110 *
111 * start bit: data "0": data "1": stop bit:
112 * ----------_________ ------______ ------________________ ------______....
113 * 3488us 3488us 872us 872us 872us 2616us 872us
114 *
115 *---------------------------------------------------------------------------------------------------------------------------------------------------
116 *
117 * KASEIKYO
118 * --------
119 *
120 * frame: 1 start bit + 48 data bits + 1 stop bit
121 * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits
122 *
123 * start bit: data "0": data "1": stop bit:
124 * ----------______ ------______ ------________________ ------______....
125 * 3380us 1690us 423us 423us 423us 1269us 423us
126 *
127 *---------------------------------------------------------------------------------------------------------------------------------------------------
128 *
129 * RECS80
130 * ------
131 *
132 * frame: 2 start bits + 10 data bits + 1 stop bit
133 * data: 1 toggle bit + 3 address bits + 6 command bits
134 *
135 * start bit: data "0": data "1": stop bit:
136 * -----_____________________ -----____________ -----______________ ------_______....
137 * 158us 7432us 158us 4902us 158us 7432us 158us
138 *
139 *---------------------------------------------------------------------------------------------------------------------------------------------------
140 *
141 * RECS80EXT
142 * ---------
143 *
144 * frame: 2 start bits + 11 data bits + 1 stop bit
145 * data: 1 toggle bit + 4 address bits + 6 command bits
146 *
147 * start bit: data "0": data "1": stop bit:
148 * -----_____________________ -----____________ -----______________ ------_______....
149 * 158us 3637us 158us 4902us 158us 7432us 158us
150 *
151 *---------------------------------------------------------------------------------------------------------------------------------------------------
152 *
153 * RC5 + RC5X
154 * ----------
155 *
156 * RC5 frame: 2 start bits + 12 data bits + no stop bit
157 * RC5 data: 1 toggle bit + 5 address bits + 6 command bits
158 * RC5X frame: 1 start bit + 13 data bits + no stop bit
159 * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits
160 *
161 * start bit: data "0": data "1":
162 * ______----- ------______ ______------
163 * 889us 889us 889us 889us 889us 889us
164 *
165 *---------------------------------------------------------------------------------------------------------------------------------------------------
166 *
167 * DENON
168 * -----
169 *
170 * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit
171 * data: 5 address bits + 10 command bits
172 *
173 * Theory:
174 *
175 * data "0": data "1":
176 * ------________________ ------______________
177 * 275us 775us 275us 1900us
178 *
179 * Practice:
180 *
181 * data "0": data "1":
182 * ------________________ ------______________
183 * 310us 745us 310us 1780us
184 *
185 *---------------------------------------------------------------------------------------------------------------------------------------------------
186 *
187 * RC6
188 * ---
189 *
190 * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 us pause
191 * RC6 data: 8 address bits + 8 command bits
192 *
193 * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1":
194 * ____________------- _______------- -------_______ _______------- -------_______
195 * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us
196 *
197 *---------------------------------------------------------------------------------------------------------------------------------------------------
198 *
199 * APPLE
200 * -----
201 *
202 * frame: 1 start bit + 32 data bits + 1 stop bit
203 * data: 16 address bits + 11100000 + 8 command bits
204 *
205 * start bit: data "0": data "1": stop bit:
206 * -----------------_________ ------______ ------________________ ------______....
207 * 9000us 4500us 560us 560us 560us 1690 us 560us
208 *
209 *---------------------------------------------------------------------------------------------------------------------------------------------------
210 *
211 * NUBERT (subwoofer system)
212 * -------------------------
213 *
214 * frame: 1 start bit + 10 data bits + 1 stop bit
215 * data: 0 address bits + 10 command bits ?
216 *
217 * start bit: data "0": data "1": stop bit:
218 * ----------_____ ------______ ------________________ ------______....
219 * 1340us 340us 500us 1300us 1340us 340us 500us
220 *
221 *---------------------------------------------------------------------------------------------------------------------------------------------------
222 *
223 * BANG_OLUFSEN
224 * ------------
225 *
226 * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit
227 * data: 0 address bits + 16 command bits
228 *
229 * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit:
230 * -----________ -----________ -----_____________ -----________
231 * 210us 3000us 210us 3000us 210us 15000us 210us 3000us
232 *
233 * data "0": data "1": data "repeat bit": trailer bit: stop bit:
234 * -----________ -----_____________ -----___________ -----_____________ -----____...
235 * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us
236 *
237 *---------------------------------------------------------------------------------------------------------------------------------------------------
238 *
239 * GRUNDIG
240 * -------
241 *
242 * packet: 1 start frame + 19,968ms pause + N info frames + 117,76ms pause + 1 stop frame
243 * frame: 1 pre bit + 1 start bit + 9 data bits + no stop bit
244 * pause between info frames: 117,76ms
245 *
246 * data of start frame: 9 x 1
247 * data of info frame: 9 command bits
248 * data of stop frame: 9 x 1
249 *
250 * pre bit: start bit data "0": data "1":
251 * ------____________ ------______ ______------ ------______
252 * 528us 2639us 528us 528us 528us 528us 528us 528us
253 *
254 *---------------------------------------------------------------------------------------------------------------------------------------------------
255 *
256 * NOKIA:
257 * ------
258 *
259 * Timing similar to Grundig, but 16 data bits:
260 * frame: 1 pre bit + 1 start bit + 8 command bits + 8 address bits + no stop bit
261 *
262 *---------------------------------------------------------------------------------------------------------------------------------------------------
263 *
264 * SIEMENS or RUWIDO:
265 * ------------------
266 *
267 * SIEMENS frame: 1 start bit + 22 data bits + no stop bit
268 * SIEMENS data: 13 address bits + 1 repeat bit + 7 data bits + 1 unknown bit
269 *
270 * start bit data "0": data "1":
271 * -------_______ _______------- -------_______
272 * 250us 250us 250us 250us 250us 250us
273 *
274 *---------------------------------------------------------------------------------------------------------------------------------------------------
275 *
276 * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar)
277 * -----------------------------------------------------------------------------------------
278 *
279 * frame: 1 start bit + 22 data bits + 1 stop bit
280 * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits
281 *
282 * European version: T = 456us
283 * USA & Canada version: T = 422us
284 *
285 * start bit: data "0": data "1": stop bit:
286 * 8T 8T 2T 2T 2T 6T 2T
287 * -------------____________ ------_____ ------_____________ ------_______....
288 * 3648us 3648us 912us 912us 912us 2736us 912us (Europe)
289 * 3376us 3376us 844us 844us 844us 2532us 844us (US)
290 *
291 *---------------------------------------------------------------------------------------------------------------------------------------------------
292 *
293 * This program is free software; you can redistribute it and/or modify
294 * it under the terms of the GNU General Public License as published by
295 * the Free Software Foundation; either version 2 of the License, or
296 * (at your option) any later version.
297 *---------------------------------------------------------------------------------------------------------------------------------------------------
298 */
299
300 #if defined(__18CXX)
301 #define PIC_C18 // Microchip C18 Compiler
302 #endif
303
304 #if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR
305 #define PIC_CCS_COMPILER
306 #endif
307
308 #ifdef unix // test on linux/unix
309 #include <stdio.h>
310 #include <unistd.h>
311 #include <stdlib.h>
312 #include <string.h>
313 #include <inttypes.h>
314
315 #define ANALYZE
316 #define PROGMEM
317 #define memcpy_P memcpy
318
319 #else // not unix:
320
321 #ifdef WIN32
322 #include <stdio.h>
323 #include <string.h>
324 typedef unsigned char uint8_t;
325 typedef unsigned short uint16_t;
326 #define ANALYZE
327 #define PROGMEM
328 #define memcpy_P memcpy
329
330 #else
331
332 #if defined (PIC_CCS_COMPILER) || defined(PIC_C18)
333
334 #include <string.h>
335 #define PROGMEM
336 #define memcpy_P memcpy
337
338 #if defined (PIC_CCS_COMPILER)
339 typedef unsigned int8 uint8_t;
340 typedef unsigned int16 uint16_t;
341 #endif
342
343 #else // AVR:
344
345 #include <inttypes.h>
346 #include <stdio.h>
347 #include <string.h>
348 #include <avr/io.h>
349 #include <util/delay.h>
350 #include <avr/pgmspace.h>
351
352 #endif // PIC_CCS_COMPILER or PIC_C18
353
354 #endif // windows
355 #endif // unix
356
357 #ifndef IRMP_USE_AS_LIB
358 #include "irmpconfig.h"
359 #endif
360 #include "irmp.h"
361
362 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_IR60_PROTOCOL == 1
363 #define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 1
364 #else
365 #define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 0
366 #endif
367
368 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 || IRMP_SUPPORT_RUWIDO_PROTOCOL == 1
369 #define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 1
370 #else
371 #define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 0
372 #endif
373
374 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || \
375 IRMP_SUPPORT_RC6_PROTOCOL == 1 || \
376 IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 || \
377 IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 || \
378 IRMP_SUPPORT_IR60_PROTOCOL
379 #define IRMP_SUPPORT_MANCHESTER 1
380 #else
381 #define IRMP_SUPPORT_MANCHESTER 0
382 #endif
383
384 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
385 #define IRMP_SUPPORT_SERIAL 1
386 #else
387 #define IRMP_SUPPORT_SERIAL 0
388 #endif
389
390 #define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec
391
392 #define MIN_TOLERANCE_00 1.0 // -0%
393 #define MAX_TOLERANCE_00 1.0 // +0%
394
395 #define MIN_TOLERANCE_05 0.95 // -5%
396 #define MAX_TOLERANCE_05 1.05 // +5%
397
398 #define MIN_TOLERANCE_10 0.9 // -10%
399 #define MAX_TOLERANCE_10 1.1 // +10%
400
401 #define MIN_TOLERANCE_15 0.85 // -15%
402 #define MAX_TOLERANCE_15 1.15 // +15%
403
404 #define MIN_TOLERANCE_20 0.8 // -20%
405 #define MAX_TOLERANCE_20 1.2 // +20%
406
407 #define MIN_TOLERANCE_30 0.7 // -30%
408 #define MAX_TOLERANCE_30 1.3 // +30%
409
410 #define MIN_TOLERANCE_40 0.6 // -40%
411 #define MAX_TOLERANCE_40 1.4 // +40%
412
413 #define MIN_TOLERANCE_50 0.5 // -50%
414 #define MAX_TOLERANCE_50 1.5 // +50%
415
416 #define MIN_TOLERANCE_60 0.4 // -60%
417 #define MAX_TOLERANCE_60 1.6 // +60%
418
419 #define MIN_TOLERANCE_70 0.3 // -70%
420 #define MAX_TOLERANCE_70 1.7 // +70%
421
422 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
423 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
424 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
425 #if IRMP_SUPPORT_NETBOX_PROTOCOL // only 5% to avoid conflict with NETBOX:
426 #define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
427 #else // only 5% + 1 to avoid conflict with RC6:
428 #define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
429 #endif
430 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
431 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
432 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
433 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
434 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
435 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
436
437 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
438 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
439 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
440 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
441 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
442 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
443 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
444 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
445 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
446 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
447 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
448 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
449 // autodetect nec repetition frame within 50 msec:
450 // NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms
451 #if 0
452 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
453 #else
454 #define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5)
455 #endif
456
457 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
458 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
459 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
460 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
461 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
462 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
463 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
464 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
465 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
466 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
467
468 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
469 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
470 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
471 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
472 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
473 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
474 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
475 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
476 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
477 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
478
479 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
480 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
481 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
482 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
483 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
484 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
485 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
486 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
487 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
488 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
489
490 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
491 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
492 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
493 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
494 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
495 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
496 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
497 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
498 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
499 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
500
501 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
502 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
503
504 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
505 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
506
507 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
508 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
509 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
510 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
511 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
512 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5)) // no -1, avoid conflict with RUWIDO
513 #else
514 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) // be more tolerant
515 #endif
516 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
517
518 #define THOMSON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
519 #define THOMSON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
520 #define THOMSON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
521 #define THOMSON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
522 #define THOMSON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
523 #define THOMSON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
524
525 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
526 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
527 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
528 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
529 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
530 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
531 #define RC6_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
532 #define RC6_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_60 + 0.5) + 1) // pulses: 300 - 800
533 #define RC6_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
534 #define RC6_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) // pauses: 300 - 600
535
536 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
537 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
538 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
539 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
540 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
541 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
542 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
543 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
544 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
545 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
546
547 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
548 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
549 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
550 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
551 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
552 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
553 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
554 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
555 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
556 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
557 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
558 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
559
560 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
561 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
562 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
563 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
564 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
565 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
566 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
567 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
568 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
569 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
570 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
571 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((PAUSE_LEN)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // value must be below IRMP_TIMEOUT
572 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
573 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
574 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
575 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
576 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
577 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
578 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
579 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
580 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
581 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
582 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
583 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
584 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
585 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
586
587 #define IR60_TIMEOUT_LEN ((uint8_t)(F_INTERRUPTS * IR60_TIMEOUT_TIME * 0.5))
588 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
589 #define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
590 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
591 #define GRUNDIG_NOKIA_IR60_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
592 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1)
593 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
594
595 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
596 #define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
597 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
598 #define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
599 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
600 #define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
601 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
602 #define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
603
604 #define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) // 5%: avoid conflict with NETBOX
605 #define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5))
606 #define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
607 #define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5))
608 #define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
609 #define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
610 #define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
611 #define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
612 #if 0
613 #define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) // could be negative: 255
614 #else
615 #define FDC_0_PAUSE_LEN_MIN (1) // simply use 1
616 #endif
617 #define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
618
619 #define RCCAR_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
620 #define RCCAR_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
621 #define RCCAR_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
622 #define RCCAR_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
623 #define RCCAR_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
624 #define RCCAR_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
625 #define RCCAR_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
626 #define RCCAR_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
627 #define RCCAR_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
628 #define RCCAR_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
629
630 #define JVC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
631 #define JVC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
632 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MIN_TOLERANCE_40 + 0.5) - 1) // HACK!
633 #define JVC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MAX_TOLERANCE_70 + 0.5) - 1) // HACK!
634 #define JVC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
635 #define JVC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
636 #define JVC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
637 #define JVC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
638 #define JVC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
639 #define JVC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
640 // autodetect JVC repetition frame within 50 msec:
641 #define JVC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
642
643 #define NIKON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
644 #define NIKON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
645 #define NIKON_START_BIT_PAUSE_LEN_MIN ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
646 #define NIKON_START_BIT_PAUSE_LEN_MAX ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
647 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
648 #define NIKON_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
649 #define NIKON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
650 #define NIKON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
651 #define NIKON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
652 #define NIKON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
653 #define NIKON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
654 #define NIKON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
655 #define NIKON_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5)
656
657 #define KATHREIN_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
658 #define KATHREIN_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
659 #define KATHREIN_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
660 #define KATHREIN_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
661 #define KATHREIN_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
662 #define KATHREIN_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
663 #define KATHREIN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
664 #define KATHREIN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
665 #define KATHREIN_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
666 #define KATHREIN_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
667 #define KATHREIN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
668 #define KATHREIN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
669 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
670 #define KATHREIN_SYNC_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
671
672 #define NETBOX_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
673 #define NETBOX_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
674 #define NETBOX_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
675 #define NETBOX_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
676 #define NETBOX_PULSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME))
677 #define NETBOX_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME))
678 #define NETBOX_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4))
679 #define NETBOX_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4))
680
681 #define LEGO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
682 #define LEGO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
683 #define LEGO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
684 #define LEGO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
685 #define LEGO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
686 #define LEGO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
687 #define LEGO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
688 #define LEGO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
689 #define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
690 #define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
691
692 #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t!
693
694 #ifdef ANALYZE
695 #define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } }
696 #define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } }
697 #define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } }
698 #define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } }
699 static int silent;
700 static int time_counter;
701 static int verbose;
702 #else
703 #define ANALYZE_PUTCHAR(a)
704 #define ANALYZE_ONLY_NORMAL_PUTCHAR(a)
705 #define ANALYZE_PRINTF(...)
706 #define ANALYZE_NEWLINE()
707 #endif
708
709 #if IRMP_USE_CALLBACK == 1
710 static void (*irmp_callback_ptr) (uint8_t);
711 #endif // IRMP_USE_CALLBACK == 1
712
713 /*---------------------------------------------------------------------------------------------------------------------------------------------------
714 * Protocol names
715 *---------------------------------------------------------------------------------------------------------------------------------------------------
716 */
717 #if IRMP_PROTOCOL_NAMES == 1
718 char *
719 irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =
720 {
721 "UNKNOWN",
722 "SIRCS",
723 "NEC",
724 "SAMSUNG",
725 "MATSUSH",
726 "KASEIKYO",
727 "RECS80",
728 "RC5",
729 "DENON",
730 "RC6",
731 "SAMSG32",
732 "APPLE",
733 "RECS80EX",
734 "NUBERT",
735 "BANG OLU",
736 "GRUNDIG",
737 "NOKIA",
738 "SIEMENS",
739 "FDC",
740 "RCCAR",
741 "JVC",
742 "RC6A",
743 "NIKON",
744 "RUWIDO",
745 "IR60",
746 "KATHREIN",
747 "NETBOX",
748 "NEC16",
749 "NEC42",
750 "LEGO",
751 "THOMSON"
752 };
753 #endif
754
755 /*---------------------------------------------------------------------------------------------------------------------------------------------------
756 * Logging
757 *---------------------------------------------------------------------------------------------------------------------------------------------------
758 */
759 #if IRMP_LOGGING == 1
760 #define BAUD 9600L
761 #include <util/setbaud.h>
762
763 #ifdef UBRR0H
764
765 #define UART0_UBRRH UBRR0H
766 #define UART0_UBRRL UBRR0L
767 #define UART0_UCSRA UCSR0A
768 #define UART0_UCSRB UCSR0B
769 #define UART0_UCSRC UCSR0C
770 #define UART0_UDRE_BIT_VALUE (1<<UDRE0)
771 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ01)
772 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ00)
773 #ifdef URSEL0
774 #define UART0_URSEL_BIT_VALUE (1<<URSEL0)
775 #else
776 #define UART0_URSEL_BIT_VALUE (0)
777 #endif
778 #define UART0_TXEN_BIT_VALUE (1<<TXEN0)
779 #define UART0_UDR UDR0
780 #define UART0_U2X U2X0
781
782 #else
783
784 #define UART0_UBRRH UBRRH
785 #define UART0_UBRRL UBRRL
786 #define UART0_UCSRA UCSRA
787 #define UART0_UCSRB UCSRB
788 #define UART0_UCSRC UCSRC
789 #define UART0_UDRE_BIT_VALUE (1<<UDRE)
790 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ1)
791 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ0)
792 #ifdef URSEL
793 #define UART0_URSEL_BIT_VALUE (1<<URSEL)
794 #else
795 #define UART0_URSEL_BIT_VALUE (0)
796 #endif
797 #define UART0_TXEN_BIT_VALUE (1<<TXEN)
798 #define UART0_UDR UDR
799 #define UART0_U2X U2X
800
801 #endif
802
803 /*---------------------------------------------------------------------------------------------------------------------------------------------------
804 * Initialize UART
805 * @details Initializes UART
806 *---------------------------------------------------------------------------------------------------------------------------------------------------
807 */
808 void
809 irmp_uart_init (void)
810 {
811 UART0_UBRRH = UBRRH_VALUE; // set baud rate
812 UART0_UBRRL = UBRRL_VALUE;
813
814 #if USE_2X
815 UART0_UCSRA |= (1<<UART0_U2X);
816 #else
817 UART0_UCSRA &= ~(1<<UART0_U2X);
818 #endif
819
820 UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;
821 UART0_UCSRB |= UART0_TXEN_BIT_VALUE; // enable UART TX
822 }
823
824 /*---------------------------------------------------------------------------------------------------------------------------------------------------
825 * Send character
826 * @details Sends character
827 * @param ch character to be transmitted
828 *---------------------------------------------------------------------------------------------------------------------------------------------------
829 */
830 void
831 irmp_uart_putc (unsigned char ch)
832 {
833 while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))
834 {
835 ;
836 }
837
838 UART0_UDR = ch;
839 }
840
841 /*---------------------------------------------------------------------------------------------------------------------------------------------------
842 * Log IR signal
843 *---------------------------------------------------------------------------------------------------------------------------------------------------
844 */
845
846 #define STARTCYCLES 2 // min count of zeros before start of logging
847 #define ENDBITS 1000 // number of sequenced highbits to detect end
848 #define DATALEN 700 // log buffer size
849
850 static void
851 irmp_log (uint8_t val)
852 {
853 static uint8_t buf[DATALEN]; // logging buffer
854 static uint16_t buf_idx; // number of written bits
855 static uint8_t startcycles; // current number of start-zeros
856 static uint16_t cnt; // counts sequenced highbits - to detect end
857
858 if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging
859 {
860 startcycles++;
861 }
862 else
863 {
864 startcycles = 0;
865
866 if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging
867 {
868 if (buf_idx < DATALEN * 8) // index in range?
869 { // yes
870 if (val)
871 {
872 buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit
873 }
874 else
875 {
876 buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit
877 }
878
879 buf_idx++;
880 }
881
882 if (val)
883 { // if high received then look at log-stop condition
884 cnt++;
885
886 if (cnt > ENDBITS)
887 { // if stop condition is true, output on uart
888 uint16_t i;
889
890 for (i = 0; i < STARTCYCLES; i++)
891 {
892 irmp_uart_putc ('0'); // the ignored starting zeros
893 }
894
895 for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars
896 {
897 uint8_t d = buf[i];
898 uint8_t j;
899
900 for (j = 0; j < 8; j++)
901 {
902 irmp_uart_putc ((d & 1) + '0');
903 d >>= 1;
904 }
905 }
906
907 irmp_uart_putc ('\n');
908 buf_idx = 0;
909 }
910 }
911 else
912 {
913 cnt = 0;
914 }
915 }
916 }
917 }
918
919 #else
920 #define irmp_log(val)
921 #endif
922
923 typedef struct
924 {
925 uint8_t protocol; // ir protocol
926 uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1
927 uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1
928 uint8_t pause_1_len_min; // minimum length of pause with bit value 1
929 uint8_t pause_1_len_max; // maximum length of pause with bit value 1
930 uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0
931 uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0
932 uint8_t pause_0_len_min; // minimum length of pause with bit value 0
933 uint8_t pause_0_len_max; // maximum length of pause with bit value 0
934 uint8_t address_offset; // address offset
935 uint8_t address_end; // end of address
936 uint8_t command_offset; // command offset
937 uint8_t command_end; // end of command
938 uint8_t complete_len; // complete length of frame
939 uint8_t stop_bit; // flag: frame has stop bit
940 uint8_t lsb_first; // flag: LSB first
941 uint8_t flags; // some flags
942 } IRMP_PARAMETER;
943
944 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
945
946 static const PROGMEM IRMP_PARAMETER sircs_param =
947 {
948 IRMP_SIRCS_PROTOCOL, // protocol: ir protocol
949 SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
950 SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
951 SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
952 SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
953 SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
954 SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
955 SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
956 SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
957 SIRCS_ADDRESS_OFFSET, // address_offset: address offset
958 SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address
959 SIRCS_COMMAND_OFFSET, // command_offset: command offset
960 SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command
961 SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
962 SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit
963 SIRCS_LSB, // lsb_first: flag: LSB first
964 SIRCS_FLAGS // flags: some flags
965 };
966
967 #endif
968
969 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
970
971 static const PROGMEM IRMP_PARAMETER nec_param =
972 {
973 IRMP_NEC_PROTOCOL, // protocol: ir protocol
974 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
975 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
976 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
977 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
978 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
979 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
980 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
981 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
982 NEC_ADDRESS_OFFSET, // address_offset: address offset
983 NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address
984 NEC_COMMAND_OFFSET, // command_offset: command offset
985 NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command
986 NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
987 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
988 NEC_LSB, // lsb_first: flag: LSB first
989 NEC_FLAGS // flags: some flags
990 };
991
992 static const PROGMEM IRMP_PARAMETER nec_rep_param =
993 {
994 IRMP_NEC_PROTOCOL, // protocol: ir protocol
995 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
996 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
997 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
998 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
999 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1000 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1001 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1002 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1003 0, // address_offset: address offset
1004 0, // address_end: end of address
1005 0, // command_offset: command offset
1006 0, // command_end: end of command
1007 0, // complete_len: complete length of frame
1008 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
1009 NEC_LSB, // lsb_first: flag: LSB first
1010 NEC_FLAGS // flags: some flags
1011 };
1012
1013 #endif
1014
1015 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
1016
1017 static const PROGMEM IRMP_PARAMETER nec42_param =
1018 {
1019 IRMP_NEC42_PROTOCOL, // protocol: ir protocol
1020 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1021 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1022 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1023 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1024 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1025 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1026 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1027 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1028 NEC42_ADDRESS_OFFSET, // address_offset: address offset
1029 NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN, // address_end: end of address
1030 NEC42_COMMAND_OFFSET, // command_offset: command offset
1031 NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN, // command_end: end of command
1032 NEC42_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1033 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
1034 NEC_LSB, // lsb_first: flag: LSB first
1035 NEC_FLAGS // flags: some flags
1036 };
1037
1038 #endif
1039
1040 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1041
1042 static const PROGMEM IRMP_PARAMETER samsung_param =
1043 {
1044 IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol
1045 SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1046 SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1047 SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1048 SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1049 SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1050 SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1051 SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1052 SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1053 SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset
1054 SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address
1055 SAMSUNG_COMMAND_OFFSET, // command_offset: command offset
1056 SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command
1057 SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1058 SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit
1059 SAMSUNG_LSB, // lsb_first: flag: LSB first
1060 SAMSUNG_FLAGS // flags: some flags
1061 };
1062
1063 #endif
1064
1065 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1066
1067 static const PROGMEM IRMP_PARAMETER matsushita_param =
1068 {
1069 IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol
1070 MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1071 MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1072 MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1073 MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1074 MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1075 MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1076 MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1077 MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1078 MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset
1079 MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address
1080 MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset
1081 MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command
1082 MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1083 MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit
1084 MATSUSHITA_LSB, // lsb_first: flag: LSB first
1085 MATSUSHITA_FLAGS // flags: some flags
1086 };
1087
1088 #endif
1089
1090 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1091
1092 static const PROGMEM IRMP_PARAMETER kaseikyo_param =
1093 {
1094 IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol
1095 KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1096 KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1097 KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1098 KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1099 KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1100 KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1101 KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1102 KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1103 KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset
1104 KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address
1105 KASEIKYO_COMMAND_OFFSET, // command_offset: command offset
1106 KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command
1107 KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1108 KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit
1109 KASEIKYO_LSB, // lsb_first: flag: LSB first
1110 KASEIKYO_FLAGS // flags: some flags
1111 };
1112
1113 #endif
1114
1115 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1116
1117 static const PROGMEM IRMP_PARAMETER recs80_param =
1118 {
1119 IRMP_RECS80_PROTOCOL, // protocol: ir protocol
1120 RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1121 RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1122 RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1123 RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1124 RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1125 RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1126 RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1127 RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1128 RECS80_ADDRESS_OFFSET, // address_offset: address offset
1129 RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address
1130 RECS80_COMMAND_OFFSET, // command_offset: command offset
1131 RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command
1132 RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1133 RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit
1134 RECS80_LSB, // lsb_first: flag: LSB first
1135 RECS80_FLAGS // flags: some flags
1136 };
1137
1138 #endif
1139
1140 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1141
1142 static const PROGMEM IRMP_PARAMETER rc5_param =
1143 {
1144 IRMP_RC5_PROTOCOL, // protocol: ir protocol
1145 RC5_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
1146 RC5_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
1147 RC5_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
1148 RC5_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1149 0, // pulse_0_len_min: here: not used
1150 0, // pulse_0_len_max: here: not used
1151 0, // pause_0_len_min: here: not used
1152 0, // pause_0_len_max: here: not used
1153 RC5_ADDRESS_OFFSET, // address_offset: address offset
1154 RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address
1155 RC5_COMMAND_OFFSET, // command_offset: command offset
1156 RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command
1157 RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1158 RC5_STOP_BIT, // stop_bit: flag: frame has stop bit
1159 RC5_LSB, // lsb_first: flag: LSB first
1160 RC5_FLAGS // flags: some flags
1161 };
1162
1163 #endif
1164
1165 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1166
1167 static const PROGMEM IRMP_PARAMETER denon_param =
1168 {
1169 IRMP_DENON_PROTOCOL, // protocol: ir protocol
1170 DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1171 DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1172 DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1173 DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1174 DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1175 DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1176 DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1177 DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1178 DENON_ADDRESS_OFFSET, // address_offset: address offset
1179 DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address
1180 DENON_COMMAND_OFFSET, // command_offset: command offset
1181 DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command
1182 DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1183 DENON_STOP_BIT, // stop_bit: flag: frame has stop bit
1184 DENON_LSB, // lsb_first: flag: LSB first
1185 DENON_FLAGS // flags: some flags
1186 };
1187
1188 #endif
1189
1190 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1191
1192 static const PROGMEM IRMP_PARAMETER rc6_param =
1193 {
1194 IRMP_RC6_PROTOCOL, // protocol: ir protocol
1195
1196 RC6_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
1197 RC6_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
1198 RC6_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
1199 RC6_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1200 0, // pulse_0_len_min: here: not used
1201 0, // pulse_0_len_max: here: not used
1202 0, // pause_0_len_min: here: not used
1203 0, // pause_0_len_max: here: not used
1204 RC6_ADDRESS_OFFSET, // address_offset: address offset
1205 RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address
1206 RC6_COMMAND_OFFSET, // command_offset: command offset
1207 RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command
1208 RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame
1209 RC6_STOP_BIT, // stop_bit: flag: frame has stop bit
1210 RC6_LSB, // lsb_first: flag: LSB first
1211 RC6_FLAGS // flags: some flags
1212 };
1213
1214 #endif
1215
1216 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1217
1218 static const PROGMEM IRMP_PARAMETER recs80ext_param =
1219 {
1220 IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol
1221 RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1222 RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1223 RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1224 RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1225 RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1226 RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1227 RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1228 RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1229 RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset
1230 RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address
1231 RECS80EXT_COMMAND_OFFSET, // command_offset: command offset
1232 RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command
1233 RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1234 RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit
1235 RECS80EXT_LSB, // lsb_first: flag: LSB first
1236 RECS80EXT_FLAGS // flags: some flags
1237 };
1238
1239 #endif
1240
1241 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1242
1243 static const PROGMEM IRMP_PARAMETER nubert_param =
1244 {
1245 IRMP_NUBERT_PROTOCOL, // protocol: ir protocol
1246 NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1247 NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1248 NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1249 NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1250 NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1251 NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1252 NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1253 NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1254 NUBERT_ADDRESS_OFFSET, // address_offset: address offset
1255 NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address
1256 NUBERT_COMMAND_OFFSET, // command_offset: command offset
1257 NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command
1258 NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1259 NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit
1260 NUBERT_LSB, // lsb_first: flag: LSB first
1261 NUBERT_FLAGS // flags: some flags
1262 };
1263
1264 #endif
1265
1266 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1267
1268 static const PROGMEM IRMP_PARAMETER bang_olufsen_param =
1269 {
1270 IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol
1271 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1272 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1273 BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1274 BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1275 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1276 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1277 BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1278 BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1279 BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset
1280 BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address
1281 BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset
1282 BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command
1283 BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1284 BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit
1285 BANG_OLUFSEN_LSB, // lsb_first: flag: LSB first
1286 BANG_OLUFSEN_FLAGS // flags: some flags
1287 };
1288
1289 #endif
1290
1291 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
1292
1293 static uint8_t first_bit;
1294
1295 static const PROGMEM IRMP_PARAMETER grundig_param =
1296 {
1297 IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol
1298
1299 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
1300 GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
1301 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
1302 GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1303 0, // pulse_0_len_min: here: not used
1304 0, // pulse_0_len_max: here: not used
1305 0, // pause_0_len_min: here: not used
1306 0, // pause_0_len_max: here: not used
1307 GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset
1308 GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address
1309 GRUNDIG_COMMAND_OFFSET, // command_offset: command offset
1310 GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!)
1311 NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG!
1312 GRUNDIG_NOKIA_IR60_STOP_BIT, // stop_bit: flag: frame has stop bit
1313 GRUNDIG_NOKIA_IR60_LSB, // lsb_first: flag: LSB first
1314 GRUNDIG_NOKIA_IR60_FLAGS // flags: some flags
1315 };
1316
1317 #endif
1318
1319 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
1320
1321 static const PROGMEM IRMP_PARAMETER ruwido_param =
1322 {
1323 IRMP_RUWIDO_PROTOCOL, // protocol: ir protocol
1324 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse
1325 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse
1326 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause
1327 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause
1328 0, // pulse_0_len_min: here: not used
1329 0, // pulse_0_len_max: here: not used
1330 0, // pause_0_len_min: here: not used
1331 0, // pause_0_len_max: here: not used
1332 RUWIDO_ADDRESS_OFFSET, // address_offset: address offset
1333 RUWIDO_ADDRESS_OFFSET + RUWIDO_ADDRESS_LEN, // address_end: end of address
1334 RUWIDO_COMMAND_OFFSET, // command_offset: command offset
1335 RUWIDO_COMMAND_OFFSET + RUWIDO_COMMAND_LEN, // command_end: end of command
1336 SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: SIEMENS instead of RUWIDO!
1337 SIEMENS_OR_RUWIDO_STOP_BIT, // stop_bit: flag: frame has stop bit
1338 SIEMENS_OR_RUWIDO_LSB, // lsb_first: flag: LSB first
1339 SIEMENS_OR_RUWIDO_FLAGS // flags: some flags
1340 };
1341
1342 #endif
1343
1344 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1345
1346 static const PROGMEM IRMP_PARAMETER fdc_param =
1347 {
1348 IRMP_FDC_PROTOCOL, // protocol: ir protocol
1349 FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1350 FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1351 FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1352 FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1353 FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1354 FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1355 FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1356 FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1357 FDC_ADDRESS_OFFSET, // address_offset: address offset
1358 FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address
1359 FDC_COMMAND_OFFSET, // command_offset: command offset
1360 FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command
1361 FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1362 FDC_STOP_BIT, // stop_bit: flag: frame has stop bit
1363 FDC_LSB, // lsb_first: flag: LSB first
1364 FDC_FLAGS // flags: some flags
1365 };
1366
1367 #endif
1368
1369 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1370
1371 static const PROGMEM IRMP_PARAMETER rccar_param =
1372 {
1373 IRMP_RCCAR_PROTOCOL, // protocol: ir protocol
1374 RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1375 RCCAR_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1376 RCCAR_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1377 RCCAR_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1378 RCCAR_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1379 RCCAR_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1380 RCCAR_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1381 RCCAR_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1382 RCCAR_ADDRESS_OFFSET, // address_offset: address offset
1383 RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN, // address_end: end of address
1384 RCCAR_COMMAND_OFFSET, // command_offset: command offset
1385 RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN, // command_end: end of command
1386 RCCAR_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1387 RCCAR_STOP_BIT, // stop_bit: flag: frame has stop bit
1388 RCCAR_LSB, // lsb_first: flag: LSB first
1389 RCCAR_FLAGS // flags: some flags
1390 };
1391
1392 #endif
1393
1394 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1395
1396 static const PROGMEM IRMP_PARAMETER nikon_param =
1397 {
1398 IRMP_NIKON_PROTOCOL, // protocol: ir protocol
1399 NIKON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1400 NIKON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1401 NIKON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1402 NIKON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1403 NIKON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1404 NIKON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1405 NIKON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1406 NIKON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1407 NIKON_ADDRESS_OFFSET, // address_offset: address offset
1408 NIKON_ADDRESS_OFFSET + NIKON_ADDRESS_LEN, // address_end: end of address
1409 NIKON_COMMAND_OFFSET, // command_offset: command offset
1410 NIKON_COMMAND_OFFSET + NIKON_COMMAND_LEN, // command_end: end of command
1411 NIKON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1412 NIKON_STOP_BIT, // stop_bit: flag: frame has stop bit
1413 NIKON_LSB, // lsb_first: flag: LSB first
1414 NIKON_FLAGS // flags: some flags
1415 };
1416
1417 #endif
1418
1419 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
1420
1421 static const PROGMEM IRMP_PARAMETER kathrein_param =
1422 {
1423 IRMP_KATHREIN_PROTOCOL, // protocol: ir protocol
1424 KATHREIN_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1425 KATHREIN_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1426 KATHREIN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1427 KATHREIN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1428 KATHREIN_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1429 KATHREIN_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1430 KATHREIN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1431 KATHREIN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1432 KATHREIN_ADDRESS_OFFSET, // address_offset: address offset
1433 KATHREIN_ADDRESS_OFFSET + KATHREIN_ADDRESS_LEN, // address_end: end of address
1434 KATHREIN_COMMAND_OFFSET, // command_offset: command offset
1435 KATHREIN_COMMAND_OFFSET + KATHREIN_COMMAND_LEN, // command_end: end of command
1436 KATHREIN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1437 KATHREIN_STOP_BIT, // stop_bit: flag: frame has stop bit
1438 KATHREIN_LSB, // lsb_first: flag: LSB first
1439 KATHREIN_FLAGS // flags: some flags
1440 };
1441
1442 #endif
1443
1444 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
1445
1446 static const PROGMEM IRMP_PARAMETER netbox_param =
1447 {
1448 IRMP_NETBOX_PROTOCOL, // protocol: ir protocol
1449 NETBOX_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value
1450 NETBOX_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value
1451 NETBOX_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1, here: exact value
1452 NETBOX_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1, here: rest value
1453 NETBOX_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value
1454 NETBOX_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value
1455 NETBOX_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0, here: exact value
1456 NETBOX_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0, here: rest value
1457 NETBOX_ADDRESS_OFFSET, // address_offset: address offset
1458 NETBOX_ADDRESS_OFFSET + NETBOX_ADDRESS_LEN, // address_end: end of address
1459 NETBOX_COMMAND_OFFSET, // command_offset: command offset
1460 NETBOX_COMMAND_OFFSET + NETBOX_COMMAND_LEN, // command_end: end of command
1461 NETBOX_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1462 NETBOX_STOP_BIT, // stop_bit: flag: frame has stop bit
1463 NETBOX_LSB, // lsb_first: flag: LSB first
1464 NETBOX_FLAGS // flags: some flags
1465 };
1466
1467 #endif
1468
1469 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
1470
1471 static const PROGMEM IRMP_PARAMETER lego_param =
1472 {
1473 IRMP_LEGO_PROTOCOL, // protocol: ir protocol
1474 LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1475 LEGO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1476 LEGO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1477 LEGO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1478 LEGO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1479 LEGO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1480 LEGO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1481 LEGO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1482 LEGO_ADDRESS_OFFSET, // address_offset: address offset
1483 LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN, // address_end: end of address
1484 LEGO_COMMAND_OFFSET, // command_offset: command offset
1485 LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN, // command_end: end of command
1486 LEGO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1487 LEGO_STOP_BIT, // stop_bit: flag: frame has stop bit
1488 LEGO_LSB, // lsb_first: flag: LSB first
1489 LEGO_FLAGS // flags: some flags
1490 };
1491
1492 #endif
1493
1494 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
1495
1496 static const PROGMEM IRMP_PARAMETER thomson_param =
1497 {
1498 IRMP_THOMSON_PROTOCOL, // protocol: ir protocol
1499 THOMSON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1500 THOMSON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1501 THOMSON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1502 THOMSON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1503 THOMSON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1504 THOMSON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1505 THOMSON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1506 THOMSON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1507 THOMSON_ADDRESS_OFFSET, // address_offset: address offset
1508 THOMSON_ADDRESS_OFFSET + THOMSON_ADDRESS_LEN, // address_end: end of address
1509 THOMSON_COMMAND_OFFSET, // command_offset: command offset
1510 THOMSON_COMMAND_OFFSET + THOMSON_COMMAND_LEN, // command_end: end of command
1511 THOMSON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1512 THOMSON_STOP_BIT, // stop_bit: flag: frame has stop bit
1513 THOMSON_LSB, // lsb_first: flag: LSB first
1514 THOMSON_FLAGS // flags: some flags
1515 };
1516
1517 #endif
1518
1519 static uint8_t irmp_bit; // current bit position
1520 static IRMP_PARAMETER irmp_param;
1521
1522 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1523 static IRMP_PARAMETER irmp_param2;
1524 #endif
1525
1526 static volatile uint8_t irmp_ir_detected;
1527 static volatile uint8_t irmp_protocol;
1528 static volatile uint16_t irmp_address;
1529 static volatile uint16_t irmp_command;
1530 static volatile uint16_t irmp_id; // only used for SAMSUNG protocol
1531 static volatile uint8_t irmp_flags;
1532 // static volatile uint8_t irmp_busy_flag;
1533
1534 #ifdef ANALYZE
1535 static uint8_t IRMP_PIN;
1536 #endif
1537
1538 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1539 * Initialize IRMP decoder
1540 * @details Configures IRMP input pin
1541 *---------------------------------------------------------------------------------------------------------------------------------------------------
1542 */
1543 #ifndef ANALYZE
1544 void
1545 irmp_init (void)
1546 {
1547 #if !defined(PIC_CCS_COMPILER) && !defined(PIC_C18) // only AVR
1548 IRMP_PORT &= ~(1<<IRMP_BIT); // deactivate pullup
1549 IRMP_DDR &= ~(1<<IRMP_BIT); // set pin to input
1550 #endif
1551
1552 #if IRMP_LOGGING == 1
1553 irmp_uart_init ();
1554 #endif
1555 }
1556 #endif
1557 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1558 * Get IRMP data
1559 * @details gets decoded IRMP data
1560 * @param pointer in order to store IRMP data
1561 * @return TRUE: successful, FALSE: failed
1562 *---------------------------------------------------------------------------------------------------------------------------------------------------
1563 */
1564 uint8_t
1565 irmp_get_data (IRMP_DATA * irmp_data_p)
1566 {
1567 uint8_t rtc = FALSE;
1568
1569 if (irmp_ir_detected)
1570 {
1571 switch (irmp_protocol)
1572 {
1573 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1574 case IRMP_SAMSUNG_PROTOCOL:
1575 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1576 {
1577 irmp_command &= 0xff;
1578 irmp_command |= irmp_id << 8;
1579 rtc = TRUE;
1580 }
1581 break;
1582 #endif
1583 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1584 case IRMP_NEC_PROTOCOL:
1585 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1586 {
1587 irmp_command &= 0xff;
1588 rtc = TRUE;
1589 }
1590 else if (irmp_address == 0x87EE)
1591 {
1592 ANALYZE_PRINTF ("Switching to APPLE protocol\n");
1593 irmp_protocol = IRMP_APPLE_PROTOCOL;
1594 irmp_address = (irmp_command & 0xFF00) >> 8;
1595 irmp_command &= 0x00FF;
1596 rtc = TRUE;
1597 }
1598 break;
1599 #endif
1600 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
1601 case IRMP_SIEMENS_PROTOCOL:
1602 case IRMP_RUWIDO_PROTOCOL:
1603 if (((irmp_command >> 1) & 0x0001) == (~irmp_command & 0x0001))
1604 {
1605 irmp_command >>= 1;
1606 rtc = TRUE;
1607 }
1608 break;
1609 #endif
1610 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
1611 case IRMP_KATHREIN_PROTOCOL:
1612 if (irmp_command != 0x0000)
1613 {
1614 rtc = TRUE;
1615 }
1616 break;
1617 #endif
1618 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1619 case IRMP_RC5_PROTOCOL:
1620 irmp_address &= ~0x20; // clear toggle bit
1621 rtc = TRUE;
1622 break;
1623 #endif
1624 #if IRMP_SUPPORT_IR60_PROTOCOL == 1
1625 case IRMP_IR60_PROTOCOL:
1626 if (irmp_command != 0x007d) // 0x007d (== 62<<1 + 1) is start instruction frame
1627 {
1628 rtc = TRUE;
1629 }
1630 break;
1631 #endif
1632 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1633 case IRMP_RCCAR_PROTOCOL:
1634 // frame in irmp_data:
1635 // Bit 12 11 10 9 8 7 6 5 4 3 2 1 0
1636 // V D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0 // 10 9 8 7 6 5 4 3 2 1 0
1637 irmp_address = (irmp_command & 0x000C) >> 2; // addr: 0 0 0 0 0 0 0 0 0 A1 A0
1638 irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit: V 0 0 0 0 0 0 0 0 0 0
1639 ((irmp_command & 0x0003) << 8) | // C-Bits: 0 C1 C0 0 0 0 0 0 0 0 0
1640 ((irmp_command & 0x0FF0) >> 4); // D-Bits: D7 D6 D5 D4 D3 D2 D1 D0
1641 rtc = TRUE; // Summe: V C1 C0 D7 D6 D5 D4 D3 D2 D1 D0
1642 break;
1643 #endif
1644
1645 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 // squeeze code to 8 bit, upper bit indicates release-key
1646 case IRMP_NETBOX_PROTOCOL:
1647 if (irmp_command & 0x1000) // last bit set?
1648 {
1649 if ((irmp_command & 0x1f) == 0x15) // key pressed: 101 01 (LSB)
1650 {
1651 irmp_command >>= 5;
1652 irmp_command &= 0x7F;
1653 rtc = TRUE;
1654 }
1655 else if ((irmp_command & 0x1f) == 0x10) // key released: 000 01 (LSB)
1656 {
1657 irmp_command >>= 5;
1658 irmp_command |= 0x80;
1659 rtc = TRUE;
1660 }
1661 else
1662 {
1663 ANALYZE_PRINTF("error NETBOX: bit6/7 must be 0/1\n");
1664 }
1665 }
1666 else
1667 {
1668 ANALYZE_PRINTF("error NETBOX: last bit not set\n");
1669 }
1670 break;
1671 #endif
1672 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
1673 case IRMP_LEGO_PROTOCOL:
1674 {
1675 uint8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4);
1676
1677 if ((irmp_command & 0x000F) == crc)
1678 {
1679 irmp_command >>= 4;
1680 rtc = TRUE;
1681 }
1682 else
1683 {
1684 ANALYZE_PRINTF ("CRC error in LEGO protocol\n");
1685 rtc = TRUE;
1686 }
1687 break;
1688 }
1689 #endif
1690 default:
1691 rtc = TRUE;
1692 }
1693
1694 if (rtc)
1695 {
1696 irmp_data_p->protocol = irmp_protocol;
1697 irmp_data_p->address = irmp_address;
1698 irmp_data_p->command = irmp_command;
1699 irmp_data_p->flags = irmp_flags;
1700 irmp_command = 0;
1701 irmp_address = 0;
1702 irmp_flags = 0;
1703 }
1704
1705 irmp_ir_detected = FALSE;
1706 }
1707
1708 return rtc;
1709 }
1710
1711 // uint8_t
1712 // irmp_is_busy (void)
1713 // {
1714 // return irmp_busy_flag;
1715 // }
1716
1717 #if IRMP_USE_CALLBACK == 1
1718 void
1719 irmp_set_callback_ptr (void (*cb)(uint8_t))
1720 {
1721 irmp_callback_ptr = cb;
1722 }
1723 #endif // IRMP_USE_CALLBACK == 1
1724
1725 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1726 static uint16_t irmp_tmp_address; // ir address
1727 static uint16_t irmp_tmp_command; // ir command
1728
1729 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
1730 static uint16_t irmp_tmp_address2; // ir address
1731 static uint16_t irmp_tmp_command2; // ir command
1732 #endif
1733
1734 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1735 static uint16_t irmp_tmp_id; // ir id (only SAMSUNG)
1736 #endif
1737 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1738 static uint8_t xor_check[6]; // check kaseikyo "parity" bits
1739 #endif
1740
1741 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1742 * store bit
1743 * @details store bit in temp address or temp command
1744 * @param value to store: 0 or 1
1745 *---------------------------------------------------------------------------------------------------------------------------------------------------
1746 */
1747 // verhindert, dass irmp_store_bit() inline compiliert wird:
1748 // static void irmp_store_bit (uint8_t) __attribute__ ((noinline));
1749
1750 static void
1751 irmp_store_bit (uint8_t value)
1752 {
1753 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
1754 if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL)
1755 {
1756 first_bit = value;
1757 }
1758 else
1759 #endif
1760
1761 if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end)
1762 {
1763 if (irmp_param.lsb_first)
1764 {
1765 irmp_tmp_address |= (((uint16_t) (value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast
1766 }
1767 else
1768 {
1769 irmp_tmp_address <<= 1;
1770 irmp_tmp_address |= value;
1771 }
1772 }
1773 else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end)
1774 {
1775 if (irmp_param.lsb_first)
1776 {
1777 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast
1778 }
1779 else
1780 {
1781 irmp_tmp_command <<= 1;
1782 irmp_tmp_command |= value;
1783 }
1784 }
1785
1786 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
1787 else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit >= 13 && irmp_bit < 26)
1788 {
1789 irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit - 13)); // CV wants cast
1790 }
1791 #endif
1792
1793 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1794 else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
1795 {
1796 irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first
1797 }
1798 #endif
1799
1800 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1801 else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit >= 20 && irmp_bit < 24)
1802 {
1803 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits in upper nibble with LSB first
1804 }
1805
1806 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit < KASEIKYO_COMPLETE_DATA_LEN)
1807 {
1808 if (value)
1809 {
1810 xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8);
1811 }
1812 else
1813 {
1814 xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8));
1815 }
1816 }
1817
1818 #endif
1819
1820 irmp_bit++;
1821 }
1822
1823 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1824 * store bit
1825 * @details store bit in temp address or temp command
1826 * @param value to store: 0 or 1
1827 *---------------------------------------------------------------------------------------------------------------------------------------------------
1828 */
1829 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1830 static void
1831 irmp_store_bit2 (uint8_t value)
1832 {
1833 uint8_t irmp_bit2;
1834
1835 if (irmp_param.protocol)
1836 {
1837 irmp_bit2 = irmp_bit - 2;
1838 }
1839 else
1840 {
1841 irmp_bit2 = irmp_bit - 1;
1842 }
1843
1844 if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end)
1845 {
1846 irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.address_offset)); // CV wants cast
1847 }
1848 else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end)
1849 {
1850 irmp_tmp_command2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.command_offset)); // CV wants cast
1851 }
1852 }
1853 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1854
1855 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1856 * ISR routine
1857 * @details ISR routine, called 10000 times per second
1858 *---------------------------------------------------------------------------------------------------------------------------------------------------
1859 */
1860 uint8_t
1861 irmp_ISR (void)
1862 {
1863 static uint8_t irmp_start_bit_detected; // flag: start bit detected
1864 static uint8_t wait_for_space; // flag: wait for data bit space
1865 static uint8_t wait_for_start_space; // flag: wait for start bit space
1866 static uint8_t irmp_pulse_time; // count bit time for pulse
1867 static PAUSE_LEN irmp_pause_time; // count bit time for pause
1868 static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition
1869 static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition
1870 static uint16_t repetition_len; // SIRCS repeats frame 2-5 times with 45 ms pause
1871 static uint8_t repetition_frame_number;
1872 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1873 static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition
1874 #endif
1875 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1876 static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit
1877 #endif
1878 #if IRMP_SUPPORT_MANCHESTER == 1
1879 static PAUSE_LEN last_pause; // last pause value
1880 #endif
1881 #if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1882 static uint8_t last_value; // last bit value
1883 #endif
1884 uint8_t irmp_input; // input value
1885
1886 #ifdef ANALYZE
1887 time_counter++;
1888 #endif
1889
1890 irmp_input = input(IRMP_PIN);
1891
1892 #if IRMP_USE_CALLBACK == 1
1893 if (irmp_callback_ptr)
1894 {
1895 static uint8_t last_inverted_input;
1896
1897 if (last_inverted_input != !irmp_input)
1898 {
1899 (*irmp_callback_ptr) (! irmp_input);
1900 last_inverted_input = !irmp_input;
1901 }
1902 }
1903 #endif // IRMP_USE_CALLBACK == 1
1904
1905 irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined
1906
1907 if (! irmp_ir_detected) // ir code already detected?
1908 { // no...
1909 if (! irmp_start_bit_detected) // start bit detected?
1910 { // no...
1911 if (! irmp_input) // receiving burst?
1912 { // yes...
1913 // irmp_busy_flag = TRUE;
1914 #ifdef ANALYZE
1915 if (! irmp_pulse_time)
1916 {
1917 ANALYZE_PRINTF("%8d [starting pulse]\n", time_counter);
1918 }
1919 #endif
1920 irmp_pulse_time++; // increment counter
1921 }
1922 else
1923 { // no...
1924 if (irmp_pulse_time) // it's dark....
1925 { // set flags for counting the time of darkness...
1926 irmp_start_bit_detected = 1;
1927 wait_for_start_space = 1;
1928 wait_for_space = 0;
1929 irmp_tmp_command = 0;
1930 irmp_tmp_address = 0;
1931
1932 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1
1933 irmp_tmp_command2 = 0;
1934 irmp_tmp_address2 = 0;
1935 #endif
1936
1937 irmp_bit = 0xff;
1938 irmp_pause_time = 1; // 1st pause: set to 1, not to 0!
1939 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1940 rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1941 #endif
1942 }
1943 else
1944 {
1945 if (repetition_len < 0xFFFF) // avoid overflow of counter
1946 {
1947 repetition_len++;
1948 }
1949 }
1950 }
1951 }
1952 else
1953 {
1954 if (wait_for_start_space) // we have received start bit...
1955 { // ...and are counting the time of darkness
1956 if (irmp_input) // still dark?
1957 { // yes
1958 irmp_pause_time++; // increment counter
1959
1960 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1961 if (((irmp_pulse_time < NIKON_START_BIT_PULSE_LEN_MIN || irmp_pulse_time > NIKON_START_BIT_PULSE_LEN_MAX) && irmp_pause_time > IRMP_TIMEOUT_LEN) ||
1962 irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN)
1963 #else
1964 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1965 #endif
1966 { // yes...
1967 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1968 if (irmp_protocol == IRMP_JVC_PROTOCOL) // don't show eror if JVC protocol, irmp_pulse_time has been set below!
1969 {
1970 ;
1971 }
1972 else
1973 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1974 {
1975 ANALYZE_PRINTF ("%8d error 1: pause after start bit pulse %d too long: %d\n", time_counter, irmp_pulse_time, irmp_pause_time);
1976 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1977 }
1978 // irmp_busy_flag = FALSE;
1979 irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit
1980 irmp_pulse_time = 0;
1981 irmp_pause_time = 0;
1982 }
1983 }
1984 else
1985 { // receiving first data pulse!
1986 IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0;
1987
1988 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1989 irmp_param2.protocol = 0;
1990 #endif
1991
1992 ANALYZE_PRINTF ("%8d [start-bit: pulse = %2d, pause = %2d]\n", time_counter, irmp_pulse_time, irmp_pause_time);
1993
1994 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1995 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
1996 irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
1997 { // it's SIRCS
1998 ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1999 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
2000 SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
2001 irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param;
2002 }
2003 else
2004 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2005
2006 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2007 if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame
2008 irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX &&
2009 irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX)
2010 {
2011 ANALYZE_PRINTF ("protocol = NEC or JVC (type 1) repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2012 JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX,
2013 JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX);
2014 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
2015 }
2016 else
2017 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2018
2019 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2020 if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
2021 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
2022 {
2023 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
2024 ANALYZE_PRINTF ("protocol = NEC42, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2025 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
2026 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
2027 irmp_param_p = (IRMP_PARAMETER *) &nec42_param;
2028 #else
2029 ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2030 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
2031 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
2032 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
2033 #endif
2034
2035 }
2036 else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
2037 irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
2038 { // it's NEC
2039 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2040 if (irmp_protocol == IRMP_JVC_PROTOCOL) // last protocol was JVC, awaiting repeat frame
2041 { // some jvc remote controls use nec repetition frame for jvc repetition frame
2042 ANALYZE_PRINTF ("protocol = JVC repeat frame type 2, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2043 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
2044 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
2045 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
2046 }
2047 else
2048 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2049 {
2050 ANALYZE_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2051 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
2052 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
2053
2054 irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
2055 }
2056 }
2057 else
2058
2059 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2060 if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame
2061 irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
2062 irmp_pause_time >= NEC_0_PAUSE_LEN_MIN && irmp_pause_time <= NEC_0_PAUSE_LEN_MAX)
2063 { // it's JVC repetition type 3
2064 ANALYZE_PRINTF ("protocol = JVC repeat frame type 3, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2065 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
2066 NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX);
2067 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
2068 }
2069 else
2070 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2071
2072 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
2073
2074 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
2075 if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX &&
2076 irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX)
2077 {
2078 ANALYZE_PRINTF ("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2079 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX,
2080 NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX);
2081 irmp_param_p = (IRMP_PARAMETER *) &nikon_param;
2082 }
2083 else
2084 #endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1
2085
2086 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2087 if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
2088 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
2089 { // it's SAMSUNG
2090 ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2091 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
2092 SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
2093 irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
2094 }
2095 else
2096 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2097
2098 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
2099 if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
2100 irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
2101 { // it's MATSUSHITA
2102 ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2103 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
2104 MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
2105 irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
2106 }
2107 else
2108 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
2109
2110 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
2111 if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
2112 irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
2113 { // it's KASEIKYO
2114 ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2115 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
2116 KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
2117 irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
2118 }
2119 else
2120 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
2121
2122 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
2123 if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
2124 irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
2125 { // it's RECS80
2126 ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2127 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
2128 RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
2129 irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
2130 }
2131 else
2132 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
2133
2134 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
2135 if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
2136 (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) &&
2137 ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
2138 (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)))
2139 { // it's RC5
2140 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
2141 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
2142 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
2143 {
2144 ANALYZE_PRINTF ("protocol = RC5 or FDC\n");
2145 ANALYZE_PRINTF ("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2146 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
2147 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2148 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2149 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2150 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
2151 memcpy_P (&irmp_param2, &fdc_param, sizeof (IRMP_PARAMETER));
2152 }
2153 else
2154 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2155
2156 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2157 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
2158 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
2159 {
2160 ANALYZE_PRINTF ("protocol = RC5 or RCCAR\n");
2161 ANALYZE_PRINTF ("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2162 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
2163 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
2164 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2165 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2166 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
2167 memcpy_P (&irmp_param2, &rccar_param, sizeof (IRMP_PARAMETER));
2168 }
2169 else
2170 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2171 {
2172 ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n",
2173 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2174 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX,
2175 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2176 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX);
2177 }
2178
2179 irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
2180 last_pause = irmp_pause_time;
2181
2182 if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) ||
2183 (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))
2184 {
2185 last_value = 0;
2186 rc5_cmd_bit6 = 1<<6;
2187 }
2188 else
2189 {
2190 last_value = 1;
2191 }
2192 }
2193 else
2194 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
2195
2196 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2197 if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
2198 ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
2199 (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
2200 { // it's DENON
2201 ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2202 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
2203 DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
2204 DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
2205 irmp_param_p = (IRMP_PARAMETER *) &denon_param;
2206 }
2207 else
2208 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
2209
2210 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2211 if ( (irmp_pulse_time >= THOMSON_PULSE_LEN_MIN && irmp_pulse_time <= THOMSON_PULSE_LEN_MAX) &&
2212 ((irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) ||
2213 (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)))
2214 { // it's THOMSON
2215 ANALYZE_PRINTF ("protocol = THOMSON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2216 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX,
2217 THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX,
2218 THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX);
2219 irmp_param_p = (IRMP_PARAMETER *) &thomson_param;
2220 }
2221 else
2222 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2223
2224 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2225 if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
2226 irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
2227 { // it's RC6
2228 ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2229 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
2230 RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
2231 irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
2232 last_pause = 0;
2233 last_value = 1;
2234 }
2235 else
2236 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2237
2238 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2239 if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
2240 irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
2241 { // it's RECS80EXT
2242 ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2243 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
2244 RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
2245 irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
2246 }
2247 else
2248 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2249
2250 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2251 if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
2252 irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
2253 { // it's NUBERT
2254 ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2255 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
2256 NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
2257 irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
2258 }
2259 else
2260 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2261
2262 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2263 if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
2264 irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
2265 { // it's BANG_OLUFSEN
2266 ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n");
2267 ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2268 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
2269 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
2270 ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2271 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
2272 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
2273 ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2274 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
2275 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
2276 ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2277 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
2278 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
2279 irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
2280 last_value = 0;
2281 }
2282 else
2283 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2284
2285 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2286 if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX &&
2287 irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX)
2288 { // it's GRUNDIG
2289 ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2290 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
2291 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX);
2292 irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
2293 last_pause = irmp_pause_time;
2294 last_value = 1;
2295 }
2296 else
2297 #endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2298
2299 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2300 if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) ||
2301 (irmp_pulse_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX)) &&
2302 ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) ||
2303 (irmp_pause_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX)))
2304 { // it's RUWIDO or SIEMENS
2305 ANALYZE_PRINTF ("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2306 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
2307 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
2308 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
2309 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX);
2310 irmp_param_p = (IRMP_PARAMETER *) &ruwido_param;
2311 last_pause = irmp_pause_time;
2312 last_value = 1;
2313 }
2314 else
2315 #endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2316
2317 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
2318 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
2319 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
2320 {
2321 ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2322 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
2323 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2324 irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
2325 }
2326 else
2327 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2328
2329 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2330 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
2331 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
2332 {
2333 ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2334 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
2335 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
2336 irmp_param_p = (IRMP_PARAMETER *) &rccar_param;
2337 }
2338 else
2339 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2340
2341 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2342 if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX &&
2343 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)
2344 { // it's KATHREIN
2345 ANALYZE_PRINTF ("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2346 KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX,
2347 KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX);
2348 irmp_param_p = (IRMP_PARAMETER *) &kathrein_param;
2349 }
2350 else
2351 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2352
2353 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2354 if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX &&
2355 irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX)
2356 { // it's NETBOX
2357 ANALYZE_PRINTF ("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2358 NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX,
2359 NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX);
2360 irmp_param_p = (IRMP_PARAMETER *) &netbox_param;
2361 }
2362 else
2363 #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2364
2365 #if IRMP_SUPPORT_LEGO_PROTOCOL == 1
2366 if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX &&
2367 irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX)
2368 {
2369 ANALYZE_PRINTF ("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2370 LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX,
2371 LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX);
2372 irmp_param_p = (IRMP_PARAMETER *) &lego_param;
2373 }
2374 else
2375 #endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1
2376
2377 {
2378 ANALYZE_PRINTF ("protocol = UNKNOWN\n");
2379 // irmp_busy_flag = FALSE;
2380 irmp_start_bit_detected = 0; // wait for another start bit...
2381 }
2382
2383 if (irmp_start_bit_detected)
2384 {
2385 memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
2386
2387 #ifdef ANALYZE
2388 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2389 {
2390 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
2391 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
2392 }
2393 else
2394 {
2395 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max,
2396 2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max);
2397 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max,
2398 2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max);
2399 }
2400
2401 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2402 if (irmp_param2.protocol)
2403 {
2404 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max);
2405 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max);
2406 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max);
2407 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max);
2408 }
2409 #endif
2410
2411
2412 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2413 if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
2414 {
2415 ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
2416 }
2417 #endif
2418
2419 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2420 {
2421 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2422 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
2423 }
2424 else
2425 {
2426 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max,
2427 2 * irmp_param.pulse_0_len_min, 2 * irmp_param.pulse_0_len_max);
2428 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max,
2429 2 * irmp_param.pause_0_len_min, 2 * irmp_param.pause_0_len_max);
2430 }
2431
2432 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2433 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2434 {
2435 ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2436 ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
2437 }
2438 #endif
2439
2440 ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
2441 ANALYZE_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset);
2442 ANALYZE_PRINTF ("complete_len: %3d\n", irmp_param.complete_len);
2443 ANALYZE_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit);
2444 #endif // ANALYZE
2445 }
2446
2447 irmp_bit = 0;
2448
2449 #if IRMP_SUPPORT_MANCHESTER == 1
2450 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2451 irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO
2452 irmp_param.protocol != IRMP_RC6_PROTOCOL) // Manchester, but not RC6
2453 {
2454 if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max)
2455 {
2456 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2457 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2458 ANALYZE_NEWLINE ();
2459 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1);
2460 }
2461 else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2462 {
2463 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2464
2465 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2466 ANALYZE_NEWLINE ();
2467 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0);
2468 }
2469 }
2470 else
2471 #endif // IRMP_SUPPORT_MANCHESTER == 1
2472
2473 #if IRMP_SUPPORT_SERIAL == 1
2474 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2475 {
2476 ; // do nothing
2477 }
2478 else
2479 #endif // IRMP_SUPPORT_SERIAL == 1
2480
2481
2482 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2483 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2484 {
2485 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2486
2487 if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
2488 { // pause timings correct for "1"?
2489 ANALYZE_PUTCHAR ('1'); // yes, store 1
2490 ANALYZE_NEWLINE ();
2491 irmp_store_bit (1);
2492 }
2493 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
2494 { // pause timings correct for "0"?
2495 ANALYZE_PUTCHAR ('0'); // yes, store 0
2496 ANALYZE_NEWLINE ();
2497 irmp_store_bit (0);
2498 }
2499 }
2500 else
2501 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
2502 #if IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2503 if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL)
2504 {
2505 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2506
2507 if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX)
2508 { // pause timings correct for "1"?
2509 ANALYZE_PUTCHAR ('1'); // yes, store 1
2510 ANALYZE_NEWLINE ();
2511 irmp_store_bit (1);
2512 }
2513 else // if (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX)
2514 { // pause timings correct for "0"?
2515 ANALYZE_PUTCHAR ('0'); // yes, store 0
2516 ANALYZE_NEWLINE ();
2517 irmp_store_bit (0);
2518 }
2519 }
2520 else
2521 #endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1
2522 {
2523 ; // else do nothing
2524 }
2525
2526 irmp_pulse_time = 1; // set counter to 1, not 0
2527 irmp_pause_time = 0;
2528 wait_for_start_space = 0;
2529 }
2530 }
2531 else if (wait_for_space) // the data section....
2532 { // counting the time of darkness....
2533 uint8_t got_light = FALSE;
2534
2535 if (irmp_input) // still dark?
2536 { // yes...
2537 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
2538 {
2539 if (
2540 #if IRMP_SUPPORT_MANCHESTER == 1
2541 (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) ||
2542 #endif
2543 #if IRMP_SUPPORT_SERIAL == 1
2544 (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) ||
2545 #endif
2546 (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max))
2547 {
2548 #ifdef ANALYZE
2549 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2550 {
2551 ANALYZE_PRINTF ("stop bit detected\n");
2552 }
2553 #endif
2554 irmp_param.stop_bit = 0;
2555 }
2556 else
2557 {
2558 ANALYZE_PRINTF ("error: stop bit timing wrong, irmp_bit = %d, irmp_pulse_time = %d, pulse_0_len_min = %d, pulse_0_len_max = %d\n",
2559 irmp_bit, irmp_pulse_time, irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2560
2561 // irmp_busy_flag = FALSE;
2562 irmp_start_bit_detected = 0; // wait for another start bit...
2563 irmp_pulse_time = 0;
2564 irmp_pause_time = 0;
2565 }
2566 }
2567 else
2568 {
2569 irmp_pause_time++; // increment counter
2570
2571 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2572 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits:
2573 irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12
2574 irmp_bit >= 12 - 1) // pause too long?
2575 { // yes, break and close this frame
2576 irmp_param.complete_len = irmp_bit + 1; // set new complete length
2577 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2578 irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8; // new: store number of additional bits in upper byte of address!
2579 irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length
2580 irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length
2581 }
2582 else
2583 #endif
2584 #if IRMP_SUPPORT_SERIAL == 1
2585 // NETBOX generates no stop bit, here is the timeout condition:
2586 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL &&
2587 irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit))
2588 {
2589 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2590 }
2591 else
2592 #endif
2593 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2594 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)
2595 {
2596 if (irmp_pause_time > IR60_TIMEOUT_LEN && irmp_bit == 6)
2597 {
2598 ANALYZE_PRINTF ("Switching to IR60 protocol\n");
2599 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2600 irmp_param.stop_bit = TRUE; // set flag
2601
2602 irmp_param.protocol = IRMP_IR60_PROTOCOL; // change protocol
2603 irmp_param.complete_len = IR60_COMPLETE_DATA_LEN; // correct complete len
2604 irmp_param.address_offset = IR60_ADDRESS_OFFSET;
2605 irmp_param.address_end = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN;
2606 irmp_param.command_offset = IR60_COMMAND_OFFSET;
2607 irmp_param.command_end = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN;
2608
2609 irmp_tmp_command <<= 1;
2610 irmp_tmp_command |= first_bit;
2611 }
2612 else if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2)
2613 { // special manchester decoder
2614 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len
2615 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2616 irmp_param.stop_bit = TRUE; // set flag
2617 }
2618 else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
2619 {
2620 ANALYZE_PRINTF ("Switching to NOKIA protocol\n");
2621 irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol
2622 irmp_param.address_offset = NOKIA_ADDRESS_OFFSET;
2623 irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
2624 irmp_param.command_offset = NOKIA_COMMAND_OFFSET;
2625 irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
2626
2627 if (irmp_tmp_command & 0x300)
2628 {
2629 irmp_tmp_address = (irmp_tmp_command >> 8);
2630 irmp_tmp_command &= 0xFF;
2631 }
2632 }
2633 }
2634 else
2635 #endif
2636 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2637 if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit)
2638 {
2639 if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2)
2640 { // special manchester decoder
2641 irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN; // correct complete len
2642 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2643 irmp_param.stop_bit = TRUE; // set flag
2644 }
2645 else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN)
2646 {
2647 ANALYZE_PRINTF ("Switching to SIEMENS protocol\n");
2648 irmp_param.protocol = IRMP_SIEMENS_PROTOCOL; // change protocol
2649 irmp_param.address_offset = SIEMENS_ADDRESS_OFFSET;
2650 irmp_param.address_end = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN;
2651 irmp_param.command_offset = SIEMENS_COMMAND_OFFSET;
2652 irmp_param.command_end = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN;
2653
2654 // 76543210
2655 // RUWIDO: AAAAAAAAACCCCCCCp
2656 // SIEMENS: AAAAAAAAAAACCCCCCCCCCp
2657 irmp_tmp_address <<= 2;
2658 irmp_tmp_address |= (irmp_tmp_command >> 6);
2659 irmp_tmp_command &= 0x003F;
2660 irmp_tmp_command <<= 4;
2661 irmp_tmp_command |= last_value;
2662 }
2663 }
2664 else
2665 #endif
2666 #if IRMP_SUPPORT_MANCHESTER == 1
2667 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2668 irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
2669 { // special manchester decoder
2670 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2671 irmp_param.stop_bit = TRUE; // set flag
2672 }
2673 else
2674 #endif // IRMP_SUPPORT_MANCHESTER == 1
2675 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
2676 { // yes...
2677 if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
2678 {
2679 irmp_bit++;
2680 }
2681 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2682 else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit
2683 {
2684 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
2685 irmp_param.stop_bit = TRUE; // set flag
2686 irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol
2687 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2688 irmp_tmp_command = (irmp_tmp_address >> 4); // set command: upper 12 bits are command bits
2689 irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits
2690 irmp_start_bit_detected = 1; // tricky: don't wait for another start bit...
2691 }
2692 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2693
2694 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
2695 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2696 else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 32) // it was a NEC stop bit
2697 {
2698 ANALYZE_PRINTF ("Switching to NEC protocol\n");
2699 irmp_param.stop_bit = TRUE; // set flag
2700 irmp_param.protocol = IRMP_NEC_PROTOCOL; // switch protocol
2701 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2702
2703 // 0123456789ABC0123456789ABC0123456701234567
2704 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
2705 // NEC: AAAAAAAAaaaaaaaaCCCCCCCCcccccccc
2706 irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 12;
2707 irmp_tmp_command = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10);
2708 }
2709 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
2710 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2711 else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit
2712 {
2713 ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit);
2714 irmp_param.stop_bit = TRUE; // set flag
2715 irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol
2716 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2717
2718 // 0123456789ABC0123456789ABC0123456701234567
2719 // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc
2720 // JVC: AAAACCCCCCCCCCCC
2721 irmp_tmp_command = (irmp_tmp_address >> 4) | (irmp_tmp_address2 << 9); // set command: upper 12 bits are command bits
2722 irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits
2723 }
2724 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2725 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
2726 else
2727 {
2728 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
2729 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2730
2731 // irmp_busy_flag = FALSE;
2732 irmp_start_bit_detected = 0; // wait for another start bit...
2733 irmp_pulse_time = 0;
2734 irmp_pause_time = 0;
2735 }
2736 }
2737 }
2738 }
2739 else
2740 { // got light now!
2741 got_light = TRUE;
2742 }
2743
2744 if (got_light)
2745 {
2746 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2747
2748 #if IRMP_SUPPORT_MANCHESTER == 1
2749 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester
2750 {
2751 #if 1
2752 if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max */)
2753 #else // better, but some IR-RCs use asymmetric timings :-/
2754 if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max &&
2755 irmp_pause_time <= 2 * irmp_param.pause_1_len_max)
2756 #endif
2757 {
2758 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2759 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2760 {
2761 ANALYZE_PUTCHAR ('T');
2762 if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode 6A
2763 {
2764 irmp_store_bit (1);
2765 last_value = 1;
2766 }
2767 else // RC6 mode 0
2768 {
2769 irmp_store_bit (0);
2770 last_value = 0;
2771 }
2772 ANALYZE_NEWLINE ();
2773 }
2774 else
2775 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2776 {
2777 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2778 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1 );
2779
2780 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2781 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2782 {
2783 ANALYZE_PUTCHAR ('T');
2784 irmp_store_bit (1);
2785
2786 if (irmp_pause_time > 2 * irmp_param.pause_1_len_max)
2787 {
2788 last_value = 0;
2789 }
2790 else
2791 {
2792 last_value = 1;
2793 }
2794 ANALYZE_NEWLINE ();
2795 }
2796 else
2797 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2798 {
2799 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2800 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0 );
2801 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2802 if (! irmp_param2.protocol)
2803 #endif
2804 {
2805 ANALYZE_NEWLINE ();
2806 }
2807 last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0;
2808 }
2809 }
2810 }
2811 else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max
2812 /* && irmp_pause_time <= 2 * irmp_param.pause_1_len_max */)
2813 {
2814 uint8_t manchester_value;
2815
2816 if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max)
2817 {
2818 manchester_value = last_value ? 0 : 1;
2819 last_value = manchester_value;
2820 }
2821 else
2822 {
2823 manchester_value = last_value;
2824 }
2825
2826 ANALYZE_PUTCHAR (manchester_value + '0');
2827
2828 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2829 if (! irmp_param2.protocol)
2830 #endif
2831 {
2832 ANALYZE_NEWLINE ();
2833 }
2834
2835 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2836 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1) // RC6 mode != 0 ???
2837 {
2838 ANALYZE_PRINTF ("Switching to RC6A protocol\n");
2839 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
2840 irmp_param.address_offset = 5;
2841 irmp_param.address_end = irmp_param.address_offset + 15;
2842 irmp_param.command_offset = irmp_param.address_end + 1; // skip 1 system bit, changes like a toggle bit
2843 irmp_param.command_end = irmp_param.command_offset + 16 - 1;
2844 irmp_tmp_address = 0;
2845 }
2846 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2847
2848 irmp_store_bit (manchester_value);
2849 }
2850 else
2851 {
2852 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2853 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL &&
2854 irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX &&
2855 ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) ||
2856 (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)))
2857 {
2858 ANALYZE_PUTCHAR ('?');
2859 irmp_param.protocol = 0; // switch to FDC, see below
2860 }
2861 else
2862 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2863 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2864 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL &&
2865 irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX &&
2866 ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) ||
2867 (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)))
2868 {
2869 ANALYZE_PUTCHAR ('?');
2870 irmp_param.protocol = 0; // switch to RCCAR, see below
2871 }
2872 else
2873 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2874 {
2875 ANALYZE_PUTCHAR ('?');
2876 ANALYZE_NEWLINE ();
2877 ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2878 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2879 // irmp_busy_flag = FALSE;
2880 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2881 irmp_pause_time = 0;
2882 }
2883 }
2884
2885 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2886 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX)
2887 {
2888 if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX)
2889 {
2890 ANALYZE_PRINTF (" 1 (FDC)\n");
2891 irmp_store_bit2 (1);
2892 }
2893 else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)
2894 {
2895 ANALYZE_PRINTF (" 0 (FDC)\n");
2896 irmp_store_bit2 (0);
2897 }
2898
2899 if (! irmp_param.protocol)
2900 {
2901 ANALYZE_PRINTF ("Switching to FDC protocol\n");
2902 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2903 irmp_param2.protocol = 0;
2904 irmp_tmp_address = irmp_tmp_address2;
2905 irmp_tmp_command = irmp_tmp_command2;
2906 }
2907 }
2908 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2909 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2910 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX)
2911 {
2912 if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX)
2913 {
2914 ANALYZE_PRINTF (" 1 (RCCAR)\n");
2915 irmp_store_bit2 (1);
2916 }
2917 else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)
2918 {
2919 ANALYZE_PRINTF (" 0 (RCCAR)\n");
2920 irmp_store_bit2 (0);
2921 }
2922
2923 if (! irmp_param.protocol)
2924 {
2925 ANALYZE_PRINTF ("Switching to RCCAR protocol\n");
2926 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2927 irmp_param2.protocol = 0;
2928 irmp_tmp_address = irmp_tmp_address2;
2929 irmp_tmp_command = irmp_tmp_command2;
2930 }
2931 }
2932 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2933
2934 last_pause = irmp_pause_time;
2935 wait_for_space = 0;
2936 }
2937 else
2938 #endif // IRMP_SUPPORT_MANCHESTER == 1
2939
2940 #if IRMP_SUPPORT_SERIAL == 1
2941 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2942 {
2943 while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max)
2944 {
2945 ANALYZE_PUTCHAR ('1');
2946 irmp_store_bit (1);
2947
2948 if (irmp_pulse_time >= irmp_param.pulse_1_len_min)
2949 {
2950 irmp_pulse_time -= irmp_param.pulse_1_len_min;
2951 }
2952 else
2953 {
2954 irmp_pulse_time = 0;
2955 }
2956 }
2957
2958 while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max)
2959 {
2960 ANALYZE_PUTCHAR ('0');
2961 irmp_store_bit (0);
2962
2963 if (irmp_pause_time >= irmp_param.pause_1_len_min)
2964 {
2965 irmp_pause_time -= irmp_param.pause_1_len_min;
2966 }
2967 else
2968 {
2969 irmp_pause_time = 0;
2970 }
2971 }
2972 ANALYZE_NEWLINE ();
2973 wait_for_space = 0;
2974 }
2975 else
2976 #endif // IRMP_SUPPORT_SERIAL == 1
2977
2978 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2979 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit
2980 {
2981 if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
2982 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
2983 {
2984 ANALYZE_PRINTF ("SYNC\n");
2985 wait_for_space = 0;
2986 irmp_tmp_id = 0;
2987 irmp_bit++;
2988 }
2989 else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
2990 {
2991 irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;
2992 irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;
2993 irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
2994 irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;
2995
2996 if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
2997 {
2998 ANALYZE_PUTCHAR ('1');
2999 ANALYZE_NEWLINE ();
3000 irmp_store_bit (1);
3001 wait_for_space = 0;
3002 }
3003 else
3004 {
3005 ANALYZE_PUTCHAR ('0');
3006 ANALYZE_NEWLINE ();
3007 irmp_store_bit (0);
3008 wait_for_space = 0;
3009 }
3010
3011 ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");
3012 }
3013 else
3014 { // timing incorrect!
3015 ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
3016 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3017 // irmp_busy_flag = FALSE;
3018 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3019 irmp_pause_time = 0;
3020 }
3021 }
3022 else
3023 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
3024
3025 #if IRMP_SUPPORT_NEC16_PROTOCOL
3026 #if IRMP_SUPPORT_NEC42_PROTOCOL == 1
3027 if (irmp_param.protocol == IRMP_NEC42_PROTOCOL &&
3028 #else // IRMP_SUPPORT_NEC_PROTOCOL instead
3029 if (irmp_param.protocol == IRMP_NEC_PROTOCOL &&
3030 #endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1
3031 irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
3032 {
3033 ANALYZE_PRINTF ("Switching to NEC16 protocol\n");
3034 irmp_param.protocol = IRMP_NEC16_PROTOCOL;
3035 irmp_param.address_offset = NEC16_ADDRESS_OFFSET;
3036 irmp_param.address_end = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN;
3037 irmp_param.command_offset = NEC16_COMMAND_OFFSET;
3038 irmp_param.command_end = NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN;
3039 irmp_param.complete_len = NEC16_COMPLETE_DATA_LEN;
3040 wait_for_space = 0;
3041 }
3042 else
3043 #endif // IRMP_SUPPORT_NEC16_PROTOCOL
3044
3045 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
3046 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
3047 {
3048 if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
3049 {
3050 if (irmp_bit == 1) // Bang & Olufsen: 3rd bit
3051 {
3052 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
3053 {
3054 ANALYZE_PRINTF ("3rd start bit\n");
3055 wait_for_space = 0;
3056 irmp_bit++;
3057 }
3058 else
3059 { // timing incorrect!
3060 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);
3061 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3062 // irmp_busy_flag = FALSE;
3063 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3064 irmp_pause_time = 0;
3065 }
3066 }
3067 else if (irmp_bit == 19) // Bang & Olufsen: trailer bit
3068 {
3069 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
3070 {
3071 ANALYZE_PRINTF ("trailer bit\n");
3072 wait_for_space = 0;
3073 irmp_bit++;
3074 }
3075 else
3076 { // timing incorrect!
3077 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);
3078 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3079 // irmp_busy_flag = FALSE;
3080 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3081 irmp_pause_time = 0;
3082 }
3083 }
3084 else
3085 {
3086 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
3087 { // pulse & pause timings correct for "1"?
3088 ANALYZE_PUTCHAR ('1');
3089 ANALYZE_NEWLINE ();
3090 irmp_store_bit (1);
3091 last_value = 1;
3092 wait_for_space = 0;
3093 }
3094 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
3095 { // pulse & pause timings correct for "0"?
3096 ANALYZE_PUTCHAR ('0');
3097 ANALYZE_NEWLINE ();
3098 irmp_store_bit (0);
3099 last_value = 0;
3100 wait_for_space = 0;
3101 }
3102 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
3103 {
3104 ANALYZE_PUTCHAR (last_value + '0');
3105 ANALYZE_NEWLINE ();
3106 irmp_store_bit (last_value);
3107 wait_for_space = 0;
3108 }
3109 else
3110 { // timing incorrect!
3111 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);
3112 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3113 // irmp_busy_flag = FALSE;
3114 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3115 irmp_pause_time = 0;
3116 }
3117 }
3118 }
3119 else
3120 { // timing incorrect!
3121 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);
3122 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3123 // irmp_busy_flag = FALSE;
3124 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3125 irmp_pause_time = 0;
3126 }
3127 }
3128 else
3129 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
3130
3131 if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
3132 irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
3133 { // pulse & pause timings correct for "1"?
3134 ANALYZE_PUTCHAR ('1');
3135 ANALYZE_NEWLINE ();
3136 irmp_store_bit (1);
3137 wait_for_space = 0;
3138 }
3139 else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
3140 irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
3141 { // pulse & pause timings correct for "0"?
3142 ANALYZE_PUTCHAR ('0');
3143 ANALYZE_NEWLINE ();
3144 irmp_store_bit (0);
3145 wait_for_space = 0;
3146 }
3147 else
3148 #if IRMP_SUPPORT_KATHREIN_PROTOCOL
3149
3150 if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL &&
3151 irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX &&
3152 (((irmp_bit == 8 || irmp_bit == 6) &&
3153 irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) ||
3154 (irmp_bit == 12 &&
3155 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)))
3156
3157 {
3158 if (irmp_bit == 8)
3159 {
3160 irmp_bit++;
3161 ANALYZE_PUTCHAR ('S');
3162 ANALYZE_NEWLINE ();
3163 irmp_tmp_command <<= 1;
3164 }
3165 else
3166 {
3167 ANALYZE_PUTCHAR ('S');
3168 ANALYZE_NEWLINE ();
3169 irmp_store_bit (1);
3170 }
3171 wait_for_space = 0;
3172 }
3173 else
3174 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL
3175 { // timing incorrect!
3176 ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
3177 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3178 // irmp_busy_flag = FALSE;
3179 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
3180 irmp_pause_time = 0;
3181 }
3182
3183 irmp_pulse_time = 1; // set counter to 1, not 0
3184 }
3185 }
3186 else
3187 { // counting the pulse length ...
3188 if (! irmp_input) // still light?
3189 { // yes...
3190 irmp_pulse_time++; // increment counter
3191 }
3192 else
3193 { // now it's dark!
3194 wait_for_space = 1; // let's count the time (see above)
3195 irmp_pause_time = 1; // set pause counter to 1, not 0
3196 }
3197 }
3198
3199 if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received?
3200 {
3201 if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN)
3202 {
3203 repetition_frame_number++;
3204 }
3205 else
3206 {
3207 repetition_frame_number = 0;
3208 }
3209
3210 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
3211 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
3212 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
3213 {
3214 ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3215 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3216 repetition_len = 0;
3217 }
3218 else
3219 #endif
3220
3221 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3222 // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame
3223 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1)
3224 {
3225 ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3226 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3227 repetition_len = 0;
3228 }
3229 else
3230 #endif
3231
3232 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3233 // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
3234 if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))
3235 {
3236 ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3237 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3238 repetition_len = 0;
3239 }
3240 else
3241 #endif
3242
3243 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
3244 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
3245 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
3246 {
3247 ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
3248 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
3249 repetition_len = 0;
3250 }
3251 else
3252 #endif
3253
3254 {
3255 ANALYZE_PRINTF ("%8d code detected, length = %d\n", time_counter, irmp_bit);
3256 irmp_ir_detected = TRUE;
3257
3258 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
3259 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
3260 { // check for repetition frame
3261 if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
3262 {
3263 irmp_tmp_command = last_irmp_denon_command; // use command received before!
3264
3265 irmp_protocol = irmp_param.protocol; // store protocol
3266 irmp_address = irmp_tmp_address; // store address
3267 irmp_command = irmp_tmp_command ; // store command
3268 }
3269 else
3270 {
3271 ANALYZE_PRINTF ("waiting for inverted command repetition\n");
3272 irmp_ir_detected = FALSE;
3273 last_irmp_denon_command = irmp_tmp_command;
3274 }
3275 }
3276 else
3277 #endif // IRMP_SUPPORT_DENON_PROTOCOL
3278
3279 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
3280 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
3281 { // Grundig start frame?
3282 ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
3283 irmp_ir_detected = FALSE;
3284 }
3285 else
3286 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
3287
3288 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
3289 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
3290 { // Nokia start frame?
3291 ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n");
3292 irmp_ir_detected = FALSE;
3293 }
3294 else
3295 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
3296 {
3297 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3298 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame
3299 {
3300 if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)
3301 {
3302 ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_len = %d\n", repetition_len);
3303 irmp_tmp_address = last_irmp_address; // address is last address
3304 irmp_tmp_command = last_irmp_command; // command is last command
3305 irmp_flags |= IRMP_FLAG_REPETITION;
3306 repetition_len = 0;
3307 }
3308 else
3309 {
3310 ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n",
3311 repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);
3312 irmp_ir_detected = FALSE;
3313 }
3314 }
3315 #endif // IRMP_SUPPORT_NEC_PROTOCOL
3316
3317 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3318 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
3319 {
3320 uint8_t xor;
3321 // ANALYZE_PRINTF ("0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
3322 // xor_check[0], xor_check[1], xor_check[2], xor_check[3], xor_check[4], xor_check[5]);
3323
3324 xor = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4);
3325
3326 if (xor != (xor_check[2] & 0x0F))
3327 {
3328 ANALYZE_PRINTF ("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor, xor_check[2] & 0x0F);
3329 irmp_ir_detected = FALSE;
3330 }
3331
3332 xor = xor_check[2] ^ xor_check[3] ^ xor_check[4];
3333
3334 if (xor != xor_check[5])
3335 {
3336 ANALYZE_PRINTF ("error 4: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor, xor_check[5]);
3337 irmp_ir_detected = FALSE;
3338 }
3339 }
3340 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3341
3342 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
3343 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode = 6?
3344 {
3345 irmp_protocol = IRMP_RC6A_PROTOCOL;
3346 }
3347 else
3348 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
3349
3350 irmp_protocol = irmp_param.protocol;
3351
3352 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
3353 if (irmp_param.protocol == IRMP_FDC_PROTOCOL)
3354 {
3355 if (irmp_tmp_command & 0x000F) // released key?
3356 {
3357 irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80; // yes, set bit 7
3358 }
3359 else
3360 {
3361 irmp_tmp_command >>= 4; // no, it's a pressed key
3362 }
3363 irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00; // 000000CCCCAAAAAA -> 0000CCCC00000000
3364 irmp_tmp_address &= 0x003F;
3365 }
3366 #endif
3367
3368 irmp_address = irmp_tmp_address; // store address
3369 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3370 if (irmp_param.protocol == IRMP_NEC_PROTOCOL)
3371 {
3372 last_irmp_address = irmp_tmp_address; // store as last address, too
3373 }
3374 #endif
3375
3376 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
3377 if (irmp_param.protocol == IRMP_RC5_PROTOCOL)
3378 {
3379 irmp_tmp_command |= rc5_cmd_bit6; // store bit 6
3380 }
3381 #endif
3382 irmp_command = irmp_tmp_command; // store command
3383
3384 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3385 irmp_id = irmp_tmp_id;
3386 #endif
3387 }
3388 }
3389
3390 if (irmp_ir_detected)
3391 {
3392 if (last_irmp_command == irmp_tmp_command &&
3393 last_irmp_address == irmp_tmp_address &&
3394 repetition_len < IRMP_KEY_REPETITION_LEN)
3395 {
3396 irmp_flags |= IRMP_FLAG_REPETITION;
3397 }
3398
3399 last_irmp_address = irmp_tmp_address; // store as last address, too
3400 last_irmp_command = irmp_tmp_command; // store as last command, too
3401
3402 repetition_len = 0;
3403 }
3404 else
3405 {
3406 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3407 }
3408
3409 // irmp_busy_flag = FALSE;
3410 irmp_start_bit_detected = 0; // and wait for next start bit
3411 irmp_tmp_command = 0;
3412 irmp_pulse_time = 0;
3413 irmp_pause_time = 0;
3414
3415 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3416 if (irmp_protocol == IRMP_JVC_PROTOCOL) // the stop bit of JVC frame is also start bit of next frame
3417 { // set pulse time here!
3418 irmp_pulse_time = ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME));
3419 }
3420 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3421 }
3422 }
3423 }
3424 return (irmp_ir_detected);
3425 }
3426
3427 #ifdef ANALYZE
3428
3429 /*---------------------------------------------------------------------------------------------------------------------------------------------------
3430 * main functions - for Unix/Linux + Windows only!
3431 *
3432 * AVR: see main.c!
3433 *
3434 * Compile it under linux with:
3435 * cc irmp.c -o irmp
3436 *
3437 * usage: ./irmp [-v|-s|-a|-l|-p] < file
3438 *
3439 * options:
3440 * -v verbose
3441 * -s silent
3442 * -a analyze
3443 * -l list pulse/pauses
3444 * -p print timings
3445 *---------------------------------------------------------------------------------------------------------------------------------------------------
3446 */
3447
3448 static void
3449 print_timings (void)
3450 {
3451 printf ("IRMP_TIMEOUT_LEN: %d [%d byte(s)]\n", IRMP_TIMEOUT_LEN, sizeof (PAUSE_LEN));
3452 printf ("IRMP_KEY_REPETITION_LEN %d\n", IRMP_KEY_REPETITION_LEN);
3453 puts ("");
3454 printf ("PROTOCOL S S-PULSE S-PAUSE PULSE-0 PAUSE-0 PULSE-1 PAUSE-1\n");
3455 printf ("====================================================================================\n");
3456 printf ("SIRCS 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3457 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX,
3458 SIRCS_0_PULSE_LEN_MIN, SIRCS_0_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX,
3459 SIRCS_1_PULSE_LEN_MIN, SIRCS_1_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX);
3460
3461 printf ("NEC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3462 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX,
3463 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3464 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3465
3466 printf ("NEC (rep) 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3467 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,
3468 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3469 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3470
3471 printf ("SAMSUNG 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3472 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX,
3473 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_0_PAUSE_LEN_MIN, SAMSUNG_0_PAUSE_LEN_MAX,
3474 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_1_PAUSE_LEN_MIN, SAMSUNG_1_PAUSE_LEN_MAX);
3475
3476 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3477 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX,
3478 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_0_PAUSE_LEN_MIN, MATSUSHITA_0_PAUSE_LEN_MAX,
3479 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_1_PAUSE_LEN_MIN, MATSUSHITA_1_PAUSE_LEN_MAX);
3480
3481 printf ("KASEIKYO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3482 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX,
3483 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_0_PAUSE_LEN_MIN, KASEIKYO_0_PAUSE_LEN_MAX,
3484 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_1_PAUSE_LEN_MIN, KASEIKYO_1_PAUSE_LEN_MAX);
3485
3486 printf ("RECS80 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3487 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX,
3488 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_0_PAUSE_LEN_MIN, RECS80_0_PAUSE_LEN_MAX,
3489 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_1_PAUSE_LEN_MIN, RECS80_1_PAUSE_LEN_MAX);
3490
3491 printf ("RC5 1 %3d - %3d %3d - %3d %3d - %3d\n",
3492 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3493 RC5_BIT_LEN_MIN, RC5_BIT_LEN_MAX);
3494
3495 printf ("DENON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3496 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
3497 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX,
3498 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX);
3499
3500 printf ("THOMSON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3501 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX,
3502 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX,
3503 THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX);
3504
3505 printf ("RC6 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3506 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX,
3507 RC6_BIT_PULSE_LEN_MIN, RC6_BIT_PULSE_LEN_MAX, RC6_BIT_PAUSE_LEN_MIN, RC6_BIT_PAUSE_LEN_MAX);
3508
3509 printf ("RECS80EXT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3510 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX,
3511 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_0_PAUSE_LEN_MIN, RECS80EXT_0_PAUSE_LEN_MAX,
3512 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_1_PAUSE_LEN_MIN, RECS80EXT_1_PAUSE_LEN_MAX);
3513
3514 printf ("NUBERT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3515 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX,
3516 NUBERT_0_PULSE_LEN_MIN, NUBERT_0_PULSE_LEN_MAX, NUBERT_0_PAUSE_LEN_MIN, NUBERT_0_PAUSE_LEN_MAX,
3517 NUBERT_1_PULSE_LEN_MIN, NUBERT_1_PULSE_LEN_MAX, NUBERT_1_PAUSE_LEN_MIN, NUBERT_1_PAUSE_LEN_MAX);
3518
3519 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
3520 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
3521 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
3522
3523 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
3524 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
3525 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
3526
3527 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
3528 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
3529 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
3530
3531 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
3532 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
3533 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
3534
3535 printf ("BANG_OLUFSEN - %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3536 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_0_PAUSE_LEN_MIN, BANG_OLUFSEN_0_PAUSE_LEN_MAX,
3537 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_1_PAUSE_LEN_MIN, BANG_OLUFSEN_1_PAUSE_LEN_MAX);
3538
3539 printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d %3d - %3d\n",
3540 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
3541 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX,
3542 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_BIT_LEN_MAX);
3543
3544 printf ("SIEMENS/RUWIDO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3545 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
3546 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
3547 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,
3548 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX,
3549 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,
3550 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX);
3551
3552 printf ("FDC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3553 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX,
3554 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_0_PAUSE_LEN_MIN, FDC_0_PAUSE_LEN_MAX,
3555 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_1_PAUSE_LEN_MIN, FDC_1_PAUSE_LEN_MAX);
3556
3557 printf ("RCCAR 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3558 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX,
3559 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_0_PAUSE_LEN_MIN, RCCAR_0_PAUSE_LEN_MAX,
3560 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_1_PAUSE_LEN_MIN, RCCAR_1_PAUSE_LEN_MAX);
3561
3562 printf ("NIKON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3563 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX,
3564 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX,
3565 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX);
3566
3567 printf ("LEGO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3568 LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX,
3569 LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_0_PAUSE_LEN_MIN, LEGO_0_PAUSE_LEN_MAX,
3570 LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_1_PAUSE_LEN_MIN, LEGO_1_PAUSE_LEN_MAX);
3571
3572 }
3573
3574 void
3575 print_spectrum (char * text, int * buf, int is_pulse)
3576 {
3577 int i;
3578 int j;
3579 int min;
3580 int max;
3581 int max_value = 0;
3582 int value;
3583 int sum = 0;
3584 int counter = 0;
3585 double average = 0;
3586 double tolerance;
3587
3588 puts ("-------------------------------------------------------------------------------");
3589 printf ("%s:\n", text);
3590
3591 for (i = 0; i < 256; i++)
3592 {
3593 if (buf[i] > max_value)
3594 {
3595 max_value = buf[i];
3596 }
3597 }
3598
3599 for (i = 1; i < 100; i++)
3600 {
3601 if (buf[i] > 0)
3602 {
3603 printf ("%3d ", i);
3604 value = (buf[i] * 60) / max_value;
3605
3606 for (j = 0; j < value; j++)
3607 {
3608 putchar ('o');
3609 }
3610 printf (" %d\n", buf[i]);
3611
3612 sum += i * buf[i];
3613 counter += buf[i];
3614 }
3615 else
3616 {
3617 max = i - 1;
3618
3619 if (counter > 0)
3620 {
3621 average = (float) sum / (float) counter;
3622
3623 if (is_pulse)
3624 {
3625 printf ("pulse ");
3626 }
3627 else
3628 {
3629 printf ("pause ");
3630 }
3631
3632 printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS);
3633 printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS);
3634 printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS);
3635
3636 tolerance = (max - average);
3637
3638 if (average - min > tolerance)
3639 {
3640 tolerance = average - min;
3641 }
3642
3643 tolerance = tolerance * 100 / average;
3644 printf ("tol: %4.1f%%\n", tolerance);
3645 }
3646
3647 counter = 0;
3648 sum = 0;
3649 min = i + 1;
3650 }
3651 }
3652 }
3653
3654 #define STATE_LEFT_SHIFT 0x01
3655 #define STATE_RIGHT_SHIFT 0x02
3656 #define STATE_LEFT_CTRL 0x04
3657 #define STATE_LEFT_ALT 0x08
3658 #define STATE_RIGHT_ALT 0x10
3659
3660 #define KEY_ESCAPE 0x1B // keycode = 0x006e
3661 #define KEY_MENUE 0x80 // keycode = 0x0070
3662 #define KEY_BACK 0x81 // keycode = 0x0071
3663 #define KEY_FORWARD 0x82 // keycode = 0x0072
3664 #define KEY_ADDRESS 0x83 // keycode = 0x0073
3665 #define KEY_WINDOW 0x84 // keycode = 0x0074
3666 #define KEY_1ST_PAGE 0x85 // keycode = 0x0075
3667 #define KEY_STOP 0x86 // keycode = 0x0076
3668 #define KEY_MAIL 0x87 // keycode = 0x0077
3669 #define KEY_FAVORITES 0x88 // keycode = 0x0078
3670 #define KEY_NEW_PAGE 0x89 // keycode = 0x0079
3671 #define KEY_SETUP 0x8A // keycode = 0x007a
3672 #define KEY_FONT 0x8B // keycode = 0x007b
3673 #define KEY_PRINT 0x8C // keycode = 0x007c
3674 #define KEY_ON_OFF 0x8E // keycode = 0x007c
3675
3676 #define KEY_INSERT 0x90 // keycode = 0x004b
3677 #define KEY_DELETE 0x91 // keycode = 0x004c
3678 #define KEY_LEFT 0x92 // keycode = 0x004f
3679 #define KEY_HOME 0x93 // keycode = 0x0050
3680 #define KEY_END 0x94 // keycode = 0x0051
3681 #define KEY_UP 0x95 // keycode = 0x0053
3682 #define KEY_DOWN 0x96 // keycode = 0x0054
3683 #define KEY_PAGE_UP 0x97 // keycode = 0x0055
3684 #define KEY_PAGE_DOWN 0x98 // keycode = 0x0056
3685 #define KEY_RIGHT 0x99 // keycode = 0x0059
3686 #define KEY_MOUSE_1 0x9E // keycode = 0x0400
3687 #define KEY_MOUSE_2 0x9F // keycode = 0x0800
3688
3689 static uint8_t
3690 get_fdc_key (uint16_t cmd)
3691 {
3692 static uint8_t key_table[128] =
3693 {
3694 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
3695 0, '^', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 0, '\b',
3696 '\t','q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 0, 0, 'a',
3697 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', '\r', 0, '<', 'y', 'x',
3698 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, 0, 0, ' ', 0, 0,
3699
3700 0, '°', '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 0, '\b',
3701 '\t','Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 0, 0, 'A',
3702 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'','\r', 0, '>', 'Y', 'X',
3703 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, 0, 0, ' ', 0, 0
3704 };
3705 static uint8_t state;
3706
3707 uint8_t key = 0;
3708
3709 switch (cmd)
3710 {
3711 case 0x002C: state |= STATE_LEFT_SHIFT; break; // pressed left shift
3712 case 0x00AC: state &= ~STATE_LEFT_SHIFT; break; // released left shift
3713 case 0x0039: state |= STATE_RIGHT_SHIFT; break; // pressed right shift
3714 case 0x00B9: state &= ~STATE_RIGHT_SHIFT; break; // released right shift
3715 case 0x003A: state |= STATE_LEFT_CTRL; break; // pressed left ctrl
3716 case 0x00BA: state &= ~STATE_LEFT_CTRL; break; // released left ctrl
3717 case 0x003C: state |= STATE_LEFT_ALT; break; // pressed left alt
3718 case 0x00BC: state &= ~STATE_LEFT_ALT; break; // released left alt
3719 case 0x003E: state |= STATE_RIGHT_ALT; break; // pressed left alt
3720 case 0x00BE: state &= ~STATE_RIGHT_ALT; break; // released left alt
3721
3722 case 0x006e: key = KEY_ESCAPE; break;
3723 case 0x004b: key = KEY_INSERT; break;
3724 case 0x004c: key = KEY_DELETE; break;
3725 case 0x004f: key = KEY_LEFT; break;
3726 case 0x0050: key = KEY_HOME; break;
3727 case 0x0051: key = KEY_END; break;
3728 case 0x0053: key = KEY_UP; break;
3729 case 0x0054: key = KEY_DOWN; break;
3730 case 0x0055: key = KEY_PAGE_UP; break;
3731 case 0x0056: key = KEY_PAGE_DOWN; break;
3732 case 0x0059: key = KEY_RIGHT; break;
3733 case 0x0400: key = KEY_MOUSE_1; break;
3734 case 0x0800: key = KEY_MOUSE_2; break;
3735
3736 default:
3737 {
3738 if (!(cmd & 0x80)) // pressed key
3739 {
3740 if (cmd >= 0x70 && cmd <= 0x7F) // function keys
3741 {
3742 key = cmd + 0x10; // 7x -> 8x
3743 }
3744 else if (cmd < 64) // key listed in key_table
3745 {
3746 if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT))
3747 {
3748 switch (cmd)
3749 {
3750 case 0x0003: key = '²'; break;
3751 case 0x0008: key = '{'; break;
3752 case 0x0009: key = '['; break;
3753 case 0x000A: key = ']'; break;
3754 case 0x000B: key = '}'; break;
3755 case 0x000C: key = '\\'; break;
3756 case 0x001C: key = '~'; break;
3757 case 0x002D: key = '|'; break;
3758 case 0x0034: key = 0xB5; break; // Mu
3759 }
3760 }
3761 else if (state & (STATE_LEFT_CTRL))
3762 {
3763 if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z')
3764 {
3765 key = key_table[cmd] - 'a' + 1;
3766 }
3767 else
3768 {
3769 key = key_table[cmd];
3770 }
3771 }
3772 else
3773 {
3774 int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0);
3775
3776 if (key_table[idx])
3777 {
3778 key = key_table[idx];
3779 }
3780 }
3781 }
3782 }
3783 break;
3784 }
3785 }
3786
3787 return (key);
3788 }
3789
3790 static int analyze = FALSE;
3791 static int list = FALSE;
3792 static IRMP_DATA irmp_data;
3793
3794 static void
3795 next_tick (void)
3796 {
3797 if (! analyze && ! list)
3798 {
3799 (void) irmp_ISR ();
3800
3801 if (irmp_get_data (&irmp_data))
3802 {
3803 uint8_t key;
3804
3805 ANALYZE_ONLY_NORMAL_PUTCHAR (' ');
3806
3807 if (verbose)
3808 {
3809 printf ("%8d ", time_counter);
3810 }
3811
3812 if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0)
3813 {
3814 if ((key >= 0x20 && key < 0x7F) || key >= 0xA0)
3815 {
3816 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n",
3817 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key);
3818 }
3819 else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys
3820 {
3821 char * p = (char *) NULL;
3822
3823 switch (key)
3824 {
3825 case '\t' : p = "TAB"; break;
3826 case '\r' : p = "CR"; break;
3827 case KEY_ESCAPE : p = "ESCAPE"; break;
3828 case KEY_MENUE : p = "MENUE"; break;
3829 case KEY_BACK : p = "BACK"; break;
3830 case KEY_FORWARD : p = "FORWARD"; break;
3831 case KEY_ADDRESS : p = "ADDRESS"; break;
3832 case KEY_WINDOW : p = "WINDOW"; break;
3833 case KEY_1ST_PAGE : p = "1ST_PAGE"; break;
3834 case KEY_STOP : p = "STOP"; break;
3835 case KEY_MAIL : p = "MAIL"; break;
3836 case KEY_FAVORITES : p = "FAVORITES"; break;
3837 case KEY_NEW_PAGE : p = "NEW_PAGE"; break;
3838 case KEY_SETUP : p = "SETUP"; break;
3839 case KEY_FONT : p = "FONT"; break;
3840 case KEY_PRINT : p = "PRINT"; break;
3841 case KEY_ON_OFF : p = "ON_OFF"; break;
3842
3843 case KEY_INSERT : p = "INSERT"; break;
3844 case KEY_DELETE : p = "DELETE"; break;
3845 case KEY_LEFT : p = "LEFT"; break;
3846 case KEY_HOME : p = "HOME"; break;
3847 case KEY_END : p = "END"; break;
3848 case KEY_UP : p = "UP"; break;
3849 case KEY_DOWN : p = "DOWN"; break;
3850 case KEY_PAGE_UP : p = "PAGE_UP"; break;
3851 case KEY_PAGE_DOWN : p = "PAGE_DOWN"; break;
3852 case KEY_RIGHT : p = "RIGHT"; break;
3853 case KEY_MOUSE_1 : p = "KEY_MOUSE_1"; break;
3854 case KEY_MOUSE_2 : p = "KEY_MOUSE_2"; break;
3855 default : p = "<UNKNWON>"; break;
3856 }
3857
3858 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n",
3859 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p);
3860 }
3861 else
3862 {
3863 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n",
3864 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key);
3865 }
3866 }
3867 else
3868 {
3869 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n",
3870 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags);
3871 }
3872 }
3873 }
3874 }
3875
3876 int
3877 main (int argc, char ** argv)
3878 {
3879 int i;
3880 int ch;
3881 int last_ch = 0;
3882 int pulse = 0;
3883 int pause = 0;
3884
3885 int start_pulses[256];
3886 int start_pauses[256];
3887 int pulses[256];
3888 int pauses[256];
3889
3890 int first_pulse = TRUE;
3891 int first_pause = TRUE;
3892
3893 if (argc == 2)
3894 {
3895 if (! strcmp (argv[1], "-v"))
3896 {
3897 verbose = TRUE;
3898 }
3899 else if (! strcmp (argv[1], "-l"))
3900 {
3901 list = TRUE;
3902 }
3903 else if (! strcmp (argv[1], "-a"))
3904 {
3905 analyze = TRUE;
3906 }
3907 else if (! strcmp (argv[1], "-s"))
3908 {
3909 silent = TRUE;
3910 }
3911 else if (! strcmp (argv[1], "-p"))
3912 {
3913 print_timings ();
3914 return (0);
3915 }
3916 }
3917
3918 for (i = 0; i < 256; i++)
3919 {
3920 start_pulses[i] = 0;
3921 start_pauses[i] = 0;
3922 pulses[i] = 0;
3923 pauses[i] = 0;
3924 }
3925
3926 IRMP_PIN = 0xFF;
3927
3928 while ((ch = getchar ()) != EOF)
3929 {
3930 if (ch == '_' || ch == '0')
3931 {
3932 if (last_ch != ch)
3933 {
3934 if (pause > 0)
3935 {
3936 if (list)
3937 {
3938 printf ("pause: %d\n", pause);
3939 }
3940
3941 if (analyze)
3942 {
3943 if (first_pause)
3944 {
3945 if (pause < 256)
3946 {
3947 start_pauses[pause]++;
3948 }
3949 first_pause = FALSE;
3950 }
3951 else
3952 {
3953 if (pause < 256)
3954 {
3955 pauses[pause]++;
3956 }
3957 }
3958 }
3959 }
3960 pause = 0;
3961 }
3962 pulse++;
3963 IRMP_PIN = 0x00;
3964 }
3965 else if (ch == 0xaf || ch == '-' || ch == '1')
3966 {
3967 if (last_ch != ch)
3968 {
3969 if (list)
3970 {
3971 printf ("pulse: %d ", pulse);
3972 }
3973
3974 if (analyze)
3975 {
3976 if (first_pulse)
3977 {
3978 if (pulse < 256)
3979 {
3980 start_pulses[pulse]++;
3981 }
3982 first_pulse = FALSE;
3983 }
3984 else
3985 {
3986 if (pulse < 256)
3987 {
3988 pulses[pulse]++;
3989 }
3990 }
3991 }
3992 pulse = 0;
3993 }
3994
3995 pause++;
3996 IRMP_PIN = 0xff;
3997 }
3998 else if (ch == '\n')
3999 {
4000 IRMP_PIN = 0xff;
4001
4002 if (list && pause > 0)
4003 {
4004 printf ("pause: %d\n", pause);
4005 }
4006 pause = 0;
4007
4008 if (! analyze)
4009 {
4010 for (i = 0; i < (int) ((8000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 800 msec
4011 {
4012 next_tick ();
4013 }
4014 }
4015 first_pulse = TRUE;
4016 first_pause = TRUE;
4017 }
4018 else if (ch == '#')
4019 {
4020 if (analyze)
4021 {
4022 while ((ch = getchar()) != '\n' && ch != EOF)
4023 {
4024 ;
4025 }
4026 }
4027 else
4028 {
4029 puts ("-------------------------------------------------------------------");
4030 putchar (ch);
4031
4032 while ((ch = getchar()) != '\n' && ch != EOF)
4033 {
4034 if (ch != '\r') // ignore CR in DOS/Windows files
4035 {
4036 putchar (ch);
4037 }
4038 }
4039 putchar ('\n');
4040 }
4041
4042 }
4043
4044 last_ch = ch;
4045
4046 next_tick ();
4047 }
4048
4049 if (analyze)
4050 {
4051 print_spectrum ("START PULSES", start_pulses, TRUE);
4052 print_spectrum ("START PAUSES", start_pauses, FALSE);
4053 print_spectrum ("PULSES", pulses, TRUE);
4054 print_spectrum ("PAUSES", pauses, FALSE);
4055 puts ("-------------------------------------------------------------------------------");
4056 }
4057 return 0;
4058 }
4059
4060 #endif // ANALYZE