1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
4 * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de
6 * $Id: irsnd.c,v 1.17 2010/06/10 10:05:56 fm Exp $
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 #ifdef unix // test/debug on linux/unix
23 #define F_CPU 8000000L
27 #ifdef WIN32 // test/debug on windows
29 #define F_CPU 8000000L
30 typedef unsigned char uint8_t;
31 typedef unsigned short uint16_t;
43 #include <util/delay.h>
44 #include <avr/pgmspace.h>
51 #include "irsndconfig.h"
54 #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)
55 #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)
56 #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)
57 #define SIRCS_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME + 0.5)
58 #define SIRCS_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME + 0.5)
59 #define SIRCS_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
60 #define SIRCS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
62 #define NEC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME + 0.5)
63 #define NEC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME + 0.5)
64 #define NEC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
65 #define NEC_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME + 0.5)
66 #define NEC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME + 0.5)
67 #define NEC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME + 0.5)
68 #define NEC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
70 #define SAMSUNG_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME + 0.5)
71 #define SAMSUNG_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME + 0.5)
72 #define SAMSUNG_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME + 0.5)
73 #define SAMSUNG_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME + 0.5)
74 #define SAMSUNG_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME + 0.5)
75 #define SAMSUNG_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
77 #define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
78 #define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
80 #define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)
81 #define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)
82 #define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)
83 #define MATSUSHITA_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME + 0.5)
84 #define MATSUSHITA_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME + 0.5)
85 #define MATSUSHITA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * MATSUSHITA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
87 #define RECS80_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME + 0.5)
88 #define RECS80_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME + 0.5)
89 #define RECS80_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME + 0.5)
90 #define RECS80_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME + 0.5)
91 #define RECS80_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME + 0.5)
92 #define RECS80_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
94 #define RC5_START_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
95 #define RC5_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
96 #define RC5_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC5_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
98 #define RC6_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME + 0.5)
99 #define RC6_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME + 0.5)
100 #define RC6_TOGGLE_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME + 0.5)
101 #define RC6_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_BIT_TIME + 0.5)
102 #define RC6_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC6_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
104 #define DENON_PULSE_LEN (uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME + 0.5)
105 #define DENON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME + 0.5)
106 #define DENON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME + 0.5)
107 #define DENON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
108 #define DENON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
110 #define RECS80EXT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME + 0.5)
111 #define RECS80EXT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME + 0.5)
112 #define RECS80EXT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME + 0.5)
113 #define RECS80EXT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME + 0.5)
114 #define RECS80EXT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME + 0.5)
115 #define RECS80EXT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80EXT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
117 #define NUBERT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME + 0.5)
118 #define NUBERT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME + 0.5)
119 #define NUBERT_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME + 0.5)
120 #define NUBERT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME + 0.5)
121 #define NUBERT_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME + 0.5)
122 #define NUBERT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME + 0.5)
123 #define NUBERT_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
124 #define NUBERT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
126 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME + 0.5)
127 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME + 0.5)
128 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME + 0.5)
129 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME + 0.5)
130 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME + 0.5)
131 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME + 0.5)
132 #define BANG_OLUFSEN_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME + 0.5)
133 #define BANG_OLUFSEN_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME + 0.5)
134 #define BANG_OLUFSEN_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME + 0.5)
135 #define BANG_OLUFSEN_R_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME + 0.5)
136 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)
137 #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
139 #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME + 0.5)
140 #define GRUNDIG_OR_NOKIA_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME + 0.5)
141 #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
142 #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
143 #define GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
145 #define SIEMENS_START_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)
146 #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)
147 #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
149 #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1)
150 #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1)
151 #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1)
152 #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1)
153 #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1)
154 #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1)
156 #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)
157 #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)
158 #define FDC_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)
159 #define FDC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)
160 #define FDC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)
161 #define FDC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
163 static volatile uint8_t irsnd_busy
;
164 static volatile uint8_t irsnd_protocol
;
165 static volatile uint8_t irsnd_buffer
[6];
166 static volatile uint8_t irsnd_repeat
;
167 static volatile uint8_t irsnd_is_on
= FALSE
;
169 /*---------------------------------------------------------------------------------------------------------------------------------------------------
171 * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing
172 *---------------------------------------------------------------------------------------------------------------------------------------------------
180 #if defined (__AVR_ATmega32__)
181 TCCR2
|= (1<<COM20
)|(1<<WGM21
); // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A
183 TCCR2A
|= (1<<COM2A0
)|(1<<WGM21
); // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A
190 /*---------------------------------------------------------------------------------------------------------------------------------------------------
192 * @details Switches PWM off
193 *---------------------------------------------------------------------------------------------------------------------------------------------------
201 #if defined (__AVR_ATmega32__)
202 TCCR2
&= ~(1<<COM20
); // normal port operation, OC2A disconnected.
204 TCCR2A
&= ~(1<<COM2A0
); // normal port operation, OC2A disconnected.
206 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
212 /*---------------------------------------------------------------------------------------------------------------------------------------------------
214 * @details sets pwm frequency
215 *---------------------------------------------------------------------------------------------------------------------------------------------------
218 irsnd_set_freq (uint8_t freq
)
221 #if defined (__AVR_ATmega32__)
229 /*---------------------------------------------------------------------------------------------------------------------------------------------------
231 * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels
232 *---------------------------------------------------------------------------------------------------------------------------------------------------
238 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
239 IRSND_DDR
|= (1<<IRSND_BIT
); // set IRSND_BIT to output
241 #if defined (__AVR_ATmega32__)
242 TCCR2
= (1<<WGM21
); // CTC mode
243 TCCR2
|= (1<<CS20
); // 0x01, start Timer 2, no prescaling
245 TCCR2A
= (1<<WGM21
); // CTC mode
246 TCCR2B
|= (1<<CS20
); // 0x01, start Timer 2, no prescaling
249 irsnd_set_freq (IRSND_FREQ_36_KHZ
); // default frequency
260 bitsrevervse (uint16_t x
, uint8_t len
)
279 irsnd_send_data (IRMP_DATA
* irmp_data_p
, uint8_t do_wait
)
281 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
282 static uint8_t toggle_bit_recs80
;
284 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
285 static uint8_t toggle_bit_recs80ext
;
287 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
288 static uint8_t toggle_bit_rc5
;
305 irsnd_protocol
= irmp_data_p
->protocol
;
306 irsnd_repeat
= irmp_data_p
->flags
;
308 switch (irsnd_protocol
)
310 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
311 case IRMP_SIRCS_PROTOCOL
:
313 command
= bitsrevervse (irmp_data_p
->command
, SIRCS_MINIMUM_DATA_LEN
);
315 irsnd_buffer
[0] = (command
& 0x0FF0) >> 4; // CCCCCCCC
316 irsnd_buffer
[1] = (command
& 0x000F) << 4; // CCCC0000
321 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
322 case IRMP_NEC_PROTOCOL
:
323 case IRMP_APPLE_PROTOCOL
:
325 address
= bitsrevervse (irmp_data_p
->address
, NEC_ADDRESS_LEN
);
326 command
= bitsrevervse (irmp_data_p
->command
, NEC_COMMAND_LEN
);
328 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
329 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
330 irsnd_buffer
[2] = (command
& 0xFF00) >> 8; // CCCCCCCC
332 if (irsnd_protocol
== IRMP_APPLE_PROTOCOL
)
334 irsnd_protocol
= IRMP_NEC_PROTOCOL
; // APPLE protocol is NEC with fix bitmask instead of inverted command
335 irsnd_buffer
[3] = 0x8B; // 10001011
339 irsnd_buffer
[3] = ~((command
& 0xFF00) >> 8); // cccccccc
346 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
347 case IRMP_SAMSUNG_PROTOCOL
:
349 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
350 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG_COMMAND_LEN
);
352 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
353 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
354 irsnd_buffer
[2] = (command
& 0x00F0) | ((command
& 0xF000) >> 12); // IIIICCCC
355 irsnd_buffer
[3] = ((command
& 0x0F00) >> 4) | ((~(command
& 0xF000) >> 12) & 0x0F); // CCCCcccc
356 irsnd_buffer
[4] = (~(command
& 0x0F00) >> 4) & 0xF0; // cccc0000
360 case IRMP_SAMSUNG32_PROTOCOL
:
362 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
363 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG32_COMMAND_LEN
);
365 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
366 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
367 irsnd_buffer
[2] = (command
& 0xFF00) >> 8; // CCCCCCCC
368 irsnd_buffer
[3] = (command
& 0x00FF); // CCCCCCCC
373 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
374 case IRMP_MATSUSHITA_PROTOCOL
:
376 address
= bitsrevervse (irmp_data_p
->address
, MATSUSHITA_ADDRESS_LEN
);
377 command
= bitsrevervse (irmp_data_p
->command
, MATSUSHITA_COMMAND_LEN
);
379 irsnd_buffer
[0] = (command
& 0x0FF0) >> 4; // CCCCCCCC
380 irsnd_buffer
[1] = ((command
& 0x000F) << 4) | ((address
& 0x0F00) >> 8); // CCCCAAAA
381 irsnd_buffer
[2] = (address
& 0x00FF); // AAAAAAAA
386 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
387 case IRMP_RECS80_PROTOCOL
:
389 toggle_bit_recs80
= toggle_bit_recs80
? 0x00 : 0x40;
391 irsnd_buffer
[0] = 0x80 | toggle_bit_recs80
| ((irmp_data_p
->address
& 0x0007) << 3) |
392 ((irmp_data_p
->command
& 0x0038) >> 3); // STAAACCC
393 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x07) << 5; // CCC00000
398 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
399 case IRMP_RECS80EXT_PROTOCOL
:
401 toggle_bit_recs80ext
= toggle_bit_recs80ext
? 0x00 : 0x40;
403 irsnd_buffer
[0] = 0x80 | toggle_bit_recs80ext
| ((irmp_data_p
->address
& 0x000F) << 2) |
404 ((irmp_data_p
->command
& 0x0030) >> 4); // STAAAACC
405 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x0F) << 4; // CCCC0000
410 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
411 case IRMP_RC5_PROTOCOL
:
413 toggle_bit_rc5
= toggle_bit_rc5
? 0x00 : 0x40;
415 irsnd_buffer
[0] = ((irmp_data_p
->command
& 0x40) ? 0x00 : 0x80) | toggle_bit_rc5
|
416 ((irmp_data_p
->address
& 0x001F) << 1) | ((irmp_data_p
->command
& 0x20) >> 5); // CTAAAAAC
417 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x1F) << 3; // CCCCC000
422 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
423 case IRMP_DENON_PROTOCOL
:
425 irsnd_buffer
[0] = ((irmp_data_p
->address
& 0x1F) << 3) | ((irmp_data_p
->command
& 0x0380) >> 7); // AAAAACCC (1st frame)
426 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x7F) << 1; // CCCCCCC
427 irsnd_buffer
[2] = ((irmp_data_p
->address
& 0x1F) << 3) | (((~irmp_data_p
->command
) & 0x0380) >> 7); // AAAAACCC (2nd frame)
428 irsnd_buffer
[3] = (~(irmp_data_p
->command
) & 0x7F) << 1; // CCCCCCC
433 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
434 case IRMP_NUBERT_PROTOCOL
:
436 irsnd_buffer
[0] = irmp_data_p
->command
>> 2; // CCCCCCCC
437 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x0003) << 6; // CC000000
442 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
443 case IRMP_BANG_OLUFSEN_PROTOCOL
:
445 irsnd_buffer
[0] = irmp_data_p
->command
>> 11; // SXSCCCCC
446 irsnd_buffer
[1] = irmp_data_p
->command
>> 3; // CCCCCCCC
447 irsnd_buffer
[2] = (irmp_data_p
->command
& 0x0007) << 5; // CCC00000
452 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
453 case IRMP_GRUNDIG_PROTOCOL
:
455 command
= bitsrevervse (irmp_data_p
->command
, GRUNDIG_COMMAND_LEN
);
457 irsnd_buffer
[0] = 0xFF; // S1111111 (1st frame)
458 irsnd_buffer
[1] = 0xC0; // 11
459 irsnd_buffer
[2] = 0x80 | (command
>> 2); // SCCCCCCC (2nd frame)
460 irsnd_buffer
[3] = (command
<< 6) & 0xC0; // CC
466 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
467 case IRMP_NOKIA_PROTOCOL
:
469 address
= bitsrevervse (irmp_data_p
->address
, NOKIA_ADDRESS_LEN
);
470 command
= bitsrevervse (irmp_data_p
->command
, NOKIA_COMMAND_LEN
);
472 irsnd_buffer
[0] = 0xBF; // S0111111 (1st + 3rd frame)
473 irsnd_buffer
[1] = 0xFF; // 11111111
474 irsnd_buffer
[2] = 0x80; // 1
475 irsnd_buffer
[3] = 0x80 | command
>> 1; // SCCCCCCC (2nd frame)
476 irsnd_buffer
[4] = (command
<< 7) | (address
>> 1); // CAAAAAAA
477 irsnd_buffer
[5] = (address
<< 7); // A
483 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
484 case IRMP_SIEMENS_PROTOCOL
:
486 irsnd_buffer
[0] = ((irmp_data_p
->address
& 0x0FFF) >> 5); // SAAAAAAA
487 irsnd_buffer
[1] = ((irmp_data_p
->address
& 0x1F) << 3) | ((irmp_data_p
->command
& 0x7F) >> 5); // AAAAA0CC
488 irsnd_buffer
[2] = (irmp_data_p
->command
<< 3); // CCCCC0
493 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
494 case IRMP_FDC_PROTOCOL
:
496 address
= bitsrevervse (irmp_data_p
->address
, FDC_ADDRESS_LEN
);
497 command
= bitsrevervse (irmp_data_p
->command
, FDC_COMMAND_LEN
);
499 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
500 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
501 irsnd_buffer
[2] = 0; // 00000000
502 irsnd_buffer
[3] = (command
& 0x0FE0) >> 5; // 0CCCCCCC
503 irsnd_buffer
[4] = ((command
& 0x001F) << 3) | 0x07; // CCCCC111
517 /*---------------------------------------------------------------------------------------------------------------------------------------------------
519 * @details ISR routine, called 10000 times per second
520 *---------------------------------------------------------------------------------------------------------------------------------------------------
525 static uint8_t current_bit
= 0xFF;
526 static uint8_t pulse_counter
;
527 static uint8_t pause_counter
;
528 static uint8_t startbit_pulse_len
;
529 static uint8_t startbit_pause_len
;
530 static uint8_t pulse_1_len
;
531 static uint8_t pause_1_len
;
532 static uint8_t pulse_0_len
;
533 static uint8_t pause_0_len
;
534 static uint8_t has_stop_bit
;
535 static uint8_t new_frame
= TRUE
;
536 static uint8_t complete_data_len
;
537 static uint8_t n_auto_repetitions
; // number of auto_repetitions
538 static uint8_t auto_repetition_counter
; // auto_repetition counter
539 static uint16_t auto_repetition_pause_len
; // pause before auto_repetition, uint16_t!
540 static uint16_t auto_repetition_pause_counter
; // pause before auto_repetition, uint16_t!
541 static uint8_t n_repeat_frames
; // number of repeat frames
542 static uint8_t repeat_counter
; // repeat counter
543 static uint16_t repeat_frame_pause_len
; // pause before repeat, uint16_t!
544 static uint16_t packet_repeat_pause_counter
; // pause before repeat, uint16_t!
545 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
546 static uint8_t last_bit_value
;
548 static uint8_t pulse_len
= 0xFF;
549 static uint8_t pause_len
= 0xFF;
553 if (current_bit
== 0xFF && new_frame
) // start of transmission...
555 if (auto_repetition_counter
> 0)
557 auto_repetition_pause_counter
++;
559 if (auto_repetition_pause_counter
>= auto_repetition_pause_len
)
561 auto_repetition_pause_counter
= 0;
563 if (irsnd_protocol
== IRMP_DENON_PROTOCOL
)
566 complete_data_len
= 2 * DENON_COMPLETE_DATA_LEN
+ 1;
568 else if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
) // n'th grundig info frame
571 complete_data_len
= 16 + GRUNDIG_COMPLETE_DATA_LEN
;
573 else if (irsnd_protocol
== IRMP_NOKIA_PROTOCOL
) // n'th nokia info frame
575 if (auto_repetition_counter
+ 1 < n_auto_repetitions
)
578 complete_data_len
= 24 + NOKIA_COMPLETE_DATA_LEN
;
580 else // nokia stop frame
583 complete_data_len
= NOKIA_COMPLETE_DATA_LEN
;
602 else if (repeat_counter
> 0 && packet_repeat_pause_counter
< repeat_frame_pause_len
)
604 packet_repeat_pause_counter
++;
620 n_repeat_frames
= irsnd_repeat
;
621 packet_repeat_pause_counter
= 0;
625 switch (irsnd_protocol
)
627 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
628 case IRMP_SIRCS_PROTOCOL
:
630 startbit_pulse_len
= SIRCS_START_BIT_PULSE_LEN
;
631 startbit_pause_len
= SIRCS_START_BIT_PAUSE_LEN
;
632 pulse_1_len
= SIRCS_1_PULSE_LEN
;
633 pause_1_len
= SIRCS_PAUSE_LEN
;
634 pulse_0_len
= SIRCS_0_PULSE_LEN
;
635 pause_0_len
= SIRCS_PAUSE_LEN
;
636 has_stop_bit
= SIRCS_STOP_BIT
;
637 complete_data_len
= SIRCS_MINIMUM_DATA_LEN
;
638 n_auto_repetitions
= (repeat_counter
== 0) ? SIRCS_FRAMES
: 1; // 3 frames auto repetition if first frame
639 auto_repetition_pause_len
= SIRCS_AUTO_REPETITION_PAUSE_LEN
; // 25ms pause
640 repeat_frame_pause_len
= SIRCS_FRAME_REPEAT_PAUSE_LEN
;
641 irsnd_set_freq (IRSND_FREQ_40_KHZ
);
645 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
646 case IRMP_NEC_PROTOCOL
:
648 startbit_pulse_len
= NEC_START_BIT_PULSE_LEN
;
650 if (repeat_counter
> 0)
652 startbit_pause_len
= NEC_REPEAT_START_BIT_PAUSE_LEN
;
653 complete_data_len
= 0;
657 startbit_pause_len
= NEC_START_BIT_PAUSE_LEN
;
658 complete_data_len
= NEC_COMPLETE_DATA_LEN
;
661 pulse_1_len
= NEC_PULSE_LEN
;
662 pause_1_len
= NEC_1_PAUSE_LEN
;
663 pulse_0_len
= NEC_PULSE_LEN
;
664 pause_0_len
= NEC_0_PAUSE_LEN
;
665 has_stop_bit
= NEC_STOP_BIT
;
666 n_auto_repetitions
= 1; // 1 frame
667 auto_repetition_pause_len
= 0;
668 repeat_frame_pause_len
= NEC_FRAME_REPEAT_PAUSE_LEN
;
669 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
673 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
674 case IRMP_SAMSUNG_PROTOCOL
:
676 startbit_pulse_len
= SAMSUNG_START_BIT_PULSE_LEN
;
677 startbit_pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
;
678 pulse_1_len
= SAMSUNG_PULSE_LEN
;
679 pause_1_len
= SAMSUNG_1_PAUSE_LEN
;
680 pulse_0_len
= SAMSUNG_PULSE_LEN
;
681 pause_0_len
= SAMSUNG_0_PAUSE_LEN
;
682 has_stop_bit
= SAMSUNG_STOP_BIT
;
683 complete_data_len
= SAMSUNG_COMPLETE_DATA_LEN
;
684 n_auto_repetitions
= 1; // 1 frame
685 auto_repetition_pause_len
= 0;
686 repeat_frame_pause_len
= SAMSUNG_FRAME_REPEAT_PAUSE_LEN
;
687 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
691 case IRMP_SAMSUNG32_PROTOCOL
:
693 startbit_pulse_len
= SAMSUNG_START_BIT_PULSE_LEN
;
694 startbit_pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
;
695 pulse_1_len
= SAMSUNG_PULSE_LEN
;
696 pause_1_len
= SAMSUNG_1_PAUSE_LEN
;
697 pulse_0_len
= SAMSUNG_PULSE_LEN
;
698 pause_0_len
= SAMSUNG_0_PAUSE_LEN
;
699 has_stop_bit
= SAMSUNG_STOP_BIT
;
700 complete_data_len
= SAMSUNG32_COMPLETE_DATA_LEN
;
701 n_auto_repetitions
= SAMSUNG32_FRAMES
; // 2 frames
702 auto_repetition_pause_len
= SAMSUNG32_AUTO_REPETITION_PAUSE_LEN
; // 47 ms pause
703 repeat_frame_pause_len
= SAMSUNG32_FRAME_REPEAT_PAUSE_LEN
;
704 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
708 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
709 case IRMP_MATSUSHITA_PROTOCOL
:
711 startbit_pulse_len
= MATSUSHITA_START_BIT_PULSE_LEN
;
712 startbit_pause_len
= MATSUSHITA_START_BIT_PAUSE_LEN
;
713 pulse_1_len
= MATSUSHITA_PULSE_LEN
;
714 pause_1_len
= MATSUSHITA_1_PAUSE_LEN
;
715 pulse_0_len
= MATSUSHITA_PULSE_LEN
;
716 pause_0_len
= MATSUSHITA_0_PAUSE_LEN
;
717 has_stop_bit
= MATSUSHITA_STOP_BIT
;
718 complete_data_len
= MATSUSHITA_COMPLETE_DATA_LEN
;
719 n_auto_repetitions
= 1; // 1 frame
720 auto_repetition_pause_len
= 0;
721 repeat_frame_pause_len
= MATSUSHITA_FRAME_REPEAT_PAUSE_LEN
;
722 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
726 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
727 case IRMP_RECS80_PROTOCOL
:
729 startbit_pulse_len
= RECS80_START_BIT_PULSE_LEN
;
730 startbit_pause_len
= RECS80_START_BIT_PAUSE_LEN
;
731 pulse_1_len
= RECS80_PULSE_LEN
;
732 pause_1_len
= RECS80_1_PAUSE_LEN
;
733 pulse_0_len
= RECS80_PULSE_LEN
;
734 pause_0_len
= RECS80_0_PAUSE_LEN
;
735 has_stop_bit
= RECS80_STOP_BIT
;
736 complete_data_len
= RECS80_COMPLETE_DATA_LEN
;
737 n_auto_repetitions
= 1; // 1 frame
738 auto_repetition_pause_len
= 0;
739 repeat_frame_pause_len
= RECS80_FRAME_REPEAT_PAUSE_LEN
;
740 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
744 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
745 case IRMP_RECS80EXT_PROTOCOL
:
747 startbit_pulse_len
= RECS80EXT_START_BIT_PULSE_LEN
;
748 startbit_pause_len
= RECS80EXT_START_BIT_PAUSE_LEN
;
749 pulse_1_len
= RECS80EXT_PULSE_LEN
;
750 pause_1_len
= RECS80EXT_1_PAUSE_LEN
;
751 pulse_0_len
= RECS80EXT_PULSE_LEN
;
752 pause_0_len
= RECS80EXT_0_PAUSE_LEN
;
753 has_stop_bit
= RECS80EXT_STOP_BIT
;
754 complete_data_len
= RECS80EXT_COMPLETE_DATA_LEN
;
755 n_auto_repetitions
= 1; // 1 frame
756 auto_repetition_pause_len
= 0;
757 repeat_frame_pause_len
= RECS80EXT_FRAME_REPEAT_PAUSE_LEN
;
758 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
762 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
763 case IRMP_RC5_PROTOCOL
:
765 startbit_pulse_len
= RC5_BIT_LEN
;
766 startbit_pause_len
= RC5_BIT_LEN
;
767 pulse_len
= RC5_BIT_LEN
;
768 pause_len
= RC5_BIT_LEN
;
769 has_stop_bit
= RC5_STOP_BIT
;
770 complete_data_len
= RC5_COMPLETE_DATA_LEN
;
771 n_auto_repetitions
= 1; // 1 frame
772 auto_repetition_pause_len
= 0;
773 repeat_frame_pause_len
= RC5_FRAME_REPEAT_PAUSE_LEN
;
774 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
778 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
779 case IRMP_DENON_PROTOCOL
:
781 startbit_pulse_len
= 0x00;
782 startbit_pause_len
= 0x00;
783 pulse_1_len
= DENON_PULSE_LEN
;
784 pause_1_len
= DENON_1_PAUSE_LEN
;
785 pulse_0_len
= DENON_PULSE_LEN
;
786 pause_0_len
= DENON_0_PAUSE_LEN
;
787 has_stop_bit
= DENON_STOP_BIT
;
788 complete_data_len
= DENON_COMPLETE_DATA_LEN
;
789 n_auto_repetitions
= DENON_FRAMES
; // 2 frames, 2nd with inverted command
790 auto_repetition_pause_len
= DENON_AUTO_REPETITION_PAUSE_LEN
; // 65 ms pause after 1st frame
791 repeat_frame_pause_len
= DENON_FRAME_REPEAT_PAUSE_LEN
;
792 irsnd_set_freq (IRSND_FREQ_32_KHZ
);
796 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
797 case IRMP_NUBERT_PROTOCOL
:
799 startbit_pulse_len
= NUBERT_START_BIT_PULSE_LEN
;
800 startbit_pause_len
= NUBERT_START_BIT_PAUSE_LEN
;
801 pulse_1_len
= NUBERT_1_PULSE_LEN
;
802 pause_1_len
= NUBERT_1_PAUSE_LEN
;
803 pulse_0_len
= NUBERT_0_PULSE_LEN
;
804 pause_0_len
= NUBERT_0_PAUSE_LEN
;
805 has_stop_bit
= NUBERT_STOP_BIT
;
806 complete_data_len
= NUBERT_COMPLETE_DATA_LEN
;
807 n_auto_repetitions
= NUBERT_FRAMES
; // 2 frames
808 auto_repetition_pause_len
= NUBERT_AUTO_REPETITION_PAUSE_LEN
; // 35 ms pause
809 repeat_frame_pause_len
= NUBERT_FRAME_REPEAT_PAUSE_LEN
;
810 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
814 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
815 case IRMP_BANG_OLUFSEN_PROTOCOL
:
817 startbit_pulse_len
= BANG_OLUFSEN_START_BIT1_PULSE_LEN
;
818 startbit_pause_len
= BANG_OLUFSEN_START_BIT1_PAUSE_LEN
;
819 pulse_1_len
= BANG_OLUFSEN_PULSE_LEN
;
820 pause_1_len
= BANG_OLUFSEN_1_PAUSE_LEN
;
821 pulse_0_len
= BANG_OLUFSEN_PULSE_LEN
;
822 pause_0_len
= BANG_OLUFSEN_0_PAUSE_LEN
;
823 has_stop_bit
= BANG_OLUFSEN_STOP_BIT
;
824 complete_data_len
= BANG_OLUFSEN_COMPLETE_DATA_LEN
;
825 n_auto_repetitions
= 1; // 1 frame
826 auto_repetition_pause_len
= 0;
827 repeat_frame_pause_len
= BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN
;
829 irsnd_set_freq (IRSND_FREQ_455_KHZ
);
833 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
834 case IRMP_GRUNDIG_PROTOCOL
:
836 startbit_pulse_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
837 startbit_pause_len
= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN
;
838 pulse_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
839 pause_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
840 has_stop_bit
= GRUNDIG_OR_NOKIA_STOP_BIT
;
841 complete_data_len
= GRUNDIG_COMPLETE_DATA_LEN
;
842 n_auto_repetitions
= GRUNDIG_FRAMES
; // 2 frames
843 auto_repetition_pause_len
= GRUNDIG_AUTO_REPETITION_PAUSE_LEN
; // 20m sec pause
844 repeat_frame_pause_len
= GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN
; // 117 msec pause
845 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
850 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
851 case IRMP_NOKIA_PROTOCOL
:
853 startbit_pulse_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
854 startbit_pause_len
= GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN
;
855 pulse_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
856 pause_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
857 has_stop_bit
= GRUNDIG_OR_NOKIA_STOP_BIT
;
858 complete_data_len
= NOKIA_COMPLETE_DATA_LEN
;
859 n_auto_repetitions
= NOKIA_FRAMES
; // 2 frames
860 auto_repetition_pause_len
= NOKIA_AUTO_REPETITION_PAUSE_LEN
; // 20 msec pause
861 repeat_frame_pause_len
= GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN
; // 117 msec pause
862 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
866 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
867 case IRMP_SIEMENS_PROTOCOL
:
869 startbit_pulse_len
= SIEMENS_BIT_LEN
;
870 startbit_pause_len
= SIEMENS_BIT_LEN
;
871 pulse_len
= SIEMENS_BIT_LEN
;
872 pause_len
= SIEMENS_BIT_LEN
;
873 has_stop_bit
= SIEMENS_STOP_BIT
;
874 complete_data_len
= SIEMENS_COMPLETE_DATA_LEN
- 1;
875 n_auto_repetitions
= 1; // 1 frame
876 auto_repetition_pause_len
= 0;
877 repeat_frame_pause_len
= SIEMENS_FRAME_REPEAT_PAUSE_LEN
;
878 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
882 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
883 case IRMP_FDC_PROTOCOL
:
885 startbit_pulse_len
= FDC_START_BIT_PULSE_LEN
;
886 startbit_pause_len
= FDC_START_BIT_PAUSE_LEN
;
887 complete_data_len
= FDC_COMPLETE_DATA_LEN
;
888 pulse_1_len
= FDC_PULSE_LEN
;
889 pause_1_len
= FDC_1_PAUSE_LEN
;
890 pulse_0_len
= FDC_PULSE_LEN
;
891 pause_0_len
= FDC_0_PAUSE_LEN
;
892 has_stop_bit
= FDC_STOP_BIT
;
893 n_auto_repetitions
= 1; // 1 frame
894 auto_repetition_pause_len
= 0;
895 repeat_frame_pause_len
= FDC_FRAME_REPEAT_PAUSE_LEN
;
896 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
913 switch (irsnd_protocol
)
915 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
916 case IRMP_SIRCS_PROTOCOL
:
918 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
919 case IRMP_NEC_PROTOCOL
:
921 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
922 case IRMP_SAMSUNG_PROTOCOL
:
923 case IRMP_SAMSUNG32_PROTOCOL
:
925 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
926 case IRMP_MATSUSHITA_PROTOCOL
:
928 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
929 case IRMP_RECS80_PROTOCOL
:
931 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
932 case IRMP_RECS80EXT_PROTOCOL
:
934 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
935 case IRMP_DENON_PROTOCOL
:
937 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
938 case IRMP_NUBERT_PROTOCOL
:
940 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
941 case IRMP_BANG_OLUFSEN_PROTOCOL
:
943 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
944 case IRMP_FDC_PROTOCOL
:
948 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \
949 IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || \
950 IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1
952 if (pulse_counter
== 0)
954 if (current_bit
== 0xFF) // send start bit
956 pulse_len
= startbit_pulse_len
;
957 pause_len
= startbit_pause_len
;
959 else if (current_bit
< complete_data_len
) // send n'th bit
961 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
962 if (irsnd_protocol
== IRMP_SAMSUNG_PROTOCOL
)
964 if (current_bit
< SAMSUNG_ADDRESS_LEN
) // send address bits
966 pulse_len
= SAMSUNG_PULSE_LEN
;
967 pause_len
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ?
968 SAMSUNG_1_PAUSE_LEN
: SAMSUNG_0_PAUSE_LEN
;
970 else if (current_bit
== SAMSUNG_ADDRESS_LEN
) // send SYNC bit (16th bit)
972 pulse_len
= SAMSUNG_PULSE_LEN
;
973 pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
;
975 else if (current_bit
< SAMSUNG_COMPLETE_DATA_LEN
) // send n'th bit
977 uint8_t cur_bit
= current_bit
- 1; // sync skipped, offset = -1 !
979 pulse_len
= SAMSUNG_PULSE_LEN
;
980 pause_len
= (irsnd_buffer
[cur_bit
/ 8] & (1<<(7-(cur_bit
% 8)))) ?
981 SAMSUNG_1_PAUSE_LEN
: SAMSUNG_0_PAUSE_LEN
;
987 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
988 if (irsnd_protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
990 if (current_bit
== 0) // send 2nd start bit
992 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
993 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
;
995 else if (current_bit
== 1) // send 3rd start bit
997 pulse_len
= BANG_OLUFSEN_START_BIT3_PULSE_LEN
;
998 pause_len
= BANG_OLUFSEN_START_BIT3_PAUSE_LEN
;
1000 else if (current_bit
== 2) // send 4th start bit
1002 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
1003 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
;
1005 else if (current_bit
== 19) // send trailer bit
1007 pulse_len
= BANG_OLUFSEN_PULSE_LEN
;
1008 pause_len
= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN
;
1010 else if (current_bit
< BANG_OLUFSEN_COMPLETE_DATA_LEN
) // send n'th bit
1012 uint8_t cur_bit_value
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? 1 : 0;
1013 pulse_len
= BANG_OLUFSEN_PULSE_LEN
;
1015 if (cur_bit_value
== last_bit_value
)
1017 pause_len
= BANG_OLUFSEN_R_PAUSE_LEN
;
1021 pause_len
= cur_bit_value
? BANG_OLUFSEN_1_PAUSE_LEN
: BANG_OLUFSEN_0_PAUSE_LEN
;
1022 last_bit_value
= cur_bit_value
;
1028 if (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8))))
1030 pulse_len
= pulse_1_len
;
1031 pause_len
= pause_1_len
;
1035 pulse_len
= pulse_0_len
;
1036 pause_len
= pause_0_len
;
1039 else if (has_stop_bit
) // send stop bit
1041 pulse_len
= pulse_0_len
;
1043 if (auto_repetition_counter
< n_auto_repetitions
)
1045 pause_len
= pause_0_len
;
1049 pause_len
= 255; // last frame: pause of 255
1054 if (pulse_counter
< pulse_len
)
1056 if (pulse_counter
== 0)
1062 else if (pause_counter
< pause_len
)
1064 if (pause_counter
== 0)
1074 if (current_bit
>= complete_data_len
+ has_stop_bit
)
1077 auto_repetition_counter
++;
1079 if (auto_repetition_counter
== n_auto_repetitions
)
1082 auto_repetition_counter
= 0;
1094 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1095 case IRMP_RC5_PROTOCOL
:
1097 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1098 case IRMP_SIEMENS_PROTOCOL
:
1100 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1101 case IRMP_GRUNDIG_PROTOCOL
:
1103 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1104 case IRMP_NOKIA_PROTOCOL
:
1107 #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1109 if (pulse_counter
== pulse_len
&& pause_counter
== pause_len
)
1113 if (current_bit
>= complete_data_len
)
1117 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1118 if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
|| irsnd_protocol
== IRMP_NOKIA_PROTOCOL
)
1120 auto_repetition_counter
++;
1122 if (repeat_counter
> 0)
1123 { // set 117 msec pause time
1124 auto_repetition_pause_len
= GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN
;
1127 if (repeat_counter
< n_repeat_frames
) // tricky: repeat n info frames per auto repetition before sending last stop frame
1129 n_auto_repetitions
++; // increment number of auto repetitions
1132 else if (auto_repetition_counter
== n_auto_repetitions
)
1135 auto_repetition_counter
= 0;
1154 uint8_t first_pulse
;
1156 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1157 if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
|| irsnd_protocol
== IRMP_NOKIA_PROTOCOL
)
1159 if (current_bit
== 0xFF || // start bit of start-frame
1160 (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
&& current_bit
== 15) || // start bit of info-frame (Grundig)
1161 (irsnd_protocol
== IRMP_NOKIA_PROTOCOL
&& (current_bit
== 23 || current_bit
== 47))) // start bit of info- or stop-frame (Nokia)
1163 pulse_len
= startbit_pulse_len
;
1164 pause_len
= startbit_pause_len
;
1167 else // send n'th bit
1169 pulse_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
1170 pause_len
= GRUNDIG_OR_NOKIA_BIT_LEN
;
1171 first_pulse
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? TRUE
: FALSE
;
1174 else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_SIEMENS_PROTOCOL)
1177 if (current_bit
== 0xFF) // 1 start bit
1181 else // send n'th bit
1183 first_pulse
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? TRUE
: FALSE
;
1186 if (irsnd_protocol
== IRMP_RC5_PROTOCOL
)
1188 first_pulse
= first_pulse
? FALSE
: TRUE
;
1194 if (pulse_counter
< pulse_len
)
1196 if (pulse_counter
== 0)
1202 else // if (pause_counter < pause_len)
1204 if (pause_counter
== 0)
1213 if (pause_counter
< pause_len
)
1215 if (pause_counter
== 0)
1221 else // if (pulse_counter < pulse_len)
1223 if (pulse_counter
== 0)
1233 #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1245 if (repeat_counter
< n_repeat_frames
)
1252 n_repeat_frames
= 0;
1274 // main function - for unix/linux + windows only!
1276 // Compile it under linux with:
1277 // cc irsnd.c -o irsnd
1279 // usage: ./irsnd protocol hex-address hex-command >filename
1282 main (int argc
, char ** argv
)
1288 IRMP_DATA irmp_data
;
1290 if (argc
!= 4 && argc
!= 5)
1292 fprintf (stderr
, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv
[0]);
1296 if (sscanf (argv
[1], "%d", &protocol
) == 1 &&
1297 sscanf (argv
[2], "%x", &address
) == 1 &&
1298 sscanf (argv
[3], "%x", &command
) == 1)
1300 irmp_data
.protocol
= protocol
;
1301 irmp_data
.address
= address
;
1302 irmp_data
.command
= command
;
1306 irmp_data
.flags
= atoi (argv
[4]);
1310 irmp_data
.flags
= 0;
1315 (void) irsnd_send_data (&irmp_data
, TRUE
);
1321 for (idx
= 0; idx
< 20; idx
++)
1330 fprintf (stderr
, "%s: wrong arguments\n", argv
[0]);