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