6,6 → 6,9 |
#include "eeprom.h" |
#include "timer0.h" |
|
//#define RECEIVER_SPEKTRUM_EXP |
|
|
/* |
Code derived from: |
|
76,6 → 79,15 |
|
|
#define USART1_BAUD 115200 |
|
|
|
#ifdef RECEIVER_SPEKTRUM_EXP |
uint8_t s_excnt = 0; // Counter for Spektrum-Expander |
uint8_t s_exparity = 0; // Parity Bit for Spektrum-Expander |
int8_t s_exdata[11]; // Data for Spektrum-Expander |
#endif |
|
/****************************************************************/ |
/* Initialization of the USART1 */ |
/****************************************************************/ |
189,7 → 201,7 |
} |
} |
else if((Sync == 1) && !bCheckDelay) |
{ |
{ |
// zweites Sync-Character ignorieren, Bedeutung unbekannt |
SpektrumTimer = MAX_BYTEGAP; |
Sync = 2; |
196,17 → 208,17 |
FrameCnt++; |
} |
else if((Sync == 2) && !bCheckDelay) |
{ |
{ |
// Datenbyte high |
SpektrumTimer = MAX_BYTEGAP; |
ByteHigh = c; |
if (FrameCnt == 2) |
{ |
{ |
// is 1st Byte of Channel-data |
// Frame 1 with Channel 1-7 comming next |
Frame2 = 0; |
if(ByteHigh & 0x80) |
{ |
{ |
// DS9: Frame 2 with Channel 8-9 comming next |
Frame2 = 1; |
} |
215,7 → 227,7 |
FrameCnt ++; |
} |
else if((Sync == 3) && !bCheckDelay) |
{ |
{ |
// Datenbyte low |
// High-Byte for next channel comes next |
SpektrumTimer = MAX_BYTEGAP; |
257,7 → 269,12 |
if(index < MAX_RC_CHANNELS) |
{ |
if(RC_Channels < index) RC_Channels = index; |
// Stabiles Signal |
// Stable Signal |
#ifdef RECEIVER_SPEKTRUM_EXP |
if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
else if (index == 4) index = 2; |
#endif |
|
if(abs(signal - PPM_in[index]) < 6) |
{ |
if(RC_Quality < 200) |
273,10 → 290,57 |
tmp = (3 * PPM_in[index] + signal)/4; |
if(tmp > signal+1) tmp--; |
else if(tmp < signal-1) tmp++; |
|
#ifdef RECEIVER_SPEKTRUM_EXP |
if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
{ |
if (signal > 100) // SYNC received |
{ |
if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
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 |
{ |
if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
else if (s_exdata[1] == -125 && s_exdata[2] == -125) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
PPM_in[6] = s_exdata[3]; // Elevator (CH6) |
PPM_in[11] = s_exdata[4]; // Aileron (CH11) |
PPM_in[12] = s_exdata[5]; // Rudder (CH12) |
|
if (s_excnt == 9) // New Mode (12 Channels) |
{ |
if (s_exdata[7] == 125) PPM_in[8] += 5; // Hover Pitch UP (CH8) |
if (s_exdata[8] == 125) PPM_in[8] -= 5; // Hover Pitch DN (CH8) |
if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
PPM_in[10] = s_exdata[6]; // AUX2 (CH10) |
} |
} |
|
s_excnt = 0; // Reset bitcounter |
s_exparity = 0; // Reset parity bit |
} |
|
if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
if (s_excnt == 10) s_excnt = 0; // Overflow protection |
if (signal < -100) |
{ |
s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
} |
} |
#endif |
|
// calculate signal difference on good signal level |
if(RC_Quality >= 180) PPM_diff[index] = ((signal - PPM_in[index]) / 3) * 3; |
if(RC_Quality >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
else PPM_diff[index] = 0; |
PPM_in[index] = signal; |
|
#ifdef RECEIVER_SPEKTRUM_EXP |
if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
else if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
else if (index == 7) PPM_in[9] = signal; // Hover Throttle (CH9) |
#else |
PPM_in[index] = tmp; |
#endif |
} |
else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
} |