Subversion Repositories FlightCtrl

Rev

Rev 1603 | Rev 1626 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1603 Rev 1622
Line 57... Line 57...
57
unsigned char BattLowVoltageWarning = 94;
57
unsigned char BattLowVoltageWarning = 94;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
59
unsigned int FlugSekunden = 0;
59
unsigned int FlugSekunden = 0;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
Line 61... Line -...
61
 
-
 
62
// -- Parametersatz aus EEPROM lesen ---
-
 
63
// number [1..5]
-
 
64
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
65
{
-
 
66
   if((number > 5)||(number < 1)) number = 3;
-
 
67
   eeprom_read_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
-
 
68
   LED_Init();
-
 
69
}
-
 
70
 
-
 
71
// -- Parametersatz ins EEPROM schreiben ---
-
 
72
// number [1..5]
-
 
73
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
74
{
-
 
75
   if(number > 5) number = 5;
-
 
76
   if(number < 1) return;
-
 
77
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
-
 
78
   eeprom_write_byte((unsigned char*)(EEPROM_ADR_PARAM_LENGTH), length); // Länge der Datensätze merken
-
 
79
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_CHANNELS), 12); // 12 Kanäle merken
-
 
80
   SetActiveParamSetNumber(number);
-
 
81
   LED_Init();
-
 
82
}
-
 
83
 
-
 
84
unsigned char GetActiveParamSetNumber(void)
-
 
85
{
-
 
86
        unsigned char set;
-
 
87
        set = eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET));
-
 
88
        if((set > 5) || (set < 1))
-
 
89
        {
-
 
90
                set = 3;
-
 
91
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
-
 
92
        }
-
 
93
        return(set);
-
 
94
}
-
 
95
 
-
 
96
void SetActiveParamSetNumber(unsigned char number)
-
 
97
{
-
 
98
        if(number > 5) number = 5;
-
 
99
        if(number < 1) return;
-
 
100
        eeprom_write_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET), number);                             // diesen Parametersatz als aktuell merken
-
 
101
}
-
 
Line 102... Line 61...
102
 
61
 
103
 
62
 
104
void CalMk3Mag(void)
63
void CalMk3Mag(void)
Line 158... Line 117...
158
//Hauptprogramm
117
//Hauptprogramm
159
int main (void)
118
int main (void)
160
//############################################################################
119
//############################################################################
161
{
120
{
162
        unsigned int timer,i,timer2 = 0, timerPolling;
121
        unsigned int timer,i,timer2 = 0, timerPolling;
163
        unsigned char RequiredMotors = 0;
-
 
Line 164... Line 122...
164
 
122
 
165
    DDRB  = 0x00;
123
    DDRB  = 0x00;
166
    PORTB = 0x00;
124
    PORTB = 0x00;
167
    for(timer = 0; timer < 1000; timer++); // verzögern
125
    for(timer = 0; timer < 1000; timer++); // verzögern
Line 202... Line 160...
202
        SPI_MasterInit();
160
        SPI_MasterInit();
203
        Capacity_Init();
161
        Capacity_Init();
204
        LIBFC_Init();
162
        LIBFC_Init();
205
        GRN_ON;
163
        GRN_ON;
206
    sei();
164
    sei();
207
 
-
 
208
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes
165
        ParamSet_Init();
Line 209... Line -...
209
 
-
 
210
 
-
 
211
    if((eeprom_read_byte((unsigned char*)(EEPROM_ADR_MIXER_TABLE)) == MIXER_REVISION) && // Check Revision in the first Byte
-
 
212
       (eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != 0xff))                   // Settings reset via Koptertool
-
 
213
        {
-
 
214
     unsigned char i;
-
 
215
     eeprom_read_block(&Mixer, (unsigned char*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
-
 
216
     for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;}
-
 
217
        }
-
 
218
        else // default
-
 
219
        {
-
 
220
     unsigned char i;
-
 
221
         printf("\n\rGenerating default Mixer Table");
-
 
222
         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;};
-
 
223
     // default = Quadro
-
 
224
     Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] =   0; Mixer.Motor[0][3] = +64;
-
 
225
     Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] =   0; Mixer.Motor[1][3] = +64;
-
 
226
     Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] =   0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64;
-
 
227
     Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] =   0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64;
-
 
228
         Mixer.Revision = MIXER_REVISION;
-
 
229
     memcpy(Mixer.Name, "Quadro\0", 11);
-
 
230
     eeprom_write_block(&Mixer, (void*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
-
 
231
    }
-
 
232
    printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
166
 
233
 
167
 
234
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
235
// + Check connected BL-Ctrls
169
// + Check connected BL-Ctrls
236
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
237
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
171
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
Line 238... Line 172...
238
        printf("\n\rFound BL-Ctrl: ");
172
        printf("\n\rFound BL-Ctrl: ");
239
    timer = SetDelay(4000);
173
    timer = SetDelay(4000);
240
 
174
 
241
        for(i=0; i < MAX_MOTORS; i++)
175
        for(i=0; i < MAX_MOTORS; i++)
242
         {
176
        {
243
          UpdateMotor = 0;
177
                UpdateMotor = 0;
244
      SendMotorData();
178
                SendMotorData();
245
          while(!UpdateMotor);
179
                while(!UpdateMotor);
246
      if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
180
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
247
        {
181
                {
248
             while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
182
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
249
                }
183
                }
250
          if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1);
-
 
251
     }
-
 
252
        for(i=0; i < MAX_MOTORS; i++)
-
 
253
         {
-
 
254
          if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
-
 
255
           {
-
 
256
            printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
-
 
257
                ServoActive = 1; // just in case the FC would be used as camera-stabilizer
-
 
258
           }
-
 
259
          Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
-
 
260
     }
-
 
261
        printf("\n\r===================================");
-
 
262
    SendMotorData();
-
 
263
//printf("\n size: %u",STRUCT_PARAM_LAENGE);
-
 
264
 
-
 
265
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
266
// + Check Settings
184
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1);
267
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
268
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != EE_DATENREVISION)
-
 
269
        {
-
 
270
          DefaultKonstanten1();
-
 
271
          printf("\n\rInit. EEPROM");
-
 
272
          for (unsigned char i=1;i<6;i++)
185
        }
273
      {
-
 
274
       if(i==2) DefaultKonstanten2(); // Kamera
-
 
275
       if(i==3) DefaultKonstanten3(); // Beginner
186
        for(i=0; i < MAX_MOTORS; i++)
276
       if(i>3)  DefaultKonstanten2(); // Kamera
-
 
277
           if(PlatinenVersion >= 20)
-
 
278
            {
-
 
279
                 EE_Parameter.Gyro_D = 5;
187
        {
280
                 EE_Parameter.Driftkomp = 0;
188
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
281
                 EE_Parameter.GyroAccFaktor = 27;
189
                {
282
         EE_Parameter.WinkelUmschlagNick = 78;
-
 
283
         EE_Parameter.WinkelUmschlagRoll = 78;
190
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
284
                }
-
 
285
    // valid Stick-Settings?
-
 
286
           if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3)) < 12)
-
 
287
            {
-
 
288
         EE_Parameter.Kanalbelegung[0] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+0));
-
 
289
         EE_Parameter.Kanalbelegung[1] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1));
-
 
290
         EE_Parameter.Kanalbelegung[2] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2));
-
 
291
         EE_Parameter.Kanalbelegung[3] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3));
-
 
292
         EE_Parameter.Kanalbelegung[4] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+4));
-
 
293
         EE_Parameter.Kanalbelegung[5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+5));
-
 
294
         EE_Parameter.Kanalbelegung[6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+6));
-
 
295
         EE_Parameter.Kanalbelegung[7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+7));
-
 
296
 
-
 
297
         if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8)) < 0xFF)
-
 
298
                  {
-
 
299
                   EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8));
-
 
300
           EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+9));
-
 
301
           EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+10));
-
 
302
           EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+11));
-
 
303
                  }
-
 
304
                  else
-
 
305
                  {
-
 
306
           EE_Parameter.Kanalbelegung[K_POTI5] = 9;
-
 
307
           EE_Parameter.Kanalbelegung[K_POTI6] = 10;
-
 
308
           EE_Parameter.Kanalbelegung[K_POTI7] = 11;
-
 
309
           EE_Parameter.Kanalbelegung[K_POTI8] = 12;
-
 
310
                  }
-
 
311
         if(i==1) printf(": Generating Default-Parameter using old Stick Settings");
-
 
312
                } else DefaultStickMapping();
-
 
313
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
314
      }
191
                        ServoActive = 1; // just in case the FC would be used as camera-stabilizer
315
          SetActiveParamSetNumber(3); // default-Setting
-
 
316
          eeprom_write_byte((unsigned char*)(EEPROM_ADR_VALID), EE_DATENREVISION);
-
 
317
        }
-
 
318
 
192
                }
319
    FlugMinuten = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1));
-
 
320
    FlugMinutenGesamt = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES+1));
193
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
321
    if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff)
-
 
322
         {
-
 
323
          FlugMinuten = 0;
-
 
324
          FlugMinutenGesamt = 0;
-
 
325
         }
-
 
326
    printf("\n\rFlight-time %u min  Total:%u min" ,FlugMinuten,FlugMinutenGesamt);
-
 
327
 
-
 
328
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACC_NICK)) > 4)
-
 
329
     {
-
 
330
       printf("\n\rACC not calibrated !");
-
 
331
     }
-
 
332
 
-
 
Line 333... Line 194...
333
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
194
        }
334
    printf("\n\rUsing parameterset %d", GetActiveParamSetNumber());
195
        printf("\n\r===================================");
335
 
196
    SendMotorData();
336
 
197
 
337
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
198
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
338
         {
199
        {
339
           printf("\n\rCalibrating pressure sensor..");
200
                printf("\n\rCalibrating pressure sensor..");
340
           timer = SetDelay(1000);
201
                timer = SetDelay(1000);
Line 341... Line 202...
341
       SucheLuftruckOffset();
202
                SucheLuftruckOffset();
Line 342... Line 203...
342
           while (!CheckDelay(timer));
203
                while (!CheckDelay(timer));
Line 343... Line 204...
343
       printf("OK\n\r");
204
                printf("OK\n\r");
344
        }
205
        }
Line -... Line 206...
-
 
206
 
-
 
207
        SetNeutral(0);
-
 
208
 
-
 
209
        ROT_OFF;
-
 
210
 
-
 
211
    beeptime = 2000;
-
 
212
    ExternControl.Digital[0] = 0x55;
-
 
213
 
-
 
214
 
-
 
215
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
-
 
216
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
345
 
217
 
346
        SetNeutral();
218
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
347
 
219
        {
Line 348... Line 220...
348
        ROT_OFF;
220
                FlugMinuten = 0;
Line 361... Line 233...
361
    LipoDetection(1);
233
    LipoDetection(1);
Line 362... Line 234...
362
 
234
 
Line 363... Line 235...
363
        LIBFC_ReceiverInit();
235
        LIBFC_ReceiverInit();
364
 
236
 
365
        printf("\n\r===================================\n\r");
237
        printf("\n\r===================================\n\r");
366
//SpektrumBinding();
238
        //SpektrumBinding();
Line 367... Line 239...
367
    timer = SetDelay(2000);
239
    timer = SetDelay(2000);
368
        timerPolling = SetDelay(250);
240
        timerPolling = SetDelay(250);
Line 472... Line 344...
472
                                if(++timer2 == 2930)  // eine Minute
344
                                if(++timer2 == 2930)  // eine Minute
473
                                 {
345
                                 {
474
                                   timer2 = 0;
346
                                   timer2 = 0;
475
                   FlugMinuten++;
347
                   FlugMinuten++;
476
                       FlugMinutenGesamt++;
348
                       FlugMinutenGesamt++;
477
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2),FlugMinuten / 256);
349
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
478
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1),FlugMinuten % 256);
350
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
479
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES),FlugMinutenGesamt / 256);
-
 
480
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES+1),FlugMinutenGesamt % 256);
-
 
481
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
351
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
482
                             }
352
                             }
483
                        }
353
                        }
484
           LED_Update();
354
           LED_Update();
485
           Capacity_Update();
355
           Capacity_Update();