]>
Commit | Line | Data |
---|---|---|
4225a882 | 1 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r |
2 | * @file irsnd.c\r | |
3 | *\r | |
4 | * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de\r | |
5 | *\r | |
879b06c2 | 6 | * $Id: irsnd.c,v 1.17 2010/06/10 10:05:56 fm Exp $\r |
5481e9cd | 7 | *\r |
4225a882 | 8 | * This program is free software; you can redistribute it and/or modify\r |
9 | * it under the terms of the GNU General Public License as published by\r | |
10 | * the Free Software Foundation; either version 2 of the License, or\r | |
11 | * (at your option) any later version.\r | |
12 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
13 | */\r | |
14 | \r | |
15 | #ifdef unix // test/debug on linux/unix\r | |
16 | #include <stdio.h>\r | |
17 | #include <unistd.h>\r | |
18 | #include <stdlib.h>\r | |
19 | #include <string.h>\r | |
20 | #include <inttypes.h>\r | |
21 | \r | |
22 | #define DEBUG\r | |
23 | #define F_CPU 8000000L\r | |
24 | \r | |
25 | #else // not unix:\r | |
26 | \r | |
27 | #ifdef WIN32 // test/debug on windows\r | |
28 | #include <stdio.h>\r | |
29 | #define F_CPU 8000000L\r | |
30 | typedef unsigned char uint8_t;\r | |
31 | typedef unsigned short uint16_t;\r | |
32 | #define DEBUG\r | |
33 | \r | |
34 | #else\r | |
35 | \r | |
36 | #ifdef CODEVISION\r | |
37 | #define COM2A0 6\r | |
38 | #define WGM21 1\r | |
39 | #define CS20 0\r | |
40 | #else\r | |
41 | #include <inttypes.h>\r | |
42 | #include <avr/io.h>\r | |
43 | #include <util/delay.h>\r | |
44 | #include <avr/pgmspace.h>\r | |
45 | #endif // CODEVISION\r | |
46 | \r | |
47 | #endif // WIN32\r | |
48 | #endif // unix\r | |
49 | \r | |
50 | #include "irmp.h"\r | |
46dd89b7 | 51 | #include "irsndconfig.h"\r |
4225a882 | 52 | #include "irsnd.h"\r |
53 | \r | |
4225a882 | 54 | #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)\r |
55 | #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)\r | |
56 | #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)\r | |
57 | #define SIRCS_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME + 0.5)\r | |
58 | #define SIRCS_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME + 0.5)\r | |
a7054daf | 59 | #define SIRCS_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r |
60 | #define SIRCS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
4225a882 | 61 | \r |
62 | #define NEC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME + 0.5)\r | |
63 | #define NEC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME + 0.5)\r | |
a7054daf | 64 | #define NEC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME + 0.5)\r |
4225a882 | 65 | #define NEC_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME + 0.5)\r |
66 | #define NEC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME + 0.5)\r | |
67 | #define NEC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 68 | #define NEC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 69 | \r |
70 | #define SAMSUNG_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME + 0.5)\r | |
71 | #define SAMSUNG_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME + 0.5)\r | |
72 | #define SAMSUNG_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME + 0.5)\r | |
73 | #define SAMSUNG_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME + 0.5)\r | |
74 | #define SAMSUNG_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 75 | #define SAMSUNG_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 76 | \r |
a7054daf | 77 | #define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r |
78 | #define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
5b437ff6 | 79 | \r |
4225a882 | 80 | #define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)\r |
81 | #define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)\r | |
82 | #define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)\r | |
83 | #define MATSUSHITA_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME + 0.5)\r | |
84 | #define MATSUSHITA_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 85 | #define MATSUSHITA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * MATSUSHITA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 86 | \r |
87 | #define RECS80_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME + 0.5)\r | |
88 | #define RECS80_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME + 0.5)\r | |
89 | #define RECS80_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME + 0.5)\r | |
90 | #define RECS80_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME + 0.5)\r | |
91 | #define RECS80_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 92 | #define RECS80_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 93 | \r |
94 | #define RC5_START_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)\r | |
95 | #define RC5_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)\r | |
a7054daf | 96 | #define RC5_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC5_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 97 | \r |
98 | #define RC6_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME + 0.5)\r | |
99 | #define RC6_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME + 0.5)\r | |
100 | #define RC6_TOGGLE_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME + 0.5)\r | |
101 | #define RC6_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_BIT_TIME + 0.5)\r | |
a7054daf | 102 | #define RC6_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC6_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 103 | \r |
104 | #define DENON_PULSE_LEN (uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME + 0.5)\r | |
105 | #define DENON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME + 0.5)\r | |
106 | #define DENON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 107 | #define DENON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r |
108 | #define DENON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
4225a882 | 109 | \r |
110 | #define RECS80EXT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME + 0.5)\r | |
111 | #define RECS80EXT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME + 0.5)\r | |
112 | #define RECS80EXT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME + 0.5)\r | |
113 | #define RECS80EXT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME + 0.5)\r | |
114 | #define RECS80EXT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 115 | #define RECS80EXT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80EXT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
4225a882 | 116 | \r |
117 | #define NUBERT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME + 0.5)\r | |
118 | #define NUBERT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME + 0.5)\r | |
119 | #define NUBERT_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME + 0.5)\r | |
120 | #define NUBERT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME + 0.5)\r | |
121 | #define NUBERT_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME + 0.5)\r | |
122 | #define NUBERT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME + 0.5)\r | |
a7054daf | 123 | #define NUBERT_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r |
124 | #define NUBERT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
4225a882 | 125 | \r |
5481e9cd | 126 | #define BANG_OLUFSEN_START_BIT1_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME + 0.5)\r |
127 | #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME + 0.5)\r | |
128 | #define BANG_OLUFSEN_START_BIT2_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME + 0.5)\r | |
129 | #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME + 0.5)\r | |
130 | #define BANG_OLUFSEN_START_BIT3_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME + 0.5)\r | |
131 | #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME + 0.5)\r | |
132 | #define BANG_OLUFSEN_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME + 0.5)\r | |
133 | #define BANG_OLUFSEN_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME + 0.5)\r | |
134 | #define BANG_OLUFSEN_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME + 0.5)\r | |
135 | #define BANG_OLUFSEN_R_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME + 0.5)\r | |
136 | #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)\r | |
a7054daf | 137 | #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r |
5481e9cd | 138 | \r |
d155e9ab | 139 | #define GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_PRE_PAUSE_TIME + 0.5)\r |
140 | #define GRUNDIG_OR_NOKIA_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_OR_NOKIA_BIT_TIME + 0.5)\r | |
a7054daf | 141 | #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r |
142 | #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!\r | |
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!\r | |
144 | \r | |
145 | #define SIEMENS_START_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)\r | |
146 | #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_BIT_TIME + 0.5)\r | |
147 | #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
5b437ff6 | 148 | \r |
4225a882 | 149 | #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1)\r |
150 | #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1)\r | |
151 | #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1)\r | |
152 | #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1)\r | |
153 | #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1)\r | |
5481e9cd | 154 | #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1)\r |
4225a882 | 155 | \r |
b5ea7869 | 156 | #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)\r |
157 | #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)\r | |
158 | #define FDC_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)\r | |
159 | #define FDC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)\r | |
160 | #define FDC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)\r | |
161 | #define FDC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!\r | |
162 | \r | |
4225a882 | 163 | static volatile uint8_t irsnd_busy;\r |
164 | static volatile uint8_t irsnd_protocol;\r | |
d155e9ab | 165 | static volatile uint8_t irsnd_buffer[6];\r |
a7054daf | 166 | static volatile uint8_t irsnd_repeat;\r |
4225a882 | 167 | static volatile uint8_t irsnd_is_on = FALSE;\r |
168 | \r | |
169 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
170 | * Switch PWM on\r | |
171 | * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing\r | |
172 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
173 | */\r | |
174 | static void\r | |
175 | irsnd_on (void)\r | |
176 | {\r | |
177 | if (! irsnd_is_on)\r | |
178 | {\r | |
179 | #ifndef DEBUG\r | |
180 | #if defined (__AVR_ATmega32__)\r | |
181 | TCCR2 |= (1<<COM20)|(1<<WGM21); // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r | |
182 | #else\r | |
183 | TCCR2A |= (1<<COM2A0)|(1<<WGM21); // = 0x42: toggle OC2A on compare match, clear Timer 2 at compare match OCR2A\r | |
46dd89b7 | 184 | #endif // __AVR...\r |
4225a882 | 185 | #endif // DEBUG\r |
186 | irsnd_is_on = TRUE;\r | |
187 | }\r | |
188 | }\r | |
189 | \r | |
190 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
191 | * Switch PWM off\r | |
192 | * @details Switches PWM off\r | |
193 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
194 | */\r | |
195 | static void\r | |
196 | irsnd_off (void)\r | |
197 | {\r | |
198 | if (irsnd_is_on)\r | |
199 | {\r | |
200 | #ifndef DEBUG\r | |
201 | #if defined (__AVR_ATmega32__)\r | |
202 | TCCR2 &= ~(1<<COM20); // normal port operation, OC2A disconnected.\r | |
203 | #else\r | |
204 | TCCR2A &= ~(1<<COM2A0); // normal port operation, OC2A disconnected.\r | |
46dd89b7 | 205 | #endif // __AVR...\r |
4225a882 | 206 | IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low\r |
207 | #endif // DEBUG\r | |
208 | irsnd_is_on = FALSE;\r | |
209 | }\r | |
210 | }\r | |
211 | \r | |
212 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
213 | * Set PWM frequency\r | |
214 | * @details sets pwm frequency\r | |
215 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
216 | */\r | |
217 | static void\r | |
218 | irsnd_set_freq (uint8_t freq)\r | |
219 | {\r | |
220 | #ifndef DEBUG\r | |
221 | #if defined (__AVR_ATmega32__)\r | |
222 | OCR2 = freq;\r | |
223 | #else\r | |
224 | OCR2A = freq;\r | |
46dd89b7 | 225 | #endif // __AVR...\r |
4225a882 | 226 | #endif // DEBUG\r |
227 | }\r | |
228 | \r | |
229 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
230 | * Initialize the PWM\r | |
231 | * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels\r | |
232 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
233 | */\r | |
234 | void\r | |
235 | irsnd_init (void)\r | |
236 | {\r | |
237 | #ifndef DEBUG\r | |
238 | IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low\r | |
239 | IRSND_DDR |= (1<<IRSND_BIT); // set IRSND_BIT to output\r | |
240 | \r | |
241 | #if defined (__AVR_ATmega32__)\r | |
242 | TCCR2 = (1<<WGM21); // CTC mode\r | |
243 | TCCR2 |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r | |
244 | #else\r | |
245 | TCCR2A = (1<<WGM21); // CTC mode\r | |
246 | TCCR2B |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r | |
46dd89b7 | 247 | #endif // __AVR... \r |
4225a882 | 248 | \r |
249 | irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency\r | |
250 | #endif // DEBUG\r | |
251 | }\r | |
252 | \r | |
253 | uint8_t\r | |
254 | irsnd_is_busy (void)\r | |
255 | {\r | |
256 | return irsnd_busy;\r | |
257 | }\r | |
258 | \r | |
259 | static uint16_t\r | |
260 | bitsrevervse (uint16_t x, uint8_t len)\r | |
261 | {\r | |
262 | uint16_t xx = 0;\r | |
263 | \r | |
264 | while(len)\r | |
265 | {\r | |
266 | xx <<= 1;\r | |
267 | if (x & 1)\r | |
268 | {\r | |
269 | xx |= 1;\r | |
270 | }\r | |
271 | x >>= 1;\r | |
272 | len--;\r | |
273 | }\r | |
274 | return xx;\r | |
275 | }\r | |
276 | \r | |
277 | \r | |
278 | uint8_t\r | |
879b06c2 | 279 | irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)\r |
4225a882 | 280 | {\r |
281 | #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r | |
282 | static uint8_t toggle_bit_recs80;\r | |
283 | #endif\r | |
284 | #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r | |
285 | static uint8_t toggle_bit_recs80ext;\r | |
286 | #endif\r | |
287 | #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r | |
288 | static uint8_t toggle_bit_rc5;\r | |
289 | #endif\r | |
290 | uint16_t address;\r | |
291 | uint16_t command;\r | |
292 | \r | |
879b06c2 | 293 | if (do_wait)\r |
4225a882 | 294 | {\r |
879b06c2 | 295 | while (irsnd_busy)\r |
296 | {\r | |
297 | // do nothing;\r | |
298 | }\r | |
299 | }\r | |
300 | else if (irsnd_busy)\r | |
301 | {\r | |
302 | return (FALSE);\r | |
4225a882 | 303 | }\r |
304 | \r | |
305 | irsnd_protocol = irmp_data_p->protocol;\r | |
a7054daf | 306 | irsnd_repeat = irmp_data_p->flags;\r |
4225a882 | 307 | \r |
308 | switch (irsnd_protocol)\r | |
309 | {\r | |
310 | #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r | |
311 | case IRMP_SIRCS_PROTOCOL:\r | |
312 | {\r | |
313 | command = bitsrevervse (irmp_data_p->command, SIRCS_MINIMUM_DATA_LEN);\r | |
314 | \r | |
4225a882 | 315 | irsnd_buffer[0] = (command & 0x0FF0) >> 4; // CCCCCCCC\r |
316 | irsnd_buffer[1] = (command & 0x000F) << 4; // CCCC0000\r | |
317 | irsnd_busy = TRUE;\r | |
318 | break;\r | |
319 | }\r | |
320 | #endif\r | |
321 | #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r | |
322 | case IRMP_NEC_PROTOCOL:\r | |
46dd89b7 | 323 | case IRMP_APPLE_PROTOCOL:\r |
4225a882 | 324 | {\r |
325 | address = bitsrevervse (irmp_data_p->address, NEC_ADDRESS_LEN);\r | |
326 | command = bitsrevervse (irmp_data_p->command, NEC_COMMAND_LEN);\r | |
327 | \r | |
4225a882 | 328 | irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA\r |
329 | irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA\r | |
330 | irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC\r | |
46dd89b7 | 331 | \r |
332 | if (irsnd_protocol == IRMP_APPLE_PROTOCOL)\r | |
333 | {\r | |
334 | irsnd_protocol = IRMP_NEC_PROTOCOL; // APPLE protocol is NEC with fix bitmask instead of inverted command\r | |
335 | irsnd_buffer[3] = 0x8B; // 10001011\r | |
336 | }\r | |
337 | else\r | |
338 | {\r | |
339 | irsnd_buffer[3] = ~((command & 0xFF00) >> 8); // cccccccc\r | |
340 | }\r | |
341 | \r | |
4225a882 | 342 | irsnd_busy = TRUE;\r |
343 | break;\r | |
344 | }\r | |
345 | #endif\r | |
346 | #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r | |
347 | case IRMP_SAMSUNG_PROTOCOL:\r | |
348 | {\r | |
349 | address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r | |
350 | command = bitsrevervse (irmp_data_p->command, SAMSUNG_COMMAND_LEN);\r | |
351 | \r | |
4225a882 | 352 | irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA\r |
353 | irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA\r | |
354 | irsnd_buffer[2] = (command & 0x00F0) | ((command & 0xF000) >> 12); // IIIICCCC\r | |
355 | irsnd_buffer[3] = ((command & 0x0F00) >> 4) | ((~(command & 0xF000) >> 12) & 0x0F); // CCCCcccc\r | |
356 | irsnd_buffer[4] = (~(command & 0x0F00) >> 4) & 0xF0; // cccc0000\r | |
357 | irsnd_busy = TRUE;\r | |
358 | break;\r | |
359 | }\r | |
360 | case IRMP_SAMSUNG32_PROTOCOL:\r | |
361 | {\r | |
362 | address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);\r | |
363 | command = bitsrevervse (irmp_data_p->command, SAMSUNG32_COMMAND_LEN);\r | |
364 | \r | |
4225a882 | 365 | irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA\r |
366 | irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA\r | |
367 | irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC\r | |
368 | irsnd_buffer[3] = (command & 0x00FF); // CCCCCCCC\r | |
369 | irsnd_busy = TRUE;\r | |
370 | break;\r | |
371 | }\r | |
372 | #endif\r | |
373 | #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r | |
374 | case IRMP_MATSUSHITA_PROTOCOL:\r | |
375 | {\r | |
376 | address = bitsrevervse (irmp_data_p->address, MATSUSHITA_ADDRESS_LEN);\r | |
377 | command = bitsrevervse (irmp_data_p->command, MATSUSHITA_COMMAND_LEN);\r | |
378 | \r | |
4225a882 | 379 | irsnd_buffer[0] = (command & 0x0FF0) >> 4; // CCCCCCCC\r |
380 | irsnd_buffer[1] = ((command & 0x000F) << 4) | ((address & 0x0F00) >> 8); // CCCCAAAA\r | |
381 | irsnd_buffer[2] = (address & 0x00FF); // AAAAAAAA\r | |
382 | irsnd_busy = TRUE;\r | |
383 | break;\r | |
384 | }\r | |
385 | #endif\r | |
386 | #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r | |
387 | case IRMP_RECS80_PROTOCOL:\r | |
388 | {\r | |
389 | toggle_bit_recs80 = toggle_bit_recs80 ? 0x00 : 0x40;\r | |
390 | \r | |
4225a882 | 391 | irsnd_buffer[0] = 0x80 | toggle_bit_recs80 | ((irmp_data_p->address & 0x0007) << 3) |\r |
392 | ((irmp_data_p->command & 0x0038) >> 3); // STAAACCC\r | |
393 | irsnd_buffer[1] = (irmp_data_p->command & 0x07) << 5; // CCC00000\r | |
394 | irsnd_busy = TRUE;\r | |
395 | break;\r | |
396 | }\r | |
397 | #endif\r | |
398 | #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r | |
399 | case IRMP_RECS80EXT_PROTOCOL:\r | |
400 | {\r | |
401 | toggle_bit_recs80ext = toggle_bit_recs80ext ? 0x00 : 0x40;\r | |
402 | \r | |
4225a882 | 403 | irsnd_buffer[0] = 0x80 | toggle_bit_recs80ext | ((irmp_data_p->address & 0x000F) << 2) |\r |
404 | ((irmp_data_p->command & 0x0030) >> 4); // STAAAACC\r | |
405 | irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4; // CCCC0000\r | |
406 | irsnd_busy = TRUE;\r | |
407 | break;\r | |
408 | }\r | |
409 | #endif\r | |
410 | #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r | |
411 | case IRMP_RC5_PROTOCOL:\r | |
412 | {\r | |
413 | toggle_bit_rc5 = toggle_bit_rc5 ? 0x00 : 0x40;\r | |
414 | \r | |
4225a882 | 415 | irsnd_buffer[0] = ((irmp_data_p->command & 0x40) ? 0x00 : 0x80) | toggle_bit_rc5 |\r |
416 | ((irmp_data_p->address & 0x001F) << 1) | ((irmp_data_p->command & 0x20) >> 5); // CTAAAAAC\r | |
417 | irsnd_buffer[1] = (irmp_data_p->command & 0x1F) << 3; // CCCCC000\r | |
418 | irsnd_busy = TRUE;\r | |
419 | break;\r | |
420 | }\r | |
421 | #endif\r | |
422 | #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r | |
423 | case IRMP_DENON_PROTOCOL:\r | |
424 | {\r | |
d155e9ab | 425 | irsnd_buffer[0] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x0380) >> 7); // AAAAACCC (1st frame)\r |
426 | irsnd_buffer[1] = (irmp_data_p->command & 0x7F) << 1; // CCCCCCC\r | |
427 | irsnd_buffer[2] = ((irmp_data_p->address & 0x1F) << 3) | (((~irmp_data_p->command) & 0x0380) >> 7); // AAAAACCC (2nd frame)\r | |
428 | irsnd_buffer[3] = (~(irmp_data_p->command) & 0x7F) << 1; // CCCCCCC\r | |
4225a882 | 429 | irsnd_busy = TRUE;\r |
430 | break;\r | |
431 | }\r | |
432 | #endif\r | |
433 | #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r | |
434 | case IRMP_NUBERT_PROTOCOL:\r | |
435 | {\r | |
4225a882 | 436 | irsnd_buffer[0] = irmp_data_p->command >> 2; // CCCCCCCC\r |
437 | irsnd_buffer[1] = (irmp_data_p->command & 0x0003) << 6; // CC000000\r | |
438 | irsnd_busy = TRUE;\r | |
439 | break;\r | |
440 | }\r | |
5481e9cd | 441 | #endif\r |
442 | #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r | |
443 | case IRMP_BANG_OLUFSEN_PROTOCOL:\r | |
444 | {\r | |
5481e9cd | 445 | irsnd_buffer[0] = irmp_data_p->command >> 11; // SXSCCCCC\r |
446 | irsnd_buffer[1] = irmp_data_p->command >> 3; // CCCCCCCC\r | |
447 | irsnd_buffer[2] = (irmp_data_p->command & 0x0007) << 5; // CCC00000\r | |
448 | irsnd_busy = TRUE;\r | |
449 | break;\r | |
450 | }\r | |
4225a882 | 451 | #endif\r |
5b437ff6 | 452 | #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r |
453 | case IRMP_GRUNDIG_PROTOCOL:\r | |
454 | {\r | |
455 | command = bitsrevervse (irmp_data_p->command, GRUNDIG_COMMAND_LEN);\r | |
456 | \r | |
d155e9ab | 457 | irsnd_buffer[0] = 0xFF; // S1111111 (1st frame)\r |
458 | irsnd_buffer[1] = 0xC0; // 11\r | |
459 | irsnd_buffer[2] = 0x80 | (command >> 2); // SCCCCCCC (2nd frame)\r | |
460 | irsnd_buffer[3] = (command << 6) & 0xC0; // CC\r | |
461 | \r | |
462 | irsnd_busy = TRUE;\r | |
463 | break;\r | |
464 | }\r | |
465 | #endif\r | |
466 | #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r | |
467 | case IRMP_NOKIA_PROTOCOL:\r | |
468 | {\r | |
469 | address = bitsrevervse (irmp_data_p->address, NOKIA_ADDRESS_LEN);\r | |
470 | command = bitsrevervse (irmp_data_p->command, NOKIA_COMMAND_LEN);\r | |
471 | \r | |
472 | irsnd_buffer[0] = 0xBF; // S0111111 (1st + 3rd frame)\r | |
473 | irsnd_buffer[1] = 0xFF; // 11111111\r | |
474 | irsnd_buffer[2] = 0x80; // 1\r | |
475 | irsnd_buffer[3] = 0x80 | command >> 1; // SCCCCCCC (2nd frame)\r | |
476 | irsnd_buffer[4] = (command << 7) | (address >> 1); // CAAAAAAA\r | |
477 | irsnd_buffer[5] = (address << 7); // A\r | |
5b437ff6 | 478 | \r |
479 | irsnd_busy = TRUE;\r | |
480 | break;\r | |
481 | }\r | |
482 | #endif\r | |
a7054daf | 483 | #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r |
484 | case IRMP_SIEMENS_PROTOCOL:\r | |
485 | {\r | |
486 | irsnd_buffer[0] = ((irmp_data_p->address & 0x0FFF) >> 5); // SAAAAAAA\r | |
487 | irsnd_buffer[1] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x7F) >> 5); // AAAAA0CC\r | |
488 | irsnd_buffer[2] = (irmp_data_p->command << 3); // CCCCC0\r | |
489 | irsnd_busy = TRUE;\r | |
490 | break;\r | |
491 | }\r | |
b5ea7869 | 492 | #endif\r |
493 | #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r | |
494 | case IRMP_FDC_PROTOCOL:\r | |
495 | {\r | |
496 | address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);\r | |
497 | command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);\r | |
498 | \r | |
499 | irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA\r | |
500 | irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA\r | |
501 | irsnd_buffer[2] = 0; // 00000000\r | |
502 | irsnd_buffer[3] = (command & 0x0FE0) >> 5; // 0CCCCCCC\r | |
503 | irsnd_buffer[4] = ((command & 0x001F) << 3) | 0x07; // CCCCC111\r | |
504 | irsnd_busy = TRUE;\r | |
505 | break;\r | |
506 | }\r | |
a7054daf | 507 | #endif\r |
4225a882 | 508 | default:\r |
509 | {\r | |
510 | break;\r | |
511 | }\r | |
512 | }\r | |
513 | \r | |
514 | return irsnd_busy;\r | |
515 | }\r | |
516 | \r | |
517 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
518 | * ISR routine\r | |
519 | * @details ISR routine, called 10000 times per second\r | |
520 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
521 | */\r | |
522 | uint8_t\r | |
523 | irsnd_ISR (void)\r | |
524 | {\r | |
525 | static uint8_t current_bit = 0xFF;\r | |
526 | static uint8_t pulse_counter;\r | |
527 | static uint8_t pause_counter;\r | |
528 | static uint8_t startbit_pulse_len;\r | |
529 | static uint8_t startbit_pause_len;\r | |
530 | static uint8_t pulse_1_len;\r | |
531 | static uint8_t pause_1_len;\r | |
532 | static uint8_t pulse_0_len;\r | |
533 | static uint8_t pause_0_len;\r | |
534 | static uint8_t has_stop_bit;\r | |
535 | static uint8_t new_frame = TRUE;\r | |
536 | static uint8_t complete_data_len;\r | |
a7054daf | 537 | static uint8_t n_auto_repetitions; // number of auto_repetitions\r |
538 | static uint8_t auto_repetition_counter; // auto_repetition counter\r | |
539 | static uint16_t auto_repetition_pause_len; // pause before auto_repetition, uint16_t!\r | |
540 | static uint16_t auto_repetition_pause_counter; // pause before auto_repetition, uint16_t!\r | |
541 | static uint8_t n_repeat_frames; // number of repeat frames\r | |
542 | static uint8_t repeat_counter; // repeat counter\r | |
543 | static uint16_t repeat_frame_pause_len; // pause before repeat, uint16_t!\r | |
544 | static uint16_t packet_repeat_pause_counter; // pause before repeat, uint16_t!\r | |
5481e9cd | 545 | #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r |
546 | static uint8_t last_bit_value;\r | |
547 | #endif\r | |
548 | static uint8_t pulse_len = 0xFF;\r | |
549 | static uint8_t pause_len = 0xFF;\r | |
4225a882 | 550 | \r |
551 | if (irsnd_busy)\r | |
552 | {\r | |
553 | if (current_bit == 0xFF && new_frame) // start of transmission...\r | |
554 | {\r | |
a7054daf | 555 | if (auto_repetition_counter > 0)\r |
4225a882 | 556 | {\r |
a7054daf | 557 | auto_repetition_pause_counter++;\r |
4225a882 | 558 | \r |
a7054daf | 559 | if (auto_repetition_pause_counter >= auto_repetition_pause_len)\r |
4225a882 | 560 | {\r |
a7054daf | 561 | auto_repetition_pause_counter = 0;\r |
4225a882 | 562 | \r |
563 | if (irsnd_protocol == IRMP_DENON_PROTOCOL)\r | |
564 | {\r | |
565 | current_bit = 16;\r | |
566 | complete_data_len = 2 * DENON_COMPLETE_DATA_LEN + 1;\r | |
567 | }\r | |
a7054daf | 568 | else if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL) // n'th grundig info frame\r |
5b437ff6 | 569 | {\r |
570 | current_bit = 15;\r | |
571 | complete_data_len = 16 + GRUNDIG_COMPLETE_DATA_LEN;\r | |
572 | }\r | |
a7054daf | 573 | else if (irsnd_protocol == IRMP_NOKIA_PROTOCOL) // n'th nokia info frame\r |
d155e9ab | 574 | {\r |
a7054daf | 575 | if (auto_repetition_counter + 1 < n_auto_repetitions)\r |
d155e9ab | 576 | {\r |
577 | current_bit = 23;\r | |
578 | complete_data_len = 24 + NOKIA_COMPLETE_DATA_LEN;\r | |
579 | }\r | |
a7054daf | 580 | else // nokia stop frame\r |
d155e9ab | 581 | {\r |
582 | current_bit = 0xFF;\r | |
583 | complete_data_len = NOKIA_COMPLETE_DATA_LEN;\r | |
584 | }\r | |
585 | }\r | |
4225a882 | 586 | }\r |
587 | else\r | |
588 | {\r | |
589 | #ifdef DEBUG\r | |
590 | if (irsnd_is_on)\r | |
591 | {\r | |
592 | putchar ('0');\r | |
593 | }\r | |
594 | else\r | |
595 | {\r | |
596 | putchar ('1');\r | |
597 | }\r | |
598 | #endif\r | |
599 | return irsnd_busy;\r | |
600 | }\r | |
601 | }\r | |
a7054daf | 602 | else if (repeat_counter > 0 && packet_repeat_pause_counter < repeat_frame_pause_len)\r |
603 | {\r | |
604 | packet_repeat_pause_counter++;\r | |
605 | \r | |
606 | #ifdef DEBUG\r | |
607 | if (irsnd_is_on)\r | |
608 | {\r | |
609 | putchar ('0');\r | |
610 | }\r | |
611 | else\r | |
612 | {\r | |
613 | putchar ('1');\r | |
614 | }\r | |
615 | #endif\r | |
616 | return irsnd_busy;\r | |
617 | }\r | |
4225a882 | 618 | else\r |
619 | {\r | |
a7054daf | 620 | n_repeat_frames = irsnd_repeat;\r |
621 | packet_repeat_pause_counter = 0;\r | |
622 | pulse_counter = 0;\r | |
623 | pause_counter = 0;\r | |
5481e9cd | 624 | \r |
4225a882 | 625 | switch (irsnd_protocol)\r |
626 | {\r | |
627 | #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r | |
628 | case IRMP_SIRCS_PROTOCOL:\r | |
629 | {\r | |
a7054daf | 630 | startbit_pulse_len = SIRCS_START_BIT_PULSE_LEN;\r |
631 | startbit_pause_len = SIRCS_START_BIT_PAUSE_LEN;\r | |
632 | pulse_1_len = SIRCS_1_PULSE_LEN;\r | |
633 | pause_1_len = SIRCS_PAUSE_LEN;\r | |
634 | pulse_0_len = SIRCS_0_PULSE_LEN;\r | |
635 | pause_0_len = SIRCS_PAUSE_LEN;\r | |
636 | has_stop_bit = SIRCS_STOP_BIT;\r | |
637 | complete_data_len = SIRCS_MINIMUM_DATA_LEN;\r | |
638 | n_auto_repetitions = (repeat_counter == 0) ? SIRCS_FRAMES : 1; // 3 frames auto repetition if first frame\r | |
639 | auto_repetition_pause_len = SIRCS_AUTO_REPETITION_PAUSE_LEN; // 25ms pause\r | |
640 | repeat_frame_pause_len = SIRCS_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 641 | irsnd_set_freq (IRSND_FREQ_40_KHZ);\r |
642 | break;\r | |
643 | }\r | |
644 | #endif\r | |
645 | #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r | |
646 | case IRMP_NEC_PROTOCOL:\r | |
647 | {\r | |
a7054daf | 648 | startbit_pulse_len = NEC_START_BIT_PULSE_LEN;\r |
649 | \r | |
650 | if (repeat_counter > 0)\r | |
651 | {\r | |
652 | startbit_pause_len = NEC_REPEAT_START_BIT_PAUSE_LEN;\r | |
653 | complete_data_len = 0;\r | |
654 | }\r | |
655 | else\r | |
656 | {\r | |
657 | startbit_pause_len = NEC_START_BIT_PAUSE_LEN;\r | |
658 | complete_data_len = NEC_COMPLETE_DATA_LEN;\r | |
659 | }\r | |
660 | \r | |
661 | pulse_1_len = NEC_PULSE_LEN;\r | |
662 | pause_1_len = NEC_1_PAUSE_LEN;\r | |
663 | pulse_0_len = NEC_PULSE_LEN;\r | |
664 | pause_0_len = NEC_0_PAUSE_LEN;\r | |
665 | has_stop_bit = NEC_STOP_BIT;\r | |
666 | n_auto_repetitions = 1; // 1 frame\r | |
667 | auto_repetition_pause_len = 0;\r | |
668 | repeat_frame_pause_len = NEC_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 669 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
670 | break;\r | |
671 | }\r | |
672 | #endif\r | |
673 | #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r | |
674 | case IRMP_SAMSUNG_PROTOCOL:\r | |
675 | {\r | |
a7054daf | 676 | startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;\r |
677 | startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN;\r | |
678 | pulse_1_len = SAMSUNG_PULSE_LEN;\r | |
679 | pause_1_len = SAMSUNG_1_PAUSE_LEN;\r | |
680 | pulse_0_len = SAMSUNG_PULSE_LEN;\r | |
681 | pause_0_len = SAMSUNG_0_PAUSE_LEN;\r | |
682 | has_stop_bit = SAMSUNG_STOP_BIT;\r | |
683 | complete_data_len = SAMSUNG_COMPLETE_DATA_LEN;\r | |
684 | n_auto_repetitions = 1; // 1 frame\r | |
685 | auto_repetition_pause_len = 0;\r | |
686 | repeat_frame_pause_len = SAMSUNG_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 687 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
688 | break;\r | |
689 | }\r | |
690 | \r | |
691 | case IRMP_SAMSUNG32_PROTOCOL:\r | |
692 | {\r | |
a7054daf | 693 | startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;\r |
694 | startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN;\r | |
695 | pulse_1_len = SAMSUNG_PULSE_LEN;\r | |
696 | pause_1_len = SAMSUNG_1_PAUSE_LEN;\r | |
697 | pulse_0_len = SAMSUNG_PULSE_LEN;\r | |
698 | pause_0_len = SAMSUNG_0_PAUSE_LEN;\r | |
699 | has_stop_bit = SAMSUNG_STOP_BIT;\r | |
700 | complete_data_len = SAMSUNG32_COMPLETE_DATA_LEN;\r | |
701 | n_auto_repetitions = SAMSUNG32_FRAMES; // 2 frames\r | |
702 | auto_repetition_pause_len = SAMSUNG32_AUTO_REPETITION_PAUSE_LEN; // 47 ms pause\r | |
703 | repeat_frame_pause_len = SAMSUNG32_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 704 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
705 | break;\r | |
706 | }\r | |
707 | #endif\r | |
708 | #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r | |
709 | case IRMP_MATSUSHITA_PROTOCOL:\r | |
710 | {\r | |
a7054daf | 711 | startbit_pulse_len = MATSUSHITA_START_BIT_PULSE_LEN;\r |
712 | startbit_pause_len = MATSUSHITA_START_BIT_PAUSE_LEN;\r | |
713 | pulse_1_len = MATSUSHITA_PULSE_LEN;\r | |
714 | pause_1_len = MATSUSHITA_1_PAUSE_LEN;\r | |
715 | pulse_0_len = MATSUSHITA_PULSE_LEN;\r | |
716 | pause_0_len = MATSUSHITA_0_PAUSE_LEN;\r | |
717 | has_stop_bit = MATSUSHITA_STOP_BIT;\r | |
718 | complete_data_len = MATSUSHITA_COMPLETE_DATA_LEN;\r | |
719 | n_auto_repetitions = 1; // 1 frame\r | |
720 | auto_repetition_pause_len = 0;\r | |
721 | repeat_frame_pause_len = MATSUSHITA_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 722 | irsnd_set_freq (IRSND_FREQ_36_KHZ);\r |
723 | break;\r | |
724 | }\r | |
725 | #endif\r | |
726 | #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r | |
727 | case IRMP_RECS80_PROTOCOL:\r | |
728 | {\r | |
a7054daf | 729 | startbit_pulse_len = RECS80_START_BIT_PULSE_LEN;\r |
730 | startbit_pause_len = RECS80_START_BIT_PAUSE_LEN;\r | |
731 | pulse_1_len = RECS80_PULSE_LEN;\r | |
732 | pause_1_len = RECS80_1_PAUSE_LEN;\r | |
733 | pulse_0_len = RECS80_PULSE_LEN;\r | |
734 | pause_0_len = RECS80_0_PAUSE_LEN;\r | |
735 | has_stop_bit = RECS80_STOP_BIT;\r | |
736 | complete_data_len = RECS80_COMPLETE_DATA_LEN;\r | |
737 | n_auto_repetitions = 1; // 1 frame\r | |
738 | auto_repetition_pause_len = 0;\r | |
739 | repeat_frame_pause_len = RECS80_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 740 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
741 | break;\r | |
742 | }\r | |
743 | #endif\r | |
744 | #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r | |
745 | case IRMP_RECS80EXT_PROTOCOL:\r | |
746 | {\r | |
a7054daf | 747 | startbit_pulse_len = RECS80EXT_START_BIT_PULSE_LEN;\r |
748 | startbit_pause_len = RECS80EXT_START_BIT_PAUSE_LEN;\r | |
749 | pulse_1_len = RECS80EXT_PULSE_LEN;\r | |
750 | pause_1_len = RECS80EXT_1_PAUSE_LEN;\r | |
751 | pulse_0_len = RECS80EXT_PULSE_LEN;\r | |
752 | pause_0_len = RECS80EXT_0_PAUSE_LEN;\r | |
753 | has_stop_bit = RECS80EXT_STOP_BIT;\r | |
754 | complete_data_len = RECS80EXT_COMPLETE_DATA_LEN;\r | |
755 | n_auto_repetitions = 1; // 1 frame\r | |
756 | auto_repetition_pause_len = 0;\r | |
757 | repeat_frame_pause_len = RECS80EXT_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 758 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
759 | break;\r | |
760 | }\r | |
761 | #endif\r | |
762 | #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r | |
763 | case IRMP_RC5_PROTOCOL:\r | |
764 | {\r | |
a7054daf | 765 | startbit_pulse_len = RC5_BIT_LEN;\r |
766 | startbit_pause_len = RC5_BIT_LEN;\r | |
767 | pulse_len = RC5_BIT_LEN;\r | |
768 | pause_len = RC5_BIT_LEN;\r | |
769 | has_stop_bit = RC5_STOP_BIT;\r | |
770 | complete_data_len = RC5_COMPLETE_DATA_LEN;\r | |
771 | n_auto_repetitions = 1; // 1 frame\r | |
772 | auto_repetition_pause_len = 0;\r | |
773 | repeat_frame_pause_len = RC5_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 774 | irsnd_set_freq (IRSND_FREQ_36_KHZ);\r |
775 | break;\r | |
776 | }\r | |
777 | #endif\r | |
778 | #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r | |
779 | case IRMP_DENON_PROTOCOL:\r | |
780 | {\r | |
a7054daf | 781 | startbit_pulse_len = 0x00;\r |
782 | startbit_pause_len = 0x00;\r | |
783 | pulse_1_len = DENON_PULSE_LEN;\r | |
784 | pause_1_len = DENON_1_PAUSE_LEN;\r | |
785 | pulse_0_len = DENON_PULSE_LEN;\r | |
786 | pause_0_len = DENON_0_PAUSE_LEN;\r | |
787 | has_stop_bit = DENON_STOP_BIT;\r | |
788 | complete_data_len = DENON_COMPLETE_DATA_LEN;\r | |
789 | n_auto_repetitions = DENON_FRAMES; // 2 frames, 2nd with inverted command\r | |
790 | auto_repetition_pause_len = DENON_AUTO_REPETITION_PAUSE_LEN; // 65 ms pause after 1st frame\r | |
791 | repeat_frame_pause_len = DENON_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 792 | irsnd_set_freq (IRSND_FREQ_32_KHZ);\r |
793 | break;\r | |
794 | }\r | |
795 | #endif\r | |
796 | #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r | |
797 | case IRMP_NUBERT_PROTOCOL:\r | |
798 | {\r | |
a7054daf | 799 | startbit_pulse_len = NUBERT_START_BIT_PULSE_LEN;\r |
800 | startbit_pause_len = NUBERT_START_BIT_PAUSE_LEN;\r | |
801 | pulse_1_len = NUBERT_1_PULSE_LEN;\r | |
802 | pause_1_len = NUBERT_1_PAUSE_LEN;\r | |
803 | pulse_0_len = NUBERT_0_PULSE_LEN;\r | |
804 | pause_0_len = NUBERT_0_PAUSE_LEN;\r | |
805 | has_stop_bit = NUBERT_STOP_BIT;\r | |
806 | complete_data_len = NUBERT_COMPLETE_DATA_LEN;\r | |
807 | n_auto_repetitions = NUBERT_FRAMES; // 2 frames\r | |
808 | auto_repetition_pause_len = NUBERT_AUTO_REPETITION_PAUSE_LEN; // 35 ms pause\r | |
809 | repeat_frame_pause_len = NUBERT_FRAME_REPEAT_PAUSE_LEN;\r | |
4225a882 | 810 | irsnd_set_freq (IRSND_FREQ_36_KHZ);\r |
811 | break;\r | |
812 | }\r | |
5481e9cd | 813 | #endif\r |
814 | #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r | |
815 | case IRMP_BANG_OLUFSEN_PROTOCOL:\r | |
816 | {\r | |
a7054daf | 817 | startbit_pulse_len = BANG_OLUFSEN_START_BIT1_PULSE_LEN;\r |
818 | startbit_pause_len = BANG_OLUFSEN_START_BIT1_PAUSE_LEN;\r | |
819 | pulse_1_len = BANG_OLUFSEN_PULSE_LEN;\r | |
820 | pause_1_len = BANG_OLUFSEN_1_PAUSE_LEN;\r | |
821 | pulse_0_len = BANG_OLUFSEN_PULSE_LEN;\r | |
822 | pause_0_len = BANG_OLUFSEN_0_PAUSE_LEN;\r | |
823 | has_stop_bit = BANG_OLUFSEN_STOP_BIT;\r | |
824 | complete_data_len = BANG_OLUFSEN_COMPLETE_DATA_LEN;\r | |
825 | n_auto_repetitions = 1; // 1 frame\r | |
826 | auto_repetition_pause_len = 0;\r | |
827 | repeat_frame_pause_len = BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN;\r | |
828 | last_bit_value = 0;\r | |
5481e9cd | 829 | irsnd_set_freq (IRSND_FREQ_455_KHZ);\r |
830 | break;\r | |
831 | }\r | |
5b437ff6 | 832 | #endif\r |
833 | #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r | |
834 | case IRMP_GRUNDIG_PROTOCOL:\r | |
835 | {\r | |
a7054daf | 836 | startbit_pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r |
837 | startbit_pause_len = GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN;\r | |
838 | pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r | |
839 | pause_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r | |
840 | has_stop_bit = GRUNDIG_OR_NOKIA_STOP_BIT;\r | |
841 | complete_data_len = GRUNDIG_COMPLETE_DATA_LEN;\r | |
842 | n_auto_repetitions = GRUNDIG_FRAMES; // 2 frames\r | |
843 | auto_repetition_pause_len = GRUNDIG_AUTO_REPETITION_PAUSE_LEN; // 20m sec pause\r | |
844 | repeat_frame_pause_len = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause\r | |
d155e9ab | 845 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
a7054daf | 846 | \r |
d155e9ab | 847 | break;\r |
848 | }\r | |
849 | #endif\r | |
850 | #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r | |
851 | case IRMP_NOKIA_PROTOCOL:\r | |
852 | {\r | |
a7054daf | 853 | startbit_pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r |
854 | startbit_pause_len = GRUNDIG_OR_NOKIA_PRE_PAUSE_LEN;\r | |
855 | pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r | |
856 | pause_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r | |
857 | has_stop_bit = GRUNDIG_OR_NOKIA_STOP_BIT;\r | |
858 | complete_data_len = NOKIA_COMPLETE_DATA_LEN;\r | |
859 | n_auto_repetitions = NOKIA_FRAMES; // 2 frames\r | |
860 | auto_repetition_pause_len = NOKIA_AUTO_REPETITION_PAUSE_LEN; // 20 msec pause\r | |
861 | repeat_frame_pause_len = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause\r | |
d155e9ab | 862 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r |
5b437ff6 | 863 | break;\r |
864 | }\r | |
a7054daf | 865 | #endif\r |
866 | #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r | |
867 | case IRMP_SIEMENS_PROTOCOL:\r | |
868 | {\r | |
869 | startbit_pulse_len = SIEMENS_BIT_LEN;\r | |
870 | startbit_pause_len = SIEMENS_BIT_LEN;\r | |
871 | pulse_len = SIEMENS_BIT_LEN;\r | |
872 | pause_len = SIEMENS_BIT_LEN;\r | |
873 | has_stop_bit = SIEMENS_STOP_BIT;\r | |
874 | complete_data_len = SIEMENS_COMPLETE_DATA_LEN - 1;\r | |
875 | n_auto_repetitions = 1; // 1 frame\r | |
876 | auto_repetition_pause_len = 0;\r | |
877 | repeat_frame_pause_len = SIEMENS_FRAME_REPEAT_PAUSE_LEN;\r | |
878 | irsnd_set_freq (IRSND_FREQ_36_KHZ);\r | |
879 | break;\r | |
880 | }\r | |
b5ea7869 | 881 | #endif\r |
882 | #if IRSND_SUPPORT_FDC_PROTOCOL == 1\r | |
883 | case IRMP_FDC_PROTOCOL:\r | |
884 | {\r | |
885 | startbit_pulse_len = FDC_START_BIT_PULSE_LEN;\r | |
886 | startbit_pause_len = FDC_START_BIT_PAUSE_LEN;\r | |
887 | complete_data_len = FDC_COMPLETE_DATA_LEN;\r | |
888 | pulse_1_len = FDC_PULSE_LEN;\r | |
889 | pause_1_len = FDC_1_PAUSE_LEN;\r | |
890 | pulse_0_len = FDC_PULSE_LEN;\r | |
891 | pause_0_len = FDC_0_PAUSE_LEN;\r | |
892 | has_stop_bit = FDC_STOP_BIT;\r | |
893 | n_auto_repetitions = 1; // 1 frame\r | |
894 | auto_repetition_pause_len = 0;\r | |
895 | repeat_frame_pause_len = FDC_FRAME_REPEAT_PAUSE_LEN;\r | |
896 | irsnd_set_freq (IRSND_FREQ_38_KHZ);\r | |
897 | break;\r | |
898 | }\r | |
4225a882 | 899 | #endif\r |
900 | default:\r | |
901 | {\r | |
902 | irsnd_busy = FALSE;\r | |
903 | break;\r | |
904 | }\r | |
905 | }\r | |
906 | }\r | |
907 | }\r | |
908 | \r | |
909 | if (irsnd_busy)\r | |
910 | {\r | |
911 | new_frame = FALSE;\r | |
a7054daf | 912 | \r |
4225a882 | 913 | switch (irsnd_protocol)\r |
914 | {\r | |
915 | #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1\r | |
916 | case IRMP_SIRCS_PROTOCOL:\r | |
917 | #endif\r | |
918 | #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r | |
919 | case IRMP_NEC_PROTOCOL:\r | |
920 | #endif\r | |
921 | #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r | |
922 | case IRMP_SAMSUNG_PROTOCOL:\r | |
923 | case IRMP_SAMSUNG32_PROTOCOL:\r | |
924 | #endif\r | |
925 | #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1\r | |
926 | case IRMP_MATSUSHITA_PROTOCOL:\r | |
927 | #endif\r | |
928 | #if IRSND_SUPPORT_RECS80_PROTOCOL == 1\r | |
929 | case IRMP_RECS80_PROTOCOL:\r | |
930 | #endif\r | |
931 | #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1\r | |
932 | case IRMP_RECS80EXT_PROTOCOL:\r | |
933 | #endif\r | |
934 | #if IRSND_SUPPORT_DENON_PROTOCOL == 1\r | |
935 | case IRMP_DENON_PROTOCOL:\r | |
936 | #endif\r | |
937 | #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1\r | |
938 | case IRMP_NUBERT_PROTOCOL:\r | |
5481e9cd | 939 | #endif\r |
940 | #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r | |
941 | case IRMP_BANG_OLUFSEN_PROTOCOL:\r | |
4225a882 | 942 | #endif\r |
b5ea7869 | 943 | #if IRSND_SUPPORT_NEC_PROTOCOL == 1\r |
944 | case IRMP_FDC_PROTOCOL:\r | |
945 | #endif\r | |
a7054daf | 946 | \r |
947 | \r | |
948 | #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \\r | |
949 | IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || \\r | |
b5ea7869 | 950 | IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1\r |
4225a882 | 951 | {\r |
5481e9cd | 952 | if (pulse_counter == 0)\r |
4225a882 | 953 | {\r |
5481e9cd | 954 | if (current_bit == 0xFF) // send start bit\r |
955 | {\r | |
956 | pulse_len = startbit_pulse_len;\r | |
957 | pause_len = startbit_pause_len;\r | |
958 | }\r | |
959 | else if (current_bit < complete_data_len) // send n'th bit\r | |
4225a882 | 960 | {\r |
5481e9cd | 961 | #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1\r |
962 | if (irsnd_protocol == IRMP_SAMSUNG_PROTOCOL)\r | |
4225a882 | 963 | {\r |
5481e9cd | 964 | if (current_bit < SAMSUNG_ADDRESS_LEN) // send address bits\r |
965 | {\r | |
966 | pulse_len = SAMSUNG_PULSE_LEN;\r | |
967 | pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r | |
968 | SAMSUNG_1_PAUSE_LEN : SAMSUNG_0_PAUSE_LEN;\r | |
969 | }\r | |
970 | else if (current_bit == SAMSUNG_ADDRESS_LEN) // send SYNC bit (16th bit)\r | |
971 | {\r | |
972 | pulse_len = SAMSUNG_PULSE_LEN;\r | |
973 | pause_len = SAMSUNG_START_BIT_PAUSE_LEN;\r | |
974 | }\r | |
975 | else if (current_bit < SAMSUNG_COMPLETE_DATA_LEN) // send n'th bit\r | |
976 | {\r | |
977 | uint8_t cur_bit = current_bit - 1; // sync skipped, offset = -1 !\r | |
978 | \r | |
979 | pulse_len = SAMSUNG_PULSE_LEN;\r | |
980 | pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r | |
981 | SAMSUNG_1_PAUSE_LEN : SAMSUNG_0_PAUSE_LEN;\r | |
982 | }\r | |
4225a882 | 983 | }\r |
5481e9cd | 984 | else\r |
985 | #endif\r | |
986 | \r | |
987 | #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1\r | |
988 | if (irsnd_protocol == IRMP_BANG_OLUFSEN_PROTOCOL)\r | |
4225a882 | 989 | {\r |
5481e9cd | 990 | if (current_bit == 0) // send 2nd start bit\r |
991 | {\r | |
992 | pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r | |
993 | pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN;\r | |
994 | }\r | |
995 | else if (current_bit == 1) // send 3rd start bit\r | |
996 | {\r | |
997 | pulse_len = BANG_OLUFSEN_START_BIT3_PULSE_LEN;\r | |
998 | pause_len = BANG_OLUFSEN_START_BIT3_PAUSE_LEN;\r | |
999 | }\r | |
1000 | else if (current_bit == 2) // send 4th start bit\r | |
1001 | {\r | |
1002 | pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;\r | |
1003 | pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN;\r | |
1004 | }\r | |
1005 | else if (current_bit == 19) // send trailer bit\r | |
1006 | {\r | |
1007 | pulse_len = BANG_OLUFSEN_PULSE_LEN;\r | |
1008 | pause_len = BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN;\r | |
1009 | }\r | |
1010 | else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN) // send n'th bit\r | |
1011 | {\r | |
1012 | uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;\r | |
1013 | pulse_len = BANG_OLUFSEN_PULSE_LEN;\r | |
1014 | \r | |
1015 | if (cur_bit_value == last_bit_value)\r | |
1016 | {\r | |
1017 | pause_len = BANG_OLUFSEN_R_PAUSE_LEN;\r | |
1018 | }\r | |
1019 | else\r | |
1020 | {\r | |
1021 | pause_len = cur_bit_value ? BANG_OLUFSEN_1_PAUSE_LEN : BANG_OLUFSEN_0_PAUSE_LEN;\r | |
1022 | last_bit_value = cur_bit_value;\r | |
1023 | }\r | |
1024 | }\r | |
4225a882 | 1025 | }\r |
5481e9cd | 1026 | else\r |
1027 | #endif\r | |
1028 | if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))\r | |
4225a882 | 1029 | {\r |
5481e9cd | 1030 | pulse_len = pulse_1_len;\r |
1031 | pause_len = pause_1_len;\r | |
1032 | }\r | |
1033 | else\r | |
1034 | {\r | |
1035 | pulse_len = pulse_0_len;\r | |
1036 | pause_len = pause_0_len;\r | |
4225a882 | 1037 | }\r |
1038 | }\r | |
5481e9cd | 1039 | else if (has_stop_bit) // send stop bit\r |
4225a882 | 1040 | {\r |
1041 | pulse_len = pulse_0_len;\r | |
4225a882 | 1042 | \r |
a7054daf | 1043 | if (auto_repetition_counter < n_auto_repetitions)\r |
5481e9cd | 1044 | {\r |
1045 | pause_len = pause_0_len;\r | |
1046 | }\r | |
1047 | else\r | |
1048 | {\r | |
1049 | pause_len = 255; // last frame: pause of 255\r | |
1050 | }\r | |
4225a882 | 1051 | }\r |
1052 | }\r | |
1053 | \r | |
1054 | if (pulse_counter < pulse_len)\r | |
1055 | {\r | |
1056 | if (pulse_counter == 0)\r | |
1057 | {\r | |
1058 | irsnd_on ();\r | |
1059 | }\r | |
1060 | pulse_counter++;\r | |
1061 | }\r | |
1062 | else if (pause_counter < pause_len)\r | |
1063 | {\r | |
1064 | if (pause_counter == 0)\r | |
1065 | {\r | |
1066 | irsnd_off ();\r | |
1067 | }\r | |
1068 | pause_counter++;\r | |
1069 | }\r | |
1070 | else\r | |
1071 | {\r | |
1072 | current_bit++;\r | |
1073 | \r | |
1074 | if (current_bit >= complete_data_len + has_stop_bit)\r | |
1075 | {\r | |
1076 | current_bit = 0xFF;\r | |
a7054daf | 1077 | auto_repetition_counter++;\r |
4225a882 | 1078 | \r |
a7054daf | 1079 | if (auto_repetition_counter == n_auto_repetitions)\r |
4225a882 | 1080 | {\r |
1081 | irsnd_busy = FALSE;\r | |
a7054daf | 1082 | auto_repetition_counter = 0;\r |
4225a882 | 1083 | }\r |
1084 | new_frame = TRUE;\r | |
1085 | }\r | |
1086 | \r | |
1087 | pulse_counter = 0;\r | |
1088 | pause_counter = 0;\r | |
1089 | }\r | |
1090 | break;\r | |
1091 | }\r | |
a7054daf | 1092 | #endif\r |
1093 | \r | |
4225a882 | 1094 | #if IRSND_SUPPORT_RC5_PROTOCOL == 1\r |
1095 | case IRMP_RC5_PROTOCOL:\r | |
a7054daf | 1096 | #endif\r |
1097 | #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1\r | |
1098 | case IRMP_SIEMENS_PROTOCOL:\r | |
1099 | #endif\r | |
1100 | #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1\r | |
1101 | case IRMP_GRUNDIG_PROTOCOL:\r | |
1102 | #endif\r | |
1103 | #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r | |
1104 | case IRMP_NOKIA_PROTOCOL:\r | |
1105 | #endif\r | |
4225a882 | 1106 | \r |
a7054daf | 1107 | #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r |
1108 | {\r | |
1109 | if (pulse_counter == pulse_len && pause_counter == pause_len)\r | |
4225a882 | 1110 | {\r |
a7054daf | 1111 | current_bit++;\r |
4225a882 | 1112 | \r |
a7054daf | 1113 | if (current_bit >= complete_data_len)\r |
4225a882 | 1114 | {\r |
a7054daf | 1115 | current_bit = 0xFF;\r |
1116 | \r | |
1117 | #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r | |
1118 | if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r | |
4225a882 | 1119 | {\r |
a7054daf | 1120 | auto_repetition_counter++;\r |
1121 | \r | |
1122 | if (repeat_counter > 0)\r | |
1123 | { // set 117 msec pause time\r | |
1124 | auto_repetition_pause_len = GRUNDIG_OR_NOKIA_FRAME_REPEAT_PAUSE_LEN;\r | |
1125 | }\r | |
1126 | \r | |
1127 | if (repeat_counter < n_repeat_frames) // tricky: repeat n info frames per auto repetition before sending last stop frame\r | |
1128 | {\r | |
1129 | n_auto_repetitions++; // increment number of auto repetitions\r | |
1130 | repeat_counter++;\r | |
1131 | }\r | |
1132 | else if (auto_repetition_counter == n_auto_repetitions)\r | |
1133 | {\r | |
1134 | irsnd_busy = FALSE;\r | |
1135 | auto_repetition_counter = 0;\r | |
1136 | }\r | |
4225a882 | 1137 | }\r |
a7054daf | 1138 | else\r |
1139 | #endif\r | |
4225a882 | 1140 | {\r |
a7054daf | 1141 | irsnd_busy = FALSE;\r |
4225a882 | 1142 | }\r |
4225a882 | 1143 | \r |
4225a882 | 1144 | new_frame = TRUE;\r |
1145 | irsnd_off ();\r | |
1146 | }\r | |
1147 | \r | |
1148 | pulse_counter = 0;\r | |
1149 | pause_counter = 0;\r | |
1150 | }\r | |
5b437ff6 | 1151 | \r |
a7054daf | 1152 | if (! new_frame)\r |
5b437ff6 | 1153 | {\r |
a7054daf | 1154 | uint8_t first_pulse;\r |
5b437ff6 | 1155 | \r |
a7054daf | 1156 | #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r |
1157 | if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)\r | |
5b437ff6 | 1158 | {\r |
a7054daf | 1159 | if (current_bit == 0xFF || // start bit of start-frame\r |
1160 | (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL && current_bit == 15) || // start bit of info-frame (Grundig)\r | |
1161 | (irsnd_protocol == IRMP_NOKIA_PROTOCOL && (current_bit == 23 || current_bit == 47))) // start bit of info- or stop-frame (Nokia)\r | |
5b437ff6 | 1162 | {\r |
a7054daf | 1163 | pulse_len = startbit_pulse_len;\r |
1164 | pause_len = startbit_pause_len;\r | |
1165 | first_pulse = TRUE;\r | |
5b437ff6 | 1166 | }\r |
a7054daf | 1167 | else // send n'th bit\r |
5b437ff6 | 1168 | {\r |
a7054daf | 1169 | pulse_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r |
1170 | pause_len = GRUNDIG_OR_NOKIA_BIT_LEN;\r | |
1171 | first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r | |
5b437ff6 | 1172 | }\r |
5b437ff6 | 1173 | }\r |
a7054daf | 1174 | else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_SIEMENS_PROTOCOL)\r |
1175 | #endif\r | |
5b437ff6 | 1176 | {\r |
a7054daf | 1177 | if (current_bit == 0xFF) // 1 start bit\r |
1178 | {\r | |
1179 | first_pulse = TRUE;\r | |
1180 | }\r | |
1181 | else // send n'th bit\r | |
1182 | {\r | |
1183 | first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r | |
1184 | }\r | |
5b437ff6 | 1185 | \r |
a7054daf | 1186 | if (irsnd_protocol == IRMP_RC5_PROTOCOL)\r |
1187 | {\r | |
1188 | first_pulse = first_pulse ? FALSE : TRUE;\r | |
1189 | }\r | |
1190 | }\r | |
5b437ff6 | 1191 | \r |
1192 | if (first_pulse)\r | |
1193 | {\r | |
a7054daf | 1194 | if (pulse_counter < pulse_len)\r |
5b437ff6 | 1195 | {\r |
1196 | if (pulse_counter == 0)\r | |
1197 | {\r | |
1198 | irsnd_on ();\r | |
1199 | }\r | |
1200 | pulse_counter++;\r | |
1201 | }\r | |
a7054daf | 1202 | else // if (pause_counter < pause_len)\r |
5b437ff6 | 1203 | {\r |
1204 | if (pause_counter == 0)\r | |
1205 | {\r | |
1206 | irsnd_off ();\r | |
1207 | }\r | |
1208 | pause_counter++;\r | |
1209 | }\r | |
5b437ff6 | 1210 | }\r |
1211 | else\r | |
1212 | {\r | |
a7054daf | 1213 | if (pause_counter < pause_len)\r |
5b437ff6 | 1214 | {\r |
1215 | if (pause_counter == 0)\r | |
1216 | {\r | |
1217 | irsnd_off ();\r | |
1218 | }\r | |
1219 | pause_counter++;\r | |
1220 | }\r | |
a7054daf | 1221 | else // if (pulse_counter < pulse_len)\r |
5b437ff6 | 1222 | {\r |
1223 | if (pulse_counter == 0)\r | |
1224 | {\r | |
1225 | irsnd_on ();\r | |
1226 | }\r | |
1227 | pulse_counter++;\r | |
1228 | }\r | |
5b437ff6 | 1229 | }\r |
1230 | }\r | |
1231 | break;\r | |
1232 | }\r | |
a7054daf | 1233 | #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1\r |
5b437ff6 | 1234 | \r |
4225a882 | 1235 | default:\r |
1236 | {\r | |
1237 | irsnd_busy = FALSE;\r | |
1238 | break;\r | |
1239 | }\r | |
1240 | }\r | |
1241 | }\r | |
a7054daf | 1242 | \r |
1243 | if (! irsnd_busy)\r | |
1244 | {\r | |
1245 | if (repeat_counter < n_repeat_frames)\r | |
1246 | {\r | |
1247 | repeat_counter++;\r | |
1248 | irsnd_busy = TRUE;\r | |
1249 | }\r | |
1250 | else\r | |
1251 | {\r | |
1252 | n_repeat_frames = 0;\r | |
1253 | repeat_counter = 0;\r | |
1254 | }\r | |
1255 | }\r | |
4225a882 | 1256 | }\r |
1257 | \r | |
1258 | #ifdef DEBUG\r | |
1259 | if (irsnd_is_on)\r | |
1260 | {\r | |
1261 | putchar ('0');\r | |
1262 | }\r | |
1263 | else\r | |
1264 | {\r | |
1265 | putchar ('1');\r | |
1266 | }\r | |
1267 | #endif\r | |
1268 | \r | |
1269 | return irsnd_busy;\r | |
1270 | }\r | |
1271 | \r | |
1272 | #ifdef DEBUG\r | |
1273 | \r | |
1274 | // main function - for unix/linux + windows only!\r | |
1275 | // AVR: see main.c!\r | |
1276 | // Compile it under linux with:\r | |
1277 | // cc irsnd.c -o irsnd\r | |
1278 | //\r | |
1279 | // usage: ./irsnd protocol hex-address hex-command >filename\r | |
1280 | \r | |
1281 | int\r | |
1282 | main (int argc, char ** argv)\r | |
1283 | {\r | |
1284 | int idx;\r | |
4225a882 | 1285 | int protocol;\r |
1286 | int address;\r | |
1287 | int command;\r | |
4225a882 | 1288 | IRMP_DATA irmp_data;\r |
1289 | \r | |
a7054daf | 1290 | if (argc != 4 && argc != 5)\r |
4225a882 | 1291 | {\r |
a7054daf | 1292 | fprintf (stderr, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv[0]);\r |
4225a882 | 1293 | return 1;\r |
1294 | }\r | |
1295 | \r | |
1296 | if (sscanf (argv[1], "%d", &protocol) == 1 &&\r | |
1297 | sscanf (argv[2], "%x", &address) == 1 &&\r | |
1298 | sscanf (argv[3], "%x", &command) == 1)\r | |
1299 | {\r | |
1300 | irmp_data.protocol = protocol;\r | |
1301 | irmp_data.address = address;\r | |
1302 | irmp_data.command = command;\r | |
1303 | \r | |
a7054daf | 1304 | if (argc == 5)\r |
1305 | {\r | |
1306 | irmp_data.flags = atoi (argv[4]);\r | |
1307 | }\r | |
1308 | else\r | |
1309 | {\r | |
1310 | irmp_data.flags = 0;\r | |
1311 | }\r | |
1312 | \r | |
4225a882 | 1313 | irsnd_init ();\r |
1314 | \r | |
879b06c2 | 1315 | (void) irsnd_send_data (&irmp_data, TRUE);\r |
4225a882 | 1316 | \r |
a7054daf | 1317 | while (irsnd_busy)\r |
1318 | {\r | |
1319 | irsnd_ISR ();\r | |
1320 | }\r | |
1321 | for (idx = 0; idx < 20; idx++)\r | |
1322 | {\r | |
1323 | irsnd_ISR ();\r | |
4225a882 | 1324 | }\r |
1325 | \r | |
1326 | putchar ('\n');\r | |
1327 | }\r | |
1328 | else\r | |
1329 | {\r | |
1330 | fprintf (stderr, "%s: wrong arguments\n", argv[0]);\r | |
1331 | return 1;\r | |
1332 | }\r | |
1333 | return 0;\r | |
1334 | }\r | |
1335 | \r | |
1336 | #endif // DEBUG\r |