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