Rev 1481 | Rev 1680 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1481 | Rev 1506 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
Line 4... | Line 4... | ||
4 | 4 | ||
5 | #include "Spektrum.h" |
5 | #include "Spektrum.h" |
- | 6 | #include "main.h" |
|
- | 7 | //#define RECEIVER_SPEKTRUM_EXP |
|
6 | #include "main.h" |
8 | |
Line -... | Line 9... | ||
- | 9 | unsigned char SpektrumTimer = 0; |
|
- | 10 | ||
- | 11 | #ifdef RECEIVER_SPEKTRUM_EXP |
|
- | 12 | unsigned char sexcnt; // Counter for Spektrum-Expander |
|
- | 13 | unsigned char sexparity; // Parity Bit for Spektrum-Expander |
|
7 | unsigned char SpektrumTimer = 0; |
14 | signed char sexdata[7]; // Data for Spektrum-Expander |
8 | 15 | #endif |
|
9 | //--------------------------------------------------------------// |
16 | //--------------------------------------------------------------// |
10 | //--------------------------------------------------------------// |
17 | //--------------------------------------------------------------// |
11 | void SpektrumBinding(void) |
18 | void SpektrumBinding(void) |
Line 297... | Line 304... | ||
297 | index = (ByteHigh >> 2) & 0x0f; |
304 | index = (ByteHigh >> 2) & 0x0f; |
298 | } |
305 | } |
Line 299... | Line 306... | ||
299 | 306 | ||
300 | index++; |
307 | index++; |
301 | if(index < 13) |
308 | if(index < 13) |
302 | { |
309 | { |
- | 310 | // Stabiles Signal |
|
- | 311 | #ifdef RECEIVER_SPEKTRUM_EXP |
|
- | 312 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
|
- | 313 | else if (index == 4) index = 2; |
|
303 | // Stabiles Signal |
314 | #endif |
304 | if(abs(signal - PPM_in[index]) < 6) |
315 | if(abs(signal - PPM_in[index]) < 6) |
305 | { |
316 | { |
306 | if(SenderOkay < 200) SenderOkay += 10; |
317 | if(SenderOkay < 200) SenderOkay += 10; |
307 | else |
318 | else |
308 | { |
319 | { |
309 | SenderOkay = 200; |
320 | SenderOkay = 200; |
310 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
321 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
311 | } |
322 | } |
312 | } |
323 | } |
313 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
324 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
314 | if(tmp > signal+1) tmp--; else |
325 | if(tmp > signal+1) tmp--; else |
- | 326 | if(tmp < signal-1) tmp++; |
|
- | 327 | ||
- | 328 | #ifdef RECEIVER_SPEKTRUM_EXP |
|
- | 329 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
|
- | 330 | { |
|
- | 331 | if (signal > 100) // SYNC received |
|
- | 332 | { |
|
- | 333 | sexcnt = 0; // Reset bitcounter |
|
- | 334 | sexparity = 0; // Reset parity bit |
|
- | 335 | } |
|
- | 336 | ||
- | 337 | if (signal < 10) |
|
- | 338 | { |
|
- | 339 | sexcnt++; // Increase counter only for non-sync bits |
|
- | 340 | sexdata[sexcnt] = -113; // Bit = 0 -> value = -113 (min) |
|
- | 341 | } |
|
- | 342 | ||
- | 343 | if (sexcnt == 7) sexcnt = 0; // Overflow protection |
|
- | 344 | ||
- | 345 | if (signal < -100) |
|
- | 346 | { |
|
- | 347 | sexdata[sexcnt] = 114; // Bit = 1 -> value = 114 (max) |
|
- | 348 | if (sexcnt < 6) sexparity = ~sexparity; // Bit = 1 -> Invert parity bit (without itself) |
|
- | 349 | } |
|
- | 350 | ||
- | 351 | if (sexcnt == 6) // Wait for complete frame |
|
- | 352 | { |
|
- | 353 | if ((sexparity != 0 && sexdata[6] == -113) || (sexparity == 0 && sexdata[6] == 114)) // Parity check |
|
- | 354 | { |
|
- | 355 | if (sexdata[1] == 114 && sexdata[2] == -113) PPM_in[5] = -113;// Reconstruct tripole Flight-Mode value (CH5) |
|
- | 356 | if (sexdata[1] == -113 && sexdata[2] == -113) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 357 | if (sexdata[1] == -113 && sexdata[2] == 114) PPM_in[5] = 114; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 358 | PPM_in[6] = sexdata[3]; // Elevator (CH6) |
|
- | 359 | PPM_in[9] = sexdata[4]; // Aileron (CH9) |
|
- | 360 | PPM_in[10] = sexdata[5]; // Rudder (CH10) |
|
- | 361 | } |
|
- | 362 | } |
|
- | 363 | } |
|
315 | if(tmp < signal-1) tmp++; |
364 | #endif |
- | 365 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
|
316 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
366 | |
- | 367 | else PPM_diff[index] = 0; |
|
- | 368 | ||
- | 369 | #ifdef RECEIVER_SPEKTRUM_EXP |
|
- | 370 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
|
- | 371 | if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
|
- | 372 | if (index == 7) PPM_in[8] = signal; // AUX2 (CH8) |
|
317 | else PPM_diff[index] = 0; |
373 | #else |
- | 374 | PPM_in[index] = tmp; |
|
318 | PPM_in[index] = tmp; |
375 | #endif |
319 | } |
376 | } |
320 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
377 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
321 | } |
378 | } |
322 | else |
379 | else |
323 | { |
380 | { |
324 | // hier stimmt was nicht: neu synchronisieren |
381 | // hier stimmt was nicht: neu synchronisieren |