Subversion Repositories FlightCtrl

Rev

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

Rev 1657 Rev 1662
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
2
// + Copyright (c) Holger Buss, Ingo Busker
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
4
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
8
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
8
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
9
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
10
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + bzgl. der Nutzungsbedingungen aufzunehmen.
11
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Verkauf von Luftbildaufnahmen, usw.
12
// + Verkauf von Luftbildaufnahmen, usw.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
15
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
18
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
19
// + eindeutig als Ursprung verlinkt werden
19
// + eindeutig als Ursprung verlinkt werden
20
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
22
// + Benutzung auf eigene Gefahr
22
// + Benutzung auf eigene Gefahr
23
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
24
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
26
// + mit unserer Zustimmung zulässig
26
// + mit unserer Zustimmung zulässig
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
31
// + this list of conditions and the following disclaimer.
31
// + this list of conditions and the following disclaimer.
32
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
33
// +     from this software without specific prior written permission.
33
// +     from this software without specific prior written permission.
34
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
35
// +     for non-commercial use (directly or indirectly)
35
// +     for non-commercial use (directly or indirectly)
36
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
37
// +     with our written permission
37
// +     with our written permission
38
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
39
// +     clearly linked as origin
39
// +     clearly linked as origin
40
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
41
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  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
 
52
 
53
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
// + Contant Values
54
// + Contant Values
55
// + 0-250 -> normale Values
55
// + 0-250 -> normale Values
56
// + 251 -> Poti1
56
// + 251 -> Poti1
57
// + 252 -> Poti2
57
// + 252 -> Poti2
58
// + 253 -> Poti3
58
// + 253 -> Poti3
59
// + 254 -> Poti4
59
// + 254 -> Poti4
60
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
61
 
61
 
62
#ifndef EEMEM
62
#ifndef EEMEM
63
#define EEMEM __attribute__ ((section (".eeprom")))
63
#define EEMEM __attribute__ ((section (".eeprom")))
64
#endif
64
#endif
65
 
65
 
66
 
66
 
67
#include <avr/eeprom.h>
67
#include <avr/eeprom.h>
68
#include <string.h>
68
#include <string.h>
69
#include "eeprom.h"
69
#include "eeprom.h"
70
#include "uart.h"
70
#include "uart.h"
71
#include "led.h"
71
#include "led.h"
72
#include "main.h"
72
#include "main.h"
73
#include "fc.h"
73
#include "fc.h"
74
#include "twimaster.h"
74
#include "twimaster.h"
75
 
75
 
76
paramset_t              EE_Parameter;
76
paramset_t              EE_Parameter;
77
MixerTable_t    Mixer;
77
MixerTable_t    Mixer;
78
uint8_t RequiredMotors;
78
uint8_t RequiredMotors;
79
BLConfig_t BLConfig[MAX_MOTORS];
-
 
80
 
79
 
81
 
80
 
82
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len)
81
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len)
83
{
82
{
84
        uint8_t crc = 0xAA;
83
        uint8_t crc = 0xAA;
85
        uint16_t i;
84
        uint16_t i;
86
 
85
 
87
        for(i=0; i<len; i++)
86
        for(i=0; i<len; i++)
88
        {
87
        {
89
                crc += pBuffer[i];
88
                crc += pBuffer[i];
90
        }
89
        }
91
        return crc;
90
        return crc;
92
}
91
}
93
 
92
 
94
uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len)
93
uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len)
95
{
94
{
96
        uint8_t crc = 0xAA;
95
        uint8_t crc = 0xAA;
97
        uint16_t off;
96
        uint16_t off;
98
 
97
 
99
        for(off=0; off<len; off++)
98
        for(off=0; off<len; off++)
100
        {
99
        {
101
                crc += eeprom_read_byte((uint8_t*)(EEAddr + off));;
100
                crc += eeprom_read_byte((uint8_t*)(EEAddr + off));;
102
        }
101
        }
103
        return crc;
102
        return crc;
104
}
103
}
105
 
104
 
106
void ParamSet_DefaultStickMapping(void)
105
void ParamSet_DefaultStickMapping(void)
107
{
106
{
108
        EE_Parameter.Kanalbelegung[K_GAS]   = 1;
107
        EE_Parameter.Kanalbelegung[K_GAS]   = 1;
109
        EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
108
        EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
110
        EE_Parameter.Kanalbelegung[K_NICK]  = 3;
109
        EE_Parameter.Kanalbelegung[K_NICK]  = 3;
111
        EE_Parameter.Kanalbelegung[K_GIER]  = 4;
110
        EE_Parameter.Kanalbelegung[K_GIER]  = 4;
112
        EE_Parameter.Kanalbelegung[K_POTI1] = 5;
111
        EE_Parameter.Kanalbelegung[K_POTI1] = 5;
113
        EE_Parameter.Kanalbelegung[K_POTI2] = 6;
112
        EE_Parameter.Kanalbelegung[K_POTI2] = 6;
114
        EE_Parameter.Kanalbelegung[K_POTI3] = 7;
113
        EE_Parameter.Kanalbelegung[K_POTI3] = 7;
115
        EE_Parameter.Kanalbelegung[K_POTI4] = 8;
114
        EE_Parameter.Kanalbelegung[K_POTI4] = 8;
116
        EE_Parameter.Kanalbelegung[K_POTI5] = 9;
115
        EE_Parameter.Kanalbelegung[K_POTI5] = 9;
117
        EE_Parameter.Kanalbelegung[K_POTI6] = 10;
116
        EE_Parameter.Kanalbelegung[K_POTI6] = 10;
118
        EE_Parameter.Kanalbelegung[K_POTI7] = 11;
117
        EE_Parameter.Kanalbelegung[K_POTI7] = 11;
119
        EE_Parameter.Kanalbelegung[K_POTI8] = 12;
118
        EE_Parameter.Kanalbelegung[K_POTI8] = 12;
120
}
119
}
121
 
120
 
122
 
121
 
123
/***************************************************/
122
/***************************************************/
124
/*    Default Values for parameter set 1           */
123
/*    Default Values for parameter set 1           */
125
/***************************************************/
124
/***************************************************/
126
void ParamSet_DefaultSet1(void) // sport
125
void ParamSet_DefaultSet1(void) // sport
127
{
126
{
128
        EE_Parameter.Revision = EEPARAM_REVISION;
127
        EE_Parameter.Revision = EEPARAM_REVISION;
129
 
128
 
130
        if(PlatinenVersion >= 20)
129
        if(PlatinenVersion >= 20)
131
        {
130
        {
132
                EE_Parameter.Gyro_D = 5;
131
                EE_Parameter.Gyro_D = 5;
133
                EE_Parameter.Driftkomp = 0;
132
                EE_Parameter.Driftkomp = 0;
134
                EE_Parameter.GyroAccFaktor = 27;
133
                EE_Parameter.GyroAccFaktor = 27;
135
                EE_Parameter.WinkelUmschlagNick = 78;
134
                EE_Parameter.WinkelUmschlagNick = 78;
136
                EE_Parameter.WinkelUmschlagRoll = 78;
135
                EE_Parameter.WinkelUmschlagRoll = 78;
137
        }
136
        }
138
        else
137
        else
139
        {
138
        {
140
                EE_Parameter.Gyro_D = 3;
139
                EE_Parameter.Gyro_D = 3;
141
                EE_Parameter.Driftkomp = 32;
140
                EE_Parameter.Driftkomp = 32;
142
                EE_Parameter.GyroAccFaktor = 30;
141
                EE_Parameter.GyroAccFaktor = 30;
143
                EE_Parameter.WinkelUmschlagNick = 85;
142
                EE_Parameter.WinkelUmschlagNick = 85;
144
                EE_Parameter.WinkelUmschlagRoll = 85;
143
                EE_Parameter.WinkelUmschlagRoll = 85;
145
        }
144
        }
146
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
145
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
147
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
146
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
148
        EE_Parameter.Hoehe_MinGas = 30;
147
        EE_Parameter.Hoehe_MinGas = 30;
149
        EE_Parameter.MaxHoehe     = 255;      // Wert : 0-247   255 -> Poti1
148
        EE_Parameter.MaxHoehe     = 255;      // Wert : 0-247   255 -> Poti1
150
        EE_Parameter.Hoehe_P      = 10;       // Wert : 0-32
149
        EE_Parameter.Hoehe_P      = 10;       // Wert : 0-32
151
        EE_Parameter.Luftdruck_D  = 30;       // Wert : 0-247
150
        EE_Parameter.Luftdruck_D  = 30;       // Wert : 0-247
152
        EE_Parameter.Hoehe_ACC_Wirkung = 30;  // Wert : 0-247
151
        EE_Parameter.Hoehe_ACC_Wirkung = 30;  // Wert : 0-247
153
        EE_Parameter.Hoehe_HoverBand = 5;     // Wert : 0-247
152
        EE_Parameter.Hoehe_HoverBand = 5;     // Wert : 0-247
154
        EE_Parameter.Hoehe_GPS_Z = 64;        // Wert : 0-247
153
        EE_Parameter.Hoehe_GPS_Z = 64;        // Wert : 0-247
155
        EE_Parameter.Hoehe_StickNeutralPoint = 0; // Wert : 0-247 (0 = Hover-Estimation)
154
        EE_Parameter.Hoehe_StickNeutralPoint = 0; // Wert : 0-247 (0 = Hover-Estimation)
156
        EE_Parameter.Hoehe_Verstaerkung = 20; // Wert : 0-50
155
        EE_Parameter.Hoehe_Verstaerkung = 20; // Wert : 0-50
157
        EE_Parameter.Stick_P = 14;            // Wert : 1-6
156
        EE_Parameter.Stick_P = 14;            // Wert : 1-6
158
        EE_Parameter.Stick_D = 16;            // Wert : 0-64
157
        EE_Parameter.Stick_D = 16;            // Wert : 0-64
159
        EE_Parameter.Gier_P = 12;             // Wert : 1-20
158
        EE_Parameter.Gier_P = 12;             // Wert : 1-20
160
        EE_Parameter.Gas_Min = 8;             // Wert : 0-32
159
        EE_Parameter.Gas_Min = 8;             // Wert : 0-32
161
        EE_Parameter.Gas_Max = 230;           // Wert : 33-247
160
        EE_Parameter.Gas_Max = 230;           // Wert : 33-247
162
        EE_Parameter.KompassWirkung = 128;    // Wert : 0-247
161
        EE_Parameter.KompassWirkung = 128;    // Wert : 0-247
163
        EE_Parameter.Gyro_P = 80;             // Wert : 0-247
162
        EE_Parameter.Gyro_P = 80;             // Wert : 0-247
164
        EE_Parameter.Gyro_I = 150;            // Wert : 0-247
163
        EE_Parameter.Gyro_I = 150;            // Wert : 0-247
165
        EE_Parameter.Gyro_Gier_P = 80;        // Wert : 0-247
164
        EE_Parameter.Gyro_Gier_P = 80;        // Wert : 0-247
166
        EE_Parameter.Gyro_Gier_I = 150;       // Wert : 0-247
165
        EE_Parameter.Gyro_Gier_I = 150;       // Wert : 0-247
167
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
166
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
168
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
167
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
169
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
168
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
170
        EE_Parameter.I_Faktor = 32;
169
        EE_Parameter.I_Faktor = 32;
171
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
170
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
172
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
171
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
173
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
172
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
174
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
173
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
175
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
174
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
176
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
175
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
177
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
176
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
178
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
177
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
179
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
178
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
180
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
179
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
181
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
180
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
182
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
181
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
183
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
182
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
184
        EE_Parameter.ServoNickRefresh = 6;
183
        EE_Parameter.ServoNickRefresh = 6;
185
        EE_Parameter.Servo3 = 125;
184
        EE_Parameter.Servo3 = 125;
186
        EE_Parameter.Servo4 = 125;
185
        EE_Parameter.Servo4 = 125;
187
        EE_Parameter.Servo5 = 125;
186
        EE_Parameter.Servo5 = 125;
188
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
187
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
189
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
188
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
190
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
189
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
191
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
190
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
192
        EE_Parameter.LoopGasLimit = 50;
191
        EE_Parameter.LoopGasLimit = 50;
193
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
192
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
194
        EE_Parameter.LoopHysterese = 50;
193
        EE_Parameter.LoopHysterese = 50;
195
        EE_Parameter.BitConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
194
        EE_Parameter.BitConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
196
        EE_Parameter.AchsKopplung1 = 90;
195
        EE_Parameter.AchsKopplung1 = 90;
197
        EE_Parameter.AchsKopplung2 = 80;
196
        EE_Parameter.AchsKopplung2 = 80;
198
        EE_Parameter.CouplingYawCorrection = 1;
197
        EE_Parameter.CouplingYawCorrection = 1;
199
        EE_Parameter.GyroAccAbgleich = 16;        // 1/k;
198
        EE_Parameter.GyroAccAbgleich = 16;        // 1/k;
200
        EE_Parameter.DynamicStability = 100;
199
        EE_Parameter.DynamicStability = 100;
201
        EE_Parameter.J16Bitmask = 95;
200
        EE_Parameter.J16Bitmask = 95;
202
        EE_Parameter.J17Bitmask = 243;
201
        EE_Parameter.J17Bitmask = 243;
203
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
202
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
204
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
203
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
205
        EE_Parameter.J16Timing = 15;
204
        EE_Parameter.J16Timing = 15;
206
        EE_Parameter.J17Timing = 15;
205
        EE_Parameter.J17Timing = 15;
207
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
206
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
208
        EE_Parameter.NaviGpsGain = 100;
207
        EE_Parameter.NaviGpsGain = 100;
209
        EE_Parameter.NaviGpsP = 90;
208
        EE_Parameter.NaviGpsP = 90;
210
        EE_Parameter.NaviGpsI = 90;
209
        EE_Parameter.NaviGpsI = 90;
211
        EE_Parameter.NaviGpsD = 90;
210
        EE_Parameter.NaviGpsD = 90;
212
        EE_Parameter.NaviGpsPLimit = 75;
211
        EE_Parameter.NaviGpsPLimit = 75;
213
        EE_Parameter.NaviGpsILimit = 75;
212
        EE_Parameter.NaviGpsILimit = 75;
214
        EE_Parameter.NaviGpsDLimit = 75;
213
        EE_Parameter.NaviGpsDLimit = 75;
215
        EE_Parameter.NaviGpsACC = 0;
214
        EE_Parameter.NaviGpsACC = 0;
216
        EE_Parameter.NaviGpsMinSat = 6;
215
        EE_Parameter.NaviGpsMinSat = 6;
217
        EE_Parameter.NaviStickThreshold = 8;
216
        EE_Parameter.NaviStickThreshold = 8;
218
        EE_Parameter.NaviWindCorrection = 90;
217
        EE_Parameter.NaviWindCorrection = 90;
219
        EE_Parameter.NaviSpeedCompensation = 30;
218
        EE_Parameter.NaviSpeedCompensation = 30;
220
        EE_Parameter.NaviOperatingRadius = 100;
219
        EE_Parameter.NaviOperatingRadius = 100;
221
        EE_Parameter.NaviAngleLimitation = 100;
220
        EE_Parameter.NaviAngleLimitation = 100;
222
        EE_Parameter.NaviPH_LoginTime = 4;
221
        EE_Parameter.NaviPH_LoginTime = 4;
223
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
222
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
224
        memcpy(EE_Parameter.Name, "Sport\0", 12);
223
        memcpy(EE_Parameter.Name, "Sport\0", 12);
225
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
224
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
226
}
225
}
227
 
226
 
228
 
227
 
229
/***************************************************/
228
/***************************************************/
230
/*    Default Values for parameter set 2           */
229
/*    Default Values for parameter set 2           */
231
/***************************************************/
230
/***************************************************/
232
void ParamSet_DefaultSet2(void) // normal
231
void ParamSet_DefaultSet2(void) // normal
233
{
232
{
234
        EE_Parameter.Revision = EEPARAM_REVISION;
233
        EE_Parameter.Revision = EEPARAM_REVISION;
235
 
234
 
236
        if(PlatinenVersion >= 20)
235
        if(PlatinenVersion >= 20)
237
        {
236
        {
238
                EE_Parameter.Gyro_D = 5;
237
                EE_Parameter.Gyro_D = 5;
239
                EE_Parameter.Driftkomp = 0;
238
                EE_Parameter.Driftkomp = 0;
240
                EE_Parameter.GyroAccFaktor = 27;
239
                EE_Parameter.GyroAccFaktor = 27;
241
                EE_Parameter.WinkelUmschlagNick = 78;
240
                EE_Parameter.WinkelUmschlagNick = 78;
242
                EE_Parameter.WinkelUmschlagRoll = 78;
241
                EE_Parameter.WinkelUmschlagRoll = 78;
243
        }
242
        }
244
        else
243
        else
245
        {
244
        {
246
                EE_Parameter.Gyro_D = 3;
245
                EE_Parameter.Gyro_D = 3;
247
                EE_Parameter.Driftkomp = 32;
246
                EE_Parameter.Driftkomp = 32;
248
                EE_Parameter.GyroAccFaktor = 30;
247
                EE_Parameter.GyroAccFaktor = 30;
249
                EE_Parameter.WinkelUmschlagNick = 85;
248
                EE_Parameter.WinkelUmschlagNick = 85;
250
                EE_Parameter.WinkelUmschlagRoll = 85;
249
                EE_Parameter.WinkelUmschlagRoll = 85;
251
        }
250
        }
252
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
251
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
253
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
252
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
254
        EE_Parameter.Hoehe_MinGas = 30;
253
        EE_Parameter.Hoehe_MinGas = 30;
255
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
254
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
256
        EE_Parameter.Hoehe_P      = 10;          // Wert : 0-32
255
        EE_Parameter.Hoehe_P      = 10;          // Wert : 0-32
257
        EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
256
        EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
258
        EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
257
        EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
259
        EE_Parameter.Hoehe_HoverBand = 5;        // Wert : 0-247
258
        EE_Parameter.Hoehe_HoverBand = 5;        // Wert : 0-247
260
        EE_Parameter.Hoehe_GPS_Z = 64;           // Wert : 0-247
259
        EE_Parameter.Hoehe_GPS_Z = 64;           // Wert : 0-247
261
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
260
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
262
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50
261
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50
263
        EE_Parameter.Stick_P = 10;               // Wert : 1-6
262
        EE_Parameter.Stick_P = 10;               // Wert : 1-6
264
        EE_Parameter.Stick_D = 16;               // Wert : 0-64
263
        EE_Parameter.Stick_D = 16;               // Wert : 0-64
265
        EE_Parameter.Gier_P = 6;                 // Wert : 1-20
264
        EE_Parameter.Gier_P = 6;                 // Wert : 1-20
266
        EE_Parameter.Gas_Min = 8;                // Wert : 0-32
265
        EE_Parameter.Gas_Min = 8;                // Wert : 0-32
267
        EE_Parameter.Gas_Max = 230;              // Wert : 33-247
266
        EE_Parameter.Gas_Max = 230;              // Wert : 33-247
268
        EE_Parameter.KompassWirkung = 128;       // Wert : 0-247
267
        EE_Parameter.KompassWirkung = 128;       // Wert : 0-247
269
        EE_Parameter.Gyro_P = 90;                // Wert : 0-247
268
        EE_Parameter.Gyro_P = 90;                // Wert : 0-247
270
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
269
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
271
        EE_Parameter.Gyro_Gier_P = 90;           // Wert : 0-247
270
        EE_Parameter.Gyro_Gier_P = 90;           // Wert : 0-247
272
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
271
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
273
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
272
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
274
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
273
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
275
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
274
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
276
        EE_Parameter.I_Faktor = 32;
275
        EE_Parameter.I_Faktor = 32;
277
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
276
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
278
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
277
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
279
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
278
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
280
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
279
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
281
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
280
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
282
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
281
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
283
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
282
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
284
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
283
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
285
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
284
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
286
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
285
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
287
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
286
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
288
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
287
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
289
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
288
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
290
        EE_Parameter.ServoNickRefresh = 6;
289
        EE_Parameter.ServoNickRefresh = 6;
291
        EE_Parameter.Servo3 = 125;
290
        EE_Parameter.Servo3 = 125;
292
        EE_Parameter.Servo4 = 125;
291
        EE_Parameter.Servo4 = 125;
293
        EE_Parameter.Servo5 = 125;
292
        EE_Parameter.Servo5 = 125;
294
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
293
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
295
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
294
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
296
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
295
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
297
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
296
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
298
        EE_Parameter.LoopGasLimit = 50;
297
        EE_Parameter.LoopGasLimit = 50;
299
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
298
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
300
        EE_Parameter.LoopHysterese = 50;
299
        EE_Parameter.LoopHysterese = 50;
301
        EE_Parameter.BitConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
300
        EE_Parameter.BitConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
302
        EE_Parameter.AchsKopplung1 = 90;
301
        EE_Parameter.AchsKopplung1 = 90;
303
        EE_Parameter.AchsKopplung2 = 80;
302
        EE_Parameter.AchsKopplung2 = 80;
304
        EE_Parameter.CouplingYawCorrection = 60;
303
        EE_Parameter.CouplingYawCorrection = 60;
305
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
304
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
306
        EE_Parameter.DynamicStability = 75;
305
        EE_Parameter.DynamicStability = 75;
307
        EE_Parameter.J16Bitmask = 95;
306
        EE_Parameter.J16Bitmask = 95;
308
        EE_Parameter.J17Bitmask = 243;
307
        EE_Parameter.J17Bitmask = 243;
309
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
308
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
310
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
309
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
311
        EE_Parameter.J16Timing = 20;
310
        EE_Parameter.J16Timing = 20;
312
        EE_Parameter.J17Timing = 20;
311
        EE_Parameter.J17Timing = 20;
313
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
312
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
314
        EE_Parameter.NaviGpsGain = 100;
313
        EE_Parameter.NaviGpsGain = 100;
315
        EE_Parameter.NaviGpsP = 90;
314
        EE_Parameter.NaviGpsP = 90;
316
        EE_Parameter.NaviGpsI = 90;
315
        EE_Parameter.NaviGpsI = 90;
317
        EE_Parameter.NaviGpsD = 90;
316
        EE_Parameter.NaviGpsD = 90;
318
        EE_Parameter.NaviGpsPLimit = 75;
317
        EE_Parameter.NaviGpsPLimit = 75;
319
        EE_Parameter.NaviGpsILimit = 75;
318
        EE_Parameter.NaviGpsILimit = 75;
320
        EE_Parameter.NaviGpsDLimit = 75;
319
        EE_Parameter.NaviGpsDLimit = 75;
321
        EE_Parameter.NaviGpsACC = 0;
320
        EE_Parameter.NaviGpsACC = 0;
322
        EE_Parameter.NaviGpsMinSat = 6;
321
        EE_Parameter.NaviGpsMinSat = 6;
323
        EE_Parameter.NaviStickThreshold = 8;
322
        EE_Parameter.NaviStickThreshold = 8;
324
        EE_Parameter.NaviWindCorrection = 90;
323
        EE_Parameter.NaviWindCorrection = 90;
325
        EE_Parameter.NaviSpeedCompensation = 30;
324
        EE_Parameter.NaviSpeedCompensation = 30;
326
        EE_Parameter.NaviOperatingRadius = 100;
325
        EE_Parameter.NaviOperatingRadius = 100;
327
        EE_Parameter.NaviAngleLimitation = 100;
326
        EE_Parameter.NaviAngleLimitation = 100;
328
        EE_Parameter.NaviPH_LoginTime = 4;
327
        EE_Parameter.NaviPH_LoginTime = 4;
329
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
328
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
330
        memcpy(EE_Parameter.Name, "Normal\0", 12);
329
        memcpy(EE_Parameter.Name, "Normal\0", 12);
331
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
330
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
332
}
331
}
333
 
332
 
334
 
333
 
335
/***************************************************/
334
/***************************************************/
336
/*    Default Values for parameter set 3           */
335
/*    Default Values for parameter set 3           */
337
/***************************************************/
336
/***************************************************/
338
void ParamSet_DefaultSet3(void) // beginner
337
void ParamSet_DefaultSet3(void) // beginner
339
{
338
{
340
        EE_Parameter.Revision = EEPARAM_REVISION;
339
        EE_Parameter.Revision = EEPARAM_REVISION;
341
        if(PlatinenVersion >= 20)
340
        if(PlatinenVersion >= 20)
342
        {
341
        {
343
                EE_Parameter.Gyro_D = 5;
342
                EE_Parameter.Gyro_D = 5;
344
                EE_Parameter.Driftkomp = 0;
343
                EE_Parameter.Driftkomp = 0;
345
                EE_Parameter.GyroAccFaktor = 27;
344
                EE_Parameter.GyroAccFaktor = 27;
346
                EE_Parameter.WinkelUmschlagNick = 78;
345
                EE_Parameter.WinkelUmschlagNick = 78;
347
                EE_Parameter.WinkelUmschlagRoll = 78;
346
                EE_Parameter.WinkelUmschlagRoll = 78;
348
        }
347
        }
349
        else
348
        else
350
        {
349
        {
351
                EE_Parameter.Gyro_D = 3;
350
                EE_Parameter.Gyro_D = 3;
352
                EE_Parameter.Driftkomp = 32;
351
                EE_Parameter.Driftkomp = 32;
353
                EE_Parameter.GyroAccFaktor = 30;
352
                EE_Parameter.GyroAccFaktor = 30;
354
                EE_Parameter.WinkelUmschlagNick = 85;
353
                EE_Parameter.WinkelUmschlagNick = 85;
355
                EE_Parameter.WinkelUmschlagRoll = 85;
354
                EE_Parameter.WinkelUmschlagRoll = 85;
356
        }
355
        }
357
        EE_Parameter.GlobalConfig = /*CFG_DREHRATEN_BEGRENZER  |*/ CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
356
        EE_Parameter.GlobalConfig = /*CFG_DREHRATEN_BEGRENZER  |*/ CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
358
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
357
        EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT;// | CFG2_VARIO_BEEP | CFG_SENSITIVE_RC
359
        EE_Parameter.Hoehe_MinGas = 30;
358
        EE_Parameter.Hoehe_MinGas = 30;
360
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
359
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
361
        EE_Parameter.Hoehe_P      = 10;          // Wert : 0-32
360
        EE_Parameter.Hoehe_P      = 10;          // Wert : 0-32
362
        EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
361
        EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
363
        EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
362
        EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
364
        EE_Parameter.Hoehe_HoverBand = 5;         // Wert : 0-247
363
        EE_Parameter.Hoehe_HoverBand = 5;         // Wert : 0-247
365
        EE_Parameter.Hoehe_GPS_Z = 64;           // Wert : 0-247
364
        EE_Parameter.Hoehe_GPS_Z = 64;           // Wert : 0-247
366
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
365
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
367
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50
366
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50
368
        EE_Parameter.Stick_P = 8;                // Wert : 1-6
367
        EE_Parameter.Stick_P = 8;                // Wert : 1-6
369
        EE_Parameter.Stick_D = 16;               // Wert : 0-64
368
        EE_Parameter.Stick_D = 16;               // Wert : 0-64
370
        EE_Parameter.Gier_P  = 6;                // Wert : 1-20
369
        EE_Parameter.Gier_P  = 6;                // Wert : 1-20
371
        EE_Parameter.Gas_Min = 8;                // Wert : 0-32
370
        EE_Parameter.Gas_Min = 8;                // Wert : 0-32
372
        EE_Parameter.Gas_Max = 230;              // Wert : 33-247
371
        EE_Parameter.Gas_Max = 230;              // Wert : 33-247
373
        EE_Parameter.KompassWirkung = 128;       // Wert : 0-247
372
        EE_Parameter.KompassWirkung = 128;       // Wert : 0-247
374
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
373
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
375
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
374
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
376
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
375
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
377
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
376
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
378
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
377
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
379
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
378
        EE_Parameter.NotGas = 35;                // Wert : 0-247     // Gaswert bei Empangsverlust
380
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
379
        EE_Parameter.NotGasZeit = 60;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
381
        EE_Parameter.I_Faktor = 16;
380
        EE_Parameter.I_Faktor = 16;
382
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
381
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
383
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
382
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
384
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
383
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
385
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
384
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
386
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
385
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
387
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
386
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
388
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
387
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
389
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
388
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
390
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
389
        EE_Parameter.ServoNickControl = 100;     // Wert : 0-247     // Stellung des Servos
391
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
390
        EE_Parameter.ServoNickComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
392
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
391
        EE_Parameter.ServoCompInvert = 1;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
393
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
392
        EE_Parameter.ServoNickMin = 0;           // Wert : 0-247     // Anschlag
394
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
393
        EE_Parameter.ServoNickMax = 247;         // Wert : 0-247     // Anschlag
395
        EE_Parameter.ServoNickRefresh = 6;
394
        EE_Parameter.ServoNickRefresh = 6;
396
        EE_Parameter.Servo3 = 125;
395
        EE_Parameter.Servo3 = 125;
397
        EE_Parameter.Servo4 = 125;
396
        EE_Parameter.Servo4 = 125;
398
        EE_Parameter.Servo5 = 125;
397
        EE_Parameter.Servo5 = 125;
399
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
398
        EE_Parameter.ServoRollControl = 100;     // Wert : 0-247     // Stellung des Servos
400
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
399
        EE_Parameter.ServoRollComp = 40;         // Wert : 0-247     // Einfluss Gyro/Servo
401
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
400
        EE_Parameter.ServoRollMin = 0;           // Wert : 0-247     // Anschlag
402
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
401
        EE_Parameter.ServoRollMax = 247;         // Wert : 0-247     // Anschlag
403
        EE_Parameter.LoopGasLimit = 50;
402
        EE_Parameter.LoopGasLimit = 50;
404
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
403
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
405
        EE_Parameter.LoopHysterese = 50;
404
        EE_Parameter.LoopHysterese = 50;
406
        EE_Parameter.BitConfig = 0;               // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
405
        EE_Parameter.BitConfig = 0;               // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
407
        EE_Parameter.AchsKopplung1 = 90;
406
        EE_Parameter.AchsKopplung1 = 90;
408
        EE_Parameter.AchsKopplung2 = 80;
407
        EE_Parameter.AchsKopplung2 = 80;
409
        EE_Parameter.CouplingYawCorrection = 70;
408
        EE_Parameter.CouplingYawCorrection = 70;
410
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
409
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
411
        EE_Parameter.DynamicStability = 50;
410
        EE_Parameter.DynamicStability = 50;
412
        EE_Parameter.J16Bitmask = 95;
411
        EE_Parameter.J16Bitmask = 95;
413
        EE_Parameter.J17Bitmask = 243;
412
        EE_Parameter.J17Bitmask = 243;
414
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
413
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
415
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
414
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
416
        EE_Parameter.J16Timing = 30;
415
        EE_Parameter.J16Timing = 30;
417
        EE_Parameter.J17Timing = 30;
416
        EE_Parameter.J17Timing = 30;
418
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
417
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
419
        EE_Parameter.NaviGpsGain = 100;
418
        EE_Parameter.NaviGpsGain = 100;
420
        EE_Parameter.NaviGpsP = 90;
419
        EE_Parameter.NaviGpsP = 90;
421
        EE_Parameter.NaviGpsI = 90;
420
        EE_Parameter.NaviGpsI = 90;
422
        EE_Parameter.NaviGpsD = 90;
421
        EE_Parameter.NaviGpsD = 90;
423
        EE_Parameter.NaviGpsPLimit = 75;
422
        EE_Parameter.NaviGpsPLimit = 75;
424
        EE_Parameter.NaviGpsILimit = 75;
423
        EE_Parameter.NaviGpsILimit = 75;
425
        EE_Parameter.NaviGpsDLimit = 75;
424
        EE_Parameter.NaviGpsDLimit = 75;
426
        EE_Parameter.NaviGpsACC = 0;
425
        EE_Parameter.NaviGpsACC = 0;
427
        EE_Parameter.NaviGpsMinSat = 6;
426
        EE_Parameter.NaviGpsMinSat = 6;
428
        EE_Parameter.NaviStickThreshold = 8;
427
        EE_Parameter.NaviStickThreshold = 8;
429
        EE_Parameter.NaviWindCorrection = 90;
428
        EE_Parameter.NaviWindCorrection = 90;
430
        EE_Parameter.NaviSpeedCompensation = 30;
429
        EE_Parameter.NaviSpeedCompensation = 30;
431
        EE_Parameter.NaviOperatingRadius = 100;
430
        EE_Parameter.NaviOperatingRadius = 100;
432
        EE_Parameter.NaviAngleLimitation = 100;
431
        EE_Parameter.NaviAngleLimitation = 100;
433
        EE_Parameter.NaviPH_LoginTime = 4;
432
        EE_Parameter.NaviPH_LoginTime = 4;
434
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
433
        EE_Parameter.Receiver = RECEIVER_SPEKTRUM;
435
        memcpy(EE_Parameter.Name, "Beginner\0", 12);
434
        memcpy(EE_Parameter.Name, "Beginner\0", 12);
436
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
435
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
437
}
436
}
438
 
437
 
439
/***************************************************/
438
/***************************************************/
440
/*       Read Parameter from EEPROM as byte        */
439
/*       Read Parameter from EEPROM as byte        */
441
/***************************************************/
440
/***************************************************/
442
uint8_t GetParamByte(uint16_t param_id)
441
uint8_t GetParamByte(uint16_t param_id)
443
{
442
{
444
        return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id));
443
        return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id));
445
}
444
}
446
 
445
 
447
/***************************************************/
446
/***************************************************/
448
/*       Write Parameter to EEPROM as byte         */
447
/*       Write Parameter to EEPROM as byte         */
449
/***************************************************/
448
/***************************************************/
450
void SetParamByte(uint16_t param_id, uint8_t value)
449
void SetParamByte(uint16_t param_id, uint8_t value)
451
{
450
{
452
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
451
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
453
}
452
}
454
 
453
 
455
/***************************************************/
454
/***************************************************/
456
/*       Read Parameter from EEPROM as word        */
455
/*       Read Parameter from EEPROM as word        */
457
/***************************************************/
456
/***************************************************/
458
uint16_t GetParamWord(uint16_t param_id)
457
uint16_t GetParamWord(uint16_t param_id)
459
{
458
{
460
        return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id));
459
        return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id));
461
}
460
}
462
 
461
 
463
/***************************************************/
462
/***************************************************/
464
/*       Write Parameter to EEPROM as word         */
463
/*       Write Parameter to EEPROM as word         */
465
/***************************************************/
464
/***************************************************/
466
void SetParamWord(uint16_t param_id, uint16_t value)
465
void SetParamWord(uint16_t param_id, uint16_t value)
467
{
466
{
468
        eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
467
        eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
469
}
468
}
470
 
469
 
471
/***************************************************/
470
/***************************************************/
472
/*       Read Parameter Set from EEPROM            */
471
/*       Read Parameter Set from EEPROM            */
473
/***************************************************/
472
/***************************************************/
474
// number [1..5]
473
// number [1..5]
475
uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber)
474
uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber)
476
{
475
{
477
        uint8_t crc;
476
        uint8_t crc;
478
        uint16_t eeaddr;
477
        uint16_t eeaddr;
479
 
478
 
480
        // range the setnumber
479
        // range the setnumber
481
        if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
480
        if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
482
 
481
 
483
        // calculate eeprom addr
482
        // calculate eeprom addr
484
        eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1);
483
        eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1);
485
 
484
 
486
        // calculate checksum from eeprom
485
        // calculate checksum from eeprom
487
        crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1);
486
        crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1);
488
 
487
 
489
        // check crc
488
        // check crc
490
        if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0;
489
        if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0;
491
 
490
 
492
        // check revision
491
        // check revision
493
        if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0;
492
        if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0;
494
 
493
 
495
        // read paramset from eeprom
494
        // read paramset from eeprom
496
        eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
495
        eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
497
        LED_Init();
496
        LED_Init();
498
        return 1;
497
        return 1;
499
}
498
}
500
 
499
 
501
/***************************************************/
500
/***************************************************/
502
/*        Write Parameter Set to EEPROM            */
501
/*        Write Parameter Set to EEPROM            */
503
/***************************************************/
502
/***************************************************/
504
// number [1..5]
503
// number [1..5]
505
uint8_t ParamSet_WriteToEEProm(uint8_t setnumber)
504
uint8_t ParamSet_WriteToEEProm(uint8_t setnumber)
506
{
505
{
507
        uint8_t crc;
506
        uint8_t crc;
508
 
507
 
509
        if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom
508
        if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom
510
        {
509
        {
511
                if(setnumber > 5) setnumber = 5;
510
                if(setnumber > 5) setnumber = 5;
512
                if(setnumber < 1) return 0;
511
                if(setnumber < 1) return 0;
513
 
512
 
514
                // update checksum
513
                // update checksum
515
                EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
514
                EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
516
 
515
 
517
                // write paramset to eeprom
516
                // write paramset to eeprom
518
                eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
517
                eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
519
 
518
 
520
                // backup channel settings to separate block in eeprom
519
                // backup channel settings to separate block in eeprom
521
                eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
520
                eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
522
 
521
 
523
                // write crc of channel block to eeprom
522
                // write crc of channel block to eeprom
524
                crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung));
523
                crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung));
525
                eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc);
524
                eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc);
526
 
525
 
527
                // update active settings number
526
                // update active settings number
528
                SetActiveParamSet(setnumber);
527
                SetActiveParamSet(setnumber);
529
                LED_Init();
528
                LED_Init();
530
                return 1;
529
                return 1;
531
        }
530
        }
532
        // wrong revision
531
        // wrong revision
533
        return 0;
532
        return 0;
534
}
533
}
535
 
534
 
536
/***************************************************/
535
/***************************************************/
537
/*          Read MixerTable from EEPROM            */
536
/*          Read MixerTable from EEPROM            */
538
/***************************************************/
537
/***************************************************/
539
uint8_t MixerTable_ReadFromEEProm(void)
538
uint8_t MixerTable_ReadFromEEProm(void)
540
{
539
{
541
        uint8_t crc;
540
        uint8_t crc;
542
 
541
 
543
        // calculate checksum in eeprom
542
        // calculate checksum in eeprom
544
        crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1);
543
        crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1);
545
 
544
 
546
        // check crc
545
        // check crc
547
        if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0;
546
        if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0;
548
 
547
 
549
        // check revision
548
        // check revision
550
        if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0;
549
        if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0;
551
 
550
 
552
        // read mixer table
551
        // read mixer table
553
        eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
552
        eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
554
        return 1;
553
        return 1;
555
}
554
}
556
 
555
 
557
/***************************************************/
556
/***************************************************/
558
/*          Write Mixer Table to EEPROM            */
557
/*          Write Mixer Table to EEPROM            */
559
/***************************************************/
558
/***************************************************/
560
uint8_t MixerTable_WriteToEEProm(void)
559
uint8_t MixerTable_WriteToEEProm(void)
561
{
560
{
562
        if(Mixer.Revision == EEMIXER_REVISION)
561
        if(Mixer.Revision == EEMIXER_REVISION)
563
        {
562
        {
564
                // update crc
563
                // update crc
565
                Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
564
                Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
566
 
565
 
567
                // write to eeprom
566
                // write to eeprom
568
                eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
567
                eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
569
                return 1;
568
                return 1;
570
        }
569
        }
571
        else return 0;
570
        else return 0;
572
}
571
}
573
 
572
 
574
/***************************************************/
573
/***************************************************/
575
/*    Default Values for Mixer Table               */
574
/*    Default Values for Mixer Table               */
576
/***************************************************/
575
/***************************************************/
577
void MixerTable_Default(void) // Quadro
576
void MixerTable_Default(void) // Quadro
578
{
577
{
579
        uint8_t i;
578
        uint8_t i;
580
 
579
 
581
        Mixer.Revision = EEMIXER_REVISION;
580
        Mixer.Revision = EEMIXER_REVISION;
582
        // clear mixer table
581
        // clear mixer table
583
        for(i = 0; i < 16; i++)
582
        for(i = 0; i < 16; i++)
584
        {
583
        {
585
                Mixer.Motor[i][MIX_GAS]  = 0;
584
                Mixer.Motor[i][MIX_GAS]  = 0;
586
                Mixer.Motor[i][MIX_NICK] = 0;
585
                Mixer.Motor[i][MIX_NICK] = 0;
587
                Mixer.Motor[i][MIX_ROLL] = 0;
586
                Mixer.Motor[i][MIX_ROLL] = 0;
588
                Mixer.Motor[i][MIX_YAW]  = 0;
587
                Mixer.Motor[i][MIX_YAW]  = 0;
589
        }
588
        }
590
        // default = Quadro
589
        // default = Quadro
591
        Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] =   0; Mixer.Motor[0][MIX_YAW] = +64;
590
        Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] =   0; Mixer.Motor[0][MIX_YAW] = +64;
592
        Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] =   0; Mixer.Motor[1][MIX_YAW] = +64;
591
        Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] =   0; Mixer.Motor[1][MIX_YAW] = +64;
593
        Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] =   0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64;
592
        Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] =   0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64;
594
        Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] =   0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64;
593
        Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] =   0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64;
595
        memcpy(Mixer.Name, "Quadro\0", 7);
594
        memcpy(Mixer.Name, "Quadro\0", 7);
596
        Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
595
        Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
597
}
596
}
598
 
-
 
599
 
-
 
600
/***************************************************/
-
 
601
/*          Read BL-Config from EEPROM             */
-
 
602
/***************************************************/
-
 
603
uint8_t BLConfig_ReadFromEEProm(uint8_t index)
-
 
604
{
-
 
605
        uint8_t crc;
-
 
606
        uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t);
-
 
607
        // calculate checksum in eeprom
-
 
608
        crc = EEProm_Checksum(eeadr, sizeof(BLConfig_t) - 1);
-
 
609
 
-
 
610
        // check crc
-
 
611
        if( crc != eeprom_read_byte((uint8_t*)(eeadr + sizeof(BLConfig_t) - 1)) ) return 0;
-
 
612
 
-
 
613
        // check revision
-
 
614
        if(eeprom_read_byte((uint8_t*)(eeadr)) != EEBLCONFIG_REVISON) return 0;
-
 
615
 
-
 
616
        // read mixer BLConfig
-
 
617
        eeprom_read_block((void *)&(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t));
-
 
618
        return 1;
-
 
619
}
-
 
620
 
-
 
621
/***************************************************/
-
 
622
/*         Write BL-Config to EEPROM               */
-
 
623
/***************************************************/
-
 
624
uint8_t BLConfig_WriteToEEProm(uint8_t index)
-
 
625
{
-
 
626
        uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t);
-
 
627
        if(index >= MAX_MOTORS) return 0;
-
 
628
        if(BLConfig[index].Revision == EEBLCONFIG_REVISON)
-
 
629
        {
-
 
630
                // update crc
-
 
631
                BLConfig[index].crc = RAM_Checksum((uint8_t*)(&(BLConfig[index])), sizeof(BLConfig_t) - 1);
-
 
632
 
-
 
633
                // write to eeprom
-
 
634
                eeprom_write_block((void *) &(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t));
-
 
635
                return 1;
-
 
636
        }
-
 
637
        else return 0;
-
 
638
}
-
 
639
 
-
 
640
/***************************************************/
-
 
641
/*    Default BLConfig                             */
-
 
642
/***************************************************/
-
 
643
void BLConfig_SetDefault(uint8_t index)
-
 
644
{
-
 
645
        if(index < MAX_MOTORS)
-
 
646
        {
-
 
647
                BLConfig[index].Revision = EEBLCONFIG_REVISON; // set revision
-
 
648
                BLConfig[index].SetMask =       MASK_SET_PWM_SCALING|MASK_SET_CURRENT_LIMIT|MASK_SET_TEMP_LIMIT|MASK_SET_CURRENT_SCALING|MASK_SET_BITCONFIG;
-
 
649
                BLConfig[index].PwmScaling = 255;               // MaxPWM
-
 
650
                BLConfig[index].CurrentLimit = 30;              // Current Limit in A
-
 
651
                BLConfig[index].TempLimit = 99;                 // Temperature Limit in °C
-
 
652
                BLConfig[index].CurrentScaling = 64;    // Current Scaling
-
 
653
                BLConfig[index].BitConfig = 0;                  // BitConfig
-
 
654
                BLConfig[index].crc = RAM_Checksum((uint8_t*)&(BLConfig[index]), sizeof(BLConfig_t) - 1); // update checksum
-
 
655
        }
-
 
656
}
-
 
657
 
-
 
658
 
597
 
659
/***************************************************/
598
/***************************************************/
660
/*       Get active parameter set                  */
599
/*       Get active parameter set                  */
661
/***************************************************/
600
/***************************************************/
662
uint8_t GetActiveParamSet(void)
601
uint8_t GetActiveParamSet(void)
663
{
602
{
664
        uint8_t setnumber;
603
        uint8_t setnumber;
665
        setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET));
604
        setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET));
666
        if(setnumber > 5)
605
        if(setnumber > 5)
667
        {
606
        {
668
                setnumber = 3;
607
                setnumber = 3;
669
                eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber);
608
                eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber);
670
        }
609
        }
671
        return(setnumber);
610
        return(setnumber);
672
}
611
}
673
 
612
 
674
/***************************************************/
613
/***************************************************/
675
/*       Set active parameter set                  */
614
/*       Set active parameter set                  */
676
/***************************************************/
615
/***************************************************/
677
void SetActiveParamSet(uint8_t setnumber)
616
void SetActiveParamSet(uint8_t setnumber)
678
{
617
{
679
        if(setnumber > 5) setnumber = 5;
618
        if(setnumber > 5) setnumber = 5;
680
        if(setnumber < 1) setnumber = 1;
619
        if(setnumber < 1) setnumber = 1;
681
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber);
620
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber);
682
}
621
}
683
 
622
 
684
/***************************************************/
623
/***************************************************/
685
/*       Initialize EEPROM Parameter Sets          */
624
/*       Initialize EEPROM Parameter Sets          */
686
/***************************************************/
625
/***************************************************/
687
void ParamSet_Init(void)
626
void ParamSet_Init(void)
688
{
627
{
689
        uint8_t channel_backup  = 0, bad_params = 0, ee_default = 0,i;
628
        uint8_t channel_backup  = 0, bad_params = 0, ee_default = 0,i;
690
 
629
 
691
 
630
 
692
        if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) )
631
        if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) )
693
        {
632
        {
694
                ee_default = 1; // software update or forced by mktool
633
                ee_default = 1; // software update or forced by mktool
695
                SetParamByte(PID_EE_REVISION, EEPARAM_REVISION);
634
                SetParamByte(PID_EE_REVISION, EEPARAM_REVISION);
696
        }
635
        }
697
 
636
 
698
 
637
 
699
        // 1st check for a valid channel backup in eeprom
638
        // 1st check for a valid channel backup in eeprom
700
        i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
639
        i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
701
        if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1;
640
        if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1;
702
 
641
 
703
 
642
 
704
        // parameter check
643
        // parameter check
705
 
644
 
706
        // check all 5 parameter settings
645
        // check all 5 parameter settings
707
        for (i = 1;i < 6; i++)
646
        for (i = 1;i < 6; i++)
708
        {
647
        {
709
                if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom
648
                if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom
710
                {
649
                {
711
                        bad_params = 1;
650
                        bad_params = 1;
712
                        printf("\n\rGenerating default Parameter Set %d",i);
651
                        printf("\n\rGenerating default Parameter Set %d",i);
713
                        switch(i)
652
                        switch(i)
714
                        {
653
                        {
715
                                case 1:
654
                                case 1:
716
                                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
655
                                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
717
                                        break;
656
                                        break;
718
                                case 2:
657
                                case 2:
719
                                        ParamSet_DefaultSet2(); // Kamera
658
                                        ParamSet_DefaultSet2(); // Kamera
720
                                        break;
659
                                        break;
721
                                case 3:
660
                                case 3:
722
                                        ParamSet_DefaultSet3(); // Beginner
661
                                        ParamSet_DefaultSet3(); // Beginner
723
                                        break;
662
                                        break;
724
                                default:
663
                                default:
725
                                        ParamSet_DefaultSet2(); // Kamera
664
                                        ParamSet_DefaultSet2(); // Kamera
726
                                        break;
665
                                        break;
727
                        }
666
                        }
728
                        if(channel_backup) // if we have an channel mapping backup in eeprom
667
                        if(channel_backup) // if we have an channel mapping backup in eeprom
729
                        {       // restore it from eeprom
668
                        {       // restore it from eeprom
730
                                eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
669
                                eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
731
                        }
670
                        }
732
                        else
671
                        else
733
                        {       // use default mapping
672
                        {       // use default mapping
734
                                ParamSet_DefaultStickMapping();
673
                                ParamSet_DefaultStickMapping();
735
                        }
674
                        }
736
                        ParamSet_WriteToEEProm(i);
675
                        ParamSet_WriteToEEProm(i);
737
                }
676
                }
738
        }
677
        }
739
        if(bad_params) // at least one of the parameter settings were invalid
678
        if(bad_params) // at least one of the parameter settings were invalid
740
        {
679
        {
741
                // default-Setting is parameter set 3
680
                // default-Setting is parameter set 3
742
                SetActiveParamSet(3);
681
                SetActiveParamSet(3);
743
        }
682
        }
744
 
683
 
745
 
684
 
746
        // read active parameter set to ParamSet stucture
685
        // read active parameter set to ParamSet stucture
747
        i = GetActiveParamSet();
686
        i = GetActiveParamSet();
748
        ParamSet_ReadFromEEProm(i);
687
        ParamSet_ReadFromEEProm(i);
749
        printf("\n\rUsing Parameter Set %d", i);
688
        printf("\n\rUsing Parameter Set %d", i);
750
 
-
 
751
        // load all BLConfig's
-
 
752
        for(i=0; i<MAX_MOTORS; i++)
-
 
753
        {
-
 
754
                if(ee_default || !BLConfig_ReadFromEEProm(i)) // could not read BLConfig from eeprom
-
 
755
                {
-
 
756
                        printf("\n\rGenerating default BL-Config for motor %d", i+1);
-
 
757
                        BLConfig_SetDefault(i);
-
 
758
                        BLConfig_WriteToEEProm(i);
-
 
759
                }
-
 
760
        }
-
 
761
 
689
 
762
        // load mixer table
690
        // load mixer table
763
        if(ee_default || !MixerTable_ReadFromEEProm() )
691
        if(ee_default || !MixerTable_ReadFromEEProm() )
764
        {
692
        {
765
                printf("\n\rGenerating default Mixer Table");
693
                printf("\n\rGenerating default Mixer Table");
766
                MixerTable_Default(); // Quadro
694
                MixerTable_Default(); // Quadro
767
                MixerTable_WriteToEEProm();
695
                MixerTable_WriteToEEProm();
768
        }
696
        }
769
        // determine motornumber
697
        // determine motornumber
770
        RequiredMotors = 0;
698
        RequiredMotors = 0;
771
        for(i = 0; i < 16; i++)
699
        for(i = 0; i < 16; i++)
772
        {
700
        {
773
                if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++;
701
                if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++;
774
        }
702
        }
775
 
703
 
776
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
704
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
777
        printf("\n\r==============================");
705
        printf("\n\r==============================");
778
}
706
}
779
 
707