Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2506 | - | 1 | /* |
2 | * FlightCtrl.c |
||
3 | * |
||
4 | * Created: 03.02.2015 06:32:39 |
||
5 | * Author: SIE-AV |
||
6 | */ |
||
7 | |||
8 | |||
9 | #include <avr/io.h> |
||
10 | |||
11 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
12 | // + www.MikroKopter.com |
||
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
14 | // + Software Nutzungsbedingungen (english version: see below) |
||
15 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
16 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
17 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
18 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
19 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
20 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
21 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
||
22 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
23 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
24 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
25 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
26 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
27 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
28 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
29 | // + des Mitverschuldens offen. |
||
30 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
31 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
32 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
33 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
34 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
35 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
36 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
37 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
38 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
39 | // + Software LICENSING TERMS |
||
40 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
41 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
||
42 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
43 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
44 | // + The Software may only be used with the Licensor's products. |
||
45 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
46 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
47 | // + agreement shall be the property of the Licensor. |
||
48 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
49 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
50 | // + The customer shall be responsible for taking reasonable precautions |
||
51 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
52 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
53 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
54 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
55 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
56 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
57 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
58 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
59 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
60 | // + #### END OF LICENSING TERMS #### |
||
61 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
62 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
63 | #include "main.h" |
||
64 | unsigned char DisableRcOffBeeping = 0; |
||
65 | unsigned char PlatinenVersion = 10; |
||
66 | unsigned char BattLowVoltageWarning = 94; |
||
67 | unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0; |
||
68 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
||
69 | unsigned int FlugSekunden = 0; |
||
70 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
||
71 | unsigned char FoundMotors = 0; |
||
72 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
||
73 | unsigned char ActiveParamSet = 3; |
||
74 | unsigned char LipoCells = 4; |
||
75 | |||
76 | void PrintLine(void) |
||
77 | { |
||
78 | printf("\n\r==================================="); |
||
79 | } |
||
80 | |||
81 | |||
82 | void CalMk3Mag(void) |
||
83 | { |
||
84 | static unsigned char stick = 1; |
||
85 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
86 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
87 | { |
||
88 | stick = 1; |
||
89 | WinkelOut.CalcState++; |
||
90 | if(WinkelOut.CalcState > 4) |
||
91 | { |
||
92 | // WinkelOut.CalcState = 0; // in Uart.c |
||
93 | beeptime = 1000; |
||
94 | } |
||
95 | else Piep(WinkelOut.CalcState,150); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | |||
100 | void LipoDetection(unsigned char print) |
||
101 | { |
||
102 | #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO |
||
103 | if(print) |
||
104 | { |
||
105 | printf("\n\rBatt:"); |
||
106 | LipoCells = 1 + UBat / MAX_CELL_VOLTAGE; |
||
107 | if(LipoCells > 6) LipoCells = 6; |
||
108 | } |
||
109 | |||
110 | if(EE_Parameter.UnterspannungsWarnung < 50) |
||
111 | { |
||
112 | BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung; |
||
113 | if(print) |
||
114 | { |
||
115 | Piep(LipoCells, 200); |
||
116 | printf(" %d Cells ", LipoCells); |
||
117 | } |
||
118 | } |
||
119 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
||
120 | |||
121 | // automatische Zellenerkennung |
||
122 | if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage; |
||
123 | if(EE_Parameter.ComingHomeVoltage < 50) BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage; |
||
124 | |||
125 | if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1; |
||
126 | if(BattComingHomeVoltage >= BattLowVoltageWarning) BattComingHomeVoltage = BattLowVoltageWarning - 1; |
||
127 | if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1; |
||
128 | |||
129 | if(print) |
||
130 | { |
||
131 | printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
||
132 | if(BattComingHomeVoltage) printf(" Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10); |
||
133 | if(BattAutoLandingVoltage) printf(" Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10); |
||
134 | } |
||
135 | |||
136 | } |
||
137 | |||
138 | //############################################################################ |
||
139 | //Hauptprogramm |
||
140 | int main (void) |
||
141 | //############################################################################ |
||
142 | { |
||
143 | unsigned int timer,i,timer2 = 0, timerPolling; |
||
144 | unsigned char update_spi = 1; |
||
145 | DDRB = 0x00; |
||
146 | PORTB = 0x00; |
||
147 | DDRD = 0x0A; // UART & J3 J4 J5 |
||
148 | PORTD = 0x5F; // PPM-Input & UART |
||
149 | for(timer = 0; timer < 1000; timer++); // verzögern |
||
150 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
151 | unsigned char AccZ_ErrorCnt = 0; |
||
152 | if(PINB & 0x02) |
||
153 | { |
||
154 | if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND |
||
155 | else { PlatinenVersion = 22; ACC_AltitudeControl = 1;}; |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | PlatinenVersion = 25; ACC_AltitudeControl = 1; |
||
160 | } |
||
161 | #else |
||
162 | if(PINB & 0x01) |
||
163 | { |
||
164 | if(PINB & 0x02) PlatinenVersion = 13; |
||
165 | else PlatinenVersion = 11; |
||
166 | } |
||
167 | else |
||
168 | { |
||
169 | if(PINB & 0x02) PlatinenVersion = 20; |
||
170 | else |
||
171 | { |
||
172 | PlatinenVersion = 10; |
||
173 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
174 | PORTD = 0x47; // |
||
175 | } |
||
176 | } |
||
177 | #endif |
||
178 | |||
179 | DDRC = 0x81; // I2C, Spaker |
||
180 | DDRC |=0x40; // HEF4017 Reset |
||
181 | PORTC = 0xff; // Pullup SDA |
||
182 | DDRB = 0x1B; // LEDs und Druckoffset |
||
183 | PORTB = 0x01; // LED_Rot |
||
184 | |||
185 | HEF4017Reset_ON; |
||
186 | MCUSR &=~(1<<WDRF); |
||
187 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
188 | WDTCSR = 0; |
||
189 | |||
190 | beeptime = 2500; |
||
191 | StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0; |
||
192 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
||
193 | ROT_OFF; |
||
194 | GRN_ON; |
||
195 | |||
196 | Timer_Init(); |
||
197 | TIMER2_Init(); |
||
198 | UART_Init(); |
||
199 | rc_sum_init(); |
||
200 | ADC_Init(); |
||
201 | I2C_Init(1); |
||
202 | SPI_MasterInit(); |
||
203 | Capacity_Init(); |
||
204 | LIBFC_Init(LIB_FC_COMPATIBLE); |
||
205 | GRN_ON; |
||
206 | sei(); |
||
207 | ParamSet_Init(); |
||
208 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
209 | if(PlatinenVersion < 20) |
||
210 | { |
||
211 | wdt_enable(WDTO_250MS); // Reset-Commando |
||
212 | while(1) printf("\n\rOld FC Hardware not supported by this Firmware!"); |
||
213 | } |
||
214 | #ifndef REDUNDANT_FC_SLAVE |
||
215 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
216 | // + Check connected BL-Ctrls |
||
217 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
218 | // Check connected BL-Ctrls |
||
219 | BLFlags |= BLFLAG_READ_VERSION; |
||
220 | motor_read = 0; // read the first I2C-Data |
||
221 | for(i=0; i < 500; i++) |
||
222 | { |
||
223 | SendMotorData(); |
||
224 | timer = SetDelay(5); |
||
225 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
226 | } |
||
227 | printf("\n\rFound BL-Ctrl: "); |
||
228 | // timer = SetDelay(1000); |
||
229 | for(i=0; i < MAX_MOTORS; i++) |
||
230 | { |
||
231 | // SendMotorData(); |
||
232 | // while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
233 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
||
234 | { |
||
235 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
||
236 | { |
||
237 | SendMotorData(); |
||
238 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
239 | } |
||
240 | } |
||
241 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
||
242 | { |
||
243 | unsigned char vers; |
||
244 | printf("%d",(i+1)%10); |
||
245 | FoundMotors++; |
||
246 | vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04 |
||
247 | if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers; |
||
248 | // if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r"); |
||
249 | // else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r"); |
||
250 | // printf(":V%03d\n\r",vers); |
||
251 | } |
||
252 | } |
||
253 | for(i=0; i < MAX_MOTORS; i++) |
||
254 | { |
||
255 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
||
256 | { |
||
257 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
||
258 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
||
259 | } |
||
260 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
||
261 | } |
||
262 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
263 | if(VersionInfo.BL_Firmware != 255) |
||
264 | { |
||
265 | printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100); |
||
266 | if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!"); |
||
267 | } |
||
268 | #endif |
||
269 | |||
270 | PrintLine();// ("\n\r==================================="); |
||
271 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
||
272 | if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors; |
||
273 | #else |
||
274 | printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r"); |
||
275 | #endif |
||
276 | |||
277 | #ifdef REDUNDANT_FC_MASTER |
||
278 | printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r"); |
||
279 | #endif |
||
280 | |||
281 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
282 | // Calibrating altitude sensor |
||
283 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
284 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
||
285 | { |
||
286 | printf("\n\rCalibrating pressure sensor.."); |
||
287 | timer = SetDelay(1000); |
||
288 | SucheLuftruckOffset(); |
||
289 | while (!CheckDelay(timer)); |
||
290 | printf("OK\n\r"); |
||
291 | } |
||
292 | |||
293 | #ifdef REDUNDANT_FC_SLAVE |
||
294 | VersionInfo.HardwareError[0] = 0; |
||
295 | VersionInfo.HardwareError[1] = 0; |
||
296 | #endif |
||
297 | |||
298 | SetNeutral(0); |
||
299 | |||
300 | ROT_OFF; |
||
301 | |||
302 | beeptime = 2000; |
||
303 | ExternControl.Digital[0] = 0x55; |
||
304 | |||
305 | |||
306 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
||
307 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
||
308 | |||
309 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
||
310 | { |
||
311 | FlugMinuten = 0; |
||
312 | FlugMinutenGesamt = 0; |
||
313 | } |
||
314 | printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
||
315 | LcdClear(); |
||
316 | I2CTimeout = 5000; |
||
317 | WinkelOut.Orientation = 1; |
||
318 | LipoDetection(1); |
||
319 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
||
320 | PrintLine();// ("\n\r==================================="); |
||
321 | //SpektrumBinding(); |
||
322 | timer = SetDelay(2000); |
||
323 | timerPolling = SetDelay(250); |
||
324 | |||
325 | Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
||
326 | //printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN); |
||
327 | |||
328 | DebugOut.Status[0] = 0x01 | 0x02; |
||
329 | JetiBeep = 0; |
||
330 | if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING) DisableRcOffBeeping = 1; |
||
331 | ReadBlSize = 3; // don't read the version any more |
||
332 | #ifdef REDUNDANT_FC_SLAVE |
||
333 | timer = SetDelay(2500); |
||
334 | while(!CheckDelay(timer)); |
||
335 | printf("\n\rStart\n\r"); |
||
336 | #endif |
||
337 | while(1) |
||
338 | { |
||
339 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
||
340 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
||
341 | if(UpdateMotor && AdReady) // ReglerIntervall |
||
342 | { |
||
343 | cli(); |
||
344 | UpdateMotor--; |
||
345 | sei(); |
||
346 | if(WinkelOut.CalcState) CalMk3Mag(); |
||
347 | else MotorRegler(); |
||
348 | SendMotorData(); |
||
349 | ROT_OFF; |
||
350 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
||
351 | else |
||
352 | { |
||
353 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
||
354 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
||
355 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
||
356 | // Now clear the channel values - they would be wrong |
||
357 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
||
358 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
359 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
||
360 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
361 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
362 | PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
||
363 | } |
||
364 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
365 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
||
366 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
||
367 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
368 | if(!--I2CTimeout || MissingMotor) |
||
369 | { |
||
370 | if(!I2CTimeout) |
||
371 | { |
||
372 | I2C_Reset(); |
||
373 | I2CTimeout = 5; |
||
374 | DebugOut.Analog[28]++; // I2C-Error |
||
375 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
||
376 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
||
377 | } |
||
378 | if((BeepMuster == 0xffff) && MotorenEin) |
||
379 | { |
||
380 | beeptime = 25000; |
||
381 | BeepMuster = 0x0080; |
||
382 | } |
||
383 | } |
||
384 | else |
||
385 | { |
||
386 | ROT_OFF; |
||
387 | } |
||
388 | LIBFC_Polling(); |
||
389 | |||
390 | if(!UpdateMotor) |
||
391 | { |
||
392 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
393 | if(NewSBusData) ProcessSBus(); |
||
394 | else |
||
395 | #endif |
||
396 | { |
||
397 | if(BytegapSPI == 0) SPI_TransmitByte(); |
||
398 | if(CalculateServoSignals) CalculateServo(); |
||
399 | DatenUebertragung(); |
||
400 | BearbeiteRxDaten(); |
||
401 | if(CheckDelay(timer)) |
||
402 | { |
||
403 | static unsigned char second; |
||
404 | timer += 20; // 20 ms interval |
||
405 | CalcNickServoValue(); |
||
406 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
407 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
||
408 | else |
||
409 | if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario(); |
||
410 | // ++++++++++++++++++++++++++++ |
||
411 | // + check the ACC-Z range |
||
412 | if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil |
||
413 | { |
||
414 | if(++AccZ_ErrorCnt > 50) |
||
415 | { |
||
416 | if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; |
||
417 | else CalibrationDone = 0; |
||
418 | } |
||
419 | } |
||
420 | else AccZ_ErrorCnt = 0; |
||
421 | // ++++++++++++++++++++++++++++ |
||
422 | #endif |
||
423 | if(MissingMotor || Capacity.MinOfMaxPWM < 30) |
||
424 | { |
||
425 | if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
||
426 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
||
427 | } |
||
428 | else |
||
429 | { |
||
430 | if(!beeptime) |
||
431 | { |
||
432 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
||
433 | } |
||
434 | } |
||
435 | if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
||
436 | if(PcZugriff) PcZugriff--; |
||
437 | else |
||
438 | { |
||
439 | ExternControl.Config = 0; |
||
440 | ExternStickNick = 0; |
||
441 | ExternStickRoll = 0; |
||
442 | ExternStickGier = 0; |
||
443 | if(!SenderOkay) |
||
444 | { |
||
445 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
||
446 | { |
||
447 | beeptime = 15000; |
||
448 | BeepMuster = 0x0c00; |
||
449 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
||
450 | } |
||
451 | } |
||
452 | } |
||
453 | if(NaviDataOkay > 200) |
||
454 | { |
||
455 | NaviDataOkay--; |
||
456 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
||
457 | VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT; |
||
458 | } |
||
459 | else |
||
460 | { |
||
461 | if(NC_Version.Compatible) |
||
462 | { |
||
463 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
||
464 | NC_ErrorCode = 9; // "ERR: no NC communication" |
||
465 | if(BeepMuster == 0xffff && MotorenEin) |
||
466 | { |
||
467 | beeptime = 15000; |
||
468 | BeepMuster = 0xA800; |
||
469 | } |
||
470 | } |
||
471 | GPS_Nick = 0; |
||
472 | GPS_Roll = 0; |
||
473 | GPS_Aid_StickMultiplikator = 0; |
||
474 | GPSInfo.Flags = 0; |
||
475 | FromNaviCtrl_Value.Kalman_K = -1; |
||
476 | FromNaviCtrl.AccErrorN = 0; |
||
477 | FromNaviCtrl.AccErrorR = 0; |
||
478 | FromNaviCtrl.CompassValue = -1; |
||
479 | FromNC_AltitudeSpeed = 0; |
||
480 | FromNC_AltitudeSetpoint = 0; |
||
481 | VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT; |
||
482 | NaviDataOkay = 0; |
||
483 | } |
||
484 | if(UBat <= BattLowVoltageWarning) |
||
485 | { |
||
486 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
||
487 | if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB) |
||
488 | { |
||
489 | beeptime = 6000; |
||
490 | BeepMuster = 0x0300; |
||
491 | } |
||
492 | } |
||
493 | // +++++++++++++++++++++++++++++++++ |
||
494 | // Sekundentakt |
||
495 | if(++second == 49) |
||
496 | { |
||
497 | second = 0; |
||
498 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
499 | if(ShowSettingNameTime) ShowSettingNameTime--; |
||
500 | #endif |
||
501 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
||
502 | else timer2 = 1450; // 0,5 Minuten aufrunden |
||
503 | if(modell_fliegt < 1024) |
||
504 | { |
||
505 | if(StartLuftdruck < Luftdruck) StartLuftdruck += 5; |
||
506 | else |
||
507 | if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5; |
||
508 | } |
||
509 | if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
||
510 | } |
||
511 | // +++++++++++++++++++++++++++++++++ |
||
512 | if(++timer2 == 2930) // eine Minute |
||
513 | { |
||
514 | timer2 = 0; |
||
515 | FlugMinuten++; |
||
516 | FlugMinutenGesamt++; |
||
517 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
||
518 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
||
519 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
||
520 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
||
521 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
||
522 | } |
||
523 | } |
||
524 | LED_Update(); |
||
525 | Capacity_Update(); |
||
526 | } |
||
527 | } //else DebugOut.Analog[18]++; |
||
528 | if(update_spi) update_spi--; |
||
529 | } // 500Hz |
||
530 | if(update_spi == 0) // 41Hz |
||
531 | { |
||
532 | if(SPI_StartTransmitPacket()) update_spi = 12; |
||
533 | else |
||
534 | if(BytegapSPI == 0) SPI_TransmitByte(); |
||
535 | } |
||
536 | else if(BytegapSPI == 0) SPI_TransmitByte(); |
||
537 | } |
||
538 | } |
||
539 | //DebugOut.Analog[16] |
||
540 |