]> cloudbase.mooo.com Git - irmp.git/blob - irmp.c
version 1.9.9: some code corrections
[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.97 2011/02/25 15:24:06 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 µs 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_NEC16_PROTOCOL == 1
961
962 static PROGMEM IRMP_PARAMETER nec16_param =
963 {
964 IRMP_NEC16_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 NEC16_ADDRESS_OFFSET, // address_offset: address offset
974 NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN, // address_end: end of address
975 NEC16_COMMAND_OFFSET, // command_offset: command offset
976 NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN, // command_end: end of command
977 NEC16_COMPLETE_DATA_LEN, // complete_len: complete length of frame
978 NEC16_STOP_BIT, // stop_bit: flag: frame has stop bit
979 NEC16_LSB, // lsb_first: flag: LSB first
980 NEC16_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)
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_SAMSUNG_PROTOCOL == 1
1670 else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
1671 {
1672 irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first
1673 }
1674 #endif
1675
1676 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1677 else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit >= 20 && irmp_bit < 24)
1678 {
1679 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits in upper nibble with LSB first
1680 }
1681
1682 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && irmp_bit < KASEIKYO_COMPLETE_DATA_LEN)
1683 {
1684 if (value)
1685 {
1686 xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8);
1687 }
1688 else
1689 {
1690 xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8));
1691 }
1692 }
1693
1694 #endif
1695
1696 irmp_bit++;
1697 }
1698
1699 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1700 * store bit
1701 * @details store bit in temp address or temp command
1702 * @param value to store: 0 or 1
1703 *---------------------------------------------------------------------------------------------------------------------------------------------------
1704 */
1705 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1706 static void
1707 irmp_store_bit2 (uint8_t value)
1708 {
1709 uint8_t irmp_bit2;
1710
1711 if (irmp_param.protocol)
1712 {
1713 irmp_bit2 = irmp_bit - 2;
1714 }
1715 else
1716 {
1717 irmp_bit2 = irmp_bit - 1;
1718 }
1719
1720 if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end)
1721 {
1722 irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.address_offset)); // CV wants cast
1723 }
1724 else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end)
1725 {
1726 irmp_tmp_command2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.command_offset)); // CV wants cast
1727 }
1728 }
1729 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1730
1731 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1732 * ISR routine
1733 * @details ISR routine, called 10000 times per second
1734 *---------------------------------------------------------------------------------------------------------------------------------------------------
1735 */
1736 uint8_t
1737 irmp_ISR (void)
1738 {
1739 static uint8_t irmp_start_bit_detected; // flag: start bit detected
1740 static uint8_t wait_for_space; // flag: wait for data bit space
1741 static uint8_t wait_for_start_space; // flag: wait for start bit space
1742 static uint8_t irmp_pulse_time; // count bit time for pulse
1743 static PAUSE_LEN irmp_pause_time; // count bit time for pause
1744 static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition
1745 static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition
1746 static uint16_t repetition_len; // SIRCS repeats frame 2-5 times with 45 ms pause
1747 static uint8_t repetition_frame_number;
1748 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1749 static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition
1750 #endif
1751 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1752 static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit
1753 #endif
1754 #if IRMP_SUPPORT_MANCHESTER == 1
1755 static PAUSE_LEN last_pause; // last pause value
1756 #endif
1757 #if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1758 static uint8_t last_value; // last bit value
1759 #endif
1760 uint8_t irmp_input; // input value
1761
1762 #ifdef ANALYZE
1763 time_counter++;
1764 #endif
1765
1766 irmp_input = input(IRMP_PIN);
1767
1768 irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined
1769
1770 if (! irmp_ir_detected) // ir code already detected?
1771 { // no...
1772 if (! irmp_start_bit_detected) // start bit detected?
1773 { // no...
1774 if (! irmp_input) // receiving burst?
1775 { // yes...
1776 #ifdef ANALYZE
1777 if (! irmp_pulse_time)
1778 {
1779 ANALYZE_PRINTF("%8d [starting pulse]\n", time_counter);
1780 }
1781 #endif
1782 irmp_pulse_time++; // increment counter
1783 }
1784 else
1785 { // no...
1786 if (irmp_pulse_time) // it's dark....
1787 { // set flags for counting the time of darkness...
1788 irmp_start_bit_detected = 1;
1789 wait_for_start_space = 1;
1790 wait_for_space = 0;
1791 irmp_tmp_command = 0;
1792 irmp_tmp_address = 0;
1793
1794 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1795 irmp_tmp_command2 = 0;
1796 irmp_tmp_address2 = 0;
1797 #endif
1798
1799 irmp_bit = 0xff;
1800 irmp_pause_time = 1; // 1st pause: set to 1, not to 0!
1801 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1802 rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1803 #endif
1804 }
1805 else
1806 {
1807 if (repetition_len < 0xFFFF) // avoid overflow of counter
1808 {
1809 repetition_len++;
1810 }
1811 }
1812 }
1813 }
1814 else
1815 {
1816 if (wait_for_start_space) // we have received start bit...
1817 { // ...and are counting the time of darkness
1818 if (irmp_input) // still dark?
1819 { // yes
1820 irmp_pause_time++; // increment counter
1821
1822 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1823 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) ||
1824 irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN)
1825 #else
1826 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1827 #endif
1828 { // yes...
1829 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1830 if (irmp_protocol == IRMP_JVC_PROTOCOL) // don't show eror if JVC protocol, irmp_pulse_time has been set below!
1831 {
1832 ;
1833 }
1834 else
1835 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1836 {
1837 ANALYZE_PRINTF ("%8d error 1: pause after start bit pulse %d too long: %d\n", time_counter, irmp_pulse_time, irmp_pause_time);
1838 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
1839 }
1840 irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit
1841 irmp_pulse_time = 0;
1842 irmp_pause_time = 0;
1843 }
1844 }
1845 else
1846 { // receiving first data pulse!
1847 IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0;
1848
1849 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
1850 irmp_param2.protocol = 0;
1851 #endif
1852
1853 ANALYZE_PRINTF ("%8d [start-bit: pulse = %2d, pause = %2d]\n", time_counter, irmp_pulse_time, irmp_pause_time);
1854
1855 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1856 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
1857 irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
1858 { // it's SIRCS
1859 ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1860 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
1861 SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
1862 irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param;
1863 }
1864 else
1865 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1866
1867 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
1868 if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame
1869 irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX &&
1870 irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1871 {
1872 ANALYZE_PRINTF ("protocol = NEC or JVC repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1873 JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX,
1874 JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1875 irmp_param_p = (IRMP_PARAMETER *) &nec_param; // tricky: use nec parameters
1876 }
1877 else
1878 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
1879
1880 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1881 if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1882 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
1883 {
1884 ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1885 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1886 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
1887 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1888 }
1889 else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1890 irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1891 { // it's NEC
1892 ANALYZE_PRINTF ("protocol = NEC (repetition frame), 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_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1895
1896 irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
1897 }
1898 else
1899 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1900
1901 #if IRMP_SUPPORT_NIKON_PROTOCOL == 1
1902 if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX &&
1903 irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX)
1904 {
1905 ANALYZE_PRINTF ("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1906 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX,
1907 NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX);
1908 irmp_param_p = (IRMP_PARAMETER *) &nikon_param;
1909 }
1910 else
1911 #endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1
1912
1913 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1914 if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
1915 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
1916 { // it's SAMSUNG
1917 ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1918 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
1919 SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
1920 irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
1921 }
1922 else
1923 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1924
1925 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1926 if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
1927 irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
1928 { // it's MATSUSHITA
1929 ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1930 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
1931 MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
1932 irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
1933 }
1934 else
1935 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1936
1937 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1938 if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
1939 irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
1940 { // it's KASEIKYO
1941 ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1942 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
1943 KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
1944 irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
1945 }
1946 else
1947 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1948
1949 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1950 if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
1951 irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
1952 { // it's RECS80
1953 ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1954 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
1955 RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
1956 irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
1957 }
1958 else
1959 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1960
1961 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1962 if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
1963 (irmp_pulse_time >= RC5_START_BIT_LEN_MIN_2 && irmp_pulse_time <= RC5_START_BIT_LEN_MAX_2)) &&
1964 ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
1965 (irmp_pause_time >= RC5_START_BIT_LEN_MIN_2 && irmp_pause_time <= RC5_START_BIT_LEN_MAX_2)))
1966 { // it's RC5
1967 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1968 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
1969 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
1970 {
1971 ANALYZE_PRINTF ("protocol = RC5 or FDC\n");
1972 ANALYZE_PRINTF ("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1973 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
1974 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
1975 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1976 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1977 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1978 memcpy_P (&irmp_param2, &fdc_param, sizeof (IRMP_PARAMETER));
1979 }
1980 else
1981 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
1982
1983 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1984 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
1985 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
1986 {
1987 ANALYZE_PRINTF ("protocol = RC5 or RCCAR\n");
1988 ANALYZE_PRINTF ("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1989 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
1990 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
1991 ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1992 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1993 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1994 memcpy_P (&irmp_param2, &rccar_param, sizeof (IRMP_PARAMETER));
1995 }
1996 else
1997 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
1998 {
1999 ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n",
2000 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2001 RC5_START_BIT_LEN_MIN_2, RC5_START_BIT_LEN_MAX_2,
2002 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
2003 RC5_START_BIT_LEN_MIN_2, RC5_START_BIT_LEN_MAX_2);
2004 }
2005
2006 irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
2007 last_pause = irmp_pause_time;
2008
2009 if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= RC5_START_BIT_LEN_MAX_2) ||
2010 (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= RC5_START_BIT_LEN_MAX_2))
2011 {
2012 last_value = 0;
2013 rc5_cmd_bit6 = 1<<6;
2014 }
2015 else
2016 {
2017 last_value = 1;
2018 }
2019 }
2020 else
2021 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
2022
2023 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2024 if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
2025 ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
2026 (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
2027 { // it's DENON
2028 ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2029 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
2030 DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
2031 DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
2032 irmp_param_p = (IRMP_PARAMETER *) &denon_param;
2033 }
2034 else
2035 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
2036
2037 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2038 if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
2039 irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
2040 { // it's RC6
2041 ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2042 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
2043 RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
2044 irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
2045 last_pause = 0;
2046 last_value = 1;
2047 }
2048 else
2049 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2050
2051 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2052 if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
2053 irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
2054 { // it's RECS80EXT
2055 ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2056 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
2057 RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
2058 irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
2059 }
2060 else
2061 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
2062
2063 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2064 if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
2065 irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
2066 { // it's NUBERT
2067 ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2068 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
2069 NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
2070 irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
2071 }
2072 else
2073 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2074
2075 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2076 if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
2077 irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
2078 { // it's BANG_OLUFSEN
2079 ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n");
2080 ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2081 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
2082 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
2083 ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2084 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
2085 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
2086 ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2087 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
2088 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
2089 ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2090 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
2091 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
2092 irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
2093 last_value = 0;
2094 }
2095 else
2096 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2097
2098 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2099 if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX &&
2100 irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX)
2101 { // it's GRUNDIG
2102 ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2103 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
2104 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX);
2105 irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
2106 last_pause = irmp_pause_time;
2107 last_value = 1;
2108 }
2109 else
2110 #endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2111
2112 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2113 if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) ||
2114 (irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN_2 && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX_2)) &&
2115 ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) ||
2116 (irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN_2 && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX_2)))
2117 { // it's RUWIDO or SIEMENS
2118 ANALYZE_PRINTF ("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
2119 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
2120 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN_2, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX_2,
2121 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
2122 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN_2, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX_2);
2123 irmp_param_p = (IRMP_PARAMETER *) &ruwido_param;
2124 last_pause = irmp_pause_time;
2125 last_value = 1;
2126 }
2127 else
2128 #endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2129
2130 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
2131 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
2132 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
2133 {
2134 ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2135 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
2136 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2137 irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
2138 }
2139 else
2140 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2141
2142 #if IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2143 if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX &&
2144 irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX)
2145 {
2146 ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2147 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX,
2148 RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX);
2149 irmp_param_p = (IRMP_PARAMETER *) &rccar_param;
2150 }
2151 else
2152 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2153
2154 #if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2155 if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX &&
2156 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)
2157 { // it's KATHREIN
2158 ANALYZE_PRINTF ("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2159 KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX,
2160 KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX);
2161 irmp_param_p = (IRMP_PARAMETER *) &kathrein_param;
2162 }
2163 else
2164 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1
2165
2166 #if IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2167 if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX &&
2168 irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX)
2169 { // it's NETBOX
2170 ANALYZE_PRINTF ("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2171 NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX,
2172 NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX);
2173 irmp_param_p = (IRMP_PARAMETER *) &netbox_param;
2174 }
2175 else
2176 #endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1
2177
2178 #if IRMP_SUPPORT_IMON_PROTOCOL == 1
2179 if (irmp_pulse_time >= IMON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= IMON_START_BIT_PULSE_LEN_MAX &&
2180 irmp_pause_time >= IMON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= IMON_START_BIT_PAUSE_LEN_MAX)
2181 { // it's IMON
2182 ANALYZE_PRINTF ("protocol = IMON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
2183 IMON_START_BIT_PULSE_LEN_MIN, IMON_START_BIT_PULSE_LEN_MAX,
2184 IMON_START_BIT_PAUSE_LEN_MIN, IMON_START_BIT_PAUSE_LEN_MAX);
2185 irmp_param_p = (IRMP_PARAMETER *) &imon_param;
2186 }
2187 else
2188 #endif // IRMP_SUPPORT_IMON_PROTOCOL == 1
2189
2190 {
2191 ANALYZE_PRINTF ("protocol = UNKNOWN\n");
2192 irmp_start_bit_detected = 0; // wait for another start bit...
2193 }
2194
2195 if (irmp_start_bit_detected)
2196 {
2197 memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
2198
2199 #ifdef ANALYZE
2200 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2201 {
2202 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
2203 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
2204 }
2205 else
2206 {
2207 ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max,
2208 irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2209 ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max,
2210 irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
2211 }
2212
2213 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2214 if (irmp_param2.protocol)
2215 {
2216 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max);
2217 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max);
2218 ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max);
2219 ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max);
2220 }
2221 #endif
2222
2223
2224 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2225 if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
2226 {
2227 ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
2228 }
2229 #endif
2230
2231 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2232 {
2233 ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2234 ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
2235 }
2236
2237 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2238 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2239 {
2240 ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
2241 ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
2242 }
2243 #endif
2244
2245 ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
2246 ANALYZE_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset);
2247 ANALYZE_PRINTF ("complete_len: %3d\n", irmp_param.complete_len);
2248 ANALYZE_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit);
2249 #endif // ANALYZE
2250 }
2251
2252 irmp_bit = 0;
2253
2254 #if IRMP_SUPPORT_MANCHESTER == 1
2255 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2256 irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO
2257 irmp_param.protocol != IRMP_RC6_PROTOCOL) // Manchester, but not RC6
2258 {
2259 if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= irmp_param.pulse_0_len_max) // XXXXXXXX!!!
2260 {
2261 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2262 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2263 ANALYZE_NEWLINE ();
2264 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1);
2265 }
2266 else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2267 {
2268 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2269
2270 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2271 ANALYZE_NEWLINE ();
2272 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0);
2273 }
2274 }
2275 else
2276 #endif // IRMP_SUPPORT_MANCHESTER == 1
2277
2278 #if IRMP_SUPPORT_SERIAL == 1
2279 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2280 {
2281 ; // do nothing
2282 }
2283 else
2284 #endif // IRMP_SUPPORT_SERIAL == 1
2285
2286
2287 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2288 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2289 {
2290 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2291
2292 if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
2293 { // pause timings correct for "1"?
2294 ANALYZE_PUTCHAR ('1'); // yes, store 1
2295 ANALYZE_NEWLINE ();
2296 irmp_store_bit (1);
2297 }
2298 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
2299 { // pause timings correct for "0"?
2300 ANALYZE_PUTCHAR ('0'); // yes, store 0
2301 ANALYZE_NEWLINE ();
2302 irmp_store_bit (0);
2303 }
2304 }
2305 else
2306 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
2307 {
2308 ; // else do nothing
2309 }
2310
2311 irmp_pulse_time = 1; // set counter to 1, not 0
2312 irmp_pause_time = 0;
2313 wait_for_start_space = 0;
2314 }
2315 }
2316 else if (wait_for_space) // the data section....
2317 { // counting the time of darkness....
2318 uint8_t got_light = FALSE;
2319
2320 if (irmp_input) // still dark?
2321 { // yes...
2322 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
2323 {
2324 if (
2325 #if IRMP_SUPPORT_MANCHESTER == 1
2326 (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) ||
2327 #endif
2328 #if IRMP_SUPPORT_SERIAL == 1
2329 (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) ||
2330 #endif
2331 (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max))
2332 {
2333 #ifdef ANALYZE
2334 if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER))
2335 {
2336 ANALYZE_PRINTF ("stop bit detected\n");
2337 }
2338 #endif
2339 irmp_param.stop_bit = 0;
2340 }
2341 else
2342 {
2343 ANALYZE_PRINTF ("error: stop bit timing wrong\n");
2344
2345 irmp_start_bit_detected = 0; // wait for another start bit...
2346 irmp_pulse_time = 0;
2347 irmp_pause_time = 0;
2348 }
2349 }
2350 else
2351 {
2352 irmp_pause_time++; // increment counter
2353
2354 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2355 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits:
2356 irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12
2357 irmp_bit >= 12 - 1) // pause too long?
2358 { // yes, break and close this frame
2359 irmp_param.complete_len = irmp_bit + 1; // set new complete length
2360 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2361 irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8; // new: store number of additional bits in upper byte of address!
2362 irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length
2363 irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length
2364 }
2365 else
2366 #endif
2367 #if IRMP_SUPPORT_SERIAL == 1
2368 // NETBOX generates no stop bit, here is the timeout condition:
2369 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL &&
2370 irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit))
2371 {
2372 got_light = TRUE; // this is a lie, but helps (generates stop bit)
2373 }
2374 else
2375 #endif
2376 #if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1
2377 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit)
2378 {
2379 if (irmp_pause_time > IR60_TIMEOUT_LEN && irmp_bit == 6)
2380 {
2381 ANALYZE_PRINTF ("Switching to IR60 protocol\n");
2382 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2383 irmp_param.stop_bit = TRUE; // set flag
2384
2385 irmp_param.protocol = IRMP_IR60_PROTOCOL; // change protocol
2386 irmp_param.complete_len = IR60_COMPLETE_DATA_LEN; // correct complete len
2387 irmp_param.address_offset = IR60_ADDRESS_OFFSET;
2388 irmp_param.address_end = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN;
2389 irmp_param.command_offset = IR60_COMMAND_OFFSET;
2390 irmp_param.command_end = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN;
2391
2392 irmp_tmp_command <<= 1;
2393 irmp_tmp_command |= first_bit;
2394 }
2395 else if (irmp_pause_time >= irmp_param.pause_0_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2)
2396 { // special manchester decoder
2397 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len
2398 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2399 irmp_param.stop_bit = TRUE; // set flag
2400 }
2401 else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
2402 {
2403 ANALYZE_PRINTF ("Switching to NOKIA protocol\n");
2404 irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol
2405 irmp_param.address_offset = NOKIA_ADDRESS_OFFSET;
2406 irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
2407 irmp_param.command_offset = NOKIA_COMMAND_OFFSET;
2408 irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
2409
2410 if (irmp_tmp_command & 0x300)
2411 {
2412 irmp_tmp_address = (irmp_tmp_command >> 8);
2413 irmp_tmp_command &= 0xFF;
2414 }
2415 }
2416 }
2417 else
2418 #endif
2419 #if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1
2420 if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit)
2421 {
2422 if (irmp_pause_time >= irmp_param.pause_0_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2)
2423 { // special manchester decoder
2424 irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN; // correct complete len
2425 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2426 irmp_param.stop_bit = TRUE; // set flag
2427 }
2428 else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN)
2429 {
2430 ANALYZE_PRINTF ("Switching to SIEMENS protocol\n");
2431 irmp_param.protocol = IRMP_SIEMENS_PROTOCOL; // change protocol
2432 irmp_param.address_offset = SIEMENS_ADDRESS_OFFSET;
2433 irmp_param.address_end = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN;
2434 irmp_param.command_offset = SIEMENS_COMMAND_OFFSET;
2435 irmp_param.command_end = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN;
2436
2437 // 76543210
2438 // RUWIDO: AAAAAAAAACCCCCCCp
2439 // SIEMENS: AAAAAAAAAAACCCCCCCCCCp
2440 irmp_tmp_address <<= 2;
2441 irmp_tmp_address |= (irmp_tmp_command >> 6);
2442 irmp_tmp_command &= 0x003F;
2443 irmp_tmp_command <<= 4;
2444 irmp_tmp_command |= last_value;
2445 }
2446 }
2447 else
2448 #endif
2449 #if IRMP_SUPPORT_MANCHESTER == 1
2450 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) &&
2451 irmp_pause_time >= irmp_param.pause_0_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
2452 { // special manchester decoder
2453 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
2454 irmp_param.stop_bit = TRUE; // set flag
2455 }
2456 else
2457 #endif // IRMP_SUPPORT_MANCHESTER == 1
2458 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
2459 { // yes...
2460 if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
2461 {
2462 irmp_bit++;
2463 }
2464 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
2465 else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit
2466 {
2467 ANALYZE_PRINTF ("Switching to JVC protocol\n");
2468 irmp_param.stop_bit = TRUE; // set flag
2469 irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol
2470 irmp_param.complete_len = irmp_bit; // patch length: 16 or 17
2471 irmp_tmp_command = (irmp_tmp_address >> 4); // set command: upper 12 bits are command bits
2472 irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits
2473 irmp_start_bit_detected = 1; // tricky: don't wait for another start bit...
2474 }
2475 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
2476 else
2477 {
2478 ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
2479 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2480
2481 irmp_start_bit_detected = 0; // wait for another start bit...
2482 irmp_pulse_time = 0;
2483 irmp_pause_time = 0;
2484 }
2485 }
2486 }
2487 }
2488 else
2489 { // got light now!
2490 got_light = TRUE;
2491 }
2492
2493 if (got_light)
2494 {
2495 ANALYZE_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
2496
2497 #if IRMP_SUPPORT_MANCHESTER == 1
2498 if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester
2499 {
2500 #if 0
2501 if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= irmp_param.pulse_0_len_max */)
2502 #else // better:
2503 if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
2504 irmp_pause_time <= irmp_param.pause_0_len_max)
2505 #endif
2506 {
2507 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2508 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2509 {
2510 ANALYZE_PUTCHAR ('T');
2511 if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode 6A
2512 {
2513 irmp_store_bit (1);
2514 last_value = 1;
2515 }
2516 else // RC6 mode 0
2517 {
2518 irmp_store_bit (0);
2519 last_value = 0;
2520 }
2521 ANALYZE_NEWLINE ();
2522 }
2523 else
2524 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2525 {
2526 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1');
2527 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1 );
2528
2529 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2530 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit
2531 {
2532 ANALYZE_PUTCHAR ('T');
2533 irmp_store_bit (1);
2534
2535 if (irmp_pause_time > irmp_param.pause_0_len_max)
2536 {
2537 last_value = 0;
2538 }
2539 else
2540 {
2541 last_value = 1;
2542 }
2543 ANALYZE_NEWLINE ();
2544 }
2545 else
2546 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2547 {
2548 ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0');
2549 irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0 );
2550 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2551 if (! irmp_param2.protocol)
2552 #endif
2553 {
2554 ANALYZE_NEWLINE ();
2555 }
2556 last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0;
2557 }
2558 }
2559 }
2560 else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max /* &&
2561 irmp_pause_time <= irmp_param.pause_0_len_max */)
2562 {
2563 uint8_t manchester_value;
2564
2565 if (last_pause > irmp_param.pause_1_len_max && last_pause <= irmp_param.pause_0_len_max)
2566 {
2567 manchester_value = last_value ? 0 : 1;
2568 last_value = manchester_value;
2569 }
2570 else
2571 {
2572 manchester_value = last_value;
2573 }
2574
2575 ANALYZE_PUTCHAR (manchester_value + '0');
2576
2577 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1)
2578 if (! irmp_param2.protocol)
2579 #endif
2580 {
2581 ANALYZE_NEWLINE ();
2582 }
2583
2584 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
2585 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1) // RC6 mode != 0 ???
2586 {
2587 ANALYZE_PRINTF ("Switching to RC6A protocol\n");
2588 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
2589 irmp_param.address_offset = 5;
2590 irmp_param.address_end = irmp_param.address_offset + 15;
2591 irmp_param.command_offset = irmp_param.address_end + 1; // skip 1 system bit, changes like a toggle bit
2592 irmp_param.command_end = irmp_param.command_offset + 16 - 1;
2593 irmp_tmp_address = 0;
2594 }
2595 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
2596
2597 irmp_store_bit (manchester_value);
2598 }
2599 else
2600 {
2601 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2602 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL &&
2603 irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX &&
2604 ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) ||
2605 (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)))
2606 {
2607 ANALYZE_PUTCHAR ('?');
2608 irmp_param.protocol = 0; // switch to FDC, see below
2609 }
2610 else
2611 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2612 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2613 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL &&
2614 irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX &&
2615 ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) ||
2616 (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)))
2617 {
2618 ANALYZE_PUTCHAR ('?');
2619 irmp_param.protocol = 0; // switch to RCCAR, see below
2620 }
2621 else
2622 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2623 {
2624 ANALYZE_PUTCHAR ('?');
2625 ANALYZE_NEWLINE ();
2626 ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2627 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2628 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2629 irmp_pause_time = 0;
2630 }
2631 }
2632
2633 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1
2634 if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX)
2635 {
2636 if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX)
2637 {
2638 ANALYZE_PRINTF (" 1 (FDC)\n");
2639 irmp_store_bit2 (1);
2640 }
2641 else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX)
2642 {
2643 ANALYZE_PRINTF (" 0 (FDC)\n");
2644 irmp_store_bit2 (0);
2645 }
2646
2647 if (! irmp_param.protocol)
2648 {
2649 ANALYZE_PRINTF ("Switching to FDC protocol\n");
2650 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2651 irmp_param2.protocol = 0;
2652 irmp_tmp_address = irmp_tmp_address2;
2653 irmp_tmp_command = irmp_tmp_command2;
2654 }
2655 }
2656 #endif // IRMP_SUPPORT_FDC_PROTOCOL == 1
2657 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2658 if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX)
2659 {
2660 if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX)
2661 {
2662 ANALYZE_PRINTF (" 1 (RCCAR)\n");
2663 irmp_store_bit2 (1);
2664 }
2665 else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX)
2666 {
2667 ANALYZE_PRINTF (" 0 (RCCAR)\n");
2668 irmp_store_bit2 (0);
2669 }
2670
2671 if (! irmp_param.protocol)
2672 {
2673 ANALYZE_PRINTF ("Switching to RCCAR protocol\n");
2674 memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER));
2675 irmp_param2.protocol = 0;
2676 irmp_tmp_address = irmp_tmp_address2;
2677 irmp_tmp_command = irmp_tmp_command2;
2678 }
2679 }
2680 #endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1
2681
2682 last_pause = irmp_pause_time;
2683 wait_for_space = 0;
2684 }
2685 else
2686 #endif // IRMP_SUPPORT_MANCHESTER == 1
2687
2688 #if IRMP_SUPPORT_SERIAL == 1
2689 if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL)
2690 {
2691 while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max)
2692 {
2693 ANALYZE_PUTCHAR ('1');
2694 irmp_store_bit (1);
2695
2696 if (irmp_pulse_time >= irmp_param.pulse_1_len_min)
2697 {
2698 irmp_pulse_time -= irmp_param.pulse_1_len_min;
2699 }
2700 else
2701 {
2702 irmp_pulse_time = 0;
2703 }
2704 }
2705
2706 while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max)
2707 {
2708 ANALYZE_PUTCHAR ('0');
2709 irmp_store_bit (0);
2710
2711 if (irmp_pause_time >= irmp_param.pause_1_len_min)
2712 {
2713 irmp_pause_time -= irmp_param.pause_1_len_min;
2714 }
2715 else
2716 {
2717 irmp_pause_time = 0;
2718 }
2719 }
2720 ANALYZE_NEWLINE ();
2721 wait_for_space = 0;
2722 }
2723 else
2724 #endif // IRMP_SUPPORT_SERIAL == 1
2725
2726 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2727 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit
2728 {
2729 if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
2730 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
2731 {
2732 ANALYZE_PRINTF ("SYNC\n");
2733 wait_for_space = 0;
2734 irmp_tmp_id = 0;
2735 irmp_bit++;
2736 }
2737 else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
2738 {
2739 irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;
2740 irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;
2741 irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
2742 irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;
2743
2744 if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
2745 {
2746 ANALYZE_PUTCHAR ('1');
2747 ANALYZE_NEWLINE ();
2748 irmp_store_bit (1);
2749 wait_for_space = 0;
2750 }
2751 else
2752 {
2753 ANALYZE_PUTCHAR ('0');
2754 ANALYZE_NEWLINE ();
2755 irmp_store_bit (0);
2756 wait_for_space = 0;
2757 }
2758
2759 ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n");
2760 }
2761 else
2762 { // timing incorrect!
2763 ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2764 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2765 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2766 irmp_pause_time = 0;
2767 }
2768 }
2769 else
2770 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
2771
2772 #if IRMP_SUPPORT_NEC16_PROTOCOL
2773 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 8 &&
2774 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
2775 {
2776 ANALYZE_PRINTF ("Switching to NEC16 protocol\n");
2777 memcpy_P (&irmp_param, &nec16_param, sizeof (IRMP_PARAMETER));
2778 wait_for_space = 0;
2779 }
2780 else
2781 #endif // IRMP_SUPPORT_NEC16_PROTOCOL
2782
2783 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2784 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2785 {
2786 if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
2787 {
2788 if (irmp_bit == 1) // Bang & Olufsen: 3rd bit
2789 {
2790 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
2791 {
2792 ANALYZE_PRINTF ("3rd start bit\n");
2793 wait_for_space = 0;
2794 irmp_bit++;
2795 }
2796 else
2797 { // timing incorrect!
2798 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);
2799 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2800 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2801 irmp_pause_time = 0;
2802 }
2803 }
2804 else if (irmp_bit == 19) // Bang & Olufsen: trailer bit
2805 {
2806 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
2807 {
2808 ANALYZE_PRINTF ("trailer bit\n");
2809 wait_for_space = 0;
2810 irmp_bit++;
2811 }
2812 else
2813 { // timing incorrect!
2814 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);
2815 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2816 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2817 irmp_pause_time = 0;
2818 }
2819 }
2820 else
2821 {
2822 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
2823 { // pulse & pause timings correct for "1"?
2824 ANALYZE_PUTCHAR ('1');
2825 ANALYZE_NEWLINE ();
2826 irmp_store_bit (1);
2827 last_value = 1;
2828 wait_for_space = 0;
2829 }
2830 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
2831 { // pulse & pause timings correct for "0"?
2832 ANALYZE_PUTCHAR ('0');
2833 ANALYZE_NEWLINE ();
2834 irmp_store_bit (0);
2835 last_value = 0;
2836 wait_for_space = 0;
2837 }
2838 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
2839 {
2840 ANALYZE_PUTCHAR (last_value + '0');
2841 ANALYZE_NEWLINE ();
2842 irmp_store_bit (last_value);
2843 wait_for_space = 0;
2844 }
2845 else
2846 { // timing incorrect!
2847 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);
2848 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2849 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2850 irmp_pause_time = 0;
2851 }
2852 }
2853 }
2854 else
2855 { // timing incorrect!
2856 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);
2857 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2858 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2859 irmp_pause_time = 0;
2860 }
2861 }
2862 else
2863 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
2864
2865 if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
2866 irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2867 { // pulse & pause timings correct for "1"?
2868 ANALYZE_PUTCHAR ('1');
2869 ANALYZE_NEWLINE ();
2870 irmp_store_bit (1);
2871 wait_for_space = 0;
2872 }
2873 else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
2874 irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
2875 { // pulse & pause timings correct for "0"?
2876 ANALYZE_PUTCHAR ('0');
2877 ANALYZE_NEWLINE ();
2878 irmp_store_bit (0);
2879 wait_for_space = 0;
2880 }
2881 else
2882 #if IRMP_SUPPORT_KATHREIN_PROTOCOL
2883
2884 if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL &&
2885 irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX &&
2886 (((irmp_bit == 8 || irmp_bit == 6) &&
2887 irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) ||
2888 (irmp_bit == 12 &&
2889 irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX)))
2890
2891 {
2892 if (irmp_bit == 8)
2893 {
2894 irmp_bit++;
2895 ANALYZE_PUTCHAR ('S');
2896 ANALYZE_NEWLINE ();
2897 irmp_tmp_command <<= 1;
2898 }
2899 else
2900 {
2901 ANALYZE_PUTCHAR ('S');
2902 ANALYZE_NEWLINE ();
2903 irmp_store_bit (1);
2904 }
2905 wait_for_space = 0;
2906 }
2907 else
2908 #endif // IRMP_SUPPORT_KATHREIN_PROTOCOL
2909 { // timing incorrect!
2910 ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2911 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
2912 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2913 irmp_pause_time = 0;
2914 }
2915
2916 irmp_pulse_time = 1; // set counter to 1, not 0
2917 }
2918 }
2919 else
2920 { // counting the pulse length ...
2921 if (! irmp_input) // still light?
2922 { // yes...
2923 irmp_pulse_time++; // increment counter
2924 }
2925 else
2926 { // now it's dark!
2927 wait_for_space = 1; // let's count the time (see above)
2928 irmp_pause_time = 1; // set pause counter to 1, not 0
2929 }
2930 }
2931
2932 if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received?
2933 {
2934 if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN)
2935 {
2936 repetition_frame_number++;
2937 }
2938 else
2939 {
2940 repetition_frame_number = 0;
2941 }
2942
2943 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2944 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
2945 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
2946 {
2947 ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2948 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
2949 repetition_len = 0;
2950 }
2951 else
2952 #endif
2953
2954 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
2955 // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame
2956 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1)
2957 {
2958 ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2959 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
2960 repetition_len = 0;
2961 }
2962 else
2963 #endif
2964
2965 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2966 // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2967 if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))
2968 {
2969 ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2970 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
2971 repetition_len = 0;
2972 }
2973 else
2974 #endif
2975
2976 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2977 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2978 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
2979 {
2980 ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2981 repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN);
2982 repetition_len = 0;
2983 }
2984 else
2985 #endif
2986
2987 {
2988 ANALYZE_PRINTF ("%8d code detected, length = %d\n", time_counter, irmp_bit);
2989 irmp_ir_detected = TRUE;
2990
2991 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2992 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2993 { // check for repetition frame
2994 if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
2995 {
2996 irmp_tmp_command = last_irmp_denon_command; // use command received before!
2997
2998 irmp_protocol = irmp_param.protocol; // store protocol
2999 irmp_address = irmp_tmp_address; // store address
3000 irmp_command = irmp_tmp_command ; // store command
3001 }
3002 else
3003 {
3004 ANALYZE_PRINTF ("waiting for inverted command repetition\n");
3005 irmp_ir_detected = FALSE;
3006 last_irmp_denon_command = irmp_tmp_command;
3007 }
3008 }
3009 else
3010 #endif // IRMP_SUPPORT_DENON_PROTOCOL
3011
3012 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
3013 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
3014 { // Grundig start frame?
3015 ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
3016 irmp_ir_detected = FALSE;
3017 }
3018 else
3019 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
3020
3021 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
3022 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
3023 { // Nokia start frame?
3024 ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n");
3025 irmp_ir_detected = FALSE;
3026 }
3027 else
3028 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
3029 {
3030 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3031 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame
3032 {
3033 if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX)
3034 {
3035 ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_len = %d\n", repetition_len);
3036 irmp_tmp_address = last_irmp_address; // address is last address
3037 irmp_tmp_command = last_irmp_command; // command is last command
3038 irmp_flags |= IRMP_FLAG_REPETITION;
3039 repetition_len = 0;
3040 }
3041 else
3042 {
3043 ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n",
3044 repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX);
3045 irmp_ir_detected = FALSE;
3046 }
3047 }
3048 #endif // IRMP_SUPPORT_NEC_PROTOCOL
3049
3050 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3051 if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL)
3052 {
3053 uint8_t xor;
3054 // ANALYZE_PRINTF ("0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
3055 // xor_check[0], xor_check[1], xor_check[2], xor_check[3], xor_check[4], xor_check[5]);
3056
3057 xor = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4);
3058
3059 if (xor != (xor_check[2] & 0x0F))
3060 {
3061 ANALYZE_PRINTF ("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor, xor_check[2] & 0x0F);
3062 irmp_ir_detected = FALSE;
3063 }
3064
3065 xor = xor_check[2] ^ xor_check[3] ^ xor_check[4];
3066
3067 if (xor != xor_check[5])
3068 {
3069 ANALYZE_PRINTF ("error 4: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor, xor_check[5]);
3070 irmp_ir_detected = FALSE;
3071 }
3072 }
3073 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
3074
3075 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
3076 if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode = 6?
3077 {
3078 irmp_protocol = IRMP_RC6A_PROTOCOL;
3079 }
3080 else
3081 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
3082
3083 irmp_protocol = irmp_param.protocol;
3084
3085 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
3086 if (irmp_param.protocol == IRMP_FDC_PROTOCOL)
3087 {
3088 if (irmp_tmp_command & 0x000F) // released key?
3089 {
3090 irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80; // yes, set bit 7
3091 }
3092 else
3093 {
3094 irmp_tmp_command >>= 4; // no, it's a pressed key
3095 }
3096 irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00; // 000000CCCCAAAAAA -> 0000CCCC00000000
3097 irmp_tmp_address &= 0x003F;
3098 }
3099 #endif
3100
3101 irmp_address = irmp_tmp_address; // store address
3102 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
3103 last_irmp_address = irmp_tmp_address; // store as last address, too
3104 #endif
3105
3106 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
3107 if (irmp_param.protocol == IRMP_RC5_PROTOCOL)
3108 {
3109 irmp_tmp_command |= rc5_cmd_bit6; // store bit 6
3110 }
3111 #endif
3112 irmp_command = irmp_tmp_command; // store command
3113
3114 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
3115 irmp_id = irmp_tmp_id;
3116 #endif
3117 }
3118 }
3119
3120 if (irmp_ir_detected)
3121 {
3122 if (last_irmp_command == irmp_command &&
3123 last_irmp_address == irmp_address &&
3124 repetition_len < IRMP_KEY_REPETITION_LEN)
3125 {
3126 irmp_flags |= IRMP_FLAG_REPETITION;
3127 }
3128
3129 last_irmp_address = irmp_tmp_address; // store as last address, too
3130 last_irmp_command = irmp_tmp_command; // store as last command, too
3131
3132 repetition_len = 0;
3133 }
3134 else
3135 {
3136 ANALYZE_ONLY_NORMAL_PUTCHAR ('\n');
3137 }
3138
3139 irmp_start_bit_detected = 0; // and wait for next start bit
3140 irmp_tmp_command = 0;
3141 irmp_pulse_time = 0;
3142 irmp_pause_time = 0;
3143
3144 #if IRMP_SUPPORT_JVC_PROTOCOL == 1
3145 if (irmp_protocol == IRMP_JVC_PROTOCOL) // the stop bit of JVC frame is also start bit of next frame
3146 { // set pulse time here!
3147 irmp_pulse_time = ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME));
3148 }
3149 #endif // IRMP_SUPPORT_JVC_PROTOCOL == 1
3150 }
3151 }
3152 }
3153 return (irmp_ir_detected);
3154 }
3155
3156 #ifdef ANALYZE
3157
3158 /*---------------------------------------------------------------------------------------------------------------------------------------------------
3159 * main functions - for Unix/Linux + Windows only!
3160 *
3161 * AVR: see main.c!
3162 *
3163 * Compile it under linux with:
3164 * cc irmp.c -o irmp
3165 *
3166 * usage: ./irmp [-v|-s|-a|-l|-p] < file
3167 *
3168 * options:
3169 * -v verbose
3170 * -s silent
3171 * -a analyze
3172 * -l list pulse/pauses
3173 * -p print timings
3174 *---------------------------------------------------------------------------------------------------------------------------------------------------
3175 */
3176
3177 static void
3178 print_timings (void)
3179 {
3180 printf ("IRMP_TIMEOUT_LEN: %d [%d byte(s)]\n", IRMP_TIMEOUT_LEN, sizeof (PAUSE_LEN));
3181 printf ("IRMP_KEY_REPETITION_LEN %d\n", IRMP_KEY_REPETITION_LEN);
3182 puts ("");
3183 printf ("PROTOCOL S S-PULSE S-PAUSE PULSE-0 PAUSE-0 PULSE-1 PAUSE-1\n");
3184 printf ("====================================================================================\n");
3185 printf ("SIRCS 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3186 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX,
3187 SIRCS_0_PULSE_LEN_MIN, SIRCS_0_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX,
3188 SIRCS_1_PULSE_LEN_MIN, SIRCS_1_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX);
3189
3190 printf ("NEC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3191 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX,
3192 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3193 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3194
3195 printf ("NEC (rep) 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3196 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,
3197 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX,
3198 NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX);
3199
3200 printf ("SAMSUNG 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3201 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX,
3202 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_0_PAUSE_LEN_MIN, SAMSUNG_0_PAUSE_LEN_MAX,
3203 SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_1_PAUSE_LEN_MIN, SAMSUNG_1_PAUSE_LEN_MAX);
3204
3205 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3206 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX,
3207 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_0_PAUSE_LEN_MIN, MATSUSHITA_0_PAUSE_LEN_MAX,
3208 MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_1_PAUSE_LEN_MIN, MATSUSHITA_1_PAUSE_LEN_MAX);
3209
3210 printf ("KASEIKYO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3211 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX,
3212 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_0_PAUSE_LEN_MIN, KASEIKYO_0_PAUSE_LEN_MAX,
3213 KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_1_PAUSE_LEN_MIN, KASEIKYO_1_PAUSE_LEN_MAX);
3214
3215 printf ("RECS80 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3216 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX,
3217 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_0_PAUSE_LEN_MIN, RECS80_0_PAUSE_LEN_MAX,
3218 RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_1_PAUSE_LEN_MIN, RECS80_1_PAUSE_LEN_MAX);
3219
3220 printf ("RC5 1 %3d - %3d %3d - %3d %3d - %3d\n",
3221 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
3222 RC5_BIT_LEN_MIN, RC5_BIT_LEN_MAX);
3223
3224 printf ("DENON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3225 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
3226 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX,
3227 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX);
3228
3229 printf ("RC6 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3230 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX,
3231 RC6_BIT_PULSE_LEN_MIN, RC6_BIT_PULSE_LEN_MAX, RC6_BIT_PAUSE_LEN_MIN, RC6_BIT_PAUSE_LEN_MAX);
3232
3233 printf ("RECS80EXT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3234 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX,
3235 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_0_PAUSE_LEN_MIN, RECS80EXT_0_PAUSE_LEN_MAX,
3236 RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_1_PAUSE_LEN_MIN, RECS80EXT_1_PAUSE_LEN_MAX);
3237
3238 printf ("NUBERT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3239 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX,
3240 NUBERT_0_PULSE_LEN_MIN, NUBERT_0_PULSE_LEN_MAX, NUBERT_0_PAUSE_LEN_MIN, NUBERT_0_PAUSE_LEN_MAX,
3241 NUBERT_1_PULSE_LEN_MIN, NUBERT_1_PULSE_LEN_MAX, NUBERT_1_PAUSE_LEN_MIN, NUBERT_1_PAUSE_LEN_MAX);
3242
3243 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
3244 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
3245 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
3246
3247 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
3248 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
3249 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
3250
3251 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
3252 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
3253 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
3254
3255 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
3256 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
3257 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
3258
3259 printf ("BANG_OLUFSEN - %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3260 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_0_PAUSE_LEN_MIN, BANG_OLUFSEN_0_PAUSE_LEN_MAX,
3261 BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_1_PAUSE_LEN_MIN, BANG_OLUFSEN_1_PAUSE_LEN_MAX);
3262
3263 printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d %3d - %3d\n",
3264 GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX,
3265 GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX,
3266 GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_BIT_LEN_MAX);
3267
3268 printf ("SIEMENS/RUWIDO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3269 SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX,
3270 SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX,
3271 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX,
3272 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX,
3273 SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN_2, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX_2,
3274 SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN_2, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX_2);
3275
3276 printf ("FDC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3277 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX,
3278 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_0_PAUSE_LEN_MIN, FDC_0_PAUSE_LEN_MAX,
3279 FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_1_PAUSE_LEN_MIN, FDC_1_PAUSE_LEN_MAX);
3280
3281 printf ("RCCAR 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3282 RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX,
3283 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_0_PAUSE_LEN_MIN, RCCAR_0_PAUSE_LEN_MAX,
3284 RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_1_PAUSE_LEN_MIN, RCCAR_1_PAUSE_LEN_MAX);
3285
3286 printf ("NIKON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n",
3287 NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX,
3288 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX,
3289 NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX);
3290 }
3291
3292 void
3293 print_spectrum (char * text, int * buf, int is_pulse)
3294 {
3295 int i;
3296 int j;
3297 int min;
3298 int max;
3299 int max_value = 0;
3300 int value;
3301 int sum = 0;
3302 int counter = 0;
3303 double average = 0;
3304 double tolerance;
3305
3306 puts ("-------------------------------------------------------------------------------");
3307 printf ("%s:\n", text);
3308
3309 for (i = 0; i < 256; i++)
3310 {
3311 if (buf[i] > max_value)
3312 {
3313 max_value = buf[i];
3314 }
3315 }
3316
3317 for (i = 1; i < 100; i++)
3318 {
3319 if (buf[i] > 0)
3320 {
3321 printf ("%3d ", i);
3322 value = (buf[i] * 60) / max_value;
3323
3324 for (j = 0; j < value; j++)
3325 {
3326 putchar ('o');
3327 }
3328 printf (" %d\n", buf[i]);
3329
3330 sum += i * buf[i];
3331 counter += buf[i];
3332 }
3333 else
3334 {
3335 max = i - 1;
3336
3337 if (counter > 0)
3338 {
3339 average = (float) sum / (float) counter;
3340
3341 if (is_pulse)
3342 {
3343 printf ("pulse ");
3344 }
3345 else
3346 {
3347 printf ("pause ");
3348 }
3349
3350 printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS);
3351 printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS);
3352 printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS);
3353
3354 tolerance = (max - average);
3355
3356 if (average - min > tolerance)
3357 {
3358 tolerance = average - min;
3359 }
3360
3361 tolerance = tolerance * 100 / average;
3362 printf ("tol: %4.1f%%\n", tolerance);
3363 }
3364
3365 counter = 0;
3366 sum = 0;
3367 min = i + 1;
3368 }
3369 }
3370 }
3371
3372 #define STATE_LEFT_SHIFT 0x01
3373 #define STATE_RIGHT_SHIFT 0x02
3374 #define STATE_LEFT_CTRL 0x04
3375 #define STATE_LEFT_ALT 0x08
3376 #define STATE_RIGHT_ALT 0x10
3377
3378 #define KEY_ESCAPE 0x1B // keycode = 0x006e
3379 #define KEY_MENUE 0x80 // keycode = 0x0070
3380 #define KEY_BACK 0x81 // keycode = 0x0071
3381 #define KEY_FORWARD 0x82 // keycode = 0x0072
3382 #define KEY_ADDRESS 0x83 // keycode = 0x0073
3383 #define KEY_WINDOW 0x84 // keycode = 0x0074
3384 #define KEY_1ST_PAGE 0x85 // keycode = 0x0075
3385 #define KEY_STOP 0x86 // keycode = 0x0076
3386 #define KEY_MAIL 0x87 // keycode = 0x0077
3387 #define KEY_FAVORITES 0x88 // keycode = 0x0078
3388 #define KEY_NEW_PAGE 0x89 // keycode = 0x0079
3389 #define KEY_SETUP 0x8A // keycode = 0x007a
3390 #define KEY_FONT 0x8B // keycode = 0x007b
3391 #define KEY_PRINT 0x8C // keycode = 0x007c
3392 #define KEY_ON_OFF 0x8E // keycode = 0x007c
3393
3394 #define KEY_INSERT 0x90 // keycode = 0x004b
3395 #define KEY_DELETE 0x91 // keycode = 0x004c
3396 #define KEY_LEFT 0x92 // keycode = 0x004f
3397 #define KEY_HOME 0x93 // keycode = 0x0050
3398 #define KEY_END 0x94 // keycode = 0x0051
3399 #define KEY_UP 0x95 // keycode = 0x0053
3400 #define KEY_DOWN 0x96 // keycode = 0x0054
3401 #define KEY_PAGE_UP 0x97 // keycode = 0x0055
3402 #define KEY_PAGE_DOWN 0x98 // keycode = 0x0056
3403 #define KEY_RIGHT 0x99 // keycode = 0x0059
3404 #define KEY_MOUSE_1 0x9E // keycode = 0x0400
3405 #define KEY_MOUSE_2 0x9F // keycode = 0x0800
3406
3407 static uint8_t
3408 get_fdc_key (uint16_t cmd)
3409 {
3410 static uint8_t key_table[128] =
3411 {
3412 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
3413 0, '^', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 0, '\b',
3414 '\t','q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 0, 0, 'a',
3415 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', '\r', 0, '<', 'y', 'x',
3416 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, 0, 0, ' ', 0, 0,
3417
3418 0, '°', '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 0, '\b',
3419 '\t','Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 0, 0, 'A',
3420 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'','\r', 0, '>', 'Y', 'X',
3421 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, 0, 0, ' ', 0, 0
3422 };
3423 static uint8_t state;
3424
3425 uint8_t key = 0;
3426
3427 switch (cmd)
3428 {
3429 case 0x002C: state |= STATE_LEFT_SHIFT; break; // pressed left shift
3430 case 0x00AC: state &= ~STATE_LEFT_SHIFT; break; // released left shift
3431 case 0x0039: state |= STATE_RIGHT_SHIFT; break; // pressed right shift
3432 case 0x00B9: state &= ~STATE_RIGHT_SHIFT; break; // released right shift
3433 case 0x003A: state |= STATE_LEFT_CTRL; break; // pressed left ctrl
3434 case 0x00BA: state &= ~STATE_LEFT_CTRL; break; // released left ctrl
3435 case 0x003C: state |= STATE_LEFT_ALT; break; // pressed left alt
3436 case 0x00BC: state &= ~STATE_LEFT_ALT; break; // released left alt
3437 case 0x003E: state |= STATE_RIGHT_ALT; break; // pressed left alt
3438 case 0x00BE: state &= ~STATE_RIGHT_ALT; break; // released left alt
3439
3440 case 0x006e: key = KEY_ESCAPE; break;
3441 case 0x004b: key = KEY_INSERT; break;
3442 case 0x004c: key = KEY_DELETE; break;
3443 case 0x004f: key = KEY_LEFT; break;
3444 case 0x0050: key = KEY_HOME; break;
3445 case 0x0051: key = KEY_END; break;
3446 case 0x0053: key = KEY_UP; break;
3447 case 0x0054: key = KEY_DOWN; break;
3448 case 0x0055: key = KEY_PAGE_UP; break;
3449 case 0x0056: key = KEY_PAGE_DOWN; break;
3450 case 0x0059: key = KEY_RIGHT; break;
3451 case 0x0400: key = KEY_MOUSE_1; break;
3452 case 0x0800: key = KEY_MOUSE_2; break;
3453
3454 default:
3455 {
3456 if (!(cmd & 0x80)) // pressed key
3457 {
3458 if (cmd >= 0x70 && cmd <= 0x7F) // function keys
3459 {
3460 key = cmd + 0x10; // 7x -> 8x
3461 }
3462 else if (cmd < 64) // key listed in key_table
3463 {
3464 if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT))
3465 {
3466 switch (cmd)
3467 {
3468 case 0x0003: key = '²'; break;
3469 case 0x0008: key = '{'; break;
3470 case 0x0009: key = '['; break;
3471 case 0x000A: key = ']'; break;
3472 case 0x000B: key = '}'; break;
3473 case 0x000C: key = '\\'; break;
3474 case 0x001C: key = '~'; break;
3475 case 0x002D: key = '|'; break;
3476 case 0x0034: key = 'µ'; break;
3477 }
3478 }
3479 else if (state & (STATE_LEFT_CTRL))
3480 {
3481 if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z')
3482 {
3483 key = key_table[cmd] - 'a' + 1;
3484 }
3485 else
3486 {
3487 key = key_table[cmd];
3488 }
3489 }
3490 else
3491 {
3492 int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0);
3493
3494 if (key_table[idx])
3495 {
3496 key = key_table[idx];
3497 }
3498 }
3499 }
3500 }
3501 break;
3502 }
3503 }
3504
3505 return (key);
3506 }
3507
3508 static int analyze = FALSE;
3509 static int list = FALSE;
3510 static IRMP_DATA irmp_data;
3511
3512 static void
3513 next_tick (void)
3514 {
3515 if (! analyze && ! list)
3516 {
3517 (void) irmp_ISR ();
3518
3519 if (irmp_get_data (&irmp_data))
3520 {
3521 uint8_t key;
3522
3523 ANALYZE_ONLY_NORMAL_PUTCHAR (' ');
3524
3525 if (verbose)
3526 {
3527 printf ("%8d ", time_counter);
3528 }
3529
3530 if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0)
3531 {
3532 if ((key >= 0x20 && key < 0x7F) || key >= 0xA0)
3533 {
3534 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n",
3535 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key);
3536 }
3537 else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys
3538 {
3539 char * p = (char *) NULL;
3540
3541 switch (key)
3542 {
3543 case '\t' : p = "TAB"; break;
3544 case '\r' : p = "CR"; break;
3545 case KEY_ESCAPE : p = "ESCAPE"; break;
3546 case KEY_MENUE : p = "MENUE"; break;
3547 case KEY_BACK : p = "BACK"; break;
3548 case KEY_FORWARD : p = "FORWARD"; break;
3549 case KEY_ADDRESS : p = "ADDRESS"; break;
3550 case KEY_WINDOW : p = "WINDOW"; break;
3551 case KEY_1ST_PAGE : p = "1ST_PAGE"; break;
3552 case KEY_STOP : p = "STOP"; break;
3553 case KEY_MAIL : p = "MAIL"; break;
3554 case KEY_FAVORITES : p = "FAVORITES"; break;
3555 case KEY_NEW_PAGE : p = "NEW_PAGE"; break;
3556 case KEY_SETUP : p = "SETUP"; break;
3557 case KEY_FONT : p = "FONT"; break;
3558 case KEY_PRINT : p = "PRINT"; break;
3559 case KEY_ON_OFF : p = "ON_OFF"; break;
3560
3561 case KEY_INSERT : p = "INSERT"; break;
3562 case KEY_DELETE : p = "DELETE"; break;
3563 case KEY_LEFT : p = "LEFT"; break;
3564 case KEY_HOME : p = "HOME"; break;
3565 case KEY_END : p = "END"; break;
3566 case KEY_UP : p = "UP"; break;
3567 case KEY_DOWN : p = "DOWN"; break;
3568 case KEY_PAGE_UP : p = "PAGE_UP"; break;
3569 case KEY_PAGE_DOWN : p = "PAGE_DOWN"; break;
3570 case KEY_RIGHT : p = "RIGHT"; break;
3571 case KEY_MOUSE_1 : p = "KEY_MOUSE_1"; break;
3572 case KEY_MOUSE_2 : p = "KEY_MOUSE_2"; break;
3573 default : p = "<UNKNWON>"; break;
3574 }
3575
3576 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n",
3577 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p);
3578 }
3579 else
3580 {
3581 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n",
3582 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key);
3583 }
3584 }
3585 else
3586 {
3587 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n",
3588 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags);
3589 }
3590 }
3591 }
3592 }
3593
3594 int
3595 main (int argc, char ** argv)
3596 {
3597 int i;
3598 int ch;
3599 int last_ch = 0;
3600 int pulse = 0;
3601 int pause = 0;
3602
3603 int start_pulses[256];
3604 int start_pauses[256];
3605 int pulses[256];
3606 int pauses[256];
3607
3608 int first_pulse = TRUE;
3609 int first_pause = TRUE;
3610
3611 if (argc == 2)
3612 {
3613 if (! strcmp (argv[1], "-v"))
3614 {
3615 verbose = TRUE;
3616 }
3617 else if (! strcmp (argv[1], "-l"))
3618 {
3619 list = TRUE;
3620 }
3621 else if (! strcmp (argv[1], "-a"))
3622 {
3623 analyze = TRUE;
3624 }
3625 else if (! strcmp (argv[1], "-s"))
3626 {
3627 silent = TRUE;
3628 }
3629 else if (! strcmp (argv[1], "-p"))
3630 {
3631 print_timings ();
3632 return (0);
3633 }
3634 }
3635
3636 for (i = 0; i < 256; i++)
3637 {
3638 start_pulses[i] = 0;
3639 start_pauses[i] = 0;
3640 pulses[i] = 0;
3641 pauses[i] = 0;
3642 }
3643
3644 IRMP_PIN = 0xFF;
3645
3646 while ((ch = getchar ()) != EOF)
3647 {
3648 if (ch == '_' || ch == '0')
3649 {
3650 if (last_ch != ch)
3651 {
3652 if (pause > 0)
3653 {
3654 if (list)
3655 {
3656 printf ("pause: %d\n", pause);
3657 }
3658
3659 if (analyze)
3660 {
3661 if (first_pause)
3662 {
3663 if (pause < 256)
3664 {
3665 start_pauses[pause]++;
3666 }
3667 first_pause = FALSE;
3668 }
3669 else
3670 {
3671 if (pause < 256)
3672 {
3673 pauses[pause]++;
3674 }
3675 }
3676 }
3677 }
3678 pause = 0;
3679 }
3680 pulse++;
3681 IRMP_PIN = 0x00;
3682 }
3683 else if (ch == 0xaf || ch == '-' || ch == '1')
3684 {
3685 if (last_ch != ch)
3686 {
3687 if (list)
3688 {
3689 printf ("pulse: %d ", pulse);
3690 }
3691
3692 if (analyze)
3693 {
3694 if (first_pulse)
3695 {
3696 if (pulse < 256)
3697 {
3698 start_pulses[pulse]++;
3699 }
3700 first_pulse = FALSE;
3701 }
3702 else
3703 {
3704 if (pulse < 256)
3705 {
3706 pulses[pulse]++;
3707 }
3708 }
3709 }
3710 pulse = 0;
3711 }
3712
3713 pause++;
3714 IRMP_PIN = 0xff;
3715 }
3716 else if (ch == '\n')
3717 {
3718 IRMP_PIN = 0xff;
3719
3720 if (list && pause > 0)
3721 {
3722 printf ("pause: %d\n", pause);
3723 }
3724 pause = 0;
3725
3726 if (! analyze)
3727 {
3728 for (i = 0; i < (int) ((8000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 800 msec
3729 {
3730 next_tick ();
3731 }
3732 }
3733 first_pulse = TRUE;
3734 first_pause = TRUE;
3735 }
3736 else if (ch == '#')
3737 {
3738 if (analyze)
3739 {
3740 while ((ch = getchar()) != '\n' && ch != EOF)
3741 {
3742 ;
3743 }
3744 }
3745 else
3746 {
3747 puts ("-------------------------------------------------------------------");
3748 putchar (ch);
3749
3750 while ((ch = getchar()) != '\n' && ch != EOF)
3751 {
3752 if (ch != '\r') // ignore CR in DOS/Windows files
3753 {
3754 putchar (ch);
3755 }
3756 }
3757 putchar ('\n');
3758 }
3759
3760 }
3761
3762 last_ch = ch;
3763
3764 next_tick ();
3765 }
3766
3767 if (analyze)
3768 {
3769 print_spectrum ("START PULSES", start_pulses, TRUE);
3770 print_spectrum ("START PAUSES", start_pauses, FALSE);
3771 print_spectrum ("PULSES", pulses, TRUE);
3772 print_spectrum ("PAUSES", pauses, FALSE);
3773 puts ("-------------------------------------------------------------------------------");
3774 }
3775 return 0;
3776 }
3777
3778 #endif // ANALYZE