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