1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp.c - infrared multi-protocol decoder, supports several remote control protocols
4 * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de
6 * $Id: irmp.c,v 1.17 2010/04/16 09:23:29 fm Exp $
10 * Typical manufacturers:
13 * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers
15 * MATSUSHITA - Matsushita
16 * KASEIKYO - Panasonic, Denon & other Japanese manufacturers (members of "Japan's Association for Electric Home Application")
17 * RECS80 - Philips, Nokia, Thomson, Nordmende, Telefunken, Saba
18 * RC5 - Philips and other European manufacturers
20 * RC6 - Philips and other European manufacturers
22 * NUBERT - Nubert Subwoofer System
23 * B&O - Bang & Olufsen
24 * PANASONIC - Panasonic (older, yet not implemented)
26 *---------------------------------------------------------------------------------------------------------------------------------------------------
31 * frame: 1 start bit + 12-20 data bits + no stop bit
32 * data: 7 command bits + 5 address bits + 0 to 8 additional bits
34 * start bit: data "0": data "1": stop bit:
35 * -----------------_________ ------_____ ------------______
36 * 2400us 600us 600us 600us 1200us 600 us no stop bit
38 *---------------------------------------------------------------------------------------------------------------------------------------------------
41 * -------------------------
43 * frame: 1 start bit + 32 data bits + 1 stop bit
44 * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits
45 * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits
47 * start bit: data "0": data "1": stop bit:
48 * -----------------_________ ------______ ------________________ ------______....
49 * 9000us 4500us 560us 560us 560us 1690 us 560us
54 * -----------------_________------______ .... ~100ms Pause, then repeat
57 *---------------------------------------------------------------------------------------------------------------------------------------------------
62 * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit
63 * data(1): 16 address bits
64 * data(2): 4 ID bits + 8 command bits + 8 inverted command bits
66 * start bit: data "0": data "1": sync bit: stop bit:
67 * ----------______________ ------______ ------________________ ------______________ ------______....
68 * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us
70 *---------------------------------------------------------------------------------------------------------------------------------------------------
75 * frame: 1 start bit + 32 data bits + 1 stop bit
76 * data: 16 address bits + 16 command bits
78 * start bit: data "0": data "1": stop bit:
79 * ----------______________ ------______ ------________________ ------______....
80 * 4500us 4500us 550us 450us 550us 1450us 550us
82 *---------------------------------------------------------------------------------------------------------------------------------------------------
87 * frame: 1 start bit + 24 data bits + 1 stop bit
88 * data: 6 custom bits + 6 command bits + 12 address bits
90 * start bit: data "0": data "1": stop bit:
91 * ----------_________ ------______ ------________________ ------______....
92 * 3488us 3488us 872us 872us 872us 2616us 872us
94 *---------------------------------------------------------------------------------------------------------------------------------------------------
99 * frame: 1 start bit + 48 data bits + 1 stop bit
100 * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits
102 * start bit: data "0": data "1": stop bit:
103 * ----------______ ------______ ------________________ ------______....
104 * 3380us 1690us 423us 423us 423us 1269us 423us
106 *---------------------------------------------------------------------------------------------------------------------------------------------------
111 * frame: 2 start bits + 10 data bits + 1 stop bit
112 * data: 1 toggle bit + 3 address bits + 6 command bits
114 * start bit: data "0": data "1": stop bit:
115 * -----_____________________ -----____________ -----______________ ------_______....
116 * 158us 7432us 158us 4902us 158us 7432us 158us
118 *---------------------------------------------------------------------------------------------------------------------------------------------------
123 * frame: 2 start bits + 11 data bits + 1 stop bit
124 * data: 1 toggle bit + 4 address bits + 6 command bits
126 * start bit: data "0": data "1": stop bit:
127 * -----_____________________ -----____________ -----______________ ------_______....
128 * 158us 3637us 158us 4902us 158us 7432us 158us
130 *---------------------------------------------------------------------------------------------------------------------------------------------------
135 * RC5 frame: 2 start bits + 12 data bits + no stop bit
136 * RC5 data: 1 toggle bit + 5 address bits + 6 command bits
137 * RC5X frame: 1 start bit + 13 data bits + no stop bit
138 * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits
140 * start bit: data "0": data "1":
141 * ______----- ------______ ______------
142 * 889us 889us 889us 889us 889us 889us
144 *---------------------------------------------------------------------------------------------------------------------------------------------------
149 * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit
150 * data: 5 address bits + 10 command bits
152 * data "0": data "1":
153 * ------________________ ------______________
154 * 275us 1050us 275us 1900us
156 *---------------------------------------------------------------------------------------------------------------------------------------------------
161 * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 µs pause
162 * RC6 data: 8 address bits + 8 command bits
164 * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1":
165 * ____________------- _______------- -------_______ _______------- -------_______
166 * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us
168 *---------------------------------------------------------------------------------------------------------------------------------------------------
173 * frame: 1 start bit + 32 data bits + 1 stop bit
174 * data: 16 address bits + 11100000 + 8 command bits
176 * start bit: data "0": data "1": stop bit:
177 * -----------------_________ ------______ ------________________ ------______....
178 * 9000us 4500us 560us 560us 560us 1690 us 560us
180 *---------------------------------------------------------------------------------------------------------------------------------------------------
182 * NUBERT (subwoofer system)
183 * -------------------------
185 * frame: 1 start bit + 10 data bits + 1 stop bit
186 * data: 0 address bits + 10 command bits ?
188 * start bit: data "0": data "1": stop bit:
189 * ----------_____ ------______ ------________________ ------______....
190 * 1340us 340us 500us 1300us 1340us 340us 500us
192 *---------------------------------------------------------------------------------------------------------------------------------------------------
197 * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit
198 * data: 0 address bits + 16 command bits
200 * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit:
201 * -----________ -----________ -----_____________ -----________
202 * 210us 3000us 210us 3000us 210us 15000us 210us 3000us
204 * data "0": data "1": data "repeat bit": trailer bit: stop bit:
205 * -----________ -----_____________ -----___________ -----_____________ -----____...
206 * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us
208 *---------------------------------------------------------------------------------------------------------------------------------------------------
210 * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar)
211 * -----------------------------------------------------------------------------------------
213 * frame: 1 start bit + 22 data bits + 1 stop bit
214 * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits
216 * European version: T = 456us
217 * USA & Canada version: T = 422us
219 * start bit: data "0": data "1": stop bit:
220 * 8T 8T 2T 2T 2T 6T 2T
221 * -------------____________ ------_____ ------_____________ ------_______....
222 * 3648us 3648us 912us 912us 912us 2736us 912us (Europe)
223 * 3376us 3376us 844us 844us 844us 2532us 844us (US)
225 *---------------------------------------------------------------------------------------------------------------------------------------------------
227 * This program is free software; you can redistribute it and/or modify
228 * it under the terms of the GNU General Public License as published by
229 * the Free Software Foundation; either version 2 of the License, or
230 * (at your option) any later version.
231 *---------------------------------------------------------------------------------------------------------------------------------------------------
234 #if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR
235 #define PIC_CCS_COMPILER
238 #ifdef unix // test on linux/unix
243 #include <inttypes.h>
247 #define memcpy_P memcpy
254 typedef unsigned char uint8_t;
255 typedef unsigned short uint16_t;
258 #define memcpy_P memcpy
264 #ifdef PIC_CCS_COMPILER
267 typedef unsigned int8
uint8_t;
268 typedef unsigned int16
uint16_t;
270 #define memcpy_P memcpy
274 #include <inttypes.h>
278 #include <util/delay.h>
279 #include <avr/pgmspace.h>
281 #endif // PIC_CCS_COMPILER
288 #include "irmpconfig.h"
290 #define IRMP_TIMEOUT_TIME 16500.0e-6 // timeout after 16.5 ms darkness
291 #define IRMP_TIMEOUT_LEN (uint8_t)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)
292 #define IRMP_REPETITION_TIME (uint16_t)(F_INTERRUPTS * 100.0e-3 + 0.5) // autodetect key repetition within 100 msec
294 #define MIN_TOLERANCE_00 1.0 // -0%
295 #define MAX_TOLERANCE_00 1.0 // +0%
297 #define MIN_TOLERANCE_05 0.95 // -5%
298 #define MAX_TOLERANCE_05 1.05 // +5%
300 #define MIN_TOLERANCE_10 0.9 // -10%
301 #define MAX_TOLERANCE_10 1.1 // +10%
303 #define MIN_TOLERANCE_15 0.85 // -15%
304 #define MAX_TOLERANCE_15 1.15 // +15%
306 #define MIN_TOLERANCE_20 0.8 // -20%
307 #define MAX_TOLERANCE_20 1.2 // +20%
309 #define MIN_TOLERANCE_30 0.7 // -30%
310 #define MAX_TOLERANCE_30 1.3 // +30%
312 #define MIN_TOLERANCE_40 0.6 // -40%
313 #define MAX_TOLERANCE_40 1.4 // +40%
315 #define MIN_TOLERANCE_50 0.5 // -50%
316 #define MAX_TOLERANCE_50 1.5 // +50%
318 #define MIN_TOLERANCE_60 0.4 // -60%
319 #define MAX_TOLERANCE_60 1.6 // +60%
321 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
322 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
323 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
324 #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
325 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
326 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
327 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
328 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
329 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
330 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
332 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
333 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
334 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
335 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
336 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
337 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
338 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
339 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
340 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
341 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
342 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
343 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
345 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
346 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
347 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
348 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
349 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
350 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
351 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
352 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
353 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
354 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
356 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
357 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
358 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
359 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
360 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
361 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
362 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
363 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
364 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
365 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
367 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
368 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
369 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
370 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
371 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
372 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_60 + 0.5) + 1)
373 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
374 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
375 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
376 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
378 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
379 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
380 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
381 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
382 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
383 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
384 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
385 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
386 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
387 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
389 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
390 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
391 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
392 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
394 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
395 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
396 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
397 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
398 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
399 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
401 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
402 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
403 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
404 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
405 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
406 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
407 #define RC6_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
408 #define RC6_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
410 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
411 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
412 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
413 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
414 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
415 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
416 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
417 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
418 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
419 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
421 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
422 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
423 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
424 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
425 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
426 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
427 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
428 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
429 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
430 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
431 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
432 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
434 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
435 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
436 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
437 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
438 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
439 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
440 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
441 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
442 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
443 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
444 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
445 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
446 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
447 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
448 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
449 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
450 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
451 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
452 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
453 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
454 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
455 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
456 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
457 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
458 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
459 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
461 #define AUTO_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_REPETITION_TIME + 0.5) // use uint16_t!
464 #define DEBUG_PUTCHAR(a) { if (! silent) { putchar (a); } }
465 #define DEBUG_PRINTF(...) { if (! silent) { printf (__VA_ARGS__); } }
468 #define DEBUG_PUTCHAR(a)
469 #define DEBUG_PRINTF(...)
472 #if IRMP_LOGGING == 1
473 #define irmp_logIsr(x) irmp_logIr((x) ? 1:0)
474 #define UART_BAUD 9600L
476 // calculate real baud rate:
477 #define UBRR_VAL ((F_CPU+UART_BAUD*8)/(UART_BAUD*16)-1) // round
478 #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) // real baudrate
481 #if ((BAUD_REAL*1000)/UART_BAUD-1000) > 10
482 # error Error of baud rate of RS232 UARTx is more than 1%. That is too high!
485 #else // not CODEVISION
487 #define BAUD_ERROR ((BAUD_REAL*1000)/UART_BAUD-1000) // error in promille
489 #if ((BAUD_ERROR > 10) || (-BAUD_ERROR < 10))
490 # error Error of baud rate of RS232 UARTx is more than 1%. That is too high!
495 /*---------------------------------------------------------------------------------------------------------------------------------------------------
497 * @details Initializes UART
498 *---------------------------------------------------------------------------------------------------------------------------------------------------
501 irmp_uart_init (void)
503 UCSR0B
|= (1<<TXEN0
); // activate UART0 TX
504 UBRR0H
= UBRR_VAL
>> 8; // store baudrate (upper byte)
505 UBRR0L
= UBRR_VAL
& 0xFF; // store baudrate (lower byte)
508 /*---------------------------------------------------------------------------------------------------------------------------------------------------
510 * @details Sends character
511 * @param ch character to be transmitted
512 *---------------------------------------------------------------------------------------------------------------------------------------------------
515 irmp_uart_putc (unsigned char ch
)
517 while (!(UCSR0A
& (1<<UDRE0
)))
525 /*---------------------------------------------------------------------------------------------------------------------------------------------------
527 *---------------------------------------------------------------------------------------------------------------------------------------------------
529 #define c_startcycles 2 // min count of zeros before start of logging
530 #define c_endBits 1000 // log buffer size
531 #define c_datalen 700 // number of sequenced highbits to detect end
534 irmp_logIr (uint8_t val
)
536 static uint8_t s_data
[c_datalen
]; // logging buffer
537 static uint16_t s_dataIdx
; // number of written bits
538 static uint8_t s_startcycles
; // current number of start-zeros
539 static uint16_t s_ctr
; // counts sequenced highbits - to detect end
541 if ((val
== 0) && (s_startcycles
< c_startcycles
) && !s_dataIdx
) // prevent that single random zeros init logging
549 if ( (val
== 0) // start or continue logging on "0"
550 || ((val
== 1) && (s_dataIdx
!= 0))) // "1" cannot init logging
553 { // set or clear bit in bitarray
554 s_data
[(s_dataIdx
/ 8)] |= (1<<(s_dataIdx
% 8));
558 s_data
[(s_dataIdx
/ 8)] &= ~(1<<(s_dataIdx
% 8));
564 { // if high received then look at log-stop condition
567 if (s_ctr
> c_endBits
)
568 { // if stop condition (200 sequenced ones) meets, output on uart
571 for (i
= 0; i
< c_startcycles
; ++i
)
573 irmp_uart_putc ('0'); // the ignored starting zeros
576 for (i
= 0;i
< (s_dataIdx
- c_endBits
+ 20) / 8; ++i
) // transform bitset into uart chars
578 uint8_t d
= s_data
[i
];
583 irmp_uart_putc ((d
& 1) + '0');
588 irmp_uart_putc ('\n');
601 #define irmp_logIsr(x)
606 uint8_t protocol
; // ir protocol
607 uint8_t pulse_1_len_min
; // minimum length of pulse with bit value 1
608 uint8_t pulse_1_len_max
; // maximum length of pulse with bit value 1
609 uint8_t pause_1_len_min
; // minimum length of pause with bit value 1
610 uint8_t pause_1_len_max
; // maximum length of pause with bit value 1
611 uint8_t pulse_0_len_min
; // minimum length of pulse with bit value 0
612 uint8_t pulse_0_len_max
; // maximum length of pulse with bit value 0
613 uint8_t pause_0_len_min
; // minimum length of pause with bit value 0
614 uint8_t pause_0_len_max
; // maximum length of pause with bit value 0
615 uint8_t address_offset
; // address offset
616 uint8_t address_end
; // end of address
617 uint8_t command_offset
; // command offset
618 uint8_t command_end
; // end of command
619 uint8_t complete_len
; // complete length of frame
620 uint8_t stop_bit
; // flag: frame has stop bit
621 uint8_t lsb_first
; // flag: LSB first
624 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
626 static PROGMEM IRMP_PARAMETER sircs_param
=
629 SIRCS_1_PULSE_LEN_MIN
,
630 SIRCS_1_PULSE_LEN_MAX
,
633 SIRCS_0_PULSE_LEN_MIN
,
634 SIRCS_0_PULSE_LEN_MAX
,
637 SIRCS_ADDRESS_OFFSET
,
638 SIRCS_ADDRESS_OFFSET
+ SIRCS_ADDRESS_LEN
,
639 SIRCS_COMMAND_OFFSET
,
640 SIRCS_COMMAND_OFFSET
+ SIRCS_COMMAND_LEN
,
641 SIRCS_COMPLETE_DATA_LEN
,
648 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
650 static PROGMEM IRMP_PARAMETER nec_param
=
662 NEC_ADDRESS_OFFSET
+ NEC_ADDRESS_LEN
,
664 NEC_COMMAND_OFFSET
+ NEC_COMMAND_LEN
,
665 NEC_COMPLETE_DATA_LEN
,
672 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
674 static PROGMEM IRMP_PARAMETER samsung_param
=
676 IRMP_SAMSUNG_PROTOCOL
,
677 SAMSUNG_PULSE_LEN_MIN
,
678 SAMSUNG_PULSE_LEN_MAX
,
679 SAMSUNG_1_PAUSE_LEN_MIN
,
680 SAMSUNG_1_PAUSE_LEN_MAX
,
681 SAMSUNG_PULSE_LEN_MIN
,
682 SAMSUNG_PULSE_LEN_MAX
,
683 SAMSUNG_0_PAUSE_LEN_MIN
,
684 SAMSUNG_0_PAUSE_LEN_MAX
,
685 SAMSUNG_ADDRESS_OFFSET
,
686 SAMSUNG_ADDRESS_OFFSET
+ SAMSUNG_ADDRESS_LEN
,
687 SAMSUNG_COMMAND_OFFSET
,
688 SAMSUNG_COMMAND_OFFSET
+ SAMSUNG_COMMAND_LEN
,
689 SAMSUNG_COMPLETE_DATA_LEN
,
696 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
698 static PROGMEM IRMP_PARAMETER matsushita_param
=
700 IRMP_MATSUSHITA_PROTOCOL
,
701 MATSUSHITA_PULSE_LEN_MIN
,
702 MATSUSHITA_PULSE_LEN_MAX
,
703 MATSUSHITA_1_PAUSE_LEN_MIN
,
704 MATSUSHITA_1_PAUSE_LEN_MAX
,
705 MATSUSHITA_PULSE_LEN_MIN
,
706 MATSUSHITA_PULSE_LEN_MAX
,
707 MATSUSHITA_0_PAUSE_LEN_MIN
,
708 MATSUSHITA_0_PAUSE_LEN_MAX
,
709 MATSUSHITA_ADDRESS_OFFSET
,
710 MATSUSHITA_ADDRESS_OFFSET
+ MATSUSHITA_ADDRESS_LEN
,
711 MATSUSHITA_COMMAND_OFFSET
,
712 MATSUSHITA_COMMAND_OFFSET
+ MATSUSHITA_COMMAND_LEN
,
713 MATSUSHITA_COMPLETE_DATA_LEN
,
720 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
722 static PROGMEM IRMP_PARAMETER kaseikyo_param
=
724 IRMP_KASEIKYO_PROTOCOL
,
725 KASEIKYO_PULSE_LEN_MIN
,
726 KASEIKYO_PULSE_LEN_MAX
,
727 KASEIKYO_1_PAUSE_LEN_MIN
,
728 KASEIKYO_1_PAUSE_LEN_MAX
,
729 KASEIKYO_PULSE_LEN_MIN
,
730 KASEIKYO_PULSE_LEN_MAX
,
731 KASEIKYO_0_PAUSE_LEN_MIN
,
732 KASEIKYO_0_PAUSE_LEN_MAX
,
733 KASEIKYO_ADDRESS_OFFSET
,
734 KASEIKYO_ADDRESS_OFFSET
+ KASEIKYO_ADDRESS_LEN
,
735 KASEIKYO_COMMAND_OFFSET
,
736 KASEIKYO_COMMAND_OFFSET
+ KASEIKYO_COMMAND_LEN
,
737 KASEIKYO_COMPLETE_DATA_LEN
,
744 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
746 static PROGMEM IRMP_PARAMETER recs80_param
=
748 IRMP_RECS80_PROTOCOL
,
749 RECS80_PULSE_LEN_MIN
,
750 RECS80_PULSE_LEN_MAX
,
751 RECS80_1_PAUSE_LEN_MIN
,
752 RECS80_1_PAUSE_LEN_MAX
,
753 RECS80_PULSE_LEN_MIN
,
754 RECS80_PULSE_LEN_MAX
,
755 RECS80_0_PAUSE_LEN_MIN
,
756 RECS80_0_PAUSE_LEN_MAX
,
757 RECS80_ADDRESS_OFFSET
,
758 RECS80_ADDRESS_OFFSET
+ RECS80_ADDRESS_LEN
,
759 RECS80_COMMAND_OFFSET
,
760 RECS80_COMMAND_OFFSET
+ RECS80_COMMAND_LEN
,
761 RECS80_COMPLETE_DATA_LEN
,
768 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
770 static PROGMEM IRMP_PARAMETER rc5_param
=
777 1, // tricky: use this as stop bit length
782 RC5_ADDRESS_OFFSET
+ RC5_ADDRESS_LEN
,
784 RC5_COMMAND_OFFSET
+ RC5_COMMAND_LEN
,
785 RC5_COMPLETE_DATA_LEN
,
792 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
794 static PROGMEM IRMP_PARAMETER denon_param
=
799 DENON_1_PAUSE_LEN_MIN
,
800 DENON_1_PAUSE_LEN_MAX
,
803 DENON_0_PAUSE_LEN_MIN
,
804 DENON_0_PAUSE_LEN_MAX
,
805 DENON_ADDRESS_OFFSET
,
806 DENON_ADDRESS_OFFSET
+ DENON_ADDRESS_LEN
,
807 DENON_COMMAND_OFFSET
,
808 DENON_COMMAND_OFFSET
+ DENON_COMMAND_LEN
,
809 DENON_COMPLETE_DATA_LEN
,
816 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
818 static PROGMEM IRMP_PARAMETER rc6_param
=
825 1, // tricky: use this as stop bit length
830 RC6_ADDRESS_OFFSET
+ RC6_ADDRESS_LEN
,
832 RC6_COMMAND_OFFSET
+ RC6_COMMAND_LEN
,
833 RC6_COMPLETE_DATA_LEN_SHORT
,
840 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
842 static PROGMEM IRMP_PARAMETER recs80ext_param
=
844 IRMP_RECS80EXT_PROTOCOL
,
845 RECS80EXT_PULSE_LEN_MIN
,
846 RECS80EXT_PULSE_LEN_MAX
,
847 RECS80EXT_1_PAUSE_LEN_MIN
,
848 RECS80EXT_1_PAUSE_LEN_MAX
,
849 RECS80EXT_PULSE_LEN_MIN
,
850 RECS80EXT_PULSE_LEN_MAX
,
851 RECS80EXT_0_PAUSE_LEN_MIN
,
852 RECS80EXT_0_PAUSE_LEN_MAX
,
853 RECS80EXT_ADDRESS_OFFSET
,
854 RECS80EXT_ADDRESS_OFFSET
+ RECS80EXT_ADDRESS_LEN
,
855 RECS80EXT_COMMAND_OFFSET
,
856 RECS80EXT_COMMAND_OFFSET
+ RECS80EXT_COMMAND_LEN
,
857 RECS80EXT_COMPLETE_DATA_LEN
,
864 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
866 static PROGMEM IRMP_PARAMETER nubert_param
=
868 IRMP_NUBERT_PROTOCOL
,
869 NUBERT_1_PULSE_LEN_MIN
,
870 NUBERT_1_PULSE_LEN_MAX
,
871 NUBERT_1_PAUSE_LEN_MIN
,
872 NUBERT_1_PAUSE_LEN_MAX
,
873 NUBERT_0_PULSE_LEN_MIN
,
874 NUBERT_0_PULSE_LEN_MAX
,
875 NUBERT_0_PAUSE_LEN_MIN
,
876 NUBERT_0_PAUSE_LEN_MAX
,
877 NUBERT_ADDRESS_OFFSET
,
878 NUBERT_ADDRESS_OFFSET
+ NUBERT_ADDRESS_LEN
,
879 NUBERT_COMMAND_OFFSET
,
880 NUBERT_COMMAND_OFFSET
+ NUBERT_COMMAND_LEN
,
881 NUBERT_COMPLETE_DATA_LEN
,
888 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
890 static PROGMEM IRMP_PARAMETER bang_olufsen_param
=
892 IRMP_BANG_OLUFSEN_PROTOCOL
,
893 BANG_OLUFSEN_PULSE_LEN_MIN
,
894 BANG_OLUFSEN_PULSE_LEN_MAX
,
895 BANG_OLUFSEN_1_PAUSE_LEN_MIN
,
896 BANG_OLUFSEN_1_PAUSE_LEN_MAX
,
897 BANG_OLUFSEN_PULSE_LEN_MIN
,
898 BANG_OLUFSEN_PULSE_LEN_MAX
,
899 BANG_OLUFSEN_0_PAUSE_LEN_MIN
,
900 BANG_OLUFSEN_0_PAUSE_LEN_MAX
,
901 BANG_OLUFSEN_ADDRESS_OFFSET
,
902 BANG_OLUFSEN_ADDRESS_OFFSET
+ BANG_OLUFSEN_ADDRESS_LEN
,
903 BANG_OLUFSEN_COMMAND_OFFSET
,
904 BANG_OLUFSEN_COMMAND_OFFSET
+ BANG_OLUFSEN_COMMAND_LEN
,
905 BANG_OLUFSEN_COMPLETE_DATA_LEN
,
906 BANG_OLUFSEN_STOP_BIT
,
912 static uint8_t irmp_bit
; // current bit position
913 static IRMP_PARAMETER irmp_param
;
915 static volatile uint8_t irmp_ir_detected
;
916 static volatile uint8_t irmp_protocol
;
917 static volatile uint16_t irmp_address
;
918 static volatile uint16_t irmp_command
;
919 static volatile uint16_t irmp_id
; // only used for SAMSUNG protocol
920 static volatile uint8_t irmp_flags
;
923 static uint8_t IRMP_PIN
;
926 /*---------------------------------------------------------------------------------------------------------------------------------------------------
927 * Initialize IRMP decoder
928 * @details Configures IRMP input pin
929 *---------------------------------------------------------------------------------------------------------------------------------------------------
935 #ifndef PIC_CCS_COMPILER
936 IRMP_PORT
&= ~(1<<IRMP_BIT
); // deactivate pullup
937 IRMP_DDR
&= ~(1<<IRMP_BIT
); // set pin to input
938 #endif // PIC_CCS_COMPILER
940 #if IRMP_LOGGING == 1
945 /*---------------------------------------------------------------------------------------------------------------------------------------------------
947 * @details gets decoded IRMP data
948 * @param pointer in order to store IRMP data
949 * @return TRUE: successful, FALSE: failed
950 *---------------------------------------------------------------------------------------------------------------------------------------------------
953 irmp_get_data (IRMP_DATA
* irmp_data_p
)
957 if (irmp_ir_detected
)
959 switch (irmp_protocol
)
961 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
962 case IRMP_SAMSUNG_PROTOCOL
:
963 if ((irmp_command
>> 8) == (~irmp_command
& 0x00FF))
965 irmp_command
&= 0xff;
966 irmp_command
|= irmp_id
<< 8;
971 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
972 case IRMP_NEC_PROTOCOL
:
973 if ((irmp_command
>> 8) == (~irmp_command
& 0x00FF))
975 irmp_command
&= 0xff;
978 else if ((irmp_command
& 0xFF00) == 0xD100)
980 DEBUG_PRINTF ("Switching to APPLE protocol\n");
981 irmp_protocol
= IRMP_APPLE_PROTOCOL
;
982 irmp_command
&= 0xff;
993 irmp_data_p
->protocol
= irmp_protocol
;
994 irmp_data_p
->address
= irmp_address
;
995 irmp_data_p
->command
= irmp_command
;
996 irmp_data_p
->flags
= irmp_flags
;
1002 irmp_ir_detected
= FALSE
;
1008 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1009 static uint16_t irmp_tmp_address
; // ir address
1010 static uint16_t irmp_tmp_command
; // ir command
1011 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1012 static uint16_t irmp_tmp_id
; // ir id (only SAMSUNG)
1015 static uint8_t irmp_bit
; // current bit position
1017 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1019 * @details store bit in temp address or temp command
1020 * @param value to store: 0 or 1
1021 *---------------------------------------------------------------------------------------------------------------------------------------------------
1024 irmp_store_bit (uint8_t value
)
1026 if (irmp_bit
>= irmp_param
.address_offset
&& irmp_bit
< irmp_param
.address_end
)
1028 if (irmp_param
.lsb_first
)
1030 irmp_tmp_address
|= (((uint16_t) (value
)) << (irmp_bit
- irmp_param
.address_offset
)); // CV wants cast
1034 irmp_tmp_address
<<= 1;
1035 irmp_tmp_address
|= value
;
1038 else if (irmp_bit
>= irmp_param
.command_offset
&& irmp_bit
< irmp_param
.command_end
)
1040 if (irmp_param
.lsb_first
)
1042 irmp_tmp_command
|= (((uint16_t) (value
)) << (irmp_bit
- irmp_param
.command_offset
)); // CV wants cast
1046 irmp_tmp_command
<<= 1;
1047 irmp_tmp_command
|= value
;
1050 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1051 else if (irmp_param
.protocol
== IRMP_SAMSUNG_PROTOCOL
&& irmp_bit
>= SAMSUNG_ID_OFFSET
&& irmp_bit
< SAMSUNG_ID_OFFSET
+ SAMSUNG_ID_LEN
)
1053 irmp_tmp_id
|= (((uint16_t) (value
)) << (irmp_bit
- SAMSUNG_ID_OFFSET
)); // store with LSB first
1059 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1061 * @details ISR routine, called 10000 times per second
1062 *---------------------------------------------------------------------------------------------------------------------------------------------------
1067 static uint8_t irmp_start_bit_detected
; // flag: start bit detected
1068 static uint8_t wait_for_space
; // flag: wait for data bit space
1069 static uint8_t wait_for_start_space
; // flag: wait for start bit space
1070 static uint8_t irmp_pulse_time
; // count bit time for pulse
1071 static uint8_t irmp_pause_time
; // count bit time for pause
1072 static uint16_t last_irmp_address
= 0xFFFF; // save last irmp address to recognize key repetition
1073 static uint16_t last_irmp_command
= 0xFFFF; // save last irmp command to recognize key repetition
1074 static uint16_t repetition_counter
; // SIRCS repeats frame 2-5 times with 45 ms pause
1075 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1076 static uint16_t last_irmp_denon_command
; // save last irmp command to recognize DENON frame repetition
1078 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1079 static uint8_t rc5_cmd_bit6
; // bit 6 of RC5 command is the inverted 2nd start bit
1081 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1
1082 static uint8_t last_pause
; // last pause value
1084 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1085 static uint8_t last_value
; // last bit value
1087 uint8_t irmp_input
; // input value
1089 irmp_input
= input(IRMP_PIN
);
1091 irmp_logIsr(irmp_input
); // log ir signal, if IRMP_LOGGING defined
1093 if (! irmp_ir_detected
) // ir code already detected?
1095 if (! irmp_start_bit_detected
) // start bit detected?
1097 if (!irmp_input
) // receiving burst?
1099 irmp_pulse_time
++; // increment counter
1103 if (irmp_pulse_time
) // it's dark....
1104 { // set flags for counting the time of darkness...
1105 irmp_start_bit_detected
= 1;
1106 wait_for_start_space
= 1;
1108 irmp_tmp_command
= 0;
1109 irmp_tmp_address
= 0;
1111 irmp_pause_time
= 1; // 1st pause: set to 1, not to 0!
1112 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1113 rc5_cmd_bit6
= 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1118 repetition_counter
++;
1124 if (wait_for_start_space
) // we have received start bit...
1125 { // ...and are counting the time of darkness
1126 if (irmp_input
) // still dark?
1128 irmp_pause_time
++; // increment counter
1130 if (irmp_pause_time
> IRMP_TIMEOUT_LEN
) // timeout?
1132 DEBUG_PRINTF ("error 1: pause after start bit %d too long: %d\n", irmp_pulse_time
, irmp_pause_time
);
1133 irmp_start_bit_detected
= 0; // reset flags, let's wait for another start bit
1134 irmp_pulse_time
= 0;
1135 irmp_pause_time
= 0;
1139 { // receiving first data pulse!
1140 DEBUG_PRINTF ("start-bit: pulse = %d, pause = %d\n", irmp_pulse_time
, irmp_pause_time
);
1142 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1143 if (irmp_pulse_time
>= SIRCS_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= SIRCS_START_BIT_PULSE_LEN_MAX
&&
1144 irmp_pause_time
>= SIRCS_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SIRCS_START_BIT_PAUSE_LEN_MAX
)
1146 DEBUG_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1147 SIRCS_START_BIT_PULSE_LEN_MIN
, SIRCS_START_BIT_PULSE_LEN_MAX
,
1148 SIRCS_START_BIT_PAUSE_LEN_MIN
, SIRCS_START_BIT_PAUSE_LEN_MAX
);
1149 memcpy_P (&irmp_param
, &sircs_param
, sizeof (IRMP_PARAMETER
));
1152 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1154 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1155 if (irmp_pulse_time
>= NEC_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= NEC_START_BIT_PULSE_LEN_MAX
&&
1156 ((irmp_pause_time
>= NEC_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NEC_START_BIT_PAUSE_LEN_MAX
) ||
1157 (irmp_pause_time
>= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
)))
1159 if (irmp_pause_time
<= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
)
1161 DEBUG_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1162 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
,
1163 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN
, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
);
1167 DEBUG_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1168 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
,
1169 NEC_START_BIT_PAUSE_LEN_MIN
, NEC_START_BIT_PAUSE_LEN_MAX
);
1172 memcpy_P (&irmp_param
, &nec_param
, sizeof (IRMP_PARAMETER
));
1174 if (irmp_pause_time
<= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
)
1176 irmp_param
.address_offset
= 0;
1177 irmp_param
.address_end
= 0;
1178 irmp_param
.command_offset
= 0;
1179 irmp_param
.command_end
= 0;
1180 irmp_param
.complete_len
= 0;
1184 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1186 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1187 if (irmp_pulse_time
>= SAMSUNG_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_START_BIT_PULSE_LEN_MAX
&&
1188 irmp_pause_time
>= SAMSUNG_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_START_BIT_PAUSE_LEN_MAX
)
1190 DEBUG_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1191 SAMSUNG_START_BIT_PULSE_LEN_MIN
, SAMSUNG_START_BIT_PULSE_LEN_MAX
,
1192 SAMSUNG_START_BIT_PAUSE_LEN_MIN
, SAMSUNG_START_BIT_PAUSE_LEN_MAX
);
1193 memcpy_P (&irmp_param
, &samsung_param
, sizeof (IRMP_PARAMETER
));
1196 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1198 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1199 if (irmp_pulse_time
>= MATSUSHITA_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= MATSUSHITA_START_BIT_PULSE_LEN_MAX
&&
1200 irmp_pause_time
>= MATSUSHITA_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= MATSUSHITA_START_BIT_PAUSE_LEN_MAX
)
1201 { // it's MATSUSHITA
1202 DEBUG_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1203 MATSUSHITA_START_BIT_PULSE_LEN_MIN
, MATSUSHITA_START_BIT_PULSE_LEN_MAX
,
1204 MATSUSHITA_START_BIT_PAUSE_LEN_MIN
, MATSUSHITA_START_BIT_PAUSE_LEN_MAX
);
1205 memcpy_P (&irmp_param
, &matsushita_param
, sizeof (IRMP_PARAMETER
));
1208 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1210 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1211 if (irmp_pulse_time
>= KASEIKYO_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= KASEIKYO_START_BIT_PULSE_LEN_MAX
&&
1212 irmp_pause_time
>= KASEIKYO_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= KASEIKYO_START_BIT_PAUSE_LEN_MAX
)
1214 DEBUG_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1215 KASEIKYO_START_BIT_PULSE_LEN_MIN
, KASEIKYO_START_BIT_PULSE_LEN_MAX
,
1216 KASEIKYO_START_BIT_PAUSE_LEN_MIN
, KASEIKYO_START_BIT_PAUSE_LEN_MAX
);
1217 memcpy_P (&irmp_param
, &kaseikyo_param
, sizeof (IRMP_PARAMETER
));
1220 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1222 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1223 if (irmp_pulse_time
>= RECS80_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RECS80_START_BIT_PULSE_LEN_MAX
&&
1224 irmp_pause_time
>= RECS80_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RECS80_START_BIT_PAUSE_LEN_MAX
)
1226 DEBUG_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1227 RECS80_START_BIT_PULSE_LEN_MIN
, RECS80_START_BIT_PULSE_LEN_MAX
,
1228 RECS80_START_BIT_PAUSE_LEN_MIN
, RECS80_START_BIT_PAUSE_LEN_MAX
);
1229 memcpy_P (&irmp_param
, &recs80_param
, sizeof (IRMP_PARAMETER
));
1232 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1234 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1235 if (((irmp_pulse_time
>= RC5_START_BIT_LEN_MIN
&& irmp_pulse_time
<= RC5_START_BIT_LEN_MAX
) ||
1236 (irmp_pulse_time
>= 2 * RC5_START_BIT_LEN_MIN
&& irmp_pulse_time
<= 2 * RC5_START_BIT_LEN_MAX
)) &&
1237 ((irmp_pause_time
>= RC5_START_BIT_LEN_MIN
&& irmp_pause_time
<= RC5_START_BIT_LEN_MAX
) ||
1238 (irmp_pause_time
>= 2 * RC5_START_BIT_LEN_MIN
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
)))
1240 DEBUG_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1241 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
,
1242 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
);
1243 memcpy_P (&irmp_param
, &rc5_param
, sizeof (IRMP_PARAMETER
));
1244 last_pause
= irmp_pause_time
;
1246 if ((irmp_pulse_time
> RC5_START_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC5_START_BIT_LEN_MAX
) ||
1247 (irmp_pause_time
> RC5_START_BIT_LEN_MAX
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
))
1250 rc5_cmd_bit6
= 1<<6;
1258 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1260 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1261 if ( (irmp_pulse_time
>= DENON_PULSE_LEN_MIN
&& irmp_pulse_time
<= DENON_PULSE_LEN_MAX
) &&
1262 ((irmp_pause_time
>= DENON_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_1_PAUSE_LEN_MAX
) ||
1263 (irmp_pause_time
>= DENON_0_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_0_PAUSE_LEN_MAX
)))
1265 DEBUG_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
1266 DENON_PULSE_LEN_MIN
, DENON_PULSE_LEN_MAX
,
1267 DENON_1_PAUSE_LEN_MIN
, DENON_1_PAUSE_LEN_MAX
,
1268 DENON_0_PAUSE_LEN_MIN
, DENON_0_PAUSE_LEN_MAX
);
1269 memcpy_P (&irmp_param
, &denon_param
, sizeof (IRMP_PARAMETER
));
1272 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1274 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1275 if (irmp_pulse_time
>= RC6_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RC6_START_BIT_PULSE_LEN_MAX
&&
1276 irmp_pause_time
>= RC6_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RC6_START_BIT_PAUSE_LEN_MAX
)
1278 DEBUG_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1279 RC6_START_BIT_PULSE_LEN_MIN
, RC6_START_BIT_PULSE_LEN_MAX
,
1280 RC6_START_BIT_PAUSE_LEN_MIN
, RC6_START_BIT_PAUSE_LEN_MAX
);
1281 memcpy_P (&irmp_param
, &rc6_param
, sizeof (IRMP_PARAMETER
));
1286 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1288 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1289 if (irmp_pulse_time
>= RECS80EXT_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RECS80EXT_START_BIT_PULSE_LEN_MAX
&&
1290 irmp_pause_time
>= RECS80EXT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RECS80EXT_START_BIT_PAUSE_LEN_MAX
)
1292 DEBUG_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1293 RECS80EXT_START_BIT_PULSE_LEN_MIN
, RECS80EXT_START_BIT_PULSE_LEN_MAX
,
1294 RECS80EXT_START_BIT_PAUSE_LEN_MIN
, RECS80EXT_START_BIT_PAUSE_LEN_MAX
);
1295 memcpy_P (&irmp_param
, &recs80ext_param
, sizeof (IRMP_PARAMETER
));
1298 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1300 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1301 if (irmp_pulse_time
>= NUBERT_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= NUBERT_START_BIT_PULSE_LEN_MAX
&&
1302 irmp_pause_time
>= NUBERT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NUBERT_START_BIT_PAUSE_LEN_MAX
)
1304 DEBUG_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1305 NUBERT_START_BIT_PULSE_LEN_MIN
, NUBERT_START_BIT_PULSE_LEN_MAX
,
1306 NUBERT_START_BIT_PAUSE_LEN_MIN
, NUBERT_START_BIT_PAUSE_LEN_MAX
);
1307 memcpy_P (&irmp_param
, &nubert_param
, sizeof (IRMP_PARAMETER
));
1310 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1312 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1313 if (irmp_pulse_time
>= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN
&& irmp_pulse_time
<= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX
&&
1314 irmp_pause_time
>= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX
)
1315 { // it's BANG_OLUFSEN
1316 DEBUG_PRINTF ("protocol = BANG_OLUFSEN\n");
1317 DEBUG_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1318 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX
,
1319 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX
);
1320 DEBUG_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1321 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX
,
1322 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX
);
1323 DEBUG_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1324 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX
,
1325 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX
);
1326 DEBUG_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1327 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX
,
1328 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX
);
1329 memcpy_P (&irmp_param
, &bang_olufsen_param
, sizeof (IRMP_PARAMETER
));
1333 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1336 DEBUG_PRINTF ("protocol = UNKNOWN\n");
1337 irmp_start_bit_detected
= 0; // wait for another start bit...
1340 if (irmp_start_bit_detected
)
1342 DEBUG_PRINTF ("pulse_1: %3d - %3d\n", irmp_param
.pulse_1_len_min
, irmp_param
.pulse_1_len_max
);
1343 DEBUG_PRINTF ("pause_1: %3d - %3d\n", irmp_param
.pause_1_len_min
, irmp_param
.pause_1_len_max
);
1344 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1345 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
)
1347 DEBUG_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN
, RC6_TOGGLE_BIT_LEN_MAX
);
1350 DEBUG_PRINTF ("pulse_0: %3d - %3d\n", irmp_param
.pulse_0_len_min
, irmp_param
.pulse_0_len_max
);
1351 DEBUG_PRINTF ("pause_0: %3d - %3d\n", irmp_param
.pause_0_len_min
, irmp_param
.pause_0_len_max
);
1352 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1353 if (irmp_param
.protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1355 DEBUG_PRINTF ("pulse_r: %3d - %3d\n", irmp_param
.pulse_0_len_min
, irmp_param
.pulse_0_len_max
);
1356 DEBUG_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN
, BANG_OLUFSEN_R_PAUSE_LEN_MAX
);
1360 DEBUG_PRINTF ("command_offset: %2d\n", irmp_param
.command_offset
);
1361 DEBUG_PRINTF ("command_len: %3d\n", irmp_param
.command_end
- irmp_param
.command_offset
);
1362 DEBUG_PRINTF ("complete_len: %3d\n", irmp_param
.complete_len
);
1363 DEBUG_PRINTF ("stop_bit: %3d\n", irmp_param
.stop_bit
);
1368 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1369 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
)
1371 if (irmp_pause_time
> RC5_START_BIT_LEN_MAX
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
)
1373 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1374 DEBUG_PUTCHAR ('1');
1375 DEBUG_PUTCHAR ('\n');
1378 else if (! last_value
)
1380 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1381 DEBUG_PUTCHAR ('0');
1382 DEBUG_PUTCHAR ('\n');
1387 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1389 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1390 if (irmp_param
.protocol
== IRMP_DENON_PROTOCOL
)
1392 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1394 if (irmp_pause_time
>= DENON_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_1_PAUSE_LEN_MAX
)
1395 { // pause timings correct for "1"?
1396 DEBUG_PUTCHAR ('1'); // yes, store 1
1397 DEBUG_PUTCHAR ('\n');
1400 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
1401 { // pause timings correct for "0"?
1402 DEBUG_PUTCHAR ('0'); // yes, store 0
1403 DEBUG_PUTCHAR ('\n');
1407 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1409 irmp_pulse_time
= 1; // set counter to 1, not 0
1410 irmp_pause_time
= 0;
1411 wait_for_start_space
= 0;
1414 else if (wait_for_space
) // the data section....
1415 { // counting the time of darkness....
1416 uint8_t got_light
= FALSE
;
1418 if (irmp_input
) // still dark?
1420 if (irmp_bit
== irmp_param
.complete_len
&& irmp_param
.stop_bit
== 1)
1422 if (irmp_pulse_time
>= irmp_param
.pulse_0_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_0_len_max
)
1425 if (irmp_param
.protocol
!= IRMP_RC5_PROTOCOL
)
1427 DEBUG_PRINTF ("stop bit detected\n");
1430 irmp_param
.stop_bit
= 0;
1434 DEBUG_PRINTF ("stop bit timing wrong\n");
1436 irmp_start_bit_detected
= 0; // wait for another start bit...
1437 irmp_pulse_time
= 0;
1438 irmp_pause_time
= 0;
1443 irmp_pause_time
++; // increment counter
1445 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1446 if (irmp_param
.protocol
== IRMP_SIRCS_PROTOCOL
&& // Sony has a variable number of bits:
1447 irmp_pause_time
> SIRCS_PAUSE_LEN_MAX
&& // minimum is 12
1448 irmp_bit
>= 12 - 1) // pause too long?
1449 { // yes, break and close this frame
1450 irmp_param
.complete_len
= irmp_bit
+ 1; // set new complete length
1451 got_light
= TRUE
; // this is a lie, but helps (generates stop bit)
1452 irmp_param
.command_end
= irmp_param
.command_offset
+ irmp_bit
+ 1; // correct command length
1453 irmp_pause_time
= SIRCS_PAUSE_LEN_MAX
- 1; // correct pause length
1457 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1458 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
&&
1459 irmp_pause_time
> 2 * RC5_BIT_LEN_MAX
&& irmp_bit
>= RC5_COMPLETE_DATA_LEN
- 2 && !irmp_param
.stop_bit
)
1460 { // special rc5 decoder
1461 got_light
= TRUE
; // this is a lie, but generates a stop bit ;-)
1462 irmp_param
.stop_bit
= TRUE
; // set flag
1466 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1467 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
&&
1468 irmp_pause_time
> 2 * RC6_BIT_LEN_MAX
&& irmp_bit
>= irmp_param
.complete_len
- 2 && !irmp_param
.stop_bit
)
1469 { // special rc6 decoder
1470 got_light
= TRUE
; // this is a lie, but generates a stop bit ;-)
1471 irmp_param
.stop_bit
= TRUE
; // set flag
1475 if (irmp_pause_time
> IRMP_TIMEOUT_LEN
) // timeout?
1477 if (irmp_bit
== irmp_param
.complete_len
- 1 && irmp_param
.stop_bit
== 0)
1483 DEBUG_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time
, irmp_bit
);
1485 irmp_start_bit_detected
= 0; // wait for another start bit...
1486 irmp_pulse_time
= 0;
1487 irmp_pause_time
= 0;
1499 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1501 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1502 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
) // special rc5 decoder
1504 if (irmp_pulse_time
> RC5_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC5_BIT_LEN_MAX
)
1506 DEBUG_PUTCHAR ('1');
1508 DEBUG_PUTCHAR ('0');
1509 DEBUG_PUTCHAR ('\n');
1514 else // if (irmp_pulse_time >= RC5_BIT_LEN_MIN && irmp_pulse_time <= RC5_BIT_LEN_MAX)
1518 if (last_pause
> RC5_BIT_LEN_MAX
&& last_pause
<= 2 * RC5_BIT_LEN_MAX
)
1520 rc5_value
= last_value
? 0 : 1;
1521 last_value
= rc5_value
;
1525 rc5_value
= last_value
;
1528 DEBUG_PUTCHAR (rc5_value
+ '0');
1529 DEBUG_PUTCHAR ('\n');
1530 irmp_store_bit (rc5_value
);
1533 last_pause
= irmp_pause_time
;
1539 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1540 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
) // special rc6 decoder
1543 { // handle toggle bit, which is 2 times longer than other bits
1547 if (irmp_pulse_time
> RC6_TOGGLE_BIT_LEN_MAX
&& irmp_pause_time
> RC6_TOGGLE_BIT_LEN_MAX
)
1549 DEBUG_PUTCHAR ('1');
1553 DEBUG_PUTCHAR ('0');
1556 DEBUG_PUTCHAR ('\n');
1560 if (irmp_pulse_time
> RC6_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC6_BIT_LEN_MAX
)
1562 DEBUG_PUTCHAR ('0');
1564 DEBUG_PUTCHAR ('1');
1565 DEBUG_PUTCHAR ('\n');
1569 else // if (irmp_pulse_time >= RC6_BIT_LEN_MIN && irmp_pulse_time <= RC6_BIT_LEN_MAX)
1573 if (last_pause
> RC6_BIT_LEN_MAX
&& last_pause
<= 2 * RC6_BIT_LEN_MAX
)
1575 rc5_value
= last_value
? 0 : 1;
1576 last_value
= rc5_value
;
1580 rc5_value
= last_value
;
1583 if (irmp_bit
== 1 && rc5_value
== 0)
1585 irmp_param
.complete_len
= RC6_COMPLETE_DATA_LEN_LONG
;
1588 DEBUG_PUTCHAR (rc5_value
+ '0');
1589 DEBUG_PUTCHAR ('\n');
1590 irmp_store_bit (rc5_value
);
1593 last_pause
= irmp_pause_time
;
1602 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1603 if (irmp_param
.protocol
== IRMP_SAMSUNG_PROTOCOL
&& irmp_bit
== 16) // Samsung: 16th bit
1605 if (irmp_pulse_time
>= SAMSUNG_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_PULSE_LEN_MAX
&&
1606 irmp_pause_time
>= SAMSUNG_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_START_BIT_PAUSE_LEN_MAX
)
1608 DEBUG_PRINTF ("SYNC\n");
1613 else if (irmp_pulse_time
>= SAMSUNG_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_PULSE_LEN_MAX
)
1615 if (irmp_pause_time
>= SAMSUNG_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_1_PAUSE_LEN_MAX
)
1617 DEBUG_PUTCHAR ('1');
1618 DEBUG_PUTCHAR ('\n');
1624 DEBUG_PUTCHAR ('0');
1625 DEBUG_PUTCHAR ('\n');
1630 DEBUG_PRINTF ("Switching to SAMSUNG32 protocol\n");
1632 irmp_param
.protocol
= IRMP_SAMSUNG32_PROTOCOL
;
1633 irmp_param
.command_offset
= SAMSUNG32_COMMAND_OFFSET
;
1634 irmp_param
.command_end
= SAMSUNG32_COMMAND_OFFSET
+ SAMSUNG32_COMMAND_LEN
;
1635 irmp_param
.complete_len
= SAMSUNG32_COMPLETE_DATA_LEN
;
1638 { // timing incorrect!
1639 DEBUG_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1640 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1641 irmp_pause_time
= 0;
1644 irmp_pulse_time
= 1; // set counter to 1, not 0
1647 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
1649 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1650 if (irmp_param
.protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1652 if (irmp_pulse_time
>= BANG_OLUFSEN_PULSE_LEN_MIN
&& irmp_pulse_time
<= BANG_OLUFSEN_PULSE_LEN_MAX
)
1654 if (irmp_bit
== 1) // Bang & Olufsen: 3rd bit
1656 if (irmp_pause_time
>= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX
)
1658 DEBUG_PRINTF ("3rd start bit\n");
1664 { // timing incorrect!
1665 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
);
1666 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1667 irmp_pause_time
= 0;
1670 irmp_pulse_time
= 1; // set counter to 1, not 0
1672 else if (irmp_bit
== 19) // Bang & Olufsen: trailer bit
1674 if (irmp_pause_time
>= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX
)
1676 DEBUG_PRINTF ("trailer bit\n");
1682 { // timing incorrect!
1683 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
);
1684 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1685 irmp_pause_time
= 0;
1688 irmp_pulse_time
= 1; // set counter to 1, not 0
1692 if (irmp_pause_time
>= irmp_param
.pause_1_len_min
&& irmp_pause_time
<= irmp_param
.pause_1_len_max
)
1693 { // pulse & pause timings correct for "1"?
1694 DEBUG_PUTCHAR ('1');
1695 DEBUG_PUTCHAR ('\n');
1700 else if (irmp_pause_time
>= irmp_param
.pause_0_len_min
&& irmp_pause_time
<= irmp_param
.pause_0_len_max
)
1701 { // pulse & pause timings correct for "0"?
1702 DEBUG_PUTCHAR ('0');
1703 DEBUG_PUTCHAR ('\n');
1708 else if (irmp_pause_time
>= BANG_OLUFSEN_R_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_R_PAUSE_LEN_MAX
)
1710 DEBUG_PUTCHAR (last_value
+ '0');
1711 DEBUG_PUTCHAR ('\n');
1712 irmp_store_bit (last_value
);
1716 { // timing incorrect!
1717 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
);
1718 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1719 irmp_pause_time
= 0;
1724 { // timing incorrect!
1725 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
);
1726 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1727 irmp_pause_time
= 0;
1731 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
1733 if (irmp_pulse_time
>= irmp_param
.pulse_1_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_1_len_max
&&
1734 irmp_pause_time
>= irmp_param
.pause_1_len_min
&& irmp_pause_time
<= irmp_param
.pause_1_len_max
)
1735 { // pulse & pause timings correct for "1"?
1736 DEBUG_PUTCHAR ('1');
1737 DEBUG_PUTCHAR ('\n');
1741 else if (irmp_pulse_time
>= irmp_param
.pulse_0_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_0_len_max
&&
1742 irmp_pause_time
>= irmp_param
.pause_0_len_min
&& irmp_pause_time
<= irmp_param
.pause_0_len_max
)
1743 { // pulse & pause timings correct for "0"?
1744 DEBUG_PUTCHAR ('0');
1745 DEBUG_PUTCHAR ('\n');
1750 { // timing incorrect!
1751 DEBUG_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1752 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1753 irmp_pause_time
= 0;
1756 irmp_pulse_time
= 1; // set counter to 1, not 0
1760 { // counting the pulse length ...
1761 if (!irmp_input
) // still light?
1763 irmp_pulse_time
++; // increment counter
1767 wait_for_space
= 1; // let's count the time (see above)
1768 irmp_pause_time
= 1; // set pause counter to 1, not 0
1772 if (irmp_bit
== irmp_param
.complete_len
&& irmp_param
.stop_bit
== 0) // enough bits received?
1774 // if SIRCS/SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore it.
1775 if ((irmp_param
.protocol
== IRMP_SIRCS_PROTOCOL
||
1776 irmp_param
.protocol
== IRMP_SAMSUNG32_PROTOCOL
||
1777 irmp_param
.protocol
== IRMP_NUBERT_PROTOCOL
) &&
1778 last_irmp_command
== irmp_tmp_command
&& repetition_counter
< AUTO_REPETITION_LEN
)
1780 DEBUG_PRINTF ("code skipped, recognized SIRCS, SAMSUNG32 or NUBERT repetition, counter = %d, auto repetition len = %d\n",
1781 repetition_counter
, AUTO_REPETITION_LEN
);
1782 repetition_counter
= 0;
1786 DEBUG_PRINTF ("code detected, length = %d\n", irmp_bit
);
1787 irmp_ir_detected
= TRUE
;
1789 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1790 if (irmp_param
.protocol
== IRMP_DENON_PROTOCOL
)
1791 { // check for repetition frame
1792 if ((~irmp_tmp_command
& 0x3FF) == last_irmp_denon_command
) // command bits must be inverted
1794 irmp_tmp_command
= last_irmp_denon_command
; // use command received before!
1796 irmp_protocol
= irmp_param
.protocol
; // store protocol
1797 irmp_address
= irmp_tmp_address
; // store address
1798 irmp_command
= irmp_tmp_command
; // store command
1802 DEBUG_PRINTF ("waiting for inverted command repetition\n");
1803 irmp_ir_detected
= FALSE
;
1804 last_irmp_denon_command
= irmp_tmp_command
;
1808 #endif // IRMP_SUPPORT_DENON_PROTOCOL
1810 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1811 if (irmp_param
.protocol
== IRMP_NEC_PROTOCOL
&& irmp_bit
== 0) // repetition frame
1813 irmp_tmp_address
= last_irmp_address
; // address is last address
1814 irmp_tmp_command
= last_irmp_command
; // command is last command
1815 irmp_flags
|= IRMP_FLAG_REPETITION
;
1817 #endif // IRMP_SUPPORT_NEC_PROTOCOL
1818 irmp_protocol
= irmp_param
.protocol
;
1819 irmp_address
= irmp_tmp_address
; // store address
1820 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1821 last_irmp_address
= irmp_tmp_address
; // store as last address, too
1824 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1825 irmp_tmp_command
|= rc5_cmd_bit6
; // store bit 6
1827 irmp_command
= irmp_tmp_command
; // store command
1829 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1830 irmp_id
= irmp_tmp_id
;
1835 if (irmp_ir_detected
)
1837 if (last_irmp_command
== irmp_command
&&
1838 last_irmp_address
== irmp_address
&&
1839 repetition_counter
< IRMP_REPETITION_TIME
)
1841 irmp_flags
|= IRMP_FLAG_REPETITION
;
1844 last_irmp_address
= irmp_tmp_address
; // store as last address, too
1845 last_irmp_command
= irmp_tmp_command
; // store as last command, too
1847 repetition_counter
= 0;
1850 irmp_start_bit_detected
= 0; // and wait for next start bit
1851 irmp_tmp_command
= 0;
1852 irmp_pulse_time
= 0;
1853 irmp_pause_time
= 0;
1861 // main function - for unix/linux + windows only!
1863 // Compile it under linux with:
1864 // cc irmp.c -o irmp
1866 // usage: ./irmp [-v|-s|-a] < file
1869 print_timings (void)
1871 printf ("PROTOCOL START BIT NO. START BIT PULSE START BIT PAUSE\n");
1872 printf ("====================================================================================\n");
1873 printf ("SIRCS 1 %3d - %3d %3d - %3d\n",
1874 SIRCS_START_BIT_PULSE_LEN_MIN
, SIRCS_START_BIT_PULSE_LEN_MAX
, SIRCS_START_BIT_PAUSE_LEN_MIN
, SIRCS_START_BIT_PAUSE_LEN_MAX
);
1875 printf ("NEC 1 %3d - %3d %3d - %3d\n",
1876 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
, NEC_START_BIT_PAUSE_LEN_MIN
, NEC_START_BIT_PAUSE_LEN_MAX
);
1877 printf ("NEC (rep) 1 %3d - %3d %3d - %3d\n",
1878 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
);
1879 printf ("SAMSUNG 1 %3d - %3d %3d - %3d\n",
1880 SAMSUNG_START_BIT_PULSE_LEN_MIN
, SAMSUNG_START_BIT_PULSE_LEN_MAX
, SAMSUNG_START_BIT_PAUSE_LEN_MIN
, SAMSUNG_START_BIT_PAUSE_LEN_MAX
);
1881 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d\n",
1882 MATSUSHITA_START_BIT_PULSE_LEN_MIN
, MATSUSHITA_START_BIT_PULSE_LEN_MAX
, MATSUSHITA_START_BIT_PAUSE_LEN_MIN
, MATSUSHITA_START_BIT_PAUSE_LEN_MAX
);
1883 printf ("KASEIKYO 1 %3d - %3d %3d - %3d\n",
1884 KASEIKYO_START_BIT_PULSE_LEN_MIN
, KASEIKYO_START_BIT_PULSE_LEN_MAX
, KASEIKYO_START_BIT_PAUSE_LEN_MIN
, KASEIKYO_START_BIT_PAUSE_LEN_MAX
);
1885 printf ("RECS80 1 %3d - %3d %3d - %3d\n",
1886 RECS80_START_BIT_PULSE_LEN_MIN
, RECS80_START_BIT_PULSE_LEN_MAX
, RECS80_START_BIT_PAUSE_LEN_MIN
, RECS80_START_BIT_PAUSE_LEN_MAX
);
1887 printf ("RC5 1 %3d - %3d %3d - %3d\n",
1888 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
, RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
);
1889 printf ("DENON 1 %3d - %3d %3d - %3d or %3d - %3d\n",
1890 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
);
1891 printf ("RC6 1 %3d - %3d %3d - %3d\n",
1892 RC6_START_BIT_PULSE_LEN_MIN
, RC6_START_BIT_PULSE_LEN_MAX
, RC6_START_BIT_PAUSE_LEN_MIN
, RC6_START_BIT_PAUSE_LEN_MAX
);
1893 printf ("RECS80EXT 1 %3d - %3d %3d - %3d\n",
1894 RECS80EXT_START_BIT_PULSE_LEN_MIN
, RECS80EXT_START_BIT_PULSE_LEN_MAX
, RECS80EXT_START_BIT_PAUSE_LEN_MIN
, RECS80EXT_START_BIT_PAUSE_LEN_MAX
);
1895 printf ("NUBERT 1 %3d - %3d %3d - %3d\n",
1896 NUBERT_START_BIT_PULSE_LEN_MIN
, NUBERT_START_BIT_PULSE_LEN_MAX
, NUBERT_START_BIT_PAUSE_LEN_MIN
, NUBERT_START_BIT_PAUSE_LEN_MAX
);
1897 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
1898 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
);
1899 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
1900 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
);
1901 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
1902 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
);
1903 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
1904 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
);
1908 main (int argc
, char ** argv
)
1911 int verbose
= FALSE
;
1912 int analyze
= FALSE
;
1918 int min_pulse_long
= 100000;
1919 int max_pulse_long
= 0;
1920 int sum_pulses_long
= 0;
1921 int n_pulses_long
= 0;
1923 int min_pulse_short
= 100000;
1924 int max_pulse_short
= 0;
1925 int sum_pulses_short
= 0;
1926 int n_pulses_short
= 0;
1928 int min_pause_long
= 100000;
1929 int max_pause_long
= 0;
1930 int sum_pauses_long
= 0;
1931 int n_pauses_long
= 0;
1933 int min_pause_short
= 100000;
1934 int max_pause_short
= 0;
1935 int sum_pauses_short
= 0;
1936 int n_pauses_short
= 0;
1938 int min_start_pulse
= 100000;
1939 int max_start_pulse
= 0;
1940 int sum_start_pulses
= 0;
1941 int n_start_pulses
= 0;
1943 int min_start_pause
= 100000;
1944 int max_start_pause
= 0;
1945 int sum_start_pauses
= 0;
1946 int n_start_pauses
= 0;
1948 int first_pulse
= TRUE
;
1949 int first_pause
= TRUE
;
1951 IRMP_DATA irmp_data
;
1955 if (! strcmp (argv
[1], "-v"))
1959 else if (! strcmp (argv
[1], "-a"))
1964 else if (! strcmp (argv
[1], "-s"))
1968 else if (! strcmp (argv
[1], "-p"))
1977 while ((ch
= getchar ()) != EOF
)
1979 if (ch
== '_' || ch
== '0')
1983 if (verbose
&& pause
> 0)
1985 printf ("pause: %d\n", pause
);
1989 if (min_start_pause
> pause
)
1991 min_start_pause
= pause
;
1993 if (max_start_pause
< pause
)
1995 max_start_pause
= pause
;
1998 sum_start_pauses
+= pause
;
1999 first_pause
= FALSE
;
2005 if (pause
> 100) // perhaps repetition frame follows
2012 if (min_pause_long
> pause
)
2014 min_pause_long
= pause
;
2016 if (max_pause_long
< pause
)
2018 max_pause_long
= pause
;
2021 sum_pauses_long
+= pause
;
2026 if (min_pause_short
> pause
)
2028 min_pause_short
= pause
;
2030 if (max_pause_short
< pause
)
2032 max_pause_short
= pause
;
2035 sum_pauses_short
+= pause
;
2044 else if (ch
== 0xaf || ch
== '-' || ch
== '1')
2050 printf ("pulse: %d ", pulse
);
2054 if (min_start_pulse
> pulse
)
2056 min_start_pulse
= pulse
;
2058 if (max_start_pulse
< pulse
)
2060 max_start_pulse
= pulse
;
2063 sum_start_pulses
+= pulse
;
2064 first_pulse
= FALSE
;
2070 if (min_pulse_long
> pulse
)
2072 min_pulse_long
= pulse
;
2074 if (max_pulse_long
< pulse
)
2076 max_pulse_long
= pulse
;
2079 sum_pulses_long
+= pulse
;
2083 if (min_pulse_short
> pulse
)
2085 min_pulse_short
= pulse
;
2087 if (max_pulse_short
< pulse
)
2089 max_pulse_short
= pulse
;
2092 sum_pulses_short
+= pulse
;
2101 else if (ch
== '\n')
2105 if (verbose
&& pause
> 0)
2107 printf ("pause: %d\n", pause
);
2113 for (i
= 0; i
< 8000; i
++) // newline: long pause of 800 msec
2123 puts ("-------------------------------------------------------------------");
2126 while ((ch
= getchar()) != '\n' && ch
!= EOF
)
2128 if (ch
!= '\r') // ignore CR in DOS/Windows files
2143 if (irmp_get_data (&irmp_data
))
2145 printf ("protcol = %d, address = 0x%04x, code = 0x%04x, flags = 0x%02x\n",
2146 irmp_data
.protocol
, irmp_data
.address
, irmp_data
.command
, irmp_data
.flags
);
2152 printf ("\nSTATITSTICS:\n");
2153 printf ("---------------------------------\n");
2154 printf ("number of start pulses: %d\n", n_start_pulses
);
2155 printf ("minimum start pulse length: %d usec\n", (1000000 * min_start_pulse
) / F_INTERRUPTS
);
2156 printf ("maximum start pulse length: %d usec\n", (1000000 * max_start_pulse
) / F_INTERRUPTS
);
2157 if (n_start_pulses
> 0)
2159 printf ("average start pulse length: %d usec\n", ((1000000 * sum_start_pulses
) / n_start_pulses
) / F_INTERRUPTS
);
2162 printf ("number of start pauses: %d\n", n_start_pauses
);
2163 if (n_start_pauses
> 0)
2165 printf ("minimum start pause length: %d usec\n", (1000000 * min_start_pause
) / F_INTERRUPTS
);
2166 printf ("maximum start pause length: %d usec\n", (1000000 * max_start_pause
) / F_INTERRUPTS
);
2167 printf ("average start pause length: %d usec\n", ((1000000 * sum_start_pauses
) / n_start_pauses
) / F_INTERRUPTS
);
2170 printf ("number of long pulses: %d\n", n_pulses_long
);
2171 if (n_pulses_long
> 0)
2173 printf ("minimum long pulse length: %d usec\n", (1000000 * min_pulse_long
) / F_INTERRUPTS
);
2174 printf ("maximum long pulse length: %d usec\n", (1000000 * max_pulse_long
) / F_INTERRUPTS
);
2175 printf ("average long pulse length: %d usec\n", ((1000000 * sum_pulses_long
) / n_pulses_long
) / F_INTERRUPTS
);
2178 printf ("number of short pulses: %d\n", n_pulses_short
);
2179 if (n_pulses_short
> 0)
2181 printf ("minimum short pulse length: %d usec\n", (1000000 * min_pulse_short
) / F_INTERRUPTS
);
2182 printf ("maximum short pulse length: %d usec\n", (1000000 * max_pulse_short
) / F_INTERRUPTS
);
2183 printf ("average short pulse length: %d usec\n", ((1000000 * sum_pulses_short
) / n_pulses_short
) / F_INTERRUPTS
);
2187 printf ("number of long pauses: %d\n", n_pauses_long
);
2188 if (n_pauses_long
> 0)
2190 printf ("minimum long pause length: %d usec\n", (1000000 * min_pause_long
) / F_INTERRUPTS
);
2191 printf ("maximum long pause length: %d usec\n", (1000000 * max_pause_long
) / F_INTERRUPTS
);
2192 printf ("average long pause length: %d usec\n", ((1000000 * sum_pauses_long
) / n_pauses_long
) / F_INTERRUPTS
);
2195 printf ("number of short pauses: %d\n", n_pauses_short
);
2196 if (n_pauses_short
> 0)
2198 printf ("minimum short pause length: %d usec\n", (1000000 * min_pause_short
) / F_INTERRUPTS
);
2199 printf ("maximum short pause length: %d usec\n", (1000000 * max_pause_short
) / F_INTERRUPTS
);
2200 printf ("average short pause length: %d usec\n", ((1000000 * sum_pauses_short
) / n_pauses_short
) / F_INTERRUPTS
);