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