Subversion Repositories FlightCtrl

Rev

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