Rev 2081 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1171 | hbuss | 1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
||
3 | #######################################################################################*/ |
||
4 | |||
1426 | ingob | 5 | #include "Spektrum.h" |
1171 | hbuss | 6 | #include "main.h" |
1928 | holgerb | 7 | // Achtung: RECEIVER_SPEKTRUM_DX7EXP oder RECEIVER_SPEKTRUM_DX8EXP wird in der Main.h gesetzt |
1506 | holgerb | 8 | |
2093 | - | 9 | #ifndef WITHSPECTRUM /// MartinW |
10 | #warning : "### without SPECTRUM Code ###" |
||
11 | #endif |
||
12 | |||
1320 | hbuss | 13 | unsigned char SpektrumTimer = 0; |
1171 | hbuss | 14 | |
1928 | holgerb | 15 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
1680 | holgerb | 16 | unsigned char s_excnt = 0; // Counter for Spektrum-Expander |
17 | unsigned char s_exparity = 0; // Parity Bit for Spektrum-Expander |
||
18 | signed char s_exdata[11]; // Data for Spektrum-Expander |
||
1506 | holgerb | 19 | #endif |
1213 | ingob | 20 | //--------------------------------------------------------------// |
21 | //--------------------------------------------------------------// |
||
1743 | holgerb | 22 | /* |
1213 | ingob | 23 | void SpektrumBinding(void) |
24 | { |
||
25 | unsigned int timerTimeout = SetDelay(10000); // Timeout 10 sec. |
||
26 | unsigned char connected = 0; |
||
27 | unsigned int delaycounter; |
||
1391 | killagreg | 28 | |
1213 | ingob | 29 | UCSR1B &= ~(1 << RXCIE1); // disable rx-interrupt |
30 | UCSR1B &= ~(1<<RXEN1); // disable Uart-Rx |
||
31 | PORTD &= ~(1 << PORTD2); // disable pull-up |
||
1391 | killagreg | 32 | |
1213 | ingob | 33 | printf("\n\rPlease connect Spektrum receiver for binding NOW..."); |
1391 | killagreg | 34 | |
1213 | ingob | 35 | while(!CheckDelay(timerTimeout)) |
36 | { |
||
37 | if (PIND & (1 << PORTD2)) { timerTimeout = SetDelay(90); connected = 1; break; } |
||
38 | } |
||
1391 | killagreg | 39 | |
40 | if (connected) |
||
41 | { |
||
42 | |||
43 | printf("ok.\n\r"); |
||
1213 | ingob | 44 | DDRD |= (1 << DDD2); // Rx as output |
45 | |||
1680 | holgerb | 46 | while(!CheckDelay(timerTimeout)); // delay after startup of RX |
47 | for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2); |
||
48 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
1391 | killagreg | 49 | |
1680 | holgerb | 50 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
1213 | ingob | 51 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
1680 | holgerb | 52 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
53 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
1391 | killagreg | 54 | |
1680 | holgerb | 55 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
1213 | ingob | 56 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
1680 | holgerb | 57 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
58 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
||
1213 | ingob | 59 | |
1680 | holgerb | 60 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
1213 | ingob | 61 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
1680 | holgerb | 62 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
1391 | killagreg | 63 | |
1213 | ingob | 64 | } |
1391 | killagreg | 65 | else |
66 | { printf("Timeout.\n\r"); |
||
67 | |||
68 | |||
1213 | ingob | 69 | } |
1391 | killagreg | 70 | |
1213 | ingob | 71 | DDRD &= ~(1 << DDD2); // RX as input |
1391 | killagreg | 72 | PORTD &= ~(1 << PORTD2); |
1213 | ingob | 73 | |
1424 | ingob | 74 | SpektrumUartInit(); // init Uart again |
1213 | ingob | 75 | } |
1743 | holgerb | 76 | */ |
1171 | hbuss | 77 | //############################################################################ |
78 | // USART1 initialisation from killagreg |
||
1424 | ingob | 79 | void SpektrumUartInit(void) |
1171 | hbuss | 80 | //############################################################################ |
81 | { |
||
2093 | - | 82 | #ifdef WITHSPECTRUM /// MartinW main.h means no memsave |
83 | #warning : "### with left over Spectrum code ###" |
||
84 | |||
1680 | holgerb | 85 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
86 | // USART1 Control and Status Register A, B, C and baud rate register |
||
87 | uint8_t sreg = SREG; |
||
1928 | holgerb | 88 | |
1680 | holgerb | 89 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
1928 | holgerb | 90 | |
1680 | holgerb | 91 | // disable all interrupts before reconfiguration |
92 | cli(); |
||
93 | // disable RX-Interrupt |
||
94 | UCSR1B &= ~(1 << RXCIE1); |
||
95 | // disable TX-Interrupt |
||
96 | UCSR1B &= ~(1 << TXCIE1); |
||
97 | // disable DRE-Interrupt |
||
98 | UCSR1B &= ~(1 << UDRIE1); |
||
99 | // set direction of RXD1 and TXD1 pins |
||
100 | // set RXD1 (PD2) as an input pin |
||
101 | PORTD |= (1 << PORTD2); |
||
102 | DDRD &= ~(1 << DDD2); |
||
1431 | ingob | 103 | |
1680 | holgerb | 104 | // set TXD1 (PD3) as an output pin |
105 | PORTD |= (1 << PORTD3); |
||
106 | DDRD |= (1 << DDD3); |
||
1928 | holgerb | 107 | |
1680 | holgerb | 108 | // USART0 Baud Rate Register |
109 | // set clock divider |
||
110 | UBRR1H = (uint8_t)(ubrr>>8); |
||
111 | UBRR1L = (uint8_t)ubrr; |
||
112 | // enable double speed operation |
||
113 | UCSR1A |= (1 << U2X1); |
||
114 | // enable receiver and transmitter |
||
115 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
||
1391 | killagreg | 116 | |
1680 | holgerb | 117 | UCSR1B = (1<<RXEN1); |
118 | // set asynchronous mode |
||
119 | UCSR1C &= ~(1 << UMSEL11); |
||
120 | UCSR1C &= ~(1 << UMSEL10); |
||
121 | // no parity |
||
122 | UCSR1C &= ~(1 << UPM11); |
||
123 | UCSR1C &= ~(1 << UPM10); |
||
124 | // 1 stop bit |
||
125 | UCSR1C &= ~(1 << USBS1); |
||
126 | // 8-bit |
||
127 | UCSR1B &= ~(1 << UCSZ12); |
||
128 | UCSR1C |= (1 << UCSZ11); |
||
129 | UCSR1C |= (1 << UCSZ10); |
||
130 | // flush receive buffer explicit |
||
131 | while(UCSR1A & (1<<RXC1)) UDR1; |
||
132 | // enable RX-interrupts at the end |
||
133 | UCSR1B |= (1 << RXCIE1); |
||
134 | // -- End of USART1 initialisation |
||
135 | // restore global interrupt flags |
||
1928 | holgerb | 136 | |
1680 | holgerb | 137 | SREG = sreg; |
2093 | - | 138 | #endif |
1171 | hbuss | 139 | return; |
140 | } |
||
1391 | killagreg | 141 | |
1171 | hbuss | 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 |
||
1680 | holgerb | 160 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
161 | // Schwarz: GND |
||
162 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
||
1171 | hbuss | 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. |
||
1680 | holgerb | 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) |
||
1171 | hbuss | 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: |
||
1680 | holgerb | 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 |
||
1171 | hbuss | 190 | // 2nd Frame: |
1680 | holgerb | 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 |
||
1171 | hbuss | 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 | |||
1322 | hbuss | 212 | #define MIN_FRAMEGAP 68 // 7ms |
213 | #define MAX_BYTEGAP 3 // 310us |
||
1320 | hbuss | 214 | |
1419 | ingob | 215 | |
1171 | hbuss | 216 | //############################################################################ |
1481 | holgerb | 217 | // Wird im UART-Interrupt aufgerufen |
1171 | hbuss | 218 | //############################################################################ |
1419 | ingob | 219 | void SpektrumParser(unsigned char c) |
1171 | hbuss | 220 | { |
2093 | - | 221 | #ifdef WITHSPECTRUM /// MartinW main.h means no memsave |
222 | #warning : "### with left over Spectrum code ###" |
||
223 | |||
1320 | hbuss | 224 | static unsigned char Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0; |
1680 | holgerb | 225 | unsigned int Channel, index = 0; |
226 | signed int signal = 0, tmp; |
||
227 | int bCheckDelay; |
||
228 | // c = UDR1; // get data byte |
||
229 | if(ReSync == 1) |
||
230 | { |
||
231 | // wait for beginning of new frame |
||
232 | ReSync = 0; |
||
233 | SpektrumTimer = MIN_FRAMEGAP; |
||
234 | FrameCnt = 0; |
||
235 | Sync = 0; |
||
236 | ByteHigh = 0; |
||
237 | } |
||
1171 | hbuss | 238 | else |
1391 | killagreg | 239 | { |
1680 | holgerb | 240 | if(!SpektrumTimer) bCheckDelay = 1; else bCheckDelay = 0;//CheckDelay(FrameTimer); |
241 | if ( Sync == 0 ) |
||
242 | { |
||
243 | if(bCheckDelay) |
||
244 | { |
||
245 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
||
246 | // Zeichen ignorieren, da Bedeutung unbekannt |
||
247 | Sync = 1; |
||
248 | FrameCnt ++; |
||
249 | SpektrumTimer = MAX_BYTEGAP; |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
||
254 | // warten auf erstes Sync-Zeichen |
||
255 | SpektrumTimer = MIN_FRAMEGAP; |
||
256 | FrameCnt = 0; |
||
257 | Sync = 0; |
||
258 | ByteHigh = 0; |
||
259 | } |
||
260 | } |
||
261 | else if((Sync == 1) && !bCheckDelay) |
||
262 | { |
||
263 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
||
264 | Sync = 2; |
||
265 | FrameCnt ++; |
||
266 | SpektrumTimer = MAX_BYTEGAP; |
||
267 | } |
||
268 | else if((Sync == 2) && !bCheckDelay) |
||
269 | { |
||
270 | SpektrumTimer = MAX_BYTEGAP; |
||
271 | // Datenbyte high |
||
272 | ByteHigh = c; |
||
273 | if (FrameCnt == 2) |
||
274 | { |
||
275 | // is 1st Byte of Channel-data |
||
276 | // Frame 1 with Channel 1-7 comming next |
||
277 | Frame2 = 0; |
||
278 | if(ByteHigh & 0x80) |
||
279 | { |
||
280 | // DS9: Frame 2 with Channel 8-9 comming next |
||
281 | Frame2 = 1; |
||
282 | } |
||
283 | } |
||
284 | Sync = 3; |
||
285 | FrameCnt ++; |
||
286 | } |
||
287 | else if((Sync == 3) && !bCheckDelay) |
||
288 | { |
||
289 | // Datenbyte low |
||
290 | // High-Byte for next channel comes next |
||
291 | SpektrumTimer = MAX_BYTEGAP; |
||
292 | Sync = 2; |
||
293 | FrameCnt ++; |
||
294 | Channel = ((unsigned int)ByteHigh << 8) | c; |
||
295 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM) |
||
296 | { |
||
297 | signal = Channel & 0x3ff; |
||
298 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
||
299 | signal = signal/3; // scaling to fit PPM resolution |
||
300 | index = (ByteHigh >> 2) & 0x0f; |
||
301 | } |
||
302 | else |
||
303 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_HI_RES) |
||
304 | { |
||
305 | signal = Channel & 0x7ff; |
||
306 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
||
307 | signal = signal/6; // scaling to fit PPM resolution |
||
308 | index = (ByteHigh >> 3) & 0x0f; |
||
1928 | holgerb | 309 | } |
1680 | holgerb | 310 | else |
311 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
||
312 | { |
||
313 | signal = Channel & 0x3ff; |
||
314 | signal -= 360; // Offset, range 0x000..0x3ff? |
||
315 | signal = signal/2; // scaling to fit PPM resolution |
||
316 | index = (ByteHigh >> 2) & 0x0f; |
||
317 | } |
||
1391 | killagreg | 318 | |
1680 | holgerb | 319 | index++; |
320 | if(index < 13) |
||
321 | { |
||
322 | // Stabiles Signal |
||
1928 | holgerb | 323 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
324 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
||
325 | else if (index == 4) index = 2; |
||
1506 | holgerb | 326 | #endif |
2011 | holgerb | 327 | if(abs(signal - PPM_in[index]) < 6) |
328 | { |
||
329 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
||
330 | { |
||
331 | if(SenderOkay < 200) SenderOkay += 10; |
||
332 | else |
||
333 | { |
||
1928 | holgerb | 334 | SenderOkay = 200; |
335 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
||
2011 | holgerb | 336 | } |
337 | } |
||
338 | } |
||
1928 | holgerb | 339 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
340 | if(tmp > signal+1) tmp--; else |
||
341 | if(tmp < signal-1) tmp++; |
||
342 | |||
343 | #ifdef RECEIVER_SPEKTRUM_DX7EXP |
||
344 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
||
345 | { |
||
346 | if (signal > 100) // SYNC received |
||
347 | { |
||
348 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
||
349 | 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 |
||
350 | { |
||
351 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
||
352 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
||
353 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
||
354 | PPM_in[6] = s_exdata[3]; // Elevator (CH6) |
||
355 | PPM_in[11] = s_exdata[4]; // Aileron (CH11) |
||
356 | PPM_in[12] = s_exdata[5]; // Rudder (CH12) |
||
1680 | holgerb | 357 | |
1928 | holgerb | 358 | if (s_excnt == 9) // New Mode (12 Channels) |
359 | { |
||
360 | if (s_exdata[7] == 125) PPM_in[8] += 5; // Hover Pitch UP (CH8) |
||
361 | if (s_exdata[8] == 125) PPM_in[8] -= 5; // Hover Pitch DN (CH8) |
||
362 | if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
||
363 | else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
||
364 | PPM_in[10] = s_exdata[6]; // AUX2 (CH10) |
||
365 | } |
||
366 | } |
||
1680 | holgerb | 367 | |
1928 | holgerb | 368 | s_excnt = 0; // Reset bitcounter |
369 | s_exparity = 0; // Reset parity bit |
||
370 | } |
||
1506 | holgerb | 371 | |
1928 | holgerb | 372 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
373 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
||
374 | if (signal < -100) |
||
375 | { |
||
376 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
||
377 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
||
378 | } |
||
1680 | holgerb | 379 | |
1928 | holgerb | 380 | } |
381 | |||
382 | #elif defined RECEIVER_SPEKTRUM_DX8EXP |
||
383 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
||
384 | { |
||
385 | if (signal > 100) // SYNC received |
||
386 | { |
||
387 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
||
388 | if (s_excnt == 9 && ((s_exparity == 0 && s_exdata[s_excnt] == -125) || (s_exparity != 0 && s_exdata[s_excnt] == 125))) // Parity check |
||
389 | { |
||
390 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
||
391 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
||
392 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
||
393 | |||
394 | if (s_exdata[3] == 125 && s_exdata[6] == -125) PPM_in[6] = 125; // Reconstruct tripole Elev D/R value (CH6) |
||
395 | else if (s_exdata[3] == -125 && s_exdata[6] == -125) PPM_in[6] = 0; // Reconstruct tripole Elev D/R value (CH6) |
||
396 | else if (s_exdata[3] == -125 && s_exdata[6] == 125) PPM_in[6] = -125; // Reconstruct tripole Elev D/R value (CH6) |
||
397 | |||
398 | |||
399 | if (s_exdata[7] == 125 && s_exdata[8] == -125) PPM_in[9] = -125; // Reconstruct tripole AIL D/R value (CH9) |
||
400 | else if (s_exdata[7] == -125 && s_exdata[8] == -125) PPM_in[9] = 0; // Reconstruct tripole AIL D/R value (CH9) |
||
401 | else if (s_exdata[7] == -125 && s_exdata[8] == 125) PPM_in[9] = 125; // Reconstruct tripole AIL D/R value (CH9) |
||
402 | |||
403 | PPM_in[10] = s_exdata[5]; // Gear (CH10) |
||
404 | PPM_in[12] = s_exdata[4]; // Mix (CH12) |
||
405 | } |
||
406 | |||
407 | s_excnt = 0; // Reset bitcounter |
||
408 | s_exparity = 0; // Reset parity bit |
||
409 | } |
||
410 | |||
411 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
||
412 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
||
413 | if (signal < -100) |
||
414 | { |
||
415 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
||
416 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
||
417 | } |
||
418 | |||
419 | } |
||
1506 | holgerb | 420 | #endif |
1928 | holgerb | 421 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
422 | else PPM_diff[index] = 0; |
||
1506 | holgerb | 423 | |
1928 | holgerb | 424 | #ifdef RECEIVER_SPEKTRUM_DX7EXP |
425 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
||
426 | else if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
||
427 | else if (index == 7) PPM_in[9] = signal; // Hover Throttle (CH9) |
||
428 | #elif defined RECEIVER_SPEKTRUM_DX8EXP |
||
429 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
||
430 | else if (index == 7) PPM_in[7] = signal; // R Trim (CH7) |
||
431 | else if (index == 5) PPM_in[8] = signal; // AUX2 (CH8) |
||
432 | else if (index == 8) PPM_in[11] = signal; // AUX3 (CH11) |
||
1506 | holgerb | 433 | #else |
1928 | holgerb | 434 | PPM_in[index] = tmp; |
1506 | holgerb | 435 | #endif |
1928 | holgerb | 436 | } |
1506 | holgerb | 437 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
1680 | holgerb | 438 | } |
439 | else |
||
440 | { |
||
441 | // hier stimmt was nicht: neu synchronisieren |
||
442 | ReSync = 1; |
||
443 | FrameCnt = 0; |
||
444 | Frame2 = 0; |
||
445 | // new frame next, nach fruehestens 7ms erwartet |
||
446 | SpektrumTimer = MIN_FRAMEGAP; |
||
447 | } |
||
1391 | killagreg | 448 | |
1680 | holgerb | 449 | // 16 Bytes eingetroffen -> Komplett |
450 | if(FrameCnt >= 16) |
||
451 | { |
||
452 | // Frame complete |
||
453 | if(Frame2 == 0) |
||
454 | { |
||
455 | // Null bedeutet: Neue Daten |
||
456 | // nur beim ersten Frame (CH 0-7) setzen |
||
457 | if(!ReSync) NewPpmData = 0; |
||
458 | } |
||
459 | FrameCnt = 0; |
||
460 | Frame2 = 0; |
||
461 | Sync = 0; |
||
462 | SpektrumTimer = MIN_FRAMEGAP; |
||
463 | } |
||
1171 | hbuss | 464 | } |
2093 | - | 465 | #endif |
1391 | killagreg | 466 | } |
1928 | holgerb | 467 |