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