Rev 2008 | Rev 2028 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2008 | Rev 2012 | ||
---|---|---|---|
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 | #ifndef EEMEM |
54 | #ifndef EEMEM |
55 | #define EEMEM __attribute__ ((section (".eeprom"))) |
55 | #define EEMEM __attribute__ ((section (".eeprom"))) |
56 | #endif |
56 | #endif |
57 | 57 | ||
58 | 58 | ||
59 | #include <avr/eeprom.h> |
59 | #include <avr/eeprom.h> |
60 | #include <string.h> |
60 | #include <string.h> |
61 | #include "eeprom.h" |
61 | #include "eeprom.h" |
62 | #include "uart.h" |
62 | #include "uart.h" |
63 | #include "led.h" |
63 | #include "led.h" |
64 | #include "main.h" |
64 | #include "main.h" |
65 | #include "fc.h" |
65 | #include "fc.h" |
66 | #include "twimaster.h" |
66 | #include "twimaster.h" |
67 | 67 | ||
68 | paramset_t EE_Parameter; |
68 | paramset_t EE_Parameter; |
69 | MixerTable_t Mixer; |
69 | MixerTable_t Mixer; |
70 | uint8_t RequiredMotors; |
70 | uint8_t RequiredMotors; |
71 | 71 | ||
72 | 72 | ||
73 | uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
73 | uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
74 | { |
74 | { |
75 | uint8_t crc = 0xAA; |
75 | uint8_t crc = 0xAA; |
76 | uint16_t i; |
76 | uint16_t i; |
77 | 77 | ||
78 | for(i=0; i<len; i++) |
78 | for(i=0; i<len; i++) |
79 | { |
79 | { |
80 | crc += pBuffer[i]; |
80 | crc += pBuffer[i]; |
81 | } |
81 | } |
82 | return crc; |
82 | return crc; |
83 | } |
83 | } |
84 | 84 | ||
85 | uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len) |
85 | uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len) |
86 | { |
86 | { |
87 | uint8_t crc = 0xAA; |
87 | uint8_t crc = 0xAA; |
88 | uint16_t off; |
88 | uint16_t off; |
89 | 89 | ||
90 | for(off=0; off<len; off++) |
90 | for(off=0; off<len; off++) |
91 | { |
91 | { |
92 | crc += eeprom_read_byte((uint8_t*)(EEAddr + off));; |
92 | crc += eeprom_read_byte((uint8_t*)(EEAddr + off));; |
93 | } |
93 | } |
94 | return crc; |
94 | return crc; |
95 | } |
95 | } |
96 | 96 | ||
97 | void ParamSet_DefaultStickMapping(void) |
97 | void ParamSet_DefaultStickMapping(void) |
98 | { |
98 | { |
99 | EE_Parameter.Kanalbelegung[K_GAS] = 1; |
99 | EE_Parameter.Kanalbelegung[K_GAS] = 1; |
100 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
100 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
101 | EE_Parameter.Kanalbelegung[K_NICK] = 3; |
101 | EE_Parameter.Kanalbelegung[K_NICK] = 3; |
102 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
102 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
103 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
103 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
104 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
104 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
105 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
105 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
106 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
106 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
107 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
107 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
108 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
108 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
109 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
109 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
110 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
110 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
111 | } |
111 | } |
112 | 112 | ||
113 | 113 | ||
114 | /***************************************************/ |
114 | /***************************************************/ |
115 | /* Default Values for parameter set 1 */ |
115 | /* Default Values for parameter set 1 */ |
116 | /***************************************************/ |
116 | /***************************************************/ |
117 | void CommonDefaults(void) |
117 | void CommonDefaults(void) |
118 | { |
118 | { |
119 | EE_Parameter.Revision = EEPARAM_REVISION; |
119 | EE_Parameter.Revision = EEPARAM_REVISION; |
120 | 120 | ||
121 | if(PlatinenVersion >= 20) |
121 | if(PlatinenVersion >= 20) |
122 | { |
122 | { |
123 | EE_Parameter.Gyro_D = 10; |
123 | EE_Parameter.Gyro_D = 10; |
124 | EE_Parameter.Driftkomp = 0; |
124 | EE_Parameter.Driftkomp = 0; |
125 | EE_Parameter.GyroAccFaktor = 27; |
125 | EE_Parameter.GyroAccFaktor = 27; |
126 | EE_Parameter.WinkelUmschlagNick = 78; |
126 | EE_Parameter.WinkelUmschlagNick = 78; |
127 | EE_Parameter.WinkelUmschlagRoll = 78; |
127 | EE_Parameter.WinkelUmschlagRoll = 78; |
128 | } |
128 | } |
129 | else |
129 | else |
130 | { |
130 | { |
131 | EE_Parameter.Gyro_D = 3; |
131 | EE_Parameter.Gyro_D = 3; |
132 | EE_Parameter.Driftkomp = 32; |
132 | EE_Parameter.Driftkomp = 32; |
133 | EE_Parameter.GyroAccFaktor = 30; |
133 | EE_Parameter.GyroAccFaktor = 30; |
134 | EE_Parameter.WinkelUmschlagNick = 85; |
134 | EE_Parameter.WinkelUmschlagNick = 85; |
135 | EE_Parameter.WinkelUmschlagRoll = 85; |
135 | EE_Parameter.WinkelUmschlagRoll = 85; |
136 | } |
136 | } |
137 | EE_Parameter.GyroAccAbgleich = 32; // 1/k |
137 | EE_Parameter.GyroAccAbgleich = 32; // 1/k |
138 | EE_Parameter.BitConfig = 0; // Looping usw. |
138 | EE_Parameter.BitConfig = 0; // Looping usw. |
139 | EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER; |
139 | EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER; |
140 | EE_Parameter.ExtraConfig = CFG_GPS_AID | CFG2_VARIO_BEEP; |
140 | EE_Parameter.ExtraConfig = CFG_GPS_AID | CFG2_VARIO_BEEP; |
141 | EE_Parameter.GlobalConfig3 = 0; |
141 | EE_Parameter.GlobalConfig3 = 0; |
142 | EE_Parameter.Receiver = RECEIVER_JETI; |
142 | EE_Parameter.Receiver = RECEIVER_JETI; |
143 | EE_Parameter.MotorSafetySwitch = 0; |
143 | EE_Parameter.MotorSafetySwitch = 0; |
144 | EE_Parameter.ExternalControl = 0; |
144 | EE_Parameter.ExternalControl = 0; |
145 | 145 | ||
146 | EE_Parameter.Gas_Min = 8; // Wert : 0-32 |
146 | EE_Parameter.Gas_Min = 8; // Wert : 0-32 |
147 | EE_Parameter.Gas_Max = 230; // Wert : 33-247 |
147 | EE_Parameter.Gas_Max = 230; // Wert : 33-247 |
148 | EE_Parameter.KompassWirkung = 64; // Wert : 0-247 |
148 | EE_Parameter.KompassWirkung = 64; // Wert : 0-247 |
149 | 149 | ||
150 | EE_Parameter.Hoehe_MinGas = 30; |
150 | EE_Parameter.Hoehe_MinGas = 30; |
151 | EE_Parameter.MaxHoehe = 255; // Wert : 0-247 255 -> Poti1 |
151 | EE_Parameter.MaxHoehe = 255; // Wert : 0-247 255 -> Poti1 |
152 | EE_Parameter.Hoehe_P = 15; // Wert : 0-32 |
152 | EE_Parameter.Hoehe_P = 15; // Wert : 0-32 |
153 | EE_Parameter.Luftdruck_D = 30; // Wert : 0-247 |
153 | EE_Parameter.Luftdruck_D = 30; // Wert : 0-247 |
154 | EE_Parameter.Hoehe_ACC_Wirkung = 0; // Wert : 0-247 |
154 | EE_Parameter.Hoehe_ACC_Wirkung = 0; // Wert : 0-247 |
155 | EE_Parameter.Hoehe_HoverBand = 8; // Wert : 0-247 |
155 | EE_Parameter.Hoehe_HoverBand = 8; // Wert : 0-247 |
156 | EE_Parameter.Hoehe_GPS_Z = 64; // Wert : 0-247 |
156 | EE_Parameter.Hoehe_GPS_Z = 64; // Wert : 0-247 |
157 | EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation) |
157 | EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation) |
158 | EE_Parameter.Hoehe_Verstaerkung = 15; // Wert : 0-50 (15 -> ca. +/- 5m/sek bei Stick-Voll-Ausschlag) |
158 | EE_Parameter.Hoehe_Verstaerkung = 15; // Wert : 0-50 (15 -> ca. +/- 5m/sek bei Stick-Voll-Ausschlag) |
159 | 159 | ||
160 | EE_Parameter.UserParam1 = 0; // zur freien Verwendung |
160 | EE_Parameter.UserParam1 = 0; // zur freien Verwendung |
161 | EE_Parameter.UserParam2 = 0; // zur freien Verwendung |
161 | EE_Parameter.UserParam2 = 0; // zur freien Verwendung |
162 | EE_Parameter.UserParam3 = 0; // zur freien Verwendung |
162 | EE_Parameter.UserParam3 = 0; // zur freien Verwendung |
163 | EE_Parameter.UserParam4 = 0; // zur freien Verwendung |
163 | EE_Parameter.UserParam4 = 0; // zur freien Verwendung |
164 | EE_Parameter.UserParam5 = 0; // zur freien Verwendung |
164 | EE_Parameter.UserParam5 = 0; // zur freien Verwendung |
165 | EE_Parameter.UserParam6 = 0; // zur freien Verwendung |
165 | EE_Parameter.UserParam6 = 0; // zur freien Verwendung |
166 | EE_Parameter.UserParam7 = 0; // zur freien Verwendung |
166 | EE_Parameter.UserParam7 = 0; // zur freien Verwendung |
167 | EE_Parameter.UserParam8 = 0; // zur freien Verwendung |
167 | EE_Parameter.UserParam8 = 0; // zur freien Verwendung |
168 | 168 | ||
169 | EE_Parameter.ServoNickControl = 128; // Wert : 0-247 // Stellung des Servos |
169 | EE_Parameter.ServoNickControl = 128; // Wert : 0-247 // Stellung des Servos |
170 | EE_Parameter.ServoNickComp = 50; // Wert : 0-247 // Einfluss Gyro/Servo |
170 | EE_Parameter.ServoNickComp = 50; // Wert : 0-247 // Einfluss Gyro/Servo |
171 | EE_Parameter.ServoCompInvert = 2; // Wert : 0-247 // Richtung Einfluss Gyro/Servo |
171 | EE_Parameter.ServoCompInvert = 2; // Wert : 0-247 // Richtung Einfluss Gyro/Servo |
172 | EE_Parameter.ServoNickMin = 15; // Wert : 0-247 // Anschlag |
172 | EE_Parameter.ServoNickMin = 15; // Wert : 0-247 // Anschlag |
173 | EE_Parameter.ServoNickMax = 230; // Wert : 0-247 // Anschlag |
173 | EE_Parameter.ServoNickMax = 230; // Wert : 0-247 // Anschlag |
174 | EE_Parameter.ServoNickRefresh = 4; |
174 | EE_Parameter.ServoNickRefresh = 4; |
175 | EE_Parameter.Servo3 = 125; |
175 | EE_Parameter.Servo3 = 125; |
176 | EE_Parameter.Servo4 = 125; |
176 | EE_Parameter.Servo4 = 125; |
177 | EE_Parameter.Servo5 = 125; |
177 | EE_Parameter.Servo5 = 125; |
178 | EE_Parameter.ServoRollControl = 128; // Wert : 0-247 // Stellung des Servos |
178 | EE_Parameter.ServoRollControl = 128; // Wert : 0-247 // Stellung des Servos |
179 | EE_Parameter.ServoRollComp = 85; // Wert : 0-247 // Einfluss Gyro/Servo |
179 | EE_Parameter.ServoRollComp = 85; // Wert : 0-247 // Einfluss Gyro/Servo |
180 | EE_Parameter.ServoRollMin = 70; // Wert : 0-247 // Anschlag |
180 | EE_Parameter.ServoRollMin = 70; // Wert : 0-247 // Anschlag |
181 | EE_Parameter.ServoRollMax = 220; // Wert : 0-247 // Anschlag |
181 | EE_Parameter.ServoRollMax = 220; // Wert : 0-247 // Anschlag |
182 | EE_Parameter.ServoManualControlSpeed = 60; |
182 | EE_Parameter.ServoManualControlSpeed = 60; |
183 | EE_Parameter.CamOrientation = 0; // Wert : 0-24 -> 0-360 -> 15° steps |
183 | EE_Parameter.CamOrientation = 0; // Wert : 0-24 -> 0-360 -> 15° steps |
184 | 184 | ||
185 | EE_Parameter.J16Bitmask = 95; |
185 | EE_Parameter.J16Bitmask = 95; |
186 | EE_Parameter.J17Bitmask = 243; |
186 | EE_Parameter.J17Bitmask = 243; |
187 | EE_Parameter.WARN_J16_Bitmask = 0xAA; |
187 | EE_Parameter.WARN_J16_Bitmask = 0xAA; |
188 | EE_Parameter.WARN_J17_Bitmask = 0xAA; |
188 | EE_Parameter.WARN_J17_Bitmask = 0xAA; |
189 | EE_Parameter.J16Timing = 20; |
189 | EE_Parameter.J16Timing = 20; |
190 | EE_Parameter.J17Timing = 20; |
190 | EE_Parameter.J17Timing = 20; |
191 | 191 | ||
192 | EE_Parameter.LoopGasLimit = 50; |
192 | EE_Parameter.LoopGasLimit = 50; |
193 | EE_Parameter.LoopThreshold = 90; // Wert: 0-247 Schwelle für Stickausschlag |
193 | EE_Parameter.LoopThreshold = 90; // Wert: 0-247 Schwelle für Stickausschlag |
194 | EE_Parameter.LoopHysterese = 50; |
194 | EE_Parameter.LoopHysterese = 50; |
195 | 195 | ||
196 | EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2 |
196 | EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2 |
197 | EE_Parameter.NaviGpsGain = 100; |
197 | EE_Parameter.NaviGpsGain = 100; |
198 | EE_Parameter.NaviGpsP = 90; |
198 | EE_Parameter.NaviGpsP = 90; |
199 | EE_Parameter.NaviGpsI = 90; |
199 | EE_Parameter.NaviGpsI = 90; |
200 | EE_Parameter.NaviGpsD = 90; |
200 | EE_Parameter.NaviGpsD = 90; |
201 | EE_Parameter.NaviGpsPLimit = 75; |
201 | EE_Parameter.NaviGpsPLimit = 75; |
202 | EE_Parameter.NaviGpsILimit = 85; |
202 | EE_Parameter.NaviGpsILimit = 85; |
203 | EE_Parameter.NaviGpsDLimit = 75; |
203 | EE_Parameter.NaviGpsDLimit = 75; |
204 | EE_Parameter.NaviGpsACC = 0; |
204 | EE_Parameter.NaviGpsACC = 0; |
205 | EE_Parameter.NaviGpsMinSat = 6; |
205 | EE_Parameter.NaviGpsMinSat = 6; |
206 | EE_Parameter.NaviStickThreshold = 8; |
206 | EE_Parameter.NaviStickThreshold = 8; |
207 | EE_Parameter.NaviWindCorrection = 90; |
207 | EE_Parameter.NaviWindCorrection = 90; |
208 | EE_Parameter.NaviAccCompensation = 42; |
208 | EE_Parameter.NaviAccCompensation = 42; |
209 | EE_Parameter.NaviOperatingRadius = 245; |
209 | EE_Parameter.NaviOperatingRadius = 245; |
210 | EE_Parameter.NaviAngleLimitation = 140; |
210 | EE_Parameter.NaviAngleLimitation = 140; |
211 | EE_Parameter.NaviPH_LoginTime = 5; |
211 | EE_Parameter.NaviPH_LoginTime = 5; |
212 | EE_Parameter.OrientationAngle = 0; |
212 | EE_Parameter.OrientationAngle = 0; |
213 | EE_Parameter.CareFreeModeControl = 0; |
213 | EE_Parameter.CareFreeModeControl = 0; |
214 | EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50) |
214 | EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50) |
215 | EE_Parameter.NotGas = 45; // Wert : 0-247 // Gaswert bei Empangsverlust |
215 | EE_Parameter.NotGas = 45; // Wert : 0-247 // Gaswert bei Empangsverlust |
216 | EE_Parameter.NotGasZeit = 90; // Wert : 0-247 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
216 | EE_Parameter.NotGasZeit = 90; // Wert : 0-247 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
217 | EE_Parameter.MotorSmooth = 0; |
217 | EE_Parameter.MotorSmooth = 0; |
218 | EE_Parameter.ComingHomeAltitude = 0; // 0 = don't change |
218 | EE_Parameter.ComingHomeAltitude = 0; // 0 = don't change |
219 | EE_Parameter.FailSafeTime = 0; // 0 = off |
219 | EE_Parameter.FailSafeTime = 0; // 0 = off |
220 | EE_Parameter.MaxAltitude = 150; // 0 = off |
220 | EE_Parameter.MaxAltitude = 150; // 0 = off |
221 | EE_Parameter.AchsKopplung1 = 90; |
221 | EE_Parameter.AchsKopplung1 = 90; |
222 | EE_Parameter.AchsKopplung2 = 55; |
222 | EE_Parameter.AchsKopplung2 = 55; |
223 | EE_Parameter.FailsafeChannel = 0; |
223 | EE_Parameter.FailsafeChannel = 0; |
- | 224 | EE_Parameter.ServoFilterNick = 0; |
|
- | 225 | EE_Parameter.ServoFilterRoll = 0; |
|
224 | } |
226 | } |
225 | /* |
227 | /* |
226 | void ParamSet_DefaultSet1(void) // sport |
228 | void ParamSet_DefaultSet1(void) // sport |
227 | { |
229 | { |
228 | CommonDefaults(); |
230 | CommonDefaults(); |
229 | EE_Parameter.Stick_P = 14; // Wert : 1-20 |
231 | EE_Parameter.Stick_P = 14; // Wert : 1-20 |
230 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
232 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
231 | EE_Parameter.StickGier_P = 12; // Wert : 1-20 |
233 | EE_Parameter.StickGier_P = 12; // Wert : 1-20 |
232 | EE_Parameter.Gyro_P = 80; // Wert : 0-247 |
234 | EE_Parameter.Gyro_P = 80; // Wert : 0-247 |
233 | EE_Parameter.Gyro_I = 150; // Wert : 0-247 |
235 | EE_Parameter.Gyro_I = 150; // Wert : 0-247 |
234 | EE_Parameter.Gyro_Gier_P = 80; // Wert : 0-247 |
236 | EE_Parameter.Gyro_Gier_P = 80; // Wert : 0-247 |
235 | EE_Parameter.Gyro_Gier_I = 150; // Wert : 0-247 |
237 | EE_Parameter.Gyro_Gier_I = 150; // Wert : 0-247 |
236 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
238 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
237 | EE_Parameter.I_Faktor = 32; |
239 | EE_Parameter.I_Faktor = 32; |
238 | EE_Parameter.CouplingYawCorrection = 1; |
240 | EE_Parameter.CouplingYawCorrection = 1; |
239 | EE_Parameter.GyroAccAbgleich = 16; // 1/k; |
241 | EE_Parameter.GyroAccAbgleich = 16; // 1/k; |
240 | EE_Parameter.DynamicStability = 100; |
242 | EE_Parameter.DynamicStability = 100; |
241 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
243 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
242 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
244 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
243 | } |
245 | } |
244 | */ |
246 | */ |
245 | 247 | ||
246 | /***************************************************/ |
248 | /***************************************************/ |
247 | /* Default Values for parameter set 1 */ |
249 | /* Default Values for parameter set 1 */ |
248 | /***************************************************/ |
250 | /***************************************************/ |
249 | void ParamSet_DefaultSet1(void) // normal |
251 | void ParamSet_DefaultSet1(void) // normal |
250 | { |
252 | { |
251 | CommonDefaults(); |
253 | CommonDefaults(); |
252 | EE_Parameter.Stick_P = 10; // Wert : 1-20 |
254 | EE_Parameter.Stick_P = 10; // Wert : 1-20 |
253 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
255 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
254 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
256 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
255 | EE_Parameter.Gyro_P = 90; // Wert : 0-247 |
257 | EE_Parameter.Gyro_P = 90; // Wert : 0-247 |
256 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
258 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
257 | EE_Parameter.Gyro_Gier_P = 90; // Wert : 0-247 |
259 | EE_Parameter.Gyro_Gier_P = 90; // Wert : 0-247 |
258 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
260 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
259 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
261 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
260 | EE_Parameter.I_Faktor = 32; |
262 | EE_Parameter.I_Faktor = 32; |
261 | EE_Parameter.CouplingYawCorrection = 60; |
263 | EE_Parameter.CouplingYawCorrection = 60; |
262 | EE_Parameter.DynamicStability = 75; |
264 | EE_Parameter.DynamicStability = 75; |
263 | memcpy(EE_Parameter.Name, "Fast\0", 12); |
265 | memcpy(EE_Parameter.Name, "Fast\0", 12); |
264 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
266 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
265 | } |
267 | } |
266 | 268 | ||
267 | 269 | ||
268 | /***************************************************/ |
270 | /***************************************************/ |
269 | /* Default Values for parameter set 2 */ |
271 | /* Default Values for parameter set 2 */ |
270 | /***************************************************/ |
272 | /***************************************************/ |
271 | void ParamSet_DefaultSet2(void) // beginner |
273 | void ParamSet_DefaultSet2(void) // beginner |
272 | { |
274 | { |
273 | CommonDefaults(); |
275 | CommonDefaults(); |
274 | EE_Parameter.Stick_P = 8; // Wert : 1-20 |
276 | EE_Parameter.Stick_P = 8; // Wert : 1-20 |
275 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
277 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
276 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
278 | EE_Parameter.StickGier_P = 6; // Wert : 1-20 |
277 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
279 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
278 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
280 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
279 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
281 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
280 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
282 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
281 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
283 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
282 | EE_Parameter.I_Faktor = 16; |
284 | EE_Parameter.I_Faktor = 16; |
283 | EE_Parameter.CouplingYawCorrection = 70; |
285 | EE_Parameter.CouplingYawCorrection = 70; |
284 | EE_Parameter.DynamicStability = 70; |
286 | EE_Parameter.DynamicStability = 70; |
285 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
287 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
286 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
288 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
287 | } |
289 | } |
288 | 290 | ||
289 | /***************************************************/ |
291 | /***************************************************/ |
290 | /* Default Values for parameter set 3 */ |
292 | /* Default Values for parameter set 3 */ |
291 | /***************************************************/ |
293 | /***************************************************/ |
292 | void ParamSet_DefaultSet3(void) // beginner |
294 | void ParamSet_DefaultSet3(void) // beginner |
293 | { |
295 | { |
294 | CommonDefaults(); |
296 | CommonDefaults(); |
295 | EE_Parameter.Stick_P = 6; // Wert : 1-20 |
297 | EE_Parameter.Stick_P = 6; // Wert : 1-20 |
296 | EE_Parameter.Stick_D = 10; // Wert : 0-20 |
298 | EE_Parameter.Stick_D = 10; // Wert : 0-20 |
297 | EE_Parameter.StickGier_P = 4; // Wert : 1-20 |
299 | EE_Parameter.StickGier_P = 4; // Wert : 1-20 |
298 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
300 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
299 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
301 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
300 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
302 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
301 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
303 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
302 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
304 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
303 | EE_Parameter.I_Faktor = 16; |
305 | EE_Parameter.I_Faktor = 16; |
304 | EE_Parameter.CouplingYawCorrection = 70; |
306 | EE_Parameter.CouplingYawCorrection = 70; |
305 | EE_Parameter.DynamicStability = 70; |
307 | EE_Parameter.DynamicStability = 70; |
306 | memcpy(EE_Parameter.Name, "Easy\0", 12); |
308 | memcpy(EE_Parameter.Name, "Easy\0", 12); |
307 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
309 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
308 | } |
310 | } |
309 | 311 | ||
310 | 312 | ||
311 | /***************************************************/ |
313 | /***************************************************/ |
312 | /* Read Parameter from EEPROM as byte */ |
314 | /* Read Parameter from EEPROM as byte */ |
313 | /***************************************************/ |
315 | /***************************************************/ |
314 | uint8_t GetParamByte(uint16_t param_id) |
316 | uint8_t GetParamByte(uint16_t param_id) |
315 | { |
317 | { |
316 | return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
318 | return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
317 | } |
319 | } |
318 | 320 | ||
319 | /***************************************************/ |
321 | /***************************************************/ |
320 | /* Write Parameter to EEPROM as byte */ |
322 | /* Write Parameter to EEPROM as byte */ |
321 | /***************************************************/ |
323 | /***************************************************/ |
322 | void SetParamByte(uint16_t param_id, uint8_t value) |
324 | void SetParamByte(uint16_t param_id, uint8_t value) |
323 | { |
325 | { |
324 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
326 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
325 | } |
327 | } |
326 | 328 | ||
327 | /***************************************************/ |
329 | /***************************************************/ |
328 | /* Read Parameter from EEPROM as word */ |
330 | /* Read Parameter from EEPROM as word */ |
329 | /***************************************************/ |
331 | /***************************************************/ |
330 | uint16_t GetParamWord(uint16_t param_id) |
332 | uint16_t GetParamWord(uint16_t param_id) |
331 | { |
333 | { |
332 | return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
334 | return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
333 | } |
335 | } |
334 | 336 | ||
335 | /***************************************************/ |
337 | /***************************************************/ |
336 | /* Write Parameter to EEPROM as word */ |
338 | /* Write Parameter to EEPROM as word */ |
337 | /***************************************************/ |
339 | /***************************************************/ |
338 | void SetParamWord(uint16_t param_id, uint16_t value) |
340 | void SetParamWord(uint16_t param_id, uint16_t value) |
339 | { |
341 | { |
340 | eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
342 | eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
341 | } |
343 | } |
342 | 344 | ||
343 | /***************************************************/ |
345 | /***************************************************/ |
344 | /* Read Parameter Set from EEPROM */ |
346 | /* Read Parameter Set from EEPROM */ |
345 | /***************************************************/ |
347 | /***************************************************/ |
346 | // number [1..5] |
348 | // number [1..5] |
347 | uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber) |
349 | uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber) |
348 | { |
350 | { |
349 | uint8_t crc; |
351 | uint8_t crc; |
350 | uint16_t eeaddr; |
352 | uint16_t eeaddr; |
351 | 353 | ||
352 | // range the setnumber |
354 | // range the setnumber |
353 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
355 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
354 | 356 | ||
355 | // calculate eeprom addr |
357 | // calculate eeprom addr |
356 | eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1); |
358 | eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1); |
357 | 359 | ||
358 | // calculate checksum from eeprom |
360 | // calculate checksum from eeprom |
359 | crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1); |
361 | crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1); |
360 | 362 | ||
361 | // check crc |
363 | // check crc |
362 | if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0; |
364 | if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0; |
363 | 365 | ||
364 | // check revision |
366 | // check revision |
365 | if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0; |
367 | if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0; |
366 | 368 | ||
367 | // read paramset from eeprom |
369 | // read paramset from eeprom |
368 | eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
370 | eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
369 | LED_Init(); |
371 | LED_Init(); |
370 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
372 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
371 | LIBFC_HoTT_Clear(); |
373 | LIBFC_HoTT_Clear(); |
372 | #endif |
374 | #endif |
373 | return 1; |
375 | return 1; |
374 | } |
376 | } |
375 | 377 | ||
376 | /***************************************************/ |
378 | /***************************************************/ |
377 | /* Write Parameter Set to EEPROM */ |
379 | /* Write Parameter Set to EEPROM */ |
378 | /***************************************************/ |
380 | /***************************************************/ |
379 | // number [1..5] |
381 | // number [1..5] |
380 | uint8_t ParamSet_WriteToEEProm(uint8_t setnumber) |
382 | uint8_t ParamSet_WriteToEEProm(uint8_t setnumber) |
381 | { |
383 | { |
382 | uint8_t crc; |
384 | uint8_t crc; |
383 | 385 | ||
384 | if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom |
386 | if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom |
385 | { |
387 | { |
386 | if(setnumber > 5) setnumber = 5; |
388 | if(setnumber > 5) setnumber = 5; |
387 | if(setnumber < 1) return 0; |
389 | if(setnumber < 1) return 0; |
388 | LIBFC_CheckSettings(); |
390 | LIBFC_CheckSettings(); |
389 | // update checksum |
391 | // update checksum |
390 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
392 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
391 | 393 | ||
392 | // write paramset to eeprom |
394 | // write paramset to eeprom |
393 | eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
395 | eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
394 | 396 | ||
395 | // backup channel settings to separate block in eeprom |
397 | // backup channel settings to separate block in eeprom |
396 | eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
398 | eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
397 | 399 | ||
398 | // write crc of channel block to eeprom |
400 | // write crc of channel block to eeprom |
399 | crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung)); |
401 | crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung)); |
400 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc); |
402 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc); |
401 | 403 | ||
402 | // update active settings number |
404 | // update active settings number |
403 | SetActiveParamSet(setnumber); |
405 | SetActiveParamSet(setnumber); |
404 | LED_Init(); |
406 | LED_Init(); |
405 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
407 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
406 | LIBFC_HoTT_Clear(); |
408 | LIBFC_HoTT_Clear(); |
407 | #endif |
409 | #endif |
408 | return 1; |
410 | return 1; |
409 | } |
411 | } |
410 | // wrong revision |
412 | // wrong revision |
411 | return 0; |
413 | return 0; |
412 | } |
414 | } |
413 | 415 | ||
414 | /***************************************************/ |
416 | /***************************************************/ |
415 | /* Read MixerTable from EEPROM */ |
417 | /* Read MixerTable from EEPROM */ |
416 | /***************************************************/ |
418 | /***************************************************/ |
417 | uint8_t MixerTable_ReadFromEEProm(void) |
419 | uint8_t MixerTable_ReadFromEEProm(void) |
418 | { |
420 | { |
419 | uint8_t crc; |
421 | uint8_t crc; |
420 | 422 | ||
421 | // calculate checksum in eeprom |
423 | // calculate checksum in eeprom |
422 | crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1); |
424 | crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1); |
423 | 425 | ||
424 | // check crc |
426 | // check crc |
425 | if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0; |
427 | if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0; |
426 | 428 | ||
427 | // check revision |
429 | // check revision |
428 | if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0; |
430 | if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0; |
429 | 431 | ||
430 | // read mixer table |
432 | // read mixer table |
431 | eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
433 | eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
432 | return 1; |
434 | return 1; |
433 | } |
435 | } |
434 | 436 | ||
435 | /***************************************************/ |
437 | /***************************************************/ |
436 | /* Write Mixer Table to EEPROM */ |
438 | /* Write Mixer Table to EEPROM */ |
437 | /***************************************************/ |
439 | /***************************************************/ |
438 | uint8_t MixerTable_WriteToEEProm(void) |
440 | uint8_t MixerTable_WriteToEEProm(void) |
439 | { |
441 | { |
440 | if(Mixer.Revision == EEMIXER_REVISION) |
442 | if(Mixer.Revision == EEMIXER_REVISION) |
441 | { |
443 | { |
442 | // update crc |
444 | // update crc |
443 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
445 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
444 | 446 | ||
445 | // write to eeprom |
447 | // write to eeprom |
446 | eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
448 | eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
447 | return 1; |
449 | return 1; |
448 | } |
450 | } |
449 | else return 0; |
451 | else return 0; |
450 | } |
452 | } |
451 | 453 | ||
452 | /***************************************************/ |
454 | /***************************************************/ |
453 | /* Default Values for Mixer Table */ |
455 | /* Default Values for Mixer Table */ |
454 | /***************************************************/ |
456 | /***************************************************/ |
455 | void MixerTable_Default(void) // Quadro |
457 | void MixerTable_Default(void) // Quadro |
456 | { |
458 | { |
457 | uint8_t i; |
459 | uint8_t i; |
458 | 460 | ||
459 | Mixer.Revision = EEMIXER_REVISION; |
461 | Mixer.Revision = EEMIXER_REVISION; |
460 | // clear mixer table |
462 | // clear mixer table |
461 | for(i = 0; i < 16; i++) |
463 | for(i = 0; i < 16; i++) |
462 | { |
464 | { |
463 | Mixer.Motor[i][MIX_GAS] = 0; |
465 | Mixer.Motor[i][MIX_GAS] = 0; |
464 | Mixer.Motor[i][MIX_NICK] = 0; |
466 | Mixer.Motor[i][MIX_NICK] = 0; |
465 | Mixer.Motor[i][MIX_ROLL] = 0; |
467 | Mixer.Motor[i][MIX_ROLL] = 0; |
466 | Mixer.Motor[i][MIX_YAW] = 0; |
468 | Mixer.Motor[i][MIX_YAW] = 0; |
467 | } |
469 | } |
468 | // default = Quadro |
470 | // default = Quadro |
469 | Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] = 0; Mixer.Motor[0][MIX_YAW] = +64; |
471 | Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] = 0; Mixer.Motor[0][MIX_YAW] = +64; |
470 | Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] = 0; Mixer.Motor[1][MIX_YAW] = +64; |
472 | Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] = 0; Mixer.Motor[1][MIX_YAW] = +64; |
471 | Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
473 | Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
472 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
474 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
473 | memcpy(Mixer.Name, "Quadro\0", 7); |
475 | memcpy(Mixer.Name, "Quadro\0", 7); |
474 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
476 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
475 | } |
477 | } |
476 | 478 | ||
477 | /***************************************************/ |
479 | /***************************************************/ |
478 | /* Get active parameter set */ |
480 | /* Get active parameter set */ |
479 | /***************************************************/ |
481 | /***************************************************/ |
480 | uint8_t GetActiveParamSet(void) |
482 | uint8_t GetActiveParamSet(void) |
481 | { |
483 | { |
482 | uint8_t setnumber; |
484 | uint8_t setnumber; |
483 | setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET)); |
485 | setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET)); |
484 | if(setnumber > 5) |
486 | if(setnumber > 5) |
485 | { |
487 | { |
486 | setnumber = 3; |
488 | setnumber = 3; |
487 | eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber); |
489 | eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber); |
488 | } |
490 | } |
489 | return(setnumber); |
491 | return(setnumber); |
490 | } |
492 | } |
491 | 493 | ||
492 | /***************************************************/ |
494 | /***************************************************/ |
493 | /* Set active parameter set */ |
495 | /* Set active parameter set */ |
494 | /***************************************************/ |
496 | /***************************************************/ |
495 | void SetActiveParamSet(uint8_t setnumber) |
497 | void SetActiveParamSet(uint8_t setnumber) |
496 | { |
498 | { |
497 | if(setnumber > 5) setnumber = 5; |
499 | if(setnumber > 5) setnumber = 5; |
498 | if(setnumber < 1) setnumber = 1; |
500 | if(setnumber < 1) setnumber = 1; |
499 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber); |
501 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber); |
500 | } |
502 | } |
501 | 503 | ||
502 | /***************************************************/ |
504 | /***************************************************/ |
503 | /* Set default parameter set */ |
505 | /* Set default parameter set */ |
504 | /***************************************************/ |
506 | /***************************************************/ |
505 | void SetDefaultParameter(uint8_t set, uint8_t restore_channels) |
507 | void SetDefaultParameter(uint8_t set, uint8_t restore_channels) |
506 | { |
508 | { |
507 | 509 | ||
508 | if(set > 5) set = 5; |
510 | if(set > 5) set = 5; |
509 | else if(set < 1) set = 1; |
511 | else if(set < 1) set = 1; |
510 | 512 | ||
511 | switch(set) |
513 | switch(set) |
512 | { |
514 | { |
513 | case 1: |
515 | case 1: |
514 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
516 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
515 | break; |
517 | break; |
516 | case 2: |
518 | case 2: |
517 | ParamSet_DefaultSet2(); // Kamera |
519 | ParamSet_DefaultSet2(); // Kamera |
518 | break; |
520 | break; |
519 | case 3: |
521 | case 3: |
520 | ParamSet_DefaultSet3(); // Beginner |
522 | ParamSet_DefaultSet3(); // Beginner |
521 | break; |
523 | break; |
522 | default: |
524 | default: |
523 | ParamSet_DefaultSet3(); // Beginner |
525 | ParamSet_DefaultSet3(); // Beginner |
524 | break; |
526 | break; |
525 | } |
527 | } |
526 | if(restore_channels) |
528 | if(restore_channels) |
527 | { |
529 | { |
528 | uint8_t crc; |
530 | uint8_t crc; |
529 | // 1st check for a valid channel backup in eeprom |
531 | // 1st check for a valid channel backup in eeprom |
530 | crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
532 | crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
531 | if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) |
533 | if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) |
532 | { |
534 | { |
533 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
535 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
534 | } |
536 | } |
535 | else ParamSet_DefaultStickMapping(); |
537 | else ParamSet_DefaultStickMapping(); |
536 | } |
538 | } |
537 | else ParamSet_DefaultStickMapping(); |
539 | else ParamSet_DefaultStickMapping(); |
538 | ParamSet_WriteToEEProm(set); |
540 | ParamSet_WriteToEEProm(set); |
539 | } |
541 | } |
540 | 542 | ||
541 | /***************************************************/ |
543 | /***************************************************/ |
542 | /* Initialize EEPROM Parameter Sets */ |
544 | /* Initialize EEPROM Parameter Sets */ |
543 | /***************************************************/ |
545 | /***************************************************/ |
544 | void ParamSet_Init(void) |
546 | void ParamSet_Init(void) |
545 | { |
547 | { |
546 | uint8_t channel_backup = 0, bad_params = 0, ee_default = 0,i; |
548 | uint8_t channel_backup = 0, bad_params = 0, ee_default = 0,i; |
547 | 549 | ||
548 | 550 | ||
549 | if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) ) |
551 | if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) ) |
550 | { |
552 | { |
551 | ee_default = 1; // software update or forced by mktool |
553 | ee_default = 1; // software update or forced by mktool |
552 | } |
554 | } |
553 | 555 | ||
554 | 556 | ||
555 | // 1st check for a valid channel backup in eeprom |
557 | // 1st check for a valid channel backup in eeprom |
556 | i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
558 | i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
557 | if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1; |
559 | if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1; |
558 | 560 | ||
559 | 561 | ||
560 | // parameter check |
562 | // parameter check |
561 | 563 | ||
562 | // check all 5 parameter settings |
564 | // check all 5 parameter settings |
563 | for (i = 1;i < 6; i++) |
565 | for (i = 1;i < 6; i++) |
564 | { |
566 | { |
565 | if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom |
567 | if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom |
566 | { |
568 | { |
567 | bad_params = 1; |
569 | bad_params = 1; |
568 | printf("\n\rGenerating default Parameter Set %d",i); |
570 | printf("\n\rGenerating default Parameter Set %d",i); |
569 | switch(i) |
571 | switch(i) |
570 | { |
572 | { |
571 | case 1: |
573 | case 1: |
572 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
574 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
573 | break; |
575 | break; |
574 | case 2: |
576 | case 2: |
575 | ParamSet_DefaultSet2(); // Kamera |
577 | ParamSet_DefaultSet2(); // Kamera |
576 | break; |
578 | break; |
577 | case 3: |
579 | case 3: |
578 | ParamSet_DefaultSet3(); // Beginner |
580 | ParamSet_DefaultSet3(); // Beginner |
579 | break; |
581 | break; |
580 | default: |
582 | default: |
581 | ParamSet_DefaultSet3(); // Kamera |
583 | ParamSet_DefaultSet3(); // Kamera |
582 | break; |
584 | break; |
583 | } |
585 | } |
584 | if(channel_backup) // if we have an channel mapping backup in eeprom |
586 | if(channel_backup) // if we have an channel mapping backup in eeprom |
585 | { // restore it from eeprom |
587 | { // restore it from eeprom |
586 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
588 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
587 | } |
589 | } |
588 | else |
590 | else |
589 | { // use default mapping |
591 | { // use default mapping |
590 | ParamSet_DefaultStickMapping(); |
592 | ParamSet_DefaultStickMapping(); |
591 | } |
593 | } |
592 | ParamSet_WriteToEEProm(i); |
594 | ParamSet_WriteToEEProm(i); |
593 | } |
595 | } |
594 | } |
596 | } |
595 | if(bad_params) // at least one of the parameter settings were invalid |
597 | if(bad_params) // at least one of the parameter settings were invalid |
596 | { |
598 | { |
597 | // default-Setting is parameter set 3 |
599 | // default-Setting is parameter set 3 |
598 | SetActiveParamSet(3); |
600 | SetActiveParamSet(3); |
599 | } |
601 | } |
600 | 602 | ||
601 | 603 | ||
602 | // read active parameter set to ParamSet stucture |
604 | // read active parameter set to ParamSet stucture |
603 | i = GetActiveParamSet(); |
605 | i = GetActiveParamSet(); |
604 | ParamSet_ReadFromEEProm(i); |
606 | ParamSet_ReadFromEEProm(i); |
605 | printf("\n\rUsing Parameter Set %d", i); |
607 | printf("\n\rUsing Parameter Set %d", i); |
606 | 608 | ||
607 | // load mixer table |
609 | // load mixer table |
608 | if(GetParamByte(PID_EE_REVISION) == 0xff || !MixerTable_ReadFromEEProm() ) |
610 | if(GetParamByte(PID_EE_REVISION) == 0xff || !MixerTable_ReadFromEEProm() ) |
609 | { |
611 | { |
610 | printf("\n\rGenerating default Mixer Table"); |
612 | printf("\n\rGenerating default Mixer Table"); |
611 | MixerTable_Default(); // Quadro |
613 | MixerTable_Default(); // Quadro |
612 | MixerTable_WriteToEEProm(); |
614 | MixerTable_WriteToEEProm(); |
613 | } |
615 | } |
614 | if(ee_default) SetParamByte(PID_EE_REVISION, EEPARAM_REVISION); |
616 | if(ee_default) SetParamByte(PID_EE_REVISION, EEPARAM_REVISION); |
615 | // determine motornumber |
617 | // determine motornumber |
616 | RequiredMotors = 0; |
618 | RequiredMotors = 0; |
617 | for(i = 0; i < 16; i++) |
619 | for(i = 0; i < 16; i++) |
618 | { |
620 | { |
619 | if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++; |
621 | if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++; |
620 | } |
622 | } |
621 | 623 | ||
622 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
624 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
623 | printf("\n\r=============================="); |
625 | printf("\n\r=============================="); |
624 | } |
626 | } |
625 | 627 |