Rev 1378 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1378 | Rev 1550 | ||
---|---|---|---|
Line 49... | Line 49... | ||
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
52 | #include "main.h" |
Line -... | Line 53... | ||
- | 53 | ||
53 | 54 | ||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char PlatinenVersion = 10; |
56 | unsigned char PlatinenVersion = 10; |
56 | unsigned char SendVersionToNavi = 1; |
57 | unsigned char SendVersionToNavi = 1; |
57 | unsigned char BattLowVoltageWarning = 94; |
58 | unsigned char BattLowVoltageWarning = 94; |
- | 59 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
|
- | 60 | unsigned int FlugSekunden = 0; |
|
- | 61 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
|
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
62 | |
59 | // -- Parametersatz aus EEPROM lesen --- |
63 | // -- Parametersatz aus EEPROM lesen --- |
60 | // number [1..5] |
64 | // number [1..5] |
61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
65 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
62 | { |
66 | { |
Line 71... | Line 75... | ||
71 | { |
75 | { |
72 | if(number > 5) number = 5; |
76 | if(number > 5) number = 5; |
73 | if(number < 1) return; |
77 | if(number < 1) return; |
74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
78 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
79 | 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 |
80 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken |
77 | SetActiveParamSetNumber(number); |
81 | SetActiveParamSetNumber(number); |
78 | LED_Init(); |
82 | LED_Init(); |
79 | } |
83 | } |
Line 80... | Line 84... | ||
80 | 84 | ||
Line 88... | Line 92... | ||
88 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
92 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
89 | } |
93 | } |
90 | return(set); |
94 | return(set); |
91 | } |
95 | } |
Line 92... | Line -... | ||
92 | - | ||
93 | 96 | ||
94 | void SetActiveParamSetNumber(unsigned char number) |
97 | void SetActiveParamSetNumber(unsigned char number) |
95 | { |
98 | { |
96 | if(number > 5) number = 5; |
99 | if(number > 5) number = 5; |
97 | if(number < 1) return; |
100 | if(number < 1) return; |
Line 116... | Line 119... | ||
116 | else Piep(WinkelOut.CalcState,150); |
119 | else Piep(WinkelOut.CalcState,150); |
117 | } |
120 | } |
118 | DebugOut.Analog[19] = WinkelOut.CalcState; |
121 | DebugOut.Analog[19] = WinkelOut.CalcState; |
119 | } |
122 | } |
Line -... | Line 123... | ||
- | 123 | ||
- | 124 | ||
120 | 125 | ||
121 | void LipoDetection(unsigned char print) |
126 | void LipoDetection(unsigned char print) |
122 | { |
127 | { |
123 | unsigned int timer; |
128 | unsigned int timer; |
124 | if(print) printf("\n\rBatt:"); |
129 | if(print) printf("\n\rBatt:"); |
Line 127... | Line 132... | ||
127 | timer = SetDelay(500); |
132 | timer = SetDelay(500); |
128 | if(print) while (!CheckDelay(timer)); |
133 | if(print) while (!CheckDelay(timer)); |
129 | if(UBat < 130) |
134 | if(UBat < 130) |
130 | { |
135 | { |
131 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
136 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
132 | if(print) |
137 | if(print) |
133 | { |
138 | { |
134 | Piep(3,200); |
139 | Piep(3,200); |
135 | printf(" 3 Cells "); |
140 | printf(" 3 Cells "); |
136 | } |
141 | } |
137 | } |
142 | } |
138 | else |
143 | else |
139 | { |
144 | { |
140 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
145 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
141 | if(print) |
146 | if(print) |
142 | { |
147 | { |
143 | Piep(4,200); |
148 | Piep(4,200); |
144 | printf(" 4 Cells "); |
149 | printf(" 4 Cells "); |
145 | } |
150 | } |
146 | } |
151 | } |
147 | } |
152 | } |
148 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
153 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
149 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
154 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
150 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
155 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
Line 153... | Line 158... | ||
153 | //############################################################################ |
158 | //############################################################################ |
154 | //Hauptprogramm |
159 | //Hauptprogramm |
155 | int main (void) |
160 | int main (void) |
156 | //############################################################################ |
161 | //############################################################################ |
157 | { |
162 | { |
158 | unsigned int timer,i,timer2 = 0; |
163 | unsigned int timer,i,timer2 = 0, timerPolling; |
- | 164 | unsigned char RequiredMotors = 0; |
|
- | 165 | ||
159 | DDRB = 0x00; |
166 | DDRB = 0x00; |
160 | PORTB = 0x00; |
167 | PORTB = 0x00; |
161 | for(timer = 0; timer < 1000; timer++); // verzögern |
168 | for(timer = 0; timer < 1000; timer++); // verzögern |
162 | if(PINB & 0x01) |
169 | if(PINB & 0x01) |
163 | { |
170 | { |
Line 192... | Line 199... | ||
192 | UART_Init(); |
199 | UART_Init(); |
193 | rc_sum_init(); |
200 | rc_sum_init(); |
194 | ADC_Init(); |
201 | ADC_Init(); |
195 | i2c_init(); |
202 | i2c_init(); |
196 | SPI_MasterInit(); |
203 | SPI_MasterInit(); |
- | 204 | Capacity_Init(); |
|
- | 205 | LIBFC_Init(); |
|
- | 206 | GRN_ON; |
|
- | 207 | sei(); |
|
Line 197... | Line -... | ||
197 | - | ||
198 | sei(); |
- | |
199 | - | ||
200 | printf("\n\r==================================="); |
- | |
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'); |
208 | |
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"); |
- | |
Line 204... | Line -... | ||
204 | printf("\n\r==================================="); |
- | |
205 | - | ||
206 | if(UCSR1A == 0x20 && UCSR1C == 0x06) // initial Values for 644P |
- | |
207 | { |
- | |
208 | Uart1Init(); |
- | |
209 | } |
- | |
Line 210... | Line 209... | ||
210 | GRN_ON; |
209 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
211 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
210 | |
212 | 211 | ||
213 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
212 | 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 |
- | |
215 | { |
213 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
216 | unsigned char i; |
214 | { |
217 | RequiredMotors = 0; |
215 | unsigned char i; |
218 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
216 | 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++;} |
217 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
Line 231... | Line 229... | ||
231 | Mixer.Revision = MIXER_REVISION; |
229 | Mixer.Revision = MIXER_REVISION; |
232 | memcpy(Mixer.Name, "Quadro\0", 11); |
230 | memcpy(Mixer.Name, "Quadro\0", 11); |
233 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
231 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
234 | } |
232 | } |
235 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
233 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
- | 234 | ||
236 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
235 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
237 | // + Check connected BL-Ctrls |
236 | // + Check connected BL-Ctrls |
238 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
237 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
239 | printf("\n\rFound BL-Ctrl: "); |
238 | printf("\n\rFound BL-Ctrl: "); |
240 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
239 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
241 | timer = SetDelay(2000); |
240 | timer = SetDelay(2000); |
- | 241 | ||
242 | for(i=0; i < MAX_MOTORS; i++) |
242 | for(i=0; i < MAX_MOTORS; i++) |
243 | { |
243 | { |
244 | UpdateMotor = 0; |
244 | UpdateMotor = 0; |
245 | SendMotorData(); |
245 | SendMotorData(); |
246 | while(!UpdateMotor); |
246 | while(!UpdateMotor); |
247 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
247 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
248 | { |
248 | { |
249 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
249 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
250 | } |
250 | } |
251 | if(MotorPresent[i]) printf("%d ",i+1); |
251 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1); |
252 | } |
252 | } |
253 | for(i=0; i < MAX_MOTORS; i++) |
253 | for(i=0; i < MAX_MOTORS; i++) |
254 | { |
254 | { |
255 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
255 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
256 | { |
256 | { |
257 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
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 |
258 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
259 | } |
259 | } |
260 | MotorError[i] = 0; |
260 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
261 | } |
261 | } |
262 | printf("\n\r==================================="); |
262 | printf("\n\r==================================="); |
263 | SendMotorData(); |
263 | SendMotorData(); |
- | 264 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
|
Line 264... | Line 265... | ||
264 | 265 | ||
265 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | // + Check Settings |
267 | // + Check Settings |
267 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
268 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 291... | Line 292... | ||
291 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
292 | 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[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[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[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
295 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
296 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
- | 297 | ||
- | 298 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
|
- | 299 | { |
|
- | 300 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
|
- | 301 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
|
- | 302 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
|
- | 303 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
|
- | 304 | } |
|
- | 305 | else |
|
- | 306 | { |
|
- | 307 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
|
- | 308 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
|
- | 309 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
|
- | 310 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
|
- | 311 | } |
|
296 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
312 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
297 | } else DefaultStickMapping(); |
313 | } else DefaultStickMapping(); |
298 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
314 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
299 | } |
315 | } |
300 | SetActiveParamSetNumber(3); // default-Setting |
316 | SetActiveParamSetNumber(3); // default-Setting |
Line 317... | Line 333... | ||
317 | 333 | ||
318 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
334 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
Line 319... | Line 335... | ||
319 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
335 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
320 | 336 | ||
321 | 337 | ||
322 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
338 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
323 | { |
339 | { |
324 | printf("\n\rCalibrating pressure sensor.."); |
340 | printf("\n\rCalibrating pressure sensor.."); |
Line 342... | Line 358... | ||
342 | 358 | ||
343 | LcdClear(); |
359 | LcdClear(); |
344 | I2CTimeout = 5000; |
360 | I2CTimeout = 5000; |
345 | WinkelOut.Orientation = 1; |
361 | WinkelOut.Orientation = 1; |
- | 362 | LipoDetection(1); |
|
- | 363 | ||
- | 364 | LIBFC_ReceiverInit(); |
|
346 | LipoDetection(1); |
365 | |
347 | printf("\n\r===================================\n\r"); |
366 | printf("\n\r===================================\n\r"); |
348 | //SpektrumBinding(); |
367 | //SpektrumBinding(); |
- | 368 | timer = SetDelay(2000); |
|
- | 369 | timerPolling = SetDelay(250); |
|
349 | timer = SetDelay(2000); |
370 | |
350 | while (1) |
371 | while (1) |
- | 372 | { |
|
- | 373 | ||
- | 374 | if(CheckDelay(timerPolling)) |
|
- | 375 | { |
|
- | 376 | timerPolling = SetDelay(100); |
|
- | 377 | LIBFC_Polling(); |
|
- | 378 | } |
|
351 | { |
379 | |
352 | if(UpdateMotor && AdReady) // ReglerIntervall |
380 | if(UpdateMotor && AdReady) // ReglerIntervall |
353 | { |
381 | { |
354 | UpdateMotor=0; |
382 | UpdateMotor=0; |
355 | if(WinkelOut.CalcState) CalMk3Mag(); |
383 | if(WinkelOut.CalcState) CalMk3Mag(); |
356 | else MotorRegler(); |
384 | else MotorRegler(); |
357 | SendMotorData(); |
385 | SendMotorData(); |
358 | ROT_OFF; |
386 | ROT_OFF; |
359 | if(SenderOkay) SenderOkay--; |
387 | if(SenderOkay) SenderOkay--; |
360 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
388 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
361 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
389 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
362 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
390 | //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; |
391 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
364 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
365 | if(NaviDataOkay) |
392 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
366 | { |
- | |
367 | if(--NaviDataOkay == 0) |
- | |
368 | { |
- | |
369 | GPS_Nick = 0; |
- | |
370 | GPS_Roll = 0; |
- | |
371 | } |
- | |
372 | } |
393 | |
373 | if(!--I2CTimeout || MissingMotor) |
394 | if(!--I2CTimeout || MissingMotor) |
374 | { |
395 | { |
375 | if(!I2CTimeout) |
396 | if(!I2CTimeout) |
376 | { |
397 | { |
377 | i2c_reset(); |
398 | i2c_reset(); |
378 | I2CTimeout = 5; |
399 | I2CTimeout = 5; |
- | 400 | DebugOut.Analog[28]++; // I2C-Error |
|
379 | DebugOut.Analog[28]++; // I2C-Error |
401 | FCFlags |= FCFLAG_I2CERR; |
380 | } |
402 | } |
381 | if((BeepMuster == 0xffff) && MotorenEin) |
403 | if((BeepMuster == 0xffff) && MotorenEin) |
382 | { |
404 | { |
383 | beeptime = 10000; |
405 | beeptime = 10000; |
384 | BeepMuster = 0x0080; |
406 | BeepMuster = 0x0080; |
385 | } |
407 | } |
386 | } |
408 | } |
387 | else |
409 | else |
388 | { |
410 | { |
- | 411 | ROT_OFF; |
|
389 | ROT_OFF; |
412 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
390 | } |
413 | } |
391 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
414 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
392 | { |
415 | { |
393 | DatenUebertragung(); |
416 | DatenUebertragung(); |
394 | BearbeiteRxDaten(); |
417 | BearbeiteRxDaten(); |
395 | } |
418 | } |
396 | else BearbeiteRxDaten(); |
419 | else BearbeiteRxDaten(); |
397 | if(CheckDelay(timer)) |
420 | if(CheckDelay(timer)) |
- | 421 | { |
|
398 | { |
422 | static unsigned char second; |
399 | timer += 20; |
423 | timer += 20; // 20 ms interval |
400 | if(PcZugriff) PcZugriff--; |
424 | if(PcZugriff) PcZugriff--; |
401 | else |
425 | else |
402 | { |
426 | { |
403 | ExternControl.Config = 0; |
427 | ExternControl.Config = 0; |
404 | ExternStickNick = 0; |
428 | ExternStickNick = 0; |
405 | ExternStickRoll = 0; |
429 | ExternStickRoll = 0; |
406 | ExternStickGier = 0; |
430 | ExternStickGier = 0; |
407 | if(BeepMuster == 0xffff && SenderOkay == 0) |
431 | if(BeepMuster == 0xffff && SenderOkay == 0) |
408 | { |
432 | { |
409 | beeptime = 15000; |
433 | beeptime = 15000; |
- | 434 | BeepMuster = 0x0c00; |
|
- | 435 | } |
|
- | 436 | } |
|
- | 437 | if(NaviDataOkay) |
|
- | 438 | { |
|
- | 439 | NaviDataOkay--; |
|
- | 440 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
|
- | 441 | } |
|
- | 442 | else |
|
410 | BeepMuster = 0x0c00; |
443 | { |
411 | } |
444 | GPS_Nick = 0; |
- | 445 | GPS_Roll = 0; |
|
- | 446 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
|
412 | } |
447 | } |
413 | if(UBat < BattLowVoltageWarning) |
448 | if(UBat < BattLowVoltageWarning) |
414 | { |
449 | { |
415 | MikroKopterFlags |= FLAG_LOWBAT; |
450 | FCFlags |= FCFLAG_LOWBAT; |
416 | if(BeepMuster == 0xffff) |
451 | if(BeepMuster == 0xffff) |
417 | { |
452 | { |
418 | beeptime = 6000; |
453 | beeptime = 6000; |
419 | BeepMuster = 0x0300; |
454 | BeepMuster = 0x0300; |
420 | } |
455 | } |
421 | } |
456 | } |
- | 457 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
|
422 | else MikroKopterFlags &= ~FLAG_LOWBAT; |
458 | |
423 | SPI_StartTransmitPacket(); |
459 | SPI_StartTransmitPacket(); |
424 | SendSPI = 4; |
460 | SendSPI = 4; |
- | 461 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
|
- | 462 | else |
|
- | 463 | if(++second == 49) |
|
- | 464 | { |
|
- | 465 | second = 0; |
|
- | 466 | FlugSekunden++; |
|
- | 467 | } |
|
425 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
468 | |
426 | if(++timer2 == 2930) // eine Minute |
469 | if(++timer2 == 2930) // eine Minute |
427 | { |
470 | { |
428 | timer2 = 0; |
471 | timer2 = 0; |
429 | FlugMinuten++; |
472 | FlugMinuten++; |
430 | FlugMinutenGesamt++; |
473 | FlugMinutenGesamt++; |
431 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
474 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
432 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
475 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
433 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
476 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
434 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
477 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
435 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
478 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
436 | } |
479 | } |
437 | } |
480 | } |
- | 481 | LED_Update(); |
|
438 | LED_Update(); |
482 | Capacity_Update(); |
439 | } |
483 | } |
440 | if(!SendSPI) { SPI_TransmitByte(); } |
484 | if(!SendSPI) { SPI_TransmitByte(); } |
441 | } |
485 | } |
442 | return (1); |
486 | return (1); |