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