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