Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
304 ingob 1
// ######################## SPI - FlightCtrl ###################
2
#include "main.h"
1622 killagreg 3
#include "eeprom.h"
304 ingob 4
 
823 ingob 5
//struct str_ToNaviCtrl_Version   ToNaviCtrl_Version;
6
//struct str_FromNaviCtrl_Version   FromNaviCtrl_Version;
7
struct str_ToNaviCtrl   ToNaviCtrl;
8
struct str_FromNaviCtrl   FromNaviCtrl;
978 hbuss 9
struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
1448 killagreg 10
struct str_SPI_VersionInfo NC_Version;
1451 killagreg 11
struct str_GPSInfo GPSInfo;
708 ingob 12
 
2008 holgerb 13
unsigned char SPI_BufferIndex;
14
unsigned char SPI_RxBufferIndex;
1668 holgerb 15
signed char FromNC_Rotate_C = 32, FromNC_Rotate_S = 0;
606 ingob 16
 
882 hbuss 17
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
823 ingob 18
unsigned char *SPI_TX_Buffer;
708 ingob 19
 
617 ingob 20
unsigned char SPITransferCompleted, SPI_ChkSum;
1690 holgerb 21
unsigned char SPI_RxDataValid,NaviDataOkay = 250;
720 ingob 22
 
2183 holgerb 23
unsigned char SPI_CommandSequence[] = { SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_PARAMETER1,
2341 holgerb 24
                                                                                SPI_FCCMD_STICK, SPI_FCCMD_VERSION, SPI_FCCMD_BL_ACCU,
2348 holgerb 25
                                        SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_MISC,SPI_FCCMD_SERVOS,
2341 holgerb 26
                                                                                SPI_FCCMD_STICK, SPI_FCCMD_PARAMETER2, SPI_FCCMD_BL_ACCU
2183 holgerb 27
                                                                                };
823 ingob 28
unsigned char SPI_CommandCounter = 0;
1703 holgerb 29
unsigned char NC_ErrorCode = 0;
1920 holgerb 30
unsigned char NC_GPS_ModeCharacter = ' ';
1972 holgerb 31
unsigned char EarthMagneticField = 0;
32
unsigned char EarthMagneticInclination = 0, EarthMagneticInclinationTheoretic = 0;
2009 holgerb 33
unsigned char NC_To_FC_Flags = 0;
2034 holgerb 34
unsigned char NC_To_FC_MaxAltitude = 0; // this is a Parameter on the SD-card
1840 holgerb 35
signed int POI_KameraNick = 0; // in 0,1°
1852 killagreg 36
vector16_t MagVec = {0,0,0};
823 ingob 37
 
597 ingob 38
#ifdef USE_SPI_COMMUNICATION
691 ingob 39
 
304 ingob 40
//------------------------------------------------------
41
void SPI_MasterInit(void)
42
{
1051 killagreg 43
  DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK);    // Set MOSI and SCK output, all others input
304 ingob 44
  SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT);
1051 killagreg 45
 
46
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE);   // Enable SPI, Master, set clock rate fck/64
723 hbuss 47
  SPSR = 0;//(1<<SPI2X);
1051 killagreg 48
 
49
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);
606 ingob 50
  SPITransferCompleted = 1;
1051 killagreg 51
 
708 ingob 52
  //SPDR = 0x00;  // dummy write
1051 killagreg 53
 
823 ingob 54
  ToNaviCtrl.Sync1 = 0xAA;
55
  ToNaviCtrl.Sync2 = 0x83;
1051 killagreg 56
 
1448 killagreg 57
  ToNaviCtrl.Command = SPI_FCCMD_USER;
823 ingob 58
  ToNaviCtrl.IntegralNick = 0;
59
  ToNaviCtrl.IntegralRoll = 0;
1215 hbuss 60
  FromNaviCtrl_Value.SerialDataOkay = 0;
1051 killagreg 61
  SPI_RxDataValid = 0;
62
 
304 ingob 63
}
64
 
65
//------------------------------------------------------
823 ingob 66
void SPI_StartTransmitPacket(void)
304 ingob 67
{
606 ingob 68
   if (!SPITransferCompleted) return;
304 ingob 69
   SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
823 ingob 70
   SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl;
1051 killagreg 71
 
823 ingob 72
   ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
73
   if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
1051 killagreg 74
 
606 ingob 75
   SPITransferCompleted = 0;
304 ingob 76
   UpdateSPI_Buffer();                              // update buffer
77
   SPI_BufferIndex = 1;
823 ingob 78
   ToNaviCtrl.Chksum = ToNaviCtrl.Sync1;
1051 killagreg 79
   SPDR = ToNaviCtrl.Sync1;                  // Start transmission
304 ingob 80
}
81
 
82
//------------------------------------------------------
83
//SIGNAL(SIG_SPI)
84
void SPI_TransmitByte(void)
85
{
708 ingob 86
   static unsigned char SPI_RXState = 0;
1051 killagreg 87
   unsigned char rxdata;
708 ingob 88
   static unsigned char rxchksum;
1051 killagreg 89
 
691 ingob 90
   if (SPITransferCompleted) return;
304 ingob 91
   if (!(SPSR & (1 << SPIF))) return;
2341 holgerb 92
  SendSPI = SPI_BYTEGAP;
1051 killagreg 93
//   _delay_us(30);
606 ingob 94
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);   // DeselectSlave
1051 killagreg 95
 
708 ingob 96
  rxdata = SPDR;
97
  switch ( SPI_RXState)
98
  {
1051 killagreg 99
  case 0:
100
                        SPI_RxBufferIndex = 0;
101
                        rxchksum = rxdata;
102
                        if (rxdata == 0x81 )  { SPI_RXState  = 1;  }   // 1. Syncbyte ok
103
 
708 ingob 104
           break;
105
 
1051 killagreg 106
   case 1:
107
                    if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState  = 2;  }   // 2. Syncbyte ok
108
                 else SPI_RXState  = 0;
109
           break;
110
 
708 ingob 111
   case 2:
112
                   SPI_Buffer[SPI_RxBufferIndex++]= rxdata;             // get data
113
           //DebugOut.Analog[19]++;
1051 killagreg 114
           if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl))
115
                   {
708 ingob 116
                if (rxdata == rxchksum)
117
                        {
823 ingob 118
                  unsigned char *ptr = (unsigned char *)&FromNaviCtrl;
708 ingob 119
                          memcpy(ptr, (unsigned char *) SPI_Buffer,  sizeof(SPI_Buffer));
1051 killagreg 120
                          SPI_RxDataValid = 1;
121
                        }
1856 killagreg 122
                        else
1855 holgerb 123
                         {
124
                          SPI_RxDataValid = 0;
1856 killagreg 125
                         }
1051 killagreg 126
                        SPI_RXState  = 0;
708 ingob 127
                   }
1051 killagreg 128
                  else rxchksum += rxdata;
129
        break;
130
 
131
  }
132
 
133
   if (SPI_BufferIndex < sizeof(ToNaviCtrl))
134
     {
606 ingob 135
           SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
2341 holgerb 136
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
708 ingob 137
           SPDR = SPI_TX_Buffer[SPI_BufferIndex];
823 ingob 138
           ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex];
2341 holgerb 139
         }
1051 killagreg 140
         else SPITransferCompleted = 1;
141
 
304 ingob 142
         SPI_BufferIndex++;
143
}
144
 
691 ingob 145
 
304 ingob 146
//------------------------------------------------------
147
void UpdateSPI_Buffer(void)
148
{
846 hbuss 149
  signed int tmp;
2150 holgerb 150
  static unsigned char motorindex, oldcommand = SPI_NCCMD_VERSION;
1171 hbuss 151
  ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4));
152
  ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4));
153
  ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR;
1664 holgerb 154
  ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier;
1171 hbuss 155
  ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4;
156
  ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4;
819 hbuss 157
  NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0;
823 ingob 158
//  ToNaviCtrl.User8 = Parameter_UserParam8;
159
//  ToNaviCtrl.CalState = WinkelOut.CalcState;
1051 killagreg 160
   switch(ToNaviCtrl.Command)  //
823 ingob 161
   {
1448 killagreg 162
         case SPI_FCCMD_USER:
823 ingob 163
                                ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1;
164
                                ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2;
165
                                ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3;
166
                                ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4;
167
                                ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5;
168
                                ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6;
169
                                ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7;
921 hbuss 170
                                ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8;
1765 killagreg 171
                                ToNaviCtrl.Param.Byte[8] = FC_StatusFlags;
2309 holgerb 172
//if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) ToNaviCtrl.Param.Byte[8] &= ~FC_STATUS_FLY;
1765 killagreg 173
                FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START);
2333 holgerb 174
                    ToNaviCtrl.Param.Byte[9] = ActiveParamSet;
1915 holgerb 175
                                ToNaviCtrl.Param.Byte[10] = EE_Parameter.ComingHomeAltitude;
1861 holgerb 176
                                ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2;
2348 holgerb 177
                                if(!(PORTC & (1<<PORTC2))) FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;       // Out1 (J16)
921 hbuss 178
        break;
2341 holgerb 179
     case SPI_FCCMD_BL_ACCU:
1508 killagreg 180
                        ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A
181
                        ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh
182
                        ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V
2342 holgerb 183
                                ToNaviCtrl.Param.Byte[5] = GetChannelValue(EE_Parameter.NaviGpsModeChannel);  // GPS-Mode control 
1865 holgerb 184
                                ToNaviCtrl.Param.Byte[6] = VarioCharacter;
2037 holgerb 185
                                ToNaviCtrl.Param.Byte[7] = motorindex;
186
                                ToNaviCtrl.Param.Byte[8] = Motor[motorindex].MaxPWM;
187
                                ToNaviCtrl.Param.Byte[9] = Motor[motorindex].State;
1948 holgerb 188
                                ToNaviCtrl.Param.Byte[10] = Motor[motorindex].Temperature;
2346 holgerb 189
                                ToNaviCtrl.Param.Byte[11] = Motor[motorindex].Current;
190
                                if(Mixer.Motor[++motorindex][0] == 0) // next motor is not used ?
191
                                  while(Mixer.Motor[motorindex][0] == 0 && motorindex) motorindex = (motorindex + 1) % 12;
1508 killagreg 192
        break;
1448 killagreg 193
         case SPI_FCCMD_PARAMETER1:
2341 holgerb 194
                                ToNaviCtrl.Param.Byte[0] = (unsigned char) BattLowVoltageWarning; //0.1V
195
                                ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain;           // Parameters for the Naviboard
1051 killagreg 196
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP;
197
                                ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI;
198
                                ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD;
2344 holgerb 199
                                ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsA;
1051 killagreg 200
                                ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat;
201
                ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold;
993 hbuss 202
                ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius;
203
                ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection;
1936 holgerb 204
                ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviAccCompensation;
1064 hbuss 205
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation;
823 ingob 206
            break;
2183 holgerb 207
         case SPI_FCCMD_PARAMETER2:
208
                                ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviOut1Parameter;     // Distance between Photo releases
2190 holgerb 209
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2263 holgerb 210
                                // create the ToNC_SpeakHoTT
211
                                if(EE_Parameter.Receiver != RECEIVER_HOTT)
212
                                 {
213
                                  if(JetiBeep != 'B') JetiBeep = pgm_read_byte(&JETI_CODE[HoTT_Waring()]);
214
                                  else HoTT_Waring();
215
                                 }
2190 holgerb 216
                                ToNaviCtrl.Param.Byte[1] = ToNC_SpeakHoTT;
217
#else
218
                                ToNaviCtrl.Param.Byte[1] = 0;
219
#endif
2340 holgerb 220
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.LandingSpeed;
2183 holgerb 221
            break;
1448 killagreg 222
         case SPI_FCCMD_STICK:
1320 hbuss 223
              cli();
871 hbuss 224
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 225
                                ToNaviCtrl.Param.Byte[0] = (char) tmp;
871 hbuss 226
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 227
                                ToNaviCtrl.Param.Byte[1] = (char) tmp;
871 hbuss 228
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 229
                                ToNaviCtrl.Param.Byte[2] = (char) tmp;
871 hbuss 230
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
1320 hbuss 231
              sei();
846 hbuss 232
                                ToNaviCtrl.Param.Byte[3] = (char) tmp;
1377 hbuss 233
                                ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0];
234
                                ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1];
235
                                ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2];
236
                    ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3];
237
                                ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4];
238
                                ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5];
239
                                ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6];
240
                                ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7];
1241 killagreg 241
                        break;
1448 killagreg 242
                case SPI_FCCMD_MISC:
1241 killagreg 243
                        if(WinkelOut.CalcState > 5)
244
                        {
245
                                WinkelOut.CalcState = 0;
246
                                ToNaviCtrl.Param.Byte[0] = 5;
247
                        }
248
                        else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState;
1312 hbuss 249
                        ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime;
1662 killagreg 250
                        ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5);
1312 hbuss 251
                        ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5);
252
                        ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit;
253
                        ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit;
254
                        ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit;
1377 hbuss 255
            ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay;
2341 holgerb 256
//            ToNaviCtrl.Param.Byte[10] = (unsigned char) PPM_in[0]; // ACT RSSI
257
ToNaviCtrl.Param.Byte[10] = 0;
1377 hbuss 258
                        ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil
1241 killagreg 259
                        break;
1448 killagreg 260
                case SPI_FCCMD_VERSION:
261
                        ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR;
262
                        ToNaviCtrl.Param.Byte[1] = VERSION_MINOR;
263
                        ToNaviCtrl.Param.Byte[2] = VERSION_PATCH;
264
                        ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE;
1241 killagreg 265
                        ToNaviCtrl.Param.Byte[4] = PlatinenVersion;
1702 holgerb 266
                        ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0];
267
                        ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1];
2269 holgerb 268
                        VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; //                         VersionInfo.HardwareError[0] = 0;
1938 holgerb 269
                        VersionInfo.HardwareError[1] &= FC_ERROR1_MIXER;
2344 holgerb 270
ToNaviCtrl.Param.Byte[7] = 0;
2037 holgerb 271
                        ToNaviCtrl.Param.Byte[8] = Parameter_GlobalConfig;
272
                        ToNaviCtrl.Param.Byte[9] = Parameter_ExtraConfig;
1913 holgerb 273
                        ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle;
2008 holgerb 274
                        ToNaviCtrl.Param.Byte[11] = EE_Parameter.GlobalConfig3;
1241 killagreg 275
                break;
1448 killagreg 276
            case SPI_FCCMD_SERVOS:
1241 killagreg 277
                ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh;     // Parameters for the Servo Control
278
                        ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert;
279
                        ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl;
280
                        ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp;
281
                        ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin;
282
                        ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax;
283
                        ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl;
284
                        ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp;
285
                        ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin;
286
                        ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax;
1948 holgerb 287
                        ToNaviCtrl.Param.Byte[10] = Capacity.MinOfMaxPWM;
288
                        ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[28]; // I2C-Error counter
1241 killagreg 289
                break;
290
        }
2010 holgerb 291
 
1215 hbuss 292
  if(SPI_RxDataValid)
1051 killagreg 293
  {
2148 holgerb 294
        if(FromNaviCtrl.Command != oldcommand) NaviDataOkay = 250;
295
        oldcommand = FromNaviCtrl.Command;
1852 killagreg 296
        CalculateCompassTimer = 1;
297
        if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV))
298
        {
299
                GPS_Nick = FromNaviCtrl.GPS_Nick;
300
                GPS_Roll = FromNaviCtrl.GPS_Roll;
301
        }
1690 holgerb 302
 
1852 killagreg 303
        // update compass readings
1936 holgerb 304
//      MagVec.x = FromNaviCtrl.MagVecX;
305
//      MagVec.y = FromNaviCtrl.MagVecY;
306
//      MagVec.z = FromNaviCtrl.MagVecZ;
1852 killagreg 307
 
1690 holgerb 308
        if(FromNaviCtrl.CompassValue <= 360)   KompassValue = FromNaviCtrl.CompassValue;
1941 holgerb 309
//    KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
1051 killagreg 310
 
2029 holgerb 311
    if(FromNaviCtrl.BeepTime > beeptime && !DisableRcOffBeeping) beeptime = FromNaviCtrl.BeepTime;
823 ingob 312
          switch (FromNaviCtrl.Command)
313
          {
1448 killagreg 314
            case SPI_NCCMD_KALMAN:
1231 killagreg 315
                        FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0];
316
                        FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1];
317
                        FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2];
1944 holgerb 318
                        KompassFusion = FromNaviCtrl.Param.sByte[3];
1283 hbuss 319
                        FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4];
1664 holgerb 320
                        FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5];
321
                        FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6];
1945 holgerb 322
                        GPS_Aid_StickMultiplikator = FromNaviCtrl.Param.Byte[7];
1912 holgerb 323
                        if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0)
1840 holgerb 324
                         {
325
                          KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben
1876 holgerb 326
                          if(EE_Parameter.CamOrientation)  // Kamera angle is not front
327
                           {
328
                            KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15);
329
                                KompassSollWert %= 360;
330
                           }   
1856 killagreg 331
                         }
1862 holgerb 332
                        POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel
1231 killagreg 333
                        break;
1448 killagreg 334
                case SPI_NCCMD_VERSION:
335
                        NC_Version.Major = FromNaviCtrl.Param.Byte[0];
336
                        NC_Version.Minor = FromNaviCtrl.Param.Byte[1];
337
                        NC_Version.Patch = FromNaviCtrl.Param.Byte[2];
338
                        NC_Version.Compatible = FromNaviCtrl.Param.Byte[3];
339
                        NC_Version.Hardware = FromNaviCtrl.Param.Byte[4];
1702 holgerb 340
                        DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5];
341
                        DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08));
1920 holgerb 342
                        NC_ErrorCode = FromNaviCtrl.Param.Byte[7];
343
                        NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8];
1944 holgerb 344
                        FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[9];
2009 holgerb 345
                        NC_To_FC_Flags = FromNaviCtrl.Param.Byte[10];
2034 holgerb 346
                        NC_To_FC_MaxAltitude = FromNaviCtrl.Param.Byte[11];
1856 killagreg 347
                        break;
1451 killagreg 348
                case SPI_NCCMD_GPSINFO:
349
                        GPSInfo.Flags = FromNaviCtrl.Param.Byte[0];
350
                        GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1];
351
                        GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2];
1690 holgerb 352
                        GPSInfo.Speed = FromNaviCtrl.Param.Byte[3];
1852 killagreg 353
                        GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2];
1472 killagreg 354
                        GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3];
2340 holgerb 355
                        PPM_in[WP_EVENT_PPM_IN] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value (FromNC_WP_EventChannel)
1855 holgerb 356
            FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9];
1857 holgerb 357
                FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10;  // in cm
1451 killagreg 358
                        break;
1972 holgerb 359
                case SPI_MISC:
360
                        EarthMagneticField = FromNaviCtrl.Param.Byte[0];
361
                        EarthMagneticInclination = FromNaviCtrl.Param.Byte[1];
362
                        EarthMagneticInclinationTheoretic = FromNaviCtrl.Param.Byte[2];
2090 holgerb 363
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2179 holgerb 364
                        if(FromNaviCtrl.Param.Byte[3])
2120 holgerb 365
            if(!SpeakHoTT || (SpeakHoTT >= SPEAK_GPS_HOLD && SpeakHoTT <= SPEAK_GPS_OFF)) SpeakHoTT = FromNaviCtrl.Param.Byte[3];
2179 holgerb 366
                        NaviData_WaypointIndex = FromNaviCtrl.Param.Byte[4];
367
                        NaviData_WaypointNumber = FromNaviCtrl.Param.Byte[5];
368
                        NaviData_TargetDistance = FromNaviCtrl.Param.Int[3];
369
                        NaviData_TargetHoldTime = FromNaviCtrl.Param.Byte[8];
2090 holgerb 370
#endif
371
                        break;    
1972 holgerb 372
 
1940 holgerb 373
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
374
                case SPI_NCCMD_HOTT_DATA:
375
                        if(EE_Parameter.Receiver == RECEIVER_HOTT) NC_Fills_HoTT_Telemety();
376
                        break;
377
#endif
378
 
1855 holgerb 379
// 0 = 0,1
380
// 1 = 2,3
381
// 2 = 4,5
382
// 3 = 6,7
383
// 4 = 8,9
384
// 5 = 10,11
823 ingob 385
                default:
1451 killagreg 386
                        break;
823 ingob 387
          }
720 ingob 388
  }
389
  else
390
  {
819 hbuss 391
//    KompassValue = 0;
392
//    KompassRichtung = 0;
720 ingob 393
        GPS_Nick = 0;
394
    GPS_Roll = 0;
395
  }
304 ingob 396
}
397
 
597 ingob 398
#endif
304 ingob 399
 
400