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