]> cloudbase.mooo.com Git - irmp.git/blob - irsnd.c
version 2.0.0-pre2: added LEGO protocol
[irmp.git] / irsnd.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * @file irsnd.c
3 *
4 * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: irsnd.c,v 1.35 2011/04/11 13:26:17 fm Exp $
7 *
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 *---------------------------------------------------------------------------------------------------------------------------------------------------
13 */
14
15 #ifdef unix // test/debug on linux/unix
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <inttypes.h>
21
22 #define DEBUG
23 #define F_CPU 8000000L
24
25 #else // not unix:
26
27 #ifdef WIN32 // test/debug on windows
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #define F_CPU 8000000L
33 typedef unsigned char uint8_t;
34 typedef unsigned short uint16_t;
35 #define DEBUG
36
37 #else
38
39 #ifdef CODEVISION
40 #define COM2A0 6
41 #define WGM21 1
42 #define CS20 0
43 #else
44 #include <inttypes.h>
45 #include <avr/io.h>
46 #include <util/delay.h>
47 #include <avr/pgmspace.h>
48 #endif // CODEVISION
49
50 #endif // WIN32
51 #endif // unix
52
53 #include "irmp.h"
54 #include "irsndconfig.h"
55 #include "irsnd.h"
56
57 /*---------------------------------------------------------------------------------------------------------------------------------------------------
58 * ATmega pin definition of OC2 / OC2A / OC2B
59 *---------------------------------------------------------------------------------------------------------------------------------------------------
60 */
61 #if defined (__AVR_ATmega8__) // ATmega8 uses OC2 = PB3
62 #undef IRSND_OC2 // has no OC2A / OC2B
63 #define IRSND_OC2 0 // magic: use OC2
64 #define IRSND_PORT PORTB // port B
65 #define IRSND_DDR DDRB // ddr B
66 #define IRSND_BIT 3 // OC2A
67
68 #elif defined (__AVR_ATmega16__) \
69 || defined (__AVR_ATmega32__) // ATmega16|32 uses OC2 = PD7
70 #undef IRSND_OC2 // has no OC2A / OC2B
71 #define IRSND_OC2 0 // magic: use OC2
72 #define IRSND_PORT PORTD // port D
73 #define IRSND_DDR DDRD // ddr D
74 #define IRSND_BIT 7 // OC2
75
76 #elif defined (__AVR_ATmega162__) // ATmega162 uses OC2 = PB1
77 #undef IRSND_OC2 // has no OC2A / OC2B
78 #define IRSND_OC2 0 // magic: use OC2
79 #define IRSND_PORT PORTB // port B
80 #define IRSND_DDR DDRB // ddr B
81 #define IRSND_BIT 1 // OC2
82
83 #elif defined (__AVR_ATmega164__) \
84 || defined (__AVR_ATmega324__) \
85 || defined (__AVR_ATmega644__) \
86 || defined (__AVR_ATmega644P__) \
87 || defined (__AVR_ATmega1284__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6
88 #if IRSND_OC2 == 1 // OC2A
89 #define IRSND_PORT PORTD // port D
90 #define IRSND_DDR DDRD // ddr D
91 #define IRSND_BIT 7 // OC2A
92 #elif IRSND_OC2 == 2 // OC2B
93 #define IRSND_PORT PORTD // port D
94 #define IRSND_DDR DDRD // ddr D
95 #define IRSND_BIT 6 // OC2B
96 #else
97 #error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h
98 #endif // IRSND_OC2
99
100 #elif defined (__AVR_ATmega48__) \
101 || defined (__AVR_ATmega88__) \
102 || defined (__AVR_ATmega168__) \
103 || defined (__AVR_ATmega168__) \
104 || defined (__AVR_ATmega328__) \
105 || defined (__AVR_ATmega328P__) // ATmega48|88|168|328P uses OC2A = PB3 or OC2B = PD3
106 #if IRSND_OC2 == 1 // OC2A
107 #define IRSND_PORT PORTB // port B
108 #define IRSND_DDR DDRB // ddr B
109 #define IRSND_BIT 3 // OC2A
110 #elif IRSND_OC2 == 2 // OC2B
111 #define IRSND_PORT PORTD // port D
112 #define IRSND_DDR DDRD // ddr D
113 #define IRSND_BIT 3 // OC2B
114 #else
115 #error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h
116 #endif // IRSND_OC2
117
118 #else
119 #if !defined (unix) && !defined (WIN32)
120 #error OC2A/OC2B not defined, please fill in definitions here.
121 #endif // unix, WIN32
122 #endif // __AVR...
123
124 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
125 typedef uint16_t IRSND_PAUSE_LEN;
126 #else
127 typedef uint8_t IRSND_PAUSE_LEN;
128 #endif
129
130 /*---------------------------------------------------------------------------------------------------------------------------------------------------
131 * IR timings
132 *---------------------------------------------------------------------------------------------------------------------------------------------------
133 */
134 #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)
135 #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)
136 #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)
137 #define SIRCS_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME + 0.5)
138 #define SIRCS_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME + 0.5)
139 #define SIRCS_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
140 #define SIRCS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
141
142 #define NEC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME + 0.5)
143 #define NEC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME + 0.5)
144 #define NEC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
145 #define NEC_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME + 0.5)
146 #define NEC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME + 0.5)
147 #define NEC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME + 0.5)
148 #define NEC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
149
150 #define SAMSUNG_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME + 0.5)
151 #define SAMSUNG_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME + 0.5)
152 #define SAMSUNG_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME + 0.5)
153 #define SAMSUNG_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME + 0.5)
154 #define SAMSUNG_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME + 0.5)
155 #define SAMSUNG_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
156
157 #define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
158 #define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
159
160 #define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)
161 #define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)
162 #define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)
163 #define MATSUSHITA_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME + 0.5)
164 #define MATSUSHITA_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME + 0.5)
165 #define MATSUSHITA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * MATSUSHITA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
166
167 #define KASEIKYO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME + 0.5)
168 #define KASEIKYO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME + 0.5)
169 #define KASEIKYO_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME + 0.5)
170 #define KASEIKYO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME + 0.5)
171 #define KASEIKYO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME + 0.5)
172 #define KASEIKYO_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
173 #define KASEIKYO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
174
175 #define RECS80_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME + 0.5)
176 #define RECS80_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME + 0.5)
177 #define RECS80_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME + 0.5)
178 #define RECS80_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME + 0.5)
179 #define RECS80_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME + 0.5)
180 #define RECS80_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
181
182 #define RC5_START_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
183 #define RC5_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
184 #define RC5_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC5_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
185
186 #define RC6_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME + 0.5)
187 #define RC6_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME + 0.5)
188 #define RC6_TOGGLE_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME + 0.5)
189 #define RC6_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_BIT_TIME + 0.5)
190 #define RC6_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC6_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
191
192 #define DENON_PULSE_LEN (uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME + 0.5)
193 #define DENON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME + 0.5)
194 #define DENON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME + 0.5)
195 #define DENON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
196 #define DENON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
197
198 #define RECS80EXT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME + 0.5)
199 #define RECS80EXT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME + 0.5)
200 #define RECS80EXT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME + 0.5)
201 #define RECS80EXT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME + 0.5)
202 #define RECS80EXT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME + 0.5)
203 #define RECS80EXT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80EXT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
204
205 #define NUBERT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME + 0.5)
206 #define NUBERT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME + 0.5)
207 #define NUBERT_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME + 0.5)
208 #define NUBERT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME + 0.5)
209 #define NUBERT_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME + 0.5)
210 #define NUBERT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME + 0.5)
211 #define NUBERT_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
212 #define NUBERT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
213
214 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME + 0.5)
215 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME + 0.5)
216 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME + 0.5)
217 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME + 0.5)
218 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME + 0.5)
219 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME + 0.5)
220 #define BANG_OLUFSEN_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME + 0.5)
221 #define BANG_OLUFSEN_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME + 0.5)
222 #define BANG_OLUFSEN_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME + 0.5)
223 #define BANG_OLUFSEN_R_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME + 0.5)
224 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)
225 #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
226
227 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5)
228 #define GRUNDIG_NOKIA_IR60_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5)
229 #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
230 #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
231 #define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
232
233 #define SIEMENS_START_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME + 0.5)
234 #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5)
235 #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
236
237 #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1)
238 #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1)
239 #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1)
240 #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1)
241 #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1)
242 #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1)
243
244 #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)
245 #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)
246 #define FDC_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)
247 #define FDC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)
248 #define FDC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)
249 #define FDC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
250
251 #define RCCAR_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME + 0.5)
252 #define RCCAR_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME + 0.5)
253 #define RCCAR_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME + 0.5)
254 #define RCCAR_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME + 0.5)
255 #define RCCAR_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME + 0.5)
256 #define RCCAR_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RCCAR_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
257
258 #define JVC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME + 0.5)
259 #define JVC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PAUSE_TIME + 0.5)
260 #define JVC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
261 #define JVC_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME + 0.5)
262 #define JVC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME + 0.5)
263 #define JVC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME + 0.5)
264 #define JVC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
265
266 #define NIKON_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME + 0.5)
267 #define NIKON_START_BIT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME + 0.5)
268 #define NIKON_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME + 0.5)
269 #define NIKON_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME + 0.5)
270 #define NIKON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME + 0.5)
271 #define NIKON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME + 0.5)
272 #define NIKON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
273
274 #define LEGO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME + 0.5)
275 #define LEGO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME + 0.5)
276 #define LEGO_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_REPEAT_START_BIT_PAUSE_TIME + 0.5)
277 #define LEGO_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME + 0.5)
278 #define LEGO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME + 0.5)
279 #define LEGO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5)
280 #define LEGO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
281
282 static volatile uint8_t irsnd_busy;
283 static volatile uint8_t irsnd_protocol;
284 static volatile uint8_t irsnd_buffer[6];
285 static volatile uint8_t irsnd_repeat;
286 static volatile uint8_t irsnd_is_on = FALSE;
287
288 #if IRSND_USE_CALLBACK == 1
289 static void (*irsnd_callback_ptr) (uint8_t);
290 #endif // IRSND_USE_CALLBACK == 1
291
292 /*---------------------------------------------------------------------------------------------------------------------------------------------------
293 * Switch PWM on
294 * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing
295 *---------------------------------------------------------------------------------------------------------------------------------------------------
296 */
297 static void
298 irsnd_on (void)
299 {
300 if (! irsnd_is_on)
301 {
302 #ifndef DEBUG
303 #if IRSND_OC2 == 0 // use OC2
304 TCCR2 |= (1<<COM20)|(1<<WGM21); // toggle OC2 on compare match, clear Timer 2 at compare match OCR2
305 #elif IRSND_OC2 == 1 // use OC2A
306 TCCR2A |= (1<<COM2A0)|(1<<WGM21); // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A
307 #else // use OC2B
308 TCCR2A |= (1<<COM2B0)|(1<<WGM21); // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)
309 #endif // IRSND_OC2
310 #endif // DEBUG
311
312 #if IRSND_USE_CALLBACK == 1
313 if (irsnd_callback_ptr)
314 {
315 (*irsnd_callback_ptr) (TRUE);
316 }
317 #endif // IRSND_USE_CALLBACK == 1
318
319 irsnd_is_on = TRUE;
320 }
321 }
322
323 /*---------------------------------------------------------------------------------------------------------------------------------------------------
324 * Switch PWM off
325 * @details Switches PWM off
326 *---------------------------------------------------------------------------------------------------------------------------------------------------
327 */
328 static void
329 irsnd_off (void)
330 {
331 if (irsnd_is_on)
332 {
333 #ifndef DEBUG
334 #if IRSND_OC2 == 0 // use OC2
335 TCCR2 &= ~(1<<COM20); // normal port operation, OC2 disconnected.
336 #elif IRSND_OC2 == 1 // use OC2A
337 TCCR2A &= ~(1<<COM2A0); // normal port operation, OC2A disconnected.
338 #else // use OC2B
339 TCCR2A &= ~(1<<COM2B0); // normal port operation, OC2B disconnected.
340 #endif // IRSND_OC2
341 IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low
342 #endif // DEBUG
343
344 #if IRSND_USE_CALLBACK == 1
345 if (irsnd_callback_ptr)
346 {
347 (*irsnd_callback_ptr) (FALSE);
348 }
349 #endif // IRSND_USE_CALLBACK == 1
350
351 irsnd_is_on = FALSE;
352 }
353 }
354
355 /*---------------------------------------------------------------------------------------------------------------------------------------------------
356 * Set PWM frequency
357 * @details sets pwm frequency
358 *---------------------------------------------------------------------------------------------------------------------------------------------------
359 */
360 static void
361 irsnd_set_freq (uint8_t freq)
362 {
363 #ifndef DEBUG
364 #if IRSND_OC2 == 0
365 OCR2 = freq; // use register OCR2 for OC2
366 #else
367 OCR2A = freq; // use register OCR2A for OC2A and OC2B!
368 #endif
369 #endif // DEBUG
370 }
371
372 /*---------------------------------------------------------------------------------------------------------------------------------------------------
373 * Initialize the PWM
374 * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels
375 *---------------------------------------------------------------------------------------------------------------------------------------------------
376 */
377 void
378 irsnd_init (void)
379 {
380 #ifndef DEBUG
381 IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low
382 IRSND_DDR |= (1<<IRSND_BIT); // set IRSND_BIT to output
383
384 #if defined (__AVR_ATmega32__)
385 TCCR2 = (1<<WGM21); // CTC mode
386 TCCR2 |= (1<<CS20); // 0x01, start Timer 2, no prescaling
387 #else
388 TCCR2A = (1<<WGM21); // CTC mode
389 TCCR2B |= (1<<CS20); // 0x01, start Timer 2, no prescaling
390 #endif // __AVR...
391
392 irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency
393 #endif // DEBUG
394 }
395
396 #if IRSND_USE_CALLBACK == 1
397 void
398 irsnd_set_callback_ptr (void (*cb)(uint8_t))
399 {
400 irsnd_callback_ptr = cb;
401 }
402 #endif // IRSND_USE_CALLBACK == 1
403
404 uint8_t
405 irsnd_is_busy (void)
406 {
407 return irsnd_busy;
408 }
409
410 static uint16_t
411 bitsrevervse (uint16_t x, uint8_t len)
412 {
413 uint16_t xx = 0;
414
415 while(len)
416 {
417 xx <<= 1;
418 if (x & 1)
419 {
420 xx |= 1;
421 }
422 x >>= 1;
423 len--;
424 }
425 return xx;
426 }
427
428
429 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
430 static uint8_t sircs_additional_bitlen;
431 #endif // IRSND_SUPPORT_SIRCS_PROTOCOL == 1
432
433 uint8_t
434 irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)
435 {
436 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
437 static uint8_t toggle_bit_recs80;
438 #endif
439 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
440 static uint8_t toggle_bit_recs80ext;
441 #endif
442 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
443 static uint8_t toggle_bit_rc5;
444 #endif
445 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
446 static uint8_t toggle_bit_rc6;
447 #endif
448 uint16_t address;
449 uint16_t command;
450
451 if (do_wait)
452 {
453 while (irsnd_busy)
454 {
455 // do nothing;
456 }
457 }
458 else if (irsnd_busy)
459 {
460 return (FALSE);
461 }
462
463 irsnd_protocol = irmp_data_p->protocol;
464 irsnd_repeat = irmp_data_p->flags;
465
466 switch (irsnd_protocol)
467 {
468 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
469 case IRMP_SIRCS_PROTOCOL:
470 {
471 uint8_t sircs_additional_command_len;
472 uint8_t sircs_additional_address_len;
473
474 sircs_additional_bitlen = (irmp_data_p->address & 0xFF00) >> 8; // additional bitlen
475
476 if (sircs_additional_bitlen > 15 - SIRCS_MINIMUM_DATA_LEN)
477 {
478 sircs_additional_command_len = 15 - SIRCS_MINIMUM_DATA_LEN;
479 sircs_additional_address_len = sircs_additional_bitlen - (15 - SIRCS_MINIMUM_DATA_LEN);
480 }
481 else
482 {
483 sircs_additional_command_len = sircs_additional_bitlen;
484 sircs_additional_address_len = 0;
485 }
486
487 command = bitsrevervse (irmp_data_p->command, 15);
488
489 irsnd_buffer[0] = (command & 0x7F80) >> 7; // CCCCCCCC
490 irsnd_buffer[1] = (command & 0x007F) << 1; // CCCC****
491
492 if (sircs_additional_address_len > 0)
493 {
494 address = bitsrevervse (irmp_data_p->address, 5);
495 irsnd_buffer[1] |= (address & 0x0010) >> 4;
496 irsnd_buffer[2] = (address & 0x000F) << 4;
497 }
498 irsnd_busy = TRUE;
499 break;
500 }
501 #endif
502 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
503 case IRMP_APPLE_PROTOCOL:
504 {
505 command = irmp_data_p->command | (irmp_data_p->address << 8); // store address as ID in upper byte of command
506 address = 0x87EE; // set fixed NEC-lookalike address (customer ID of apple)
507
508 address = bitsrevervse (address, NEC_ADDRESS_LEN);
509 command = bitsrevervse (command, NEC_COMMAND_LEN);
510
511 irsnd_protocol = IRMP_NEC_PROTOCOL; // APPLE protocol is NEC with id instead of inverted command
512
513 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
514 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
515 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
516 irsnd_buffer[3] = (command & 0x00FF); // CCCCCCCC
517
518 irsnd_busy = TRUE;
519 break;
520 }
521 case IRMP_NEC_PROTOCOL:
522 {
523 address = bitsrevervse (irmp_data_p->address, NEC_ADDRESS_LEN);
524 command = bitsrevervse (irmp_data_p->command, NEC_COMMAND_LEN);
525
526 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
527 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
528 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
529
530 irsnd_protocol = IRMP_NEC_PROTOCOL; // APPLE protocol is NEC with fix bitmask instead of inverted command
531 irsnd_buffer[3] = 0x8B; // 10001011
532 {
533 irsnd_buffer[3] = ~((command & 0xFF00) >> 8); // cccccccc
534 }
535
536 irsnd_busy = TRUE;
537 break;
538 }
539 #endif
540 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
541 case IRMP_SAMSUNG_PROTOCOL:
542 {
543 address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);
544 command = bitsrevervse (irmp_data_p->command, SAMSUNG_COMMAND_LEN);
545
546 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
547 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
548 irsnd_buffer[2] = (command & 0x00F0) | ((command & 0xF000) >> 12); // IIIICCCC
549 irsnd_buffer[3] = ((command & 0x0F00) >> 4) | ((~(command & 0xF000) >> 12) & 0x0F); // CCCCcccc
550 irsnd_buffer[4] = (~(command & 0x0F00) >> 4) & 0xF0; // cccc0000
551 irsnd_busy = TRUE;
552 break;
553 }
554 case IRMP_SAMSUNG32_PROTOCOL:
555 {
556 address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);
557 command = bitsrevervse (irmp_data_p->command, SAMSUNG32_COMMAND_LEN);
558
559 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
560 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
561 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
562 irsnd_buffer[3] = (command & 0x00FF); // CCCCCCCC
563 irsnd_busy = TRUE;
564 break;
565 }
566 #endif
567 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
568 case IRMP_MATSUSHITA_PROTOCOL:
569 {
570 address = bitsrevervse (irmp_data_p->address, MATSUSHITA_ADDRESS_LEN);
571 command = bitsrevervse (irmp_data_p->command, MATSUSHITA_COMMAND_LEN);
572
573 irsnd_buffer[0] = (command & 0x0FF0) >> 4; // CCCCCCCC
574 irsnd_buffer[1] = ((command & 0x000F) << 4) | ((address & 0x0F00) >> 8); // CCCCAAAA
575 irsnd_buffer[2] = (address & 0x00FF); // AAAAAAAA
576 irsnd_busy = TRUE;
577 break;
578 }
579 #endif
580 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
581 case IRMP_KASEIKYO_PROTOCOL:
582 {
583 uint8_t xor;
584
585 address = bitsrevervse (irmp_data_p->address, KASEIKYO_ADDRESS_LEN);
586 command = bitsrevervse (irmp_data_p->command, KASEIKYO_COMMAND_LEN + 4);
587
588 xor = ((address & 0x000F) ^ ((address & 0x00F0) >> 4) ^ ((address & 0x0F00) >> 8) ^ ((address & 0xF000) >> 12)) & 0x0F;
589
590 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
591 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
592 irsnd_buffer[2] = xor << 4 | (command & 0x000F); // XXXXCCCC
593 irsnd_buffer[3] = 0 | (command & 0xF000) >> 12; // 0000CCCC
594 irsnd_buffer[4] = (command & 0x0FF0) >> 4; // CCCCCCCC
595
596 xor = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4];
597
598 irsnd_buffer[5] = xor;
599 irsnd_busy = TRUE;
600 break;
601 }
602 #endif
603 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
604 case IRMP_RECS80_PROTOCOL:
605 {
606 toggle_bit_recs80 = toggle_bit_recs80 ? 0x00 : 0x40;
607
608 irsnd_buffer[0] = 0x80 | toggle_bit_recs80 | ((irmp_data_p->address & 0x0007) << 3) |
609 ((irmp_data_p->command & 0x0038) >> 3); // STAAACCC
610 irsnd_buffer[1] = (irmp_data_p->command & 0x07) << 5; // CCC00000
611 irsnd_busy = TRUE;
612 break;
613 }
614 #endif
615 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
616 case IRMP_RECS80EXT_PROTOCOL:
617 {
618 toggle_bit_recs80ext = toggle_bit_recs80ext ? 0x00 : 0x40;
619
620 irsnd_buffer[0] = 0x80 | toggle_bit_recs80ext | ((irmp_data_p->address & 0x000F) << 2) |
621 ((irmp_data_p->command & 0x0030) >> 4); // STAAAACC
622 irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4; // CCCC0000
623 irsnd_busy = TRUE;
624 break;
625 }
626 #endif
627 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
628 case IRMP_RC5_PROTOCOL:
629 {
630 toggle_bit_rc5 = toggle_bit_rc5 ? 0x00 : 0x40;
631
632 irsnd_buffer[0] = ((irmp_data_p->command & 0x40) ? 0x00 : 0x80) | toggle_bit_rc5 |
633 ((irmp_data_p->address & 0x001F) << 1) | ((irmp_data_p->command & 0x20) >> 5); // CTAAAAAC
634 irsnd_buffer[1] = (irmp_data_p->command & 0x1F) << 3; // CCCCC000
635 irsnd_busy = TRUE;
636 break;
637 }
638 #endif
639 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
640 case IRMP_RC6_PROTOCOL:
641 {
642 toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;
643
644 irsnd_buffer[0] = 0x80 | toggle_bit_rc6 | ((irmp_data_p->address & 0x00E0) >> 5); // 1MMMTAAA, MMM = 000
645 irsnd_buffer[1] = ((irmp_data_p->address & 0x001F) << 3) | ((irmp_data_p->command & 0xE0) >> 5); // AAAAACCC
646 irsnd_buffer[2] = (irmp_data_p->command & 0x1F) << 3; // CCCCC
647 irsnd_busy = TRUE;
648 break;
649 }
650 #endif
651 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
652 case IRMP_RC6A_PROTOCOL:
653 {
654 toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;
655
656 irsnd_buffer[0] = 0x80 | 0x60 | ((irmp_data_p->address & 0x3000) >> 12); // 1MMMT0AA, MMM = 110
657 irsnd_buffer[1] = ((irmp_data_p->address & 0x0FFF) >> 4) ; // AAAAAAAA
658 irsnd_buffer[2] = ((irmp_data_p->address & 0x000F) << 4) | ((irmp_data_p->command & 0xF000) >> 12) | toggle_bit_rc6; // AAAACCCC
659 irsnd_buffer[3] = (irmp_data_p->command & 0x0FF0) >> 4; // CCCCCCCC
660 irsnd_buffer[4] = (irmp_data_p->command & 0x000F) << 4; // CCCC
661 irsnd_busy = TRUE;
662 break;
663 }
664 #endif
665 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
666 case IRMP_DENON_PROTOCOL:
667 {
668 irsnd_buffer[0] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x0380) >> 7); // AAAAACCC (1st frame)
669 irsnd_buffer[1] = (irmp_data_p->command & 0x7F) << 1; // CCCCCCC
670 irsnd_buffer[2] = ((irmp_data_p->address & 0x1F) << 3) | (((~irmp_data_p->command) & 0x0380) >> 7); // AAAAACCC (2nd frame)
671 irsnd_buffer[3] = (~(irmp_data_p->command) & 0x7F) << 1; // CCCCCCC
672 irsnd_busy = TRUE;
673 break;
674 }
675 #endif
676 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
677 case IRMP_NUBERT_PROTOCOL:
678 {
679 irsnd_buffer[0] = irmp_data_p->command >> 2; // CCCCCCCC
680 irsnd_buffer[1] = (irmp_data_p->command & 0x0003) << 6; // CC000000
681 irsnd_busy = TRUE;
682 break;
683 }
684 #endif
685 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
686 case IRMP_BANG_OLUFSEN_PROTOCOL:
687 {
688 irsnd_buffer[0] = irmp_data_p->command >> 11; // SXSCCCCC
689 irsnd_buffer[1] = irmp_data_p->command >> 3; // CCCCCCCC
690 irsnd_buffer[2] = (irmp_data_p->command & 0x0007) << 5; // CCC00000
691 irsnd_busy = TRUE;
692 break;
693 }
694 #endif
695 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
696 case IRMP_GRUNDIG_PROTOCOL:
697 {
698 command = bitsrevervse (irmp_data_p->command, GRUNDIG_COMMAND_LEN);
699
700 irsnd_buffer[0] = 0xFF; // S1111111 (1st frame)
701 irsnd_buffer[1] = 0xC0; // 11
702 irsnd_buffer[2] = 0x80 | (command >> 2); // SCCCCCCC (2nd frame)
703 irsnd_buffer[3] = (command << 6) & 0xC0; // CC
704
705 irsnd_busy = TRUE;
706 break;
707 }
708 #endif
709 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
710 case IRMP_NOKIA_PROTOCOL:
711 {
712 address = bitsrevervse (irmp_data_p->address, NOKIA_ADDRESS_LEN);
713 command = bitsrevervse (irmp_data_p->command, NOKIA_COMMAND_LEN);
714
715 irsnd_buffer[0] = 0xBF; // S0111111 (1st + 3rd frame)
716 irsnd_buffer[1] = 0xFF; // 11111111
717 irsnd_buffer[2] = 0x80; // 1
718 irsnd_buffer[3] = 0x80 | command >> 1; // SCCCCCCC (2nd frame)
719 irsnd_buffer[4] = (command << 7) | (address >> 1); // CAAAAAAA
720 irsnd_buffer[5] = (address << 7); // A
721
722 irsnd_busy = TRUE;
723 break;
724 }
725 #endif
726 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
727 case IRMP_SIEMENS_PROTOCOL:
728 {
729 irsnd_buffer[0] = ((irmp_data_p->address & 0x0FFF) >> 5); // SAAAAAAA
730 irsnd_buffer[1] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x7F) >> 5); // AAAAA0CC
731 irsnd_buffer[2] = (irmp_data_p->command << 3) | ((~irmp_data_p->command & 0x01) << 2); // CCCCCc
732
733 irsnd_busy = TRUE;
734 break;
735 }
736 #endif
737 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
738 case IRMP_FDC_PROTOCOL:
739 {
740 address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);
741 command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);
742
743 irsnd_buffer[0] = (address & 0xFF); // AAAAAAAA
744 irsnd_buffer[1] = 0; // 00000000
745 irsnd_buffer[2] = 0; // 0000RRRR
746 irsnd_buffer[3] = (command & 0xFF); // CCCCCCCC
747 irsnd_buffer[4] = ~(command & 0xFF); // cccccccc
748 irsnd_busy = TRUE;
749 break;
750 }
751 #endif
752 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
753 case IRMP_RCCAR_PROTOCOL:
754 {
755 address = bitsrevervse (irmp_data_p->address, 2); // A0 A1
756 command = bitsrevervse (irmp_data_p->command, RCCAR_COMMAND_LEN - 2); // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V
757
758 irsnd_buffer[0] = ((command & 0x06) << 5) | ((address & 0x0003) << 4) | ((command & 0x0780) >> 7); // C0 C1 A0 A1 D0 D1 D2 D3
759 irsnd_buffer[1] = ((command & 0x78) << 1) | ((command & 0x0001) << 3); // D4 D5 D6 D7 V 0 0 0
760
761 irsnd_busy = TRUE;
762 break;
763 }
764 #endif
765 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
766 case IRMP_JVC_PROTOCOL:
767 {
768 address = bitsrevervse (irmp_data_p->address, JVC_ADDRESS_LEN);
769 command = bitsrevervse (irmp_data_p->command, JVC_COMMAND_LEN);
770
771 irsnd_buffer[0] = ((address & 0x000F) << 4) | (command & 0x0F00) >> 8; // AAAACCCC
772 irsnd_buffer[1] = (command & 0x00FF); // CCCCCCCC
773
774 irsnd_busy = TRUE;
775 break;
776 }
777 #endif
778 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
779 case IRMP_NIKON_PROTOCOL:
780 {
781 irsnd_buffer[0] = (irmp_data_p->command & 0x0003) << 6; // CC
782 irsnd_busy = TRUE;
783 break;
784 }
785 #endif
786 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
787 case IRMP_LEGO_PROTOCOL:
788 {
789 uint8_t crc = 0x0F ^ ((irmp_data_p->command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F);
790
791 irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4; // CCCCCCCC
792 irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc; // CCCCcccc
793
794 irsnd_protocol = IRMP_LEGO_PROTOCOL;
795 irsnd_busy = TRUE;
796 break;
797 }
798 #endif
799 default:
800 {
801 break;
802 }
803 }
804
805 return irsnd_busy;
806 }
807
808 /*---------------------------------------------------------------------------------------------------------------------------------------------------
809 * ISR routine
810 * @details ISR routine, called 10000 times per second
811 *---------------------------------------------------------------------------------------------------------------------------------------------------
812 */
813 uint8_t
814 irsnd_ISR (void)
815 {
816 static uint8_t current_bit = 0xFF;
817 static uint8_t pulse_counter;
818 static IRSND_PAUSE_LEN pause_counter;
819 static uint8_t startbit_pulse_len;
820 static IRSND_PAUSE_LEN startbit_pause_len;
821 static uint8_t pulse_1_len;
822 static uint8_t pause_1_len;
823 static uint8_t pulse_0_len;
824 static uint8_t pause_0_len;
825 static uint8_t has_stop_bit;
826 static uint8_t new_frame = TRUE;
827 static uint8_t complete_data_len;
828 static uint8_t n_auto_repetitions; // number of auto_repetitions
829 static uint8_t auto_repetition_counter; // auto_repetition counter
830 static uint16_t auto_repetition_pause_len; // pause before auto_repetition, uint16_t!
831 static uint16_t auto_repetition_pause_counter; // pause before auto_repetition, uint16_t!
832 static uint8_t n_repeat_frames; // number of repeat frames
833 static uint8_t repeat_counter; // repeat counter
834 static uint16_t repeat_frame_pause_len; // pause before repeat, uint16_t!
835 static uint16_t packet_repeat_pause_counter; // pause before repeat, uint16_t!
836 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
837 static uint8_t last_bit_value;
838 #endif
839 static uint8_t pulse_len = 0xFF;
840 static IRSND_PAUSE_LEN pause_len = 0xFF;
841
842 if (irsnd_busy)
843 {
844 if (current_bit == 0xFF && new_frame) // start of transmission...
845 {
846 if (auto_repetition_counter > 0)
847 {
848 auto_repetition_pause_counter++;
849
850 if (auto_repetition_pause_counter >= auto_repetition_pause_len)
851 {
852 auto_repetition_pause_counter = 0;
853
854 if (irsnd_protocol == IRMP_DENON_PROTOCOL)
855 {
856 current_bit = 16;
857 complete_data_len = 2 * DENON_COMPLETE_DATA_LEN + 1;
858 }
859 else if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL) // n'th grundig info frame
860 {
861 current_bit = 15;
862 complete_data_len = 16 + GRUNDIG_COMPLETE_DATA_LEN;
863 }
864 else if (irsnd_protocol == IRMP_NOKIA_PROTOCOL) // n'th nokia info frame
865 {
866 if (auto_repetition_counter + 1 < n_auto_repetitions)
867 {
868 current_bit = 23;
869 complete_data_len = 24 + NOKIA_COMPLETE_DATA_LEN;
870 }
871 else // nokia stop frame
872 {
873 current_bit = 0xFF;
874 complete_data_len = NOKIA_COMPLETE_DATA_LEN;
875 }
876 }
877 }
878 else
879 {
880 #ifdef DEBUG
881 if (irsnd_is_on)
882 {
883 putchar ('0');
884 }
885 else
886 {
887 putchar ('1');
888 }
889 #endif
890 return irsnd_busy;
891 }
892 }
893 else if (repeat_counter > 0 && packet_repeat_pause_counter < repeat_frame_pause_len)
894 {
895 packet_repeat_pause_counter++;
896
897 #ifdef DEBUG
898 if (irsnd_is_on)
899 {
900 putchar ('0');
901 }
902 else
903 {
904 putchar ('1');
905 }
906 #endif
907 return irsnd_busy;
908 }
909 else
910 {
911 n_repeat_frames = irsnd_repeat;
912 packet_repeat_pause_counter = 0;
913 pulse_counter = 0;
914 pause_counter = 0;
915
916 switch (irsnd_protocol)
917 {
918 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
919 case IRMP_SIRCS_PROTOCOL:
920 {
921 startbit_pulse_len = SIRCS_START_BIT_PULSE_LEN;
922 startbit_pause_len = SIRCS_START_BIT_PAUSE_LEN - 1;
923 pulse_1_len = SIRCS_1_PULSE_LEN;
924 pause_1_len = SIRCS_PAUSE_LEN - 1;
925 pulse_0_len = SIRCS_0_PULSE_LEN;
926 pause_0_len = SIRCS_PAUSE_LEN - 1;
927 has_stop_bit = SIRCS_STOP_BIT;
928 complete_data_len = SIRCS_MINIMUM_DATA_LEN + sircs_additional_bitlen;
929 n_auto_repetitions = (repeat_counter == 0) ? SIRCS_FRAMES : 1; // 3 frames auto repetition if first frame
930 auto_repetition_pause_len = SIRCS_AUTO_REPETITION_PAUSE_LEN; // 25ms pause
931 repeat_frame_pause_len = SIRCS_FRAME_REPEAT_PAUSE_LEN;
932 irsnd_set_freq (IRSND_FREQ_40_KHZ);
933 break;
934 }
935 #endif
936 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
937 case IRMP_NEC_PROTOCOL:
938 {
939 startbit_pulse_len = NEC_START_BIT_PULSE_LEN;
940
941 if (repeat_counter > 0)
942 {
943 startbit_pause_len = NEC_REPEAT_START_BIT_PAUSE_LEN - 1;
944 complete_data_len = 0;
945 }
946 else
947 {
948 startbit_pause_len = NEC_START_BIT_PAUSE_LEN - 1;
949 complete_data_len = NEC_COMPLETE_DATA_LEN;
950 }
951
952 pulse_1_len = NEC_PULSE_LEN;
953 pause_1_len = NEC_1_PAUSE_LEN - 1;
954 pulse_0_len = NEC_PULSE_LEN;
955 pause_0_len = NEC_0_PAUSE_LEN - 1;
956 has_stop_bit = NEC_STOP_BIT;
957 n_auto_repetitions = 1; // 1 frame
958 auto_repetition_pause_len = 0;
959 repeat_frame_pause_len = NEC_FRAME_REPEAT_PAUSE_LEN;
960 irsnd_set_freq (IRSND_FREQ_38_KHZ);
961 break;
962 }
963 #endif
964 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
965 case IRMP_SAMSUNG_PROTOCOL:
966 {
967 startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;
968 startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
969 pulse_1_len = SAMSUNG_PULSE_LEN;
970 pause_1_len = SAMSUNG_1_PAUSE_LEN - 1;
971 pulse_0_len = SAMSUNG_PULSE_LEN;
972 pause_0_len = SAMSUNG_0_PAUSE_LEN - 1;
973 has_stop_bit = SAMSUNG_STOP_BIT;
974 complete_data_len = SAMSUNG_COMPLETE_DATA_LEN;
975 n_auto_repetitions = 1; // 1 frame
976 auto_repetition_pause_len = 0;
977 repeat_frame_pause_len = SAMSUNG_FRAME_REPEAT_PAUSE_LEN;
978 irsnd_set_freq (IRSND_FREQ_38_KHZ);
979 break;
980 }
981
982 case IRMP_SAMSUNG32_PROTOCOL:
983 {
984 startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;
985 startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
986 pulse_1_len = SAMSUNG_PULSE_LEN;
987 pause_1_len = SAMSUNG_1_PAUSE_LEN - 1;
988 pulse_0_len = SAMSUNG_PULSE_LEN;
989 pause_0_len = SAMSUNG_0_PAUSE_LEN - 1;
990 has_stop_bit = SAMSUNG_STOP_BIT;
991 complete_data_len = SAMSUNG32_COMPLETE_DATA_LEN;
992 n_auto_repetitions = SAMSUNG32_FRAMES; // 2 frames
993 auto_repetition_pause_len = SAMSUNG32_AUTO_REPETITION_PAUSE_LEN; // 47 ms pause
994 repeat_frame_pause_len = SAMSUNG32_FRAME_REPEAT_PAUSE_LEN;
995 irsnd_set_freq (IRSND_FREQ_38_KHZ);
996 break;
997 }
998 #endif
999 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1000 case IRMP_MATSUSHITA_PROTOCOL:
1001 {
1002 startbit_pulse_len = MATSUSHITA_START_BIT_PULSE_LEN;
1003 startbit_pause_len = MATSUSHITA_START_BIT_PAUSE_LEN - 1;
1004 pulse_1_len = MATSUSHITA_PULSE_LEN;
1005 pause_1_len = MATSUSHITA_1_PAUSE_LEN - 1;
1006 pulse_0_len = MATSUSHITA_PULSE_LEN;
1007 pause_0_len = MATSUSHITA_0_PAUSE_LEN - 1;
1008 has_stop_bit = MATSUSHITA_STOP_BIT;
1009 complete_data_len = MATSUSHITA_COMPLETE_DATA_LEN;
1010 n_auto_repetitions = 1; // 1 frame
1011 auto_repetition_pause_len = 0;
1012 repeat_frame_pause_len = MATSUSHITA_FRAME_REPEAT_PAUSE_LEN;
1013 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1014 break;
1015 }
1016 #endif
1017 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1018 case IRMP_KASEIKYO_PROTOCOL:
1019 {
1020 startbit_pulse_len = KASEIKYO_START_BIT_PULSE_LEN;
1021 startbit_pause_len = KASEIKYO_START_BIT_PAUSE_LEN - 1;
1022 pulse_1_len = KASEIKYO_PULSE_LEN;
1023 pause_1_len = KASEIKYO_1_PAUSE_LEN - 1;
1024 pulse_0_len = KASEIKYO_PULSE_LEN;
1025 pause_0_len = KASEIKYO_0_PAUSE_LEN - 1;
1026 has_stop_bit = KASEIKYO_STOP_BIT;
1027 complete_data_len = KASEIKYO_COMPLETE_DATA_LEN;
1028 n_auto_repetitions = (repeat_counter == 0) ? KASEIKYO_FRAMES : 1; // 2 frames auto repetition if first frame
1029 auto_repetition_pause_len = KASEIKYO_AUTO_REPETITION_PAUSE_LEN; // 75 ms pause
1030 repeat_frame_pause_len = KASEIKYO_FRAME_REPEAT_PAUSE_LEN;
1031 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1032 break;
1033 }
1034 #endif
1035 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1036 case IRMP_RECS80_PROTOCOL:
1037 {
1038 startbit_pulse_len = RECS80_START_BIT_PULSE_LEN;
1039 startbit_pause_len = RECS80_START_BIT_PAUSE_LEN - 1;
1040 pulse_1_len = RECS80_PULSE_LEN;
1041 pause_1_len = RECS80_1_PAUSE_LEN - 1;
1042 pulse_0_len = RECS80_PULSE_LEN;
1043 pause_0_len = RECS80_0_PAUSE_LEN - 1;
1044 has_stop_bit = RECS80_STOP_BIT;
1045 complete_data_len = RECS80_COMPLETE_DATA_LEN;
1046 n_auto_repetitions = 1; // 1 frame
1047 auto_repetition_pause_len = 0;
1048 repeat_frame_pause_len = RECS80_FRAME_REPEAT_PAUSE_LEN;
1049 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1050 break;
1051 }
1052 #endif
1053 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1054 case IRMP_RECS80EXT_PROTOCOL:
1055 {
1056 startbit_pulse_len = RECS80EXT_START_BIT_PULSE_LEN;
1057 startbit_pause_len = RECS80EXT_START_BIT_PAUSE_LEN - 1;
1058 pulse_1_len = RECS80EXT_PULSE_LEN;
1059 pause_1_len = RECS80EXT_1_PAUSE_LEN - 1;
1060 pulse_0_len = RECS80EXT_PULSE_LEN;
1061 pause_0_len = RECS80EXT_0_PAUSE_LEN - 1;
1062 has_stop_bit = RECS80EXT_STOP_BIT;
1063 complete_data_len = RECS80EXT_COMPLETE_DATA_LEN;
1064 n_auto_repetitions = 1; // 1 frame
1065 auto_repetition_pause_len = 0;
1066 repeat_frame_pause_len = RECS80EXT_FRAME_REPEAT_PAUSE_LEN;
1067 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1068 break;
1069 }
1070 #endif
1071 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1072 case IRMP_RC5_PROTOCOL:
1073 {
1074 startbit_pulse_len = RC5_BIT_LEN;
1075 startbit_pause_len = RC5_BIT_LEN;
1076 pulse_len = RC5_BIT_LEN;
1077 pause_len = RC5_BIT_LEN;
1078 has_stop_bit = RC5_STOP_BIT;
1079 complete_data_len = RC5_COMPLETE_DATA_LEN;
1080 n_auto_repetitions = 1; // 1 frame
1081 auto_repetition_pause_len = 0;
1082 repeat_frame_pause_len = RC5_FRAME_REPEAT_PAUSE_LEN;
1083 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1084 break;
1085 }
1086 #endif
1087 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1088 case IRMP_RC6_PROTOCOL:
1089 {
1090 startbit_pulse_len = RC6_START_BIT_PULSE_LEN;
1091 startbit_pause_len = RC6_START_BIT_PAUSE_LEN - 1;
1092 pulse_len = RC6_BIT_LEN;
1093 pause_len = RC6_BIT_LEN;
1094 has_stop_bit = RC6_STOP_BIT;
1095 complete_data_len = RC6_COMPLETE_DATA_LEN_SHORT;
1096 n_auto_repetitions = 1; // 1 frame
1097 auto_repetition_pause_len = 0;
1098 repeat_frame_pause_len = RC6_FRAME_REPEAT_PAUSE_LEN;
1099 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1100 break;
1101 }
1102 #endif
1103 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1104 case IRMP_RC6A_PROTOCOL:
1105 {
1106 startbit_pulse_len = RC6_START_BIT_PULSE_LEN;
1107 startbit_pause_len = RC6_START_BIT_PAUSE_LEN - 1;
1108 pulse_len = RC6_BIT_LEN;
1109 pause_len = RC6_BIT_LEN;
1110 has_stop_bit = RC6_STOP_BIT;
1111 complete_data_len = RC6_COMPLETE_DATA_LEN_LONG;
1112 n_auto_repetitions = 1; // 1 frame
1113 auto_repetition_pause_len = 0;
1114 repeat_frame_pause_len = RC6_FRAME_REPEAT_PAUSE_LEN;
1115 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1116 break;
1117 }
1118 #endif
1119 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1120 case IRMP_DENON_PROTOCOL:
1121 {
1122 startbit_pulse_len = 0x00;
1123 startbit_pause_len = 0x00;
1124 pulse_1_len = DENON_PULSE_LEN;
1125 pause_1_len = DENON_1_PAUSE_LEN - 1;
1126 pulse_0_len = DENON_PULSE_LEN;
1127 pause_0_len = DENON_0_PAUSE_LEN - 1;
1128 has_stop_bit = DENON_STOP_BIT;
1129 complete_data_len = DENON_COMPLETE_DATA_LEN;
1130 n_auto_repetitions = DENON_FRAMES; // 2 frames, 2nd with inverted command
1131 auto_repetition_pause_len = DENON_AUTO_REPETITION_PAUSE_LEN; // 65 ms pause after 1st frame
1132 repeat_frame_pause_len = DENON_FRAME_REPEAT_PAUSE_LEN;
1133 irsnd_set_freq (IRSND_FREQ_36_KHZ); // in theory 32kHz, in practice 36kHz is better
1134 break;
1135 }
1136 #endif
1137 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1138 case IRMP_NUBERT_PROTOCOL:
1139 {
1140 startbit_pulse_len = NUBERT_START_BIT_PULSE_LEN;
1141 startbit_pause_len = NUBERT_START_BIT_PAUSE_LEN - 1;
1142 pulse_1_len = NUBERT_1_PULSE_LEN;
1143 pause_1_len = NUBERT_1_PAUSE_LEN - 1;
1144 pulse_0_len = NUBERT_0_PULSE_LEN;
1145 pause_0_len = NUBERT_0_PAUSE_LEN - 1;
1146 has_stop_bit = NUBERT_STOP_BIT;
1147 complete_data_len = NUBERT_COMPLETE_DATA_LEN;
1148 n_auto_repetitions = NUBERT_FRAMES; // 2 frames
1149 auto_repetition_pause_len = NUBERT_AUTO_REPETITION_PAUSE_LEN; // 35 ms pause
1150 repeat_frame_pause_len = NUBERT_FRAME_REPEAT_PAUSE_LEN;
1151 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1152 break;
1153 }
1154 #endif
1155 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1156 case IRMP_BANG_OLUFSEN_PROTOCOL:
1157 {
1158 startbit_pulse_len = BANG_OLUFSEN_START_BIT1_PULSE_LEN;
1159 startbit_pause_len = BANG_OLUFSEN_START_BIT1_PAUSE_LEN - 1;
1160 pulse_1_len = BANG_OLUFSEN_PULSE_LEN;
1161 pause_1_len = BANG_OLUFSEN_1_PAUSE_LEN - 1;
1162 pulse_0_len = BANG_OLUFSEN_PULSE_LEN;
1163 pause_0_len = BANG_OLUFSEN_0_PAUSE_LEN - 1;
1164 has_stop_bit = BANG_OLUFSEN_STOP_BIT;
1165 complete_data_len = BANG_OLUFSEN_COMPLETE_DATA_LEN;
1166 n_auto_repetitions = 1; // 1 frame
1167 auto_repetition_pause_len = 0;
1168 repeat_frame_pause_len = BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN;
1169 last_bit_value = 0;
1170 irsnd_set_freq (IRSND_FREQ_455_KHZ);
1171 break;
1172 }
1173 #endif
1174 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1175 case IRMP_GRUNDIG_PROTOCOL:
1176 {
1177 startbit_pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1178 startbit_pause_len = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;
1179 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1180 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1181 has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT;
1182 complete_data_len = GRUNDIG_COMPLETE_DATA_LEN;
1183 n_auto_repetitions = GRUNDIG_FRAMES; // 2 frames
1184 auto_repetition_pause_len = GRUNDIG_AUTO_REPETITION_PAUSE_LEN; // 20m sec pause
1185 repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause
1186 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1187
1188 break;
1189 }
1190 #endif
1191 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1192 case IRMP_NOKIA_PROTOCOL:
1193 {
1194 startbit_pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1195 startbit_pause_len = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;
1196 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1197 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1198 has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT;
1199 complete_data_len = NOKIA_COMPLETE_DATA_LEN;
1200 n_auto_repetitions = NOKIA_FRAMES; // 2 frames
1201 auto_repetition_pause_len = NOKIA_AUTO_REPETITION_PAUSE_LEN; // 20 msec pause
1202 repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause
1203 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1204 break;
1205 }
1206 #endif
1207 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1208 case IRMP_SIEMENS_PROTOCOL:
1209 {
1210 startbit_pulse_len = SIEMENS_BIT_LEN;
1211 startbit_pause_len = SIEMENS_BIT_LEN;
1212 pulse_len = SIEMENS_BIT_LEN;
1213 pause_len = SIEMENS_BIT_LEN;
1214 has_stop_bit = SIEMENS_OR_RUWIDO_STOP_BIT;
1215 complete_data_len = SIEMENS_COMPLETE_DATA_LEN - 1;
1216 n_auto_repetitions = 1; // 1 frame
1217 auto_repetition_pause_len = 0;
1218 repeat_frame_pause_len = SIEMENS_FRAME_REPEAT_PAUSE_LEN;
1219 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1220 break;
1221 }
1222 #endif
1223 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1224 case IRMP_FDC_PROTOCOL:
1225 {
1226 startbit_pulse_len = FDC_START_BIT_PULSE_LEN;
1227 startbit_pause_len = FDC_START_BIT_PAUSE_LEN - 1;
1228 complete_data_len = FDC_COMPLETE_DATA_LEN;
1229 pulse_1_len = FDC_PULSE_LEN;
1230 pause_1_len = FDC_1_PAUSE_LEN - 1;
1231 pulse_0_len = FDC_PULSE_LEN;
1232 pause_0_len = FDC_0_PAUSE_LEN - 1;
1233 has_stop_bit = FDC_STOP_BIT;
1234 n_auto_repetitions = 1; // 1 frame
1235 auto_repetition_pause_len = 0;
1236 repeat_frame_pause_len = FDC_FRAME_REPEAT_PAUSE_LEN;
1237 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1238 break;
1239 }
1240 #endif
1241 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1242 case IRMP_RCCAR_PROTOCOL:
1243 {
1244 startbit_pulse_len = RCCAR_START_BIT_PULSE_LEN;
1245 startbit_pause_len = RCCAR_START_BIT_PAUSE_LEN - 1;
1246 complete_data_len = RCCAR_COMPLETE_DATA_LEN;
1247 pulse_1_len = RCCAR_PULSE_LEN;
1248 pause_1_len = RCCAR_1_PAUSE_LEN - 1;
1249 pulse_0_len = RCCAR_PULSE_LEN;
1250 pause_0_len = RCCAR_0_PAUSE_LEN - 1;
1251 has_stop_bit = RCCAR_STOP_BIT;
1252 n_auto_repetitions = 1; // 1 frame
1253 auto_repetition_pause_len = 0;
1254 repeat_frame_pause_len = RCCAR_FRAME_REPEAT_PAUSE_LEN;
1255 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1256 break;
1257 }
1258 #endif
1259 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1260 case IRMP_JVC_PROTOCOL:
1261 {
1262 if (repeat_counter != 0) // skip start bit if repetition frame
1263 {
1264 current_bit = 0;
1265 }
1266
1267 startbit_pulse_len = JVC_START_BIT_PULSE_LEN;
1268 startbit_pause_len = JVC_START_BIT_PAUSE_LEN - 1;
1269 complete_data_len = JVC_COMPLETE_DATA_LEN;
1270 pulse_1_len = JVC_PULSE_LEN;
1271 pause_1_len = JVC_1_PAUSE_LEN - 1;
1272 pulse_0_len = JVC_PULSE_LEN;
1273 pause_0_len = JVC_0_PAUSE_LEN - 1;
1274 has_stop_bit = JVC_STOP_BIT;
1275 n_auto_repetitions = 1; // 1 frame
1276 auto_repetition_pause_len = 0;
1277 repeat_frame_pause_len = JVC_FRAME_REPEAT_PAUSE_LEN;
1278 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1279
1280 break;
1281 }
1282 #endif
1283 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1284 case IRMP_NIKON_PROTOCOL:
1285 {
1286 startbit_pulse_len = NIKON_START_BIT_PULSE_LEN;
1287 startbit_pause_len = 271 - 1; // NIKON_START_BIT_PAUSE_LEN;
1288 complete_data_len = NIKON_COMPLETE_DATA_LEN;
1289 pulse_1_len = NIKON_PULSE_LEN;
1290 pause_1_len = NIKON_1_PAUSE_LEN - 1;
1291 pulse_0_len = NIKON_PULSE_LEN;
1292 pause_0_len = NIKON_0_PAUSE_LEN - 1;
1293 has_stop_bit = NIKON_STOP_BIT;
1294 n_auto_repetitions = 1; // 1 frame
1295 auto_repetition_pause_len = 0;
1296 repeat_frame_pause_len = NIKON_FRAME_REPEAT_PAUSE_LEN;
1297 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1298
1299 break;
1300 }
1301 #endif
1302 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1303 case IRMP_LEGO_PROTOCOL:
1304 {
1305 startbit_pulse_len = LEGO_START_BIT_PULSE_LEN;
1306 startbit_pause_len = LEGO_START_BIT_PAUSE_LEN - 1;
1307 complete_data_len = LEGO_COMPLETE_DATA_LEN;
1308 pulse_1_len = LEGO_PULSE_LEN;
1309 pause_1_len = LEGO_1_PAUSE_LEN - 1;
1310 pulse_0_len = LEGO_PULSE_LEN;
1311 pause_0_len = LEGO_0_PAUSE_LEN - 1;
1312 has_stop_bit = LEGO_STOP_BIT;
1313 n_auto_repetitions = 1; // 1 frame
1314 auto_repetition_pause_len = 0;
1315 repeat_frame_pause_len = LEGO_FRAME_REPEAT_PAUSE_LEN;
1316 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1317 break;
1318 }
1319 #endif
1320 default:
1321 {
1322 irsnd_busy = FALSE;
1323 break;
1324 }
1325 }
1326 }
1327 }
1328
1329 if (irsnd_busy)
1330 {
1331 new_frame = FALSE;
1332
1333 switch (irsnd_protocol)
1334 {
1335 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1336 case IRMP_SIRCS_PROTOCOL:
1337 #endif
1338 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1339 case IRMP_NEC_PROTOCOL:
1340 #endif
1341 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1342 case IRMP_SAMSUNG_PROTOCOL:
1343 case IRMP_SAMSUNG32_PROTOCOL:
1344 #endif
1345 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1346 case IRMP_MATSUSHITA_PROTOCOL:
1347 #endif
1348 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1349 case IRMP_KASEIKYO_PROTOCOL:
1350 #endif
1351 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1352 case IRMP_RECS80_PROTOCOL:
1353 #endif
1354 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1355 case IRMP_RECS80EXT_PROTOCOL:
1356 #endif
1357 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1358 case IRMP_DENON_PROTOCOL:
1359 #endif
1360 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1361 case IRMP_NUBERT_PROTOCOL:
1362 #endif
1363 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1364 case IRMP_BANG_OLUFSEN_PROTOCOL:
1365 #endif
1366 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1367 case IRMP_FDC_PROTOCOL:
1368 #endif
1369 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1370 case IRMP_RCCAR_PROTOCOL:
1371 #endif
1372 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1373 case IRMP_JVC_PROTOCOL:
1374 #endif
1375 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1376 case IRMP_NIKON_PROTOCOL:
1377 #endif
1378 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1379 case IRMP_LEGO_PROTOCOL:
1380 #endif
1381
1382
1383 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \
1384 IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \
1385 IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 || \
1386 IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1
1387 {
1388 if (pulse_counter == 0)
1389 {
1390 if (current_bit == 0xFF) // send start bit
1391 {
1392 pulse_len = startbit_pulse_len;
1393 pause_len = startbit_pause_len;
1394 }
1395 else if (current_bit < complete_data_len) // send n'th bit
1396 {
1397 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1398 if (irsnd_protocol == IRMP_SAMSUNG_PROTOCOL)
1399 {
1400 if (current_bit < SAMSUNG_ADDRESS_LEN) // send address bits
1401 {
1402 pulse_len = SAMSUNG_PULSE_LEN;
1403 pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?
1404 (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);
1405 }
1406 else if (current_bit == SAMSUNG_ADDRESS_LEN) // send SYNC bit (16th bit)
1407 {
1408 pulse_len = SAMSUNG_PULSE_LEN;
1409 pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
1410 }
1411 else if (current_bit < SAMSUNG_COMPLETE_DATA_LEN) // send n'th bit
1412 {
1413 uint8_t cur_bit = current_bit - 1; // sync skipped, offset = -1 !
1414
1415 pulse_len = SAMSUNG_PULSE_LEN;
1416 pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?
1417 (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);
1418 }
1419 }
1420 else
1421 #endif
1422
1423 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1424 if (irsnd_protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
1425 {
1426 if (current_bit == 0) // send 2nd start bit
1427 {
1428 pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;
1429 pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;
1430 }
1431 else if (current_bit == 1) // send 3rd start bit
1432 {
1433 pulse_len = BANG_OLUFSEN_START_BIT3_PULSE_LEN;
1434 pause_len = BANG_OLUFSEN_START_BIT3_PAUSE_LEN - 1;
1435 }
1436 else if (current_bit == 2) // send 4th start bit
1437 {
1438 pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;
1439 pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;
1440 }
1441 else if (current_bit == 19) // send trailer bit
1442 {
1443 pulse_len = BANG_OLUFSEN_PULSE_LEN;
1444 pause_len = BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN - 1;
1445 }
1446 else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN) // send n'th bit
1447 {
1448 uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;
1449 pulse_len = BANG_OLUFSEN_PULSE_LEN;
1450
1451 if (cur_bit_value == last_bit_value)
1452 {
1453 pause_len = BANG_OLUFSEN_R_PAUSE_LEN - 1;
1454 }
1455 else
1456 {
1457 pause_len = cur_bit_value ? (BANG_OLUFSEN_1_PAUSE_LEN - 1) : (BANG_OLUFSEN_0_PAUSE_LEN - 1);
1458 last_bit_value = cur_bit_value;
1459 }
1460 }
1461 }
1462 else
1463 #endif
1464 if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))
1465 {
1466 pulse_len = pulse_1_len;
1467 pause_len = pause_1_len;
1468 }
1469 else
1470 {
1471 pulse_len = pulse_0_len;
1472 pause_len = pause_0_len;
1473 }
1474 }
1475 else if (has_stop_bit) // send stop bit
1476 {
1477 pulse_len = pulse_0_len;
1478
1479 if (auto_repetition_counter < n_auto_repetitions)
1480 {
1481 pause_len = pause_0_len;
1482 }
1483 else
1484 {
1485 pause_len = 255; // last frame: pause of 255
1486 }
1487 }
1488 }
1489
1490 if (pulse_counter < pulse_len)
1491 {
1492 if (pulse_counter == 0)
1493 {
1494 irsnd_on ();
1495 }
1496 pulse_counter++;
1497 }
1498 else if (pause_counter < pause_len)
1499 {
1500 if (pause_counter == 0)
1501 {
1502 irsnd_off ();
1503 }
1504 pause_counter++;
1505 }
1506 else
1507 {
1508 current_bit++;
1509
1510 if (current_bit >= complete_data_len + has_stop_bit)
1511 {
1512 current_bit = 0xFF;
1513 auto_repetition_counter++;
1514
1515 if (auto_repetition_counter == n_auto_repetitions)
1516 {
1517 irsnd_busy = FALSE;
1518 auto_repetition_counter = 0;
1519 }
1520 new_frame = TRUE;
1521 }
1522
1523 pulse_counter = 0;
1524 pause_counter = 0;
1525 }
1526 break;
1527 }
1528 #endif
1529
1530 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1531 case IRMP_RC5_PROTOCOL:
1532 #endif
1533 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1534 case IRMP_RC6_PROTOCOL:
1535 #endif
1536 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1537 case IRMP_RC6A_PROTOCOL:
1538 #endif
1539 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1540 case IRMP_SIEMENS_PROTOCOL:
1541 #endif
1542 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1543 case IRMP_GRUNDIG_PROTOCOL:
1544 #endif
1545 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1546 case IRMP_NOKIA_PROTOCOL:
1547 #endif
1548
1549 #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || \
1550 IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1551 {
1552 if (pulse_counter == pulse_len && pause_counter == pause_len)
1553 {
1554 current_bit++;
1555
1556 if (current_bit >= complete_data_len)
1557 {
1558 current_bit = 0xFF;
1559
1560 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1561 if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)
1562 {
1563 auto_repetition_counter++;
1564
1565 if (repeat_counter > 0)
1566 { // set 117 msec pause time
1567 auto_repetition_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;
1568 }
1569
1570 if (repeat_counter < n_repeat_frames) // tricky: repeat n info frames per auto repetition before sending last stop frame
1571 {
1572 n_auto_repetitions++; // increment number of auto repetitions
1573 repeat_counter++;
1574 }
1575 else if (auto_repetition_counter == n_auto_repetitions)
1576 {
1577 irsnd_busy = FALSE;
1578 auto_repetition_counter = 0;
1579 }
1580 }
1581 else
1582 #endif
1583 {
1584 irsnd_busy = FALSE;
1585 }
1586
1587 new_frame = TRUE;
1588 irsnd_off ();
1589 }
1590
1591 pulse_counter = 0;
1592 pause_counter = 0;
1593 }
1594
1595 if (! new_frame)
1596 {
1597 uint8_t first_pulse;
1598
1599 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1600 if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)
1601 {
1602 if (current_bit == 0xFF || // start bit of start-frame
1603 (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL && current_bit == 15) || // start bit of info-frame (Grundig)
1604 (irsnd_protocol == IRMP_NOKIA_PROTOCOL && (current_bit == 23 || current_bit == 47))) // start bit of info- or stop-frame (Nokia)
1605 {
1606 pulse_len = startbit_pulse_len;
1607 pause_len = startbit_pause_len;
1608 first_pulse = TRUE;
1609 }
1610 else // send n'th bit
1611 {
1612 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1613 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1614 first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;
1615 }
1616 }
1617 else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||
1618 // irsnd_protocol == IRMP_SIEMENS_PROTOCOL)
1619 #endif
1620 {
1621 if (current_bit == 0xFF) // 1 start bit
1622 {
1623 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1624 if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)
1625 {
1626 pulse_len = startbit_pulse_len;
1627 pause_len = startbit_pause_len;
1628 }
1629 #endif
1630 first_pulse = TRUE;
1631 }
1632 else // send n'th bit
1633 {
1634 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1635 if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)
1636 {
1637 pulse_len = RC6_BIT_LEN;
1638 pause_len = RC6_BIT_LEN;
1639
1640 if (irsnd_protocol == IRMP_RC6_PROTOCOL)
1641 {
1642 if (current_bit == 4) // toggle bit (double len)
1643 {
1644 pulse_len = 2 * RC6_BIT_LEN;
1645 pause_len = 2 * RC6_BIT_LEN;
1646 }
1647 }
1648 else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)
1649 {
1650 if (current_bit == 4) // toggle bit (double len)
1651 {
1652 pulse_len = 2 * RC6_BIT_LEN + RC6_BIT_LEN; // hack!
1653 pause_len = 2 * RC6_BIT_LEN;
1654 }
1655 else if (current_bit == 5) // toggle bit (double len)
1656 {
1657 pause_len = 2 * RC6_BIT_LEN;
1658 }
1659 }
1660 }
1661 #endif
1662 first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;
1663 }
1664
1665 if (irsnd_protocol == IRMP_RC5_PROTOCOL)
1666 {
1667 first_pulse = first_pulse ? FALSE : TRUE;
1668 }
1669 }
1670
1671 if (first_pulse)
1672 {
1673 if (pulse_counter < pulse_len)
1674 {
1675 if (pulse_counter == 0)
1676 {
1677 irsnd_on ();
1678 }
1679 pulse_counter++;
1680 }
1681 else // if (pause_counter < pause_len)
1682 {
1683 if (pause_counter == 0)
1684 {
1685 irsnd_off ();
1686 }
1687 pause_counter++;
1688 }
1689 }
1690 else
1691 {
1692 if (pause_counter < pause_len)
1693 {
1694 if (pause_counter == 0)
1695 {
1696 irsnd_off ();
1697 }
1698 pause_counter++;
1699 }
1700 else // if (pulse_counter < pulse_len)
1701 {
1702 if (pulse_counter == 0)
1703 {
1704 irsnd_on ();
1705 }
1706 pulse_counter++;
1707 }
1708 }
1709 }
1710 break;
1711 }
1712 #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 ||
1713 // IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1714
1715 default:
1716 {
1717 irsnd_busy = FALSE;
1718 break;
1719 }
1720 }
1721 }
1722
1723 if (! irsnd_busy)
1724 {
1725 if (repeat_counter < n_repeat_frames)
1726 {
1727 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1728 if (irsnd_protocol == IRMP_FDC_PROTOCOL)
1729 {
1730 irsnd_buffer[2] |= 0x0F;
1731 }
1732 #endif
1733 repeat_counter++;
1734 irsnd_busy = TRUE;
1735 }
1736 else
1737 {
1738 n_repeat_frames = 0;
1739 repeat_counter = 0;
1740 }
1741 }
1742 }
1743
1744 #ifdef DEBUG
1745 if (irsnd_is_on)
1746 {
1747 putchar ('0');
1748 }
1749 else
1750 {
1751 putchar ('1');
1752 }
1753 #endif
1754
1755 return irsnd_busy;
1756 }
1757
1758 #ifdef DEBUG
1759
1760 // main function - for unix/linux + windows only!
1761 // AVR: see main.c!
1762 // Compile it under linux with:
1763 // cc irsnd.c -o irsnd
1764 //
1765 // usage: ./irsnd protocol hex-address hex-command >filename
1766
1767 int
1768 main (int argc, char ** argv)
1769 {
1770 int idx;
1771 int protocol;
1772 int address;
1773 int command;
1774 IRMP_DATA irmp_data;
1775
1776 if (argc != 4 && argc != 5)
1777 {
1778 fprintf (stderr, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv[0]);
1779 return 1;
1780 }
1781
1782 if (sscanf (argv[1], "%d", &protocol) == 1 &&
1783 sscanf (argv[2], "%x", &address) == 1 &&
1784 sscanf (argv[3], "%x", &command) == 1)
1785 {
1786 irmp_data.protocol = protocol;
1787 irmp_data.address = address;
1788 irmp_data.command = command;
1789
1790 if (argc == 5)
1791 {
1792 irmp_data.flags = atoi (argv[4]);
1793 }
1794 else
1795 {
1796 irmp_data.flags = 0;
1797 }
1798
1799 irsnd_init ();
1800
1801 (void) irsnd_send_data (&irmp_data, TRUE);
1802
1803 while (irsnd_busy)
1804 {
1805 irsnd_ISR ();
1806 }
1807 for (idx = 0; idx < 20; idx++)
1808 {
1809 irsnd_ISR ();
1810 }
1811
1812 putchar ('\n');
1813 }
1814 else
1815 {
1816 fprintf (stderr, "%s: wrong arguments\n", argv[0]);
1817 return 1;
1818 }
1819 return 0;
1820 }
1821
1822 #endif // DEBUG