Subversion Repositories FlightCtrl

Rev

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