Subversion Repositories FlightCtrl

Rev

Rev 1166 | Rev 1171 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1166 Rev 1167
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
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.
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
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
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"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
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
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.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
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
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
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
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
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
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"
53
 
53
 
54
unsigned char EEPromArray[E2END+1] EEMEM;
54
unsigned char EEPromArray[E2END+1] EEMEM;
55
unsigned char PlatinenVersion = 10;
55
unsigned char PlatinenVersion = 10;
56
unsigned char SendVersionToNavi = 1;
56
unsigned char SendVersionToNavi = 1;
57
// -- Parametersatz aus EEPROM lesen ---
57
// -- Parametersatz aus EEPROM lesen ---
58
// number [1..5]
58
// number [1..5]
59
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
59
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
60
{
60
{
61
   if((number > 5)||(number < 1)) number = 3;
61
   if((number > 5)||(number < 1)) number = 3;
62
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
62
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
63
   LED_Init();
63
   LED_Init();
64
}
64
}
65
 
65
 
66
// -- Parametersatz ins EEPROM schreiben ---
66
// -- Parametersatz ins EEPROM schreiben ---
67
// number [1..5]
67
// number [1..5]
68
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
68
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
69
{
69
{
70
   if(number > 5) number = 5;
70
   if(number > 5) number = 5;
71
   if(number < 1) return;
71
   if(number < 1) return;
72
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
72
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
73
   SetActiveParamSetNumber(number);
73
   SetActiveParamSetNumber(number);
74
   LED_Init();
74
   LED_Init();
75
}
75
}
76
 
76
 
77
unsigned char GetActiveParamSetNumber(void)
77
unsigned char GetActiveParamSetNumber(void)
78
{
78
{
79
        unsigned char set;
79
        unsigned char set;
80
        set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
80
        set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
81
        if((set > 5) || (set < 1))
81
        if((set > 5) || (set < 1))
82
        {
82
        {
83
                set = 3;
83
                set = 3;
84
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
84
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
85
        }
85
        }
86
        return(set);
86
        return(set);
87
}
87
}
88
 
88
 
89
 
89
 
90
void SetActiveParamSetNumber(unsigned char number)
90
void SetActiveParamSetNumber(unsigned char number)
91
{
91
{
92
        if(number > 5) number = 5;
92
        if(number > 5) number = 5;
93
        if(number < 1) return;
93
        if(number < 1) return;
94
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                                 // diesen Parametersatz als aktuell merken
94
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                                 // diesen Parametersatz als aktuell merken
95
}
95
}
96
 
96
 
97
 
97
 
98
void CalMk3Mag(void)
98
void CalMk3Mag(void)
99
{
99
{
100
 static unsigned char stick = 1;
100
 static unsigned char stick = 1;
101
 
101
 
102
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
102
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
103
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
103
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
104
  {
104
  {
105
   stick = 1;
105
   stick = 1;
106
   WinkelOut.CalcState++;
106
   WinkelOut.CalcState++;
107
   if(WinkelOut.CalcState > 4)
107
   if(WinkelOut.CalcState > 4)
108
    {
108
    {
109
//     WinkelOut.CalcState = 0; // in Uart.c
109
//     WinkelOut.CalcState = 0; // in Uart.c
110
     beeptime = 1000;
110
     beeptime = 1000;
111
    }
111
    }
112
   else Piep(WinkelOut.CalcState);
112
   else Piep(WinkelOut.CalcState);
113
  }
113
  }
114
  DebugOut.Analog[19] = WinkelOut.CalcState;
114
  DebugOut.Analog[19] = WinkelOut.CalcState;
115
}
115
}
116
 
116
 
117
//############################################################################
117
//############################################################################
118
//Hauptprogramm
118
//Hauptprogramm
119
int main (void)
119
int main (void)
120
//############################################################################
120
//############################################################################
121
{
121
{
122
        unsigned int timer;
122
        unsigned int timer;
123
    DDRB  = 0x00;
123
    DDRB  = 0x00;
124
    PORTB = 0x00;
124
    PORTB = 0x00;
125
    for(timer = 0; timer < 1000; timer++); // verzögern
125
    for(timer = 0; timer < 1000; timer++); // verzögern
126
    if(PINB & 0x01)
126
    if(PINB & 0x01)
127
     {
127
     {
128
      if(PINB & 0x02) PlatinenVersion = 13;
128
      if(PINB & 0x02) PlatinenVersion = 13;
129
       else           PlatinenVersion = 11;
129
       else           PlatinenVersion = 11;
130
     }
130
     }
131
    else
131
    else
132
     {
132
     {
133
      if(PINB & 0x02) PlatinenVersion = 20;
133
      if(PINB & 0x02) PlatinenVersion = 20;
134
       else           PlatinenVersion = 10;
134
       else           PlatinenVersion = 10;
135
     }
135
     }
136
 
136
 
137
    DDRC  = 0x81; // SCL
137
    DDRC  = 0x81; // SCL
138
    DDRC  |=0x40; // HEF4017 Reset
138
    DDRC  |=0x40; // HEF4017 Reset
139
    PORTC = 0xff; // Pullup SDA
139
    PORTC = 0xff; // Pullup SDA
140
    DDRB  = 0x1B; // LEDs und Druckoffset
140
    DDRB  = 0x1B; // LEDs und Druckoffset
141
    PORTB = 0x01; // LED_Rot
141
    PORTB = 0x01; // LED_Rot
142
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
142
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
143
    DDRD  |=0x80; // J7 -> Servo signal
143
    DDRD  |=0x80; // J7 -> Servo signal
144
        PORTD = 0x47; // LED
144
        PORTD = 0x47; // LED
145
 
145
 
146
    MCUSR &=~(1<<WDRF);
146
    MCUSR &=~(1<<WDRF);
147
    WDTCSR |= (1<<WDCE)|(1<<WDE);
147
    WDTCSR |= (1<<WDCE)|(1<<WDE);
148
    WDTCSR = 0;
148
    WDTCSR = 0;
149
 
149
 
150
    beeptime = 2000;
150
    beeptime = 2000;
151
 
151
 
152
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
152
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
153
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
153
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
154
    ROT_OFF;
154
    ROT_OFF;
155
 
155
 
156
    Timer_Init();
156
    Timer_Init();
157
        TIMER2_Init();
157
        TIMER2_Init();
158
        UART_Init();
158
        UART_Init();
159
    rc_sum_init();
159
    rc_sum_init();
160
        ADC_Init();
160
        ADC_Init();
161
        i2c_init();
161
        i2c_init();
162
        SPI_MasterInit();
162
        SPI_MasterInit();
163
 
163
 
164
        sei();
164
        sei();
165
 
165
 
166
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a');
166
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a');
167
        printf("\n\r==============================");
167
        printf("\n\r==============================");
168
 
168
 
169
        GRN_ON;
169
        GRN_ON;
170
 
170
 
171
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes
171
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes
172
    // valid Stick-Settings?
172
    // valid Stick-Settings?
173
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION ||
173
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION ||
174
        EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9)
174
        EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9)
175
           {
175
           {
176
            printf("\n\rInit. EEPROM");
176
            printf("\n\rInit. EEPROM");
177
        DefaultStickMapping();
177
        DefaultStickMapping();
178
       }
178
       }
179
    else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings");
179
    else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings");
180
 
180
 
181
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
181
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
182
        {
182
        {
183
          DefaultKonstanten1();
183
          DefaultKonstanten1();
184
          for (unsigned char i=1;i<6;i++)
184
          for (unsigned char i=1;i<6;i++)
185
      {
185
      {
186
       if(i==2) DefaultKonstanten2(); // Kamera
186
       if(i==2) DefaultKonstanten2(); // Kamera
187
       if(i==3) DefaultKonstanten3(); // Beginner
187
       if(i==3) DefaultKonstanten3(); // Beginner
188
       if(i>3)  DefaultKonstanten2(); // Kamera
188
       if(i>3)  DefaultKonstanten2(); // Kamera
189
           if(PlatinenVersion >= 20)
189
           if(PlatinenVersion >= 20)
190
            {
190
            {
191
                 EE_Parameter.Gyro_D = 8;
191
                 EE_Parameter.Gyro_D = 5;
192
                 EE_Parameter.Driftkomp = 0;
192
                 EE_Parameter.Driftkomp = 0;
193
                 EE_Parameter.GyroAccFaktor = 27;
193
                 EE_Parameter.GyroAccFaktor = 27;
194
         EE_Parameter.WinkelUmschlagNick = 78;
194
         EE_Parameter.WinkelUmschlagNick = 78;
195
         EE_Parameter.WinkelUmschlagRoll = 78;
195
         EE_Parameter.WinkelUmschlagRoll = 78;
196
                 
196
                 
197
                }
197
                }
198
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
198
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
199
      }
199
      }
200
          SetActiveParamSetNumber(3); // default-Setting
200
          SetActiveParamSetNumber(3); // default-Setting
201
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
201
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
202
        }
202
        }
203
 
203
 
204
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
204
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
205
     {
205
     {
206
       printf("\n\rACC nicht abgeglichen!");
206
       printf("\n\rACC nicht abgeglichen!");
207
     }
207
     }
208
 
208
 
209
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
209
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
210
    printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber());
210
    printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber());
211
 
211
 
212
 
212
 
213
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
213
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
214
         {
214
         {
215
           printf("\n\rAbgleich Luftdrucksensor..");
215
           printf("\n\rAbgleich Luftdrucksensor..");
216
           timer = SetDelay(1000);
216
           timer = SetDelay(1000);
217
       SucheLuftruckOffset();
217
       SucheLuftruckOffset();
218
           while (!CheckDelay(timer));
218
           while (!CheckDelay(timer));
219
       printf("OK\n\r");
219
       printf("OK\n\r");
220
        }
220
        }
221
 
221
 
222
        SetNeutral();
222
        SetNeutral();
223
 
223
 
224
        ROT_OFF;
224
        ROT_OFF;
225
 
225
 
226
    beeptime = 2000;
226
    beeptime = 2000;
227
    ExternControl.Digital[0] = 0x55;
227
    ExternControl.Digital[0] = 0x55;
228
 
228
 
229
 
229
 
230
        printf("\n\rSteuerung: ");
230
        printf("\n\rSteuerung: ");
231
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
231
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
232
        else printf("Neutral");
232
        else printf("Neutral");
233
 
233
 
234
        printf("\n\n\r");
234
        printf("\n\n\r");
235
 
235
 
236
    LcdClear();
236
    LcdClear();
237
    I2CTimeout = 5000;
237
    I2CTimeout = 5000;
238
    WinkelOut.Orientation = 1;
238
    WinkelOut.Orientation = 1;
239
        while (1)
239
        while (1)
240
        {
240
        {
241
            if(UpdateMotor && AdReady)      // ReglerIntervall
241
            if(UpdateMotor && AdReady)      // ReglerIntervall
242
            {
242
            {
243
J3High;
243
J3High;
244
                    UpdateMotor=0;
244
                    UpdateMotor=0;
245
            if(WinkelOut.CalcState) CalMk3Mag();
245
            if(WinkelOut.CalcState) CalMk3Mag();
246
            else MotorRegler();
246
            else MotorRegler();
247
            SendMotorData();
247
            SendMotorData();
248
            ROT_OFF;
248
            ROT_OFF;
249
J3Low;
249
J3Low;
250
            if(PcZugriff) PcZugriff--;
250
            if(PcZugriff) PcZugriff--;
251
             else
251
             else
252
              {
252
              {
253
                           ExternControl.Config = 0;
253
                           ExternControl.Config = 0;
254
               ExternStickNick = 0;
254
               ExternStickNick = 0;
255
               ExternStickRoll = 0;
255
               ExternStickRoll = 0;
256
               ExternStickGier = 0;
256
               ExternStickGier = 0;
257
              }
257
              }
258
            if(SenderOkay)  SenderOkay--;
258
            if(SenderOkay)  SenderOkay--;
259
            if(!I2CTimeout)
259
            if(!I2CTimeout)
260
                {
260
                {
261
                 I2CTimeout = 5;
261
                 I2CTimeout = 5;
262
                 i2c_reset();
262
                 i2c_reset();
263
                  if((BeepMuster == 0xffff) && MotorenEin)
263
                  if((BeepMuster == 0xffff) && MotorenEin)
264
                   {
264
                   {
265
                    beeptime = 10000;
265
                    beeptime = 10000;
266
                    BeepMuster = 0x0080;
266
                    BeepMuster = 0x0080;
267
                   }
267
                   }
268
                }
268
                }
269
            else
269
            else
270
                {
270
                {
271
                 I2CTimeout--;
271
                 I2CTimeout--;
272
                 ROT_OFF;
272
                 ROT_OFF;
273
                }
273
                }
274
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
274
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
275
              {
275
              {
276
               DatenUebertragung();
276
               DatenUebertragung();
277
               BearbeiteRxDaten();
277
               BearbeiteRxDaten();
278
              }
278
              }
279
              else BearbeiteRxDaten();
279
              else BearbeiteRxDaten();
280
         if(CheckDelay(timer))
280
         if(CheckDelay(timer))
281
            {
281
            {
282
            if(UBat < EE_Parameter.UnterspannungsWarnung)
282
            if(UBat < EE_Parameter.UnterspannungsWarnung)
283
                {
283
                {
284
                  if(BeepMuster == 0xffff)
284
                  if(BeepMuster == 0xffff)
285
                   {
285
                   {
286
                    beeptime = 6000;
286
                    beeptime = 6000;
287
                    BeepMuster = 0x0300;
287
                    BeepMuster = 0x0300;
288
                   }
288
                   }
289
                }
289
                }
290
             SPI_StartTransmitPacket();
290
             SPI_StartTransmitPacket();
291
 
291
 
292
             SendSPI = 4;
292
             SendSPI = 4;
293
                         timer = SetDelay(20);
293
                         timer = SetDelay(20);
294
            }
294
            }
295
           LED_Update();
295
           LED_Update();
296
          }
296
          }
297
     if(!SendSPI) { SPI_TransmitByte(); }
297
     if(!SendSPI) { SPI_TransmitByte(); }
298
    }
298
    }
299
 return (1);
299
 return (1);
300
}
300
}
301
 
301
 
302
 
302