Subversion Repositories FlightCtrl

Rev

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

Rev 2316 Rev 2318
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// + Software Nutzungsbedingungen (english version: see below)
4
// + Software Nutzungsbedingungen (english version: see below)
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
19
// + des Mitverschuldens offen.
19
// + des Mitverschuldens offen.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
34
// + The Software may only be used with the Licensor's products.
34
// + The Software may only be used with the Licensor's products.
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
37
// + agreement shall be the property of the Licensor.
37
// + agreement shall be the property of the Licensor.
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
40
// + The customer shall be responsible for taking reasonable precautions
40
// + The customer shall be responsible for taking reasonable precautions
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
 
53
 
54
 
54
 
55
#ifndef EEMEM
55
#ifndef EEMEM
56
#define EEMEM __attribute__ ((section (".eeprom")))
56
#define EEMEM __attribute__ ((section (".eeprom")))
57
#endif
57
#endif
58
 
58
 
59
 
59
 
60
#include <avr/eeprom.h>
60
#include <avr/eeprom.h>
61
#include <string.h>
61
#include <string.h>
62
#include "eeprom.h"
62
#include "eeprom.h"
63
#include "uart.h"
63
#include "uart.h"
64
#include "led.h"
64
#include "led.h"
65
#include "main.h"
65
#include "main.h"
66
#include "fc.h"
66
#include "fc.h"
67
#include "twimaster.h"
67
#include "twimaster.h"
68
 
68
 
69
paramset_t              EE_Parameter;
69
paramset_t              EE_Parameter;
70
MixerTable_t    Mixer;
70
MixerTable_t    Mixer;
71
uint8_t RequiredMotors;
71
uint8_t RequiredMotors;
72
 
72
 
73
 
73
 
74
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len)
74
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len)
75
{
75
{
76
        uint8_t crc = 0xAA;
76
        uint8_t crc = 0xAA;
77
        uint16_t i;
77
        uint16_t i;
78
 
78
 
79
        for(i=0; i<len; i++)
79
        for(i=0; i<len; i++)
80
        {
80
        {
81
                crc += pBuffer[i];
81
                crc += pBuffer[i];
82
        }
82
        }
83
        return crc;
83
        return crc;
84
}
84
}
85
 
85
 
86
uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len)
86
uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len)
87
{
87
{
88
        uint8_t crc = 0xAA;
88
        uint8_t crc = 0xAA;
89
        uint16_t off;
89
        uint16_t off;
90
 
90
 
91
        for(off=0; off<len; off++)
91
        for(off=0; off<len; off++)
92
        {
92
        {
93
                crc += eeprom_read_byte((uint8_t*)(EEAddr + off));;
93
                crc += eeprom_read_byte((uint8_t*)(EEAddr + off));;
94
        }
94
        }
95
        return crc;
95
        return crc;
96
}
96
}
97
 
97
 
98
void ParamSet_DefaultStickMapping(void)
98
void ParamSet_DefaultStickMapping(void)
99
{
99
{
100
        EE_Parameter.Kanalbelegung[K_GAS]   = 1;
100
        EE_Parameter.Kanalbelegung[K_GAS]   = 1;
101
        EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
101
        EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
102
        EE_Parameter.Kanalbelegung[K_NICK]  = 3;
102
        EE_Parameter.Kanalbelegung[K_NICK]  = 3;
103
        EE_Parameter.Kanalbelegung[K_GIER]  = 4;
103
        EE_Parameter.Kanalbelegung[K_GIER]  = 4;
104
        EE_Parameter.Kanalbelegung[K_POTI1] = 5;
104
        EE_Parameter.Kanalbelegung[K_POTI1] = 5;
105
        EE_Parameter.Kanalbelegung[K_POTI2] = 6;
105
        EE_Parameter.Kanalbelegung[K_POTI2] = 6;
106
        EE_Parameter.Kanalbelegung[K_POTI3] = 7;
106
        EE_Parameter.Kanalbelegung[K_POTI3] = 7;
107
        EE_Parameter.Kanalbelegung[K_POTI4] = 8;
107
        EE_Parameter.Kanalbelegung[K_POTI4] = 8;
108
        EE_Parameter.Kanalbelegung[K_POTI5] = 9;
108
        EE_Parameter.Kanalbelegung[K_POTI5] = 9;
109
        EE_Parameter.Kanalbelegung[K_POTI6] = 10;
109
        EE_Parameter.Kanalbelegung[K_POTI6] = 10;
110
        EE_Parameter.Kanalbelegung[K_POTI7] = 11;
110
        EE_Parameter.Kanalbelegung[K_POTI7] = 11;
111
        EE_Parameter.Kanalbelegung[K_POTI8] = 12;
111
        EE_Parameter.Kanalbelegung[K_POTI8] = 12;
112
}
112
}
113
 
113
 
114
 
114
 
115
/***************************************************/
115
/***************************************************/
116
/*    Default Values for parameter set 1           */
116
/*    Default Values for parameter set 1           */
117
/***************************************************/
117
/***************************************************/
118
void CommonDefaults(void)
118
void CommonDefaults(void)
119
{
119
{
120
        EE_Parameter.Revision = EEPARAM_REVISION;
120
        EE_Parameter.Revision = EEPARAM_REVISION;
121
        memset(EE_Parameter.Name,0,12); // delete name
121
        memset(EE_Parameter.Name,0,12); // delete name
122
        if(PlatinenVersion >= 20)
122
        if(PlatinenVersion >= 20)
123
        {
123
        {
124
                EE_Parameter.Gyro_D = 10;
124
                EE_Parameter.Gyro_D = 10;
125
                EE_Parameter.Driftkomp = 0;
125
                EE_Parameter.Driftkomp = 0;
126
                EE_Parameter.GyroAccFaktor = 27;
126
                EE_Parameter.GyroAccFaktor = 27;
127
                EE_Parameter.WinkelUmschlagNick = 78;
127
                EE_Parameter.WinkelUmschlagNick = 78;
128
                EE_Parameter.WinkelUmschlagRoll = 78;
128
                EE_Parameter.WinkelUmschlagRoll = 78;
129
        }
129
        }
130
        else
130
        else
131
        {
131
        {
132
                EE_Parameter.Gyro_D = 3;
132
                EE_Parameter.Gyro_D = 3;
133
                EE_Parameter.Driftkomp = 32;
133
                EE_Parameter.Driftkomp = 32;
134
                EE_Parameter.GyroAccFaktor = 30;
134
                EE_Parameter.GyroAccFaktor = 30;
135
                EE_Parameter.WinkelUmschlagNick = 85;
135
                EE_Parameter.WinkelUmschlagNick = 85;
136
                EE_Parameter.WinkelUmschlagRoll = 85;
136
                EE_Parameter.WinkelUmschlagRoll = 85;
137
        }
137
        }
138
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
138
        EE_Parameter.GyroAccAbgleich = 32;        // 1/k
139
        EE_Parameter.BitConfig = 0;              // Looping usw.
139
        EE_Parameter.BitConfig = 0;              // Looping usw.
140
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
140
        EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER;
141
        EE_Parameter.ExtraConfig = CFG_GPS_AID | CFG2_VARIO_BEEP;
141
        EE_Parameter.ExtraConfig = CFG_GPS_AID | CFG2_VARIO_BEEP;
142
        EE_Parameter.GlobalConfig3 = CFG3_SPEAK_ALL;//CFG3_VARIO_FAILSAFE; 
142
        EE_Parameter.GlobalConfig3 = CFG3_SPEAK_ALL;//CFG3_VARIO_FAILSAFE; 
143
        EE_Parameter.Receiver = RECEIVER_HOTT;
143
        EE_Parameter.Receiver = RECEIVER_HOTT;
144
        EE_Parameter.MotorSafetySwitch = 0;
144
        EE_Parameter.MotorSafetySwitch = 0;
145
        EE_Parameter.ExternalControl = 0;
145
        EE_Parameter.ExternalControl = 0;
146
 
146
 
147
        EE_Parameter.Gas_Min = 8;             // Wert : 0-32
147
        EE_Parameter.Gas_Min = 8;             // Wert : 0-32
148
        EE_Parameter.Gas_Max = 230;           // Wert : 33-247
148
        EE_Parameter.Gas_Max = 230;           // Wert : 33-247
149
        EE_Parameter.KompassWirkung = 64;    // Wert : 0-247
149
        EE_Parameter.KompassWirkung = 64;    // Wert : 0-247
150
 
150
 
151
        EE_Parameter.Hoehe_MinGas = 30;
151
        EE_Parameter.Hoehe_MinGas = 30;
152
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
152
        EE_Parameter.MaxHoehe     = 255;         // Wert : 0-247   255 -> Poti1
153
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
153
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
154
        if(ACC_AltitudeControl)
154
        if(ACC_AltitudeControl)
155
        {
155
        {
156
                EE_Parameter.Hoehe_P      = 20;          // Wert : 0-32
156
                EE_Parameter.Hoehe_P      = 20;          // Wert : 0-32
157
                EE_Parameter.Luftdruck_D  = 40;          // Wert : 0-247
157
                EE_Parameter.Luftdruck_D  = 40;          // Wert : 0-247
158
                EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
158
                EE_Parameter.Hoehe_ACC_Wirkung = 30;     // Wert : 0-247
159
                EE_Parameter.Hoehe_HoverBand = 1;         // Wert : 0-247
159
                EE_Parameter.Hoehe_HoverBand = 1;         // Wert : 0-247
160
                EE_Parameter.Hoehe_GPS_Z = 0;           // Wert : 0-247
160
                EE_Parameter.Hoehe_GPS_Z = 0;           // Wert : 0-247
161
        }
161
        }
162
        else
162
        else
163
#endif
163
#endif
164
        {
164
        {
165
                EE_Parameter.Hoehe_P      = 15;          // Wert : 0-32
165
                EE_Parameter.Hoehe_P      = 15;          // Wert : 0-32
166
                EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
166
                EE_Parameter.Luftdruck_D  = 30;          // Wert : 0-247
167
                EE_Parameter.Hoehe_ACC_Wirkung = 0;     // Wert : 0-247
167
                EE_Parameter.Hoehe_ACC_Wirkung = 0;     // Wert : 0-247
168
                EE_Parameter.Hoehe_HoverBand = 8;         // Wert : 0-247
168
                EE_Parameter.Hoehe_HoverBand = 8;         // Wert : 0-247
169
                EE_Parameter.Hoehe_GPS_Z = 20;           // Wert : 0-247
169
                EE_Parameter.Hoehe_GPS_Z = 20;           // Wert : 0-247
170
        }
170
        }
171
       
171
       
172
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
172
        EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation)
173
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50 (15 -> ca. +/- 5m/sek bei Stick-Voll-Ausschlag)
173
        EE_Parameter.Hoehe_Verstaerkung = 15;    // Wert : 0-50 (15 -> ca. +/- 5m/sek bei Stick-Voll-Ausschlag)
174
 
174
 
175
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
175
        EE_Parameter.UserParam1 =   0;           // zur freien Verwendung
176
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
176
        EE_Parameter.UserParam2 =   0;           // zur freien Verwendung
177
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
177
        EE_Parameter.UserParam3 =   0;           // zur freien Verwendung
178
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
178
        EE_Parameter.UserParam4 =   0;           // zur freien Verwendung
179
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
179
        EE_Parameter.UserParam5 =   0;           // zur freien Verwendung
180
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
180
        EE_Parameter.UserParam6 =   0;           // zur freien Verwendung
181
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
181
        EE_Parameter.UserParam7 = 0;             // zur freien Verwendung
182
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
182
        EE_Parameter.UserParam8 = 0;             // zur freien Verwendung
183
 
183
 
184
        EE_Parameter.ServoNickControl = 128;     // Wert : 0-247     // Stellung des Servos
184
        EE_Parameter.ServoNickControl = 128;     // Wert : 0-247     // Stellung des Servos
185
        EE_Parameter.ServoNickComp = 50;         // Wert : 0-247     // Einfluss Gyro/Servo
185
        EE_Parameter.ServoNickComp = 50;         // Wert : 0-247     // Einfluss Gyro/Servo
186
        EE_Parameter.ServoCompInvert = 2;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
186
        EE_Parameter.ServoCompInvert = 2;        // Wert : 0-247     // Richtung Einfluss Gyro/Servo
187
        EE_Parameter.ServoNickMin = 15;          // Wert : 0-247     // Anschlag
187
        EE_Parameter.ServoNickMin = 15;          // Wert : 0-247     // Anschlag
188
        EE_Parameter.ServoNickMax = 230;         // Wert : 0-247     // Anschlag
188
        EE_Parameter.ServoNickMax = 230;         // Wert : 0-247     // Anschlag
189
        EE_Parameter.ServoNickRefresh = 4;
189
        EE_Parameter.ServoNickRefresh = 4;
190
        EE_Parameter.Servo3 = 125;
190
        EE_Parameter.Servo3 = 125;
191
        EE_Parameter.Servo4 = 125;
191
        EE_Parameter.Servo4 = 125;
192
        EE_Parameter.Servo5 = 125;
192
        EE_Parameter.Servo5 = 125;
193
        EE_Parameter.ServoRollControl = 128;     // Wert : 0-247     // Stellung des Servos
193
        EE_Parameter.ServoRollControl = 128;     // Wert : 0-247     // Stellung des Servos
194
        EE_Parameter.ServoRollComp = 85;         // Wert : 0-247     // Einfluss Gyro/Servo
194
        EE_Parameter.ServoRollComp = 85;         // Wert : 0-247     // Einfluss Gyro/Servo
195
        EE_Parameter.ServoRollMin = 70;          // Wert : 0-247     // Anschlag
195
        EE_Parameter.ServoRollMin = 70;          // Wert : 0-247     // Anschlag
196
        EE_Parameter.ServoRollMax = 220;         // Wert : 0-247     // Anschlag
196
        EE_Parameter.ServoRollMax = 220;         // Wert : 0-247     // Anschlag
197
        EE_Parameter.ServoManualControlSpeed = 60;
197
        EE_Parameter.ServoManualControlSpeed = 60;
198
        EE_Parameter.CamOrientation = 0;         // Wert : 0-24 -> 0-360 -> 15° steps
198
        EE_Parameter.CamOrientation = 0;         // Wert : 0-24 -> 0-360 -> 15° steps
199
 
199
 
200
        EE_Parameter.J16Bitmask = 95;
200
        EE_Parameter.J16Bitmask = 95;
201
        EE_Parameter.J17Bitmask = 243;
201
        EE_Parameter.J17Bitmask = 243;
202
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
202
        EE_Parameter.WARN_J16_Bitmask = 0xAA;
203
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
203
        EE_Parameter.WARN_J17_Bitmask = 0xAA;
204
        EE_Parameter.J16Timing = 40;
204
        EE_Parameter.J16Timing = 40;
205
        EE_Parameter.J17Timing = 40;
205
        EE_Parameter.J17Timing = 40;
206
    EE_Parameter.NaviOut1Parameter = 0;       // Photo release in meter
206
    EE_Parameter.NaviOut1Parameter = 0;       // Photo release in meter
207
        EE_Parameter.LoopGasLimit = 50;
207
        EE_Parameter.LoopGasLimit = 50;
208
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
208
        EE_Parameter.LoopThreshold = 90;         // Wert: 0-247  Schwelle für Stickausschlag
209
        EE_Parameter.LoopHysterese = 50;
209
        EE_Parameter.LoopHysterese = 50;
210
 
210
 
211
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
211
        EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2
212
        EE_Parameter.NaviGpsGain = 100;
212
        EE_Parameter.NaviGpsGain = 100;
213
        EE_Parameter.NaviGpsP = 90;
213
        EE_Parameter.NaviGpsP = 90;
214
        EE_Parameter.NaviGpsI = 90;
214
        EE_Parameter.NaviGpsI = 90;
215
        EE_Parameter.NaviGpsD = 90;
215
        EE_Parameter.NaviGpsD = 90;
216
        EE_Parameter.NaviGpsPLimit = 75;
216
        EE_Parameter.NaviGpsPLimit = 75;
217
        EE_Parameter.NaviGpsILimit = 85;
217
        EE_Parameter.NaviGpsILimit = 85;
218
        EE_Parameter.NaviGpsDLimit = 75;
218
        EE_Parameter.NaviGpsDLimit = 75;
219
        EE_Parameter.NaviGpsACC = 0;
219
        EE_Parameter.NaviGpsACC = 0;
220
        EE_Parameter.NaviGpsMinSat = 6;
220
        EE_Parameter.NaviGpsMinSat = 6;
221
        EE_Parameter.NaviStickThreshold = 8;
221
        EE_Parameter.NaviStickThreshold = 8;
222
        EE_Parameter.NaviWindCorrection = 90;
222
        EE_Parameter.NaviWindCorrection = 90;
223
        EE_Parameter.NaviAccCompensation = 42;
223
        EE_Parameter.NaviAccCompensation = 42;
224
        EE_Parameter.NaviOperatingRadius = 245;
224
        EE_Parameter.NaviOperatingRadius = 245;
225
        EE_Parameter.NaviAngleLimitation = 140;
225
        EE_Parameter.NaviAngleLimitation = 140;
226
        EE_Parameter.NaviPH_LoginTime = 5;
226
        EE_Parameter.NaviPH_LoginTime = 5;
227
        EE_Parameter.OrientationAngle = 0;
227
        EE_Parameter.OrientationAngle = 0;
228
        EE_Parameter.CareFreeModeControl = 0;
228
        EE_Parameter.CareFreeModeControl = 0;
229
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
229
        EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50)
230
        EE_Parameter.NotGas = 65;                // Wert : 0-247     // Gaswert bei Empangsverlust (ggf. in Prozent)
230
        EE_Parameter.NotGas = 65;                // Wert : 0-247     // Gaswert bei Empangsverlust (ggf. in Prozent)
231
        EE_Parameter.NotGasZeit = 90;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
231
        EE_Parameter.NotGasZeit = 90;            // Wert : 0-247     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
232
        EE_Parameter.MotorSmooth = 0;          
232
        EE_Parameter.MotorSmooth = 0;          
233
        EE_Parameter.ComingHomeAltitude = 0;      // 0 = don't change 
233
        EE_Parameter.ComingHomeAltitude = 0;      // 0 = don't change 
234
        EE_Parameter.FailSafeTime = 0;            // 0 = off
234
        EE_Parameter.FailSafeTime = 0;            // 0 = off
235
        EE_Parameter.MaxAltitude = 150;           // 0 = off
235
        EE_Parameter.MaxAltitude = 150;           // 0 = off
236
        EE_Parameter.AchsKopplung1 = 125;
236
        EE_Parameter.AchsKopplung1 = 125;
237
        EE_Parameter.AchsKopplung2 = 52;
237
        EE_Parameter.AchsKopplung2 = 52;
238
        EE_Parameter.FailsafeChannel = 0;
238
        EE_Parameter.FailsafeChannel = 0;
239
        EE_Parameter.ServoFilterNick = 0;
239
        EE_Parameter.ServoFilterNick = 0;
240
        EE_Parameter.ServoFilterRoll = 0;
240
        EE_Parameter.ServoFilterRoll = 0;
241
}
241
}
242
/*
242
/*
243
void ParamSet_DefaultSet1(void) // sport
243
void ParamSet_DefaultSet1(void) // sport
244
{
244
{
245
        CommonDefaults();
245
        CommonDefaults();
246
        EE_Parameter.Stick_P = 14;            // Wert : 1-20
246
        EE_Parameter.Stick_P = 14;            // Wert : 1-20
247
        EE_Parameter.Stick_D = 16;            // Wert : 0-20
247
        EE_Parameter.Stick_D = 16;            // Wert : 0-20
248
        EE_Parameter.StickGier_P = 12;             // Wert : 1-20
248
        EE_Parameter.StickGier_P = 12;             // Wert : 1-20
249
        EE_Parameter.Gyro_P = 80;             // Wert : 0-247
249
        EE_Parameter.Gyro_P = 80;             // Wert : 0-247
250
        EE_Parameter.Gyro_I = 150;            // Wert : 0-247
250
        EE_Parameter.Gyro_I = 150;            // Wert : 0-247
251
        EE_Parameter.Gyro_Gier_P = 80;        // Wert : 0-247
251
        EE_Parameter.Gyro_Gier_P = 80;        // Wert : 0-247
252
        EE_Parameter.Gyro_Gier_I = 150;       // Wert : 0-247
252
        EE_Parameter.Gyro_Gier_I = 150;       // Wert : 0-247
253
        EE_Parameter.Gyro_Stability = 6;          // Wert : 1-8
253
        EE_Parameter.Gyro_Stability = 6;          // Wert : 1-8
254
        EE_Parameter.I_Faktor = 32;
254
        EE_Parameter.I_Faktor = 32;
255
        EE_Parameter.CouplingYawCorrection = 1;
255
        EE_Parameter.CouplingYawCorrection = 1;
256
        EE_Parameter.GyroAccAbgleich = 16;        // 1/k;
256
        EE_Parameter.GyroAccAbgleich = 16;        // 1/k;
257
        EE_Parameter.DynamicStability = 100;
257
        EE_Parameter.DynamicStability = 100;
258
        memcpy(EE_Parameter.Name, "Sport\0", 12);
258
        memcpy(EE_Parameter.Name, "Sport\0", 12);
259
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
259
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
260
}
260
}
261
*/
261
*/
262
 
262
 
263
/***************************************************/
263
/***************************************************/
264
/*    Default Values for parameter set 1           */
264
/*    Default Values for parameter set 1           */
265
/***************************************************/
265
/***************************************************/
266
void ParamSet_DefaultSet1(void) // normal
266
void ParamSet_DefaultSet1(void) // normal
267
{
267
{
268
        CommonDefaults();
268
        CommonDefaults();
269
        EE_Parameter.Stick_P = 10;               // Wert : 1-20
269
        EE_Parameter.Stick_P = 10;               // Wert : 1-20
270
        EE_Parameter.Stick_D = 16;               // Wert : 0-20
270
        EE_Parameter.Stick_D = 16;               // Wert : 0-20
271
        EE_Parameter.StickGier_P = 6;                 // Wert : 1-20
271
        EE_Parameter.StickGier_P = 6;                 // Wert : 1-20
272
        EE_Parameter.Gyro_P = 90;                // Wert : 0-247
272
        EE_Parameter.Gyro_P = 90;                // Wert : 0-247
273
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
273
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
274
        EE_Parameter.Gyro_Gier_P = 90;           // Wert : 0-247
274
        EE_Parameter.Gyro_Gier_P = 90;           // Wert : 0-247
275
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
275
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
276
        EE_Parameter.Gyro_Stability = 6;                  // Wert : 1-8
276
        EE_Parameter.Gyro_Stability = 6;                  // Wert : 1-8
277
        EE_Parameter.I_Faktor = 32;
277
        EE_Parameter.I_Faktor = 32;
278
        EE_Parameter.CouplingYawCorrection = 60;
278
        EE_Parameter.CouplingYawCorrection = 60;
279
        EE_Parameter.DynamicStability = 75;
279
        EE_Parameter.DynamicStability = 75;
280
        memcpy(EE_Parameter.Name, "Fast",4);
280
        memcpy(EE_Parameter.Name, "Fast",4);
281
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
281
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
282
}
282
}
283
 
283
 
284
 
284
 
285
/***************************************************/
285
/***************************************************/
286
/*    Default Values for parameter set 2           */
286
/*    Default Values for parameter set 2           */
287
/***************************************************/
287
/***************************************************/
288
void ParamSet_DefaultSet2(void) // beginner
288
void ParamSet_DefaultSet2(void) // beginner
289
{
289
{
290
        CommonDefaults();
290
        CommonDefaults();
291
        EE_Parameter.Stick_P = 8;                // Wert : 1-20
291
        EE_Parameter.Stick_P = 8;                // Wert : 1-20
292
        EE_Parameter.Stick_D = 16;               // Wert : 0-20
292
        EE_Parameter.Stick_D = 16;               // Wert : 0-20
293
        EE_Parameter.StickGier_P  = 6;                // Wert : 1-20
293
        EE_Parameter.StickGier_P  = 6;                // Wert : 1-20
294
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
294
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
295
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
295
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
296
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
296
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
297
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
297
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
298
        EE_Parameter.Gyro_Stability = 6;                  // Wert : 1-8
298
        EE_Parameter.Gyro_Stability = 6;                  // Wert : 1-8
299
        EE_Parameter.I_Faktor = 16;
299
        EE_Parameter.I_Faktor = 16;
300
        EE_Parameter.CouplingYawCorrection = 70;
300
        EE_Parameter.CouplingYawCorrection = 70;
301
        EE_Parameter.DynamicStability = 70;
301
        EE_Parameter.DynamicStability = 70;
302
        memcpy(EE_Parameter.Name, "Normal",6);
302
        memcpy(EE_Parameter.Name, "Normal",6);
303
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
303
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
304
}
304
}
305
 
305
 
306
/***************************************************/
306
/***************************************************/
307
/*    Default Values for parameter set 3           */
307
/*    Default Values for parameter set 3           */
308
/***************************************************/
308
/***************************************************/
309
void ParamSet_DefaultSet3(void) // beginner
309
void ParamSet_DefaultSet3(void) // beginner
310
{
310
{
311
        CommonDefaults();
311
        CommonDefaults();
312
        EE_Parameter.Stick_P = 6;                // Wert : 1-20
312
        EE_Parameter.Stick_P = 6;                // Wert : 1-20
313
        EE_Parameter.Stick_D = 10;               // Wert : 0-20
313
        EE_Parameter.Stick_D = 10;               // Wert : 0-20
314
        EE_Parameter.StickGier_P  = 4;           // Wert : 1-20
314
        EE_Parameter.StickGier_P  = 4;           // Wert : 1-20
315
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
315
        EE_Parameter.Gyro_P = 100;               // Wert : 0-247
316
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
316
        EE_Parameter.Gyro_I = 120;               // Wert : 0-247
317
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
317
        EE_Parameter.Gyro_Gier_P = 100;          // Wert : 0-247
318
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
318
        EE_Parameter.Gyro_Gier_I = 120;          // Wert : 0-247
319
        EE_Parameter.Gyro_Stability = 6;              // Wert : 1-8
319
        EE_Parameter.Gyro_Stability = 6;              // Wert : 1-8
320
        EE_Parameter.I_Faktor = 16;
320
        EE_Parameter.I_Faktor = 16;
321
        EE_Parameter.CouplingYawCorrection = 70;
321
        EE_Parameter.CouplingYawCorrection = 70;
322
        EE_Parameter.DynamicStability = 70;
322
        EE_Parameter.DynamicStability = 70;
323
        memcpy(EE_Parameter.Name, "Easy", 4);
323
        memcpy(EE_Parameter.Name, "Easy", 4);
324
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
324
        EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
325
}
325
}
326
 
326
 
327
 
327
 
328
/***************************************************/
328
/***************************************************/
329
/*       Read Parameter from EEPROM as byte        */
329
/*       Read Parameter from EEPROM as byte        */
330
/***************************************************/
330
/***************************************************/
331
uint8_t GetParamByte(uint16_t param_id)
331
uint8_t GetParamByte(uint16_t param_id)
332
{
332
{
333
        return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id));
333
        return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id));
334
}
334
}
335
 
335
 
336
/***************************************************/
336
/***************************************************/
337
/*       Write Parameter to EEPROM as byte         */
337
/*       Write Parameter to EEPROM as byte         */
338
/***************************************************/
338
/***************************************************/
339
void SetParamByte(uint16_t param_id, uint8_t value)
339
void SetParamByte(uint16_t param_id, uint8_t value)
340
{
340
{
341
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
341
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
342
}
342
}
343
 
343
 
344
/***************************************************/
344
/***************************************************/
345
/*       Read Parameter from EEPROM as word        */
345
/*       Read Parameter from EEPROM as word        */
346
/***************************************************/
346
/***************************************************/
347
uint16_t GetParamWord(uint16_t param_id)
347
uint16_t GetParamWord(uint16_t param_id)
348
{
348
{
349
        return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id));
349
        return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id));
350
}
350
}
351
 
351
 
352
/***************************************************/
352
/***************************************************/
353
/*       Write Parameter to EEPROM as word         */
353
/*       Write Parameter to EEPROM as word         */
354
/***************************************************/
354
/***************************************************/
355
void SetParamWord(uint16_t param_id, uint16_t value)
355
void SetParamWord(uint16_t param_id, uint16_t value)
356
{
356
{
357
        eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
357
        eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value);
358
}
358
}
359
 
359
 
360
/***************************************************/
360
/***************************************************/
361
/*       Read Parameter Set from EEPROM            */
361
/*       Read Parameter Set from EEPROM            */
362
/***************************************************/
362
/***************************************************/
363
// number [1..5]
363
// number [1..5]
364
uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber)
364
uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber)
365
{
365
{
366
        uint8_t crc;
366
        uint8_t crc;
367
        uint16_t eeaddr;
367
        uint16_t eeaddr;
368
 
368
 
369
        // range the setnumber
369
        // range the setnumber
370
        if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
370
        if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
371
 
371
 
372
        // calculate eeprom addr
372
        // calculate eeprom addr
373
        eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1);
373
        eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1);
374
 
374
 
375
        // calculate checksum from eeprom
375
        // calculate checksum from eeprom
376
        crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1);
376
        crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1);
377
 
377
 
378
        // check crc
378
        // check crc
379
        if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0;
379
        if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0;
380
 
380
 
381
        // check revision
381
        // check revision
382
        if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0;
382
        if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0;
383
 
383
 
384
        // read paramset from eeprom
384
        // read paramset from eeprom
385
        eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
385
        eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
386
        LED_Init();
386
        LED_Init();
387
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
387
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
388
        LIBFC_HoTT_Clear();
388
        LIBFC_HoTT_Clear();
389
#endif
389
#endif
390
        return 1;
390
        return 1;
391
}
391
}
392
 
392
 
393
/***************************************************/
393
/***************************************************/
394
/*        Write Parameter Set to EEPROM            */
394
/*        Write Parameter Set to EEPROM            */
395
/***************************************************/
395
/***************************************************/
396
// number [1..5]
396
// number [1..5]
397
uint8_t ParamSet_WriteToEEProm(uint8_t setnumber)
397
uint8_t ParamSet_WriteToEEProm(uint8_t setnumber)
398
{
398
{
399
        uint8_t crc;
399
        uint8_t crc;
400
 
400
 
401
        if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom
401
        if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom
402
        {
402
        {
403
                if(setnumber > 5) setnumber = 5;
403
                if(setnumber > 5) setnumber = 5;
404
                if(setnumber < 1) return 0;
404
                if(setnumber < 1) return 0;
405
        LIBFC_CheckSettings();
405
        LIBFC_CheckSettings();
406
                if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE)         // check the Setting: Not more than 100% emergency gas
406
                if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE)         // check the Setting: Not more than 100% emergency gas
407
                        {
407
                        {
408
                         if(EE_Parameter.NotGas > 99) EE_Parameter.NotGas = 80; // i.e. 80% of Hovergas
408
                         if(EE_Parameter.NotGas > 99) EE_Parameter.NotGas = 80; // i.e. 80% of Hovergas
409
                        }
409
                        }
410
                // update checksum
410
                // update checksum
411
                EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
411
                EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1);
412
 
412
 
413
                // write paramset to eeprom
413
                // write paramset to eeprom
414
                eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
414
                eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN);
415
 
415
 
416
                // backup channel settings to separate block in eeprom
416
                // backup channel settings to separate block in eeprom
417
                eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
417
                eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
418
 
418
 
419
                // write crc of channel block to eeprom
419
                // write crc of channel block to eeprom
420
                crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung));
420
                crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung));
421
                eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc);
421
                eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc);
422
 
422
 
423
                // update active settings number
423
                // update active settings number
424
                SetActiveParamSet(setnumber);
424
                SetActiveParamSet(setnumber);
425
                LED_Init();
425
                LED_Init();
426
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
426
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
427
                LIBFC_HoTT_Clear();
427
                LIBFC_HoTT_Clear();
428
#endif
428
#endif
429
                return 1;
429
                return 1;
430
        }
430
        }
431
        // wrong revision
431
        // wrong revision
432
        return 0;
432
        return 0;
433
}
433
}
434
 
434
 
435
/***************************************************/
435
/***************************************************/
436
/*          Read MixerTable from EEPROM            */
436
/*          Read MixerTable from EEPROM            */
437
/***************************************************/
437
/***************************************************/
438
uint8_t MixerTable_ReadFromEEProm(void)
438
uint8_t MixerTable_ReadFromEEProm(void)
439
{
439
{
440
        uint8_t crc;
440
        uint8_t crc;
441
 
441
 
442
        // calculate checksum in eeprom
442
        // calculate checksum in eeprom
443
        crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1);
443
        crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1);
444
 
444
 
445
        // check crc
445
        // check crc
446
        if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0;
446
        if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0;
447
 
447
 
448
        // check revision
448
        // check revision
449
        if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0;
449
        if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0;
450
 
450
 
451
        // read mixer table
451
        // read mixer table
452
        eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
452
        eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
453
        return 1;
453
        return 1;
454
}
454
}
455
 
455
 
456
/***************************************************/
456
/***************************************************/
457
/*          Write Mixer Table to EEPROM            */
457
/*          Write Mixer Table to EEPROM            */
458
/***************************************************/
458
/***************************************************/
459
uint8_t MixerTable_WriteToEEProm(void)
459
uint8_t MixerTable_WriteToEEProm(void)
460
{
460
{
461
        if(Mixer.Revision == EEMIXER_REVISION)
461
        if(Mixer.Revision == EEMIXER_REVISION)
462
        {
462
        {
463
                // update crc
463
                // update crc
464
                Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
464
                Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
465
 
465
 
466
                // write to eeprom
466
                // write to eeprom
467
                eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
467
                eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer));
468
                return 1;
468
                return 1;
469
        }
469
        }
470
        else return 0;
470
        else return 0;
471
}
471
}
472
 
472
 
473
/***************************************************/
473
/***************************************************/
474
/*    Default Values for Mixer Table               */
474
/*    Default Values for Mixer Table               */
475
/***************************************************/
475
/***************************************************/
476
void MixerTable_Default(void) // Quadro
476
void MixerTable_Default(void) // Quadro
477
{
477
{
478
        uint8_t i;
478
        uint8_t i;
479
 
479
 
480
        Mixer.Revision = EEMIXER_REVISION;
480
        Mixer.Revision = EEMIXER_REVISION;
481
        // clear mixer table
481
        // clear mixer table
482
        for(i = 0; i < 16; i++)
482
        for(i = 0; i < 16; i++)
483
        {
483
        {
484
                Mixer.Motor[i][MIX_GAS]  = 0;
484
                Mixer.Motor[i][MIX_GAS]  = 0;
485
                Mixer.Motor[i][MIX_NICK] = 0;
485
                Mixer.Motor[i][MIX_NICK] = 0;
486
                Mixer.Motor[i][MIX_ROLL] = 0;
486
                Mixer.Motor[i][MIX_ROLL] = 0;
487
                Mixer.Motor[i][MIX_YAW]  = 0;
487
                Mixer.Motor[i][MIX_YAW]  = 0;
488
        }
488
        }
489
        // default = Quadro
489
        // default = Quadro
490
        Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] =   0; Mixer.Motor[0][MIX_YAW] = +64;
490
        Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] =   0; Mixer.Motor[0][MIX_YAW] = +64;
491
        Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] =   0; Mixer.Motor[1][MIX_YAW] = +64;
491
        Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] =   0; Mixer.Motor[1][MIX_YAW] = +64;
492
        Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] =   0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64;
492
        Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] =   0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64;
493
        Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] =   0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64;
493
        Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] =   0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64;
494
        memcpy(Mixer.Name, "Quadro\0\0\0\0\0\0", 12);
494
        memcpy(Mixer.Name, "Quadro\0\0\0\0\0\0", 12);
495
        Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
495
        Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1);
496
}
496
}
497
 
497
 
498
/***************************************************/
498
/***************************************************/
499
/*       Get active parameter set                  */
499
/*       Get active parameter set                  */
500
/***************************************************/
500
/***************************************************/
501
uint8_t GetActiveParamSet(void)
501
uint8_t GetActiveParamSet(void)
502
{
502
{
503
        uint8_t setnumber;
503
        uint8_t setnumber;
504
        setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET));
504
        setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET));
505
        if(setnumber > 5)
505
        if(setnumber > 5)
506
        {
506
        {
507
                setnumber = 3;
507
                setnumber = 3;
508
                eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber);
508
                eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber);
509
        }
509
        }
510
        return(setnumber);
510
        return(setnumber);
511
}
511
}
512
 
512
 
513
/***************************************************/
513
/***************************************************/
514
/*       Set active parameter set                  */
514
/*       Set active parameter set                  */
515
/***************************************************/
515
/***************************************************/
516
void SetActiveParamSet(uint8_t setnumber)
516
void SetActiveParamSet(uint8_t setnumber)
517
{
517
{
518
        if(setnumber > 5) setnumber = 5;
518
        if(setnumber > 5) setnumber = 5;
519
        if(setnumber < 1) setnumber = 1;
519
        if(setnumber < 1) setnumber = 1;
520
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber);
520
        eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber);
521
}
521
}
522
 
522
 
523
/***************************************************/
523
/***************************************************/
524
/*       Set default parameter set                 */
524
/*       Set default parameter set                 */
525
/***************************************************/
525
/***************************************************/
526
void SetDefaultParameter(uint8_t set, uint8_t restore_channels)
526
void SetDefaultParameter(uint8_t set, uint8_t restore_channels)
527
{
527
{
528
 
528
 
529
        if(set > 5) set = 5;
529
        if(set > 5) set = 5;
530
        else if(set < 1) set = 1;
530
        else if(set < 1) set = 1;
531
 
531
 
532
        switch(set)
532
        switch(set)
533
        {
533
        {
534
                case 1:
534
                case 1:
535
                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
535
                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
536
                        break;
536
                        break;
537
                case 2:
537
                case 2:
538
                        ParamSet_DefaultSet2(); // Kamera
538
                        ParamSet_DefaultSet2(); // Kamera
539
                        break;
539
                        break;
540
                case 3:
540
                case 3:
541
                        ParamSet_DefaultSet3(); // Beginner
541
                        ParamSet_DefaultSet3(); // Beginner
542
                        break;
542
                        break;
543
                default:
543
                default:
544
                        ParamSet_DefaultSet3(); // Beginner
544
                        ParamSet_DefaultSet3(); // Beginner
545
                        break;
545
                        break;
546
        }
546
        }
547
        if(restore_channels)
547
        if(restore_channels)
548
        {
548
        {
549
                uint8_t crc;
549
                uint8_t crc;
550
                // 1st check for a valid channel backup in eeprom
550
                // 1st check for a valid channel backup in eeprom
551
                crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
551
                crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
552
                if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) )
552
                if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) )
553
                {
553
                {
554
                        eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
554
                        eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
555
                }
555
                }
556
                else ParamSet_DefaultStickMapping();
556
                else ParamSet_DefaultStickMapping();
557
        }
557
        }
558
        else ParamSet_DefaultStickMapping();
558
        else ParamSet_DefaultStickMapping();
559
        ParamSet_WriteToEEProm(set);
559
        ParamSet_WriteToEEProm(set);
560
}
560
}
561
 
561
 
562
/***************************************************/
562
/***************************************************/
563
/*       Initialize EEPROM Parameter Sets          */
563
/*       Initialize EEPROM Parameter Sets          */
564
/***************************************************/
564
/***************************************************/
565
void ParamSet_Init(void)
565
void ParamSet_Init(void)
566
{
566
{
567
        uint8_t channel_backup  = 0, bad_params = 0, ee_default = 0,i;
567
        uint8_t channel_backup  = 0, bad_params = 0, ee_default = 0,i;
568
 
-
 
569
 
568
 
570
        if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) )
569
        if((EEPARAM_REVISION - EEPARAM_REVISION_SUB) != GetParamByte(PID_EE_REVISION))  
571
        {
570
        {
572
                ee_default = 1; // software update or forced by mktool
571
                ee_default = 1; // software update or forced by mktool
573
        }
572
        }
574
        // 1st check for a valid channel backup in eeprom
573
        // 1st check for a valid channel backup in eeprom
575
        i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
574
        i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung));
576
        if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1;
575
        if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)))) channel_backup = 1;
577
 
576
 
578
        // parameter check
577
        // parameter check
579
 
578
 
580
        // check all 5 parameter settings
579
        // check all 5 parameter settings
581
        for (i = 1;i < 6; i++)
580
        for (i = 1;i < 6; i++)
582
        {
581
        {
583
                if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom
582
                if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom
584
                {
583
                {
585
                        bad_params = 1;
584
                        bad_params = 1;
586
                        printf("\n\rGenerating default Parameter Set %d",i);
585
                        printf("\n\rGenerating default Parameter Set %d",i);
587
                        switch(i)
586
                        switch(i)
588
                        {
587
                        {
589
                                case 1:
588
                                case 1:
590
                                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
589
                                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
591
                                        break;
590
                                        break;
592
                                case 2:
591
                                case 2:
593
                                        ParamSet_DefaultSet2(); // Kamera
592
                                        ParamSet_DefaultSet2(); // Kamera
594
                                        break;
593
                                        break;
595
                                case 3:
594
                                case 3:
596
                                        ParamSet_DefaultSet3(); // Beginner
595
                                        ParamSet_DefaultSet3(); // Beginner
597
                                        break;
596
                                        break;
598
                                default:
597
                                default:
599
                                        ParamSet_DefaultSet3(); // Kamera
598
                                        ParamSet_DefaultSet3(); // Kamera
600
                                        break;
599
                                        break;
601
                        }
600
                        }
602
                        if(channel_backup) // if we have an channel mapping backup in eeprom
601
                        if(channel_backup) // if we have an channel mapping backup in eeprom
603
                        {       // restore it from eeprom
602
                        {       // restore it from eeprom
604
                                eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
603
                                eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung));
605
                        }
604
                        }
606
                        else
605
                        else
607
                        {       // use default mapping
606
                        {       // use default mapping
608
                                ParamSet_DefaultStickMapping();
607
                                ParamSet_DefaultStickMapping();
609
                        }
608
                        }
610
                        ParamSet_WriteToEEProm(i);
609
                        ParamSet_WriteToEEProm(i);
611
                }
610
                }
612
        }
611
        }
613
        if(bad_params) // at least one of the parameter settings were invalid
612
        if(bad_params) // at least one of the parameter settings were invalid
614
        {
613
        {
615
                // default-Setting is parameter set 3
614
                // default-Setting is parameter set 3
616
                SetActiveParamSet(3);
615
                SetActiveParamSet(3);
617
        }
616
        }
618
 
617
 
619
 
618
 
620
        // read active parameter set to ParamSet stucture
619
        // read active parameter set to ParamSet stucture
621
        i = GetActiveParamSet();
620
        i = GetActiveParamSet();
622
        ParamSet_ReadFromEEProm(i);
621
        ParamSet_ReadFromEEProm(i);
623
        printf("\n\rUsing Parameter Set %d", i);
622
        printf("\n\rUsing Parameter Set %d", i);
624
 
623
 
625
        // load mixer table
624
        // load mixer table
626
        if(GetParamByte(PID_EE_REVISION) == 0xff || !MixerTable_ReadFromEEProm() )
625
        if(GetParamByte(PID_EE_REVISION) == 0xff || !MixerTable_ReadFromEEProm() )
627
        {
626
        {
628
                printf("\n\rGenerating default Mixer Table");
627
                printf("\n\rGenerating default Mixer Table");
629
                MixerTable_Default(); // Quadro
628
                MixerTable_Default(); // Quadro
630
                MixerTable_WriteToEEProm();
629
                MixerTable_WriteToEEProm();
631
        }
630
        }
632
        if(ee_default)  SetParamByte(PID_EE_REVISION, EEPARAM_REVISION);
631
        if(ee_default)  SetParamByte(PID_EE_REVISION, (EEPARAM_REVISION - EEPARAM_REVISION_SUB));
633
        // determine motornumber
632
        // determine motornumber
634
        RequiredMotors = 0;
633
        RequiredMotors = 0;
635
        for(i = 0; i < 16; i++)
634
        for(i = 0; i < 16; i++)
636
        {
635
        {
637
                if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++;
636
                if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++;
638
        }
637
        }
639
 
638
 
640
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
639
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
641
 PrintLine();// ("\n\r===================================");
640
 PrintLine();// ("\n\r===================================");
642
 
641
 
643
}
642
}
644
 
643