Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1797 | - | 1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
||
3 | #######################################################################################*/ |
||
4 | |||
5 | #include "Spektrum.h" |
||
6 | #include "main.h" |
||
7 | |||
8 | unsigned char SpektrumTimer = 0; |
||
9 | |||
10 | // Achtung: RECEIVER_SPEKTRUM_DX7EXP oder RECEIVER_SPEKTRUM_DX8EXP wird in der main.h gesetzt |
||
11 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
||
12 | unsigned char s_excnt = 0; // Bitcounter for Spektrum-Expander |
||
13 | unsigned char s_exparity = 0; // Parity Bit for Spektrum-Expander |
||
14 | signed char s_exdata[11]; // Data for Spektrum-Expander |
||
15 | |||
16 | void s_update(unsigned char channel, signed int value) // Channel-Diff numbercrunching and finally assign new stickvalue to PPM_in |
||
17 | { |
||
18 | if(SenderOkay >= 180) PPM_diff[channel] = ((value - PPM_in[channel]) / 3) * 3; |
||
19 | else PPM_diff[channel] = 0; |
||
20 | PPM_in[channel] = value; |
||
21 | } |
||
22 | #endif |
||
23 | |||
24 | //--------------------------------------------------------------// |
||
25 | //--------------------------------------------------------------// |
||
26 | /* |
||
27 | void SpektrumBinding(void) |
||
28 | { |
||
29 | unsigned int timerTimeout = SetDelay(10000); // Timeout 10 sec. |
||
30 | unsigned char connected = 0; |
||
31 | unsigned int delaycounter; |
||
32 | |||
33 | UCSR1B &= ~(1 << RXCIE1); // disable rx-interrupt |
||
34 | UCSR1B &= ~(1<<RXEN1); // disable Uart-Rx |
||
35 | PORTD &= ~(1 << PORTD2); // disable pull-up |
||
36 | |||
37 | printf("\n\rPlease connect Spektrum receiver for binding NOW..."); |
||
38 | |||
39 | while(!CheckDelay(timerTimeout)) |
||
40 | { |
||
41 | if (PIND & (1 << PORTD2)) { timerTimeout = SetDelay(90); connected = 1; break; } |
||
42 | } |
||
43 | |||
44 | if (connected) |
||
45 | { |
||
46 | |||
47 | printf("ok.\n\r"); |
||
48 | DDRD |= (1 << DDD2); // Rx as output |
||
49 | |||
50 | while(!CheckDelay(timerTimeout)); // delay after startup of RX |
||
51 | for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2); |
||
52 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
53 | |||
54 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
||
55 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
56 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
||
57 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
58 | |||
59 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
||
60 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
61 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
||
62 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
63 | |||
64 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
||
65 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
66 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
||
67 | |||
68 | } |
||
69 | else |
||
70 | { printf("Timeout.\n\r"); |
||
71 | |||
72 | |||
73 | } |
||
74 | |||
75 | DDRD &= ~(1 << DDD2); // RX as input |
||
76 | PORTD &= ~(1 << PORTD2); |
||
77 | |||
78 | SpektrumUartInit(); // init Uart again |
||
79 | } |
||
80 | */ |
||
81 | //############################################################################ |
||
82 | // USART1 initialisation from killagreg |
||
83 | void SpektrumUartInit(void) |
||
84 | //############################################################################ |
||
85 | { |
||
86 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
||
87 | // USART1 Control and Status Register A, B, C and baud rate register |
||
88 | uint8_t sreg = SREG; |
||
89 | |||
90 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
||
91 | |||
92 | // disable all interrupts before reconfiguration |
||
93 | cli(); |
||
94 | // disable RX-Interrupt |
||
95 | UCSR1B &= ~(1 << RXCIE1); |
||
96 | // disable TX-Interrupt |
||
97 | UCSR1B &= ~(1 << TXCIE1); |
||
98 | // disable DRE-Interrupt |
||
99 | UCSR1B &= ~(1 << UDRIE1); |
||
100 | // set direction of RXD1 and TXD1 pins |
||
101 | // set RXD1 (PD2) as an input pin |
||
102 | PORTD |= (1 << PORTD2); |
||
103 | DDRD &= ~(1 << DDD2); |
||
104 | |||
105 | // set TXD1 (PD3) as an output pin |
||
106 | PORTD |= (1 << PORTD3); |
||
107 | DDRD |= (1 << DDD3); |
||
108 | |||
109 | // USART0 Baud Rate Register |
||
110 | // set clock divider |
||
111 | UBRR1H = (uint8_t)(ubrr>>8); |
||
112 | UBRR1L = (uint8_t)ubrr; |
||
113 | // enable double speed operation |
||
114 | UCSR1A |= (1 << U2X1); |
||
115 | // enable receiver and transmitter |
||
116 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
||
117 | |||
118 | UCSR1B = (1<<RXEN1); |
||
119 | // set asynchronous mode |
||
120 | UCSR1C &= ~(1 << UMSEL11); |
||
121 | UCSR1C &= ~(1 << UMSEL10); |
||
122 | // no parity |
||
123 | UCSR1C &= ~(1 << UPM11); |
||
124 | UCSR1C &= ~(1 << UPM10); |
||
125 | // 1 stop bit |
||
126 | UCSR1C &= ~(1 << USBS1); |
||
127 | // 8-bit |
||
128 | UCSR1B &= ~(1 << UCSZ12); |
||
129 | UCSR1C |= (1 << UCSZ11); |
||
130 | UCSR1C |= (1 << UCSZ10); |
||
131 | // flush receive buffer explicit |
||
132 | while(UCSR1A & (1<<RXC1)) UDR1; |
||
133 | // enable RX-interrupts at the end |
||
134 | UCSR1B |= (1 << RXCIE1); |
||
135 | // -- End of USART1 initialisation |
||
136 | // restore global interrupt flags |
||
137 | |||
138 | SREG = sreg; |
||
139 | return; |
||
140 | } |
||
141 | |||
142 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
143 | // + Copyright (c) Rainer Walther |
||
144 | // + RC-routines from original MK rc.c (c) H&I |
||
145 | // + Useful infos from Walter: http://www.rcgroups.com/forums/showthread.php?t=714299&page=2 |
||
146 | // + only for non-profit use |
||
147 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
148 | // |
||
149 | // 20080808 rw Modified for Spektrum AR6100 (PPM) |
||
150 | // 20080823 rw Add Spektrum satellite receiver on USART1 (644P only) |
||
151 | // 20081213 rw Add support for Spektrum DS9 Air-Tx-Module (9 channels) |
||
152 | // Replace AR6100-coding with original composit-signal routines |
||
153 | // |
||
154 | // --- |
||
155 | // Entweder Summensignal ODER Spektrum-Receiver anschließen. Nicht beides gleichzeitig betreiben! |
||
156 | // Binding is not implemented. Bind with external Receiver. |
||
157 | // Servo output J3, J4, J5 not serviced |
||
158 | // |
||
159 | // Anschuß Spektrum Receiver |
||
160 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
||
161 | // Schwarz: GND |
||
162 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
||
163 | // |
||
164 | // --- |
||
165 | // Satellite-Reciever connected on USART1: |
||
166 | // |
||
167 | // DX7/DX6i: One data-frame at 115200 baud every 22ms. |
||
168 | // DX7se: One data-frame at 115200 baud every 11ms. |
||
169 | // byte1: unknown |
||
170 | // byte2: unknown |
||
171 | // byte3: and byte4: channel data (FLT-Mode) |
||
172 | // byte5: and byte6: channel data (Roll) |
||
173 | // byte7: and byte8: channel data (Nick) |
||
174 | // byte9: and byte10: channel data (Gier) |
||
175 | // byte11: and byte12: channel data (Gear Switch) |
||
176 | // byte13: and byte14: channel data (Gas) |
||
177 | // byte15: and byte16: channel data (AUX2) |
||
178 | // |
||
179 | // DS9 (9 Channel): One data-frame at 115200 baud every 11ms, alternating frame 1/2 for CH1-7 / CH8-9 |
||
180 | // 1st Frame: |
||
181 | // byte1: unknown |
||
182 | // byte2: unknown |
||
183 | // byte3: and byte4: channel data |
||
184 | // byte5: and byte6: channel data |
||
185 | // byte7: and byte8: channel data |
||
186 | // byte9: and byte10: channel data |
||
187 | // byte11: and byte12: channel data |
||
188 | // byte13: and byte14: channel data |
||
189 | // byte15: and byte16: channel data |
||
190 | // 2nd Frame: |
||
191 | // byte1: unknown |
||
192 | // byte2: unknown |
||
193 | // byte3: and byte4: channel data |
||
194 | // byte5: and byte6: channel data |
||
195 | // byte7: and byte8: 0xffff |
||
196 | // byte9: and byte10: 0xffff |
||
197 | // byte11: and byte12: 0xffff |
||
198 | // byte13: and byte14: 0xffff |
||
199 | // byte15: and byte16: 0xffff |
||
200 | // |
||
201 | // Each channel data (16 bit= 2byte, first msb, second lsb) is arranged as: |
||
202 | // |
||
203 | // Bits: F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 |
||
204 | // |
||
205 | // 0 means a '0' bit |
||
206 | // F: 1 = indicates beginning of 2nd frame for CH8-9 (DS9 only) |
||
207 | // C3 to C0 is the channel number. 0 to 9 (4 bit, as assigned in the transmitter) |
||
208 | // D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for 100% transmitter-travel |
||
209 | // |
||
210 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
211 | |||
212 | #define MIN_FRAMEGAP 68 // 7ms |
||
213 | #define MAX_BYTEGAP 3 // 310us |
||
214 | |||
215 | |||
216 | //############################################################################ |
||
217 | // Wird im UART-Interrupt aufgerufen |
||
218 | //############################################################################ |
||
219 | void SpektrumParser(unsigned char c) |
||
220 | { |
||
221 | static unsigned char Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0; |
||
222 | unsigned int Channel, index = 0; |
||
223 | signed int signal = 0, tmp; |
||
224 | int bCheckDelay; |
||
225 | // c = UDR1; // get data byte |
||
226 | if(ReSync == 1) |
||
227 | { |
||
228 | // wait for beginning of new frame |
||
229 | ReSync = 0; |
||
230 | SpektrumTimer = MIN_FRAMEGAP; |
||
231 | FrameCnt = 0; |
||
232 | Sync = 0; |
||
233 | ByteHigh = 0; |
||
234 | } |
||
235 | else |
||
236 | { |
||
237 | if(!SpektrumTimer) bCheckDelay = 1; else bCheckDelay = 0;//CheckDelay(FrameTimer); |
||
238 | if ( Sync == 0 ) |
||
239 | { |
||
240 | if(bCheckDelay) |
||
241 | { |
||
242 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
||
243 | // Zeichen ignorieren, da Bedeutung unbekannt |
||
244 | Sync = 1; |
||
245 | FrameCnt ++; |
||
246 | SpektrumTimer = MAX_BYTEGAP; |
||
247 | } |
||
248 | else |
||
249 | { |
||
250 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
||
251 | // warten auf erstes Sync-Zeichen |
||
252 | SpektrumTimer = MIN_FRAMEGAP; |
||
253 | FrameCnt = 0; |
||
254 | Sync = 0; |
||
255 | ByteHigh = 0; |
||
256 | } |
||
257 | } |
||
258 | else if((Sync == 1) && !bCheckDelay) |
||
259 | { |
||
260 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
||
261 | Sync = 2; |
||
262 | FrameCnt ++; |
||
263 | SpektrumTimer = MAX_BYTEGAP; |
||
264 | } |
||
265 | else if((Sync == 2) && !bCheckDelay) |
||
266 | { |
||
267 | SpektrumTimer = MAX_BYTEGAP; |
||
268 | // Datenbyte high |
||
269 | ByteHigh = c; |
||
270 | if (FrameCnt == 2) |
||
271 | { |
||
272 | // is 1st Byte of Channel-data |
||
273 | // Frame 1 with Channel 1-7 comming next |
||
274 | Frame2 = 0; |
||
275 | if(ByteHigh & 0x80) |
||
276 | { |
||
277 | // DS9: Frame 2 with Channel 8-9 comming next |
||
278 | Frame2 = 1; |
||
279 | } |
||
280 | } |
||
281 | Sync = 3; |
||
282 | FrameCnt ++; |
||
283 | } |
||
284 | else if((Sync == 3) && !bCheckDelay) |
||
285 | { |
||
286 | // Datenbyte low |
||
287 | // High-Byte for next channel comes next |
||
288 | SpektrumTimer = MAX_BYTEGAP; |
||
289 | Sync = 2; |
||
290 | FrameCnt ++; |
||
291 | Channel = ((unsigned int)ByteHigh << 8) | c; |
||
292 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM) |
||
293 | { |
||
294 | signal = Channel & 0x3ff; |
||
295 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
||
296 | signal = signal/3; // scaling to fit PPM resolution |
||
297 | index = (ByteHigh >> 2) & 0x0f; |
||
298 | } |
||
299 | else |
||
300 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_HI_RES) |
||
301 | { |
||
302 | signal = Channel & 0x7ff; |
||
303 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
||
304 | signal = signal/6; // scaling to fit PPM resolution |
||
305 | index = (ByteHigh >> 3) & 0x0f; |
||
306 | } |
||
307 | else |
||
308 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
||
309 | { |
||
310 | signal = Channel & 0x3ff; |
||
311 | signal -= 360; // Offset, range 0x000..0x3ff? |
||
312 | signal = signal/2; // scaling to fit PPM resolution |
||
313 | index = (ByteHigh >> 2) & 0x0f; |
||
314 | } |
||
315 | |||
316 | index++; |
||
317 | if(index < 13) |
||
318 | { |
||
319 | // Stabiles Signal |
||
320 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
||
321 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
||
322 | else if (index == 4) index = 2; |
||
323 | #endif |
||
324 | if(abs(signal - PPM_in[index]) < 6) |
||
325 | { |
||
326 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
||
327 | { |
||
328 | if(SenderOkay < 200) SenderOkay += 10; |
||
329 | else |
||
330 | { |
||
331 | SenderOkay = 200; |
||
332 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
||
333 | } |
||
334 | } |
||
335 | } |
||
336 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
337 | if(tmp > signal+1) tmp--; else |
||
338 | if(tmp < signal-1) tmp++; |
||
339 | |||
340 | #ifdef RECEIVER_SPEKTRUM_DX7EXP |
||
341 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
||
342 | { |
||
343 | if (signal > 100) // SYNC received |
||
344 | { |
||
345 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
||
346 | if ((s_excnt == 6 && ((s_exparity != 0 && s_exdata[s_excnt] == -125) || (s_exparity == 0 && s_exdata[s_excnt] == 125))) || (s_excnt == 9 && ((s_exparity == 0 && s_exdata[s_excnt] == -125) || (s_exparity != 0 && s_exdata[s_excnt] == 125)))) // Parity check |
||
347 | { |
||
348 | if (s_exdata[1] == 125 && s_exdata[2] == -125) s_update(5,-125); // Reconstruct tripole Flight-Mode value (CH5) |
||
349 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) s_update(5,0); // Reconstruct tripole Flight-Mode value (CH5) |
||
350 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) s_update(5,125); // Reconstruct tripole Flight-Mode value (CH5) |
||
351 | s_update(6,s_exdata[3]); // Elevator (CH6) |
||
352 | s_update(11,s_exdata[4]); // Aileron (CH11) |
||
353 | s_update(12,s_exdata[5]); // Rudder (CH12) |
||
354 | |||
355 | if (s_excnt == 9) // New Mode (12 Channels) |
||
356 | { |
||
357 | if (s_exdata[7] == 125) s_update(8,PPM_in[8]+5); // Hover Pitch UP (CH8) |
||
358 | if (s_exdata[8] == 125) s_update(8,PPM_in[8]-5); // Hover Pitch DN (CH8) |
||
359 | if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
||
360 | else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
||
361 | s_update(10,s_exdata[6]); // AUX2 (CH10) |
||
362 | } |
||
363 | } |
||
364 | |||
365 | s_excnt = 0; // Reset bitcounter |
||
366 | s_exparity = 0; // Reset parity bit |
||
367 | } |
||
368 | |||
369 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
||
370 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
||
371 | if (signal < -100) |
||
372 | { |
||
373 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
||
374 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
||
375 | } |
||
376 | |||
377 | } |
||
378 | |||
379 | if (index < 5 ) s_update(index,tmp); // Update normal potis (CH1-4) |
||
380 | else if (index == 5) s_update(7,signal); // Gear (CH7) |
||
381 | else if (index == 7) s_update(9,signal); // Hover Throttle (CH9) |
||
382 | |||
383 | #elif defined RECEIVER_SPEKTRUM_DX8EXP |
||
384 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
||
385 | { |
||
386 | if (signal > 100) // SYNC received |
||
387 | { |
||
388 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
||
389 | if (s_excnt == 9 && ((s_exparity == 0 && s_exdata[s_excnt] == -125) || (s_exparity != 0 && s_exdata[s_excnt] == 125))) // Parity check |
||
390 | { |
||
391 | if (s_exdata[1] == 125 && s_exdata[2] == -125) s_update(5,-125); // Reconstruct tripole Flight-Mode value (CH5) |
||
392 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) s_update(5,0); // Reconstruct tripole Flight-Mode value (CH5) |
||
393 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) s_update(5,125); // Reconstruct tripole Flight-Mode value (CH5) |
||
394 | |||
395 | if (s_exdata[3] == 125 && s_exdata[6] == -125) s_update(6,125); // Reconstruct tripole Elev D/R value (CH6) |
||
396 | else if (s_exdata[3] == -125 && s_exdata[6] == -125) s_update(6,0); // Reconstruct tripole Elev D/R value (CH6) |
||
397 | else if (s_exdata[3] == -125 && s_exdata[6] == 125) s_update(6,-125); // Reconstruct tripole Elev D/R value (CH6) |
||
398 | |||
399 | |||
400 | if (s_exdata[7] == 125 && s_exdata[8] == -125) s_update(9,-125); // Reconstruct tripole AIL D/R value (CH9) |
||
401 | else if (s_exdata[7] == -125 && s_exdata[8] == -125) s_update(9,0); // Reconstruct tripole AIL D/R value (CH9) |
||
402 | else if (s_exdata[7] == -125 && s_exdata[8] == 125) s_update(9,125); // Reconstruct tripole AIL D/R value (CH9) |
||
403 | |||
404 | s_update(10,s_exdata[5]); // Gear (CH10) |
||
405 | s_update(12,s_exdata[4]); // Mix (CH12) |
||
406 | } |
||
407 | |||
408 | s_excnt = 0; // Reset bitcounter |
||
409 | s_exparity = 0; // Reset parity bit |
||
410 | } |
||
411 | |||
412 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
||
413 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
||
414 | if (signal < -100) |
||
415 | { |
||
416 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
||
417 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
||
418 | } |
||
419 | |||
420 | } |
||
421 | |||
422 | if (index < 5 ) s_update(index,tmp); // Update normal potis (CH1-4) |
||
423 | else if (index == 7) s_update(7,signal); // R Trim (CH7) |
||
424 | else if (index == 5) s_update(8,signal); // AUX2 (CH8) |
||
425 | else if (index == 8) s_update(11,signal); // AUX3 (CH11) |
||
426 | |||
427 | #else |
||
428 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
429 | else PPM_diff[index] = 0; |
||
430 | PPM_in[index] = tmp; |
||
431 | #endif |
||
432 | } |
||
433 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
||
434 | } |
||
435 | else |
||
436 | { |
||
437 | // hier stimmt was nicht: neu synchronisieren |
||
438 | ReSync = 1; |
||
439 | FrameCnt = 0; |
||
440 | Frame2 = 0; |
||
441 | // new frame next, nach fruehestens 7ms erwartet |
||
442 | SpektrumTimer = MIN_FRAMEGAP; |
||
443 | } |
||
444 | |||
445 | // 16 Bytes eingetroffen -> Komplett |
||
446 | if(FrameCnt >= 16) |
||
447 | { |
||
448 | // Frame complete |
||
449 | if(Frame2 == 0) |
||
450 | { |
||
451 | // Null bedeutet: Neue Daten |
||
452 | // nur beim ersten Frame (CH 0-7) setzen |
||
453 | if(!ReSync) NewPpmData = 0; |
||
454 | } |
||
455 | FrameCnt = 0; |
||
456 | Frame2 = 0; |
||
457 | Sync = 0; |
||
458 | SpektrumTimer = MIN_FRAMEGAP; |
||
459 | } |
||
460 | } |
||
461 | } |
||
462 |