Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
||
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2050 | holgerb | 4 | // + Software Nutzungsbedingungen (english version: see below) |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
1 | ingob | 10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
19 | // + des Mitverschuldens offen. |
||
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
27 | // + 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. |
||
1 | ingob | 28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 29 | // + Software LICENSING TERMS |
1 | ingob | 30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
32 | // + 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 |
||
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
34 | // + The Software may only be used with the Licensor's products. |
||
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
37 | // + agreement shall be the property of the Licensor. |
||
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
40 | // + The customer shall be responsible for taking reasonable precautions |
||
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
50 | // + #### END OF LICENSING TERMS #### |
||
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
1 | ingob | 52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | #include "main.h" |
||
2628 | holgerb | 54 | unsigned char DisableRcOffBeeping = 1; |
173 | holgerb | 55 | unsigned char PlatinenVersion = 10; |
1232 | hbuss | 56 | unsigned char BattLowVoltageWarning = 94; |
2416 | holgerb | 57 | unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0; |
1298 | hbuss | 58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
1512 | holgerb | 59 | unsigned int FlugSekunden = 0; |
1444 | ingob | 60 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
1702 | holgerb | 61 | unsigned char FoundMotors = 0; |
1834 | holgerb | 62 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
2333 | holgerb | 63 | unsigned char ActiveParamSet = 3; |
2402 | holgerb | 64 | unsigned char LipoCells = 4; |
2617 | holgerb | 65 | unsigned char IamMaster = 0; |
66 | unsigned char Delete_Stoppflag_Timer = 0; |
||
1444 | ingob | 67 | |
2030 | holgerb | 68 | void PrintLine(void) |
69 | { |
||
70 | printf("\n\r==================================="); |
||
71 | } |
||
72 | |||
73 | |||
819 | hbuss | 74 | void CalMk3Mag(void) |
75 | { |
||
76 | static unsigned char stick = 1; |
||
2499 | holgerb | 77 | ChannelAssingment(); |
2496 | holgerb | 78 | if(ChannelNick > -20) stick = 0; |
79 | if((ChannelNick < -70) && !stick) |
||
819 | hbuss | 80 | { |
81 | stick = 1; |
||
82 | WinkelOut.CalcState++; |
||
1051 | killagreg | 83 | if(WinkelOut.CalcState > 4) |
84 | { |
||
2609 | holgerb | 85 | // WinkelOut.CalcState = 0; // in SPI.c |
819 | hbuss | 86 | beeptime = 1000; |
1051 | killagreg | 87 | } |
1232 | hbuss | 88 | else Piep(WinkelOut.CalcState,150); |
819 | hbuss | 89 | } |
2609 | holgerb | 90 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
91 | ShowCmpsCalibrateTime = 6; |
||
92 | #endif |
||
819 | hbuss | 93 | } |
94 | |||
1268 | hbuss | 95 | void LipoDetection(unsigned char print) |
96 | { |
||
2517 | holgerb | 97 | unsigned int warning; |
2407 | holgerb | 98 | #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO |
2408 | holgerb | 99 | if(print) |
100 | { |
||
101 | printf("\n\rBatt:"); |
||
102 | LipoCells = 1 + UBat / MAX_CELL_VOLTAGE; |
||
2416 | holgerb | 103 | if(LipoCells > 6) LipoCells = 6; |
2408 | holgerb | 104 | } |
2416 | holgerb | 105 | |
2390 | holgerb | 106 | if(EE_Parameter.UnterspannungsWarnung < 50) |
1654 | killagreg | 107 | { |
2517 | holgerb | 108 | warning = LipoCells * EE_Parameter.UnterspannungsWarnung; |
1654 | killagreg | 109 | if(print) |
110 | { |
||
2402 | holgerb | 111 | Piep(LipoCells, 200); |
112 | printf(" %d Cells ", LipoCells); |
||
1420 | killagreg | 113 | } |
1654 | killagreg | 114 | } |
2517 | holgerb | 115 | else warning = EE_Parameter.UnterspannungsWarnung; |
116 | if(warning > 255) warning = 255; BattLowVoltageWarning = warning; |
||
2390 | holgerb | 117 | // automatische Zellenerkennung |
2517 | holgerb | 118 | if(EE_Parameter.AutoLandingVoltage < 50) warning = LipoCells * EE_Parameter.AutoLandingVoltage; else warning = EE_Parameter.AutoLandingVoltage; |
119 | if(warning > 255) warning = 255; BattAutoLandingVoltage = warning; |
||
120 | |||
121 | if(EE_Parameter.ComingHomeVoltage < 50) warning = LipoCells * EE_Parameter.ComingHomeVoltage; else warning = EE_Parameter.ComingHomeVoltage; |
||
122 | if(warning > 255) warning = 255; BattComingHomeVoltage = warning; |
||
2390 | holgerb | 123 | |
2416 | holgerb | 124 | if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1; |
125 | if(BattComingHomeVoltage >= BattLowVoltageWarning) BattComingHomeVoltage = BattLowVoltageWarning - 1; |
||
126 | if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1; |
||
2408 | holgerb | 127 | |
2390 | holgerb | 128 | if(print) |
129 | { |
||
2408 | holgerb | 130 | printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
2416 | holgerb | 131 | if(BattComingHomeVoltage) printf(" Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10); |
132 | if(BattAutoLandingVoltage) printf(" Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10); |
||
2390 | holgerb | 133 | } |
2416 | holgerb | 134 | |
1268 | hbuss | 135 | } |
136 | |||
2575 | holgerb | 137 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
138 | void LoadStoreSingleWP(void) |
||
139 | { |
||
140 | // +++++++++++++++++++++++++++++++++++++++++++ |
||
141 | // + Load/Store one single point |
||
142 | // +++++++++++++++++++++++++++++++++++++++++++ |
||
143 | static unsigned char switch_hyterese = 0, hyterese = 1, wp_tmp_s = 0, wp_tmp_l = 0; |
||
144 | static int delay; |
||
145 | |||
146 | if(PPM_in[EE_Parameter.SingleWpControlChannel] > 50) // Switch Up -> load |
||
147 | { |
||
148 | if(switch_hyterese == 1 || switch_hyterese == 3) |
||
149 | { |
||
150 | ToNC_Load_SingePoint = 1; |
||
151 | switch_hyterese = 2; |
||
152 | SpeakHoTT = SPEAK_NEXT_WP; |
||
153 | Show_Load_Time = 5; |
||
154 | Show_Load_Value = 1; |
||
155 | wp_tmp_l = 1; |
||
156 | } |
||
157 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
158 | // Bedienung per Taster am Sender |
||
159 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
||
160 | { |
||
161 | hyterese = 2; |
||
162 | if(CheckDelay(delay)) { wp_tmp_l = 0; hyterese = 1;} |
||
163 | } |
||
164 | else |
||
2605 | holgerb | 165 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
2575 | holgerb | 166 | { |
167 | delay = SetDelay(2500); |
||
168 | if(hyterese == 2 && (wp_tmp_l < NaviData_MaxWpListIndex)) |
||
169 | { |
||
170 | wp_tmp_l++; |
||
171 | ToNC_Load_SingePoint = wp_tmp_l; |
||
172 | Show_Load_Time = 5; |
||
173 | Show_Load_Value = wp_tmp_l; |
||
174 | SpeakHoTT = SPEAK_NEXT_WP; |
||
175 | } |
||
176 | hyterese = 0; |
||
177 | } |
||
178 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
179 | } |
||
180 | else |
||
181 | if(PPM_in[EE_Parameter.SingleWpControlChannel] < -50) // Switch Down -> store |
||
182 | { |
||
183 | if(switch_hyterese == 1 || switch_hyterese == 2) |
||
184 | { |
||
185 | ToNC_Store_SingePoint = 1; |
||
186 | switch_hyterese = 3; |
||
187 | SpeakHoTT = SPEAK_MIKROKOPTER; |
||
188 | Show_Store_Time = 5; |
||
189 | Show_Store_Value = 1; |
||
190 | wp_tmp_s = 1; |
||
191 | } |
||
192 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
193 | // Bedienung per Taster am Sender |
||
194 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
||
195 | { |
||
196 | hyterese = 2; |
||
197 | if(CheckDelay(delay)) { wp_tmp_s = 0; hyterese = 1;} |
||
198 | } |
||
199 | else |
||
2605 | holgerb | 200 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
2575 | holgerb | 201 | { |
202 | delay = SetDelay(2500); |
||
203 | if(hyterese == 2 && (wp_tmp_s < NaviData_MaxWpListIndex)) |
||
204 | { |
||
205 | wp_tmp_s++; |
||
206 | ToNC_Store_SingePoint = wp_tmp_s; |
||
207 | Show_Store_Time = 5; |
||
208 | Show_Store_Value = wp_tmp_s; |
||
209 | SpeakHoTT = SPEAK_MIKROKOPTER; |
||
210 | } |
||
211 | hyterese = 0; |
||
212 | } |
||
213 | } |
||
214 | else // Middle |
||
215 | { |
||
216 | switch_hyterese = 1; |
||
217 | } |
||
218 | } |
||
219 | // +++++++++++++++++++++++++++++++++++++++++++ |
||
220 | #endif |
||
2627 | holgerb | 221 | |
222 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
223 | // check if ServoControl is serial Poti and if yes: check if there is valid data |
||
224 | void InitSerialPoti(void) |
||
225 | { |
||
226 | unsigned char i; |
||
227 | if(!SerialChannelDataOkay) |
||
228 | { |
||
229 | if(EE_Parameter.ServoNickControl >= 248) // Poti-Value |
||
230 | { |
||
231 | i = 255 - EE_Parameter.ServoNickControl; // Poti-number |
||
232 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
||
233 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
||
234 | { |
||
235 | if(EE_Parameter.ServoFS_Pos[0]) PPM_in[i] = EE_Parameter.ServoFS_Pos[0] - 127; // there is a failsafe position |
||
236 | else PPM_in[i] = 0; // middle position |
||
237 | } |
||
238 | } |
||
239 | if(EE_Parameter.ServoRollControl >= 248) // Poti-Value |
||
240 | { |
||
241 | i = 255 - EE_Parameter.ServoRollControl; // Poti-number |
||
242 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
||
243 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
||
244 | { |
||
245 | if(EE_Parameter.ServoFS_Pos[1]) PPM_in[i] = EE_Parameter.ServoFS_Pos[1] - 127; |
||
246 | else PPM_in[i] = 0; // middle position |
||
247 | } |
||
248 | } |
||
249 | if(EE_Parameter.Servo3 >= 248) // Poti-Value |
||
250 | { |
||
251 | i = 255 - EE_Parameter.Servo3; // Poti-number |
||
252 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
||
253 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
||
254 | { |
||
255 | if(EE_Parameter.ServoFS_Pos[2]) PPM_in[i] = EE_Parameter.ServoFS_Pos[2] - 127; |
||
256 | else PPM_in[i] = 0; // middle position |
||
257 | } |
||
258 | } |
||
259 | if(EE_Parameter.Servo4 >= 248) // Poti-Value |
||
260 | { |
||
261 | i = 255 - EE_Parameter.Servo4; // Poti-number |
||
262 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
||
263 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
||
264 | { |
||
265 | if(EE_Parameter.ServoFS_Pos[3]) PPM_in[i] = EE_Parameter.ServoFS_Pos[3] - 127; |
||
266 | else PPM_in[i] = 0; // middle position |
||
267 | } |
||
268 | } |
||
269 | if(EE_Parameter.Servo5 >= 248) // Poti-Value |
||
270 | { |
||
271 | i = 255 - EE_Parameter.Servo5; // Poti-number |
||
272 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
||
273 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
||
274 | { |
||
275 | if(EE_Parameter.ServoFS_Pos[4]) PPM_in[i] = EE_Parameter.ServoFS_Pos[4] - 127; |
||
276 | else PPM_in[i] = 0; // middle position |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | } |
||
281 | |||
1 | ingob | 282 | //############################################################################ |
283 | //Hauptprogramm |
||
284 | int main (void) |
||
285 | //############################################################################ |
||
286 | { |
||
1424 | ingob | 287 | unsigned int timer,i,timer2 = 0, timerPolling; |
2575 | holgerb | 288 | unsigned char update_spi = 1; |
1051 | killagreg | 289 | DDRB = 0x00; |
2330 | holgerb | 290 | PORTB = 0x00; |
2309 | holgerb | 291 | DDRD = 0x0A; // UART & J3 J4 J5 |
2609 | holgerb | 292 | PORTD = 0x7F; // PPM-Input & UART |
188 | holgerb | 293 | for(timer = 0; timer < 1000; timer++); // verzögern |
1660 | holgerb | 294 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2334 | holgerb | 295 | unsigned char AccZ_ErrorCnt = 0; |
2309 | holgerb | 296 | if(PINB & 0x02) |
297 | { |
||
298 | if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND |
||
299 | else { PlatinenVersion = 22; ACC_AltitudeControl = 1;}; |
||
300 | } |
||
301 | else |
||
302 | { |
||
2597 | holgerb | 303 | PlatinenVersion = LIBFC_Get_HW_Version(25); |
2579 | holgerb | 304 | ACC_AltitudeControl = 1; |
305 | J4Low; |
||
2309 | holgerb | 306 | } |
2617 | holgerb | 307 | /* |
308 | if(PlatinenVersion >= 30) -> wird noch der #define gemacht |
||
309 | { |
||
310 | if(!(PIND & 0x20)) IamMaster = SLAVE; // Slave |
||
311 | else IamMaster = MASTER; // Master |
||
312 | } |
||
313 | */ |
||
1660 | holgerb | 314 | #else |
315 | if(PINB & 0x01) |
||
918 | hbuss | 316 | { |
1051 | killagreg | 317 | if(PINB & 0x02) PlatinenVersion = 13; |
318 | else PlatinenVersion = 11; |
||
918 | hbuss | 319 | } |
1051 | killagreg | 320 | else |
1021 | hbuss | 321 | { |
1051 | killagreg | 322 | if(PINB & 0x02) PlatinenVersion = 20; |
2309 | holgerb | 323 | else |
324 | { |
||
325 | PlatinenVersion = 10; |
||
326 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
327 | PORTD = 0x47; // |
||
328 | } |
||
1021 | hbuss | 329 | } |
1660 | holgerb | 330 | #endif |
2316 | holgerb | 331 | |
2309 | holgerb | 332 | DDRC = 0x81; // I2C, Spaker |
1036 | hbuss | 333 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 334 | PORTC = 0xff; // Pullup SDA |
335 | DDRB = 0x1B; // LEDs und Druckoffset |
||
2609 | holgerb | 336 | PORTB = 0x05; // LED_Rot & pullup on PB2 (RC-Voltage detection) |
2597 | holgerb | 337 | |
2146 | holgerb | 338 | HEF4017Reset_ON; |
1 | ingob | 339 | MCUSR &=~(1<<WDRF); |
340 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
341 | WDTCSR = 0; |
||
342 | |||
1652 | holgerb | 343 | beeptime = 2500; |
2496 | holgerb | 344 | StickGier = 0; StickRoll = 0; StickNick = 0; |
1660 | holgerb | 345 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
1 | ingob | 346 | ROT_OFF; |
2193 | holgerb | 347 | GRN_ON; |
1479 | killagreg | 348 | |
1 | ingob | 349 | Timer_Init(); |
1156 | hbuss | 350 | TIMER2_Init(); |
1 | ingob | 351 | UART_Init(); |
352 | rc_sum_init(); |
||
353 | ADC_Init(); |
||
1743 | holgerb | 354 | I2C_Init(1); |
597 | ingob | 355 | SPI_MasterInit(); |
1486 | killagreg | 356 | Capacity_Init(); |
2309 | holgerb | 357 | LIBFC_Init(LIB_FC_COMPATIBLE); |
1431 | ingob | 358 | GRN_ON; |
359 | sei(); |
||
1622 | killagreg | 360 | ParamSet_Init(); |
1211 | hbuss | 361 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2426 | holgerb | 362 | if(PlatinenVersion < 20) |
363 | { |
||
364 | wdt_enable(WDTO_250MS); // Reset-Commando |
||
2462 | holgerb | 365 | while(1) printf("\n\rOld FC Hardware not supported by this Firmware!"); |
2426 | holgerb | 366 | } |
2427 | holgerb | 367 | #ifndef REDUNDANT_FC_SLAVE |
2426 | holgerb | 368 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1211 | hbuss | 369 | // + Check connected BL-Ctrls |
370 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1648 | killagreg | 371 | // Check connected BL-Ctrls |
372 | BLFlags |= BLFLAG_READ_VERSION; |
||
1662 | killagreg | 373 | motor_read = 0; // read the first I2C-Data |
2466 | holgerb | 374 | for(i=0; i < 500; i++) |
375 | { |
||
376 | SendMotorData(); |
||
377 | timer = SetDelay(5); |
||
378 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
379 | } |
||
1648 | killagreg | 380 | printf("\n\rFound BL-Ctrl: "); |
2466 | holgerb | 381 | // timer = SetDelay(1000); |
1211 | hbuss | 382 | for(i=0; i < MAX_MOTORS; i++) |
1622 | killagreg | 383 | { |
2466 | holgerb | 384 | // SendMotorData(); |
385 | // while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
1622 | killagreg | 386 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
387 | { |
||
1648 | killagreg | 388 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
389 | { |
||
2496 | holgerb | 390 | if((BLFlags & BLFLAG_TX_COMPLETE)) SendMotorData(); |
391 | //while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
1648 | killagreg | 392 | } |
1232 | hbuss | 393 | } |
1648 | killagreg | 394 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
395 | { |
||
2466 | holgerb | 396 | unsigned char vers; |
397 | printf("%d",(i+1)%10); |
||
1702 | holgerb | 398 | FoundMotors++; |
2466 | holgerb | 399 | vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04 |
400 | if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers; |
||
2527 | holgerb | 401 | //if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)"); |
402 | //if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)"); |
||
403 | //printf(":V%03d\n\r",vers); |
||
1648 | killagreg | 404 | } |
1622 | killagreg | 405 | } |
1211 | hbuss | 406 | for(i=0; i < MAX_MOTORS; i++) |
1051 | killagreg | 407 | { |
1622 | killagreg | 408 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
409 | { |
||
410 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
||
1701 | holgerb | 411 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
1111 | hbuss | 412 | } |
1622 | killagreg | 413 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
1 | ingob | 414 | } |
2466 | holgerb | 415 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
416 | if(VersionInfo.BL_Firmware != 255) |
||
417 | { |
||
418 | printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100); |
||
419 | if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!"); |
||
420 | } |
||
421 | #endif |
||
422 | |||
2030 | holgerb | 423 | PrintLine();// ("\n\r==================================="); |
1765 | killagreg | 424 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
2407 | holgerb | 425 | if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors; |
2437 | holgerb | 426 | #else |
2462 | holgerb | 427 | printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r"); |
2617 | holgerb | 428 | IamMaster = SLAVE; |
2437 | holgerb | 429 | #endif |
430 | |||
431 | #ifdef REDUNDANT_FC_MASTER |
||
2462 | holgerb | 432 | printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r"); |
2617 | holgerb | 433 | IamMaster = MASTER; |
2437 | holgerb | 434 | #endif |
2427 | holgerb | 435 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
436 | // Calibrating altitude sensor |
||
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1529 | killagreg | 438 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1622 | killagreg | 439 | { |
440 | printf("\n\rCalibrating pressure sensor.."); |
||
441 | timer = SetDelay(1000); |
||
442 | SucheLuftruckOffset(); |
||
443 | while (!CheckDelay(timer)); |
||
444 | printf("OK\n\r"); |
||
1 | ingob | 445 | } |
1051 | killagreg | 446 | |
2427 | holgerb | 447 | #ifdef REDUNDANT_FC_SLAVE |
2418 | holgerb | 448 | VersionInfo.HardwareError[0] = 0; |
449 | VersionInfo.HardwareError[1] = 0; |
||
450 | #endif |
||
451 | |||
1622 | killagreg | 452 | SetNeutral(0); |
1 | ingob | 453 | |
454 | ROT_OFF; |
||
1051 | killagreg | 455 | |
1 | ingob | 456 | beeptime = 2000; |
457 | |||
1652 | holgerb | 458 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
459 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
||
1622 | killagreg | 460 | |
1702 | holgerb | 461 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
1622 | killagreg | 462 | { |
463 | FlugMinuten = 0; |
||
464 | FlugMinutenGesamt = 0; |
||
465 | } |
||
2034 | holgerb | 466 | printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
1 | ingob | 467 | LcdClear(); |
173 | holgerb | 468 | I2CTimeout = 5000; |
819 | hbuss | 469 | WinkelOut.Orientation = 1; |
1268 | hbuss | 470 | LipoDetection(1); |
1626 | killagreg | 471 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
2030 | holgerb | 472 | PrintLine();// ("\n\r==================================="); |
1622 | killagreg | 473 | //SpektrumBinding(); |
1350 | hbuss | 474 | timer = SetDelay(2000); |
1424 | ingob | 475 | timerPolling = SetDelay(250); |
1648 | killagreg | 476 | |
1636 | ingob | 477 | Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
2340 | holgerb | 478 | //printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN); |
479 | |||
1702 | holgerb | 480 | DebugOut.Status[0] = 0x01 | 0x02; |
1834 | holgerb | 481 | JetiBeep = 0; |
2628 | holgerb | 482 | if(!(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)) DisableRcOffBeeping = 0; |
2466 | holgerb | 483 | ReadBlSize = 3; // don't read the version any more |
2462 | holgerb | 484 | #ifdef REDUNDANT_FC_SLAVE |
485 | timer = SetDelay(2500); |
||
486 | while(!CheckDelay(timer)); |
||
487 | printf("\n\rStart\n\r"); |
||
488 | #endif |
||
2597 | holgerb | 489 | // printf("\n\rSize %i\n\r", sizeof(HugeBlockToNavi)); |
2330 | holgerb | 490 | while(1) |
1 | ingob | 491 | { |
2439 | holgerb | 492 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
1945 | holgerb | 493 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
1419 | ingob | 494 | if(UpdateMotor && AdReady) // ReglerIntervall |
1051 | killagreg | 495 | { |
2386 | holgerb | 496 | cli(); |
497 | UpdateMotor--; |
||
498 | sei(); |
||
819 | hbuss | 499 | if(WinkelOut.CalcState) CalMk3Mag(); |
1644 | holgerb | 500 | else MotorRegler(); |
501 | SendMotorData(); |
||
1 | ingob | 502 | ROT_OFF; |
2597 | holgerb | 503 | |
504 | if(SenderOkay > ReceiverOkay) ReceiverOkay = SenderOkay; |
||
505 | |||
506 | if(ReceiverOkay) ReceiverOkay--; |
||
507 | else |
||
508 | { |
||
509 | ChannelNick = 0; |
||
510 | ChannelRoll = 0; |
||
511 | ChannelYaw = 0; |
||
512 | ChannelGas = 0; |
||
513 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
||
514 | } |
||
515 | |||
1937 | holgerb | 516 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
1603 | killagreg | 517 | else |
518 | { |
||
519 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
||
520 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
||
2486 | holgerb | 521 | // Now clear the channel values - they would be wrong |
522 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
||
523 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
524 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
||
525 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
526 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
527 | PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
||
1603 | killagreg | 528 | } |
1420 | killagreg | 529 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1481 | holgerb | 530 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
531 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
||
1309 | hbuss | 532 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1210 | hbuss | 533 | if(!--I2CTimeout || MissingMotor) |
173 | holgerb | 534 | { |
1254 | killagreg | 535 | if(!I2CTimeout) |
1210 | hbuss | 536 | { |
1662 | killagreg | 537 | I2C_Reset(); |
1210 | hbuss | 538 | I2CTimeout = 5; |
1322 | hbuss | 539 | DebugOut.Analog[28]++; // I2C-Error |
1765 | killagreg | 540 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
1702 | holgerb | 541 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
1322 | hbuss | 542 | } |
1051 | killagreg | 543 | if((BeepMuster == 0xffff) && MotorenEin) |
544 | { |
||
1936 | holgerb | 545 | beeptime = 25000; |
173 | holgerb | 546 | BeepMuster = 0x0080; |
1051 | killagreg | 547 | } |
1 | ingob | 548 | } |
1051 | killagreg | 549 | else |
1 | ingob | 550 | { |
1051 | killagreg | 551 | ROT_OFF; |
1944 | holgerb | 552 | } |
1916 | holgerb | 553 | LIBFC_Polling(); |
554 | |||
1639 | holgerb | 555 | if(!UpdateMotor) |
2012 | holgerb | 556 | { |
557 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
558 | if(NewSBusData) ProcessSBus(); |
||
559 | else |
||
2543 | holgerb | 560 | if(NewMlinkData) ProcessMlinkData(); |
561 | else |
||
2012 | holgerb | 562 | #endif |
1639 | holgerb | 563 | { |
2404 | holgerb | 564 | if(BytegapSPI == 0) SPI_TransmitByte(); |
2627 | holgerb | 565 | if(CalculateServoSignals) CalculateServo(0); |
1760 | holgerb | 566 | DatenUebertragung(); |
567 | BearbeiteRxDaten(); |
||
2609 | holgerb | 568 | if(!(PINB & 0x04)) VersionInfo.HardwareError[1] |= FC_ERROR1_RC_VOLTAGE; |
1254 | killagreg | 569 | if(CheckDelay(timer)) |
570 | { |
||
1512 | holgerb | 571 | static unsigned char second; |
1420 | killagreg | 572 | timer += 20; // 20 ms interval |
2191 | holgerb | 573 | CalcNickServoValue(); |
2609 | holgerb | 574 | if(!CalibrationDone) FC_StatusFlags3 |= FC_STATUS3_NOT_CALIBRATED; else FC_StatusFlags3 &= ~FC_STATUS3_NOT_CALIBRATED; |
2497 | holgerb | 575 | // ++++++++++++++++++++++++++++ |
576 | // + New direction setpoint from NC |
||
2605 | holgerb | 577 | if((NC_CompassSetpoint != -1) && !NeueKompassRichtungMerken) |
2497 | holgerb | 578 | { |
579 | int diff; |
||
2605 | holgerb | 580 | if((KompassSollWert != NC_CompassSetpoint) && (CareFree || NCForcesNewDirection)) |
2497 | holgerb | 581 | { |
582 | diff = ((540 + (KompassSollWert - NC_CompassSetpoint)) % 360) - 180; |
||
583 | if(diff > 2) diff = 2; // max. 2° in 20ms = 100°/sec |
||
584 | else |
||
585 | if(diff < -2) diff = -2; |
||
586 | KompassSollWert -= diff; |
||
587 | } |
||
2500 | holgerb | 588 | else |
589 | { |
||
590 | NC_CompassSetpoint = -1; |
||
591 | NCForcesNewDirection = 0; // allows Yawing without CareFree (Yawing at Coming Home) |
||
592 | } |
||
2497 | holgerb | 593 | } |
594 | // ++++++++++++++++++++++++++++ |
||
1925 | holgerb | 595 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1917 | holgerb | 596 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
2263 | holgerb | 597 | else |
598 | if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario(); |
||
2334 | holgerb | 599 | // ++++++++++++++++++++++++++++ |
600 | // + check the ACC-Z range |
||
601 | if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil |
||
602 | { |
||
603 | if(++AccZ_ErrorCnt > 50) |
||
604 | { |
||
605 | if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; |
||
606 | else CalibrationDone = 0; |
||
607 | } |
||
608 | } |
||
609 | else AccZ_ErrorCnt = 0; |
||
610 | // ++++++++++++++++++++++++++++ |
||
1925 | holgerb | 611 | #endif |
2390 | holgerb | 612 | if(MissingMotor || Capacity.MinOfMaxPWM < 30) |
1702 | holgerb | 613 | { |
2390 | holgerb | 614 | if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
1702 | holgerb | 615 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
1765 | killagreg | 616 | } |
617 | else |
||
1702 | holgerb | 618 | { |
1936 | holgerb | 619 | if(!beeptime) |
620 | { |
||
621 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
||
622 | } |
||
1765 | killagreg | 623 | } |
2597 | holgerb | 624 | if(DisableRcOffBeeping) if(ReceiverOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
1420 | killagreg | 625 | if(PcZugriff) PcZugriff--; |
626 | else |
||
627 | { |
||
2597 | holgerb | 628 | if(!ReceiverOkay) |
1420 | killagreg | 629 | { |
1914 | holgerb | 630 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
1913 | holgerb | 631 | { |
632 | beeptime = 15000; |
||
633 | BeepMuster = 0x0c00; |
||
1914 | holgerb | 634 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
1913 | holgerb | 635 | } |
1914 | holgerb | 636 | } |
1420 | killagreg | 637 | } |
1682 | holgerb | 638 | if(NaviDataOkay > 200) |
1420 | killagreg | 639 | { |
640 | NaviDataOkay--; |
||
1765 | killagreg | 641 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
2342 | holgerb | 642 | VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT; |
1420 | killagreg | 643 | } |
644 | else |
||
645 | { |
||
1702 | holgerb | 646 | if(NC_Version.Compatible) |
647 | { |
||
1930 | holgerb | 648 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
649 | NC_ErrorCode = 9; // "ERR: no NC communication" |
||
1702 | holgerb | 650 | if(BeepMuster == 0xffff && MotorenEin) |
651 | { |
||
652 | beeptime = 15000; |
||
653 | BeepMuster = 0xA800; |
||
654 | } |
||
1765 | killagreg | 655 | } |
1420 | killagreg | 656 | GPS_Nick = 0; |
657 | GPS_Roll = 0; |
||
1945 | holgerb | 658 | GPS_Aid_StickMultiplikator = 0; |
1916 | holgerb | 659 | GPSInfo.Flags = 0; |
2348 | holgerb | 660 | FromNaviCtrl_Value.Kalman_K = -1; |
1936 | holgerb | 661 | FromNaviCtrl.AccErrorN = 0; |
662 | FromNaviCtrl.AccErrorR = 0; |
||
1691 | holgerb | 663 | FromNaviCtrl.CompassValue = -1; |
2342 | holgerb | 664 | FromNC_AltitudeSpeed = 0; |
665 | FromNC_AltitudeSetpoint = 0; |
||
666 | VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT; |
||
2553 | holgerb | 667 | NC_To_FC_Flags = 0; |
1703 | holgerb | 668 | NaviDataOkay = 0; |
1420 | killagreg | 669 | } |
2390 | holgerb | 670 | if(UBat <= BattLowVoltageWarning) |
1254 | killagreg | 671 | { |
1765 | killagreg | 672 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
2373 | holgerb | 673 | if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB) |
1254 | killagreg | 674 | { |
675 | beeptime = 6000; |
||
676 | BeepMuster = 0x0300; |
||
677 | } |
||
678 | } |
||
2009 | holgerb | 679 | // +++++++++++++++++++++++++++++++++ |
2496 | holgerb | 680 | if(ExternalControlTimeout) |
681 | { |
||
682 | ExternalControlTimeout--; |
||
2577 | holgerb | 683 | if(ExternalControlTimeout == 1) |
684 | { |
||
685 | ExternalControl.Config = 0; |
||
686 | beeptime = 2000; |
||
687 | } |
||
2496 | holgerb | 688 | } |
2346 | holgerb | 689 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2563 | holgerb | 690 | // +++++++++++++++++++++++++++++++++++++++++++ |
691 | // + Load/Store one single point |
||
692 | // +++++++++++++++++++++++++++++++++++++++++++ |
||
2575 | holgerb | 693 | if(EE_Parameter.SingleWpControlChannel) LoadStoreSingleWP(); |
2563 | holgerb | 694 | // +++++++++++++++++++++++++++++++++++++++++++ |
695 | #endif |
||
2576 | holgerb | 696 | #ifdef NO_RECEIVER |
697 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
||
698 | PPM_in[EE_Parameter.HoeheChannel] = (unsigned char) 200; |
||
699 | PPM_in[EE_Parameter.NaviGpsModeChannel] = (unsigned char) 200; |
||
700 | PPM_in[EE_Parameter.CareFreeChannel] = (unsigned char) 200; |
||
701 | SenderOkay = 180; |
||
702 | MotorenEin = 0; |
||
703 | #endif |
||
2575 | holgerb | 704 | // +++++++++++++++++++++++++++++++++ |
705 | // Sekundentakt |
||
706 | if(++second == 49) |
||
707 | { |
||
708 | second = 0; |
||
2563 | holgerb | 709 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2345 | holgerb | 710 | if(ShowSettingNameTime) ShowSettingNameTime--; |
2575 | holgerb | 711 | if(Show_Load_Time) Show_Load_Time--; |
712 | if(Show_Store_Time) Show_Store_Time--; |
||
2609 | holgerb | 713 | if(ShowCmpsCalibrateTime) ShowCmpsCalibrateTime--; |
2617 | holgerb | 714 | if(Delete_Stoppflag_Timer) Delete_Stoppflag_Timer--; else FC_StatusFlags3 &= ~FC_STATUS3_MOTORS_STOPPED_BY_RC; |
2346 | holgerb | 715 | #endif |
2627 | holgerb | 716 | if(SerialChannelDataOkay) if(--SerialChannelDataOkay == 0) InitSerialPoti(); |
2541 | holgerb | 717 | if(NC_To_FC_Flags & NC_TO_FC_FAILSAFE_LANDING) ServoFailsafeActive = SERVO_FS_TIME; |
718 | else |
||
719 | if(ServoFailsafeActive) ServoFailsafeActive--; |
||
720 | |||
2009 | holgerb | 721 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
2309 | holgerb | 722 | else timer2 = 1450; // 0,5 Minuten aufrunden |
723 | if(modell_fliegt < 1024) |
||
2009 | holgerb | 724 | { |
2309 | holgerb | 725 | if(StartLuftdruck < Luftdruck) StartLuftdruck += 5; |
2009 | holgerb | 726 | else |
2309 | holgerb | 727 | if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5; |
2534 | holgerb | 728 | FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
2009 | holgerb | 729 | } |
2534 | holgerb | 730 | else |
731 | { |
||
732 | #ifdef REDUNDANT_FC_MASTER |
||
733 | if(!(FC_StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE)) FC_StatusFlags3 |= FC_STATUS3_REDUNDANCE_ERROR; |
||
734 | else FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
||
735 | #endif |
||
736 | } |
||
2390 | holgerb | 737 | if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
2627 | holgerb | 738 | TIMSK2 |= (1<<OCIE2A); // enable Servo-Interrupt now |
1512 | holgerb | 739 | } |
2009 | holgerb | 740 | // +++++++++++++++++++++++++++++++++ |
1320 | hbuss | 741 | if(++timer2 == 2930) // eine Minute |
1298 | hbuss | 742 | { |
743 | timer2 = 0; |
||
744 | FlugMinuten++; |
||
745 | FlugMinutenGesamt++; |
||
1652 | holgerb | 746 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
747 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
||
748 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
||
749 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
||
1344 | hbuss | 750 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
1298 | hbuss | 751 | } |
1254 | killagreg | 752 | } |
921 | hbuss | 753 | LED_Update(); |
1486 | killagreg | 754 | Capacity_Update(); |
2386 | holgerb | 755 | } |
756 | } //else DebugOut.Analog[18]++; |
||
2341 | holgerb | 757 | if(update_spi) update_spi--; |
758 | } // 500Hz |
||
2386 | holgerb | 759 | if(update_spi == 0) // 41Hz |
760 | { |
||
2628 | holgerb | 761 | if(!MotorenEin && NC_RequestsConfig) { SendSettingToNC(); update_spi = 12;} |
2604 | holgerb | 762 | else |
2386 | holgerb | 763 | if(SPI_StartTransmitPacket()) update_spi = 12; |
764 | else |
||
765 | if(BytegapSPI == 0) SPI_TransmitByte(); |
||
766 | } |
||
767 | else if(BytegapSPI == 0) SPI_TransmitByte(); |
||
1 | ingob | 768 | } |
769 | } |
||
2534 | holgerb | 770 | //DebugOut.Analog[] |
1 | ingob | 771 | |
2604 | holgerb | 772 |