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