Rev 1378 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1338 | ingob | 2 | // + Copyright (c) Holger Buss, Ingo Busker |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
||
1 | ingob | 4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
||
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
1 | ingob | 10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
||
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
1 | ingob | 14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
21 | // + Benutzung auf eigene Gefahr |
||
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1338 | ingob | 24 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
1 | ingob | 25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
1 | ingob | 30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
32 | // + from this software without specific prior written permission. |
||
1051 | killagreg | 33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
1 | ingob | 34 | // + for non-commercial use (directly or indirectly) |
1051 | killagreg | 35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 36 | // + with our written permission |
1051 | killagreg | 37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
||
1338 | ingob | 39 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
1 | ingob | 40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
1051 | killagreg | 50 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
||
53 | |||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
||
173 | holgerb | 55 | unsigned char PlatinenVersion = 10; |
723 | hbuss | 56 | unsigned char SendVersionToNavi = 1; |
1232 | hbuss | 57 | unsigned char BattLowVoltageWarning = 94; |
1298 | hbuss | 58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
1 | ingob | 59 | // -- Parametersatz aus EEPROM lesen --- |
1051 | killagreg | 60 | // number [1..5] |
1 | ingob | 61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
62 | { |
||
993 | hbuss | 63 | if((number > 5)||(number < 1)) number = 3; |
1063 | killagreg | 64 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
921 | hbuss | 65 | LED_Init(); |
1 | ingob | 66 | } |
67 | |||
68 | // -- Parametersatz ins EEPROM schreiben --- |
||
1051 | killagreg | 69 | // number [1..5] |
1 | ingob | 70 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
71 | { |
||
1051 | killagreg | 72 | if(number > 5) number = 5; |
993 | hbuss | 73 | if(number < 1) return; |
1063 | killagreg | 74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
1171 | hbuss | 75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
76 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 8); // 8 Kanäle merken |
||
1063 | killagreg | 77 | SetActiveParamSetNumber(number); |
921 | hbuss | 78 | LED_Init(); |
1 | ingob | 79 | } |
80 | |||
81 | unsigned char GetActiveParamSetNumber(void) |
||
82 | { |
||
1063 | killagreg | 83 | unsigned char set; |
84 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
85 | if((set > 5) || (set < 1)) |
||
86 | { |
||
87 | set = 3; |
||
88 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
||
89 | } |
||
90 | return(set); |
||
1 | ingob | 91 | } |
92 | |||
1063 | killagreg | 93 | |
94 | void SetActiveParamSetNumber(unsigned char number) |
||
95 | { |
||
96 | if(number > 5) number = 5; |
||
97 | if(number < 1) return; |
||
98 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
99 | } |
||
100 | |||
101 | |||
819 | hbuss | 102 | void CalMk3Mag(void) |
103 | { |
||
104 | static unsigned char stick = 1; |
||
105 | |||
106 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
107 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
108 | { |
||
109 | stick = 1; |
||
110 | WinkelOut.CalcState++; |
||
1051 | killagreg | 111 | if(WinkelOut.CalcState > 4) |
112 | { |
||
819 | hbuss | 113 | // WinkelOut.CalcState = 0; // in Uart.c |
114 | beeptime = 1000; |
||
1051 | killagreg | 115 | } |
1232 | hbuss | 116 | else Piep(WinkelOut.CalcState,150); |
819 | hbuss | 117 | } |
118 | DebugOut.Analog[19] = WinkelOut.CalcState; |
||
119 | } |
||
120 | |||
1268 | hbuss | 121 | void LipoDetection(unsigned char print) |
122 | { |
||
123 | unsigned int timer; |
||
124 | if(print) printf("\n\rBatt:"); |
||
125 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
||
126 | { |
||
127 | timer = SetDelay(500); |
||
128 | if(print) while (!CheckDelay(timer)); |
||
129 | if(UBat < 130) |
||
130 | { |
||
131 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
||
132 | if(print) |
||
133 | { |
||
134 | Piep(3,200); |
||
135 | printf(" 3 Cells "); |
||
136 | } |
||
137 | } |
||
138 | else |
||
139 | { |
||
140 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
||
141 | if(print) |
||
142 | { |
||
143 | Piep(4,200); |
||
144 | printf(" 4 Cells "); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
||
1374 | hbuss | 149 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
1268 | hbuss | 150 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
151 | } |
||
152 | |||
1 | ingob | 153 | //############################################################################ |
154 | //Hauptprogramm |
||
155 | int main (void) |
||
156 | //############################################################################ |
||
157 | { |
||
1298 | hbuss | 158 | unsigned int timer,i,timer2 = 0; |
1051 | killagreg | 159 | DDRB = 0x00; |
160 | PORTB = 0x00; |
||
188 | holgerb | 161 | for(timer = 0; timer < 1000; timer++); // verzögern |
1051 | killagreg | 162 | if(PINB & 0x01) |
918 | hbuss | 163 | { |
1051 | killagreg | 164 | if(PINB & 0x02) PlatinenVersion = 13; |
165 | else PlatinenVersion = 11; |
||
918 | hbuss | 166 | } |
1051 | killagreg | 167 | else |
1021 | hbuss | 168 | { |
1051 | killagreg | 169 | if(PINB & 0x02) PlatinenVersion = 20; |
170 | else PlatinenVersion = 10; |
||
1021 | hbuss | 171 | } |
172 | |||
173 | holgerb | 173 | DDRC = 0x81; // SCL |
1036 | hbuss | 174 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 175 | PORTC = 0xff; // Pullup SDA |
176 | DDRB = 0x1B; // LEDs und Druckoffset |
||
177 | PORTB = 0x01; // LED_Rot |
||
178 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
1153 | hbuss | 179 | PORTD = 0x47; // LED |
1171 | hbuss | 180 | HEF4017R_ON; |
1 | ingob | 181 | MCUSR &=~(1<<WDRF); |
182 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
183 | WDTCSR = 0; |
||
184 | |||
185 | beeptime = 2000; |
||
186 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
||
1111 | hbuss | 187 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
1 | ingob | 188 | ROT_OFF; |
1051 | killagreg | 189 | |
1 | ingob | 190 | Timer_Init(); |
1156 | hbuss | 191 | TIMER2_Init(); |
1 | ingob | 192 | UART_Init(); |
193 | rc_sum_init(); |
||
194 | ADC_Init(); |
||
195 | i2c_init(); |
||
597 | ingob | 196 | SPI_MasterInit(); |
1051 | killagreg | 197 | |
1 | ingob | 198 | sei(); |
199 | |||
1211 | hbuss | 200 | printf("\n\r==================================="); |
1051 | killagreg | 201 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
1344 | hbuss | 202 | printf("\n\rthe use of this software is only permitted \n\ron original MikroKopter-Hardware"); |
203 | printf("\n\rwww.MikroKopter.de (c) HiSystems GmbH"); |
||
204 | printf("\n\r==================================="); |
||
205 | |||
1172 | hbuss | 206 | if(UCSR1A == 0x20 && UCSR1C == 0x06) // initial Values for 644P |
1254 | killagreg | 207 | { |
1172 | hbuss | 208 | Uart1Init(); |
209 | } |
||
1 | ingob | 210 | GRN_ON; |
1063 | killagreg | 211 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
1051 | killagreg | 212 | |
1212 | hbuss | 213 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
214 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
||
1209 | hbuss | 215 | { |
1254 | killagreg | 216 | unsigned char i; |
1209 | hbuss | 217 | RequiredMotors = 0; |
218 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
||
219 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
||
1254 | killagreg | 220 | } |
1209 | hbuss | 221 | else // default |
222 | { |
||
1254 | killagreg | 223 | unsigned char i; |
1211 | hbuss | 224 | printf("\n\rGenerating default Mixer Table"); |
1209 | hbuss | 225 | for(i=0; i<16;i++) { Mixer.Motor[i][0] = 0;Mixer.Motor[i][1] = 0;Mixer.Motor[i][2] = 0;Mixer.Motor[i][3] = 0;}; |
226 | // default = Quadro |
||
227 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
||
228 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
||
229 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
||
230 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
||
1211 | hbuss | 231 | Mixer.Revision = MIXER_REVISION; |
1254 | killagreg | 232 | memcpy(Mixer.Name, "Quadro\0", 11); |
1209 | hbuss | 233 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
234 | } |
||
235 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
||
1211 | hbuss | 236 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
237 | // + Check connected BL-Ctrls |
||
238 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
239 | printf("\n\rFound BL-Ctrl: "); |
||
240 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
||
1232 | hbuss | 241 | timer = SetDelay(2000); |
1211 | hbuss | 242 | for(i=0; i < MAX_MOTORS; i++) |
243 | { |
||
244 | UpdateMotor = 0; |
||
245 | SendMotorData(); |
||
246 | while(!UpdateMotor); |
||
1232 | hbuss | 247 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
248 | { |
||
249 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
||
250 | } |
||
1211 | hbuss | 251 | if(MotorPresent[i]) printf("%d ",i+1); |
252 | } |
||
253 | for(i=0; i < MAX_MOTORS; i++) |
||
254 | { |
||
1320 | hbuss | 255 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
256 | { |
||
257 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
||
258 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
||
259 | } |
||
1211 | hbuss | 260 | MotorError[i] = 0; |
261 | } |
||
1320 | hbuss | 262 | printf("\n\r==================================="); |
1356 | hbuss | 263 | SendMotorData(); |
1320 | hbuss | 264 | |
1211 | hbuss | 265 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | // + Check Settings |
||
267 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 268 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
269 | { |
||
1 | ingob | 270 | DefaultKonstanten1(); |
1171 | hbuss | 271 | printf("\n\rInit. EEPROM"); |
1051 | killagreg | 272 | for (unsigned char i=1;i<6;i++) |
1 | ingob | 273 | { |
395 | hbuss | 274 | if(i==2) DefaultKonstanten2(); // Kamera |
275 | if(i==3) DefaultKonstanten3(); // Beginner |
||
276 | if(i>3) DefaultKonstanten2(); // Kamera |
||
1254 | killagreg | 277 | if(PlatinenVersion >= 20) |
278 | { |
||
1167 | hbuss | 279 | EE_Parameter.Gyro_D = 5; |
1111 | hbuss | 280 | EE_Parameter.Driftkomp = 0; |
281 | EE_Parameter.GyroAccFaktor = 27; |
||
282 | EE_Parameter.WinkelUmschlagNick = 78; |
||
283 | EE_Parameter.WinkelUmschlagRoll = 78; |
||
284 | } |
||
1171 | hbuss | 285 | // valid Stick-Settings? |
286 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
||
287 | { |
||
288 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
||
289 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
||
290 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
||
291 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
||
292 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
||
293 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
||
294 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
||
295 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
||
296 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
||
297 | } else DefaultStickMapping(); |
||
1 | ingob | 298 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1051 | killagreg | 299 | } |
1063 | killagreg | 300 | SetActiveParamSetNumber(3); // default-Setting |
173 | holgerb | 301 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
1 | ingob | 302 | } |
513 | hbuss | 303 | |
1298 | hbuss | 304 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
305 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
||
1350 | hbuss | 306 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
1298 | hbuss | 307 | { |
308 | FlugMinuten = 0; |
||
309 | FlugMinutenGesamt = 0; |
||
310 | } |
||
311 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
||
312 | |||
1051 | killagreg | 313 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 314 | { |
1211 | hbuss | 315 | printf("\n\rACC not calibrated !"); |
513 | hbuss | 316 | } |
1051 | killagreg | 317 | |
1 | ingob | 318 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1211 | hbuss | 319 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
1 | ingob | 320 | |
1051 | killagreg | 321 | |
1 | ingob | 322 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1051 | killagreg | 323 | { |
1211 | hbuss | 324 | printf("\n\rCalibrating pressure sensor.."); |
1051 | killagreg | 325 | timer = SetDelay(1000); |
1 | ingob | 326 | SucheLuftruckOffset(); |
327 | while (!CheckDelay(timer)); |
||
328 | printf("OK\n\r"); |
||
329 | } |
||
1051 | killagreg | 330 | |
1 | ingob | 331 | SetNeutral(); |
332 | |||
333 | ROT_OFF; |
||
1051 | killagreg | 334 | |
1 | ingob | 335 | beeptime = 2000; |
1051 | killagreg | 336 | ExternControl.Digital[0] = 0x55; |
1 | ingob | 337 | |
1051 | killagreg | 338 | |
1211 | hbuss | 339 | printf("\n\rControl: "); |
1 | ingob | 340 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
1211 | hbuss | 341 | else printf("Normal (ACC-Mode)"); |
1051 | killagreg | 342 | |
1 | ingob | 343 | LcdClear(); |
173 | holgerb | 344 | I2CTimeout = 5000; |
819 | hbuss | 345 | WinkelOut.Orientation = 1; |
1268 | hbuss | 346 | LipoDetection(1); |
1232 | hbuss | 347 | printf("\n\r===================================\n\r"); |
1320 | hbuss | 348 | //SpektrumBinding(); |
1350 | hbuss | 349 | timer = SetDelay(2000); |
1 | ingob | 350 | while (1) |
351 | { |
||
1155 | hbuss | 352 | if(UpdateMotor && AdReady) // ReglerIntervall |
1051 | killagreg | 353 | { |
1171 | hbuss | 354 | UpdateMotor=0; |
819 | hbuss | 355 | if(WinkelOut.CalcState) CalMk3Mag(); |
1051 | killagreg | 356 | else MotorRegler(); |
1 | ingob | 357 | SendMotorData(); |
358 | ROT_OFF; |
||
359 | if(SenderOkay) SenderOkay--; |
||
1309 | hbuss | 360 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
361 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1316 | hbuss | 362 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
363 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
||
1309 | hbuss | 364 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1254 | killagreg | 365 | if(NaviDataOkay) |
1215 | hbuss | 366 | { |
367 | if(--NaviDataOkay == 0) |
||
368 | { |
||
369 | GPS_Nick = 0; |
||
370 | GPS_Roll = 0; |
||
371 | } |
||
372 | } |
||
1210 | hbuss | 373 | if(!--I2CTimeout || MissingMotor) |
173 | holgerb | 374 | { |
1254 | killagreg | 375 | if(!I2CTimeout) |
1210 | hbuss | 376 | { |
377 | i2c_reset(); |
||
378 | I2CTimeout = 5; |
||
1322 | hbuss | 379 | DebugOut.Analog[28]++; // I2C-Error |
380 | } |
||
1051 | killagreg | 381 | if((BeepMuster == 0xffff) && MotorenEin) |
382 | { |
||
173 | holgerb | 383 | beeptime = 10000; |
384 | BeepMuster = 0x0080; |
||
1051 | killagreg | 385 | } |
1 | ingob | 386 | } |
1051 | killagreg | 387 | else |
1 | ingob | 388 | { |
1051 | killagreg | 389 | ROT_OFF; |
1 | ingob | 390 | } |
805 | hbuss | 391 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
1 | ingob | 392 | { |
393 | DatenUebertragung(); |
||
394 | BearbeiteRxDaten(); |
||
395 | } |
||
1254 | killagreg | 396 | else BearbeiteRxDaten(); |
397 | if(CheckDelay(timer)) |
||
398 | { |
||
1344 | hbuss | 399 | timer += 20; |
1309 | hbuss | 400 | if(PcZugriff) PcZugriff--; |
401 | else |
||
402 | { |
||
403 | ExternControl.Config = 0; |
||
404 | ExternStickNick = 0; |
||
405 | ExternStickRoll = 0; |
||
406 | ExternStickGier = 0; |
||
407 | if(BeepMuster == 0xffff && SenderOkay == 0) |
||
408 | { |
||
409 | beeptime = 15000; |
||
410 | BeepMuster = 0x0c00; |
||
411 | } |
||
412 | } |
||
413 | if(UBat < BattLowVoltageWarning) |
||
1254 | killagreg | 414 | { |
415 | MikroKopterFlags |= FLAG_LOWBAT; |
||
416 | if(BeepMuster == 0xffff) |
||
417 | { |
||
418 | beeptime = 6000; |
||
419 | BeepMuster = 0x0300; |
||
420 | } |
||
421 | } |
||
422 | else MikroKopterFlags &= ~FLAG_LOWBAT; |
||
423 | SPI_StartTransmitPacket(); |
||
424 | SendSPI = 4; |
||
1320 | hbuss | 425 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
426 | if(++timer2 == 2930) // eine Minute |
||
1298 | hbuss | 427 | { |
428 | timer2 = 0; |
||
429 | FlugMinuten++; |
||
430 | FlugMinutenGesamt++; |
||
1344 | hbuss | 431 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
432 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
||
433 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
||
434 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
||
435 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
||
1298 | hbuss | 436 | } |
1254 | killagreg | 437 | } |
921 | hbuss | 438 | LED_Update(); |
604 | hbuss | 439 | } |
723 | hbuss | 440 | if(!SendSPI) { SPI_TransmitByte(); } |
1 | ingob | 441 | } |
442 | return (1); |
||
443 | } |
||
444 | |||
1219 | hbuss | 445 |