Rev 2323 | Go to most recent revision | Details | Compare with Previous | 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" |
||
1913 | holgerb | 54 | unsigned char DisableRcOffBeeping = 0; |
173 | holgerb | 55 | unsigned char PlatinenVersion = 10; |
1232 | hbuss | 56 | unsigned char BattLowVoltageWarning = 94; |
1298 | hbuss | 57 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
1512 | holgerb | 58 | unsigned int FlugSekunden = 0; |
1444 | ingob | 59 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
1702 | holgerb | 60 | unsigned char FoundMotors = 0; |
1834 | holgerb | 61 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
1444 | ingob | 62 | |
2030 | holgerb | 63 | void PrintLine(void) |
64 | { |
||
65 | printf("\n\r==================================="); |
||
66 | } |
||
67 | |||
68 | |||
819 | hbuss | 69 | void CalMk3Mag(void) |
70 | { |
||
71 | static unsigned char stick = 1; |
||
72 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
73 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
74 | { |
||
75 | stick = 1; |
||
76 | WinkelOut.CalcState++; |
||
1051 | killagreg | 77 | if(WinkelOut.CalcState > 4) |
78 | { |
||
819 | hbuss | 79 | // WinkelOut.CalcState = 0; // in Uart.c |
80 | beeptime = 1000; |
||
1051 | killagreg | 81 | } |
1232 | hbuss | 82 | else Piep(WinkelOut.CalcState,150); |
819 | hbuss | 83 | } |
84 | } |
||
85 | |||
1438 | ingob | 86 | |
1268 | hbuss | 87 | void LipoDetection(unsigned char print) |
88 | { |
||
1654 | killagreg | 89 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
90 | unsigned int timer, cells; |
||
91 | if(print) printf("\n\rBatt:"); |
||
92 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
||
93 | { |
||
94 | timer = SetDelay(500); |
||
95 | if(print) while (!CheckDelay(timer)); |
||
1657 | killagreg | 96 | // up to 6s LiPo, less than 2s is technical impossible |
97 | for(cells = 2; cells < 7; cells++) |
||
1654 | killagreg | 98 | { |
99 | if(UBat < cells * MAX_CELL_VOLTAGE) break; |
||
1420 | killagreg | 100 | } |
1654 | killagreg | 101 | |
102 | BattLowVoltageWarning = cells * EE_Parameter.UnterspannungsWarnung; |
||
103 | if(print) |
||
104 | { |
||
105 | Piep(cells, 200); |
||
106 | printf(" %d Cells ", cells); |
||
1420 | killagreg | 107 | } |
1654 | killagreg | 108 | } |
109 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
||
2034 | holgerb | 110 | if(print) printf(" Low warning: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
1268 | hbuss | 111 | } |
112 | |||
1 | ingob | 113 | //############################################################################ |
114 | //Hauptprogramm |
||
115 | int main (void) |
||
116 | //############################################################################ |
||
117 | { |
||
1424 | ingob | 118 | unsigned int timer,i,timer2 = 0, timerPolling; |
1051 | killagreg | 119 | DDRB = 0x00; |
2330 | holgerb | 120 | PORTB = 0x00; |
2309 | holgerb | 121 | DDRD = 0x0A; // UART & J3 J4 J5 |
122 | PORTD = 0x5F; // PPM-Input & UART |
||
188 | holgerb | 123 | for(timer = 0; timer < 1000; timer++); // verzögern |
1660 | holgerb | 124 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2309 | holgerb | 125 | if(PINB & 0x02) |
126 | { |
||
127 | if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND |
||
128 | else { PlatinenVersion = 22; ACC_AltitudeControl = 1;}; |
||
129 | } |
||
130 | else |
||
131 | { |
||
132 | PlatinenVersion = 23; ACC_AltitudeControl = 1; |
||
133 | } |
||
1660 | holgerb | 134 | #else |
135 | if(PINB & 0x01) |
||
918 | hbuss | 136 | { |
1051 | killagreg | 137 | if(PINB & 0x02) PlatinenVersion = 13; |
138 | else PlatinenVersion = 11; |
||
918 | hbuss | 139 | } |
1051 | killagreg | 140 | else |
1021 | hbuss | 141 | { |
1051 | killagreg | 142 | if(PINB & 0x02) PlatinenVersion = 20; |
2309 | holgerb | 143 | else |
144 | { |
||
145 | PlatinenVersion = 10; |
||
146 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
147 | PORTD = 0x47; // |
||
148 | } |
||
1021 | hbuss | 149 | } |
1660 | holgerb | 150 | #endif |
2316 | holgerb | 151 | |
2309 | holgerb | 152 | DDRC = 0x81; // I2C, Spaker |
1036 | hbuss | 153 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 154 | PORTC = 0xff; // Pullup SDA |
155 | DDRB = 0x1B; // LEDs und Druckoffset |
||
156 | PORTB = 0x01; // LED_Rot |
||
2309 | holgerb | 157 | |
2146 | holgerb | 158 | HEF4017Reset_ON; |
1 | ingob | 159 | MCUSR &=~(1<<WDRF); |
160 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
161 | WDTCSR = 0; |
||
162 | |||
1652 | holgerb | 163 | beeptime = 2500; |
1660 | holgerb | 164 | StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0; |
165 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
||
1 | ingob | 166 | ROT_OFF; |
2193 | holgerb | 167 | GRN_ON; |
1479 | killagreg | 168 | |
1 | ingob | 169 | Timer_Init(); |
1156 | hbuss | 170 | TIMER2_Init(); |
1 | ingob | 171 | UART_Init(); |
172 | rc_sum_init(); |
||
173 | ADC_Init(); |
||
1743 | holgerb | 174 | I2C_Init(1); |
597 | ingob | 175 | SPI_MasterInit(); |
1486 | killagreg | 176 | Capacity_Init(); |
2309 | holgerb | 177 | LIBFC_Init(LIB_FC_COMPATIBLE); |
1431 | ingob | 178 | GRN_ON; |
179 | sei(); |
||
2330 | holgerb | 180 | |
181 | if(GetParamByte(PID_EE_REVISION) == EEPARAM_REVISION - 50) SetParamByte(PID_EE_REVISION,EEPARAM_REVISION); // remove the EEPARAM_REVISION_SUB from Version 0.90g |
||
182 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
183 | if(PlatinenVersion != GetParamByte(PID_HARDWARE_VERSION)) |
||
184 | { |
||
185 | if(GetParamByte(PID_HARDWARE_VERSION) == 21) SetParamByte(PID_EE_REVISION,0); // reset the Settings if the Version changed to V2.2 |
||
186 | SetParamByte(PID_HARDWARE_VERSION,PlatinenVersion); // Remember the Version number |
||
187 | wdt_enable(WDTO_15MS); // Reset-Commando |
||
188 | printf("\n\r--> Hardware Version Byte Changed <--"); |
||
189 | while(1); |
||
190 | } |
||
191 | #endif |
||
1622 | killagreg | 192 | ParamSet_Init(); |
1344 | hbuss | 193 | |
1211 | hbuss | 194 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
195 | // + Check connected BL-Ctrls |
||
196 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1648 | killagreg | 197 | // Check connected BL-Ctrls |
198 | BLFlags |= BLFLAG_READ_VERSION; |
||
1662 | killagreg | 199 | motor_read = 0; // read the first I2C-Data |
1648 | killagreg | 200 | SendMotorData(); |
1683 | killagreg | 201 | timer = SetDelay(500); |
202 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
||
1654 | killagreg | 203 | |
1648 | killagreg | 204 | printf("\n\rFound BL-Ctrl: "); |
1591 | holgerb | 205 | timer = SetDelay(4000); |
1211 | hbuss | 206 | for(i=0; i < MAX_MOTORS; i++) |
1622 | killagreg | 207 | { |
208 | SendMotorData(); |
||
1683 | killagreg | 209 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
1622 | killagreg | 210 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
211 | { |
||
1648 | killagreg | 212 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
213 | { |
||
214 | SendMotorData(); |
||
1683 | killagreg | 215 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
1648 | killagreg | 216 | } |
1232 | hbuss | 217 | } |
1648 | killagreg | 218 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
219 | { |
||
220 | printf("%d",i+1); |
||
1702 | holgerb | 221 | FoundMotors++; |
1652 | holgerb | 222 | // if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); |
1648 | killagreg | 223 | } |
1622 | killagreg | 224 | } |
1211 | hbuss | 225 | for(i=0; i < MAX_MOTORS; i++) |
1051 | killagreg | 226 | { |
1622 | killagreg | 227 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
228 | { |
||
229 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
||
1701 | holgerb | 230 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
1111 | hbuss | 231 | } |
1622 | killagreg | 232 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
1 | ingob | 233 | } |
2030 | holgerb | 234 | PrintLine();// ("\n\r==================================="); |
1648 | killagreg | 235 | |
2030 | holgerb | 236 | |
1765 | killagreg | 237 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
1702 | holgerb | 238 | |
1529 | killagreg | 239 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1622 | killagreg | 240 | { |
241 | printf("\n\rCalibrating pressure sensor.."); |
||
242 | timer = SetDelay(1000); |
||
243 | SucheLuftruckOffset(); |
||
244 | while (!CheckDelay(timer)); |
||
245 | printf("OK\n\r"); |
||
1 | ingob | 246 | } |
1051 | killagreg | 247 | |
1622 | killagreg | 248 | SetNeutral(0); |
1 | ingob | 249 | |
250 | ROT_OFF; |
||
1051 | killagreg | 251 | |
1 | ingob | 252 | beeptime = 2000; |
1051 | killagreg | 253 | ExternControl.Digital[0] = 0x55; |
1 | ingob | 254 | |
1051 | killagreg | 255 | |
1652 | holgerb | 256 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
257 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
||
1622 | killagreg | 258 | |
1702 | holgerb | 259 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
1622 | killagreg | 260 | { |
261 | FlugMinuten = 0; |
||
262 | FlugMinutenGesamt = 0; |
||
263 | } |
||
2034 | holgerb | 264 | printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
1622 | killagreg | 265 | |
1 | ingob | 266 | LcdClear(); |
173 | holgerb | 267 | I2CTimeout = 5000; |
819 | hbuss | 268 | WinkelOut.Orientation = 1; |
1268 | hbuss | 269 | LipoDetection(1); |
1626 | killagreg | 270 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
2030 | holgerb | 271 | PrintLine();// ("\n\r==================================="); |
1622 | killagreg | 272 | //SpektrumBinding(); |
1350 | hbuss | 273 | timer = SetDelay(2000); |
1424 | ingob | 274 | timerPolling = SetDelay(250); |
1648 | killagreg | 275 | |
1636 | ingob | 276 | Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
1702 | holgerb | 277 | DebugOut.Status[0] = 0x01 | 0x02; |
1834 | holgerb | 278 | JetiBeep = 0; |
1913 | holgerb | 279 | if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING) DisableRcOffBeeping = 1; |
2330 | holgerb | 280 | while(1) |
1 | ingob | 281 | { |
1945 | holgerb | 282 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
2330 | holgerb | 283 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
1930 | holgerb | 284 | //GRN_ON; |
1419 | ingob | 285 | if(UpdateMotor && AdReady) // ReglerIntervall |
1051 | killagreg | 286 | { |
1930 | holgerb | 287 | //GRN_OFF; |
1907 | ingob | 288 | UpdateMotor=0; |
819 | hbuss | 289 | if(WinkelOut.CalcState) CalMk3Mag(); |
1644 | holgerb | 290 | else MotorRegler(); |
291 | SendMotorData(); |
||
1 | ingob | 292 | ROT_OFF; |
1937 | holgerb | 293 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
1603 | killagreg | 294 | else |
295 | { |
||
296 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
||
297 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
||
1765 | killagreg | 298 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
1603 | killagreg | 299 | } |
1420 | killagreg | 300 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1481 | holgerb | 301 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
302 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
||
1309 | hbuss | 303 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1210 | hbuss | 304 | if(!--I2CTimeout || MissingMotor) |
173 | holgerb | 305 | { |
1254 | killagreg | 306 | if(!I2CTimeout) |
1210 | hbuss | 307 | { |
1662 | killagreg | 308 | I2C_Reset(); |
1210 | hbuss | 309 | I2CTimeout = 5; |
1322 | hbuss | 310 | DebugOut.Analog[28]++; // I2C-Error |
1765 | killagreg | 311 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
1702 | holgerb | 312 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
1322 | hbuss | 313 | } |
1051 | killagreg | 314 | if((BeepMuster == 0xffff) && MotorenEin) |
315 | { |
||
1936 | holgerb | 316 | beeptime = 25000; |
173 | holgerb | 317 | BeepMuster = 0x0080; |
1051 | killagreg | 318 | } |
1 | ingob | 319 | } |
1051 | killagreg | 320 | else |
1 | ingob | 321 | { |
1051 | killagreg | 322 | ROT_OFF; |
1944 | holgerb | 323 | } |
1916 | holgerb | 324 | LIBFC_Polling(); |
325 | |||
1639 | holgerb | 326 | if(!UpdateMotor) |
2012 | holgerb | 327 | { |
328 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
329 | if(NewSBusData) ProcessSBus(); |
||
330 | else |
||
331 | #endif |
||
1639 | holgerb | 332 | { |
1760 | holgerb | 333 | if(CalculateServoSignals) CalculateServo(); |
334 | DatenUebertragung(); |
||
335 | BearbeiteRxDaten(); |
||
1254 | killagreg | 336 | if(CheckDelay(timer)) |
337 | { |
||
1512 | holgerb | 338 | static unsigned char second; |
1420 | killagreg | 339 | timer += 20; // 20 ms interval |
2191 | holgerb | 340 | CalcNickServoValue(); |
1925 | holgerb | 341 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1917 | holgerb | 342 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
2263 | holgerb | 343 | else |
344 | if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario(); |
||
1925 | holgerb | 345 | #endif |
1702 | holgerb | 346 | if(MissingMotor) |
347 | { |
||
1765 | killagreg | 348 | VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
1702 | holgerb | 349 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
1765 | killagreg | 350 | } |
351 | else |
||
1702 | holgerb | 352 | { |
1936 | holgerb | 353 | if(!beeptime) |
354 | { |
||
355 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
||
356 | } |
||
1765 | killagreg | 357 | } |
2029 | holgerb | 358 | if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
1420 | killagreg | 359 | if(PcZugriff) PcZugriff--; |
360 | else |
||
361 | { |
||
362 | ExternControl.Config = 0; |
||
363 | ExternStickNick = 0; |
||
364 | ExternStickRoll = 0; |
||
365 | ExternStickGier = 0; |
||
1913 | holgerb | 366 | if(!SenderOkay) |
1420 | killagreg | 367 | { |
1914 | holgerb | 368 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
1913 | holgerb | 369 | { |
370 | beeptime = 15000; |
||
371 | BeepMuster = 0x0c00; |
||
1914 | holgerb | 372 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
1913 | holgerb | 373 | } |
1914 | holgerb | 374 | } |
1420 | killagreg | 375 | } |
1682 | holgerb | 376 | if(NaviDataOkay > 200) |
1420 | killagreg | 377 | { |
378 | NaviDataOkay--; |
||
1765 | killagreg | 379 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
1420 | killagreg | 380 | } |
381 | else |
||
382 | { |
||
1702 | holgerb | 383 | if(NC_Version.Compatible) |
384 | { |
||
1930 | holgerb | 385 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
386 | NC_ErrorCode = 9; // "ERR: no NC communication" |
||
1702 | holgerb | 387 | if(BeepMuster == 0xffff && MotorenEin) |
388 | { |
||
389 | beeptime = 15000; |
||
390 | BeepMuster = 0xA800; |
||
391 | } |
||
1765 | killagreg | 392 | } |
1420 | killagreg | 393 | GPS_Nick = 0; |
394 | GPS_Roll = 0; |
||
1945 | holgerb | 395 | GPS_Aid_StickMultiplikator = 0; |
1916 | holgerb | 396 | GPSInfo.Flags = 0; |
1936 | holgerb | 397 | FromNaviCtrl.AccErrorN = 0; |
398 | FromNaviCtrl.AccErrorR = 0; |
||
1691 | holgerb | 399 | FromNaviCtrl.CompassValue = -1; |
1703 | holgerb | 400 | NaviDataOkay = 0; |
1420 | killagreg | 401 | } |
1309 | hbuss | 402 | if(UBat < BattLowVoltageWarning) |
1254 | killagreg | 403 | { |
1765 | killagreg | 404 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
1254 | killagreg | 405 | if(BeepMuster == 0xffff) |
406 | { |
||
407 | beeptime = 6000; |
||
408 | BeepMuster = 0x0300; |
||
409 | } |
||
410 | } |
||
1765 | killagreg | 411 | else if(!beeptime) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
1420 | killagreg | 412 | |
1254 | killagreg | 413 | SPI_StartTransmitPacket(); |
414 | SendSPI = 4; |
||
2009 | holgerb | 415 | // +++++++++++++++++++++++++++++++++ |
416 | // Sekundentakt |
||
1512 | holgerb | 417 | if(++second == 49) |
418 | { |
||
419 | second = 0; |
||
2009 | holgerb | 420 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
2309 | holgerb | 421 | else timer2 = 1450; // 0,5 Minuten aufrunden |
422 | if(modell_fliegt < 1024) |
||
2009 | holgerb | 423 | { |
2309 | holgerb | 424 | if(StartLuftdruck < Luftdruck) StartLuftdruck += 5; |
2009 | holgerb | 425 | else |
2309 | holgerb | 426 | if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5; |
2009 | holgerb | 427 | } |
1512 | holgerb | 428 | } |
2009 | holgerb | 429 | // +++++++++++++++++++++++++++++++++ |
1320 | hbuss | 430 | if(++timer2 == 2930) // eine Minute |
1298 | hbuss | 431 | { |
432 | timer2 = 0; |
||
433 | FlugMinuten++; |
||
434 | FlugMinutenGesamt++; |
||
1652 | holgerb | 435 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
436 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
||
437 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
||
438 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
||
1344 | hbuss | 439 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
1298 | hbuss | 440 | } |
1254 | killagreg | 441 | } |
921 | hbuss | 442 | LED_Update(); |
1486 | killagreg | 443 | Capacity_Update(); |
1936 | holgerb | 444 | } //else DebugOut.Analog[26]++; |
604 | hbuss | 445 | } |
2012 | holgerb | 446 | } |
447 | if(!SendSPI) { SPI_TransmitByte(); } |
||
1 | ingob | 448 | } |
449 | return (1); |
||
450 | } |
||
1944 | holgerb | 451 | //DebugOut.Analog[16] |
1 | ingob | 452 |