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