Go to most recent revision | Details | 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 | |||
1438 | ingob | 54 | |
1 | ingob | 55 | unsigned char EEPromArray[E2END+1] EEMEM; |
173 | holgerb | 56 | unsigned char PlatinenVersion = 10; |
723 | hbuss | 57 | unsigned char SendVersionToNavi = 1; |
1232 | hbuss | 58 | unsigned char BattLowVoltageWarning = 94; |
1298 | hbuss | 59 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
1444 | ingob | 60 | |
61 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
||
62 | |||
1 | ingob | 63 | // -- Parametersatz aus EEPROM lesen --- |
1051 | killagreg | 64 | // number [1..5] |
1 | ingob | 65 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
66 | { |
||
993 | hbuss | 67 | if((number > 5)||(number < 1)) number = 3; |
1063 | killagreg | 68 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
921 | hbuss | 69 | LED_Init(); |
1 | ingob | 70 | } |
71 | |||
72 | // -- Parametersatz ins EEPROM schreiben --- |
||
1051 | killagreg | 73 | // number [1..5] |
1 | ingob | 74 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
75 | { |
||
1051 | killagreg | 76 | if(number > 5) number = 5; |
993 | hbuss | 77 | if(number < 1) return; |
1063 | killagreg | 78 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
1171 | hbuss | 79 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
1377 | hbuss | 80 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken |
1063 | killagreg | 81 | SetActiveParamSetNumber(number); |
921 | hbuss | 82 | LED_Init(); |
1 | ingob | 83 | } |
84 | |||
85 | unsigned char GetActiveParamSetNumber(void) |
||
86 | { |
||
1063 | killagreg | 87 | unsigned char set; |
88 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
89 | if((set > 5) || (set < 1)) |
||
90 | { |
||
91 | set = 3; |
||
92 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
||
93 | } |
||
94 | return(set); |
||
1 | ingob | 95 | } |
96 | |||
1063 | killagreg | 97 | void SetActiveParamSetNumber(unsigned char number) |
98 | { |
||
99 | if(number > 5) number = 5; |
||
100 | if(number < 1) return; |
||
101 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
102 | } |
||
103 | |||
104 | |||
819 | hbuss | 105 | void CalMk3Mag(void) |
106 | { |
||
107 | static unsigned char stick = 1; |
||
108 | |||
109 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
110 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
111 | { |
||
112 | stick = 1; |
||
113 | WinkelOut.CalcState++; |
||
1051 | killagreg | 114 | if(WinkelOut.CalcState > 4) |
115 | { |
||
819 | hbuss | 116 | // WinkelOut.CalcState = 0; // in Uart.c |
117 | beeptime = 1000; |
||
1051 | killagreg | 118 | } |
1232 | hbuss | 119 | else Piep(WinkelOut.CalcState,150); |
819 | hbuss | 120 | } |
121 | DebugOut.Analog[19] = WinkelOut.CalcState; |
||
122 | } |
||
123 | |||
1438 | ingob | 124 | |
125 | |||
1268 | hbuss | 126 | void LipoDetection(unsigned char print) |
127 | { |
||
128 | unsigned int timer; |
||
129 | if(print) printf("\n\rBatt:"); |
||
130 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
||
131 | { |
||
132 | timer = SetDelay(500); |
||
133 | if(print) while (!CheckDelay(timer)); |
||
134 | if(UBat < 130) |
||
135 | { |
||
136 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
||
1420 | killagreg | 137 | if(print) |
1268 | hbuss | 138 | { |
139 | Piep(3,200); |
||
140 | printf(" 3 Cells "); |
||
1420 | killagreg | 141 | } |
1268 | hbuss | 142 | } |
143 | else |
||
144 | { |
||
145 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
||
1420 | killagreg | 146 | if(print) |
1268 | hbuss | 147 | { |
148 | Piep(4,200); |
||
149 | printf(" 4 Cells "); |
||
1420 | killagreg | 150 | } |
1268 | hbuss | 151 | } |
152 | } |
||
153 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
||
1374 | hbuss | 154 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
1268 | hbuss | 155 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
156 | } |
||
157 | |||
1 | ingob | 158 | //############################################################################ |
159 | //Hauptprogramm |
||
160 | int main (void) |
||
161 | //############################################################################ |
||
162 | { |
||
1424 | ingob | 163 | unsigned int timer,i,timer2 = 0, timerPolling; |
1479 | killagreg | 164 | unsigned char RequiredMotors = 0; |
165 | |||
1051 | killagreg | 166 | DDRB = 0x00; |
167 | PORTB = 0x00; |
||
188 | holgerb | 168 | for(timer = 0; timer < 1000; timer++); // verzögern |
1051 | killagreg | 169 | if(PINB & 0x01) |
918 | hbuss | 170 | { |
1051 | killagreg | 171 | if(PINB & 0x02) PlatinenVersion = 13; |
172 | else PlatinenVersion = 11; |
||
918 | hbuss | 173 | } |
1051 | killagreg | 174 | else |
1021 | hbuss | 175 | { |
1051 | killagreg | 176 | if(PINB & 0x02) PlatinenVersion = 20; |
177 | else PlatinenVersion = 10; |
||
1021 | hbuss | 178 | } |
179 | |||
173 | holgerb | 180 | DDRC = 0x81; // SCL |
1036 | hbuss | 181 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 182 | PORTC = 0xff; // Pullup SDA |
183 | DDRB = 0x1B; // LEDs und Druckoffset |
||
184 | PORTB = 0x01; // LED_Rot |
||
185 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
1153 | hbuss | 186 | PORTD = 0x47; // LED |
1171 | hbuss | 187 | HEF4017R_ON; |
1 | ingob | 188 | MCUSR &=~(1<<WDRF); |
189 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
190 | WDTCSR = 0; |
||
191 | |||
192 | beeptime = 2000; |
||
193 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
||
1111 | hbuss | 194 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
1 | ingob | 195 | ROT_OFF; |
1479 | killagreg | 196 | |
1 | ingob | 197 | Timer_Init(); |
1156 | hbuss | 198 | TIMER2_Init(); |
1 | ingob | 199 | UART_Init(); |
200 | rc_sum_init(); |
||
201 | ADC_Init(); |
||
202 | i2c_init(); |
||
597 | ingob | 203 | SPI_MasterInit(); |
1486 | killagreg | 204 | Capacity_Init(); |
1435 | killagreg | 205 | LIBFC_Init(); |
1431 | ingob | 206 | GRN_ON; |
207 | sei(); |
||
1344 | hbuss | 208 | |
1377 | hbuss | 209 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
1435 | killagreg | 210 | |
211 | |||
1212 | hbuss | 212 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
213 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
||
1209 | hbuss | 214 | { |
1254 | killagreg | 215 | unsigned char i; |
1209 | hbuss | 216 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
217 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
||
1254 | killagreg | 218 | } |
1209 | hbuss | 219 | else // default |
220 | { |
||
1254 | killagreg | 221 | unsigned char i; |
1211 | hbuss | 222 | printf("\n\rGenerating default Mixer Table"); |
1209 | hbuss | 223 | 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;}; |
224 | // default = Quadro |
||
225 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
||
226 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
||
227 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
||
228 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
||
1211 | hbuss | 229 | Mixer.Revision = MIXER_REVISION; |
1254 | killagreg | 230 | memcpy(Mixer.Name, "Quadro\0", 11); |
1209 | hbuss | 231 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
232 | } |
||
233 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
||
1431 | ingob | 234 | |
1435 | killagreg | 235 | |
236 | |||
1211 | hbuss | 237 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
238 | // + Check connected BL-Ctrls |
||
239 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
240 | printf("\n\rFound BL-Ctrl: "); |
||
241 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
||
1232 | hbuss | 242 | timer = SetDelay(2000); |
1420 | killagreg | 243 | |
244 | |||
1211 | hbuss | 245 | for(i=0; i < MAX_MOTORS; i++) |
246 | { |
||
247 | UpdateMotor = 0; |
||
248 | SendMotorData(); |
||
249 | while(!UpdateMotor); |
||
1232 | hbuss | 250 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
251 | { |
||
1479 | killagreg | 252 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
1232 | hbuss | 253 | } |
1479 | killagreg | 254 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1); |
1211 | hbuss | 255 | } |
256 | for(i=0; i < MAX_MOTORS; i++) |
||
257 | { |
||
1479 | killagreg | 258 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
1320 | hbuss | 259 | { |
260 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
||
261 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
||
1420 | killagreg | 262 | } |
1479 | killagreg | 263 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
1211 | hbuss | 264 | } |
1320 | hbuss | 265 | printf("\n\r==================================="); |
1356 | hbuss | 266 | SendMotorData(); |
1403 | hbuss | 267 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
1320 | hbuss | 268 | |
1211 | hbuss | 269 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
270 | // + Check Settings |
||
271 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 272 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
273 | { |
||
1 | ingob | 274 | DefaultKonstanten1(); |
1171 | hbuss | 275 | printf("\n\rInit. EEPROM"); |
1051 | killagreg | 276 | for (unsigned char i=1;i<6;i++) |
1 | ingob | 277 | { |
395 | hbuss | 278 | if(i==2) DefaultKonstanten2(); // Kamera |
279 | if(i==3) DefaultKonstanten3(); // Beginner |
||
280 | if(i>3) DefaultKonstanten2(); // Kamera |
||
1254 | killagreg | 281 | if(PlatinenVersion >= 20) |
282 | { |
||
1167 | hbuss | 283 | EE_Parameter.Gyro_D = 5; |
1111 | hbuss | 284 | EE_Parameter.Driftkomp = 0; |
285 | EE_Parameter.GyroAccFaktor = 27; |
||
286 | EE_Parameter.WinkelUmschlagNick = 78; |
||
287 | EE_Parameter.WinkelUmschlagRoll = 78; |
||
288 | } |
||
1171 | hbuss | 289 | // valid Stick-Settings? |
290 | 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) |
||
291 | { |
||
292 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
||
293 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
||
294 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
||
295 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
||
296 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
||
297 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
||
298 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
||
299 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
||
1420 | killagreg | 300 | |
1377 | hbuss | 301 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
302 | { |
||
303 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
||
304 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
||
305 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
||
306 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
||
1420 | killagreg | 307 | } |
308 | else |
||
1377 | hbuss | 309 | { |
310 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
||
311 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
||
312 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
||
313 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
||
314 | } |
||
1171 | hbuss | 315 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
316 | } else DefaultStickMapping(); |
||
1 | ingob | 317 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1051 | killagreg | 318 | } |
1063 | killagreg | 319 | SetActiveParamSetNumber(3); // default-Setting |
173 | holgerb | 320 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
1 | ingob | 321 | } |
1435 | killagreg | 322 | |
323 | |||
324 | |||
1298 | hbuss | 325 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
326 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
||
1350 | hbuss | 327 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
1298 | hbuss | 328 | { |
329 | FlugMinuten = 0; |
||
330 | FlugMinutenGesamt = 0; |
||
331 | } |
||
332 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
||
333 | |||
1051 | killagreg | 334 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 335 | { |
1211 | hbuss | 336 | printf("\n\rACC not calibrated !"); |
513 | hbuss | 337 | } |
1051 | killagreg | 338 | |
1 | ingob | 339 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1211 | hbuss | 340 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
1 | ingob | 341 | |
1051 | killagreg | 342 | |
1 | ingob | 343 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1051 | killagreg | 344 | { |
1211 | hbuss | 345 | printf("\n\rCalibrating pressure sensor.."); |
1051 | killagreg | 346 | timer = SetDelay(1000); |
1 | ingob | 347 | SucheLuftruckOffset(); |
348 | while (!CheckDelay(timer)); |
||
349 | printf("OK\n\r"); |
||
350 | } |
||
1051 | killagreg | 351 | |
1 | ingob | 352 | SetNeutral(); |
353 | |||
354 | ROT_OFF; |
||
1051 | killagreg | 355 | |
1 | ingob | 356 | beeptime = 2000; |
1051 | killagreg | 357 | ExternControl.Digital[0] = 0x55; |
1 | ingob | 358 | |
1051 | killagreg | 359 | |
1211 | hbuss | 360 | printf("\n\rControl: "); |
1 | ingob | 361 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
1211 | hbuss | 362 | else printf("Normal (ACC-Mode)"); |
1051 | killagreg | 363 | |
1 | ingob | 364 | LcdClear(); |
173 | holgerb | 365 | I2CTimeout = 5000; |
819 | hbuss | 366 | WinkelOut.Orientation = 1; |
1268 | hbuss | 367 | LipoDetection(1); |
1435 | killagreg | 368 | |
369 | LIBFC_ReceiverInit(); |
||
1444 | ingob | 370 | |
1232 | hbuss | 371 | printf("\n\r===================================\n\r"); |
1320 | hbuss | 372 | //SpektrumBinding(); |
1350 | hbuss | 373 | timer = SetDelay(2000); |
1424 | ingob | 374 | timerPolling = SetDelay(250); |
1 | ingob | 375 | while (1) |
376 | { |
||
1420 | killagreg | 377 | |
1424 | ingob | 378 | if(CheckDelay(timerPolling)) |
1419 | ingob | 379 | { |
1424 | ingob | 380 | timerPolling = SetDelay(100); |
1435 | killagreg | 381 | LIBFC_Polling(); |
1419 | ingob | 382 | } |
1420 | killagreg | 383 | |
1419 | ingob | 384 | if(UpdateMotor && AdReady) // ReglerIntervall |
1051 | killagreg | 385 | { |
1171 | hbuss | 386 | UpdateMotor=0; |
819 | hbuss | 387 | if(WinkelOut.CalcState) CalMk3Mag(); |
1051 | killagreg | 388 | else MotorRegler(); |
1 | ingob | 389 | SendMotorData(); |
390 | ROT_OFF; |
||
391 | if(SenderOkay) SenderOkay--; |
||
1309 | hbuss | 392 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
1420 | killagreg | 393 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1481 | holgerb | 394 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
395 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
||
1309 | hbuss | 396 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1420 | killagreg | 397 | |
1210 | hbuss | 398 | if(!--I2CTimeout || MissingMotor) |
173 | holgerb | 399 | { |
1254 | killagreg | 400 | if(!I2CTimeout) |
1210 | hbuss | 401 | { |
402 | i2c_reset(); |
||
403 | I2CTimeout = 5; |
||
1322 | hbuss | 404 | DebugOut.Analog[28]++; // I2C-Error |
1423 | hbuss | 405 | FCFlags |= FCFLAG_I2CERR; |
1322 | hbuss | 406 | } |
1051 | killagreg | 407 | if((BeepMuster == 0xffff) && MotorenEin) |
408 | { |
||
173 | holgerb | 409 | beeptime = 10000; |
410 | BeepMuster = 0x0080; |
||
1051 | killagreg | 411 | } |
1 | ingob | 412 | } |
1051 | killagreg | 413 | else |
1 | ingob | 414 | { |
1051 | killagreg | 415 | ROT_OFF; |
1423 | hbuss | 416 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
1 | ingob | 417 | } |
805 | hbuss | 418 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
1 | ingob | 419 | { |
420 | DatenUebertragung(); |
||
421 | BearbeiteRxDaten(); |
||
422 | } |
||
1254 | killagreg | 423 | else BearbeiteRxDaten(); |
424 | if(CheckDelay(timer)) |
||
425 | { |
||
1420 | killagreg | 426 | timer += 20; // 20 ms interval |
427 | if(PcZugriff) PcZugriff--; |
||
428 | else |
||
429 | { |
||
430 | ExternControl.Config = 0; |
||
431 | ExternStickNick = 0; |
||
432 | ExternStickRoll = 0; |
||
433 | ExternStickGier = 0; |
||
434 | if(BeepMuster == 0xffff && SenderOkay == 0) |
||
435 | { |
||
436 | beeptime = 15000; |
||
437 | BeepMuster = 0x0c00; |
||
438 | } |
||
439 | } |
||
440 | if(NaviDataOkay) |
||
441 | { |
||
442 | NaviDataOkay--; |
||
443 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
||
444 | } |
||
445 | else |
||
446 | { |
||
447 | GPS_Nick = 0; |
||
448 | GPS_Roll = 0; |
||
1423 | hbuss | 449 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
1420 | killagreg | 450 | } |
1309 | hbuss | 451 | if(UBat < BattLowVoltageWarning) |
1254 | killagreg | 452 | { |
1420 | killagreg | 453 | FCFlags |= FCFLAG_LOWBAT; |
1254 | killagreg | 454 | if(BeepMuster == 0xffff) |
455 | { |
||
456 | beeptime = 6000; |
||
457 | BeepMuster = 0x0300; |
||
458 | } |
||
459 | } |
||
1423 | hbuss | 460 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
1420 | killagreg | 461 | |
1254 | killagreg | 462 | SPI_StartTransmitPacket(); |
463 | SendSPI = 4; |
||
1420 | killagreg | 464 | |
1320 | hbuss | 465 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
1420 | killagreg | 466 | |
1320 | hbuss | 467 | if(++timer2 == 2930) // eine Minute |
1298 | hbuss | 468 | { |
469 | timer2 = 0; |
||
470 | FlugMinuten++; |
||
471 | FlugMinutenGesamt++; |
||
1420 | killagreg | 472 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
473 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
||
474 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
||
475 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
||
1344 | hbuss | 476 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
1298 | hbuss | 477 | } |
1254 | killagreg | 478 | } |
921 | hbuss | 479 | LED_Update(); |
1486 | killagreg | 480 | Capacity_Update(); |
604 | hbuss | 481 | } |
723 | hbuss | 482 | if(!SendSPI) { SPI_TransmitByte(); } |
1 | ingob | 483 | } |
484 | return (1); |
||
485 | } |
||
486 | |||
1219 | hbuss | 487 |