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