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