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