Rev 1320 | Rev 1328 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1320 | Rev 1322 | ||
---|---|---|---|
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 | unsigned char BattLowVoltageWarning = 94; |
57 | unsigned char BattLowVoltageWarning = 94; |
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
59 | // -- Parametersatz aus EEPROM lesen --- |
59 | // -- Parametersatz aus EEPROM lesen --- |
60 | // number [1..5] |
60 | // number [1..5] |
61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
62 | { |
62 | { |
63 | if((number > 5)||(number < 1)) number = 3; |
63 | if((number > 5)||(number < 1)) number = 3; |
64 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
64 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
65 | LED_Init(); |
65 | LED_Init(); |
66 | } |
66 | } |
67 | 67 | ||
68 | // -- Parametersatz ins EEPROM schreiben --- |
68 | // -- Parametersatz ins EEPROM schreiben --- |
69 | // number [1..5] |
69 | // number [1..5] |
70 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
70 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
71 | { |
71 | { |
72 | if(number > 5) number = 5; |
72 | if(number > 5) number = 5; |
73 | if(number < 1) return; |
73 | if(number < 1) return; |
74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
76 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 8); // 8 Kanäle merken |
76 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 8); // 8 Kanäle merken |
77 | SetActiveParamSetNumber(number); |
77 | SetActiveParamSetNumber(number); |
78 | LED_Init(); |
78 | LED_Init(); |
79 | } |
79 | } |
80 | 80 | ||
81 | unsigned char GetActiveParamSetNumber(void) |
81 | unsigned char GetActiveParamSetNumber(void) |
82 | { |
82 | { |
83 | unsigned char set; |
83 | unsigned char set; |
84 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
84 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
85 | if((set > 5) || (set < 1)) |
85 | if((set > 5) || (set < 1)) |
86 | { |
86 | { |
87 | set = 3; |
87 | set = 3; |
88 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
88 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
89 | } |
89 | } |
90 | return(set); |
90 | return(set); |
91 | } |
91 | } |
92 | 92 | ||
93 | 93 | ||
94 | void SetActiveParamSetNumber(unsigned char number) |
94 | void SetActiveParamSetNumber(unsigned char number) |
95 | { |
95 | { |
96 | if(number > 5) number = 5; |
96 | if(number > 5) number = 5; |
97 | if(number < 1) return; |
97 | if(number < 1) return; |
98 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
98 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
99 | } |
99 | } |
100 | 100 | ||
101 | 101 | ||
102 | void CalMk3Mag(void) |
102 | void CalMk3Mag(void) |
103 | { |
103 | { |
104 | static unsigned char stick = 1; |
104 | static unsigned char stick = 1; |
105 | 105 | ||
106 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
106 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
107 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
107 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
108 | { |
108 | { |
109 | stick = 1; |
109 | stick = 1; |
110 | WinkelOut.CalcState++; |
110 | WinkelOut.CalcState++; |
111 | if(WinkelOut.CalcState > 4) |
111 | if(WinkelOut.CalcState > 4) |
112 | { |
112 | { |
113 | // WinkelOut.CalcState = 0; // in Uart.c |
113 | // WinkelOut.CalcState = 0; // in Uart.c |
114 | beeptime = 1000; |
114 | beeptime = 1000; |
115 | } |
115 | } |
116 | else Piep(WinkelOut.CalcState,150); |
116 | else Piep(WinkelOut.CalcState,150); |
117 | } |
117 | } |
118 | DebugOut.Analog[19] = WinkelOut.CalcState; |
118 | DebugOut.Analog[19] = WinkelOut.CalcState; |
119 | } |
119 | } |
120 | 120 | ||
121 | void LipoDetection(unsigned char print) |
121 | void LipoDetection(unsigned char print) |
122 | { |
122 | { |
123 | unsigned int timer; |
123 | unsigned int timer; |
124 | if(print) printf("\n\rBatt:"); |
124 | if(print) printf("\n\rBatt:"); |
125 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
125 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
126 | { |
126 | { |
127 | timer = SetDelay(500); |
127 | timer = SetDelay(500); |
128 | if(print) while (!CheckDelay(timer)); |
128 | if(print) while (!CheckDelay(timer)); |
129 | if(UBat < 130) |
129 | if(UBat < 130) |
130 | { |
130 | { |
131 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
131 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
132 | if(print) |
132 | if(print) |
133 | { |
133 | { |
134 | Piep(3,200); |
134 | Piep(3,200); |
135 | printf(" 3 Cells "); |
135 | printf(" 3 Cells "); |
136 | } |
136 | } |
137 | } |
137 | } |
138 | else |
138 | else |
139 | { |
139 | { |
140 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
140 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
141 | if(print) |
141 | if(print) |
142 | { |
142 | { |
143 | Piep(4,200); |
143 | Piep(4,200); |
144 | printf(" 4 Cells "); |
144 | printf(" 4 Cells "); |
145 | } |
145 | } |
146 | } |
146 | } |
147 | } |
147 | } |
148 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
148 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
149 | if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
149 | if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
150 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
150 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
151 | } |
151 | } |
152 | 152 | ||
153 | //############################################################################ |
153 | //############################################################################ |
154 | //Hauptprogramm |
154 | //Hauptprogramm |
155 | int main (void) |
155 | int main (void) |
156 | //############################################################################ |
156 | //############################################################################ |
157 | { |
157 | { |
158 | unsigned int timer,i,timer2 = 0; |
158 | unsigned int timer,i,timer2 = 0; |
159 | DDRB = 0x00; |
159 | DDRB = 0x00; |
160 | PORTB = 0x00; |
160 | PORTB = 0x00; |
161 | for(timer = 0; timer < 1000; timer++); // verzögern |
161 | for(timer = 0; timer < 1000; timer++); // verzögern |
162 | if(PINB & 0x01) |
162 | if(PINB & 0x01) |
163 | { |
163 | { |
164 | if(PINB & 0x02) PlatinenVersion = 13; |
164 | if(PINB & 0x02) PlatinenVersion = 13; |
165 | else PlatinenVersion = 11; |
165 | else PlatinenVersion = 11; |
166 | } |
166 | } |
167 | else |
167 | else |
168 | { |
168 | { |
169 | if(PINB & 0x02) PlatinenVersion = 20; |
169 | if(PINB & 0x02) PlatinenVersion = 20; |
170 | else PlatinenVersion = 10; |
170 | else PlatinenVersion = 10; |
171 | } |
171 | } |
172 | 172 | ||
173 | DDRC = 0x81; // SCL |
173 | DDRC = 0x81; // SCL |
174 | DDRC |=0x40; // HEF4017 Reset |
174 | DDRC |=0x40; // HEF4017 Reset |
175 | PORTC = 0xff; // Pullup SDA |
175 | PORTC = 0xff; // Pullup SDA |
176 | DDRB = 0x1B; // LEDs und Druckoffset |
176 | DDRB = 0x1B; // LEDs und Druckoffset |
177 | PORTB = 0x01; // LED_Rot |
177 | PORTB = 0x01; // LED_Rot |
178 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
178 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
179 | PORTD = 0x47; // LED |
179 | PORTD = 0x47; // LED |
180 | HEF4017R_ON; |
180 | HEF4017R_ON; |
181 | MCUSR &=~(1<<WDRF); |
181 | MCUSR &=~(1<<WDRF); |
182 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
182 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
183 | WDTCSR = 0; |
183 | WDTCSR = 0; |
184 | 184 | ||
185 | beeptime = 2000; |
185 | beeptime = 2000; |
186 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
186 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
187 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
187 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
188 | ROT_OFF; |
188 | ROT_OFF; |
189 | 189 | ||
190 | Timer_Init(); |
190 | Timer_Init(); |
191 | TIMER2_Init(); |
191 | TIMER2_Init(); |
192 | UART_Init(); |
192 | UART_Init(); |
193 | rc_sum_init(); |
193 | rc_sum_init(); |
194 | ADC_Init(); |
194 | ADC_Init(); |
195 | i2c_init(); |
195 | i2c_init(); |
196 | SPI_MasterInit(); |
196 | SPI_MasterInit(); |
197 | 197 | ||
198 | sei(); |
198 | sei(); |
199 | 199 | ||
200 | printf("\n\r==================================="); |
200 | printf("\n\r==================================="); |
201 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
201 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
202 | if(UCSR1A == 0x20 && UCSR1C == 0x06) // initial Values for 644P |
202 | if(UCSR1A == 0x20 && UCSR1C == 0x06) // initial Values for 644P |
203 | { |
203 | { |
204 | Uart1Init(); |
204 | Uart1Init(); |
205 | } |
205 | } |
206 | GRN_ON; |
206 | GRN_ON; |
207 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
207 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
208 | 208 | ||
209 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
209 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
210 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
210 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
211 | { |
211 | { |
212 | unsigned char i; |
212 | unsigned char i; |
213 | RequiredMotors = 0; |
213 | RequiredMotors = 0; |
214 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
214 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
215 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
215 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
216 | } |
216 | } |
217 | else // default |
217 | else // default |
218 | { |
218 | { |
219 | unsigned char i; |
219 | unsigned char i; |
220 | printf("\n\rGenerating default Mixer Table"); |
220 | printf("\n\rGenerating default Mixer Table"); |
221 | 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;}; |
221 | 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;}; |
222 | // default = Quadro |
222 | // default = Quadro |
223 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
223 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
224 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
224 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
225 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
225 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
226 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
226 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
227 | Mixer.Revision = MIXER_REVISION; |
227 | Mixer.Revision = MIXER_REVISION; |
228 | memcpy(Mixer.Name, "Quadro\0", 11); |
228 | memcpy(Mixer.Name, "Quadro\0", 11); |
229 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
229 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
230 | } |
230 | } |
231 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
231 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
232 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
232 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
233 | // + Check connected BL-Ctrls |
233 | // + Check connected BL-Ctrls |
234 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
234 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
235 | printf("\n\rFound BL-Ctrl: "); |
235 | printf("\n\rFound BL-Ctrl: "); |
236 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
236 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
237 | timer = SetDelay(2000); |
237 | timer = SetDelay(2000); |
238 | for(i=0; i < MAX_MOTORS; i++) |
238 | for(i=0; i < MAX_MOTORS; i++) |
239 | { |
239 | { |
240 | UpdateMotor = 0; |
240 | UpdateMotor = 0; |
241 | SendMotorData(); |
241 | SendMotorData(); |
242 | while(!UpdateMotor); |
242 | while(!UpdateMotor); |
243 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
243 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
244 | { |
244 | { |
245 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
245 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
246 | } |
246 | } |
247 | if(MotorPresent[i]) printf("%d ",i+1); |
247 | if(MotorPresent[i]) printf("%d ",i+1); |
248 | } |
248 | } |
249 | for(i=0; i < MAX_MOTORS; i++) |
249 | for(i=0; i < MAX_MOTORS; i++) |
250 | { |
250 | { |
251 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
251 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
252 | { |
252 | { |
253 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
253 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
254 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
254 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
255 | } |
255 | } |
256 | MotorError[i] = 0; |
256 | MotorError[i] = 0; |
257 | } |
257 | } |
258 | printf("\n\r==================================="); |
258 | printf("\n\r==================================="); |
259 | 259 | ||
260 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
260 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
261 | // + Check Settings |
261 | // + Check Settings |
262 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
262 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
263 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
263 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
264 | { |
264 | { |
265 | DefaultKonstanten1(); |
265 | DefaultKonstanten1(); |
266 | printf("\n\rInit. EEPROM"); |
266 | printf("\n\rInit. EEPROM"); |
267 | for (unsigned char i=1;i<6;i++) |
267 | for (unsigned char i=1;i<6;i++) |
268 | { |
268 | { |
269 | if(i==2) DefaultKonstanten2(); // Kamera |
269 | if(i==2) DefaultKonstanten2(); // Kamera |
270 | if(i==3) DefaultKonstanten3(); // Beginner |
270 | if(i==3) DefaultKonstanten3(); // Beginner |
271 | if(i>3) DefaultKonstanten2(); // Kamera |
271 | if(i>3) DefaultKonstanten2(); // Kamera |
272 | if(PlatinenVersion >= 20) |
272 | if(PlatinenVersion >= 20) |
273 | { |
273 | { |
274 | EE_Parameter.Gyro_D = 5; |
274 | EE_Parameter.Gyro_D = 5; |
275 | EE_Parameter.Driftkomp = 0; |
275 | EE_Parameter.Driftkomp = 0; |
276 | EE_Parameter.GyroAccFaktor = 27; |
276 | EE_Parameter.GyroAccFaktor = 27; |
277 | EE_Parameter.WinkelUmschlagNick = 78; |
277 | EE_Parameter.WinkelUmschlagNick = 78; |
278 | EE_Parameter.WinkelUmschlagRoll = 78; |
278 | EE_Parameter.WinkelUmschlagRoll = 78; |
279 | } |
279 | } |
280 | // valid Stick-Settings? |
280 | // valid Stick-Settings? |
281 | 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) |
281 | 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) |
282 | { |
282 | { |
283 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
283 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
284 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
284 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
285 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
285 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
286 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
286 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
287 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
287 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
288 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
288 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
289 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
289 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
290 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
290 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
291 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
291 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
292 | } else DefaultStickMapping(); |
292 | } else DefaultStickMapping(); |
293 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
293 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
294 | } |
294 | } |
295 | SetActiveParamSetNumber(3); // default-Setting |
295 | SetActiveParamSetNumber(3); // default-Setting |
296 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
296 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
297 | } |
297 | } |
298 | 298 | ||
299 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
299 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
300 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
300 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
301 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
301 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
302 | { |
302 | { |
303 | FlugMinuten = 0; |
303 | FlugMinuten = 0; |
304 | FlugMinutenGesamt = 0; |
304 | FlugMinutenGesamt = 0; |
305 | } |
305 | } |
306 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
306 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
307 | 307 | ||
308 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
308 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
309 | { |
309 | { |
310 | printf("\n\rACC not calibrated !"); |
310 | printf("\n\rACC not calibrated !"); |
311 | } |
311 | } |
312 | 312 | ||
313 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
313 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
314 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
314 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
315 | 315 | ||
316 | 316 | ||
317 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
317 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
318 | { |
318 | { |
319 | printf("\n\rCalibrating pressure sensor.."); |
319 | printf("\n\rCalibrating pressure sensor.."); |
320 | timer = SetDelay(1000); |
320 | timer = SetDelay(1000); |
321 | SucheLuftruckOffset(); |
321 | SucheLuftruckOffset(); |
322 | while (!CheckDelay(timer)); |
322 | while (!CheckDelay(timer)); |
323 | printf("OK\n\r"); |
323 | printf("OK\n\r"); |
324 | } |
324 | } |
325 | 325 | ||
326 | SetNeutral(); |
326 | SetNeutral(); |
327 | 327 | ||
328 | ROT_OFF; |
328 | ROT_OFF; |
329 | 329 | ||
330 | beeptime = 2000; |
330 | beeptime = 2000; |
331 | ExternControl.Digital[0] = 0x55; |
331 | ExternControl.Digital[0] = 0x55; |
332 | 332 | ||
333 | 333 | ||
334 | printf("\n\rControl: "); |
334 | printf("\n\rControl: "); |
335 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
335 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
336 | else printf("Normal (ACC-Mode)"); |
336 | else printf("Normal (ACC-Mode)"); |
337 | 337 | ||
338 | LcdClear(); |
338 | LcdClear(); |
339 | I2CTimeout = 5000; |
339 | I2CTimeout = 5000; |
340 | WinkelOut.Orientation = 1; |
340 | WinkelOut.Orientation = 1; |
341 | LipoDetection(1); |
341 | LipoDetection(1); |
342 | printf("\n\r===================================\n\r"); |
342 | printf("\n\r===================================\n\r"); |
343 | //SpektrumBinding(); |
343 | //SpektrumBinding(); |
344 | timer = SetDelay(100); |
344 | timer = SetDelay(100); |
345 | while (1) |
345 | while (1) |
346 | { |
346 | { |
347 | if(UpdateMotor && AdReady) // ReglerIntervall |
347 | if(UpdateMotor && AdReady) // ReglerIntervall |
348 | { |
348 | { |
349 | UpdateMotor=0; |
349 | UpdateMotor=0; |
350 | if(WinkelOut.CalcState) CalMk3Mag(); |
350 | if(WinkelOut.CalcState) CalMk3Mag(); |
351 | else MotorRegler(); |
351 | else MotorRegler(); |
352 | SendMotorData(); |
352 | SendMotorData(); |
353 | ROT_OFF; |
353 | ROT_OFF; |
354 | if(SenderOkay) SenderOkay--; |
354 | if(SenderOkay) SenderOkay--; |
355 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
355 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
356 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
356 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
357 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
357 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
358 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
358 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
359 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
359 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | if(NaviDataOkay) |
360 | if(NaviDataOkay) |
361 | { |
361 | { |
362 | if(--NaviDataOkay == 0) |
362 | if(--NaviDataOkay == 0) |
363 | { |
363 | { |
364 | GPS_Nick = 0; |
364 | GPS_Nick = 0; |
365 | GPS_Roll = 0; |
365 | GPS_Roll = 0; |
366 | } |
366 | } |
367 | } |
367 | } |
368 | if(!--I2CTimeout || MissingMotor) |
368 | if(!--I2CTimeout || MissingMotor) |
369 | { |
369 | { |
370 | if(!I2CTimeout) |
370 | if(!I2CTimeout) |
371 | { |
371 | { |
372 | i2c_reset(); |
372 | i2c_reset(); |
373 | I2CTimeout = 5; |
373 | I2CTimeout = 5; |
- | 374 | DebugOut.Analog[28]++; // I2C-Error |
|
374 | } |
375 | } |
375 | if((BeepMuster == 0xffff) && MotorenEin) |
376 | if((BeepMuster == 0xffff) && MotorenEin) |
376 | { |
377 | { |
377 | beeptime = 10000; |
378 | beeptime = 10000; |
378 | BeepMuster = 0x0080; |
379 | BeepMuster = 0x0080; |
379 | } |
380 | } |
380 | } |
381 | } |
381 | else |
382 | else |
382 | { |
383 | { |
383 | ROT_OFF; |
384 | ROT_OFF; |
384 | } |
385 | } |
385 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
386 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
386 | { |
387 | { |
387 | DatenUebertragung(); |
388 | DatenUebertragung(); |
388 | BearbeiteRxDaten(); |
389 | BearbeiteRxDaten(); |
389 | } |
390 | } |
390 | else BearbeiteRxDaten(); |
391 | else BearbeiteRxDaten(); |
391 | if(CheckDelay(timer)) |
392 | if(CheckDelay(timer)) |
392 | { |
393 | { |
393 | timer += 20;//SetDelay(20); |
394 | timer += 20;//SetDelay(20); |
394 | if(PcZugriff) PcZugriff--; |
395 | if(PcZugriff) PcZugriff--; |
395 | else |
396 | else |
396 | { |
397 | { |
397 | ExternControl.Config = 0; |
398 | ExternControl.Config = 0; |
398 | ExternStickNick = 0; |
399 | ExternStickNick = 0; |
399 | ExternStickRoll = 0; |
400 | ExternStickRoll = 0; |
400 | ExternStickGier = 0; |
401 | ExternStickGier = 0; |
401 | if(BeepMuster == 0xffff && SenderOkay == 0) |
402 | if(BeepMuster == 0xffff && SenderOkay == 0) |
402 | { |
403 | { |
403 | beeptime = 15000; |
404 | beeptime = 15000; |
404 | BeepMuster = 0x0c00; |
405 | BeepMuster = 0x0c00; |
405 | } |
406 | } |
406 | } |
407 | } |
407 | if(UBat < BattLowVoltageWarning) |
408 | if(UBat < BattLowVoltageWarning) |
408 | { |
409 | { |
409 | MikroKopterFlags |= FLAG_LOWBAT; |
410 | MikroKopterFlags |= FLAG_LOWBAT; |
410 | if(BeepMuster == 0xffff) |
411 | if(BeepMuster == 0xffff) |
411 | { |
412 | { |
412 | beeptime = 6000; |
413 | beeptime = 6000; |
413 | BeepMuster = 0x0300; |
414 | BeepMuster = 0x0300; |
414 | } |
415 | } |
415 | } |
416 | } |
416 | else MikroKopterFlags &= ~FLAG_LOWBAT; |
417 | else MikroKopterFlags &= ~FLAG_LOWBAT; |
417 | SPI_StartTransmitPacket(); |
418 | SPI_StartTransmitPacket(); |
418 | SendSPI = 4; |
419 | SendSPI = 4; |
419 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
420 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
420 | if(++timer2 == 2930) // eine Minute |
421 | if(++timer2 == 2930) // eine Minute |
421 | { |
422 | { |
422 | timer2 = 0; |
423 | timer2 = 0; |
423 | FlugMinuten++; |
424 | FlugMinuten++; |
424 | FlugMinutenGesamt++; |
425 | FlugMinutenGesamt++; |
425 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); // ACC-NeutralWerte speichern |
426 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); // ACC-NeutralWerte speichern |
426 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); // ACC-NeutralWerte speichern |
427 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); // ACC-NeutralWerte speichern |
427 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); // ACC-NeutralWerte speichern |
428 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); // ACC-NeutralWerte speichern |
428 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); // ACC-NeutralWerte speichern |
429 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); // ACC-NeutralWerte speichern |
429 | } |
430 | } |
430 | } |
431 | } |
431 | LED_Update(); |
432 | LED_Update(); |
432 | } |
433 | } |
433 | if(!SendSPI) { SPI_TransmitByte(); } |
434 | if(!SendSPI) { SPI_TransmitByte(); } |
434 | } |
435 | } |
435 | return (1); |
436 | return (1); |
436 | } |
437 | } |
437 | 438 | ||
438 | 439 | ||
439 | 440 |