Rev 1424 | Rev 1435 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1424 | Rev 1431 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
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 oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung oder Nutzung 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 the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
39 | // + * porting the sources to other systems or using the software on other systems (except 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], 12); // 12 Kanäle merken |
76 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 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 | void SetActiveParamSetNumber(unsigned char number) |
93 | void SetActiveParamSetNumber(unsigned char number) |
94 | { |
94 | { |
95 | if(number > 5) number = 5; |
95 | if(number > 5) number = 5; |
96 | if(number < 1) return; |
96 | if(number < 1) return; |
97 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
97 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
98 | } |
98 | } |
99 | 99 | ||
100 | 100 | ||
101 | void CalMk3Mag(void) |
101 | void CalMk3Mag(void) |
102 | { |
102 | { |
103 | static unsigned char stick = 1; |
103 | static unsigned char stick = 1; |
104 | 104 | ||
105 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
105 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
106 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
106 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
107 | { |
107 | { |
108 | stick = 1; |
108 | stick = 1; |
109 | WinkelOut.CalcState++; |
109 | WinkelOut.CalcState++; |
110 | if(WinkelOut.CalcState > 4) |
110 | if(WinkelOut.CalcState > 4) |
111 | { |
111 | { |
112 | // WinkelOut.CalcState = 0; // in Uart.c |
112 | // WinkelOut.CalcState = 0; // in Uart.c |
113 | beeptime = 1000; |
113 | beeptime = 1000; |
114 | } |
114 | } |
115 | else Piep(WinkelOut.CalcState,150); |
115 | else Piep(WinkelOut.CalcState,150); |
116 | } |
116 | } |
117 | DebugOut.Analog[19] = WinkelOut.CalcState; |
117 | DebugOut.Analog[19] = WinkelOut.CalcState; |
118 | } |
118 | } |
119 | 119 | ||
120 | void LipoDetection(unsigned char print) |
120 | void LipoDetection(unsigned char print) |
121 | { |
121 | { |
122 | unsigned int timer; |
122 | unsigned int timer; |
123 | if(print) printf("\n\rBatt:"); |
123 | if(print) printf("\n\rBatt:"); |
124 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
124 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
125 | { |
125 | { |
126 | timer = SetDelay(500); |
126 | timer = SetDelay(500); |
127 | if(print) while (!CheckDelay(timer)); |
127 | if(print) while (!CheckDelay(timer)); |
128 | if(UBat < 130) |
128 | if(UBat < 130) |
129 | { |
129 | { |
130 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
130 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
131 | if(print) |
131 | if(print) |
132 | { |
132 | { |
133 | Piep(3,200); |
133 | Piep(3,200); |
134 | printf(" 3 Cells "); |
134 | printf(" 3 Cells "); |
135 | } |
135 | } |
136 | } |
136 | } |
137 | else |
137 | else |
138 | { |
138 | { |
139 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
139 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
140 | if(print) |
140 | if(print) |
141 | { |
141 | { |
142 | Piep(4,200); |
142 | Piep(4,200); |
143 | printf(" 4 Cells "); |
143 | printf(" 4 Cells "); |
144 | } |
144 | } |
145 | } |
145 | } |
146 | } |
146 | } |
147 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
147 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
148 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
148 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
149 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
149 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
150 | } |
150 | } |
151 | 151 | ||
152 | //############################################################################ |
152 | //############################################################################ |
153 | //Hauptprogramm |
153 | //Hauptprogramm |
154 | int main (void) |
154 | int main (void) |
155 | //############################################################################ |
155 | //############################################################################ |
156 | { |
156 | { |
157 | unsigned int timer,i,timer2 = 0, timerPolling; |
157 | unsigned int timer,i,timer2 = 0, timerPolling; |
158 | DDRB = 0x00; |
158 | DDRB = 0x00; |
159 | PORTB = 0x00; |
159 | PORTB = 0x00; |
160 | for(timer = 0; timer < 1000; timer++); // verzögern |
160 | for(timer = 0; timer < 1000; timer++); // verzögern |
161 | if(PINB & 0x01) |
161 | if(PINB & 0x01) |
162 | { |
162 | { |
163 | if(PINB & 0x02) PlatinenVersion = 13; |
163 | if(PINB & 0x02) PlatinenVersion = 13; |
164 | else PlatinenVersion = 11; |
164 | else PlatinenVersion = 11; |
165 | } |
165 | } |
166 | else |
166 | else |
167 | { |
167 | { |
168 | if(PINB & 0x02) PlatinenVersion = 20; |
168 | if(PINB & 0x02) PlatinenVersion = 20; |
169 | else PlatinenVersion = 10; |
169 | else PlatinenVersion = 10; |
170 | } |
170 | } |
171 | 171 | ||
172 | DDRC = 0x81; // SCL |
172 | DDRC = 0x81; // SCL |
173 | DDRC |=0x40; // HEF4017 Reset |
173 | DDRC |=0x40; // HEF4017 Reset |
174 | PORTC = 0xff; // Pullup SDA |
174 | PORTC = 0xff; // Pullup SDA |
175 | DDRB = 0x1B; // LEDs und Druckoffset |
175 | DDRB = 0x1B; // LEDs und Druckoffset |
176 | PORTB = 0x01; // LED_Rot |
176 | PORTB = 0x01; // LED_Rot |
177 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
177 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
178 | PORTD = 0x47; // LED |
178 | PORTD = 0x47; // LED |
179 | HEF4017R_ON; |
179 | HEF4017R_ON; |
180 | MCUSR &=~(1<<WDRF); |
180 | MCUSR &=~(1<<WDRF); |
181 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
181 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
182 | WDTCSR = 0; |
182 | WDTCSR = 0; |
183 | 183 | ||
184 | beeptime = 2000; |
184 | beeptime = 2000; |
185 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
185 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
186 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
186 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
187 | ROT_OFF; |
187 | ROT_OFF; |
188 | 188 | ||
189 | Timer_Init(); |
189 | Timer_Init(); |
190 | TIMER2_Init(); |
190 | TIMER2_Init(); |
191 | UART_Init(); |
191 | UART_Init(); |
192 | rc_sum_init(); |
192 | rc_sum_init(); |
193 | ADC_Init(); |
193 | ADC_Init(); |
194 | i2c_init(); |
194 | i2c_init(); |
195 | SPI_MasterInit(); |
195 | SPI_MasterInit(); |
196 | 196 | ||
197 | InitFC(); |
197 | InitFC(); |
198 | - | ||
199 | sei(); |
- | |
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'); |
- | |
202 | printf("\n\rthe use of this software is only permitted \n\ron original MikroKopter-Hardware"); |
- | |
203 | printf("\n\rwww.MikroKopter.de (c) HiSystems GmbH"); |
- | |
204 | printf("\n\r==================================="); |
198 | |
- | 199 | ||
- | 200 | GRN_ON; |
|
205 | 201 | sei(); |
|
- | 202 | ||
- | 203 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
|
206 | GRN_ON; |
204 | |
207 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
205 | |
208 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
206 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
209 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
207 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
210 | { |
208 | { |
211 | unsigned char i; |
209 | unsigned char i; |
212 | RequiredMotors = 0; |
210 | RequiredMotors = 0; |
213 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
211 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
214 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
212 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
215 | } |
213 | } |
216 | else // default |
214 | else // default |
217 | { |
215 | { |
218 | unsigned char i; |
216 | unsigned char i; |
219 | printf("\n\rGenerating default Mixer Table"); |
217 | printf("\n\rGenerating default Mixer Table"); |
220 | 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;}; |
218 | 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 | // default = Quadro |
219 | // default = Quadro |
222 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
220 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
223 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
221 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
224 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
222 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
225 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
223 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
226 | Mixer.Revision = MIXER_REVISION; |
224 | Mixer.Revision = MIXER_REVISION; |
227 | memcpy(Mixer.Name, "Quadro\0", 11); |
225 | memcpy(Mixer.Name, "Quadro\0", 11); |
228 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
226 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
229 | } |
227 | } |
230 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
228 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
- | 229 | ||
- | 230 | ||
- | 231 | ||
231 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
232 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
232 | // + Check connected BL-Ctrls |
233 | // + Check connected BL-Ctrls |
233 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
234 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
234 | printf("\n\rFound BL-Ctrl: "); |
235 | printf("\n\rFound BL-Ctrl: "); |
235 | 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 |
236 | timer = SetDelay(2000); |
237 | timer = SetDelay(2000); |
237 | 238 | ||
238 | 239 | ||
239 | for(i=0; i < MAX_MOTORS; i++) |
240 | for(i=0; i < MAX_MOTORS; i++) |
240 | { |
241 | { |
241 | UpdateMotor = 0; |
242 | UpdateMotor = 0; |
242 | SendMotorData(); |
243 | SendMotorData(); |
243 | while(!UpdateMotor); |
244 | while(!UpdateMotor); |
244 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
245 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
245 | { |
246 | { |
246 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
247 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
247 | } |
248 | } |
248 | if(MotorPresent[i]) printf("%d ",i+1); |
249 | if(MotorPresent[i]) printf("%d ",i+1); |
249 | } |
250 | } |
250 | for(i=0; i < MAX_MOTORS; i++) |
251 | for(i=0; i < MAX_MOTORS; i++) |
251 | { |
252 | { |
252 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
253 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
253 | { |
254 | { |
254 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
255 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
255 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
256 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
256 | } |
257 | } |
257 | MotorError[i] = 0; |
258 | MotorError[i] = 0; |
258 | } |
259 | } |
259 | printf("\n\r==================================="); |
260 | printf("\n\r==================================="); |
260 | SendMotorData(); |
261 | SendMotorData(); |
261 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
262 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
262 | 263 | ||
263 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
264 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
264 | // + Check Settings |
265 | // + Check Settings |
265 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
267 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
267 | { |
268 | { |
268 | DefaultKonstanten1(); |
269 | DefaultKonstanten1(); |
269 | printf("\n\rInit. EEPROM"); |
270 | printf("\n\rInit. EEPROM"); |
270 | for (unsigned char i=1;i<6;i++) |
271 | for (unsigned char i=1;i<6;i++) |
271 | { |
272 | { |
272 | if(i==2) DefaultKonstanten2(); // Kamera |
273 | if(i==2) DefaultKonstanten2(); // Kamera |
273 | if(i==3) DefaultKonstanten3(); // Beginner |
274 | if(i==3) DefaultKonstanten3(); // Beginner |
274 | if(i>3) DefaultKonstanten2(); // Kamera |
275 | if(i>3) DefaultKonstanten2(); // Kamera |
275 | if(PlatinenVersion >= 20) |
276 | if(PlatinenVersion >= 20) |
276 | { |
277 | { |
277 | EE_Parameter.Gyro_D = 5; |
278 | EE_Parameter.Gyro_D = 5; |
278 | EE_Parameter.Driftkomp = 0; |
279 | EE_Parameter.Driftkomp = 0; |
279 | EE_Parameter.GyroAccFaktor = 27; |
280 | EE_Parameter.GyroAccFaktor = 27; |
280 | EE_Parameter.WinkelUmschlagNick = 78; |
281 | EE_Parameter.WinkelUmschlagNick = 78; |
281 | EE_Parameter.WinkelUmschlagRoll = 78; |
282 | EE_Parameter.WinkelUmschlagRoll = 78; |
282 | } |
283 | } |
283 | // valid Stick-Settings? |
284 | // valid Stick-Settings? |
284 | 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) |
285 | 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) |
285 | { |
286 | { |
286 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
287 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
287 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
288 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
288 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
289 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
289 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
290 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
290 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
291 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
291 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
292 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
292 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
293 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
293 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
294 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
294 | 295 | ||
295 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
296 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
296 | { |
297 | { |
297 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
298 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
298 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
299 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
299 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
300 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
300 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
301 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
301 | } |
302 | } |
302 | else |
303 | else |
303 | { |
304 | { |
304 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
305 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
305 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
306 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
306 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
307 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
307 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
308 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
308 | } |
309 | } |
309 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
310 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
310 | } else DefaultStickMapping(); |
311 | } else DefaultStickMapping(); |
311 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
312 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
312 | } |
313 | } |
313 | SetActiveParamSetNumber(3); // default-Setting |
314 | SetActiveParamSetNumber(3); // default-Setting |
314 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
315 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
315 | } |
316 | } |
- | 317 | ||
- | 318 | ||
316 | 319 | ||
317 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
320 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
318 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
321 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
319 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
322 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
320 | { |
323 | { |
321 | FlugMinuten = 0; |
324 | FlugMinuten = 0; |
322 | FlugMinutenGesamt = 0; |
325 | FlugMinutenGesamt = 0; |
323 | } |
326 | } |
324 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
327 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
325 | 328 | ||
326 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
329 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
327 | { |
330 | { |
328 | printf("\n\rACC not calibrated !"); |
331 | printf("\n\rACC not calibrated !"); |
329 | } |
332 | } |
330 | 333 | ||
331 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
334 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
332 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
335 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
333 | 336 | ||
334 | 337 | ||
335 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
338 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
336 | { |
339 | { |
337 | printf("\n\rCalibrating pressure sensor.."); |
340 | printf("\n\rCalibrating pressure sensor.."); |
338 | timer = SetDelay(1000); |
341 | timer = SetDelay(1000); |
339 | SucheLuftruckOffset(); |
342 | SucheLuftruckOffset(); |
340 | while (!CheckDelay(timer)); |
343 | while (!CheckDelay(timer)); |
341 | printf("OK\n\r"); |
344 | printf("OK\n\r"); |
342 | } |
345 | } |
343 | 346 | ||
344 | SetNeutral(); |
347 | SetNeutral(); |
345 | 348 | ||
346 | ROT_OFF; |
349 | ROT_OFF; |
347 | 350 | ||
348 | beeptime = 2000; |
351 | beeptime = 2000; |
349 | ExternControl.Digital[0] = 0x55; |
352 | ExternControl.Digital[0] = 0x55; |
350 | 353 | ||
351 | 354 | ||
352 | printf("\n\rControl: "); |
355 | printf("\n\rControl: "); |
353 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
356 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
354 | else printf("Normal (ACC-Mode)"); |
357 | else printf("Normal (ACC-Mode)"); |
355 | 358 | ||
356 | LcdClear(); |
359 | LcdClear(); |
357 | I2CTimeout = 5000; |
360 | I2CTimeout = 5000; |
358 | WinkelOut.Orientation = 1; |
361 | WinkelOut.Orientation = 1; |
359 | LipoDetection(1); |
362 | LipoDetection(1); |
- | 363 | ||
- | 364 | InitReceiver(); |
|
360 | printf("\n\r===================================\n\r"); |
365 | printf("\n\r===================================\n\r"); |
361 | //SpektrumBinding(); |
366 | //SpektrumBinding(); |
362 | timer = SetDelay(2000); |
367 | timer = SetDelay(2000); |
363 | timerPolling = SetDelay(250); |
368 | timerPolling = SetDelay(250); |
364 | while (1) |
369 | while (1) |
365 | { |
370 | { |
366 | 371 | ||
367 | if(CheckDelay(timerPolling)) |
372 | if(CheckDelay(timerPolling)) |
368 | { |
373 | { |
369 | timerPolling = SetDelay(100); |
374 | timerPolling = SetDelay(100); |
370 | Polling(); |
375 | Polling(); |
371 | } |
376 | } |
372 | 377 | ||
373 | if(UpdateMotor && AdReady) // ReglerIntervall |
378 | if(UpdateMotor && AdReady) // ReglerIntervall |
374 | { |
379 | { |
375 | UpdateMotor=0; |
380 | UpdateMotor=0; |
376 | if(WinkelOut.CalcState) CalMk3Mag(); |
381 | if(WinkelOut.CalcState) CalMk3Mag(); |
377 | else MotorRegler(); |
382 | else MotorRegler(); |
378 | SendMotorData(); |
383 | SendMotorData(); |
379 | ROT_OFF; |
384 | ROT_OFF; |
380 | if(SenderOkay) SenderOkay--; |
385 | if(SenderOkay) SenderOkay--; |
381 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
386 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
382 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
387 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
383 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
388 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
384 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
389 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
385 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
390 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
386 | 391 | ||
387 | if(!--I2CTimeout || MissingMotor) |
392 | if(!--I2CTimeout || MissingMotor) |
388 | { |
393 | { |
389 | if(!I2CTimeout) |
394 | if(!I2CTimeout) |
390 | { |
395 | { |
391 | i2c_reset(); |
396 | i2c_reset(); |
392 | I2CTimeout = 5; |
397 | I2CTimeout = 5; |
393 | DebugOut.Analog[28]++; // I2C-Error |
398 | DebugOut.Analog[28]++; // I2C-Error |
394 | FCFlags |= FCFLAG_I2CERR; |
399 | FCFlags |= FCFLAG_I2CERR; |
395 | } |
400 | } |
396 | if((BeepMuster == 0xffff) && MotorenEin) |
401 | if((BeepMuster == 0xffff) && MotorenEin) |
397 | { |
402 | { |
398 | beeptime = 10000; |
403 | beeptime = 10000; |
399 | BeepMuster = 0x0080; |
404 | BeepMuster = 0x0080; |
400 | } |
405 | } |
401 | } |
406 | } |
402 | else |
407 | else |
403 | { |
408 | { |
404 | ROT_OFF; |
409 | ROT_OFF; |
405 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
410 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
406 | } |
411 | } |
407 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
412 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
408 | { |
413 | { |
409 | DatenUebertragung(); |
414 | DatenUebertragung(); |
410 | BearbeiteRxDaten(); |
415 | BearbeiteRxDaten(); |
411 | } |
416 | } |
412 | else BearbeiteRxDaten(); |
417 | else BearbeiteRxDaten(); |
413 | if(CheckDelay(timer)) |
418 | if(CheckDelay(timer)) |
414 | { |
419 | { |
415 | timer += 20; // 20 ms interval |
420 | timer += 20; // 20 ms interval |
416 | if(PcZugriff) PcZugriff--; |
421 | if(PcZugriff) PcZugriff--; |
417 | else |
422 | else |
418 | { |
423 | { |
419 | ExternControl.Config = 0; |
424 | ExternControl.Config = 0; |
420 | ExternStickNick = 0; |
425 | ExternStickNick = 0; |
421 | ExternStickRoll = 0; |
426 | ExternStickRoll = 0; |
422 | ExternStickGier = 0; |
427 | ExternStickGier = 0; |
423 | if(BeepMuster == 0xffff && SenderOkay == 0) |
428 | if(BeepMuster == 0xffff && SenderOkay == 0) |
424 | { |
429 | { |
425 | beeptime = 15000; |
430 | beeptime = 15000; |
426 | BeepMuster = 0x0c00; |
431 | BeepMuster = 0x0c00; |
427 | } |
432 | } |
428 | } |
433 | } |
429 | if(NaviDataOkay) |
434 | if(NaviDataOkay) |
430 | { |
435 | { |
431 | NaviDataOkay--; |
436 | NaviDataOkay--; |
432 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
437 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
433 | } |
438 | } |
434 | else |
439 | else |
435 | { |
440 | { |
436 | GPS_Nick = 0; |
441 | GPS_Nick = 0; |
437 | GPS_Roll = 0; |
442 | GPS_Roll = 0; |
438 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
443 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
439 | } |
444 | } |
440 | if(UBat < BattLowVoltageWarning) |
445 | if(UBat < BattLowVoltageWarning) |
441 | { |
446 | { |
442 | FCFlags |= FCFLAG_LOWBAT; |
447 | FCFlags |= FCFLAG_LOWBAT; |
443 | if(BeepMuster == 0xffff) |
448 | if(BeepMuster == 0xffff) |
444 | { |
449 | { |
445 | beeptime = 6000; |
450 | beeptime = 6000; |
446 | BeepMuster = 0x0300; |
451 | BeepMuster = 0x0300; |
447 | } |
452 | } |
448 | } |
453 | } |
449 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
454 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
450 | 455 | ||
451 | SPI_StartTransmitPacket(); |
456 | SPI_StartTransmitPacket(); |
452 | SendSPI = 4; |
457 | SendSPI = 4; |
453 | 458 | ||
454 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
459 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
455 | 460 | ||
456 | if(++timer2 == 2930) // eine Minute |
461 | if(++timer2 == 2930) // eine Minute |
457 | { |
462 | { |
458 | timer2 = 0; |
463 | timer2 = 0; |
459 | FlugMinuten++; |
464 | FlugMinuten++; |
460 | FlugMinutenGesamt++; |
465 | FlugMinutenGesamt++; |
461 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
466 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
462 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
467 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
463 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
468 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
464 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
469 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
465 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
470 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
466 | } |
471 | } |
467 | } |
472 | } |
468 | LED_Update(); |
473 | LED_Update(); |
469 | } |
474 | } |
470 | if(!SendSPI) { SPI_TransmitByte(); } |
475 | if(!SendSPI) { SPI_TransmitByte(); } |
471 | } |
476 | } |
472 | return (1); |
477 | return (1); |
473 | } |
478 | } |
474 | 479 | ||
475 | 480 | ||
476 | 481 |