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.20 2010/04/19 13:42:17 fm Exp $
10 * Typical manufacturers:
13 * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers
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
21 * RC6 - Philips and other European manufacturers
23 * NUBERT - Nubert Subwoofer System
24 * B&O - Bang & Olufsen
25 * PANASONIC - Panasonic (older, yet not implemented)
27 *---------------------------------------------------------------------------------------------------------------------------------------------------
32 * frame: 1 start bit + 12-20 data bits + no stop bit
33 * data: 7 command bits + 5 address bits + 0 to 8 additional bits
35 * start bit: data "0": data "1": stop bit:
36 * -----------------_________ ------_____ ------------______
37 * 2400us 600us 600us 600us 1200us 600 us no stop bit
39 *---------------------------------------------------------------------------------------------------------------------------------------------------
42 * -------------------------
44 * frame: 1 start bit + 32 data bits + 1 stop bit
45 * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits
46 * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits
48 * start bit: data "0": data "1": stop bit:
49 * -----------------_________ ------______ ------________________ ------______....
50 * 9000us 4500us 560us 560us 560us 1690 us 560us
55 * -----------------_________------______ .... ~100ms Pause, then repeat
58 *---------------------------------------------------------------------------------------------------------------------------------------------------
63 * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit
64 * data(1): 16 address bits
65 * data(2): 4 ID bits + 8 command bits + 8 inverted command bits
67 * start bit: data "0": data "1": sync bit: stop bit:
68 * ----------______________ ------______ ------________________ ------______________ ------______....
69 * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us
71 *---------------------------------------------------------------------------------------------------------------------------------------------------
76 * frame: 1 start bit + 32 data bits + 1 stop bit
77 * data: 16 address bits + 16 command bits
79 * start bit: data "0": data "1": stop bit:
80 * ----------______________ ------______ ------________________ ------______....
81 * 4500us 4500us 550us 450us 550us 1450us 550us
83 *---------------------------------------------------------------------------------------------------------------------------------------------------
88 * frame: 1 start bit + 24 data bits + 1 stop bit
89 * data: 6 custom bits + 6 command bits + 12 address bits
91 * start bit: data "0": data "1": stop bit:
92 * ----------_________ ------______ ------________________ ------______....
93 * 3488us 3488us 872us 872us 872us 2616us 872us
95 *---------------------------------------------------------------------------------------------------------------------------------------------------
100 * frame: 1 start bit + 48 data bits + 1 stop bit
101 * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits
103 * start bit: data "0": data "1": stop bit:
104 * ----------______ ------______ ------________________ ------______....
105 * 3380us 1690us 423us 423us 423us 1269us 423us
107 *---------------------------------------------------------------------------------------------------------------------------------------------------
112 * frame: 2 start bits + 10 data bits + 1 stop bit
113 * data: 1 toggle bit + 3 address bits + 6 command bits
115 * start bit: data "0": data "1": stop bit:
116 * -----_____________________ -----____________ -----______________ ------_______....
117 * 158us 7432us 158us 4902us 158us 7432us 158us
119 *---------------------------------------------------------------------------------------------------------------------------------------------------
124 * frame: 2 start bits + 11 data bits + 1 stop bit
125 * data: 1 toggle bit + 4 address bits + 6 command bits
127 * start bit: data "0": data "1": stop bit:
128 * -----_____________________ -----____________ -----______________ ------_______....
129 * 158us 3637us 158us 4902us 158us 7432us 158us
131 *---------------------------------------------------------------------------------------------------------------------------------------------------
136 * RC5 frame: 2 start bits + 12 data bits + no stop bit
137 * RC5 data: 1 toggle bit + 5 address bits + 6 command bits
138 * RC5X frame: 1 start bit + 13 data bits + no stop bit
139 * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits
141 * start bit: data "0": data "1":
142 * ______----- ------______ ______------
143 * 889us 889us 889us 889us 889us 889us
145 *---------------------------------------------------------------------------------------------------------------------------------------------------
150 * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit
151 * data: 5 address bits + 10 command bits
153 * data "0": data "1":
154 * ------________________ ------______________
155 * 275us 1050us 275us 1900us
157 *---------------------------------------------------------------------------------------------------------------------------------------------------
162 * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 µs pause
163 * RC6 data: 8 address bits + 8 command bits
165 * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1":
166 * ____________------- _______------- -------_______ _______------- -------_______
167 * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us
169 *---------------------------------------------------------------------------------------------------------------------------------------------------
174 * frame: 1 start bit + 32 data bits + 1 stop bit
175 * data: 16 address bits + 11100000 + 8 command bits
177 * start bit: data "0": data "1": stop bit:
178 * -----------------_________ ------______ ------________________ ------______....
179 * 9000us 4500us 560us 560us 560us 1690 us 560us
181 *---------------------------------------------------------------------------------------------------------------------------------------------------
183 * NUBERT (subwoofer system)
184 * -------------------------
186 * frame: 1 start bit + 10 data bits + 1 stop bit
187 * data: 0 address bits + 10 command bits ?
189 * start bit: data "0": data "1": stop bit:
190 * ----------_____ ------______ ------________________ ------______....
191 * 1340us 340us 500us 1300us 1340us 340us 500us
193 *---------------------------------------------------------------------------------------------------------------------------------------------------
198 * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit
199 * data: 0 address bits + 16 command bits
201 * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit:
202 * -----________ -----________ -----_____________ -----________
203 * 210us 3000us 210us 3000us 210us 15000us 210us 3000us
205 * data "0": data "1": data "repeat bit": trailer bit: stop bit:
206 * -----________ -----_____________ -----___________ -----_____________ -----____...
207 * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us
209 *---------------------------------------------------------------------------------------------------------------------------------------------------
211 * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar)
212 * -----------------------------------------------------------------------------------------
214 * frame: 1 start bit + 22 data bits + 1 stop bit
215 * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits
217 * European version: T = 456us
218 * USA & Canada version: T = 422us
220 * start bit: data "0": data "1": stop bit:
221 * 8T 8T 2T 2T 2T 6T 2T
222 * -------------____________ ------_____ ------_____________ ------_______....
223 * 3648us 3648us 912us 912us 912us 2736us 912us (Europe)
224 * 3376us 3376us 844us 844us 844us 2532us 844us (US)
226 *---------------------------------------------------------------------------------------------------------------------------------------------------
228 * This program is free software; you can redistribute it and/or modify
229 * it under the terms of the GNU General Public License as published by
230 * the Free Software Foundation; either version 2 of the License, or
231 * (at your option) any later version.
232 *---------------------------------------------------------------------------------------------------------------------------------------------------
235 #if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR
236 #define PIC_CCS_COMPILER
239 #ifdef unix // test on linux/unix
244 #include <inttypes.h>
248 #define memcpy_P memcpy
255 typedef unsigned char uint8_t;
256 typedef unsigned short uint16_t;
259 #define memcpy_P memcpy
265 #ifdef PIC_CCS_COMPILER
268 typedef unsigned int8
uint8_t;
269 typedef unsigned int16
uint16_t;
271 #define memcpy_P memcpy
275 #include <inttypes.h>
279 #include <util/delay.h>
280 #include <avr/pgmspace.h>
282 #endif // PIC_CCS_COMPILER
289 #include "irmpconfig.h"
291 #define IRMP_TIMEOUT_TIME 16500.0e-6 // timeout after 16.5 ms darkness
292 #define IRMP_TIMEOUT_LEN (uint8_t)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5)
293 #define IRMP_REPETITION_TIME (uint16_t)(F_INTERRUPTS * 100.0e-3 + 0.5) // autodetect key repetition within 100 msec
295 #define MIN_TOLERANCE_00 1.0 // -0%
296 #define MAX_TOLERANCE_00 1.0 // +0%
298 #define MIN_TOLERANCE_05 0.95 // -5%
299 #define MAX_TOLERANCE_05 1.05 // +5%
301 #define MIN_TOLERANCE_10 0.9 // -10%
302 #define MAX_TOLERANCE_10 1.1 // +10%
304 #define MIN_TOLERANCE_15 0.85 // -15%
305 #define MAX_TOLERANCE_15 1.15 // +15%
307 #define MIN_TOLERANCE_20 0.8 // -20%
308 #define MAX_TOLERANCE_20 1.2 // +20%
310 #define MIN_TOLERANCE_30 0.7 // -30%
311 #define MAX_TOLERANCE_30 1.3 // +30%
313 #define MIN_TOLERANCE_40 0.6 // -40%
314 #define MAX_TOLERANCE_40 1.4 // +40%
316 #define MIN_TOLERANCE_50 0.5 // -50%
317 #define MAX_TOLERANCE_50 1.5 // +50%
319 #define MIN_TOLERANCE_60 0.4 // -60%
320 #define MAX_TOLERANCE_60 1.6 // +60%
322 #define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
323 #define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
324 #define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
325 #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
326 #define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
327 #define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
328 #define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
329 #define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
330 #define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
331 #define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
333 #define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
334 #define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
335 #define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
336 #define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
337 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
338 #define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
339 #define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
340 #define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
341 #define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
342 #define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
343 #define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
344 #define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
346 #define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
347 #define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
348 #define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
349 #define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
350 #define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
351 #define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
352 #define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
353 #define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
354 #define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
355 #define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
357 #define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
358 #define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
359 #define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
360 #define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
361 #define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
362 #define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
363 #define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
364 #define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
365 #define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1)
366 #define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1)
368 #define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
369 #define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
370 #define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
371 #define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
372 #define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
373 #define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_60 + 0.5) + 1)
374 #define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
375 #define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
376 #define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1)
377 #define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1)
379 #define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
380 #define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
381 #define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
382 #define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
383 #define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
384 #define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
385 #define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
386 #define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
387 #define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
388 #define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
390 #define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
391 #define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
392 #define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
393 #define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
395 #define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
396 #define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
397 #define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
398 #define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
399 #define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
400 #define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
402 #define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
403 #define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
404 #define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
405 #define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
406 #define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
407 #define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
408 #define RC6_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
409 #define RC6_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
411 #define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1)
412 #define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1)
413 #define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
414 #define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
415 #define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
416 #define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
417 #define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
418 #define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
419 #define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1)
420 #define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1)
422 #define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
423 #define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
424 #define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
425 #define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
426 #define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
427 #define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
428 #define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
429 #define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
430 #define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
431 #define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
432 #define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1)
433 #define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1)
435 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
436 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
437 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
438 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
439 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
440 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
441 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
442 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
443 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
444 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
445 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
446 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
447 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
448 #define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
449 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
450 #define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
451 #define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
452 #define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
453 #define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
454 #define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
455 #define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
456 #define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
457 #define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
458 #define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
459 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1)
460 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1)
462 #define AUTO_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_REPETITION_TIME + 0.5) // use uint16_t!
465 #define DEBUG_PUTCHAR(a) { if (! silent) { putchar (a); } }
466 #define DEBUG_PRINTF(...) { if (! silent) { printf (__VA_ARGS__); } }
469 #define DEBUG_PUTCHAR(a)
470 #define DEBUG_PRINTF(...)
473 #if IRMP_LOGGING == 1
474 #define irmp_logIsr(x) irmp_logIr((x) ? 1:0)
475 #define UART_BAUD 9600L
477 // calculate real baud rate:
478 #define UBRR_VAL ((F_CPU + UART_BAUD * 8) / (UART_BAUD * 16) - 1) // round
479 #define BAUD_REAL (F_CPU / (16 * (UBRR_VAL + 1))) // real baudrate
482 #if ((BAUD_REAL * 1000) / UART_BAUD - 1000) > 10
483 # error Error of baud rate of RS232 UARTx is more than 1%. That is too high!
486 #else // not CODEVISION
488 #define BAUD_ERROR ((BAUD_REAL * 1000) / UART_BAUD - 1000) // error in promille
490 #if ((BAUD_ERROR > 10) || (-BAUD_ERROR < 10))
491 # error Error of baud rate of RS232 UARTx is more than 1%. That is too high!
496 /*---------------------------------------------------------------------------------------------------------------------------------------------------
498 * @details Initializes UART
499 *---------------------------------------------------------------------------------------------------------------------------------------------------
502 irmp_uart_init (void)
504 UCSR0B
|= (1<<TXEN0
); // activate UART0 TX
505 UBRR0H
= UBRR_VAL
>> 8; // store baudrate (upper byte)
506 UBRR0L
= UBRR_VAL
& 0xFF; // store baudrate (lower byte)
509 /*---------------------------------------------------------------------------------------------------------------------------------------------------
511 * @details Sends character
512 * @param ch character to be transmitted
513 *---------------------------------------------------------------------------------------------------------------------------------------------------
516 irmp_uart_putc (unsigned char ch
)
518 while (!(UCSR0A
& (1<<UDRE0
)))
526 /*---------------------------------------------------------------------------------------------------------------------------------------------------
528 *---------------------------------------------------------------------------------------------------------------------------------------------------
530 #define c_startcycles 2 // min count of zeros before start of logging
531 #define c_endBits 1000 // log buffer size
532 #define c_datalen 700 // number of sequenced highbits to detect end
535 irmp_logIr (uint8_t val
)
537 static uint8_t s_data
[c_datalen
]; // logging buffer
538 static uint16_t s_dataIdx
; // number of written bits
539 static uint8_t s_startcycles
; // current number of start-zeros
540 static uint16_t s_ctr
; // counts sequenced highbits - to detect end
542 if ((val
== 0) && (s_startcycles
< c_startcycles
) && !s_dataIdx
) // prevent that single random zeros init logging
550 if ( (val
== 0) // start or continue logging on "0"
551 || ((val
== 1) && (s_dataIdx
!= 0))) // "1" cannot init logging
554 { // set or clear bit in bitarray
555 s_data
[(s_dataIdx
/ 8)] |= (1<<(s_dataIdx
% 8));
559 s_data
[(s_dataIdx
/ 8)] &= ~(1<<(s_dataIdx
% 8));
565 { // if high received then look at log-stop condition
568 if (s_ctr
> c_endBits
)
569 { // if stop condition (200 sequenced ones) meets, output on uart
572 for (i
= 0; i
< c_startcycles
; ++i
)
574 irmp_uart_putc ('0'); // the ignored starting zeros
577 for (i
= 0;i
< (s_dataIdx
- c_endBits
+ 20) / 8; ++i
) // transform bitset into uart chars
579 uint8_t d
= s_data
[i
];
584 irmp_uart_putc ((d
& 1) + '0');
589 irmp_uart_putc ('\n');
602 #define irmp_logIsr(x)
607 uint8_t protocol
; // ir protocol
608 uint8_t pulse_1_len_min
; // minimum length of pulse with bit value 1
609 uint8_t pulse_1_len_max
; // maximum length of pulse with bit value 1
610 uint8_t pause_1_len_min
; // minimum length of pause with bit value 1
611 uint8_t pause_1_len_max
; // maximum length of pause with bit value 1
612 uint8_t pulse_0_len_min
; // minimum length of pulse with bit value 0
613 uint8_t pulse_0_len_max
; // maximum length of pulse with bit value 0
614 uint8_t pause_0_len_min
; // minimum length of pause with bit value 0
615 uint8_t pause_0_len_max
; // maximum length of pause with bit value 0
616 uint8_t address_offset
; // address offset
617 uint8_t address_end
; // end of address
618 uint8_t command_offset
; // command offset
619 uint8_t command_end
; // end of command
620 uint8_t complete_len
; // complete length of frame
621 uint8_t stop_bit
; // flag: frame has stop bit
622 uint8_t lsb_first
; // flag: LSB first
625 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
627 static PROGMEM IRMP_PARAMETER sircs_param
=
630 SIRCS_1_PULSE_LEN_MIN
,
631 SIRCS_1_PULSE_LEN_MAX
,
634 SIRCS_0_PULSE_LEN_MIN
,
635 SIRCS_0_PULSE_LEN_MAX
,
638 SIRCS_ADDRESS_OFFSET
,
639 SIRCS_ADDRESS_OFFSET
+ SIRCS_ADDRESS_LEN
,
640 SIRCS_COMMAND_OFFSET
,
641 SIRCS_COMMAND_OFFSET
+ SIRCS_COMMAND_LEN
,
642 SIRCS_COMPLETE_DATA_LEN
,
649 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
651 static PROGMEM IRMP_PARAMETER nec_param
=
663 NEC_ADDRESS_OFFSET
+ NEC_ADDRESS_LEN
,
665 NEC_COMMAND_OFFSET
+ NEC_COMMAND_LEN
,
666 NEC_COMPLETE_DATA_LEN
,
671 static PROGMEM IRMP_PARAMETER nec_rep_param
=
693 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
695 static PROGMEM IRMP_PARAMETER samsung_param
=
697 IRMP_SAMSUNG_PROTOCOL
,
698 SAMSUNG_PULSE_LEN_MIN
,
699 SAMSUNG_PULSE_LEN_MAX
,
700 SAMSUNG_1_PAUSE_LEN_MIN
,
701 SAMSUNG_1_PAUSE_LEN_MAX
,
702 SAMSUNG_PULSE_LEN_MIN
,
703 SAMSUNG_PULSE_LEN_MAX
,
704 SAMSUNG_0_PAUSE_LEN_MIN
,
705 SAMSUNG_0_PAUSE_LEN_MAX
,
706 SAMSUNG_ADDRESS_OFFSET
,
707 SAMSUNG_ADDRESS_OFFSET
+ SAMSUNG_ADDRESS_LEN
,
708 SAMSUNG_COMMAND_OFFSET
,
709 SAMSUNG_COMMAND_OFFSET
+ SAMSUNG_COMMAND_LEN
,
710 SAMSUNG_COMPLETE_DATA_LEN
,
717 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
719 static PROGMEM IRMP_PARAMETER matsushita_param
=
721 IRMP_MATSUSHITA_PROTOCOL
,
722 MATSUSHITA_PULSE_LEN_MIN
,
723 MATSUSHITA_PULSE_LEN_MAX
,
724 MATSUSHITA_1_PAUSE_LEN_MIN
,
725 MATSUSHITA_1_PAUSE_LEN_MAX
,
726 MATSUSHITA_PULSE_LEN_MIN
,
727 MATSUSHITA_PULSE_LEN_MAX
,
728 MATSUSHITA_0_PAUSE_LEN_MIN
,
729 MATSUSHITA_0_PAUSE_LEN_MAX
,
730 MATSUSHITA_ADDRESS_OFFSET
,
731 MATSUSHITA_ADDRESS_OFFSET
+ MATSUSHITA_ADDRESS_LEN
,
732 MATSUSHITA_COMMAND_OFFSET
,
733 MATSUSHITA_COMMAND_OFFSET
+ MATSUSHITA_COMMAND_LEN
,
734 MATSUSHITA_COMPLETE_DATA_LEN
,
741 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
743 static PROGMEM IRMP_PARAMETER kaseikyo_param
=
745 IRMP_KASEIKYO_PROTOCOL
,
746 KASEIKYO_PULSE_LEN_MIN
,
747 KASEIKYO_PULSE_LEN_MAX
,
748 KASEIKYO_1_PAUSE_LEN_MIN
,
749 KASEIKYO_1_PAUSE_LEN_MAX
,
750 KASEIKYO_PULSE_LEN_MIN
,
751 KASEIKYO_PULSE_LEN_MAX
,
752 KASEIKYO_0_PAUSE_LEN_MIN
,
753 KASEIKYO_0_PAUSE_LEN_MAX
,
754 KASEIKYO_ADDRESS_OFFSET
,
755 KASEIKYO_ADDRESS_OFFSET
+ KASEIKYO_ADDRESS_LEN
,
756 KASEIKYO_COMMAND_OFFSET
,
757 KASEIKYO_COMMAND_OFFSET
+ KASEIKYO_COMMAND_LEN
,
758 KASEIKYO_COMPLETE_DATA_LEN
,
765 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
767 static PROGMEM IRMP_PARAMETER recs80_param
=
769 IRMP_RECS80_PROTOCOL
,
770 RECS80_PULSE_LEN_MIN
,
771 RECS80_PULSE_LEN_MAX
,
772 RECS80_1_PAUSE_LEN_MIN
,
773 RECS80_1_PAUSE_LEN_MAX
,
774 RECS80_PULSE_LEN_MIN
,
775 RECS80_PULSE_LEN_MAX
,
776 RECS80_0_PAUSE_LEN_MIN
,
777 RECS80_0_PAUSE_LEN_MAX
,
778 RECS80_ADDRESS_OFFSET
,
779 RECS80_ADDRESS_OFFSET
+ RECS80_ADDRESS_LEN
,
780 RECS80_COMMAND_OFFSET
,
781 RECS80_COMMAND_OFFSET
+ RECS80_COMMAND_LEN
,
782 RECS80_COMPLETE_DATA_LEN
,
789 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
791 static PROGMEM IRMP_PARAMETER rc5_param
=
798 1, // tricky: use this as stop bit length
803 RC5_ADDRESS_OFFSET
+ RC5_ADDRESS_LEN
,
805 RC5_COMMAND_OFFSET
+ RC5_COMMAND_LEN
,
806 RC5_COMPLETE_DATA_LEN
,
813 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
815 static PROGMEM IRMP_PARAMETER denon_param
=
820 DENON_1_PAUSE_LEN_MIN
,
821 DENON_1_PAUSE_LEN_MAX
,
824 DENON_0_PAUSE_LEN_MIN
,
825 DENON_0_PAUSE_LEN_MAX
,
826 DENON_ADDRESS_OFFSET
,
827 DENON_ADDRESS_OFFSET
+ DENON_ADDRESS_LEN
,
828 DENON_COMMAND_OFFSET
,
829 DENON_COMMAND_OFFSET
+ DENON_COMMAND_LEN
,
830 DENON_COMPLETE_DATA_LEN
,
837 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
839 static PROGMEM IRMP_PARAMETER rc6_param
=
846 1, // tricky: use this as stop bit length
851 RC6_ADDRESS_OFFSET
+ RC6_ADDRESS_LEN
,
853 RC6_COMMAND_OFFSET
+ RC6_COMMAND_LEN
,
854 RC6_COMPLETE_DATA_LEN_SHORT
,
861 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
863 static PROGMEM IRMP_PARAMETER recs80ext_param
=
865 IRMP_RECS80EXT_PROTOCOL
,
866 RECS80EXT_PULSE_LEN_MIN
,
867 RECS80EXT_PULSE_LEN_MAX
,
868 RECS80EXT_1_PAUSE_LEN_MIN
,
869 RECS80EXT_1_PAUSE_LEN_MAX
,
870 RECS80EXT_PULSE_LEN_MIN
,
871 RECS80EXT_PULSE_LEN_MAX
,
872 RECS80EXT_0_PAUSE_LEN_MIN
,
873 RECS80EXT_0_PAUSE_LEN_MAX
,
874 RECS80EXT_ADDRESS_OFFSET
,
875 RECS80EXT_ADDRESS_OFFSET
+ RECS80EXT_ADDRESS_LEN
,
876 RECS80EXT_COMMAND_OFFSET
,
877 RECS80EXT_COMMAND_OFFSET
+ RECS80EXT_COMMAND_LEN
,
878 RECS80EXT_COMPLETE_DATA_LEN
,
885 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
887 static PROGMEM IRMP_PARAMETER nubert_param
=
889 IRMP_NUBERT_PROTOCOL
,
890 NUBERT_1_PULSE_LEN_MIN
,
891 NUBERT_1_PULSE_LEN_MAX
,
892 NUBERT_1_PAUSE_LEN_MIN
,
893 NUBERT_1_PAUSE_LEN_MAX
,
894 NUBERT_0_PULSE_LEN_MIN
,
895 NUBERT_0_PULSE_LEN_MAX
,
896 NUBERT_0_PAUSE_LEN_MIN
,
897 NUBERT_0_PAUSE_LEN_MAX
,
898 NUBERT_ADDRESS_OFFSET
,
899 NUBERT_ADDRESS_OFFSET
+ NUBERT_ADDRESS_LEN
,
900 NUBERT_COMMAND_OFFSET
,
901 NUBERT_COMMAND_OFFSET
+ NUBERT_COMMAND_LEN
,
902 NUBERT_COMPLETE_DATA_LEN
,
909 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
911 static PROGMEM IRMP_PARAMETER bang_olufsen_param
=
913 IRMP_BANG_OLUFSEN_PROTOCOL
,
914 BANG_OLUFSEN_PULSE_LEN_MIN
,
915 BANG_OLUFSEN_PULSE_LEN_MAX
,
916 BANG_OLUFSEN_1_PAUSE_LEN_MIN
,
917 BANG_OLUFSEN_1_PAUSE_LEN_MAX
,
918 BANG_OLUFSEN_PULSE_LEN_MIN
,
919 BANG_OLUFSEN_PULSE_LEN_MAX
,
920 BANG_OLUFSEN_0_PAUSE_LEN_MIN
,
921 BANG_OLUFSEN_0_PAUSE_LEN_MAX
,
922 BANG_OLUFSEN_ADDRESS_OFFSET
,
923 BANG_OLUFSEN_ADDRESS_OFFSET
+ BANG_OLUFSEN_ADDRESS_LEN
,
924 BANG_OLUFSEN_COMMAND_OFFSET
,
925 BANG_OLUFSEN_COMMAND_OFFSET
+ BANG_OLUFSEN_COMMAND_LEN
,
926 BANG_OLUFSEN_COMPLETE_DATA_LEN
,
927 BANG_OLUFSEN_STOP_BIT
,
933 static uint8_t irmp_bit
; // current bit position
934 static IRMP_PARAMETER irmp_param
;
936 static volatile uint8_t irmp_ir_detected
;
937 static volatile uint8_t irmp_protocol
;
938 static volatile uint16_t irmp_address
;
939 static volatile uint16_t irmp_command
;
940 static volatile uint16_t irmp_id
; // only used for SAMSUNG protocol
941 static volatile uint8_t irmp_flags
;
944 static uint8_t IRMP_PIN
;
947 /*---------------------------------------------------------------------------------------------------------------------------------------------------
948 * Initialize IRMP decoder
949 * @details Configures IRMP input pin
950 *---------------------------------------------------------------------------------------------------------------------------------------------------
956 #ifndef PIC_CCS_COMPILER
957 IRMP_PORT
&= ~(1<<IRMP_BIT
); // deactivate pullup
958 IRMP_DDR
&= ~(1<<IRMP_BIT
); // set pin to input
959 #endif // PIC_CCS_COMPILER
961 #if IRMP_LOGGING == 1
966 /*---------------------------------------------------------------------------------------------------------------------------------------------------
968 * @details gets decoded IRMP data
969 * @param pointer in order to store IRMP data
970 * @return TRUE: successful, FALSE: failed
971 *---------------------------------------------------------------------------------------------------------------------------------------------------
974 irmp_get_data (IRMP_DATA
* irmp_data_p
)
978 if (irmp_ir_detected
)
980 switch (irmp_protocol
)
982 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
983 case IRMP_SAMSUNG_PROTOCOL
:
984 if ((irmp_command
>> 8) == (~irmp_command
& 0x00FF))
986 irmp_command
&= 0xff;
987 irmp_command
|= irmp_id
<< 8;
992 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
993 case IRMP_NEC_PROTOCOL
:
994 if ((irmp_command
>> 8) == (~irmp_command
& 0x00FF))
996 irmp_command
&= 0xff;
999 else if ((irmp_command
& 0xFF00) == 0xD100)
1001 DEBUG_PRINTF ("Switching to APPLE protocol\n");
1002 irmp_protocol
= IRMP_APPLE_PROTOCOL
;
1003 irmp_command
&= 0xff;
1014 irmp_data_p
->protocol
= irmp_protocol
;
1015 irmp_data_p
->address
= irmp_address
;
1016 irmp_data_p
->command
= irmp_command
;
1017 irmp_data_p
->flags
= irmp_flags
;
1023 irmp_ir_detected
= FALSE
;
1029 // these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR()
1030 static uint16_t irmp_tmp_address
; // ir address
1031 static uint16_t irmp_tmp_command
; // ir command
1032 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1033 static uint16_t irmp_tmp_id
; // ir id (only SAMSUNG)
1036 static uint8_t irmp_bit
; // current bit position
1038 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1040 * @details store bit in temp address or temp command
1041 * @param value to store: 0 or 1
1042 *---------------------------------------------------------------------------------------------------------------------------------------------------
1045 irmp_store_bit (uint8_t value
)
1047 if (irmp_bit
>= irmp_param
.address_offset
&& irmp_bit
< irmp_param
.address_end
)
1049 if (irmp_param
.lsb_first
)
1051 irmp_tmp_address
|= (((uint16_t) (value
)) << (irmp_bit
- irmp_param
.address_offset
)); // CV wants cast
1055 irmp_tmp_address
<<= 1;
1056 irmp_tmp_address
|= value
;
1059 else if (irmp_bit
>= irmp_param
.command_offset
&& irmp_bit
< irmp_param
.command_end
)
1061 if (irmp_param
.lsb_first
)
1063 irmp_tmp_command
|= (((uint16_t) (value
)) << (irmp_bit
- irmp_param
.command_offset
)); // CV wants cast
1067 irmp_tmp_command
<<= 1;
1068 irmp_tmp_command
|= value
;
1071 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1072 else if (irmp_param
.protocol
== IRMP_SAMSUNG_PROTOCOL
&& irmp_bit
>= SAMSUNG_ID_OFFSET
&& irmp_bit
< SAMSUNG_ID_OFFSET
+ SAMSUNG_ID_LEN
)
1074 irmp_tmp_id
|= (((uint16_t) (value
)) << (irmp_bit
- SAMSUNG_ID_OFFSET
)); // store with LSB first
1080 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1082 * @details ISR routine, called 10000 times per second
1083 *---------------------------------------------------------------------------------------------------------------------------------------------------
1088 static uint8_t irmp_start_bit_detected
; // flag: start bit detected
1089 static uint8_t wait_for_space
; // flag: wait for data bit space
1090 static uint8_t wait_for_start_space
; // flag: wait for start bit space
1091 static uint8_t irmp_pulse_time
; // count bit time for pulse
1092 static uint8_t irmp_pause_time
; // count bit time for pause
1093 static uint16_t last_irmp_address
= 0xFFFF; // save last irmp address to recognize key repetition
1094 static uint16_t last_irmp_command
= 0xFFFF; // save last irmp command to recognize key repetition
1095 static uint16_t repetition_counter
; // SIRCS repeats frame 2-5 times with 45 ms pause
1096 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1097 static uint16_t last_irmp_denon_command
; // save last irmp command to recognize DENON frame repetition
1099 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1100 static uint8_t rc5_cmd_bit6
; // bit 6 of RC5 command is the inverted 2nd start bit
1102 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1
1103 static uint8_t last_pause
; // last pause value
1105 #if IRMP_SUPPORT_RC5_PROTOCOL == 1 || IRMP_SUPPORT_RC6_PROTOCOL == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1106 static uint8_t last_value
; // last bit value
1108 uint8_t irmp_input
; // input value
1110 irmp_input
= input(IRMP_PIN
);
1112 irmp_logIsr(irmp_input
); // log ir signal, if IRMP_LOGGING defined
1114 if (! irmp_ir_detected
) // ir code already detected?
1116 if (! irmp_start_bit_detected
) // start bit detected?
1118 if (!irmp_input
) // receiving burst?
1120 irmp_pulse_time
++; // increment counter
1124 if (irmp_pulse_time
) // it's dark....
1125 { // set flags for counting the time of darkness...
1126 irmp_start_bit_detected
= 1;
1127 wait_for_start_space
= 1;
1129 irmp_tmp_command
= 0;
1130 irmp_tmp_address
= 0;
1132 irmp_pause_time
= 1; // 1st pause: set to 1, not to 0!
1133 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1134 rc5_cmd_bit6
= 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame!
1139 repetition_counter
++;
1145 if (wait_for_start_space
) // we have received start bit...
1146 { // ...and are counting the time of darkness
1147 if (irmp_input
) // still dark?
1149 irmp_pause_time
++; // increment counter
1151 if (irmp_pause_time
> IRMP_TIMEOUT_LEN
) // timeout?
1153 DEBUG_PRINTF ("error 1: pause after start bit %d too long: %d\n", irmp_pulse_time
, irmp_pause_time
);
1154 irmp_start_bit_detected
= 0; // reset flags, let's wait for another start bit
1155 irmp_pulse_time
= 0;
1156 irmp_pause_time
= 0;
1160 { // receiving first data pulse!
1161 IRMP_PARAMETER
* irmp_param_p
= (IRMP_PARAMETER
*) 0;
1163 DEBUG_PRINTF ("start-bit: pulse = %d, pause = %d\n", irmp_pulse_time
, irmp_pause_time
);
1165 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1166 if (irmp_pulse_time
>= SIRCS_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= SIRCS_START_BIT_PULSE_LEN_MAX
&&
1167 irmp_pause_time
>= SIRCS_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SIRCS_START_BIT_PAUSE_LEN_MAX
)
1169 DEBUG_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1170 SIRCS_START_BIT_PULSE_LEN_MIN
, SIRCS_START_BIT_PULSE_LEN_MAX
,
1171 SIRCS_START_BIT_PAUSE_LEN_MIN
, SIRCS_START_BIT_PAUSE_LEN_MAX
);
1172 irmp_param_p
= (IRMP_PARAMETER
*) (IRMP_PARAMETER
*) &sircs_param
;
1175 #endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1177 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1178 if (irmp_pulse_time
>= NEC_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= NEC_START_BIT_PULSE_LEN_MAX
&&
1179 irmp_pause_time
>= NEC_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NEC_START_BIT_PAUSE_LEN_MAX
)
1181 DEBUG_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1182 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
,
1183 NEC_START_BIT_PAUSE_LEN_MIN
, NEC_START_BIT_PAUSE_LEN_MAX
);
1184 irmp_param_p
= (IRMP_PARAMETER
*) &nec_param
;
1186 else if (irmp_pulse_time
>= NEC_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= NEC_START_BIT_PULSE_LEN_MAX
&&
1187 irmp_pause_time
>= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
)
1189 DEBUG_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1190 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
,
1191 NEC_REPEAT_START_BIT_PAUSE_LEN_MIN
, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX
);
1193 irmp_param_p
= (IRMP_PARAMETER
*) &nec_rep_param
;
1196 #endif // IRMP_SUPPORT_NEC_PROTOCOL == 1
1198 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1199 if (irmp_pulse_time
>= SAMSUNG_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_START_BIT_PULSE_LEN_MAX
&&
1200 irmp_pause_time
>= SAMSUNG_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_START_BIT_PAUSE_LEN_MAX
)
1202 DEBUG_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1203 SAMSUNG_START_BIT_PULSE_LEN_MIN
, SAMSUNG_START_BIT_PULSE_LEN_MAX
,
1204 SAMSUNG_START_BIT_PAUSE_LEN_MIN
, SAMSUNG_START_BIT_PAUSE_LEN_MAX
);
1205 irmp_param_p
= (IRMP_PARAMETER
*) &samsung_param
;
1208 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1210 #if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1211 if (irmp_pulse_time
>= MATSUSHITA_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= MATSUSHITA_START_BIT_PULSE_LEN_MAX
&&
1212 irmp_pause_time
>= MATSUSHITA_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= MATSUSHITA_START_BIT_PAUSE_LEN_MAX
)
1213 { // it's MATSUSHITA
1214 DEBUG_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1215 MATSUSHITA_START_BIT_PULSE_LEN_MIN
, MATSUSHITA_START_BIT_PULSE_LEN_MAX
,
1216 MATSUSHITA_START_BIT_PAUSE_LEN_MIN
, MATSUSHITA_START_BIT_PAUSE_LEN_MAX
);
1217 irmp_param_p
= (IRMP_PARAMETER
*) &matsushita_param
;
1220 #endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1
1222 #if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1223 if (irmp_pulse_time
>= KASEIKYO_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= KASEIKYO_START_BIT_PULSE_LEN_MAX
&&
1224 irmp_pause_time
>= KASEIKYO_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= KASEIKYO_START_BIT_PAUSE_LEN_MAX
)
1226 DEBUG_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1227 KASEIKYO_START_BIT_PULSE_LEN_MIN
, KASEIKYO_START_BIT_PULSE_LEN_MAX
,
1228 KASEIKYO_START_BIT_PAUSE_LEN_MIN
, KASEIKYO_START_BIT_PAUSE_LEN_MAX
);
1229 irmp_param_p
= (IRMP_PARAMETER
*) &kaseikyo_param
;
1232 #endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1
1234 #if IRMP_SUPPORT_RECS80_PROTOCOL == 1
1235 if (irmp_pulse_time
>= RECS80_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RECS80_START_BIT_PULSE_LEN_MAX
&&
1236 irmp_pause_time
>= RECS80_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RECS80_START_BIT_PAUSE_LEN_MAX
)
1238 DEBUG_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1239 RECS80_START_BIT_PULSE_LEN_MIN
, RECS80_START_BIT_PULSE_LEN_MAX
,
1240 RECS80_START_BIT_PAUSE_LEN_MIN
, RECS80_START_BIT_PAUSE_LEN_MAX
);
1241 irmp_param_p
= (IRMP_PARAMETER
*) &recs80_param
;
1244 #endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1
1246 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1247 if (((irmp_pulse_time
>= RC5_START_BIT_LEN_MIN
&& irmp_pulse_time
<= RC5_START_BIT_LEN_MAX
) ||
1248 (irmp_pulse_time
>= 2 * RC5_START_BIT_LEN_MIN
&& irmp_pulse_time
<= 2 * RC5_START_BIT_LEN_MAX
)) &&
1249 ((irmp_pause_time
>= RC5_START_BIT_LEN_MIN
&& irmp_pause_time
<= RC5_START_BIT_LEN_MAX
) ||
1250 (irmp_pause_time
>= 2 * RC5_START_BIT_LEN_MIN
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
)))
1252 DEBUG_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1253 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
,
1254 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
);
1255 irmp_param_p
= (IRMP_PARAMETER
*) &rc5_param
;
1256 last_pause
= irmp_pause_time
;
1258 if ((irmp_pulse_time
> RC5_START_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC5_START_BIT_LEN_MAX
) ||
1259 (irmp_pause_time
> RC5_START_BIT_LEN_MAX
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
))
1262 rc5_cmd_bit6
= 1<<6;
1270 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1272 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1273 if ( (irmp_pulse_time
>= DENON_PULSE_LEN_MIN
&& irmp_pulse_time
<= DENON_PULSE_LEN_MAX
) &&
1274 ((irmp_pause_time
>= DENON_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_1_PAUSE_LEN_MAX
) ||
1275 (irmp_pause_time
>= DENON_0_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_0_PAUSE_LEN_MAX
)))
1277 DEBUG_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n",
1278 DENON_PULSE_LEN_MIN
, DENON_PULSE_LEN_MAX
,
1279 DENON_1_PAUSE_LEN_MIN
, DENON_1_PAUSE_LEN_MAX
,
1280 DENON_0_PAUSE_LEN_MIN
, DENON_0_PAUSE_LEN_MAX
);
1281 irmp_param_p
= (IRMP_PARAMETER
*) &denon_param
;
1284 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1286 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1287 if (irmp_pulse_time
>= RC6_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RC6_START_BIT_PULSE_LEN_MAX
&&
1288 irmp_pause_time
>= RC6_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RC6_START_BIT_PAUSE_LEN_MAX
)
1290 DEBUG_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1291 RC6_START_BIT_PULSE_LEN_MIN
, RC6_START_BIT_PULSE_LEN_MAX
,
1292 RC6_START_BIT_PAUSE_LEN_MIN
, RC6_START_BIT_PAUSE_LEN_MAX
);
1293 irmp_param_p
= (IRMP_PARAMETER
*) &rc6_param
;
1298 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1300 #if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1301 if (irmp_pulse_time
>= RECS80EXT_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= RECS80EXT_START_BIT_PULSE_LEN_MAX
&&
1302 irmp_pause_time
>= RECS80EXT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= RECS80EXT_START_BIT_PAUSE_LEN_MAX
)
1304 DEBUG_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1305 RECS80EXT_START_BIT_PULSE_LEN_MIN
, RECS80EXT_START_BIT_PULSE_LEN_MAX
,
1306 RECS80EXT_START_BIT_PAUSE_LEN_MIN
, RECS80EXT_START_BIT_PAUSE_LEN_MAX
);
1307 irmp_param_p
= (IRMP_PARAMETER
*) &recs80ext_param
;
1310 #endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1
1312 #if IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1313 if (irmp_pulse_time
>= NUBERT_START_BIT_PULSE_LEN_MIN
&& irmp_pulse_time
<= NUBERT_START_BIT_PULSE_LEN_MAX
&&
1314 irmp_pause_time
>= NUBERT_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= NUBERT_START_BIT_PAUSE_LEN_MAX
)
1316 DEBUG_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1317 NUBERT_START_BIT_PULSE_LEN_MIN
, NUBERT_START_BIT_PULSE_LEN_MAX
,
1318 NUBERT_START_BIT_PAUSE_LEN_MIN
, NUBERT_START_BIT_PAUSE_LEN_MAX
);
1319 irmp_param_p
= (IRMP_PARAMETER
*) &nubert_param
;
1322 #endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1
1324 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1325 if (irmp_pulse_time
>= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN
&& irmp_pulse_time
<= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX
&&
1326 irmp_pause_time
>= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX
)
1327 { // it's BANG_OLUFSEN
1328 DEBUG_PRINTF ("protocol = BANG_OLUFSEN\n");
1329 DEBUG_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1330 BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX
,
1331 BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX
);
1332 DEBUG_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1333 BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX
,
1334 BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX
);
1335 DEBUG_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1336 BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX
,
1337 BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX
);
1338 DEBUG_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n",
1339 BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN
, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX
,
1340 BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN
, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX
);
1341 irmp_param_p
= (IRMP_PARAMETER
*) &bang_olufsen_param
;
1345 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1348 DEBUG_PRINTF ("protocol = UNKNOWN\n");
1349 irmp_start_bit_detected
= 0; // wait for another start bit...
1352 if (irmp_start_bit_detected
)
1354 memcpy_P (&irmp_param
, irmp_param_p
, sizeof (IRMP_PARAMETER
));
1356 DEBUG_PRINTF ("pulse_1: %3d - %3d\n", irmp_param
.pulse_1_len_min
, irmp_param
.pulse_1_len_max
);
1357 DEBUG_PRINTF ("pause_1: %3d - %3d\n", irmp_param
.pause_1_len_min
, irmp_param
.pause_1_len_max
);
1359 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1360 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
)
1362 DEBUG_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN
, RC6_TOGGLE_BIT_LEN_MAX
);
1365 DEBUG_PRINTF ("pulse_0: %3d - %3d\n", irmp_param
.pulse_0_len_min
, irmp_param
.pulse_0_len_max
);
1366 DEBUG_PRINTF ("pause_0: %3d - %3d\n", irmp_param
.pause_0_len_min
, irmp_param
.pause_0_len_max
);
1368 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1369 if (irmp_param
.protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1371 DEBUG_PRINTF ("pulse_r: %3d - %3d\n", irmp_param
.pulse_0_len_min
, irmp_param
.pulse_0_len_max
);
1372 DEBUG_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN
, BANG_OLUFSEN_R_PAUSE_LEN_MAX
);
1376 DEBUG_PRINTF ("command_offset: %2d\n", irmp_param
.command_offset
);
1377 DEBUG_PRINTF ("command_len: %3d\n", irmp_param
.command_end
- irmp_param
.command_offset
);
1378 DEBUG_PRINTF ("complete_len: %3d\n", irmp_param
.complete_len
);
1379 DEBUG_PRINTF ("stop_bit: %3d\n", irmp_param
.stop_bit
);
1384 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1385 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
)
1387 if (irmp_pause_time
> RC5_START_BIT_LEN_MAX
&& irmp_pause_time
<= 2 * RC5_START_BIT_LEN_MAX
)
1389 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1390 DEBUG_PUTCHAR ('1');
1391 DEBUG_PUTCHAR ('\n');
1394 else if (! last_value
)
1396 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1397 DEBUG_PUTCHAR ('0');
1398 DEBUG_PUTCHAR ('\n');
1403 #endif // IRMP_SUPPORT_RC5_PROTOCOL == 1
1405 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1406 if (irmp_param
.protocol
== IRMP_DENON_PROTOCOL
)
1408 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1410 if (irmp_pause_time
>= DENON_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= DENON_1_PAUSE_LEN_MAX
)
1411 { // pause timings correct for "1"?
1412 DEBUG_PUTCHAR ('1'); // yes, store 1
1413 DEBUG_PUTCHAR ('\n');
1416 else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX)
1417 { // pause timings correct for "0"?
1418 DEBUG_PUTCHAR ('0'); // yes, store 0
1419 DEBUG_PUTCHAR ('\n');
1423 #endif // IRMP_SUPPORT_DENON_PROTOCOL == 1
1425 irmp_pulse_time
= 1; // set counter to 1, not 0
1426 irmp_pause_time
= 0;
1427 wait_for_start_space
= 0;
1430 else if (wait_for_space
) // the data section....
1431 { // counting the time of darkness....
1432 uint8_t got_light
= FALSE
;
1434 if (irmp_input
) // still dark?
1436 if (irmp_bit
== irmp_param
.complete_len
&& irmp_param
.stop_bit
== 1)
1438 if (irmp_pulse_time
>= irmp_param
.pulse_0_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_0_len_max
)
1441 if (irmp_param
.protocol
!= IRMP_RC5_PROTOCOL
)
1443 DEBUG_PRINTF ("stop bit detected\n");
1446 irmp_param
.stop_bit
= 0;
1450 DEBUG_PRINTF ("stop bit timing wrong\n");
1452 irmp_start_bit_detected
= 0; // wait for another start bit...
1453 irmp_pulse_time
= 0;
1454 irmp_pause_time
= 0;
1459 irmp_pause_time
++; // increment counter
1461 #if IRMP_SUPPORT_SIRCS_PROTOCOL == 1
1462 if (irmp_param
.protocol
== IRMP_SIRCS_PROTOCOL
&& // Sony has a variable number of bits:
1463 irmp_pause_time
> SIRCS_PAUSE_LEN_MAX
&& // minimum is 12
1464 irmp_bit
>= 12 - 1) // pause too long?
1465 { // yes, break and close this frame
1466 irmp_param
.complete_len
= irmp_bit
+ 1; // set new complete length
1467 got_light
= TRUE
; // this is a lie, but helps (generates stop bit)
1468 irmp_param
.command_end
= irmp_param
.command_offset
+ irmp_bit
+ 1; // correct command length
1469 irmp_pause_time
= SIRCS_PAUSE_LEN_MAX
- 1; // correct pause length
1473 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1474 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
&&
1475 irmp_pause_time
> 2 * RC5_BIT_LEN_MAX
&& irmp_bit
>= RC5_COMPLETE_DATA_LEN
- 2 && !irmp_param
.stop_bit
)
1476 { // special rc5 decoder
1477 got_light
= TRUE
; // this is a lie, but generates a stop bit ;-)
1478 irmp_param
.stop_bit
= TRUE
; // set flag
1482 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1483 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
&&
1484 irmp_pause_time
> 2 * RC6_BIT_LEN_MAX
&& irmp_bit
>= irmp_param
.complete_len
- 2 && !irmp_param
.stop_bit
)
1485 { // special rc6 decoder
1486 got_light
= TRUE
; // this is a lie, but generates a stop bit ;-)
1487 irmp_param
.stop_bit
= TRUE
; // set flag
1491 if (irmp_pause_time
> IRMP_TIMEOUT_LEN
) // timeout?
1493 if (irmp_bit
== irmp_param
.complete_len
- 1 && irmp_param
.stop_bit
== 0)
1499 DEBUG_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time
, irmp_bit
);
1501 irmp_start_bit_detected
= 0; // wait for another start bit...
1502 irmp_pulse_time
= 0;
1503 irmp_pause_time
= 0;
1515 DEBUG_PRINTF ("[bit %2d: pulse = %3d, pause = %3d] ", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1517 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1518 if (irmp_param
.protocol
== IRMP_RC5_PROTOCOL
) // special rc5 decoder
1520 if (irmp_pulse_time
> RC5_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC5_BIT_LEN_MAX
)
1522 DEBUG_PUTCHAR ('1');
1524 DEBUG_PUTCHAR ('0');
1525 DEBUG_PUTCHAR ('\n');
1530 else // if (irmp_pulse_time >= RC5_BIT_LEN_MIN && irmp_pulse_time <= RC5_BIT_LEN_MAX)
1534 if (last_pause
> RC5_BIT_LEN_MAX
&& last_pause
<= 2 * RC5_BIT_LEN_MAX
)
1536 rc5_value
= last_value
? 0 : 1;
1537 last_value
= rc5_value
;
1541 rc5_value
= last_value
;
1544 DEBUG_PUTCHAR (rc5_value
+ '0');
1545 DEBUG_PUTCHAR ('\n');
1546 irmp_store_bit (rc5_value
);
1549 last_pause
= irmp_pause_time
;
1555 #if IRMP_SUPPORT_RC6_PROTOCOL == 1
1556 if (irmp_param
.protocol
== IRMP_RC6_PROTOCOL
) // special rc6 decoder
1559 { // handle toggle bit, which is 2 times longer than other bits
1563 if (irmp_pulse_time
> RC6_TOGGLE_BIT_LEN_MAX
&& irmp_pause_time
> RC6_TOGGLE_BIT_LEN_MAX
)
1565 DEBUG_PUTCHAR ('1');
1569 DEBUG_PUTCHAR ('0');
1572 DEBUG_PUTCHAR ('\n');
1576 if (irmp_pulse_time
> RC6_BIT_LEN_MAX
&& irmp_pulse_time
<= 2 * RC6_BIT_LEN_MAX
)
1578 DEBUG_PUTCHAR ('0');
1580 DEBUG_PUTCHAR ('1');
1581 DEBUG_PUTCHAR ('\n');
1585 else // if (irmp_pulse_time >= RC6_BIT_LEN_MIN && irmp_pulse_time <= RC6_BIT_LEN_MAX)
1589 if (last_pause
> RC6_BIT_LEN_MAX
&& last_pause
<= 2 * RC6_BIT_LEN_MAX
)
1591 rc5_value
= last_value
? 0 : 1;
1592 last_value
= rc5_value
;
1596 rc5_value
= last_value
;
1599 if (irmp_bit
== 1 && rc5_value
== 0)
1601 irmp_param
.complete_len
= RC6_COMPLETE_DATA_LEN_LONG
;
1604 DEBUG_PUTCHAR (rc5_value
+ '0');
1605 DEBUG_PUTCHAR ('\n');
1606 irmp_store_bit (rc5_value
);
1609 last_pause
= irmp_pause_time
;
1616 #endif // IRMP_SUPPORT_RC6_PROTOCOL == 1
1618 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1619 if (irmp_param
.protocol
== IRMP_SAMSUNG_PROTOCOL
&& irmp_bit
== 16) // Samsung: 16th bit
1621 if (irmp_pulse_time
>= SAMSUNG_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_PULSE_LEN_MAX
&&
1622 irmp_pause_time
>= SAMSUNG_START_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_START_BIT_PAUSE_LEN_MAX
)
1624 DEBUG_PRINTF ("SYNC\n");
1629 else if (irmp_pulse_time
>= SAMSUNG_PULSE_LEN_MIN
&& irmp_pulse_time
<= SAMSUNG_PULSE_LEN_MAX
)
1631 if (irmp_pause_time
>= SAMSUNG_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= SAMSUNG_1_PAUSE_LEN_MAX
)
1633 DEBUG_PUTCHAR ('1');
1634 DEBUG_PUTCHAR ('\n');
1640 DEBUG_PUTCHAR ('0');
1641 DEBUG_PUTCHAR ('\n');
1646 DEBUG_PRINTF ("Switching to SAMSUNG32 protocol\n");
1648 irmp_param
.protocol
= IRMP_SAMSUNG32_PROTOCOL
;
1649 irmp_param
.command_offset
= SAMSUNG32_COMMAND_OFFSET
;
1650 irmp_param
.command_end
= SAMSUNG32_COMMAND_OFFSET
+ SAMSUNG32_COMMAND_LEN
;
1651 irmp_param
.complete_len
= SAMSUNG32_COMPLETE_DATA_LEN
;
1654 { // timing incorrect!
1655 DEBUG_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1656 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1657 irmp_pause_time
= 0;
1661 #endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL
1663 #if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1664 if (irmp_param
.protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1666 if (irmp_pulse_time
>= BANG_OLUFSEN_PULSE_LEN_MIN
&& irmp_pulse_time
<= BANG_OLUFSEN_PULSE_LEN_MAX
)
1668 if (irmp_bit
== 1) // Bang & Olufsen: 3rd bit
1670 if (irmp_pause_time
>= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX
)
1672 DEBUG_PRINTF ("3rd start bit\n");
1678 { // timing incorrect!
1679 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
);
1680 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1681 irmp_pause_time
= 0;
1684 else if (irmp_bit
== 19) // Bang & Olufsen: trailer bit
1686 if (irmp_pause_time
>= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX
)
1688 DEBUG_PRINTF ("trailer bit\n");
1694 { // timing incorrect!
1695 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
);
1696 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1697 irmp_pause_time
= 0;
1702 if (irmp_pause_time
>= BANG_OLUFSEN_1_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_1_PAUSE_LEN_MAX
)
1703 { // pulse & pause timings correct for "1"?
1704 DEBUG_PUTCHAR ('1');
1705 DEBUG_PUTCHAR ('\n');
1710 else if (irmp_pause_time
>= BANG_OLUFSEN_0_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_0_PAUSE_LEN_MAX
)
1711 { // pulse & pause timings correct for "0"?
1712 DEBUG_PUTCHAR ('0');
1713 DEBUG_PUTCHAR ('\n');
1718 else if (irmp_pause_time
>= BANG_OLUFSEN_R_PAUSE_LEN_MIN
&& irmp_pause_time
<= BANG_OLUFSEN_R_PAUSE_LEN_MAX
)
1720 DEBUG_PUTCHAR (last_value
+ '0');
1721 DEBUG_PUTCHAR ('\n');
1722 irmp_store_bit (last_value
);
1726 { // timing incorrect!
1727 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
);
1728 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1729 irmp_pause_time
= 0;
1734 { // timing incorrect!
1735 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
);
1736 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1737 irmp_pause_time
= 0;
1741 #endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL
1743 if (irmp_pulse_time
>= irmp_param
.pulse_1_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_1_len_max
&&
1744 irmp_pause_time
>= irmp_param
.pause_1_len_min
&& irmp_pause_time
<= irmp_param
.pause_1_len_max
)
1745 { // pulse & pause timings correct for "1"?
1746 DEBUG_PUTCHAR ('1');
1747 DEBUG_PUTCHAR ('\n');
1751 else if (irmp_pulse_time
>= irmp_param
.pulse_0_len_min
&& irmp_pulse_time
<= irmp_param
.pulse_0_len_max
&&
1752 irmp_pause_time
>= irmp_param
.pause_0_len_min
&& irmp_pause_time
<= irmp_param
.pause_0_len_max
)
1753 { // pulse & pause timings correct for "0"?
1754 DEBUG_PUTCHAR ('0');
1755 DEBUG_PUTCHAR ('\n');
1760 { // timing incorrect!
1761 DEBUG_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit
, irmp_pulse_time
, irmp_pause_time
);
1762 irmp_start_bit_detected
= 0; // reset flags and wait for next start bit
1763 irmp_pause_time
= 0;
1766 irmp_pulse_time
= 1; // set counter to 1, not 0
1770 { // counting the pulse length ...
1771 if (!irmp_input
) // still light?
1773 irmp_pulse_time
++; // increment counter
1777 wait_for_space
= 1; // let's count the time (see above)
1778 irmp_pause_time
= 1; // set pause counter to 1, not 0
1782 if (irmp_bit
== irmp_param
.complete_len
&& irmp_param
.stop_bit
== 0) // enough bits received?
1784 // if SIRCS/SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore it.
1785 if ((irmp_param
.protocol
== IRMP_SIRCS_PROTOCOL
||
1786 irmp_param
.protocol
== IRMP_SAMSUNG32_PROTOCOL
||
1787 irmp_param
.protocol
== IRMP_NUBERT_PROTOCOL
) &&
1788 last_irmp_command
== irmp_tmp_command
&& repetition_counter
< AUTO_REPETITION_LEN
)
1790 DEBUG_PRINTF ("code skipped, recognized SIRCS, SAMSUNG32 or NUBERT repetition, counter = %d, auto repetition len = %d\n",
1791 repetition_counter
, AUTO_REPETITION_LEN
);
1792 repetition_counter
= 0;
1796 DEBUG_PRINTF ("code detected, length = %d\n", irmp_bit
);
1797 irmp_ir_detected
= TRUE
;
1799 #if IRMP_SUPPORT_DENON_PROTOCOL == 1
1800 if (irmp_param
.protocol
== IRMP_DENON_PROTOCOL
)
1801 { // check for repetition frame
1802 if ((~irmp_tmp_command
& 0x3FF) == last_irmp_denon_command
) // command bits must be inverted
1804 irmp_tmp_command
= last_irmp_denon_command
; // use command received before!
1806 irmp_protocol
= irmp_param
.protocol
; // store protocol
1807 irmp_address
= irmp_tmp_address
; // store address
1808 irmp_command
= irmp_tmp_command
; // store command
1812 DEBUG_PRINTF ("waiting for inverted command repetition\n");
1813 irmp_ir_detected
= FALSE
;
1814 last_irmp_denon_command
= irmp_tmp_command
;
1818 #endif // IRMP_SUPPORT_DENON_PROTOCOL
1820 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1821 if (irmp_param
.protocol
== IRMP_NEC_PROTOCOL
&& irmp_bit
== 0) // repetition frame
1823 irmp_tmp_address
= last_irmp_address
; // address is last address
1824 irmp_tmp_command
= last_irmp_command
; // command is last command
1825 irmp_flags
|= IRMP_FLAG_REPETITION
;
1827 #endif // IRMP_SUPPORT_NEC_PROTOCOL
1828 irmp_protocol
= irmp_param
.protocol
;
1829 irmp_address
= irmp_tmp_address
; // store address
1830 #if IRMP_SUPPORT_NEC_PROTOCOL == 1
1831 last_irmp_address
= irmp_tmp_address
; // store as last address, too
1834 #if IRMP_SUPPORT_RC5_PROTOCOL == 1
1835 irmp_tmp_command
|= rc5_cmd_bit6
; // store bit 6
1837 irmp_command
= irmp_tmp_command
; // store command
1839 #if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1
1840 irmp_id
= irmp_tmp_id
;
1845 if (irmp_ir_detected
)
1847 if (last_irmp_command
== irmp_command
&&
1848 last_irmp_address
== irmp_address
&&
1849 repetition_counter
< IRMP_REPETITION_TIME
)
1851 irmp_flags
|= IRMP_FLAG_REPETITION
;
1854 last_irmp_address
= irmp_tmp_address
; // store as last address, too
1855 last_irmp_command
= irmp_tmp_command
; // store as last command, too
1857 repetition_counter
= 0;
1860 irmp_start_bit_detected
= 0; // and wait for next start bit
1861 irmp_tmp_command
= 0;
1862 irmp_pulse_time
= 0;
1863 irmp_pause_time
= 0;
1871 // main function - for unix/linux + windows only!
1873 // Compile it under linux with:
1874 // cc irmp.c -o irmp
1876 // usage: ./irmp [-v|-s|-a] < file
1879 print_timings (void)
1881 printf ("PROTOCOL START BIT NO. START BIT PULSE START BIT PAUSE\n");
1882 printf ("====================================================================================\n");
1883 printf ("SIRCS 1 %3d - %3d %3d - %3d\n",
1884 SIRCS_START_BIT_PULSE_LEN_MIN
, SIRCS_START_BIT_PULSE_LEN_MAX
, SIRCS_START_BIT_PAUSE_LEN_MIN
, SIRCS_START_BIT_PAUSE_LEN_MAX
);
1885 printf ("NEC 1 %3d - %3d %3d - %3d\n",
1886 NEC_START_BIT_PULSE_LEN_MIN
, NEC_START_BIT_PULSE_LEN_MAX
, NEC_START_BIT_PAUSE_LEN_MIN
, NEC_START_BIT_PAUSE_LEN_MAX
);
1887 printf ("NEC (rep) 1 %3d - %3d %3d - %3d\n",
1888 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
);
1889 printf ("SAMSUNG 1 %3d - %3d %3d - %3d\n",
1890 SAMSUNG_START_BIT_PULSE_LEN_MIN
, SAMSUNG_START_BIT_PULSE_LEN_MAX
, SAMSUNG_START_BIT_PAUSE_LEN_MIN
, SAMSUNG_START_BIT_PAUSE_LEN_MAX
);
1891 printf ("MATSUSHITA 1 %3d - %3d %3d - %3d\n",
1892 MATSUSHITA_START_BIT_PULSE_LEN_MIN
, MATSUSHITA_START_BIT_PULSE_LEN_MAX
, MATSUSHITA_START_BIT_PAUSE_LEN_MIN
, MATSUSHITA_START_BIT_PAUSE_LEN_MAX
);
1893 printf ("KASEIKYO 1 %3d - %3d %3d - %3d\n",
1894 KASEIKYO_START_BIT_PULSE_LEN_MIN
, KASEIKYO_START_BIT_PULSE_LEN_MAX
, KASEIKYO_START_BIT_PAUSE_LEN_MIN
, KASEIKYO_START_BIT_PAUSE_LEN_MAX
);
1895 printf ("RECS80 1 %3d - %3d %3d - %3d\n",
1896 RECS80_START_BIT_PULSE_LEN_MIN
, RECS80_START_BIT_PULSE_LEN_MAX
, RECS80_START_BIT_PAUSE_LEN_MIN
, RECS80_START_BIT_PAUSE_LEN_MAX
);
1897 printf ("RC5 1 %3d - %3d %3d - %3d\n",
1898 RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
, RC5_START_BIT_LEN_MIN
, RC5_START_BIT_LEN_MAX
);
1899 printf ("DENON 1 %3d - %3d %3d - %3d or %3d - %3d\n",
1900 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
);
1901 printf ("RC6 1 %3d - %3d %3d - %3d\n",
1902 RC6_START_BIT_PULSE_LEN_MIN
, RC6_START_BIT_PULSE_LEN_MAX
, RC6_START_BIT_PAUSE_LEN_MIN
, RC6_START_BIT_PAUSE_LEN_MAX
);
1903 printf ("RECS80EXT 1 %3d - %3d %3d - %3d\n",
1904 RECS80EXT_START_BIT_PULSE_LEN_MIN
, RECS80EXT_START_BIT_PULSE_LEN_MAX
, RECS80EXT_START_BIT_PAUSE_LEN_MIN
, RECS80EXT_START_BIT_PAUSE_LEN_MAX
);
1905 printf ("NUBERT 1 %3d - %3d %3d - %3d\n",
1906 NUBERT_START_BIT_PULSE_LEN_MIN
, NUBERT_START_BIT_PULSE_LEN_MAX
, NUBERT_START_BIT_PAUSE_LEN_MIN
, NUBERT_START_BIT_PAUSE_LEN_MAX
);
1907 printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n",
1908 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
);
1909 printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n",
1910 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
);
1911 printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n",
1912 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
);
1913 printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n",
1914 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
);
1918 main (int argc
, char ** argv
)
1921 int verbose
= FALSE
;
1922 int analyze
= FALSE
;
1928 int min_pulse_long
= 100000;
1929 int max_pulse_long
= 0;
1930 int sum_pulses_long
= 0;
1931 int n_pulses_long
= 0;
1933 int min_pulse_short
= 100000;
1934 int max_pulse_short
= 0;
1935 int sum_pulses_short
= 0;
1936 int n_pulses_short
= 0;
1938 int min_pause_long
= 100000;
1939 int max_pause_long
= 0;
1940 int sum_pauses_long
= 0;
1941 int n_pauses_long
= 0;
1943 int min_pause_short
= 100000;
1944 int max_pause_short
= 0;
1945 int sum_pauses_short
= 0;
1946 int n_pauses_short
= 0;
1948 int min_start_pulse
= 100000;
1949 int max_start_pulse
= 0;
1950 int sum_start_pulses
= 0;
1951 int n_start_pulses
= 0;
1953 int min_start_pause
= 100000;
1954 int max_start_pause
= 0;
1955 int sum_start_pauses
= 0;
1956 int n_start_pauses
= 0;
1958 int first_pulse
= TRUE
;
1959 int first_pause
= TRUE
;
1961 IRMP_DATA irmp_data
;
1965 if (! strcmp (argv
[1], "-v"))
1969 else if (! strcmp (argv
[1], "-a"))
1974 else if (! strcmp (argv
[1], "-s"))
1978 else if (! strcmp (argv
[1], "-p"))
1987 while ((ch
= getchar ()) != EOF
)
1989 if (ch
== '_' || ch
== '0')
1993 if (verbose
&& pause
> 0)
1995 printf ("pause: %d\n", pause
);
1999 if (min_start_pause
> pause
)
2001 min_start_pause
= pause
;
2003 if (max_start_pause
< pause
)
2005 max_start_pause
= pause
;
2008 sum_start_pauses
+= pause
;
2009 first_pause
= FALSE
;
2015 if (pause
> 100) // perhaps repetition frame follows
2022 if (min_pause_long
> pause
)
2024 min_pause_long
= pause
;
2026 if (max_pause_long
< pause
)
2028 max_pause_long
= pause
;
2031 sum_pauses_long
+= pause
;
2036 if (min_pause_short
> pause
)
2038 min_pause_short
= pause
;
2040 if (max_pause_short
< pause
)
2042 max_pause_short
= pause
;
2045 sum_pauses_short
+= pause
;
2054 else if (ch
== 0xaf || ch
== '-' || ch
== '1')
2060 printf ("pulse: %d ", pulse
);
2064 if (min_start_pulse
> pulse
)
2066 min_start_pulse
= pulse
;
2068 if (max_start_pulse
< pulse
)
2070 max_start_pulse
= pulse
;
2073 sum_start_pulses
+= pulse
;
2074 first_pulse
= FALSE
;
2080 if (min_pulse_long
> pulse
)
2082 min_pulse_long
= pulse
;
2084 if (max_pulse_long
< pulse
)
2086 max_pulse_long
= pulse
;
2089 sum_pulses_long
+= pulse
;
2093 if (min_pulse_short
> pulse
)
2095 min_pulse_short
= pulse
;
2097 if (max_pulse_short
< pulse
)
2099 max_pulse_short
= pulse
;
2102 sum_pulses_short
+= pulse
;
2111 else if (ch
== '\n')
2115 if (verbose
&& pause
> 0)
2117 printf ("pause: %d\n", pause
);
2123 for (i
= 0; i
< 8000; i
++) // newline: long pause of 800 msec
2133 puts ("-------------------------------------------------------------------");
2136 while ((ch
= getchar()) != '\n' && ch
!= EOF
)
2138 if (ch
!= '\r') // ignore CR in DOS/Windows files
2153 if (irmp_get_data (&irmp_data
))
2155 printf ("protcol = %d, address = 0x%04x, code = 0x%04x, flags = 0x%02x\n",
2156 irmp_data
.protocol
, irmp_data
.address
, irmp_data
.command
, irmp_data
.flags
);
2162 printf ("\nSTATITSTICS:\n");
2163 printf ("---------------------------------\n");
2164 printf ("number of start pulses: %d\n", n_start_pulses
);
2165 printf ("minimum start pulse length: %d usec\n", (1000000 * min_start_pulse
) / F_INTERRUPTS
);
2166 printf ("maximum start pulse length: %d usec\n", (1000000 * max_start_pulse
) / F_INTERRUPTS
);
2167 if (n_start_pulses
> 0)
2169 printf ("average start pulse length: %d usec\n", ((1000000 * sum_start_pulses
) / n_start_pulses
) / F_INTERRUPTS
);
2172 printf ("number of start pauses: %d\n", n_start_pauses
);
2173 if (n_start_pauses
> 0)
2175 printf ("minimum start pause length: %d usec\n", (1000000 * min_start_pause
) / F_INTERRUPTS
);
2176 printf ("maximum start pause length: %d usec\n", (1000000 * max_start_pause
) / F_INTERRUPTS
);
2177 printf ("average start pause length: %d usec\n", ((1000000 * sum_start_pauses
) / n_start_pauses
) / F_INTERRUPTS
);
2180 printf ("number of long pulses: %d\n", n_pulses_long
);
2181 if (n_pulses_long
> 0)
2183 printf ("minimum long pulse length: %d usec\n", (1000000 * min_pulse_long
) / F_INTERRUPTS
);
2184 printf ("maximum long pulse length: %d usec\n", (1000000 * max_pulse_long
) / F_INTERRUPTS
);
2185 printf ("average long pulse length: %d usec\n", ((1000000 * sum_pulses_long
) / n_pulses_long
) / F_INTERRUPTS
);
2188 printf ("number of short pulses: %d\n", n_pulses_short
);
2189 if (n_pulses_short
> 0)
2191 printf ("minimum short pulse length: %d usec\n", (1000000 * min_pulse_short
) / F_INTERRUPTS
);
2192 printf ("maximum short pulse length: %d usec\n", (1000000 * max_pulse_short
) / F_INTERRUPTS
);
2193 printf ("average short pulse length: %d usec\n", ((1000000 * sum_pulses_short
) / n_pulses_short
) / F_INTERRUPTS
);
2197 printf ("number of long pauses: %d\n", n_pauses_long
);
2198 if (n_pauses_long
> 0)
2200 printf ("minimum long pause length: %d usec\n", (1000000 * min_pause_long
) / F_INTERRUPTS
);
2201 printf ("maximum long pause length: %d usec\n", (1000000 * max_pause_long
) / F_INTERRUPTS
);
2202 printf ("average long pause length: %d usec\n", ((1000000 * sum_pauses_long
) / n_pauses_long
) / F_INTERRUPTS
);
2205 printf ("number of short pauses: %d\n", n_pauses_short
);
2206 if (n_pauses_short
> 0)
2208 printf ("minimum short pause length: %d usec\n", (1000000 * min_pause_short
) / F_INTERRUPTS
);
2209 printf ("maximum short pause length: %d usec\n", (1000000 * max_pause_short
) / F_INTERRUPTS
);
2210 printf ("average short pause length: %d usec\n", ((1000000 * sum_pauses_short
) / n_pauses_short
) / F_INTERRUPTS
);