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