]> cloudbase.mooo.com Git - irmp.git/blob - irmp.c
git-svn-id: svn://mikrocontroller.net/irmp@23 aeb2e35e-bfc4-4214-b83c-9e8de998ed28
[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.39 2010/06/10 10:09:47 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 * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar)
240 * -----------------------------------------------------------------------------------------
241 *
242 * frame: 1 start bit + 22 data bits + 1 stop bit
243 * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits
244 *
245 * European version: T = 456us
246 * USA & Canada version: T = 422us
247 *
248 * start bit: data "0": data "1": stop bit:
249 * 8T 8T 2T 2T 2T 6T 2T
250 * -------------____________ ------_____ ------_____________ ------_______....
251 * 3648us 3648us 912us 912us 912us 2736us 912us (Europe)
252 * 3376us 3376us 844us 844us 844us 2532us 844us (US)
253 *
254 *---------------------------------------------------------------------------------------------------------------------------------------------------
255 *
256 * This program is free software; you can redistribute it and/or modify
257 * it under the terms of the GNU General Public License as published by
258 * the Free Software Foundation; either version 2 of the License, or
259 * (at your option) any later version.
260 *---------------------------------------------------------------------------------------------------------------------------------------------------
261 */
262
263 #if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR
264 #define PIC_CCS_COMPILER
265 #endif
266
267 #ifdef unix // test on linux/unix
268 #include <stdio.h>
269 #include <unistd.h>
270 #include <stdlib.h>
271 #include <string.h>
272 #include <inttypes.h>
273
274 #define DEBUG
275 #define PROGMEM
276 #define memcpy_P memcpy
277
278 #else // not unix:
279
280 #ifdef WIN32
281 #include <stdio.h>
282 #include <string.h>
283 typedef unsigned char uint8_t;
284 typedef unsigned short uint16_t;
285 #define DEBUG
286 #define PROGMEM
287 #define memcpy_P memcpy
288
289 #else
290
291 #ifndef CODEVISION
292
293 #ifdef PIC_CCS_COMPILER
294
295 #include <string.h>
296 typedef unsigned int8 uint8_t;
297 typedef unsigned int16 uint16_t;
298 #define PROGMEM
299 #define memcpy_P memcpy
300
301 #else // AVR:
302
303 #include <inttypes.h>
304 #include <stdio.h>
305 #include <string.h>
306 #include <avr/io.h>
307 #include <util/delay.h>
308 #include <avr/pgmspace.h>
309
310 #endif // PIC_CCS_COMPILER
311 #endif // CODEVISION
312
313 #endif // windows
314 #endif // unix
315
316 #include "irmp.h"
317 #include "irmpconfig.h"
318
319 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1
320 #define IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL 1
321 #else
322 #define IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL 0
323 #endif
324
325 #define IRMP_TIMEOUT_TIME 16500.0e-6 // timeout after 16.5 ms darkness
326 #define IRMP_TIMEOUT_LEN (uint8_t)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)
327 #define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec
328
329 #define MIN_TOLERANCE_00 1.0 // -0%
330 #define MAX_TOLERANCE_00 1.0 // +0%
331
332 #define MIN_TOLERANCE_05 0.95 // -5%
333 #define MAX_TOLERANCE_05 1.05 // +5%
334
335 #define MIN_TOLERANCE_10 0.9 // -10%
336 #define MAX_TOLERANCE_10 1.1 // +10%
337
338 #define MIN_TOLERANCE_15 0.85 // -15%
339 #define MAX_TOLERANCE_15 1.15 // +15%
340
341 #define MIN_TOLERANCE_20 0.8 // -20%
342 #define MAX_TOLERANCE_20 1.2 // +20%
343
344 #define MIN_TOLERANCE_30 0.7 // -30%
345 #define MAX_TOLERANCE_30 1.3 // +30%
346
347 #define MIN_TOLERANCE_40 0.6 // -40%
348 #define MAX_TOLERANCE_40 1.4 // +40%
349
350 #define MIN_TOLERANCE_50 0.5 // -50%
351 #define MAX_TOLERANCE_50 1.5 // +50%
352
353 #define MIN_TOLERANCE_60 0.4 // -60%
354 #define MAX_TOLERANCE_60 1.6 // +60%
355
356 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
357 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
358 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
359 #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
360 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
361 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
362 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
363 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
364 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
365 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
366
367 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
368 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
369 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
370 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
371 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
372 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
373 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
374 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
375 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
376 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
377 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
378 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
379
380 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
381 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
382 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
383 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
384 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
385 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
386 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
387 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
388 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1)
389 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1)
390
391 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
392 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
393 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
394 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
395 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
396 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
397 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
398 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
399 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
400 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
401
402 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
403 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
404 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
405 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
406 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
407 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_60 + 0.5) + 1)
408 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
409 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
410 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
411 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
412
413 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
414 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
415 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
416 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
417 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
418 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
419 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
420 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
421 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
422 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
423
424 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
425 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
426 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
427 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
428
429 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
430 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
431 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
432 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
433 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
434 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
435
436 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
437 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
438 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
439 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
440 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
441 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
442 #define RC6_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
443 #define RC6_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
444
445 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
446 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
447 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
448 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
449 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
450 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
451 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
452 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
453 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
454 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
455
456 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
457 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
458 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
459 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
460 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
461 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
462 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
463 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
464 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
465 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
466 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
467 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
468
469 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
470 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
471 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
472 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
473 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
474 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
475 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
476 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
477 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
478 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
479 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
480 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // 10% is too big (uint8_t)
481 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
482 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
483 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
484 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
485 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
486 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
487 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
488 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
489 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
490 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
491 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
492 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
493 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
494 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
495
496 #define GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
497 #define GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
498 #define GRUNDIG_OR_NOKIA_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
499 #define GRUNDIG_OR_NOKIA_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
500 #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1)
501 #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
502
503 #define SIEMENS_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) - 1)
504 #define SIEMENS_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) + 1)
505 #define SIEMENS_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) - 1)
506 #define SIEMENS_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME * 1 + 0.5) + 1)
507
508 #define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
509 #define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
510 #define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
511 #define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
512 #define FDC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
513 #define FDC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
514 #define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
515 #define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
516 #define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
517 #define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
518 #define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
519 #define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
520
521 #define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t!
522
523 #ifdef DEBUG
524 #define DEBUG_PUTCHAR(a) { if (! silent) { putchar (a); } }
525 #define DEBUG_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } }
526 #define DEBUG_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } }
527 #define DEBUG_NEWLINE() { if (verbose) { putchar ('\n'); } }
528 static int silent;
529 static int time_counter;
530 static int verbose;
531 #else
532 #define DEBUG_PUTCHAR(a)
533 #define DEBUG_ONLY_NORMAL_PUTCHAR(a)
534 #define DEBUG_PRINTF(...)
535 #define DEBUG_NEWLINE()
536 #endif
537
538 #if IRMP_LOGGING == 1
539 #define BAUD 9600L
540 #include <util/setbaud.h>
541
542 #ifdef UBRR0H
543
544 #define UART0_UBRRH UBRR0H
545 #define UART0_UBRRL UBRR0L
546 #define UART0_UCSRA UCSR0A
547 #define UART0_UCSRB UCSR0B
548 #define UART0_UCSRC UCSR0C
549 #define UART0_UDRE_BIT_VALUE (1<<UDRE0)
550 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ01)
551 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ00)
552 #ifdef URSEL0
553 #define UART0_URSEL_BIT_VALUE (1<<URSEL0)
554 #else
555 #define UART0_URSEL_BIT_VALUE (0)
556 #endif
557 #define UART0_TXEN_BIT_VALUE (1<<TXEN0)
558 #define UART0_UDR UDR0
559
560 #else
561
562 #define UART0_UBRRH UBRRH
563 #define UART0_UBRRL UBRRL
564 #define UART0_UCSRA UCSRA
565 #define UART0_UCSRB UCSRB
566 #define UART0_UCSRC UCSRC
567 #define UART0_UDRE_BIT_VALUE (1<<UDRE)
568 #define UART0_UCSZ1_BIT_VALUE (1<<UCSZ1)
569 #define UART0_UCSZ0_BIT_VALUE (1<<UCSZ0)
570 #ifdef URSEL
571 #define UART0_URSEL_BIT_VALUE (1<<URSEL)
572 #else
573 #define UART0_URSEL_BIT_VALUE (0)
574 #endif
575 #define UART0_TXEN_BIT_VALUE (1<<TXEN)
576 #define UART0_UDR UDR
577
578 #endif
579
580 /*---------------------------------------------------------------------------------------------------------------------------------------------------
581 * Initialize UART
582 * @details Initializes UART
583 *---------------------------------------------------------------------------------------------------------------------------------------------------
584 */
585 void
586 irmp_uart_init (void)
587 {
588 UART0_UBRRH = UBRRH_VALUE; // set baud rate
589 UART0_UBRRL = UBRRL_VALUE;
590
591 #if USE_2X
592 UART0_UCSRA = (1<<U2X);
593 #else
594 UART0_UCSRA = 0;
595 #endif
596
597 UART0_UCSRC = UART0_UCSZ1_BIT_VALUE | UART0_UCSZ0_BIT_VALUE | UART0_URSEL_BIT_VALUE;
598 UART0_UCSRB |= UART0_TXEN_BIT_VALUE; // enable UART TX
599 }
600
601 /*---------------------------------------------------------------------------------------------------------------------------------------------------
602 * Send character
603 * @details Sends character
604 * @param ch character to be transmitted
605 *---------------------------------------------------------------------------------------------------------------------------------------------------
606 */
607 void
608 irmp_uart_putc (unsigned char ch)
609 {
610 while (!(UART0_UCSRA & UART0_UDRE_BIT_VALUE))
611 {
612 ;
613 }
614
615 UART0_UDR = ch;
616 }
617
618 /*---------------------------------------------------------------------------------------------------------------------------------------------------
619 * Log IR signal
620 *---------------------------------------------------------------------------------------------------------------------------------------------------
621 */
622
623 #define STARTCYCLES 2 // min count of zeros before start of logging
624 #define ENDBITS 1000 // number of sequenced highbits to detect end
625 #define DATALEN 700 // log buffer size
626
627 static void
628 irmp_log (uint8_t val)
629 {
630 static uint8_t buf[DATALEN]; // logging buffer
631 static uint16_t buf_idx; // number of written bits
632 static uint8_t startcycles; // current number of start-zeros
633 static uint16_t cnt; // counts sequenced highbits - to detect end
634
635 if (! val && (startcycles < STARTCYCLES) && !buf_idx) // prevent that single random zeros init logging
636 {
637 startcycles++;
638 }
639 else
640 {
641 startcycles = 0;
642
643 if (! val || (val && buf_idx != 0)) // start or continue logging on "0", "1" cannot init logging
644 {
645 if (buf_idx < DATALEN * 8) // index in range?
646 { // yes
647 if (val)
648 {
649 buf[(buf_idx / 8)] |= (1<<(buf_idx % 8)); // set bit
650 }
651 else
652 {
653 buf[(buf_idx / 8)] &= ~(1<<(buf_idx % 8)); // reset bit
654 }
655
656 buf_idx++;
657 }
658
659 if (val)
660 { // if high received then look at log-stop condition
661 cnt++;
662
663 if (cnt > ENDBITS)
664 { // if stop condition is true, output on uart
665 uint16_t i;
666
667 for (i = 0; i < STARTCYCLES; i++)
668 {
669 irmp_uart_putc ('0'); // the ignored starting zeros
670 }
671
672 for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars
673 {
674 uint8_t d = buf[i];
675 uint8_t j;
676
677 for (j = 0; j < 8; j++)
678 {
679 irmp_uart_putc ((d & 1) + '0');
680 d >>= 1;
681 }
682 }
683
684 irmp_uart_putc ('\n');
685 buf_idx = 0;
686 }
687 }
688 else
689 {
690 cnt = 0;
691 }
692 }
693 }
694 }
695
696 #else
697 #define irmp_log(val)
698 #endif
699
700 typedef struct
701 {
702 uint8_t protocol; // ir protocol
703 uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1
704 uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1
705 uint8_t pause_1_len_min; // minimum length of pause with bit value 1
706 uint8_t pause_1_len_max; // maximum length of pause with bit value 1
707 uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0
708 uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0
709 uint8_t pause_0_len_min; // minimum length of pause with bit value 0
710 uint8_t pause_0_len_max; // maximum length of pause with bit value 0
711 uint8_t address_offset; // address offset
712 uint8_t address_end; // end of address
713 uint8_t command_offset; // command offset
714 uint8_t command_end; // end of command
715 uint8_t complete_len; // complete length of frame
716 uint8_t stop_bit; // flag: frame has stop bit
717 uint8_t lsb_first; // flag: LSB first
718 } IRMP_PARAMETER;
719
720 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
721
722 static PROGMEM IRMP_PARAMETER sircs_param =
723 {
724 IRMP_SIRCS_PROTOCOL, // protocol: ir protocol
725 SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
726 SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
727 SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
728 SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
729 SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
730 SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
731 SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
732 SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
733 SIRCS_ADDRESS_OFFSET, // address_offset: address offset
734 SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address
735 SIRCS_COMMAND_OFFSET, // command_offset: command offset
736 SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command
737 SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
738 SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit
739 SIRCS_LSB // lsb_first: flag: LSB first
740 };
741
742 #endif
743
744 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
745
746 static PROGMEM IRMP_PARAMETER nec_param =
747 {
748 IRMP_NEC_PROTOCOL, // protocol: ir protocol
749 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
750 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
751 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
752 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
753 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
754 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
755 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
756 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
757 NEC_ADDRESS_OFFSET, // address_offset: address offset
758 NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address
759 NEC_COMMAND_OFFSET, // command_offset: command offset
760 NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command
761 NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
762 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
763 NEC_LSB // lsb_first: flag: LSB first
764 };
765
766 static PROGMEM IRMP_PARAMETER nec_rep_param =
767 {
768 IRMP_NEC_PROTOCOL, // protocol: ir protocol
769 NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
770 NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
771 NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
772 NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
773 NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
774 NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
775 NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
776 NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
777 0, // address_offset: address offset
778 0, // address_end: end of address
779 0, // command_offset: command offset
780 0, // command_end: end of command
781 0, // complete_len: complete length of frame
782 NEC_STOP_BIT, // stop_bit: flag: frame has stop bit
783 NEC_LSB // lsb_first: flag: LSB first
784 };
785
786 #endif
787
788 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
789
790 static PROGMEM IRMP_PARAMETER samsung_param =
791 {
792 IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol
793 SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
794 SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
795 SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
796 SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
797 SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
798 SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
799 SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
800 SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
801 SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset
802 SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address
803 SAMSUNG_COMMAND_OFFSET, // command_offset: command offset
804 SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command
805 SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame
806 SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit
807 SAMSUNG_LSB // lsb_first: flag: LSB first
808 };
809
810 #endif
811
812 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
813
814 static PROGMEM IRMP_PARAMETER matsushita_param =
815 {
816 IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol
817 MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
818 MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
819 MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
820 MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
821 MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
822 MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
823 MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
824 MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
825 MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset
826 MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address
827 MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset
828 MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command
829 MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame
830 MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit
831 MATSUSHITA_LSB // lsb_first: flag: LSB first
832 };
833
834 #endif
835
836 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
837
838 static PROGMEM IRMP_PARAMETER kaseikyo_param =
839 {
840 IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol
841 KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
842 KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
843 KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
844 KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
845 KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
846 KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
847 KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
848 KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
849 KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset
850 KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address
851 KASEIKYO_COMMAND_OFFSET, // command_offset: command offset
852 KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command
853 KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame
854 KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit
855 KASEIKYO_LSB // lsb_first: flag: LSB first
856 };
857
858 #endif
859
860 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
861
862 static PROGMEM IRMP_PARAMETER recs80_param =
863 {
864 IRMP_RECS80_PROTOCOL, // protocol: ir protocol
865 RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
866 RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
867 RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
868 RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
869 RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
870 RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
871 RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
872 RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
873 RECS80_ADDRESS_OFFSET, // address_offset: address offset
874 RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address
875 RECS80_COMMAND_OFFSET, // command_offset: command offset
876 RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command
877 RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame
878 RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit
879 RECS80_LSB // lsb_first: flag: LSB first
880 };
881
882 #endif
883
884 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
885
886 static PROGMEM IRMP_PARAMETER rc5_param =
887 {
888 IRMP_RC5_PROTOCOL, // protocol: ir protocol
889 RC5_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
890 RC5_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
891 RC5_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
892 RC5_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
893 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
894 1, // pulse_0_len_max: maximum length of pulse with bit value 0
895 1, // pause_0_len_min: minimum length of pause with bit value 0
896 1, // pause_0_len_max: maximum length of pause with bit value 0
897 RC5_ADDRESS_OFFSET, // address_offset: address offset
898 RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address
899 RC5_COMMAND_OFFSET, // command_offset: command offset
900 RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command
901 RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame
902 RC5_STOP_BIT, // stop_bit: flag: frame has stop bit
903 RC5_LSB // lsb_first: flag: LSB first
904 };
905
906 #endif
907
908 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
909
910 static PROGMEM IRMP_PARAMETER denon_param =
911 {
912 IRMP_DENON_PROTOCOL, // protocol: ir protocol
913 DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
914 DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
915 DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
916 DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
917 DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
918 DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
919 DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
920 DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
921 DENON_ADDRESS_OFFSET, // address_offset: address offset
922 DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address
923 DENON_COMMAND_OFFSET, // command_offset: command offset
924 DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command
925 DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame
926 DENON_STOP_BIT, // stop_bit: flag: frame has stop bit
927 DENON_LSB // lsb_first: flag: LSB first
928 };
929
930 #endif
931
932 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
933
934 static PROGMEM IRMP_PARAMETER rc6_param =
935 {
936 IRMP_RC6_PROTOCOL, // protocol: ir protocol
937 RC6_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
938 RC6_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
939 RC6_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
940 RC6_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
941 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
942 1, // pulse_0_len_max: maximum length of pulse with bit value 0
943 1, // pause_0_len_min: minimum length of pause with bit value 0
944 1, // pause_0_len_max: maximum length of pause with bit value 0
945 RC6_ADDRESS_OFFSET, // address_offset: address offset
946 RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address
947 RC6_COMMAND_OFFSET, // command_offset: command offset
948 RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command
949 RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame
950 RC6_STOP_BIT, // stop_bit: flag: frame has stop bit
951 RC6_LSB // lsb_first: flag: LSB first
952 };
953
954 #endif
955
956 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
957
958 static PROGMEM IRMP_PARAMETER recs80ext_param =
959 {
960 IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol
961 RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
962 RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
963 RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
964 RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
965 RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
966 RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
967 RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
968 RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
969 RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset
970 RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address
971 RECS80EXT_COMMAND_OFFSET, // command_offset: command offset
972 RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command
973 RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
974 RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit
975 RECS80EXT_LSB // lsb_first: flag: LSB first
976 };
977
978 #endif
979
980 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
981
982 static PROGMEM IRMP_PARAMETER nubert_param =
983 {
984 IRMP_NUBERT_PROTOCOL, // protocol: ir protocol
985 NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
986 NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
987 NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
988 NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
989 NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
990 NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
991 NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
992 NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
993 NUBERT_ADDRESS_OFFSET, // address_offset: address offset
994 NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address
995 NUBERT_COMMAND_OFFSET, // command_offset: command offset
996 NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command
997 NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame
998 NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit
999 NUBERT_LSB // lsb_first: flag: LSB first
1000 };
1001
1002 #endif
1003
1004 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1005
1006 static PROGMEM IRMP_PARAMETER bang_olufsen_param =
1007 {
1008 IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol
1009 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1010 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1011 BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1012 BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1013 BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1014 BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1015 BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1016 BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1017 BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset
1018 BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address
1019 BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset
1020 BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command
1021 BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1022 BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit
1023 BANG_OLUFSEN_LSB // lsb_first: flag: LSB first
1024 };
1025
1026 #endif
1027
1028 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1029
1030 static PROGMEM IRMP_PARAMETER grundig_param =
1031 {
1032 IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol
1033 GRUNDIG_OR_NOKIA_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1034 GRUNDIG_OR_NOKIA_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1035 GRUNDIG_OR_NOKIA_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1036 GRUNDIG_OR_NOKIA_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1037 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
1038 1, // pulse_0_len_max: maximum length of pulse with bit value 0
1039 1, // pause_0_len_min: minimum length of pause with bit value 0
1040 1, // pause_0_len_max: maximum length of pause with bit value 0
1041 GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset
1042 GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address
1043 GRUNDIG_COMMAND_OFFSET, // command_offset: command offset
1044 GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!)
1045 NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG!
1046 GRUNDIG_OR_NOKIA_STOP_BIT, // stop_bit: flag: frame has stop bit
1047 GRUNDIG_OR_NOKIA_LSB // lsb_first: flag: LSB first
1048 };
1049
1050 #endif
1051
1052 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1053
1054 static PROGMEM IRMP_PARAMETER siemens_param =
1055 {
1056 IRMP_SIEMENS_PROTOCOL, // protocol: ir protocol
1057 SIEMENS_BIT_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1058 SIEMENS_BIT_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1059 SIEMENS_BIT_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1060 SIEMENS_BIT_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1061 1, // tricky: use this as stop bit length // pulse_0_len_min: minimum length of pulse with bit value 0
1062 1, // pulse_0_len_max: maximum length of pulse with bit value 0
1063 1, // pause_0_len_min: minimum length of pause with bit value 0
1064 1, // pause_0_len_max: maximum length of pause with bit value 0
1065 SIEMENS_ADDRESS_OFFSET, // address_offset: address offset
1066 SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN, // address_end: end of address
1067 SIEMENS_COMMAND_OFFSET, // command_offset: command offset
1068 SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN, // command_end: end of command
1069 SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1070 SIEMENS_STOP_BIT, // stop_bit: flag: frame has stop bit
1071 SIEMENS_LSB // lsb_first: flag: LSB first
1072 };
1073
1074 #endif
1075
1076 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1077
1078 static PROGMEM IRMP_PARAMETER fdc_param =
1079 {
1080 IRMP_FDC_PROTOCOL, // protocol: ir protocol
1081 FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1
1082 FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1
1083 FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1
1084 FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1
1085 FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0
1086 FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0
1087 FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0
1088 FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0
1089 FDC_ADDRESS_OFFSET, // address_offset: address offset
1090 FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address
1091 FDC_COMMAND_OFFSET, // command_offset: command offset
1092 FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command
1093 FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame
1094 FDC_STOP_BIT, // stop_bit: flag: frame has stop bit
1095 FDC_LSB // lsb_first: flag: LSB first
1096 };
1097
1098 #endif
1099
1100 static uint8_t irmp_bit; // current bit position
1101 static IRMP_PARAMETER irmp_param;
1102
1103 static volatile uint8_t irmp_ir_detected;
1104 static volatile uint8_t irmp_protocol;
1105 static volatile uint16_t irmp_address;
1106 static volatile uint16_t irmp_command;
1107 static volatile uint16_t irmp_id; // only used for SAMSUNG protocol
1108 static volatile uint8_t irmp_flags;
1109
1110 #ifdef DEBUG
1111 static uint8_t IRMP_PIN;
1112 #endif
1113
1114 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1115 * Initialize IRMP decoder
1116 * @details Configures IRMP input pin
1117 *---------------------------------------------------------------------------------------------------------------------------------------------------
1118 */
1119 #ifndef DEBUG
1120 void
1121 irmp_init (void)
1122 {
1123 #ifndef PIC_CCS_COMPILER
1124 IRMP_PORT &= ~(1<<IRMP_BIT); // deactivate pullup
1125 IRMP_DDR &= ~(1<<IRMP_BIT); // set pin to input
1126 #endif // PIC_CCS_COMPILER
1127
1128 #if IRMP_LOGGING == 1
1129 irmp_uart_init ();
1130 #endif
1131 }
1132 #endif
1133 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1134 * Get IRMP data
1135 * @details gets decoded IRMP data
1136 * @param pointer in order to store IRMP data
1137 * @return TRUE: successful, FALSE: failed
1138 *---------------------------------------------------------------------------------------------------------------------------------------------------
1139 */
1140 uint8_t
1141 irmp_get_data (IRMP_DATA * irmp_data_p)
1142 {
1143 uint8_t rtc = FALSE;
1144
1145 if (irmp_ir_detected)
1146 {
1147 switch (irmp_protocol)
1148 {
1149 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1150 case IRMP_SAMSUNG_PROTOCOL:
1151 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1152 {
1153 irmp_command &= 0xff;
1154 irmp_command |= irmp_id << 8;
1155 rtc = TRUE;
1156 }
1157 break;
1158 #endif
1159 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1160 case IRMP_NEC_PROTOCOL:
1161 if ((irmp_command >> 8) == (~irmp_command & 0x00FF))
1162 {
1163 irmp_command &= 0xff;
1164 rtc = TRUE;
1165 }
1166 else if ((irmp_command & 0xFF00) == 0xD100)
1167 {
1168 DEBUG_PRINTF ("Switching to APPLE protocol\n");
1169 irmp_protocol = IRMP_APPLE_PROTOCOL;
1170 irmp_command &= 0xff;
1171 rtc = TRUE;
1172 }
1173 break;
1174 #endif
1175 default:
1176 rtc = TRUE;
1177 }
1178
1179 if (rtc)
1180 {
1181 irmp_data_p->protocol = irmp_protocol;
1182 irmp_data_p->address = irmp_address;
1183 irmp_data_p->command = irmp_command;
1184 irmp_data_p->flags = irmp_flags;
1185 irmp_command = 0;
1186 irmp_address = 0;
1187 irmp_flags = 0;
1188 }
1189
1190 irmp_ir_detected = FALSE;
1191 }
1192
1193 return rtc;
1194 }
1195
1196 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1197 static uint16_t irmp_tmp_address; // ir address
1198 static uint16_t irmp_tmp_command; // ir command
1199 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1200 static uint16_t irmp_tmp_id; // ir id (only SAMSUNG)
1201 #endif
1202
1203 static uint8_t irmp_bit; // current bit position
1204
1205 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1206 * store bit
1207 * @details store bit in temp address or temp command
1208 * @param value to store: 0 or 1
1209 *---------------------------------------------------------------------------------------------------------------------------------------------------
1210 */
1211 static void
1212 irmp_store_bit (uint8_t value)
1213 {
1214 if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end)
1215 {
1216 if (irmp_param.lsb_first)
1217 {
1218 irmp_tmp_address |= (((uint16_t) (value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast
1219 }
1220 else
1221 {
1222 irmp_tmp_address <<= 1;
1223 irmp_tmp_address |= value;
1224 }
1225 }
1226 else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end)
1227 {
1228 if (irmp_param.lsb_first)
1229 {
1230 irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast
1231 }
1232 else
1233 {
1234 irmp_tmp_command <<= 1;
1235 irmp_tmp_command |= value;
1236 }
1237 }
1238 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1239 else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN)
1240 {
1241 irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first
1242 }
1243 #endif
1244 irmp_bit++;
1245 }
1246
1247 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1248 * ISR routine
1249 * @details ISR routine, called 10000 times per second
1250 *---------------------------------------------------------------------------------------------------------------------------------------------------
1251 */
1252 uint8_t
1253 irmp_ISR (void)
1254 {
1255 static uint8_t irmp_start_bit_detected; // flag: start bit detected
1256 static uint8_t wait_for_space; // flag: wait for data bit space
1257 static uint8_t wait_for_start_space; // flag: wait for start bit space
1258 static uint8_t irmp_pulse_time; // count bit time for pulse
1259 static uint8_t irmp_pause_time; // count bit time for pause
1260 static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition
1261 static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition
1262 static uint16_t repetition_counter; // SIRCS repeats frame 2-5 times with 45 ms pause
1263 static uint8_t repetition_frame_number;
1264 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1265 static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition
1266 #endif
1267 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1268 static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit
1269 #endif
1270 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1 || IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1271 static uint8_t last_pause; // last pause value
1272 #endif
1273 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || \
1274 IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1275 static uint8_t last_value; // last bit value
1276 #endif
1277 uint8_t irmp_input; // input value
1278
1279 #ifdef DEBUG
1280 time_counter++;
1281 #endif
1282
1283 irmp_input = input(IRMP_PIN);
1284
1285 irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined
1286
1287 if (! irmp_ir_detected) // ir code already detected?
1288 { // no...
1289 if (! irmp_start_bit_detected) // start bit detected?
1290 { // no...
1291 if (! irmp_input) // receiving burst?
1292 { // yes...
1293 #ifdef DEBUG
1294 if (! irmp_pulse_time)
1295 {
1296 DEBUG_PRINTF("%8d [starting pulse]\n", time_counter);
1297 }
1298 #endif
1299 irmp_pulse_time++; // increment counter
1300 }
1301 else
1302 { // no...
1303 if (irmp_pulse_time) // it's dark....
1304 { // set flags for counting the time of darkness...
1305 irmp_start_bit_detected = 1;
1306 wait_for_start_space = 1;
1307 wait_for_space = 0;
1308 irmp_tmp_command = 0;
1309 irmp_tmp_address = 0;
1310 irmp_bit = 0xff;
1311 irmp_pause_time = 1; // 1st pause: set to 1, not to 0!
1312 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1313 rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1314 #endif
1315 }
1316 else
1317 {
1318 repetition_counter++;
1319 }
1320 }
1321 }
1322 else
1323 {
1324 if (wait_for_start_space) // we have received start bit...
1325 { // ...and are counting the time of darkness
1326 if (irmp_input) // still dark?
1327 { // yes
1328 irmp_pause_time++; // increment counter
1329
1330 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1331 { // yes...
1332 DEBUG_PRINTF ("error 1: pause after start bit pulse %d too long: %d\n", irmp_pulse_time, irmp_pause_time);
1333 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
1334 irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit
1335 irmp_pulse_time = 0;
1336 irmp_pause_time = 0;
1337 }
1338 }
1339 else
1340 { // receiving first data pulse!
1341 IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0;
1342
1343 DEBUG_PRINTF ("start-bit: pulse = %d, pause = %d\n", irmp_pulse_time, irmp_pause_time);
1344
1345 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1346 if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX &&
1347 irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX)
1348 { // it's SIRCS
1349 DEBUG_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1350 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX,
1351 SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
1352 irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param;
1353 }
1354 else
1355 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1356
1357 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1358 if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1359 irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX)
1360 {
1361 DEBUG_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1362 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1363 NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
1364 irmp_param_p = (IRMP_PARAMETER *) &nec_param;
1365 }
1366 else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX &&
1367 irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX)
1368 { // it's NEC
1369 DEBUG_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1370 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX,
1371 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX);
1372
1373 irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param;
1374 }
1375 else
1376 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1377
1378 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1379 if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX &&
1380 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
1381 { // it's SAMSUNG
1382 DEBUG_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1383 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX,
1384 SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
1385 irmp_param_p = (IRMP_PARAMETER *) &samsung_param;
1386 }
1387 else
1388 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1389
1390 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1391 if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX &&
1392 irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX)
1393 { // it's MATSUSHITA
1394 DEBUG_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1395 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX,
1396 MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
1397 irmp_param_p = (IRMP_PARAMETER *) &matsushita_param;
1398 }
1399 else
1400 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1401
1402 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1403 if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX &&
1404 irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX)
1405 { // it's KASEIKYO
1406 DEBUG_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1407 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX,
1408 KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
1409 irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param;
1410 }
1411 else
1412 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1413
1414 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1415 if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX &&
1416 irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX)
1417 { // it's RECS80
1418 DEBUG_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1419 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX,
1420 RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
1421 irmp_param_p = (IRMP_PARAMETER *) &recs80_param;
1422 }
1423 else
1424 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1425
1426 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1427 if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) ||
1428 (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) &&
1429 ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) ||
1430 (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)))
1431 { // it's RC5
1432 DEBUG_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1433 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX,
1434 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
1435 irmp_param_p = (IRMP_PARAMETER *) &rc5_param;
1436 last_pause = irmp_pause_time;
1437
1438 if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) ||
1439 (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))
1440 {
1441 last_value = 0;
1442 rc5_cmd_bit6 = 1<<6;
1443 }
1444 else
1445 {
1446 last_value = 1;
1447 }
1448 }
1449 else
1450 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1451
1452 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1453 if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) &&
1454 ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) ||
1455 (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)))
1456 { // it's DENON
1457 DEBUG_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
1458 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX,
1459 DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX,
1460 DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
1461 irmp_param_p = (IRMP_PARAMETER *) &denon_param;
1462 }
1463 else
1464 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1465
1466 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1467 if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX &&
1468 irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX)
1469 { // it's RC6
1470 DEBUG_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1471 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX,
1472 RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
1473 irmp_param_p = (IRMP_PARAMETER *) &rc6_param;
1474 last_pause = 0;
1475 last_value = 0;
1476 }
1477 else
1478 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1479
1480 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1481 if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX &&
1482 irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX)
1483 { // it's RECS80EXT
1484 DEBUG_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1485 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX,
1486 RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
1487 irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param;
1488 }
1489 else
1490 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1491
1492 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1493 if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX &&
1494 irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX)
1495 { // it's NUBERT
1496 DEBUG_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1497 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX,
1498 NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
1499 irmp_param_p = (IRMP_PARAMETER *) &nubert_param;
1500 }
1501 else
1502 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1503
1504 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1505 if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX &&
1506 irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX)
1507 { // it's BANG_OLUFSEN
1508 DEBUG_PRINTF ("protocol = BANG_OLUFSEN\n");
1509 DEBUG_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1510 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX,
1511 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
1512 DEBUG_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1513 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX,
1514 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
1515 DEBUG_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1516 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX,
1517 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
1518 DEBUG_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1519 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX,
1520 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
1521 irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param;
1522 last_value = 0;
1523 }
1524 else
1525 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1526
1527 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1528 if (irmp_pulse_time >= GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX &&
1529 irmp_pause_time >= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX)
1530 { // it's GRUNDIG
1531 DEBUG_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1532 GRUNDIG_OR_NOKIA_START_BIT_LEN_MIN, GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX,
1533 GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MIN, GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN_MAX);
1534 irmp_param_p = (IRMP_PARAMETER *) &grundig_param;
1535 last_pause = irmp_pause_time;
1536 last_value = 1;
1537 }
1538 else
1539 #endif // IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1540
1541 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1542 if (((irmp_pulse_time >= SIEMENS_START_BIT_LEN_MIN && irmp_pulse_time <= SIEMENS_START_BIT_LEN_MAX) ||
1543 (irmp_pulse_time >= 2 * SIEMENS_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_START_BIT_LEN_MAX)) &&
1544 ((irmp_pause_time >= SIEMENS_START_BIT_LEN_MIN && irmp_pause_time <= SIEMENS_START_BIT_LEN_MAX) ||
1545 (irmp_pause_time >= 2 * SIEMENS_START_BIT_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_START_BIT_LEN_MAX)))
1546 { // it's SIEMENS
1547 DEBUG_PRINTF ("protocol = SIEMENS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1548 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX,
1549 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX);
1550 irmp_param_p = (IRMP_PARAMETER *) &siemens_param;
1551 last_pause = irmp_pause_time;
1552 last_value = 1;
1553 }
1554 else
1555 #endif // IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1556 #if IRMP_SUPPORT_FDC_PROTOCOL == 1
1557 if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX &&
1558 irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX)
1559 {
1560 DEBUG_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1561 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX,
1562 FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
1563 irmp_param_p = (IRMP_PARAMETER *) &fdc_param;
1564 }
1565 else
1566 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1567
1568 {
1569 DEBUG_PRINTF ("protocol = UNKNOWN\n");
1570 irmp_start_bit_detected = 0; // wait for another start bit...
1571 }
1572
1573 if (irmp_start_bit_detected)
1574 {
1575 memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER));
1576
1577 DEBUG_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max);
1578 DEBUG_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max);
1579
1580 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1581 if (irmp_param.protocol == IRMP_RC6_PROTOCOL)
1582 {
1583 DEBUG_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX);
1584 }
1585 #endif
1586 DEBUG_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
1587 DEBUG_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max);
1588
1589 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1590 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
1591 {
1592 DEBUG_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max);
1593 DEBUG_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX);
1594 }
1595 #endif
1596
1597 DEBUG_PRINTF ("command_offset: %2d\n", irmp_param.command_offset);
1598 DEBUG_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset);
1599 DEBUG_PRINTF ("complete_len: %3d\n", irmp_param.complete_len);
1600 DEBUG_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit);
1601 }
1602
1603 irmp_bit = 0;
1604
1605 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1606 if (irmp_param.protocol == IRMP_RC5_PROTOCOL)
1607 {
1608 if (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)
1609 {
1610 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1611 DEBUG_PUTCHAR ('1');
1612 DEBUG_NEWLINE ();
1613 irmp_store_bit (1);
1614 }
1615 else if (! last_value)
1616 {
1617 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1618 DEBUG_PUTCHAR ('0');
1619 DEBUG_NEWLINE ();
1620 irmp_store_bit (0);
1621 }
1622 }
1623 else
1624 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1625
1626 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1627 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL || irmp_param.protocol == IRMP_NOKIA_PROTOCOL)
1628 {
1629 if (irmp_pause_time > GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX && irmp_pause_time <= 2 * GRUNDIG_OR_NOKIA_START_BIT_LEN_MAX)
1630 {
1631 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1632 DEBUG_PUTCHAR ('0');
1633 DEBUG_NEWLINE ();
1634 irmp_store_bit (0);
1635 }
1636 else if (! last_value)
1637 {
1638 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1639 DEBUG_PUTCHAR ('1');
1640 DEBUG_NEWLINE ();
1641 irmp_store_bit (1);
1642 }
1643 }
1644 else
1645 #endif // IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1646
1647 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1648 if (irmp_param.protocol == IRMP_SIEMENS_PROTOCOL)
1649 {
1650 if (irmp_pause_time > SIEMENS_START_BIT_LEN_MAX && irmp_pause_time <= 2 * SIEMENS_START_BIT_LEN_MAX)
1651 {
1652 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1653 DEBUG_PUTCHAR ('0');
1654 DEBUG_NEWLINE ();
1655 irmp_store_bit (0);
1656 }
1657 else if (! last_value)
1658 {
1659 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1660 DEBUG_PUTCHAR ('1');
1661 DEBUG_NEWLINE ();
1662 irmp_store_bit (1);
1663 }
1664 }
1665 else
1666 #endif // IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1667
1668 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1669 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
1670 {
1671 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1672
1673 if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX)
1674 { // pause timings correct for "1"?
1675 DEBUG_PUTCHAR ('1'); // yes, store 1
1676 DEBUG_NEWLINE ();
1677 irmp_store_bit (1);
1678 }
1679 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
1680 { // pause timings correct for "0"?
1681 DEBUG_PUTCHAR ('0'); // yes, store 0
1682 DEBUG_NEWLINE ();
1683 irmp_store_bit (0);
1684 }
1685 }
1686 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1687
1688 irmp_pulse_time = 1; // set counter to 1, not 0
1689 irmp_pause_time = 0;
1690 wait_for_start_space = 0;
1691 }
1692 }
1693 else if (wait_for_space) // the data section....
1694 { // counting the time of darkness....
1695 uint8_t got_light = FALSE;
1696
1697 if (irmp_input) // still dark?
1698 { // yes...
1699 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1)
1700 {
1701 if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max)
1702 {
1703 #ifdef DEBUG
1704 if (irmp_param.protocol != IRMP_RC5_PROTOCOL &&
1705 irmp_param.protocol != IRMP_RC6_PROTOCOL &&
1706 irmp_param.protocol != IRMP_GRUNDIG_PROTOCOL &&
1707 irmp_param.protocol != IRMP_NOKIA_PROTOCOL &&
1708 irmp_param.protocol != IRMP_SIEMENS_PROTOCOL)
1709 {
1710 DEBUG_PRINTF ("stop bit detected\n");
1711 }
1712 #endif
1713 irmp_param.stop_bit = 0;
1714 }
1715 else
1716 {
1717 DEBUG_PRINTF ("stop bit timing wrong\n");
1718
1719 irmp_start_bit_detected = 0; // wait for another start bit...
1720 irmp_pulse_time = 0;
1721 irmp_pause_time = 0;
1722 }
1723 }
1724 else
1725 {
1726 irmp_pause_time++; // increment counter
1727
1728 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1729 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits:
1730 irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12
1731 irmp_bit >= 12 - 1) // pause too long?
1732 { // yes, break and close this frame
1733 irmp_param.complete_len = irmp_bit + 1; // set new complete length
1734 got_light = TRUE; // this is a lie, but helps (generates stop bit)
1735 irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length
1736 irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length
1737 }
1738 else
1739 #endif
1740 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1741 if (irmp_param.protocol == IRMP_RC5_PROTOCOL &&
1742 irmp_pause_time > 2 * RC5_BIT_LEN_MAX && irmp_bit >= RC5_COMPLETE_DATA_LEN - 2 && !irmp_param.stop_bit)
1743 { // special rc5 decoder
1744 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1745 irmp_param.stop_bit = TRUE; // set flag
1746 }
1747 else
1748 #endif
1749 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1750 if (irmp_param.protocol == IRMP_RC6_PROTOCOL &&
1751 irmp_pause_time > 2 * RC6_BIT_LEN_MAX && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit)
1752 { // special rc6 decoder
1753 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1754 irmp_param.stop_bit = TRUE; // set flag
1755 }
1756 else
1757 #endif
1758 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
1759 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL &&
1760 irmp_pause_time > 2 * GRUNDIG_OR_NOKIA_BIT_LEN_MAX && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2 && !irmp_param.stop_bit)
1761 { // special Grundig/Nokia decoder
1762 irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len
1763 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1764 irmp_param.stop_bit = TRUE; // set flag
1765 }
1766 else
1767 #endif
1768 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
1769 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL &&
1770 irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN)
1771 {
1772 DEBUG_PRINTF ("Switching to NOKIA protocol\n");
1773 irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol
1774 irmp_param.address_offset = NOKIA_ADDRESS_OFFSET;
1775 irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN;
1776 irmp_param.command_offset = NOKIA_COMMAND_OFFSET;
1777 irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN;
1778
1779 if (irmp_tmp_command & 0x300)
1780 {
1781 irmp_tmp_address = (irmp_tmp_command >> 8);
1782 irmp_tmp_command &= 0xFF;
1783 }
1784 }
1785 else
1786 #endif
1787 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
1788 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL &&
1789 irmp_pause_time > 2 * GRUNDIG_OR_NOKIA_BIT_LEN_MAX && irmp_bit >= NOKIA_COMPLETE_DATA_LEN - 2 && !irmp_param.stop_bit)
1790 { // special Grundig/Nokia decoder
1791 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1792 irmp_param.stop_bit = TRUE; // set flag
1793 }
1794 else
1795 #endif
1796 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1797 if (irmp_param.protocol == IRMP_SIEMENS_PROTOCOL &&
1798 irmp_pause_time > 2 * SIEMENS_BIT_LEN_MAX && irmp_bit >= SIEMENS_COMPLETE_DATA_LEN - 2 && !irmp_param.stop_bit)
1799 { // special rc5 decoder
1800 got_light = TRUE; // this is a lie, but generates a stop bit ;-)
1801 irmp_param.stop_bit = TRUE; // set flag
1802 }
1803 else
1804 #endif
1805 if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout?
1806 { // yes...
1807 if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0)
1808 {
1809 irmp_bit++;
1810 }
1811 else
1812 {
1813 DEBUG_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit);
1814 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
1815
1816 irmp_start_bit_detected = 0; // wait for another start bit...
1817 irmp_pulse_time = 0;
1818 irmp_pause_time = 0;
1819 }
1820 }
1821 }
1822 }
1823 else
1824 { // got light now!
1825 got_light = TRUE;
1826 }
1827
1828 if (got_light)
1829 {
1830 DEBUG_PRINTF ("%8d [bit %2d: pulse = %3d, pause = %3d] ", time_counter, irmp_bit, irmp_pulse_time, irmp_pause_time);
1831
1832 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1833 if (irmp_param.protocol == IRMP_RC5_PROTOCOL) // special rc5 decoder
1834 {
1835 if (irmp_pulse_time > RC5_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_BIT_LEN_MAX)
1836 {
1837 DEBUG_PUTCHAR ('1');
1838 irmp_store_bit (1);
1839 DEBUG_PUTCHAR ('0');
1840 DEBUG_NEWLINE ();
1841 irmp_store_bit (0);
1842 last_value = 0;
1843 }
1844
1845 else // if (irmp_pulse_time >= RC5_BIT_LEN_MIN && irmp_pulse_time <= RC5_BIT_LEN_MAX)
1846 {
1847 uint8_t rc5_value;
1848
1849 if (last_pause > RC5_BIT_LEN_MAX && last_pause <= 2 * RC5_BIT_LEN_MAX)
1850 {
1851 rc5_value = last_value ? 0 : 1;
1852 last_value = rc5_value;
1853 }
1854 else
1855 {
1856 rc5_value = last_value;
1857 }
1858
1859 DEBUG_PUTCHAR (rc5_value + '0');
1860 DEBUG_NEWLINE ();
1861 irmp_store_bit (rc5_value);
1862 }
1863
1864 last_pause = irmp_pause_time;
1865 wait_for_space = 0;
1866 }
1867 else
1868 #endif
1869
1870 #if IRMP_SUPPORT_GRUNDIG_OR_NOKIA_PROTOCOL == 1
1871 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL || // special Grundig decoder
1872 irmp_param.protocol == IRMP_NOKIA_PROTOCOL) // special Nokia decoder
1873 {
1874 if (irmp_pulse_time > GRUNDIG_OR_NOKIA_BIT_LEN_MAX && irmp_pulse_time <= 2 * GRUNDIG_OR_NOKIA_BIT_LEN_MAX)
1875 {
1876 DEBUG_PUTCHAR ('0');
1877 irmp_store_bit (0);
1878 DEBUG_PUTCHAR ('1');
1879 DEBUG_NEWLINE ();
1880 irmp_store_bit (1);
1881 last_value = 1;
1882 }
1883
1884 else // if (irmp_pulse_time >= GRUNDIG_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_OR_NOKIA_BIT_LEN_MAX)
1885 {
1886 uint8_t grundig_value;
1887
1888 if (last_pause > GRUNDIG_OR_NOKIA_BIT_LEN_MAX && last_pause <= 2 * GRUNDIG_OR_NOKIA_BIT_LEN_MAX)
1889 {
1890 grundig_value = last_value ? 0 : 1;
1891 last_value = grundig_value;
1892 }
1893 else
1894 {
1895 grundig_value = last_value;
1896 }
1897
1898 DEBUG_PUTCHAR (grundig_value + '0');
1899 DEBUG_NEWLINE ();
1900 irmp_store_bit (grundig_value);
1901 }
1902
1903 last_pause = irmp_pause_time;
1904 wait_for_space = 0;
1905 }
1906 else
1907 #endif
1908
1909 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1910 if (irmp_param.protocol == IRMP_RC6_PROTOCOL) // special rc6 decoder
1911 {
1912 switch (irmp_bit)
1913 { // handle toggle bit, which is 2 times longer than other bits
1914 case 3:
1915 case 4:
1916 case 5:
1917 if (irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MAX && irmp_pause_time > RC6_TOGGLE_BIT_LEN_MAX)
1918 {
1919 DEBUG_PUTCHAR ('1');
1920 irmp_store_bit (1);
1921 }
1922
1923 DEBUG_PUTCHAR ('0');
1924 irmp_store_bit (0);
1925 last_value = 0;
1926 DEBUG_NEWLINE ();
1927 break;
1928
1929 default:
1930 if (irmp_pulse_time > RC6_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC6_BIT_LEN_MAX)
1931 {
1932 DEBUG_PUTCHAR ('0');
1933 irmp_store_bit (0);
1934 DEBUG_PUTCHAR ('1');
1935 DEBUG_NEWLINE ();
1936 irmp_store_bit (1);
1937 last_value = 1;
1938 }
1939 else // if (irmp_pulse_time >= RC6_BIT_LEN_MIN && irmp_pulse_time <= RC6_BIT_LEN_MAX)
1940 {
1941 uint8_t rc5_value;
1942
1943 if (last_pause > RC6_BIT_LEN_MAX && last_pause <= 2 * RC6_BIT_LEN_MAX)
1944 {
1945 rc5_value = last_value ? 0 : 1;
1946 last_value = rc5_value;
1947 }
1948 else
1949 {
1950 rc5_value = last_value;
1951 }
1952
1953 if (irmp_bit == 1 && rc5_value == 0)
1954 {
1955 irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG;
1956 }
1957
1958 DEBUG_PUTCHAR (rc5_value + '0');
1959 DEBUG_NEWLINE ();
1960 irmp_store_bit (rc5_value);
1961 }
1962
1963 last_pause = irmp_pause_time;
1964 break;
1965 } // switch
1966
1967 wait_for_space = 0;
1968 }
1969 else
1970 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1971
1972 #if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1
1973 if (irmp_param.protocol == IRMP_SIEMENS_PROTOCOL) // special siemens decoder
1974 {
1975 if (irmp_pulse_time > SIEMENS_BIT_LEN_MAX && irmp_pulse_time <= 2 * SIEMENS_BIT_LEN_MAX)
1976 {
1977 DEBUG_PUTCHAR ('0');
1978 irmp_store_bit (0);
1979 DEBUG_PUTCHAR ('1');
1980 DEBUG_NEWLINE ();
1981 irmp_store_bit (1);
1982 last_value = 1;
1983 }
1984
1985 else // if (irmp_pulse_time >= SIEMENS_BIT_LEN_MIN && irmp_pulse_time <= SIEMENS_BIT_LEN_MAX)
1986 {
1987 uint8_t siemens_value;
1988
1989 if (last_pause > SIEMENS_BIT_LEN_MAX && last_pause <= 2 * SIEMENS_BIT_LEN_MAX)
1990 {
1991 siemens_value = last_value ? 0 : 1;
1992 last_value = siemens_value;
1993 }
1994 else
1995 {
1996 siemens_value = last_value;
1997 }
1998
1999 DEBUG_PUTCHAR (siemens_value + '0');
2000 DEBUG_NEWLINE ();
2001 irmp_store_bit (siemens_value);
2002 }
2003
2004 last_pause = irmp_pause_time;
2005 wait_for_space = 0;
2006 }
2007 else
2008 #endif
2009
2010 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2011 if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit
2012 {
2013 if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX &&
2014 irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX)
2015 {
2016 DEBUG_PRINTF ("SYNC\n");
2017 wait_for_space = 0;
2018 irmp_tmp_id = 0;
2019 irmp_bit++;
2020 }
2021 else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX)
2022 {
2023 irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL;
2024 irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET;
2025 irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN;
2026 irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN;
2027
2028 if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX)
2029 {
2030 DEBUG_PUTCHAR ('1');
2031 DEBUG_NEWLINE ();
2032 irmp_store_bit (1);
2033 wait_for_space = 0;
2034 }
2035 else
2036 {
2037 DEBUG_PUTCHAR ('0');
2038 DEBUG_NEWLINE ();
2039 irmp_store_bit (0);
2040 wait_for_space = 0;
2041 }
2042
2043 DEBUG_PRINTF ("Switching to SAMSUNG32 protocol\n");
2044 }
2045 else
2046 { // timing incorrect!
2047 DEBUG_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2048 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2049 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2050 irmp_pause_time = 0;
2051 }
2052 }
2053 else
2054 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
2055
2056 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
2057 if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
2058 {
2059 if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX)
2060 {
2061 if (irmp_bit == 1) // Bang & Olufsen: 3rd bit
2062 {
2063 if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX)
2064 {
2065 DEBUG_PRINTF ("3rd start bit\n");
2066 wait_for_space = 0;
2067 irmp_tmp_id = 0;
2068 irmp_bit++;
2069 }
2070 else
2071 { // timing incorrect!
2072 DEBUG_PRINTF ("error 3a B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2073 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2074 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2075 irmp_pause_time = 0;
2076 }
2077 }
2078 else if (irmp_bit == 19) // Bang & Olufsen: trailer bit
2079 {
2080 if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX)
2081 {
2082 DEBUG_PRINTF ("trailer bit\n");
2083 wait_for_space = 0;
2084 irmp_tmp_id = 0;
2085 irmp_bit++;
2086 }
2087 else
2088 { // timing incorrect!
2089 DEBUG_PRINTF ("error 3b B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2090 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2091 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2092 irmp_pause_time = 0;
2093 }
2094 }
2095 else
2096 {
2097 if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX)
2098 { // pulse & pause timings correct for "1"?
2099 DEBUG_PUTCHAR ('1');
2100 DEBUG_NEWLINE ();
2101 irmp_store_bit (1);
2102 last_value = 1;
2103 wait_for_space = 0;
2104 }
2105 else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX)
2106 { // pulse & pause timings correct for "0"?
2107 DEBUG_PUTCHAR ('0');
2108 DEBUG_NEWLINE ();
2109 irmp_store_bit (0);
2110 last_value = 0;
2111 wait_for_space = 0;
2112 }
2113 else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX)
2114 {
2115 DEBUG_PUTCHAR (last_value + '0');
2116 DEBUG_NEWLINE ();
2117 irmp_store_bit (last_value);
2118 wait_for_space = 0;
2119 }
2120 else
2121 { // timing incorrect!
2122 DEBUG_PRINTF ("error 3c B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2123 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2124 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2125 irmp_pause_time = 0;
2126 }
2127 }
2128 }
2129 else
2130 { // timing incorrect!
2131 DEBUG_PRINTF ("error 3d B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2132 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2133 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2134 irmp_pause_time = 0;
2135 }
2136 }
2137 else
2138 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
2139
2140 if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max &&
2141 irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max)
2142 { // pulse & pause timings correct for "1"?
2143 DEBUG_PUTCHAR ('1');
2144 DEBUG_NEWLINE ();
2145 irmp_store_bit (1);
2146 wait_for_space = 0;
2147 }
2148 else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max &&
2149 irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max)
2150 { // pulse & pause timings correct for "0"?
2151 DEBUG_PUTCHAR ('0');
2152 DEBUG_NEWLINE ();
2153 irmp_store_bit (0);
2154 wait_for_space = 0;
2155 }
2156 else
2157 { // timing incorrect!
2158 DEBUG_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time);
2159 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2160 irmp_start_bit_detected = 0; // reset flags and wait for next start bit
2161 irmp_pause_time = 0;
2162 }
2163
2164 irmp_pulse_time = 1; // set counter to 1, not 0
2165 }
2166 }
2167 else
2168 { // counting the pulse length ...
2169 if (! irmp_input) // still light?
2170 { // yes...
2171 irmp_pulse_time++; // increment counter
2172 }
2173 else
2174 { // now it's dark!
2175 wait_for_space = 1; // let's count the time (see above)
2176 irmp_pause_time = 1; // set pause counter to 1, not 0
2177 }
2178 }
2179
2180 if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received?
2181 {
2182 if (last_irmp_command == irmp_tmp_command && repetition_counter < AUTO_FRAME_REPETITION_LEN)
2183 {
2184 repetition_frame_number++;
2185 }
2186 else
2187 {
2188 repetition_frame_number = 0;
2189 }
2190
2191 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
2192 // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame
2193 if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2))
2194 {
2195 DEBUG_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2196 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2197 repetition_counter = 0;
2198 }
2199 else
2200 #endif
2201
2202 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2203 // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2204 if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01))
2205 {
2206 DEBUG_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2207 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2208 repetition_counter = 0;
2209 }
2210 else
2211 #endif
2212
2213 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
2214 // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame
2215 if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01))
2216 {
2217 DEBUG_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n",
2218 repetition_frame_number + 1, repetition_counter, AUTO_FRAME_REPETITION_LEN);
2219 repetition_counter = 0;
2220 }
2221 else
2222 #endif
2223
2224 {
2225 DEBUG_PRINTF ("code detected, length = %d\n", irmp_bit);
2226 irmp_ir_detected = TRUE;
2227
2228 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
2229 if (irmp_param.protocol == IRMP_DENON_PROTOCOL)
2230 { // check for repetition frame
2231 if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted
2232 {
2233 irmp_tmp_command = last_irmp_denon_command; // use command received before!
2234
2235 irmp_protocol = irmp_param.protocol; // store protocol
2236 irmp_address = irmp_tmp_address; // store address
2237 irmp_command = irmp_tmp_command ; // store command
2238 }
2239 else
2240 {
2241 DEBUG_PRINTF ("waiting for inverted command repetition\n");
2242 irmp_ir_detected = FALSE;
2243 last_irmp_denon_command = irmp_tmp_command;
2244 }
2245 }
2246 else
2247 #endif // IRMP_SUPPORT_DENON_PROTOCOL
2248
2249 #if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1
2250 if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff)
2251 { // Grundig start frame?
2252 DEBUG_PRINTF ("Detected GRUNDIG start frame, ignoring it\n");
2253 irmp_ir_detected = FALSE;
2254 }
2255 else
2256 #endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL
2257
2258 #if IRMP_SUPPORT_NOKIA_PROTOCOL == 1
2259 if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe)
2260 { // Nokia start frame?
2261 DEBUG_PRINTF ("Detected NOKIA start frame, ignoring it\n");
2262 irmp_ir_detected = FALSE;
2263 }
2264 else
2265 #endif // IRMP_SUPPORT_NOKIA_PROTOCOL
2266 {
2267 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2268 if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame
2269 {
2270 irmp_tmp_address = last_irmp_address; // address is last address
2271 irmp_tmp_command = last_irmp_command; // command is last command
2272 irmp_flags |= IRMP_FLAG_REPETITION;
2273 }
2274 #endif // IRMP_SUPPORT_NEC_PROTOCOL
2275 irmp_protocol = irmp_param.protocol;
2276 irmp_address = irmp_tmp_address; // store address
2277 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
2278 last_irmp_address = irmp_tmp_address; // store as last address, too
2279 #endif
2280
2281 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
2282 irmp_tmp_command |= rc5_cmd_bit6; // store bit 6
2283 #endif
2284 irmp_command = irmp_tmp_command; // store command
2285
2286 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
2287 irmp_id = irmp_tmp_id;
2288 #endif
2289 }
2290 }
2291
2292 if (irmp_ir_detected)
2293 {
2294 if (last_irmp_command == irmp_command &&
2295 last_irmp_address == irmp_address &&
2296 repetition_counter < IRMP_KEY_REPETITION_LEN)
2297 {
2298 irmp_flags |= IRMP_FLAG_REPETITION;
2299 }
2300
2301 last_irmp_address = irmp_tmp_address; // store as last address, too
2302 last_irmp_command = irmp_tmp_command; // store as last command, too
2303
2304 repetition_counter = 0;
2305 }
2306 else
2307 {
2308 DEBUG_ONLY_NORMAL_PUTCHAR ('\n');
2309 }
2310
2311 irmp_start_bit_detected = 0; // and wait for next start bit
2312 irmp_tmp_command = 0;
2313 irmp_pulse_time = 0;
2314 irmp_pause_time = 0;
2315 }
2316 }
2317 }
2318 return (irmp_ir_detected);
2319 }
2320
2321 #ifdef DEBUG
2322
2323 // main function - for unix/linux + windows only!
2324 // AVR: see main.c!
2325 // Compile it under linux with:
2326 // cc irmp.c -o irmp
2327 //
2328 // usage: ./irmp [-v|-s|-a|-p] < file
2329
2330 static void
2331 print_timings (void)
2332 {
2333 printf ("PROTOCOL START BIT NO. START BIT PULSE START BIT PAUSE\n");
2334 printf ("====================================================================================\n");
2335 printf ("SIRCS 1 %3d - %3d %3d - %3d\n",
2336 SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX);
2337 printf ("NEC 1 %3d - %3d %3d - %3d\n",
2338 NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX);
2339 printf ("NEC (rep) 1 %3d - %3d %3d - %3d\n",
2340 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);
2341 printf ("SAMSUNG 1 %3d - %3d %3d - %3d\n",
2342 SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX);
2343 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d\n",
2344 MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX);
2345 printf ("KASEIKYO 1 %3d - %3d %3d - %3d\n",
2346 KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX);
2347 printf ("RECS80 1 %3d - %3d %3d - %3d\n",
2348 RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX);
2349 printf ("RC5 1 %3d - %3d %3d - %3d\n",
2350 RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX);
2351 printf ("DENON 1 %3d - %3d %3d - %3d or %3d - %3d\n",
2352 DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX);
2353 printf ("RC6 1 %3d - %3d %3d - %3d\n",
2354 RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX);
2355 printf ("RECS80EXT 1 %3d - %3d %3d - %3d\n",
2356 RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX);
2357 printf ("NUBERT 1 %3d - %3d %3d - %3d\n",
2358 NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX);
2359 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
2360 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX);
2361 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
2362 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX);
2363 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
2364 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX);
2365 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
2366 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX);
2367 printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d\n",
2368 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);
2369 printf ("SIEMENS 1 %3d - %3d %3d - %3d\n",
2370 SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX, SIEMENS_START_BIT_LEN_MIN, SIEMENS_START_BIT_LEN_MAX);
2371 printf ("FDC 1 %3d - %3d %3d - %3d\n",
2372 FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX);
2373 }
2374
2375 int
2376 main (int argc, char ** argv)
2377 {
2378 int i;
2379 int analyze = FALSE;
2380 int ch;
2381 int last_ch = 0;
2382 int pulse = 0;
2383 int pause = 0;
2384
2385 int min_pulse_long = 100000;
2386 int max_pulse_long = 0;
2387 int sum_pulses_long = 0;
2388 int n_pulses_long = 0;
2389
2390 int min_pulse_short = 100000;
2391 int max_pulse_short = 0;
2392 int sum_pulses_short = 0;
2393 int n_pulses_short = 0;
2394
2395 int min_pause_long = 100000;
2396 int max_pause_long = 0;
2397 int sum_pauses_long = 0;
2398 int n_pauses_long = 0;
2399
2400 int min_pause_short = 100000;
2401 int max_pause_short = 0;
2402 int sum_pauses_short = 0;
2403 int n_pauses_short = 0;
2404
2405 int min_start_pulse = 100000;
2406 int max_start_pulse = 0;
2407 int sum_start_pulses = 0;
2408 int n_start_pulses = 0;
2409
2410 int min_start_pause = 100000;
2411 int max_start_pause = 0;
2412 int sum_start_pauses = 0;
2413 int n_start_pauses = 0;
2414
2415 int first_pulse = TRUE;
2416 int first_pause = TRUE;
2417
2418 IRMP_DATA irmp_data;
2419
2420 if (argc == 2)
2421 {
2422 if (! strcmp (argv[1], "-v"))
2423 {
2424 verbose = TRUE;
2425 }
2426 else if (! strcmp (argv[1], "-a"))
2427 {
2428 analyze = TRUE;
2429 }
2430 else if (! strcmp (argv[1], "-s"))
2431 {
2432 silent = TRUE;
2433 }
2434 else if (! strcmp (argv[1], "-p"))
2435 {
2436 print_timings ();
2437 return (0);
2438 }
2439 }
2440
2441 IRMP_PIN = 0xFF;
2442
2443 while ((ch = getchar ()) != EOF)
2444 {
2445 if (ch == '_' || ch == '0')
2446 {
2447 if (last_ch != ch)
2448 {
2449 if (analyze && pause > 0)
2450 {
2451 printf ("pause: %d\n", pause);
2452
2453 if (first_pause)
2454 {
2455 if (min_start_pause > pause)
2456 {
2457 min_start_pause = pause;
2458 }
2459 if (max_start_pause < pause)
2460 {
2461 max_start_pause = pause;
2462 }
2463 n_start_pauses++;
2464 sum_start_pauses += pause;
2465 first_pause = FALSE;
2466 }
2467 else
2468 {
2469 if (pause >= 10)
2470 {
2471 if (pause > 100) // perhaps repetition frame follows
2472 {
2473 first_pulse = TRUE;
2474 first_pause = TRUE;
2475 }
2476 else
2477 {
2478 if (min_pause_long > pause)
2479 {
2480 min_pause_long = pause;
2481 }
2482 if (max_pause_long < pause)
2483 {
2484 max_pause_long = pause;
2485 }
2486 n_pauses_long++;
2487 sum_pauses_long += pause;
2488 }
2489 }
2490 else
2491 {
2492 if (min_pause_short > pause)
2493 {
2494 min_pause_short = pause;
2495 }
2496 if (max_pause_short < pause)
2497 {
2498 max_pause_short = pause;
2499 }
2500 n_pauses_short++;
2501 sum_pauses_short += pause;
2502 }
2503 }
2504 }
2505 pause = 0;
2506 }
2507 pulse++;
2508 IRMP_PIN = 0x00;
2509 }
2510 else if (ch == 0xaf || ch == '-' || ch == '1')
2511 {
2512 if (last_ch != ch)
2513 {
2514 if (analyze)
2515 {
2516 printf ("pulse: %d ", pulse);
2517
2518 if (first_pulse)
2519 {
2520 if (min_start_pulse > pulse)
2521 {
2522 min_start_pulse = pulse;
2523 }
2524 if (max_start_pulse < pulse)
2525 {
2526 max_start_pulse = pulse;
2527 }
2528 n_start_pulses++;
2529 sum_start_pulses += pulse;
2530 first_pulse = FALSE;
2531 }
2532 else
2533 {
2534 if (pulse >= 10)
2535 {
2536 if (min_pulse_long > pulse)
2537 {
2538 min_pulse_long = pulse;
2539 }
2540 if (max_pulse_long < pulse)
2541 {
2542 max_pulse_long = pulse;
2543 }
2544 n_pulses_long++;
2545 sum_pulses_long += pulse;
2546 }
2547 else
2548 {
2549 if (min_pulse_short > pulse)
2550 {
2551 min_pulse_short = pulse;
2552 }
2553 if (max_pulse_short < pulse)
2554 {
2555 max_pulse_short = pulse;
2556 }
2557 n_pulses_short++;
2558 sum_pulses_short += pulse;
2559 }
2560 }
2561 }
2562 pulse = 0;
2563 }
2564 pause++;
2565 IRMP_PIN = 0xff;
2566 }
2567 else if (ch == '\n')
2568 {
2569 IRMP_PIN = 0xff;
2570
2571 if (analyze && pause > 0)
2572 {
2573 printf ("pause: %d\n", pause);
2574 }
2575 pause = 0;
2576
2577 if (! analyze)
2578 {
2579 for (i = 0; i < 8000; i++) // newline: long pause of 800 msec
2580 {
2581 (void) irmp_ISR ();
2582 }
2583 }
2584 first_pulse = TRUE;
2585 first_pause = TRUE;
2586 }
2587 else if (ch == '#')
2588 {
2589 puts ("-------------------------------------------------------------------");
2590 putchar (ch);
2591
2592 while ((ch = getchar()) != '\n' && ch != EOF)
2593 {
2594 if (ch != '\r') // ignore CR in DOS/Windows files
2595 {
2596 putchar (ch);
2597 }
2598 }
2599 putchar ('\n');
2600 }
2601
2602 last_ch = ch;
2603
2604 if (! analyze)
2605 {
2606 (void) irmp_ISR ();
2607 }
2608
2609 if (irmp_get_data (&irmp_data))
2610 {
2611 DEBUG_ONLY_NORMAL_PUTCHAR (' ');
2612 printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n",
2613 irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags);
2614 }
2615 }
2616
2617 if (analyze)
2618 {
2619 printf ("\nSTATITSTICS:\n");
2620 printf ("---------------------------------\n");
2621 printf ("number of start pulses: %d\n", n_start_pulses);
2622 printf ("minimum start pulse length: %d usec\n", (1000000 * min_start_pulse) / F_INTERRUPTS);
2623 printf ("maximum start pulse length: %d usec\n", (1000000 * max_start_pulse) / F_INTERRUPTS);
2624 if (n_start_pulses > 0)
2625 {
2626 printf ("average start pulse length: %d usec\n", ((1000000 * sum_start_pulses) / n_start_pulses) / F_INTERRUPTS);
2627 }
2628 putchar ('\n');
2629 printf ("number of start pauses: %d\n", n_start_pauses);
2630 if (n_start_pauses > 0)
2631 {
2632 printf ("minimum start pause length: %d usec\n", (1000000 * min_start_pause) / F_INTERRUPTS);
2633 printf ("maximum start pause length: %d usec\n", (1000000 * max_start_pause) / F_INTERRUPTS);
2634 printf ("average start pause length: %d usec\n", ((1000000 * sum_start_pauses) / n_start_pauses) / F_INTERRUPTS);
2635 }
2636 putchar ('\n');
2637 printf ("number of long pulses: %d\n", n_pulses_long);
2638 if (n_pulses_long > 0)
2639 {
2640 printf ("minimum long pulse length: %d usec\n", (1000000 * min_pulse_long) / F_INTERRUPTS);
2641 printf ("maximum long pulse length: %d usec\n", (1000000 * max_pulse_long) / F_INTERRUPTS);
2642 printf ("average long pulse length: %d usec\n", ((1000000 * sum_pulses_long) / n_pulses_long) / F_INTERRUPTS);
2643 }
2644 putchar ('\n');
2645 printf ("number of short pulses: %d\n", n_pulses_short);
2646 if (n_pulses_short > 0)
2647 {
2648 printf ("minimum short pulse length: %d usec\n", (1000000 * min_pulse_short) / F_INTERRUPTS);
2649 printf ("maximum short pulse length: %d usec\n", (1000000 * max_pulse_short) / F_INTERRUPTS);
2650 printf ("average short pulse length: %d usec\n", ((1000000 * sum_pulses_short) / n_pulses_short) / F_INTERRUPTS);
2651
2652 }
2653 putchar ('\n');
2654 printf ("number of long pauses: %d\n", n_pauses_long);
2655 if (n_pauses_long > 0)
2656 {
2657 printf ("minimum long pause length: %d usec\n", (1000000 * min_pause_long) / F_INTERRUPTS);
2658 printf ("maximum long pause length: %d usec\n", (1000000 * max_pause_long) / F_INTERRUPTS);
2659 printf ("average long pause length: %d usec\n", ((1000000 * sum_pauses_long) / n_pauses_long) / F_INTERRUPTS);
2660 }
2661 putchar ('\n');
2662 printf ("number of short pauses: %d\n", n_pauses_short);
2663 if (n_pauses_short > 0)
2664 {
2665 printf ("minimum short pause length: %d usec\n", (1000000 * min_pause_short) / F_INTERRUPTS);
2666 printf ("maximum short pause length: %d usec\n", (1000000 * max_pause_short) / F_INTERRUPTS);
2667 printf ("average short pause length: %d usec\n", ((1000000 * sum_pauses_short) / n_pauses_short) / F_INTERRUPTS);
2668 }
2669 }
2670 return 0;
2671 }
2672
2673 #endif // DEBUG