Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2506 | - | 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 | signed char FromNC_WP_EventChannel_New = 0; |
||
17 | |||
18 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
||
19 | unsigned char *SPI_TX_Buffer; |
||
20 | |||
21 | unsigned char SPITransferCompleted, SPI_ChkSum; |
||
22 | unsigned char SPI_RxDataValid,NaviDataOkay = 250; |
||
23 | |||
24 | unsigned char SPI_CommandSequence[] = { SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_SLOW, |
||
25 | SPI_FCCMD_STICK, SPI_FCCMD_VERSION, SPI_FCCMD_BL_ACCU, |
||
26 | SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_MISC,SPI_FCCMD_SERVOS, |
||
27 | SPI_FCCMD_STICK, SPI_FCCMD_PARAMETER2, SPI_FCCMD_BL_ACCU |
||
28 | }; |
||
29 | unsigned char SPI_CommandCounter = 0; |
||
30 | unsigned char NC_ErrorCode = 0; |
||
31 | unsigned char NC_GPS_ModeCharacter = ' '; |
||
32 | unsigned char EarthMagneticField = 0; |
||
33 | unsigned char EarthMagneticInclination = 0, EarthMagneticInclinationTheoretic = 0; |
||
34 | unsigned char NC_To_FC_Flags = 0; |
||
35 | //unsigned char NC_To_FC_MaxAltitude = 0; // this is a Parameter on the SD-card |
||
36 | signed int POI_KameraNick = 0; // in 0,1° |
||
37 | vector16_t MagVec = {0,0,0}; |
||
38 | |||
39 | #ifdef USE_SPI_COMMUNICATION |
||
40 | |||
41 | //------------------------------------------------------ |
||
42 | void SPI_MasterInit(void) |
||
43 | { |
||
44 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
||
45 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
||
46 | |||
47 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
||
48 | SPSR = 0;//(1<<SPI2X); |
||
49 | |||
50 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
||
51 | SPITransferCompleted = 1; |
||
52 | |||
53 | //SPDR = 0x00; // dummy write |
||
54 | |||
55 | ToNaviCtrl.Sync1 = 0xAA; |
||
56 | ToNaviCtrl.Sync2 = 0x83; |
||
57 | |||
58 | ToNaviCtrl.Command = SPI_FCCMD_USER; |
||
59 | ToNaviCtrl.IntegralNick = 0; |
||
60 | ToNaviCtrl.IntegralRoll = 0; |
||
61 | FromNaviCtrl_Value.SerialDataOkay = 0; |
||
62 | SPI_RxDataValid = 0; |
||
63 | |||
64 | } |
||
65 | |||
66 | //------------------------------------------------------ |
||
67 | unsigned char SPI_StartTransmitPacket(void) |
||
68 | { |
||
69 | if(!SPITransferCompleted) return(0); |
||
70 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
||
71 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
||
72 | |||
73 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
||
74 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
||
75 | |||
76 | SPITransferCompleted = 0; |
||
77 | UpdateSPI_Buffer(); // update buffer |
||
78 | SPI_BufferIndex = 1; |
||
79 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
||
80 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
||
81 | return(1); |
||
82 | } |
||
83 | |||
84 | //------------------------------------------------------ |
||
85 | //SIGNAL(SIG_SPI) |
||
86 | void SPI_TransmitByte(void) |
||
87 | { |
||
88 | static unsigned char SPI_RXState = 0; |
||
89 | unsigned char rxdata; |
||
90 | static unsigned char rxchksum; |
||
91 | |||
92 | if (SPITransferCompleted) return; |
||
93 | if (!(SPSR & (1 << SPIF))) return; |
||
94 | BytegapSPI = SPI_BYTEGAP; |
||
95 | // _delay_us(30); |
||
96 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
||
97 | |||
98 | rxdata = SPDR; |
||
99 | switch ( SPI_RXState) |
||
100 | { |
||
101 | case 0: |
||
102 | SPI_RxBufferIndex = 0; |
||
103 | rxchksum = rxdata; |
||
104 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
||
105 | |||
106 | break; |
||
107 | |||
108 | case 1: |
||
109 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
||
110 | else SPI_RXState = 0; |
||
111 | break; |
||
112 | |||
113 | case 2: |
||
114 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
||
115 | //DebugOut.Analog[19]++; |
||
116 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
||
117 | { |
||
118 | if (rxdata == rxchksum) |
||
119 | { |
||
120 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
||
121 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
||
122 | SPI_RxDataValid = 1; |
||
123 | } |
||
124 | else |
||
125 | { |
||
126 | SPI_RxDataValid = 0; |
||
127 | } |
||
128 | SPI_RXState = 0; |
||
129 | } |
||
130 | else rxchksum += rxdata; |
||
131 | break; |
||
132 | |||
133 | } |
||
134 | |||
135 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
||
136 | { |
||
137 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
||
138 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
||
139 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
||
140 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
||
141 | } |
||
142 | else SPITransferCompleted = 1; |
||
143 | |||
144 | SPI_BufferIndex++; |
||
145 | } |
||
146 | |||
147 | |||
148 | //------------------------------------------------------ |
||
149 | void UpdateSPI_Buffer(void) |
||
150 | { |
||
151 | signed int tmp; |
||
152 | static unsigned char motorindex, oldcommand = SPI_NCCMD_VERSION, slow_command; |
||
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 |
||
155 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
||
156 | ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier; |
||
157 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
||
158 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
||
159 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
||
160 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
||
161 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
||
162 | switch(ToNaviCtrl.Command) // |
||
163 | { |
||
164 | case SPI_FCCMD_USER: |
||
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; |
||
172 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
||
173 | ToNaviCtrl.Param.Byte[8] = FC_StatusFlags; |
||
174 | //if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) ToNaviCtrl.Param.Byte[8] &= ~FC_STATUS_FLY; |
||
175 | FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START); |
||
176 | ToNaviCtrl.Param.Byte[9] = ActiveParamSet; |
||
177 | ToNaviCtrl.Param.Byte[10] = (unsigned char) UBat; // 0.1V |
||
178 | ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2; |
||
179 | if(!(PORTC & (1<<PORTC2))) FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // Out1 (J16) |
||
180 | break; |
||
181 | case SPI_FCCMD_BL_ACCU: |
||
182 | ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A |
||
183 | ToNaviCtrl.Param.Byte[2] = motorindex; |
||
184 | ToNaviCtrl.Param.Byte[3] = Capacity.MinOfMaxPWM; |
||
185 | ToNaviCtrl.Param.Byte[4] = GetChannelValue(EE_Parameter.NaviGpsModeChannel); // GPS-Mode control |
||
186 | ToNaviCtrl.Param.Byte[5] = VarioCharacter; |
||
187 | ToNaviCtrl.Param.Byte[6] = Motor[motorindex].NotReadyCnt; |
||
188 | ToNaviCtrl.Param.Byte[7] = Motor[motorindex].Version; |
||
189 | ToNaviCtrl.Param.Byte[8] = Motor[motorindex].MaxPWM; |
||
190 | ToNaviCtrl.Param.Byte[9] = Motor[motorindex].State; |
||
191 | ToNaviCtrl.Param.Byte[10] = Motor[motorindex].Temperature; |
||
192 | ToNaviCtrl.Param.Byte[11] = Motor[motorindex].Current; |
||
193 | |||
194 | if(Mixer.Motor[++motorindex][0] <= 0) // next motor is not used ? |
||
195 | while(Mixer.Motor[motorindex][0] <= 0 && motorindex) motorindex = (motorindex + 1) % 13; |
||
196 | break; |
||
197 | case SPI_FCCMD_SLOW: |
||
198 | switch(slow_command) |
||
199 | { |
||
200 | case 0: |
||
201 | ToNaviCtrl.Command = SPI_FCCMD_PARAMETER1; slow_command = 1; |
||
202 | ToNaviCtrl.Param.Byte[0] = (unsigned char) BattLowVoltageWarning; //0.1V |
||
203 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; // Parameters for the Naviboard |
||
204 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
||
205 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
||
206 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
||
207 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsA; |
||
208 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
||
209 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
||
210 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviMaxFlyingRange; |
||
211 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
||
212 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviAccCompensation; |
||
213 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
||
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] = HoverGas / 4; |
||
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 | } |
||
228 | break; |
||
229 | case SPI_FCCMD_PARAMETER2: |
||
230 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.AutoPhotoDistance; // Distance between Photo releases |
||
231 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
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 | } |
||
238 | ToNaviCtrl.Param.Byte[1] = ToNC_SpeakHoTT; |
||
239 | #else |
||
240 | ToNaviCtrl.Param.Byte[1] = 0; |
||
241 | #endif |
||
242 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.LandingSpeed; |
||
243 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ComingHomeAltitude; |
||
244 | ToNaviCtrl.Param.Byte[4] = LowVoltageHomeActive; |
||
245 | ToNaviCtrl.Param.Byte[5] = ToNC_Load_WP_List; |
||
246 | ToNaviCtrl.Param.Byte[6] = ToNC_Load_SingePoint; |
||
247 | ToNaviCtrl.Param.Byte[7] = ToNC_Store_SingePoint; |
||
248 | ToNC_Load_WP_List = 0; |
||
249 | ToNC_Load_SingePoint = 0; |
||
250 | ToNC_Store_SingePoint = 0; |
||
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 |
||
253 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.AutoPhotoAtitudes; |
||
254 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.SingleWpSpeed; |
||
255 | break; |
||
256 | case SPI_FCCMD_STICK: |
||
257 | cli(); |
||
258 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
||
259 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
||
260 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
||
261 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
||
262 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
||
263 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
||
264 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
||
265 | sei(); |
||
266 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
||
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]; |
||
275 | break; |
||
276 | case SPI_FCCMD_MISC: |
||
277 | if(WinkelOut.CalcState >= 5) |
||
278 | { |
||
279 | WinkelOut.CalcState = 0; |
||
280 | ToNaviCtrl.Param.Byte[0] = 5; |
||
281 | } |
||
282 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
||
283 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
||
284 | ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); |
||
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; |
||
289 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay; |
||
290 | ToNaviCtrl.Param.Byte[10] = NC_Wait_for_LED; |
||
291 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil |
||
292 | break; |
||
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; |
||
298 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
||
299 | ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0]; |
||
300 | ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1]; |
||
301 | VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; // VersionInfo.HardwareError[0] = 0; |
||
302 | VersionInfo.HardwareError[1] &= FC_ERROR1_MIXER; |
||
303 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.CompassOffset; |
||
304 | ToNaviCtrl.Param.Byte[8] = Parameter_GlobalConfig; |
||
305 | ToNaviCtrl.Param.Byte[9] = Parameter_ExtraConfig; |
||
306 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle; |
||
307 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.GlobalConfig3; |
||
308 | break; |
||
309 | case SPI_FCCMD_SERVOS: |
||
310 | ToNaviCtrl.Param.Int[0] = Capacity.UsedCapacity; // mAh |
||
311 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
||
312 | ToNaviCtrl.Param.Byte[3] = Parameter_ServoRollControl; |
||
313 | ToNaviCtrl.Param.Byte[4] = DebugOut.Analog[28]; // I2C-Error counter |
||
314 | ToNaviCtrl.Param.Byte[5] = FC_StatusFlags3; |
||
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 |
||
318 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.CamOrientation; |
||
319 | ToNaviCtrl.Param.Byte[11] = VersionInfo.BL_Firmware; |
||
320 | break; |
||
321 | } |
||
322 | |||
323 | if(SPI_RxDataValid) |
||
324 | { |
||
325 | if(FromNaviCtrl.Command != oldcommand) NaviDataOkay = 250; |
||
326 | oldcommand = FromNaviCtrl.Command; |
||
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 | } |
||
333 | |||
334 | // update compass readings |
||
335 | // MagVec.x = FromNaviCtrl.MagVecX; |
||
336 | // MagVec.y = FromNaviCtrl.MagVecY; |
||
337 | // MagVec.z = FromNaviCtrl.MagVecZ; |
||
338 | |||
339 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
||
340 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
||
341 | |||
342 | if(FromNaviCtrl.BeepTime > beeptime && !DisableRcOffBeeping) beeptime = FromNaviCtrl.BeepTime; |
||
343 | switch (FromNaviCtrl.Command) |
||
344 | { |
||
345 | case SPI_NCCMD_KALMAN: |
||
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]; |
||
349 | KompassFusion = FromNaviCtrl.Param.sByte[3]; |
||
350 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
||
351 | FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5]; |
||
352 | FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6]; |
||
353 | GPS_Aid_StickMultiplikator = FromNaviCtrl.Param.Byte[7]; |
||
354 | if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0) |
||
355 | { |
||
356 | KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben |
||
357 | /* |
||
358 | if(EE_Parameter.CamOrientation) // Kamera angle is not front |
||
359 | { |
||
360 | KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15); |
||
361 | KompassSollWert %= 360; |
||
362 | } |
||
363 | */ |
||
364 | } |
||
365 | POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel |
||
366 | break; |
||
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]; |
||
373 | DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5]; |
||
374 | DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08)); |
||
375 | NC_ErrorCode = FromNaviCtrl.Param.Byte[7]; |
||
376 | NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8]; |
||
377 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[9]; |
||
378 | NC_To_FC_Flags = FromNaviCtrl.Param.Byte[10]; |
||
379 | //NC_To_FC_MaxAltitude = FromNaviCtrl.Param.Byte[11]; |
||
380 | break; |
||
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]; |
||
385 | GPSInfo.Speed = FromNaviCtrl.Param.Byte[3]; |
||
386 | GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2]; |
||
387 | GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3]; |
||
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 | } |
||
392 | PPM_in[WP_EVENT_PPM_IN] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value (FromNC_WP_EventChannel) |
||
393 | FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9]; |
||
394 | FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10; // in cm |
||
395 | break; |
||
396 | case SPI_MISC: |
||
397 | EarthMagneticField = FromNaviCtrl.Param.Byte[0]; |
||
398 | EarthMagneticInclination = FromNaviCtrl.Param.Byte[1]; |
||
399 | EarthMagneticInclinationTheoretic = FromNaviCtrl.Param.Byte[2]; |
||
400 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
401 | if(FromNaviCtrl.Param.Byte[3]) |
||
402 | if(!SpeakHoTT || (SpeakHoTT >= SPEAK_GPS_HOLD && SpeakHoTT <= SPEAK_GPS_OFF)) SpeakHoTT = FromNaviCtrl.Param.Byte[3]; |
||
403 | NaviData_TargetDistance = FromNaviCtrl.Param.Int[3]; |
||
404 | #endif |
||
405 | NaviData_WaypointIndex = FromNaviCtrl.Param.Byte[4]; |
||
406 | NaviData_WaypointNumber = FromNaviCtrl.Param.Byte[5]; |
||
407 | NaviData_TargetHoldTime = FromNaviCtrl.Param.Byte[8]; |
||
408 | NaviData_MaxWpListIndex = FromNaviCtrl.Param.Byte[9]; |
||
409 | CompassCorrected = FromNaviCtrl.Param.sInt[5]; // Bytes 10 & 11 |
||
410 | break; |
||
411 | |||
412 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
413 | case SPI_NCCMD_HOTT_DATA: |
||
414 | //if(EE_Parameter.Receiver == RECEIVER_HOTT) |
||
415 | NC_Fills_HoTT_Telemety(); |
||
416 | break; |
||
417 | #endif |
||
418 | |||
419 | // 0 = 0,1 |
||
420 | // 1 = 2,3 |
||
421 | // 2 = 4,5 |
||
422 | // 3 = 6,7 |
||
423 | // 4 = 8,9 |
||
424 | // 5 = 10,11 |
||
425 | default: |
||
426 | break; |
||
427 | } |
||
428 | } |
||
429 | else |
||
430 | { |
||
431 | // KompassValue = 0; |
||
432 | // KompassRichtung = 0; |
||
433 | GPS_Nick = 0; |
||
434 | GPS_Roll = 0; |
||
435 | } |
||
436 | } |
||
437 | |||
438 | #endif |
||
439 | |||
440 |