Rev 1126 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1126 | Rev 1133 | ||
---|---|---|---|
Line 49... | Line 49... | ||
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" |
Line 53... | Line 53... | ||
53 | 53 | ||
54 | unsigned char EEPromArray[E2END + 1] EEMEM; |
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char PlatinenVersion = 10; |
55 | unsigned char PlatinenVersion = 10; |
56 | unsigned char SendVersionToNavi = 1; |
56 | unsigned char SendVersionToNavi = 1; |
57 | // -- Parametersatz aus EEPROM lesen --- |
57 | // -- Parametersatz aus EEPROM lesen --- |
58 | // number [1..5] |
- | |
59 | 58 | // number [1..5] |
|
- | 59 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
|
60 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) { |
60 | { |
61 | if ((number > 5) || (number < 1)) number = 3; |
61 | if((number > 5)||(number < 1)) number = 3; |
62 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
62 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
63 | LED_Init(); |
63 | LED_Init(); |
Line 64... | Line 64... | ||
64 | } |
64 | } |
65 | 65 | ||
- | 66 | // -- Parametersatz ins EEPROM schreiben --- |
|
- | 67 | // number [1..5] |
|
- | 68 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
|
- | 69 | { |
|
- | 70 | if(number > 5) number = 5; |
|
- | 71 | if(number < 1) return; |
|
- | 72 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
|
- | 73 | SetActiveParamSetNumber(number); |
|
Line 66... | Line -... | ||
66 | // -- Parametersatz ins EEPROM schreiben --- |
- | |
67 | // number [1..5] |
74 | LED_Init(); |
- | 75 | } |
|
68 | 76 | ||
69 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) { |
77 | unsigned char GetActiveParamSetNumber(void) |
- | 78 | { |
|
- | 79 | unsigned char set; |
|
- | 80 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
|
70 | if (number > 5) number = 5; |
81 | if((set > 5) || (set < 1)) |
- | 82 | { |
|
71 | if (number < 1) return; |
83 | set = 3; |
72 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
84 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
Line -... | Line 85... | ||
- | 85 | } |
|
73 | SetActiveParamSetNumber(number); |
86 | return(set); |
74 | LED_Init(); |
- | |
75 | } |
- | |
- | 87 | } |
|
76 | 88 | ||
77 | unsigned char GetActiveParamSetNumber(void) { |
89 | |
78 | unsigned char set; |
90 | void SetActiveParamSetNumber(unsigned char number) |
79 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
- | |
80 | if ((set > 5) || (set < 1)) { |
- | |
81 | set = 3; |
91 | { |
Line 82... | Line -... | ||
82 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
- | |
83 | } |
- | |
84 | return (set); |
- | |
85 | } |
- | |
86 | - | ||
87 | void SetActiveParamSetNumber(unsigned char number) { |
92 | if(number > 5) number = 5; |
88 | if (number > 5) number = 5; |
93 | if(number < 1) return; |
- | 94 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
|
89 | if (number < 1) return; |
95 | } |
90 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
96 | |
91 | } |
97 | |
92 | 98 | void CalMk3Mag(void) |
|
- | 99 | { |
|
93 | void CalMk3Mag(void) { |
100 | static unsigned char stick = 1; |
94 | static unsigned char stick = 1; |
101 | |
95 | 102 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
|
- | 103 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
|
96 | if (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
104 | { |
97 | if ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) { |
105 | stick = 1; |
98 | stick = 1; |
- | |
99 | WinkelOut.CalcState++; |
106 | WinkelOut.CalcState++; |
- | 107 | if(WinkelOut.CalcState > 4) |
|
- | 108 | { |
|
100 | if (WinkelOut.CalcState > 4) { |
109 | // WinkelOut.CalcState = 0; // in Uart.c |
101 | // WinkelOut.CalcState = 0; // in Uart.c |
110 | beeptime = 1000; |
Line 102... | Line 111... | ||
102 | beeptime = 1000; |
111 | } |
103 | } else Piep(WinkelOut.CalcState); |
112 | else Piep(WinkelOut.CalcState); |
104 | } |
- | |
105 | DebugOut.Analog[19] = WinkelOut.CalcState; |
113 | } |
106 | } |
114 | DebugOut.Analog[19] = WinkelOut.CalcState; |
107 | 115 | } |
|
108 | //############################################################################ |
116 | |
Line 109... | Line 117... | ||
109 | //Hauptprogramm |
117 | //############################################################################ |
110 | 118 | //Hauptprogramm |
|
111 | int main(void) |
119 | int main (void) |
112 | //############################################################################ |
120 | //############################################################################ |
113 | { |
121 | { |
- | 122 | unsigned int timer; |
|
114 | unsigned int timer; |
123 | |
115 | 124 | //unsigned int timer2 = 0; |
|
- | 125 | DDRB = 0x00; |
|
116 | //unsigned int timer2 = 0; |
126 | PORTB = 0x00; |
- | 127 | for(timer = 0; timer < 1000; timer++); // verzögern |
|
117 | DDRB = 0x00; |
128 | if(PINB & 0x01) |
118 | PORTB = 0x00; |
129 | { |
119 | for (timer = 0; timer < 1000; timer++); // verzögern |
130 | if(PINB & 0x02) PlatinenVersion = 13; |
Line 120... | Line 131... | ||
120 | if (PINB & 0x01) { |
131 | else PlatinenVersion = 11; |
121 | if (PINB & 0x02) PlatinenVersion = 13; |
132 | } |
122 | else PlatinenVersion = 11; |
133 | else |
123 | } else { |
134 | { |
124 | if (PINB & 0x02) PlatinenVersion = 20; |
135 | if(PINB & 0x02) PlatinenVersion = 20; |
125 | else PlatinenVersion = 10; |
136 | else PlatinenVersion = 10; |
126 | } |
137 | } |
127 | 138 | ||
Line 128... | Line 139... | ||
128 | DDRC = 0x81; // SCL |
139 | DDRC = 0x81; // SCL |
129 | DDRC |= 0x40; // HEF4017 Reset |
140 | DDRC |=0x40; // HEF4017 Reset |
130 | PORTC = 0xff; // Pullup SDA |
141 | PORTC = 0xff; // Pullup SDA |
Line 131... | Line 142... | ||
131 | DDRB = 0x1B; // LEDs und Druckoffset |
142 | DDRB = 0x1B; // LEDs und Druckoffset |
Line 132... | Line -... | ||
132 | PORTB = 0x01; // LED_Rot |
- | |
133 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
143 | PORTB = 0x01; // LED_Rot |
134 | DDRD |= 0x80; // J7 -> Servo signal |
- | |
135 | PORTD = 0x77; // LED |
- | |
Line 136... | Line 144... | ||
136 | 144 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
|
Line 137... | Line 145... | ||
137 | 145 | DDRD |=0x80; // J7 -> Servo signal |
|
138 | MCUSR &= ~(1 << WDRF); |
146 | PORTD = 0x77; // LED |
139 | WDTCSR |= (1 << WDCE) | (1 << WDE); |
147 | |
140 | WDTCSR = 0; |
148 | |
141 | 149 | MCUSR &=~(1<<WDRF); |
|
142 | beeptime = 2000; |
150 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
Line 143... | Line 151... | ||
143 | 151 | WDTCSR = 0; |
|
Line 144... | Line 152... | ||
144 | StickGier = 0; |
152 | |
145 | PPM_in[K_GAS] = 0; |
153 | beeptime = 2000; |
Line 146... | Line 154... | ||
146 | StickRoll = 0; |
154 | |
Line 147... | Line 155... | ||
147 | StickNick = 0; |
155 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
148 | 156 | ||
149 | ROT_OFF; |
157 | ROT_OFF; |
150 | 158 | ||
- | 159 | Timer_Init(); |
|
151 | Timer_Init(); |
160 | UART_Init(); |
152 | UART_Init(); |
161 | rc_sum_init(); |
- | 162 | ADC_Init(); |
|
153 | rc_sum_init(); |
163 | i2c_init(); |
Line 154... | Line 164... | ||
154 | ADC_Init(); |
164 | SPI_MasterInit(); |
- | 165 | ||
155 | i2c_init(); |
166 | sei(); |
156 | SPI_MasterInit(); |
167 | |
- | 168 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
|
157 | 169 | printf("\n\r=============================="); |
|
158 | sei(); |
170 | |
159 | 171 | GRN_ON; |
|
160 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ", PlatinenVersion / 10, PlatinenVersion % 10, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
172 | |
161 | printf("\n\r=============================="); |
173 | |
162 | 174 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
|
163 | GRN_ON; |
175 | // valid Stick-Settings? |
164 | 176 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION || |
|
165 | 177 | EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9) |
|
166 | ReadParameterSet(3, (unsigned char *) & EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
178 | { |
- | 179 | printf("\n\rInit. EEPROM: Generating Default-Parameter and Stick-Settings..."); |
|
167 | // valid Stick-Settings? |
180 | DefaultStickMapping(); |
168 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION || |
181 | } |
Line 169... | Line 182... | ||
169 | EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9) { |
182 | else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings"); |
170 | printf("\n\rInit. EEPROM: Generating Default-Parameter and Stick-Settings..."); |
183 | |
Line 171... | Line 184... | ||
171 | DefaultStickMapping(); |
184 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
- | 185 | { |
|
172 | } else if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings"); |
186 | DefaultKonstanten1(); |
173 | 187 | for (unsigned char i=1;i<6;i++) |
|
174 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) { |
188 | { |
175 | DefaultKonstanten1(); |
189 | if(i==2) DefaultKonstanten2(); // Kamera |
176 | for (unsigned char i = 1; i < 6; i++) { |
190 | if(i==3) DefaultKonstanten3(); // Beginner |
177 | if (i == 2) DefaultKonstanten2(); // Kamera |
191 | if(i>3) DefaultKonstanten2(); // Kamera |
Line 178... | Line 192... | ||
178 | if (i == 3) DefaultKonstanten3(); // Beginner |
192 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
Line 179... | Line 193... | ||
179 | if (i > 3) DefaultKonstanten2(); // Kamera |
193 | } |
Line 180... | Line 194... | ||
180 | WriteParameterSet(i, (unsigned char *) & EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
194 | SetActiveParamSetNumber(3); // default-Setting |
181 | } |
195 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
Line 182... | Line 196... | ||
182 | SetActiveParamSetNumber(3); // default-Setting |
196 | } |
183 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
197 | |
184 | } |
198 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
Line 185... | Line 199... | ||
185 | 199 | { |
|
Line 186... | Line 200... | ||
186 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) { |
200 | printf("\n\rACC nicht abgeglichen!"); |
187 | printf("\n\rACC nicht abgeglichen!"); |
201 | } |
188 | } |
202 | |
189 | 203 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
|
- | 204 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
|
Line 190... | Line 205... | ||
190 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) & EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
205 | |
191 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
206 | |
192 | 207 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
|
193 | 208 | { |
|
194 | if (EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) { |
209 | printf("\n\rAbgleich Luftdrucksensor.."); |
195 | printf("\n\rAbgleich Luftdrucksensor.."); |
210 | timer = SetDelay(1000); |
196 | timer = SetDelay(1000); |
211 | SucheLuftruckOffset(); |
197 | SucheLuftruckOffset(); |
212 | while (!CheckDelay(timer)); |
198 | while (!CheckDelay(timer)); |
213 | printf("OK\n\r"); |
199 | printf("OK\n\r"); |
214 | } |
200 | } |
215 | |
- | 216 | SetNeutral(); |
|
201 | 217 | ||
202 | SetNeutral(); |
218 | ROT_OFF; |
203 | 219 | ||
204 | ROT_OFF; |
220 | beeptime = 2000; |
205 | 221 | ExternControl.Digital[0] = 0x55; |
|
206 | beeptime = 2000; |
222 | |
207 | ExternControl.Digital[0] = 0x55; |
223 | |
- | 224 | printf("\n\rSteuerung: "); |
|
208 | 225 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
|
209 | 226 | else printf("Neutral"); |
|
210 | printf("\n\rSteuerung: "); |
227 | |
- | 228 | printf("\n\n\r"); |
|
211 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
229 | |
212 | else printf("Neutral"); |
230 | LcdClear(); |
- | 231 | I2CTimeout = 5000; |
|
213 | 232 | WinkelOut.Orientation = 1; |
|
214 | printf("\n\n\r"); |
233 | while (1) |
- | 234 | { |
|
215 | 235 | ||
216 | LcdClear(); |
236 | if(UpdateMotor) // ReglerIntervall |
217 | I2CTimeout = 5000; |
237 | { |
218 | WinkelOut.Orientation = 1; |
238 | UpdateMotor=0; |
- | 239 | //PORTD |= 0x08; |
|
219 | while (1) { |
240 | if(WinkelOut.CalcState) CalMk3Mag(); |
220 | 241 | else MotorRegler(); |
|
- | 242 | //PORTD &= ~0x08; |
|
221 | if (UpdateMotor) // ReglerIntervall |
243 | SendMotorData(); |
222 | { |
244 | ROT_OFF; |
- | 245 | if(PcZugriff) PcZugriff--; |
|
223 | UpdateMotor = 0; |
246 | else |
- | 247 | { |
|
224 | //PORTD |= 0x08; |
248 | ExternControl.Config = 0; |
- | 249 | ExternStickNick = 0; |
|
225 | if (WinkelOut.CalcState) CalMk3Mag(); |
250 | ExternStickRoll = 0; |
226 | else MotorRegler(); |
251 | ExternStickGier = 0; |
227 | //PORTD &= ~0x08; |
252 | } |
228 | SendMotorData(); |
253 | if(SenderOkay) SenderOkay--; |
229 | ROT_OFF; |
254 | if(!I2CTimeout) |
230 | if (PcZugriff) PcZugriff--; |
255 | { |
231 | else { |
256 | I2CTimeout = 5; |
232 | ExternControl.Config = 0; |
257 | i2c_reset(); |
233 | ExternStickNick = 0; |
258 | if((BeepMuster == 0xffff) && MotorenEin) |
234 | ExternStickRoll = 0; |
259 | { |
235 | ExternStickGier = 0; |
260 | beeptime = 10000; |
236 | } |
261 | BeepMuster = 0x0080; |
Line 237... | Line 262... | ||
237 | if (SenderOkay) SenderOkay--; |
262 | } |
238 | if (!I2CTimeout) { |
263 | } |
239 | I2CTimeout = 5; |
264 | else |
240 | i2c_reset(); |
265 | { |
241 | if ((BeepMuster == 0xffff) && MotorenEin) { |
266 | I2CTimeout--; |
242 | beeptime = 10000; |
267 | ROT_OFF; |
243 | BeepMuster = 0x0080; |
- | |
244 | } |
268 | } |
245 | } else { |
- | |
246 | I2CTimeout--; |
269 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
247 | ROT_OFF; |
270 | { |
248 | } |
271 | DatenUebertragung(); |