Rev 2676 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2676 | Rev 2679 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
2 | // + www.MikroKopter.com |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // + Software Nutzungsbedingungen (english version: see below) |
4 | // + Software Nutzungsbedingungen (english version: see below) |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
19 | // + des Mitverschuldens offen. |
19 | // + des Mitverschuldens offen. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Software LICENSING TERMS |
29 | // + Software LICENSING TERMS |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
34 | // + The Software may only be used with the Licensor's products. |
34 | // + The Software may only be used with the Licensor's products. |
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
37 | // + agreement shall be the property of the Licensor. |
37 | // + agreement shall be the property of the Licensor. |
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
40 | // + The customer shall be responsible for taking reasonable precautions |
40 | // + The customer shall be responsible for taking reasonable precautions |
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
50 | // + #### END OF LICENSING TERMS #### |
50 | // + #### END OF LICENSING TERMS #### |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | #include "main.h" |
53 | #include "main.h" |
54 | unsigned char DisableRcOffBeeping = 1; |
54 | unsigned char DisableRcOffBeeping = 1; |
55 | unsigned char PlatinenVersion = 10; |
55 | unsigned char PlatinenVersion = 10; |
56 | unsigned char BattLowVoltageWarning = 94; |
56 | unsigned char BattLowVoltageWarning = 94; |
57 | unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0; |
57 | unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0; |
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
59 | unsigned int FlugSekunden = 0; |
59 | unsigned int FlugSekunden = 0; |
60 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
60 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
61 | unsigned char FoundMotors = 0; |
61 | unsigned char FoundMotors = 0; |
62 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
62 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
63 | unsigned char ActiveParamSet = 3; |
63 | unsigned char ActiveParamSet = 3; |
64 | unsigned char LipoCells = 4; |
64 | unsigned char LipoCells = 4; |
65 | unsigned char IamMaster = 0; |
65 | unsigned char IamMaster = 0; |
66 | unsigned char Delete_Stoppflag_Timer = 0; |
66 | unsigned char Delete_Stoppflag_Timer = 0; |
67 | unsigned char OEM_String[17] = "Booting... \0\0\0\0\0"; |
67 | unsigned char OEM_String[17] = "Booting... \0\0\0\0\0"; |
68 | - | ||
- | 68 | unsigned char TouchDownTimer = 0; |
|
69 | 69 | ||
70 | void PrintLine(void) |
70 | void PrintLine(void) |
71 | { |
71 | { |
72 | printf("\r\n==================================="); |
72 | printf("\r\n==================================="); |
73 | } |
73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void CalMk3Mag(void) |
76 | void CalMk3Mag(void) |
77 | { |
77 | { |
78 | static unsigned char stick = 1; |
78 | static unsigned char stick = 1; |
79 | ChannelAssingment(); |
79 | ChannelAssingment(); |
80 | if(ChannelNick > -20) stick = 0; |
80 | if(ChannelNick > -20) stick = 0; |
81 | if((ChannelNick < -70) && !stick) |
81 | if((ChannelNick < -70) && !stick) |
82 | { |
82 | { |
83 | stick = 1; |
83 | stick = 1; |
84 | WinkelOut.CalcState++; |
84 | WinkelOut.CalcState++; |
85 | if(WinkelOut.CalcState > 4) |
85 | if(WinkelOut.CalcState > 4) |
86 | { |
86 | { |
87 | // WinkelOut.CalcState = 0; // in SPI.c |
87 | // WinkelOut.CalcState = 0; // in SPI.c |
88 | beeptime = 1000; |
88 | beeptime = 1000; |
89 | } |
89 | } |
90 | else Piep(WinkelOut.CalcState,150); |
90 | else Piep(WinkelOut.CalcState,150); |
91 | } |
91 | } |
92 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
92 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
93 | ShowCmpsCalibrateTime = 6; |
93 | ShowCmpsCalibrateTime = 6; |
94 | #endif |
94 | #endif |
95 | } |
95 | } |
96 | 96 | ||
97 | void LipoDetection(unsigned char print) |
97 | void LipoDetection(unsigned char print) |
98 | { |
98 | { |
99 | unsigned int warning; |
99 | unsigned int warning; |
100 | #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO |
100 | #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO |
101 | if(print) |
101 | if(print) |
102 | { |
102 | { |
103 | printf("\r\nBatt:"); |
103 | printf("\r\nBatt:"); |
104 | LipoCells = 1 + UBat / MAX_CELL_VOLTAGE; |
104 | LipoCells = 1 + UBat / MAX_CELL_VOLTAGE; |
105 | if(LipoCells > 6) LipoCells = 6; |
105 | if(LipoCells > 6) LipoCells = 6; |
106 | } |
106 | } |
107 | 107 | ||
108 | if(EE_Parameter.UnterspannungsWarnung < 50) |
108 | if(EE_Parameter.UnterspannungsWarnung < 50) |
109 | { |
109 | { |
110 | warning = LipoCells * EE_Parameter.UnterspannungsWarnung; |
110 | warning = LipoCells * EE_Parameter.UnterspannungsWarnung; |
111 | if(print) |
111 | if(print) |
112 | { |
112 | { |
113 | Piep(LipoCells, 200); |
113 | Piep(LipoCells, 200); |
114 | printf(" %d Cells ", LipoCells); |
114 | printf(" %d Cells ", LipoCells); |
115 | } |
115 | } |
116 | } |
116 | } |
117 | else warning = EE_Parameter.UnterspannungsWarnung; |
117 | else warning = EE_Parameter.UnterspannungsWarnung; |
118 | if(warning > 255) warning = 255; BattLowVoltageWarning = warning; |
118 | if(warning > 255) warning = 255; BattLowVoltageWarning = warning; |
119 | // automatische Zellenerkennung |
119 | // automatische Zellenerkennung |
120 | if(EE_Parameter.AutoLandingVoltage < 50) warning = LipoCells * EE_Parameter.AutoLandingVoltage; else warning = EE_Parameter.AutoLandingVoltage; |
120 | if(EE_Parameter.AutoLandingVoltage < 50) warning = LipoCells * EE_Parameter.AutoLandingVoltage; else warning = EE_Parameter.AutoLandingVoltage; |
121 | if(warning > 255) warning = 255; BattAutoLandingVoltage = warning; |
121 | if(warning > 255) warning = 255; BattAutoLandingVoltage = warning; |
122 | 122 | ||
123 | if(EE_Parameter.ComingHomeVoltage < 50) warning = LipoCells * EE_Parameter.ComingHomeVoltage; else warning = EE_Parameter.ComingHomeVoltage; |
123 | if(EE_Parameter.ComingHomeVoltage < 50) warning = LipoCells * EE_Parameter.ComingHomeVoltage; else warning = EE_Parameter.ComingHomeVoltage; |
124 | if(warning > 255) warning = 255; BattComingHomeVoltage = warning; |
124 | if(warning > 255) warning = 255; BattComingHomeVoltage = warning; |
125 | 125 | ||
126 | if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1; |
126 | if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1; |
127 | if(BattComingHomeVoltage >= BattLowVoltageWarning) BattComingHomeVoltage = BattLowVoltageWarning - 1; |
127 | if(BattComingHomeVoltage >= BattLowVoltageWarning) BattComingHomeVoltage = BattLowVoltageWarning - 1; |
128 | if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1; |
128 | if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1; |
129 | 129 | ||
130 | if(print) |
130 | if(print) |
131 | { |
131 | { |
132 | printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
132 | printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
133 | if(BattComingHomeVoltage) printf(" Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10); |
133 | if(BattComingHomeVoltage) printf(" Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10); |
134 | if(BattAutoLandingVoltage) printf(" Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10); |
134 | if(BattAutoLandingVoltage) printf(" Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10); |
135 | } |
135 | } |
136 | 136 | ||
137 | } |
137 | } |
138 | 138 | ||
139 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
139 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
140 | void LoadStoreSingleWP(void) |
140 | void LoadStoreSingleWP(void) |
141 | { |
141 | { |
142 | // +++++++++++++++++++++++++++++++++++++++++++ |
142 | // +++++++++++++++++++++++++++++++++++++++++++ |
143 | // + Load/Store one single point |
143 | // + Load/Store one single point |
144 | // +++++++++++++++++++++++++++++++++++++++++++ |
144 | // +++++++++++++++++++++++++++++++++++++++++++ |
145 | static unsigned char switch_hyterese = 0, hyterese = 1, wp_tmp_s = 0, wp_tmp_l = 0; |
145 | static unsigned char switch_hyterese = 0, hyterese = 1, wp_tmp_s = 0, wp_tmp_l = 0; |
146 | static int delay; |
146 | static int delay; |
147 | 147 | ||
148 | if(PPM_in[EE_Parameter.SingleWpControlChannel] > 50) // Switch Up -> load |
148 | if(PPM_in[EE_Parameter.SingleWpControlChannel] > 50) // Switch Up -> load |
149 | { |
149 | { |
150 | if(switch_hyterese == 1 || switch_hyterese == 3) |
150 | if(switch_hyterese == 1 || switch_hyterese == 3) |
151 | { |
151 | { |
152 | ToNC_Load_SingePoint = 1; |
152 | ToNC_Load_SingePoint = 1; |
153 | switch_hyterese = 2; |
153 | switch_hyterese = 2; |
154 | SpeakHoTT = SPEAK_NEXT_WP; |
154 | SpeakHoTT = SPEAK_NEXT_WP; |
155 | Show_Load_Time = 5; |
155 | Show_Load_Time = 5; |
156 | Show_Load_Value = 1; |
156 | Show_Load_Value = 1; |
157 | wp_tmp_l = 1; |
157 | wp_tmp_l = 1; |
158 | } |
158 | } |
159 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
159 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
160 | // Bedienung per Taster am Sender |
160 | // Bedienung per Taster am Sender |
161 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
161 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
162 | { |
162 | { |
163 | hyterese = 2; |
163 | hyterese = 2; |
164 | if(CheckDelay(delay)) { wp_tmp_l = 0; hyterese = 1;} |
164 | if(CheckDelay(delay)) { wp_tmp_l = 0; hyterese = 1;} |
165 | } |
165 | } |
166 | else |
166 | else |
167 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
167 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
168 | { |
168 | { |
169 | delay = SetDelay(2500); |
169 | delay = SetDelay(2500); |
170 | if(hyterese == 2 && (wp_tmp_l < NaviData_MaxWpListIndex)) |
170 | if(hyterese == 2 && (wp_tmp_l < NaviData_MaxWpListIndex)) |
171 | { |
171 | { |
172 | wp_tmp_l++; |
172 | wp_tmp_l++; |
173 | ToNC_Load_SingePoint = wp_tmp_l; |
173 | ToNC_Load_SingePoint = wp_tmp_l; |
174 | Show_Load_Time = 5; |
174 | Show_Load_Time = 5; |
175 | Show_Load_Value = wp_tmp_l; |
175 | Show_Load_Value = wp_tmp_l; |
176 | SpeakHoTT = SPEAK_NEXT_WP; |
176 | SpeakHoTT = SPEAK_NEXT_WP; |
177 | } |
177 | } |
178 | hyterese = 0; |
178 | hyterese = 0; |
179 | } |
179 | } |
180 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
180 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
181 | } |
181 | } |
182 | else |
182 | else |
183 | if(PPM_in[EE_Parameter.SingleWpControlChannel] < -50) // Switch Down -> store |
183 | if(PPM_in[EE_Parameter.SingleWpControlChannel] < -50) // Switch Down -> store |
184 | { |
184 | { |
185 | if(switch_hyterese == 1 || switch_hyterese == 2) |
185 | if(switch_hyterese == 1 || switch_hyterese == 2) |
186 | { |
186 | { |
187 | ToNC_Store_SingePoint = 1; |
187 | ToNC_Store_SingePoint = 1; |
188 | switch_hyterese = 3; |
188 | switch_hyterese = 3; |
189 | SpeakHoTT = SPEAK_MIKROKOPTER; |
189 | SpeakHoTT = SPEAK_MIKROKOPTER; |
190 | Show_Store_Time = 5; |
190 | Show_Store_Time = 5; |
191 | Show_Store_Value = 1; |
191 | Show_Store_Value = 1; |
192 | wp_tmp_s = 1; |
192 | wp_tmp_s = 1; |
193 | } |
193 | } |
194 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
194 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
195 | // Bedienung per Taster am Sender |
195 | // Bedienung per Taster am Sender |
196 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
196 | if(PPM_in[EE_Parameter.MenuKeyChannel] > 50) // |
197 | { |
197 | { |
198 | hyterese = 2; |
198 | hyterese = 2; |
199 | if(CheckDelay(delay)) { wp_tmp_s = 0; hyterese = 1;} |
199 | if(CheckDelay(delay)) { wp_tmp_s = 0; hyterese = 1;} |
200 | } |
200 | } |
201 | else |
201 | else |
202 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
202 | if(PPM_in[EE_Parameter.MenuKeyChannel] < 0) |
203 | { |
203 | { |
204 | delay = SetDelay(2500); |
204 | delay = SetDelay(2500); |
205 | if(hyterese == 2 && (wp_tmp_s < NaviData_MaxWpListIndex)) |
205 | if(hyterese == 2 && (wp_tmp_s < NaviData_MaxWpListIndex)) |
206 | { |
206 | { |
207 | wp_tmp_s++; |
207 | wp_tmp_s++; |
208 | ToNC_Store_SingePoint = wp_tmp_s; |
208 | ToNC_Store_SingePoint = wp_tmp_s; |
209 | Show_Store_Time = 5; |
209 | Show_Store_Time = 5; |
210 | Show_Store_Value = wp_tmp_s; |
210 | Show_Store_Value = wp_tmp_s; |
211 | SpeakHoTT = SPEAK_MIKROKOPTER; |
211 | SpeakHoTT = SPEAK_MIKROKOPTER; |
212 | } |
212 | } |
213 | hyterese = 0; |
213 | hyterese = 0; |
214 | } |
214 | } |
215 | } |
215 | } |
216 | else // Middle |
216 | else // Middle |
217 | { |
217 | { |
218 | switch_hyterese = 1; |
218 | switch_hyterese = 1; |
219 | } |
219 | } |
220 | } |
220 | } |
221 | // +++++++++++++++++++++++++++++++++++++++++++ |
221 | // +++++++++++++++++++++++++++++++++++++++++++ |
222 | #endif |
222 | #endif |
223 | 223 | ||
224 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
224 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
225 | // check if ServoControl is serial Poti and if yes: check if there is valid data |
225 | // check if ServoControl is serial Poti and if yes: check if there is valid data |
226 | void InitSerialPoti(void) |
226 | void InitSerialPoti(void) |
227 | { |
227 | { |
228 | unsigned char i; |
228 | unsigned char i; |
229 | if(!SerialChannelDataOkay) |
229 | if(!SerialChannelDataOkay) |
230 | { |
230 | { |
231 | if(EE_Parameter.ServoNickControl >= 248) // Poti-Value |
231 | if(EE_Parameter.ServoNickControl >= 248) // Poti-Value |
232 | { |
232 | { |
233 | i = 255 - EE_Parameter.ServoNickControl; // Poti-number |
233 | i = 255 - EE_Parameter.ServoNickControl; // Poti-number |
234 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
234 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
235 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
235 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
236 | { |
236 | { |
237 | if(EE_Parameter.ServoFS_Pos[0]) PPM_in[i] = EE_Parameter.ServoFS_Pos[0] - 127; // there is a failsafe position |
237 | if(EE_Parameter.ServoFS_Pos[0]) PPM_in[i] = EE_Parameter.ServoFS_Pos[0] - 127; // there is a failsafe position |
238 | else PPM_in[i] = 0; // middle position |
238 | else PPM_in[i] = 0; // middle position |
239 | } |
239 | } |
240 | } |
240 | } |
241 | if(EE_Parameter.ServoRollControl >= 248) // Poti-Value |
241 | if(EE_Parameter.ServoRollControl >= 248) // Poti-Value |
242 | { |
242 | { |
243 | i = 255 - EE_Parameter.ServoRollControl; // Poti-number |
243 | i = 255 - EE_Parameter.ServoRollControl; // Poti-number |
244 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
244 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
245 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
245 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
246 | { |
246 | { |
247 | if(EE_Parameter.ServoFS_Pos[1]) PPM_in[i] = EE_Parameter.ServoFS_Pos[1] - 127; |
247 | if(EE_Parameter.ServoFS_Pos[1]) PPM_in[i] = EE_Parameter.ServoFS_Pos[1] - 127; |
248 | else PPM_in[i] = 0; // middle position |
248 | else PPM_in[i] = 0; // middle position |
249 | } |
249 | } |
250 | } |
250 | } |
251 | if(EE_Parameter.Servo3 >= 248) // Poti-Value |
251 | if(EE_Parameter.Servo3 >= 248) // Poti-Value |
252 | { |
252 | { |
253 | i = 255 - EE_Parameter.Servo3; // Poti-number |
253 | i = 255 - EE_Parameter.Servo3; // Poti-number |
254 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
254 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
255 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
255 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
256 | { |
256 | { |
257 | if(EE_Parameter.ServoFS_Pos[2]) PPM_in[i] = EE_Parameter.ServoFS_Pos[2] - 127; |
257 | if(EE_Parameter.ServoFS_Pos[2]) PPM_in[i] = EE_Parameter.ServoFS_Pos[2] - 127; |
258 | else PPM_in[i] = 0; // middle position |
258 | else PPM_in[i] = 0; // middle position |
259 | } |
259 | } |
260 | } |
260 | } |
261 | if(EE_Parameter.Servo4 >= 248) // Poti-Value |
261 | if(EE_Parameter.Servo4 >= 248) // Poti-Value |
262 | { |
262 | { |
263 | i = 255 - EE_Parameter.Servo4; // Poti-number |
263 | i = 255 - EE_Parameter.Servo4; // Poti-number |
264 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
264 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
265 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
265 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
266 | { |
266 | { |
267 | if(EE_Parameter.ServoFS_Pos[3]) PPM_in[i] = EE_Parameter.ServoFS_Pos[3] - 127; |
267 | if(EE_Parameter.ServoFS_Pos[3]) PPM_in[i] = EE_Parameter.ServoFS_Pos[3] - 127; |
268 | else PPM_in[i] = 0; // middle position |
268 | else PPM_in[i] = 0; // middle position |
269 | } |
269 | } |
270 | } |
270 | } |
271 | if(EE_Parameter.Servo5 >= 248) // Poti-Value |
271 | if(EE_Parameter.Servo5 >= 248) // Poti-Value |
272 | { |
272 | { |
273 | i = 255 - EE_Parameter.Servo5; // Poti-number |
273 | i = 255 - EE_Parameter.Servo5; // Poti-number |
274 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
274 | i = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
275 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
275 | if(i >= SERIAL_POTI_START && i <= SERIAL_POTI_END) // value comes from a serial poti |
276 | { |
276 | { |
277 | if(EE_Parameter.ServoFS_Pos[4]) PPM_in[i] = EE_Parameter.ServoFS_Pos[4] - 127; |
277 | if(EE_Parameter.ServoFS_Pos[4]) PPM_in[i] = EE_Parameter.ServoFS_Pos[4] - 127; |
278 | else PPM_in[i] = 0; // middle position |
278 | else PPM_in[i] = 0; // middle position |
279 | } |
279 | } |
280 | } |
280 | } |
281 | } |
281 | } |
282 | } |
282 | } |
283 | 283 | ||
284 | //############################################################################ |
284 | //############################################################################ |
285 | //Hauptprogramm |
285 | //Hauptprogramm |
286 | int main (void) |
286 | int main (void) |
287 | //############################################################################ |
287 | //############################################################################ |
288 | { |
288 | { |
289 | unsigned int timer,i,timer2 = 0, timerPolling; |
289 | unsigned int timer,i,timer2 = 0, timerPolling; |
290 | unsigned char update_spi = 1; |
290 | unsigned char update_spi = 1; |
291 | DDRB = 0x00; |
291 | DDRB = 0x00; |
292 | PORTB = 0x00; |
292 | PORTB = 0x00; |
293 | DDRD = 0x0A; // UART & J3 J4 J5 |
293 | DDRD = 0x0A; // UART & J3 J4 J5 |
294 | PORTD = 0x7F; // PPM-Input & UART |
294 | PORTD = 0x7F; // PPM-Input & UART |
295 | for(timer = 0; timer < 1000; timer++); // verzögern |
295 | for(timer = 0; timer < 1000; timer++); // verzögern |
296 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
296 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
297 | unsigned char AccZ_ErrorCnt = 0; |
297 | unsigned char AccZ_ErrorCnt = 0; |
298 | if(PINB & 0x02) |
298 | if(PINB & 0x02) |
299 | { |
299 | { |
300 | if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND |
300 | if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND |
301 | else { PlatinenVersion = 22; ACC_AltitudeControl = 1;}; |
301 | else { PlatinenVersion = 22; ACC_AltitudeControl = 1;}; |
302 | } |
302 | } |
303 | else |
303 | else |
304 | { |
304 | { |
305 | PlatinenVersion = LIBFC_Get_HW_Version(25); |
305 | PlatinenVersion = LIBFC_Get_HW_Version(25); |
306 | ACC_AltitudeControl = 1; |
306 | ACC_AltitudeControl = 1; |
307 | J4Low; |
307 | J4Low; |
308 | } |
308 | } |
309 | /* |
309 | /* |
310 | if(PlatinenVersion >= 30) -> wird noch der #define gemacht |
310 | if(PlatinenVersion >= 30) -> wird noch der #define gemacht |
311 | { |
311 | { |
312 | if(!(PIND & 0x20)) IamMaster = SLAVE; // Slave |
312 | if(!(PIND & 0x20)) IamMaster = SLAVE; // Slave |
313 | else IamMaster = MASTER; // Master |
313 | else IamMaster = MASTER; // Master |
314 | } |
314 | } |
315 | */ |
315 | */ |
316 | #else |
316 | #else |
317 | if(PINB & 0x01) |
317 | if(PINB & 0x01) |
318 | { |
318 | { |
319 | if(PINB & 0x02) PlatinenVersion = 13; |
319 | if(PINB & 0x02) PlatinenVersion = 13; |
320 | else PlatinenVersion = 11; |
320 | else PlatinenVersion = 11; |
321 | } |
321 | } |
322 | else |
322 | else |
323 | { |
323 | { |
324 | if(PINB & 0x02) PlatinenVersion = 20; |
324 | if(PINB & 0x02) PlatinenVersion = 20; |
325 | else |
325 | else |
326 | { |
326 | { |
327 | PlatinenVersion = 10; |
327 | PlatinenVersion = 10; |
328 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
328 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
329 | PORTD = 0x47; // |
329 | PORTD = 0x47; // |
330 | } |
330 | } |
331 | } |
331 | } |
332 | #endif |
332 | #endif |
333 | 333 | ||
334 | DDRC = 0x81; // I2C, Spaker |
334 | DDRC = 0x81; // I2C, Spaker |
335 | DDRC |=0x40; // HEF4017 Reset |
335 | DDRC |=0x40; // HEF4017 Reset |
336 | PORTC = 0xff; // Pullup SDA |
336 | PORTC = 0xff; // Pullup SDA |
337 | DDRB = 0x1B; // LEDs und Druckoffset |
337 | DDRB = 0x1B; // LEDs und Druckoffset |
338 | PORTB = 0x05; // LED_Rot & pullup on PB2 (RC-Voltage detection) |
338 | PORTB = 0x05; // LED_Rot & pullup on PB2 (RC-Voltage detection) |
339 | 339 | ||
340 | HEF4017Reset_ON; |
340 | HEF4017Reset_ON; |
341 | MCUSR &=~(1<<WDRF); |
341 | MCUSR &=~(1<<WDRF); |
342 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
342 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
343 | WDTCSR = 0; |
343 | WDTCSR = 0; |
344 | 344 | ||
345 | beeptime = 2500; |
345 | beeptime = 2500; |
346 | StickGier = 0; StickRoll = 0; StickNick = 0; |
346 | StickGier = 0; StickRoll = 0; StickNick = 0; |
347 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
347 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
348 | ROT_OFF; |
348 | ROT_OFF; |
349 | GRN_ON; |
349 | GRN_ON; |
350 | 350 | ||
351 | Timer_Init(); |
351 | Timer_Init(); |
352 | TIMER2_Init(); |
352 | TIMER2_Init(); |
353 | UART_Init(); |
353 | UART_Init(); |
354 | rc_sum_init(); |
354 | rc_sum_init(); |
355 | ADC_Init(); |
355 | ADC_Init(); |
356 | I2C_Init(1); |
356 | I2C_Init(1); |
357 | SPI_MasterInit(); |
357 | SPI_MasterInit(); |
358 | Capacity_Init(); |
358 | Capacity_Init(); |
359 | LIBFC_Init(LIB_FC_COMPATIBLE); |
359 | LIBFC_Init(LIB_FC_COMPATIBLE); |
360 | GRN_ON; |
360 | GRN_ON; |
361 | sei(); |
361 | sei(); |
362 | ParamSet_Init(); |
362 | ParamSet_Init(); |
363 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
363 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
364 | if(PlatinenVersion < 20) |
364 | if(PlatinenVersion < 20) |
365 | { |
365 | { |
366 | wdt_enable(WDTO_250MS); // Reset-Commando |
366 | wdt_enable(WDTO_250MS); // Reset-Commando |
367 | while(1) printf("\r\nOld FC Hardware not supported by this Firmware!"); |
367 | while(1) printf("\r\nOld FC Hardware not supported by this Firmware!"); |
368 | } |
368 | } |
369 | #ifndef REDUNDANT_FC_SLAVE |
369 | #ifndef REDUNDANT_FC_SLAVE |
370 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
370 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
371 | // + Check connected BL-Ctrls |
371 | // + Check connected BL-Ctrls |
372 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
372 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
373 | // Check connected BL-Ctrls |
373 | // Check connected BL-Ctrls |
374 | BLFlags |= BLFLAG_READ_VERSION; |
374 | BLFlags |= BLFLAG_READ_VERSION; |
375 | motor_read = 0; // read the first I2C-Data |
375 | motor_read = 0; // read the first I2C-Data |
376 | for(i=0; i < 500; i++) |
376 | for(i=0; i < 500; i++) |
377 | { |
377 | { |
378 | SendMotorData(); |
378 | SendMotorData(); |
379 | timer = SetDelay(5); |
379 | timer = SetDelay(5); |
380 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
380 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
381 | } |
381 | } |
382 | printf("\r\nFound BL-Ctrl: "); |
382 | printf("\r\nFound BL-Ctrl: "); |
383 | // timer = SetDelay(1000); |
383 | // timer = SetDelay(1000); |
384 | for(i=0; i < MAX_MOTORS; i++) |
384 | for(i=0; i < MAX_MOTORS; i++) |
385 | { |
385 | { |
386 | // SendMotorData(); |
386 | // SendMotorData(); |
387 | // while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
387 | // while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
388 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
388 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
389 | { |
389 | { |
390 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
390 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
391 | { |
391 | { |
392 | if((BLFlags & BLFLAG_TX_COMPLETE)) SendMotorData(); |
392 | if((BLFlags & BLFLAG_TX_COMPLETE)) SendMotorData(); |
393 | //while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
393 | //while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
394 | } |
394 | } |
395 | } |
395 | } |
396 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
396 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
397 | { |
397 | { |
398 | unsigned char vers; |
398 | unsigned char vers; |
399 | printf("%d",(i+1)%10); |
399 | printf("%d",(i+1)%10); |
400 | FoundMotors++; |
400 | FoundMotors++; |
401 | vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04 |
401 | vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04 |
402 | if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers; |
402 | if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers; |
403 | //if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)"); |
403 | //if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)"); |
404 | //if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)"); |
404 | //if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)"); |
405 | //printf(":V%03d\r\n",vers); |
405 | //printf(":V%03d\r\n",vers); |
406 | } |
406 | } |
407 | } |
407 | } |
408 | for(i=0; i < MAX_MOTORS; i++) |
408 | for(i=0; i < MAX_MOTORS; i++) |
409 | { |
409 | { |
410 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
410 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
411 | { |
411 | { |
412 | printf("\r\n\r\n!! MISSING BL-CTRL: %d !!",i+1); |
412 | printf("\r\n\r\n!! MISSING BL-CTRL: %d !!",i+1); |
413 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
413 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
414 | } |
414 | } |
415 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
415 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
416 | } |
416 | } |
417 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
417 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
418 | if(VersionInfo.BL_Firmware != 255) |
418 | if(VersionInfo.BL_Firmware != 255) |
419 | { |
419 | { |
420 | printf("\r\nBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100); |
420 | printf("\r\nBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100); |
421 | if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!"); |
421 | if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!"); |
422 | } |
422 | } |
423 | #endif |
423 | #endif |
424 | 424 | ||
425 | PrintLine();// ("\r\n==================================="); |
425 | PrintLine();// ("\r\n==================================="); |
426 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
426 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
427 | if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors; |
427 | if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors; |
428 | #else |
428 | #else |
429 | printf("\r\n\r\n--> REDUNDANT SLAVE <---\r\n"); |
429 | printf("\r\n\r\n--> REDUNDANT SLAVE <---\r\n"); |
430 | IamMaster = SLAVE; |
430 | IamMaster = SLAVE; |
431 | #endif |
431 | #endif |
432 | 432 | ||
433 | #ifdef REDUNDANT_FC_MASTER |
433 | #ifdef REDUNDANT_FC_MASTER |
434 | printf("\r\n\r\n--> REDUNDANT MASTER <---\r\n"); |
434 | printf("\r\n\r\n--> REDUNDANT MASTER <---\r\n"); |
435 | IamMaster = MASTER; |
435 | IamMaster = MASTER; |
436 | #endif |
436 | #endif |
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
438 | // Calibrating altitude sensor |
438 | // Calibrating altitude sensor |
439 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
439 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
440 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
440 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
441 | { |
441 | { |
442 | printf("\r\nCalibrating pressure sensor.."); |
442 | printf("\r\nCalibrating pressure sensor.."); |
443 | timer = SetDelay(1000); |
443 | timer = SetDelay(1000); |
444 | SucheLuftruckOffset(); |
444 | SucheLuftruckOffset(); |
445 | while (!CheckDelay(timer)); |
445 | while (!CheckDelay(timer)); |
446 | printf("OK\r\n"); |
446 | printf("OK\r\n"); |
447 | } |
447 | } |
448 | 448 | ||
449 | #ifdef REDUNDANT_FC_SLAVE |
449 | #ifdef REDUNDANT_FC_SLAVE |
450 | VersionInfo.HardwareError[0] = 0; |
450 | VersionInfo.HardwareError[0] = 0; |
451 | VersionInfo.HardwareError[1] = 0; |
451 | VersionInfo.HardwareError[1] = 0; |
452 | #endif |
452 | #endif |
453 | 453 | ||
454 | SetNeutral(0); |
454 | SetNeutral(0); |
455 | 455 | ||
456 | ROT_OFF; |
456 | ROT_OFF; |
457 | 457 | ||
458 | beeptime = 2000; |
458 | beeptime = 2000; |
459 | 459 | ||
460 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
460 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
461 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
461 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
462 | 462 | ||
463 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
463 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
464 | { |
464 | { |
465 | FlugMinuten = 0; |
465 | FlugMinuten = 0; |
466 | FlugMinutenGesamt = 0; |
466 | FlugMinutenGesamt = 0; |
467 | } |
467 | } |
468 | printf("\r\nFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
468 | printf("\r\nFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
469 | LcdClear(); |
469 | LcdClear(); |
470 | I2CTimeout = 5000; |
470 | I2CTimeout = 5000; |
471 | WinkelOut.Orientation = 1; |
471 | WinkelOut.Orientation = 1; |
472 | LipoDetection(1); |
472 | LipoDetection(1); |
473 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
473 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
474 | PrintLine();// ("\r\n==================================="); |
474 | PrintLine();// ("\r\n==================================="); |
475 | //SpektrumBinding(); |
475 | //SpektrumBinding(); |
476 | timer = SetDelay(2000); |
476 | timer = SetDelay(2000); |
477 | timerPolling = SetDelay(250); |
477 | timerPolling = SetDelay(250); |
478 | 478 | ||
479 | Debug(ANSI_CLEAR "FC-Start!\r\nFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
479 | Debug(ANSI_CLEAR "FC-Start!\r\nFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
480 | if(PARAMSET_STRUCT_LEN != 179) while(1) printf("\r\nEE_Parameter size:%i", PARAMSET_STRUCT_LEN); |
480 | if(PARAMSET_STRUCT_LEN != 179) while(1) printf("\r\nEE_Parameter size:%i", PARAMSET_STRUCT_LEN); |
481 | 481 | ||
482 | DebugOut.Status[0] = 0x01 | 0x02; |
482 | DebugOut.Status[0] = 0x01 | 0x02; |
483 | JetiBeep = 0; |
483 | JetiBeep = 0; |
484 | if(!(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)) DisableRcOffBeeping = 0; |
484 | if(!(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)) DisableRcOffBeeping = 0; |
485 | ReadBlSize = 3; // don't read the version any more |
485 | ReadBlSize = 3; // don't read the version any more |
486 | if(PlatinenVersion < 30) OEM_String[0] = 0xff; |
486 | if(PlatinenVersion < 30) OEM_String[0] = 0xff; |
487 | #ifdef REDUNDANT_FC_SLAVE |
487 | #ifdef REDUNDANT_FC_SLAVE |
488 | timer = SetDelay(2500); |
488 | timer = SetDelay(2500); |
489 | while(!CheckDelay(timer)); |
489 | while(!CheckDelay(timer)); |
490 | printf("\r\nStart\r\n"); |
490 | printf("\r\nStart\r\n"); |
491 | #endif |
491 | #endif |
492 | while(1) |
492 | while(1) |
493 | { |
493 | { |
494 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
494 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
495 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
495 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
496 | if(UpdateMotor && AdReady) // ReglerIntervall |
496 | if(UpdateMotor && AdReady) // ReglerIntervall |
497 | { |
497 | { |
498 | cli(); |
498 | cli(); |
499 | UpdateMotor--; |
499 | UpdateMotor--; |
500 | sei(); |
500 | sei(); |
501 | if(WinkelOut.CalcState) CalMk3Mag(); |
501 | if(WinkelOut.CalcState) CalMk3Mag(); |
502 | else MotorRegler(); |
502 | else MotorRegler(); |
503 | SendMotorData(); |
503 | SendMotorData(); |
504 | ROT_OFF; |
504 | ROT_OFF; |
505 | 505 | ||
506 | if(SenderOkay > ReceiverOkay) ReceiverOkay = SenderOkay; |
506 | if(SenderOkay > ReceiverOkay) ReceiverOkay = SenderOkay; |
507 | 507 | ||
508 | if(ReceiverOkay) ReceiverOkay--; |
508 | if(ReceiverOkay) ReceiverOkay--; |
509 | else |
509 | else |
510 | { |
510 | { |
511 | ChannelNick = 0; |
511 | ChannelNick = 0; |
512 | ChannelRoll = 0; |
512 | ChannelRoll = 0; |
513 | ChannelYaw = 0; |
513 | ChannelYaw = 0; |
514 | ChannelGas = 0; |
514 | ChannelGas = 0; |
515 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
515 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
516 | } |
516 | } |
517 | 517 | ||
518 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
518 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
519 | else |
519 | else |
520 | { |
520 | { |
521 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
521 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
522 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
522 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
523 | // Now clear the channel values - they would be wrong |
523 | // Now clear the channel values - they would be wrong |
524 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
524 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
525 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
525 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
526 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
526 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
527 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
527 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
528 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
528 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
529 | PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
529 | PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
530 | } |
530 | } |
531 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
532 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
532 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
533 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
533 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
534 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
534 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
535 | if(!--I2CTimeout || MissingMotor) |
535 | if(!--I2CTimeout || MissingMotor) |
536 | { |
536 | { |
537 | if(!I2CTimeout) |
537 | if(!I2CTimeout) |
538 | { |
538 | { |
539 | I2C_Reset(); |
539 | I2C_Reset(); |
540 | I2CTimeout = 5; |
540 | I2CTimeout = 5; |
541 | DebugOut.Analog[28]++; // I2C-Error |
541 | DebugOut.Analog[28]++; // I2C-Error |
542 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
542 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
543 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
543 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
544 | } |
544 | } |
545 | if((BeepMuster == 0xffff) && MotorenEin) |
545 | if((BeepMuster == 0xffff) && MotorenEin) |
546 | { |
546 | { |
547 | beeptime = 25000; |
547 | beeptime = 25000; |
548 | BeepMuster = 0x0080; |
548 | BeepMuster = 0x0080; |
549 | } |
549 | } |
550 | } |
550 | } |
551 | else |
551 | else |
552 | { |
552 | { |
553 | ROT_OFF; |
553 | ROT_OFF; |
554 | } |
554 | } |
555 | LIBFC_Polling(); |
555 | LIBFC_Polling(); |
556 | 556 | ||
557 | if(!UpdateMotor) |
557 | if(!UpdateMotor) |
558 | { |
558 | { |
559 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
559 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
560 | if(NewSBusData) ProcessSBus(); |
560 | if(NewSBusData) ProcessSBus(); |
561 | else |
561 | else |
562 | if(NewMlinkData) ProcessMlinkData(); |
562 | if(NewMlinkData) ProcessMlinkData(); |
563 | else |
563 | else |
564 | #endif |
564 | #endif |
565 | { |
565 | { |
566 | if(BytegapSPI == 0) SPI_TransmitByte(); |
566 | if(BytegapSPI == 0) SPI_TransmitByte(); |
567 | if(CalculateServoSignals) CalculateServo(0); |
567 | if(CalculateServoSignals) CalculateServo(0); |
568 | DatenUebertragung(); |
568 | DatenUebertragung(); |
569 | BearbeiteRxDaten(); |
569 | BearbeiteRxDaten(); |
570 | if(!(PINB & 0x04)) VersionInfo.HardwareError[1] |= FC_ERROR1_RC_VOLTAGE; |
570 | if(!(PINB & 0x04)) VersionInfo.HardwareError[1] |= FC_ERROR1_RC_VOLTAGE; |
571 | if(CheckDelay(timer)) |
571 | if(CheckDelay(timer)) |
572 | { |
572 | { |
573 | static unsigned char second; |
573 | static unsigned char second; |
574 | timer += 20; // 20 ms interval |
574 | timer += 20; // 20 ms interval |
575 | //DebugOut.Analog[] = LuftdruckTemperaturOffset; |
575 | //DebugOut.Analog[] = LuftdruckTemperaturOffset; |
576 | CalcNickServoValue(); |
576 | CalcNickServoValue(); |
577 | if(!CalibrationDone) FC_StatusFlags3 |= FC_STATUS3_NOT_CALIBRATED; else FC_StatusFlags3 &= ~FC_STATUS3_NOT_CALIBRATED; |
577 | if(!CalibrationDone) FC_StatusFlags3 |= FC_STATUS3_NOT_CALIBRATED; else FC_StatusFlags3 &= ~FC_STATUS3_NOT_CALIBRATED; |
578 | // ++++++++++++++++++++++++++++ |
578 | // ++++++++++++++++++++++++++++ |
579 | // + New direction setpoint from NC |
579 | // + New direction setpoint from NC |
580 | if((NC_CompassSetpoint != -1) && !NeueKompassRichtungMerken) |
580 | if((NC_CompassSetpoint != -1) && !NeueKompassRichtungMerken) |
581 | { |
581 | { |
582 | int diff; |
582 | int diff; |
583 | if((KompassSollWert != NC_CompassSetpoint) && (CareFree || NCForcesNewDirection)) |
583 | if((KompassSollWert != NC_CompassSetpoint) && (CareFree || NCForcesNewDirection)) |
584 | { |
584 | { |
585 | diff = ((540 + (KompassSollWert - NC_CompassSetpoint)) % 360) - 180; |
585 | diff = ((540 + (KompassSollWert - NC_CompassSetpoint)) % 360) - 180; |
586 | if(diff > 2) diff = 2; // max. 2° in 20ms = 100°/sec |
586 | if(diff > 2) diff = 2; // max. 2° in 20ms = 100°/sec |
587 | else |
587 | else |
588 | if(diff < -2) diff = -2; |
588 | if(diff < -2) diff = -2; |
589 | KompassSollWert -= diff; |
589 | KompassSollWert -= diff; |
590 | } |
590 | } |
591 | else |
591 | else |
592 | { |
592 | { |
593 | NC_CompassSetpoint = -1; |
593 | NC_CompassSetpoint = -1; |
594 | NCForcesNewDirection = 0; // allows Yawing without CareFree (Yawing at Coming Home) |
594 | NCForcesNewDirection = 0; // allows Yawing without CareFree (Yawing at Coming Home) |
595 | } |
595 | } |
596 | } |
596 | } |
597 | // ++++++++++++++++++++++++++++ |
597 | // ++++++++++++++++++++++++++++ |
598 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
598 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
599 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
599 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
600 | else |
600 | else |
601 | if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario(); |
601 | if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario(); |
602 | // ++++++++++++++++++++++++++++ |
602 | // ++++++++++++++++++++++++++++ |
603 | // + check the ACC-Z range |
603 | // + check the ACC-Z range |
604 | if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil |
604 | if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil |
605 | { |
605 | { |
606 | if(++AccZ_ErrorCnt > 50) |
606 | if(++AccZ_ErrorCnt > 50) |
607 | { |
607 | { |
608 | if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; |
608 | if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; |
609 | else CalibrationDone = 0; |
609 | else CalibrationDone = 0; |
610 | } |
610 | } |
611 | } |
611 | } |
612 | else AccZ_ErrorCnt = 0; |
612 | else AccZ_ErrorCnt = 0; |
613 | // ++++++++++++++++++++++++++++ |
613 | // ++++++++++++++++++++++++++++ |
614 | #endif |
614 | #endif |
615 | if(MissingMotor || Capacity.MinOfMaxPWM < 30) |
615 | if(MissingMotor || Capacity.MinOfMaxPWM < 30) |
616 | { |
616 | { |
617 | if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
617 | if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
618 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
618 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
619 | } |
619 | } |
620 | else |
620 | else |
621 | { |
621 | { |
622 | if(!beeptime) |
622 | if(!beeptime) |
623 | { |
623 | { |
624 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
624 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
625 | } |
625 | } |
626 | } |
626 | } |
627 | if(DisableRcOffBeeping) if(ReceiverOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
627 | if(DisableRcOffBeeping) if(ReceiverOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
628 | if(PcZugriff) PcZugriff--; |
628 | if(PcZugriff) PcZugriff--; |
629 | else |
629 | else |
630 | { |
630 | { |
631 | if(!ReceiverOkay) |
631 | if(!ReceiverOkay) |
632 | { |
632 | { |
633 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
633 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
634 | { |
634 | { |
635 | beeptime = 15000; |
635 | beeptime = 15000; |
636 | BeepMuster = 0x0c00; |
636 | BeepMuster = 0x0c00; |
637 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
637 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
638 | } |
638 | } |
639 | } |
639 | } |
640 | } |
640 | } |
641 | if(NaviDataOkay > 200) |
641 | if(NaviDataOkay > 200) |
642 | { |
642 | { |
643 | NaviDataOkay--; |
643 | NaviDataOkay--; |
644 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
644 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
645 | VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT; |
645 | VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT; |
646 | } |
646 | } |
647 | else |
647 | else |
648 | { |
648 | { |
649 | if(NC_Version.Compatible) |
649 | if(NC_Version.Compatible) |
650 | { |
650 | { |
651 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
651 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
652 | NC_ErrorCode = 9; // "ERR: no NC communication" |
652 | NC_ErrorCode = 9; // "ERR: no NC communication" |
653 | if(BeepMuster == 0xffff && MotorenEin) |
653 | if(BeepMuster == 0xffff && MotorenEin) |
654 | { |
654 | { |
655 | beeptime = 15000; |
655 | beeptime = 15000; |
656 | BeepMuster = 0xA800; |
656 | BeepMuster = 0xA800; |
657 | } |
657 | } |
658 | } |
658 | } |
659 | GPS_Nick = 0; |
659 | GPS_Nick = 0; |
660 | GPS_Roll = 0; |
660 | GPS_Roll = 0; |
661 | GPS_Aid_StickMultiplikator = 0; |
661 | GPS_Aid_StickMultiplikator = 0; |
662 | GPSInfo.Flags = 0; |
662 | GPSInfo.Flags = 0; |
663 | FromNaviCtrl_Value.Kalman_K = -1; |
663 | FromNaviCtrl_Value.Kalman_K = -1; |
664 | FromNaviCtrl.AccErrorN = 0; |
664 | FromNaviCtrl.AccErrorN = 0; |
665 | FromNaviCtrl.AccErrorR = 0; |
665 | FromNaviCtrl.AccErrorR = 0; |
666 | FromNaviCtrl.CompassValue = -1; |
666 | FromNaviCtrl.CompassValue = -1; |
667 | FromNC_AltitudeSpeed = 0; |
667 | FromNC_AltitudeSpeed = 0; |
668 | FromNC_AltitudeSetpoint = 0; |
668 | FromNC_AltitudeSetpoint = 0; |
669 | VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT; |
669 | VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT; |
670 | NC_To_FC_Flags = 0; |
670 | NC_To_FC_Flags = 0; |
671 | NaviDataOkay = 0; |
671 | NaviDataOkay = 0; |
672 | } |
672 | } |
673 | if(UBat <= BattLowVoltageWarning) |
673 | if(UBat <= BattLowVoltageWarning) |
674 | { |
674 | { |
675 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
675 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
676 | if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB) |
676 | if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB) |
677 | { |
677 | { |
678 | beeptime = 6000; |
678 | beeptime = 6000; |
679 | BeepMuster = 0x0300; |
679 | BeepMuster = 0x0300; |
680 | } |
680 | } |
681 | } |
681 | } |
682 | // +++++++++++++++++++++++++++++++++ |
682 | // +++++++++++++++++++++++++++++++++ |
683 | if(ExternalControlTimeout) |
683 | if(ExternalControlTimeout) |
684 | { |
684 | { |
685 | ExternalControlTimeout--; |
685 | ExternalControlTimeout--; |
686 | if(ExternalControlTimeout == 1) |
686 | if(ExternalControlTimeout == 1) |
687 | { |
687 | { |
688 | ExternalControl.Config = 0; |
688 | ExternalControl.Config = 0; |
689 | beeptime = 2000; |
689 | beeptime = 2000; |
690 | } |
690 | } |
691 | } |
691 | } |
692 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
692 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
693 | // +++++++++++++++++++++++++++++++++++++++++++ |
693 | // +++++++++++++++++++++++++++++++++++++++++++ |
694 | // + Load/Store one single point |
694 | // + Load/Store one single point |
695 | // +++++++++++++++++++++++++++++++++++++++++++ |
695 | // +++++++++++++++++++++++++++++++++++++++++++ |
696 | if(EE_Parameter.SingleWpControlChannel) LoadStoreSingleWP(); |
696 | if(EE_Parameter.SingleWpControlChannel) LoadStoreSingleWP(); |
697 | // +++++++++++++++++++++++++++++++++++++++++++ |
697 | // +++++++++++++++++++++++++++++++++++++++++++ |
698 | #endif |
698 | #endif |
699 | #ifdef NO_RECEIVER |
699 | #ifdef NO_RECEIVER |
700 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
700 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0; |
701 | PPM_in[EE_Parameter.HoeheChannel] = (unsigned char) 200; |
701 | PPM_in[EE_Parameter.HoeheChannel] = (unsigned char) 200; |
702 | PPM_in[EE_Parameter.NaviGpsModeChannel] = (unsigned char) 200; |
702 | PPM_in[EE_Parameter.NaviGpsModeChannel] = (unsigned char) 200; |
703 | PPM_in[EE_Parameter.CareFreeChannel] = (unsigned char) 200; |
703 | PPM_in[EE_Parameter.CareFreeChannel] = (unsigned char) 200; |
704 | SenderOkay = 180; |
704 | SenderOkay = 180; |
705 | MotorenEin = 0; |
705 | MotorenEin = 0; |
706 | #endif |
706 | #endif |
707 | if(BaroExpandCnt > 0) BaroExpandCnt--; |
707 | if(BaroExpandCnt > 0) BaroExpandCnt--; |
708 | else |
708 | else |
709 | if(BaroExpandCnt < 0) BaroExpandCnt++; |
709 | if(BaroExpandCnt < 0) BaroExpandCnt++; |
710 | 710 | ||
711 | // +++++++++++++++++++++++++++++++++ |
711 | // +++++++++++++++++++++++++++++++++ |
712 | // Sekundentakt |
712 | // Sekundentakt |
713 | if(++second == 49) |
713 | if(++second == 49) |
714 | { |
714 | { |
- | 715 | static long altitudeOld = 0; |
|
- | 716 | static char threeseconds = 3; |
|
- | 717 | ||
715 | second = 0; |
718 | second = 0; |
716 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
719 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
717 | if(ShowSettingNameTime) ShowSettingNameTime--; |
720 | if(ShowSettingNameTime) ShowSettingNameTime--; |
718 | if(Show_Load_Time) Show_Load_Time--; |
721 | if(Show_Load_Time) Show_Load_Time--; |
719 | if(Show_Store_Time) Show_Store_Time--; |
722 | if(Show_Store_Time) Show_Store_Time--; |
720 | if(ShowCmpsCalibrateTime) ShowCmpsCalibrateTime--; |
723 | if(ShowCmpsCalibrateTime) ShowCmpsCalibrateTime--; |
721 | if(Delete_Stoppflag_Timer) Delete_Stoppflag_Timer--; else FC_StatusFlags3 &= ~FC_STATUS3_MOTORS_STOPPED_BY_RC; |
724 | if(Delete_Stoppflag_Timer) Delete_Stoppflag_Timer--; else FC_StatusFlags3 &= ~FC_STATUS3_MOTORS_STOPPED_BY_RC; |
722 | #endif |
725 | #endif |
- | 726 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 727 | // + for auto switch - off |
|
- | 728 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 729 | if(--threeseconds == 0) |
|
- | 730 | { |
|
- | 731 | int AltitudeDeviationPer3Seconds = 0; |
|
- | 732 | threeseconds = 3; |
|
- | 733 | AltitudeDeviationPer3Seconds = HoehenWert - altitudeOld; |
|
- | 734 | altitudeOld = HoehenWert; |
|
- | 735 | if(abs(AltitudeDeviationPer3Seconds) > 90) TouchDownTimer = 0; |
|
- | 736 | if(!MotorenEin) TouchDownTimer = 0; |
|
- | 737 | } |
|
- | 738 | if(ACC_AltitudeControl && HoehenReglerAktiv && (SollHoehe < (HoehenWert-1100)) && !(VersionInfo.HardwareError[0] & FC_ERROR0_PRESSURE)) // 11m unter Sollwert |
|
- | 739 | { |
|
- | 740 | if(TouchDownTimer < 255) TouchDownTimer++; |
|
- | 741 | } |
|
- | 742 | else TouchDownTimer = 0; |
|
- | 743 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 744 | if( (NC_To_FC_Flags & NC_TO_FC_SWITCHOFF_IF_LANDED) || // for auto landing waypoints points |
|
- | 745 | (NC_To_FC_Flags & NC_TO_FC_FAILSAFE_LANDING) || // for RC failsafe |
|
- | 746 | (LowVoltageLandingActive) || // undervoltage |
|
- | 747 | (FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING) // Auto landing by switch |
|
- | 748 | ) |
|
- | 749 | { |
|
- | 750 | if(TouchDownTimer == 6) SpeakHoTT = SPEAK_SINKING; |
|
- | 751 | else |
|
- | 752 | if(TouchDownTimer == 9) |
|
- | 753 | { |
|
- | 754 | SpeakHoTT = SPEAK_LANDING; |
|
- | 755 | } |
|
- | 756 | else |
|
- | 757 | if(TouchDownTimer == 16) |
|
- | 758 | { |
|
- | 759 | FC_StatusFlags3 |= FC_STATUS3_MOTORS_STOPPED_BY_RC; // that informs the slave to disarm the Motors |
|
- | 760 | Delete_Stoppflag_Timer = 2; // 1-2 seconds |
|
- | 761 | MotorenEin = 0; |
|
- | 762 | modell_fliegt = 0; |
|
- | 763 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
|
- | 764 | SpeakHoTT = SPEAK_MK_OFF; |
|
- | 765 | } |
|
- | 766 | } |
|
- | 767 | else TouchDownTimer = 0; |
|
- | 768 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 769 | ||
723 | if(SerialChannelDataOkay) if(--SerialChannelDataOkay == 0) InitSerialPoti(); |
770 | if(SerialChannelDataOkay) if(--SerialChannelDataOkay == 0) InitSerialPoti(); |
724 | if(NC_To_FC_Flags & NC_TO_FC_FAILSAFE_LANDING) ServoFailsafeActive = SERVO_FS_TIME; |
771 | if(NC_To_FC_Flags & NC_TO_FC_FAILSAFE_LANDING) ServoFailsafeActive = SERVO_FS_TIME; |
725 | else |
772 | else |
726 | if(ServoFailsafeActive) ServoFailsafeActive--; |
773 | if(ServoFailsafeActive) ServoFailsafeActive--; |
727 | 774 | ||
728 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
775 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
729 | else timer2 = 1450; // 0,5 Minuten aufrunden |
776 | else timer2 = 1450; // 0,5 Minuten aufrunden |
730 | if(modell_fliegt < 1024 && !BaroCalState) |
777 | if(modell_fliegt < 1024 && !BaroCalState) |
731 | { |
778 | { |
732 | if(StartLuftdruck < LuftdruckKompensiert) StartLuftdruck += 5; |
779 | if(StartLuftdruck < LuftdruckKompensiert) StartLuftdruck += 5; |
733 | else |
780 | else |
734 | if(StartLuftdruck > LuftdruckKompensiert) StartLuftdruck -= 5; |
781 | if(StartLuftdruck > LuftdruckKompensiert) StartLuftdruck -= 5; |
735 | FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
782 | FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
736 | } |
783 | } |
737 | else |
784 | else |
738 | { |
785 | { |
739 | #ifdef REDUNDANT_FC_MASTER |
786 | #ifdef REDUNDANT_FC_MASTER |
740 | if(!(FC_StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE)) FC_StatusFlags3 |= FC_STATUS3_REDUNDANCE_ERROR; |
787 | if(!(FC_StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE)) FC_StatusFlags3 |= FC_STATUS3_REDUNDANCE_ERROR; |
741 | else FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
788 | else FC_StatusFlags3 &= ~FC_STATUS3_REDUNDANCE_ERROR; |
742 | #endif |
789 | #endif |
743 | } |
790 | } |
744 | if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
791 | if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
745 | TIMSK2 |= (1<<OCIE2A); // enable Servo-Interrupt now |
792 | TIMSK2 |= (1<<OCIE2A); // enable Servo-Interrupt now |
746 | } |
793 | } |
747 | // +++++++++++++++++++++++++++++++++ |
794 | // +++++++++++++++++++++++++++++++++ |
748 | if(++timer2 == 2930) // eine Minute |
795 | if(++timer2 == 2930) // eine Minute |
749 | { |
796 | { |
750 | timer2 = 0; |
797 | timer2 = 0; |
751 | FlugMinuten++; |
798 | FlugMinuten++; |
752 | FlugMinutenGesamt++; |
799 | FlugMinutenGesamt++; |
753 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
800 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
754 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
801 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
755 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
802 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
756 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
803 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
757 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
804 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
758 | } |
805 | } |
759 | } |
806 | } |
760 | LED_Update(); |
807 | LED_Update(); |
761 | Capacity_Update(); |
808 | Capacity_Update(); |
762 | } |
809 | } |
763 | } //else DebugOut.Analog[18]++; |
810 | } //else DebugOut.Analog[18]++; |
764 | if(update_spi) update_spi--; |
811 | if(update_spi) update_spi--; |
765 | } // 500Hz |
812 | } // 500Hz |
766 | if(update_spi == 0) // 41Hz |
813 | if(update_spi == 0) // 41Hz |
767 | { |
814 | { |
768 | if(!MotorenEin && NC_RequestsConfig) { SendSettingToNC(); update_spi = 12;} |
815 | if(!MotorenEin && NC_RequestsConfig) { SendSettingToNC(); update_spi = 12;} |
769 | else |
816 | else |
770 | if(SPI_StartTransmitPacket()) update_spi = 12; |
817 | if(SPI_StartTransmitPacket()) update_spi = 12; |
771 | else |
818 | else |
772 | if(BytegapSPI == 0) SPI_TransmitByte(); |
819 | if(BytegapSPI == 0) SPI_TransmitByte(); |
773 | } |
820 | } |
774 | else if(BytegapSPI == 0) SPI_TransmitByte(); |
821 | else if(BytegapSPI == 0) SPI_TransmitByte(); |
775 | } |
822 | } |
776 | } |
823 | } |
777 | //DebugOut.Analog[] |
824 | //DebugOut.Analog[] |
778 | 825 | ||
779 | 826 | ||
780 | 827 |