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