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