Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1471 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
||
5 | * Copyright (C) 2011 Harald Bongartz * |
||
6 | * * |
||
7 | * This program is free software; you can redistribute it and/or modify * |
||
8 | * it under the terms of the GNU General Public License as published by * |
||
9 | * the Free Software Foundation; either version 2 of the License. * |
||
10 | * * |
||
11 | * This program is distributed in the hope that it will be useful, * |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
14 | * GNU General Public License for more details. * |
||
15 | * * |
||
16 | * You should have received a copy of the GNU General Public License * |
||
17 | * along with this program; if not, write to the * |
||
18 | * Free Software Foundation, Inc., * |
||
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
20 | * * |
||
21 | * * |
||
22 | * Credits to: * |
||
23 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
||
24 | * http://www.mikrokopter.de * |
||
25 | * Gregor "killagreg" Stobrawa for his version of the MK code * |
||
26 | * Thomas Kaiser "thkais" for the original project. See * |
||
27 | * http://www.ft-fanpage.de/mikrokopter/ * |
||
28 | * http://forum.mikrokopter.de/topic-4061-1.html * |
||
29 | * Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
||
30 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
31 | * Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
||
32 | *****************************************************************************/ |
||
33 | |||
34 | |||
35 | #include "cpu.h" |
||
36 | #include <avr/io.h> |
||
37 | #include <inttypes.h> |
||
38 | #include <stdlib.h> |
||
39 | #include <avr/pgmspace.h> |
||
40 | #include <avr/wdt.h> |
||
41 | #include <util/delay.h> |
||
42 | #include <avr/eeprom.h> |
||
43 | |||
44 | //************************************************************************************ |
||
45 | // Watchdog integrieren und abschalten, wird für Bootloader benötigt |
||
46 | // !!muss hier stehen bleiben!! |
||
47 | |||
48 | //-------------------------------------------------------------- |
||
49 | void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1"))); |
||
50 | |||
51 | //-------------------------------------------------------------- |
||
52 | void wdt_init(void) |
||
53 | { |
||
54 | MCUSR = 0; |
||
55 | wdt_disable(); |
||
56 | return; |
||
57 | } |
||
58 | |||
59 | //************************************************************************************ |
||
60 | // erst ab hier weitere #includes |
||
61 | |||
62 | |||
63 | #include "lipo.h" |
||
64 | #include "main.h" |
||
65 | #include "lcd.h" |
||
66 | #include "usart.h" |
||
67 | #include "uart1.h" |
||
68 | #include "mk-data-structs.h" |
||
69 | #include "parameter.h" |
||
70 | #include "menu.h" |
||
71 | #include "display.h" |
||
72 | #include "timer.h" |
||
73 | #include "eeprom.h" |
||
74 | #include "Wi232.h" |
||
75 | #include "twimaster.h" |
||
76 | #include "messages.h" |
||
77 | |||
78 | //#define MTEST 0 // Menu Test (skip FC/NC detection) |
||
79 | |||
80 | Version_t *version; |
||
81 | |||
82 | volatile uint8_t mode = 0; |
||
83 | uint8_t hardware = 0; |
||
84 | uint8_t current_hardware = 0; |
||
85 | mk_param_struct_t *mk_param_struct; |
||
86 | |||
87 | |||
88 | //-------------------------------------------------------------- |
||
89 | int main (void) |
||
90 | { |
||
91 | #ifndef DEBUG |
||
92 | uint8_t timeout; |
||
93 | uint8_t val =0; |
||
94 | uint8_t spalte =0; |
||
95 | #endif |
||
96 | |||
97 | InitHWPorts(); // Hardwareanhängige Ports konfigurieren |
||
98 | // dafür wird je nach Hardware die HAL_HWxxx verwendet |
||
99 | // Define dazu in der main.h |
||
100 | |||
101 | hardware = NO; |
||
102 | current_hardware = 0; |
||
103 | |||
104 | |||
105 | if (PKT_StartInfo == true) |
||
106 | { |
||
107 | lcd_cls (); |
||
108 | // lcd_printp_at (0,0,PSTR("Portables Kopter Tool"), 0); |
||
109 | lcd_puts_at(0, 0, strGet(START_MSG1), 0); |
||
110 | lcd_puts_at(0, 1, strGet(START_MSG2), 0); |
||
111 | // lcd_printp_at (0,1,PSTR("für FC Ver "), 0); |
||
112 | // lcd_printp_at (11,1,PSTR(FC_Version),0); |
||
113 | // lcd_printp_at (0,3,PSTR("GNU GPL License"), 0); |
||
114 | lcd_puts_at(0, 3, strGet(GNU_GPL), 0); |
||
115 | |||
116 | #ifdef HWVERSION1_2 |
||
117 | // lcd_printp_at (0,4,PSTR("Hardware 1.2"), 0); |
||
118 | // lcd_printp_at (0,5,PSTR("ATmega 644"), 0); |
||
119 | lcd_puts_at(0, 4, strGet(HW12), 0); |
||
120 | lcd_puts_at(0, 5, strGet(ATMEGA644), 0); |
||
121 | #endif |
||
122 | |||
123 | #ifdef HWVERSION1_2W |
||
124 | // lcd_printp_at (0,4,PSTR("Hardware 1.2W"), 0); |
||
125 | // lcd_printp_at (0,5,PSTR("ATmega 644"), 0); |
||
126 | lcd_puts_at(0, 4, strGet(HW12W), 0); |
||
127 | lcd_puts_at(0, 5, strGet(ATMEGA644), 0); |
||
128 | #endif |
||
129 | |||
130 | #ifdef HWVERSION1_3 |
||
131 | // lcd_printp_at (0,4,PSTR("Hardware 1.3"), 0); |
||
132 | // lcd_printp_at (0,5,PSTR("ATmega 644P"), 0); |
||
133 | lcd_puts_at(0, 4, strGet(HW13), 0); |
||
134 | lcd_puts_at(0, 5, strGet(ATMEGA644P), 0); |
||
135 | #endif |
||
136 | |||
137 | #ifdef HWVERSION1_3W |
||
138 | // lcd_printp_at (0,4,PSTR("Hardware 1.3W"), 0); |
||
139 | // lcd_printp_at (0,5,PSTR("ATmega 644P"), 0); |
||
140 | lcd_puts_at(0, 4, strGet(HW13W), 0); |
||
141 | lcd_puts_at(0, 5, strGet(ATMEGA644P), 0); |
||
142 | #endif |
||
143 | |||
144 | #ifdef HWVERSION3_9 |
||
145 | // lcd_printp_at (0,4,PSTR("Hardware 3.9"), 0); |
||
146 | // lcd_printp_at (0,5,PSTR("ATmega 1284P"), 0); |
||
147 | lcd_puts_at(0, 4, strGet(HW39), 0); |
||
148 | lcd_puts_at(0, 5, strGet(ATMEGA1284P), 0); |
||
149 | #endif |
||
150 | |||
151 | _delay_ms(1500); |
||
152 | } |
||
153 | |||
154 | #ifndef DEBUG |
||
155 | |||
156 | ReadLastPosition (); |
||
157 | |||
158 | if (LastLongitude>0x00000000 && LastLatitude>0x00000000) |
||
159 | { |
||
160 | // lcd_printp_at (0, 4, PSTR(" Letzte Position "), 2); |
||
161 | // lcd_printp_at (0, 5, PSTR(" Breitengr Längengr "), 2); |
||
162 | // lcd_printp_at (0, 7, PSTR("löschen weiter"), 0); |
||
163 | lcd_puts_at(0, 4, strGet(START_LASTPOS), 2); |
||
164 | lcd_puts_at(0, 5, strGet(START_LASTPOS1), 3); |
||
165 | lcd_puts_at(0, 7, strGet(START_LASTPOS2), 0); |
||
166 | |||
167 | |||
168 | write_ndigit_number_u (1, 6, (uint16_t)(LastLongitude/10000000), 2, 0); |
||
169 | lcd_printp_at (3, 6, PSTR("."), 0); |
||
170 | write_ndigit_number_u (4, 6, (uint16_t)((LastLongitude/1000) % 10000), 4, 1); |
||
171 | write_ndigit_number_u (8, 6, (uint16_t)((LastLongitude/10) % 100), 2, 1); |
||
172 | |||
173 | |||
174 | write_ndigit_number_u (12, 6, (uint16_t)(LastLatitude/10000000), 2, 0); |
||
175 | lcd_printp_at (14, 6, PSTR("."), 0); |
||
176 | write_ndigit_number_u (15, 6, (uint16_t)((LastLatitude/1000) % 10000), 4, 1); |
||
177 | write_ndigit_number_u (19, 6, (uint16_t)((LastLatitude/10) % 100), 2, 1); |
||
178 | |||
179 | for (;;) |
||
180 | { |
||
181 | if (get_key_press (1 << KEY_MINUS)) |
||
182 | { |
||
183 | WriteLastPosition(0x00000000,0x00000000); // Löschen |
||
184 | lcd_frect (0, (8*4), 128, 8, 0); // Zeile löschen (x, y, l, h, in Pixel) |
||
185 | lcd_frect (0, (8*5), 128, 8, 0); |
||
186 | // lcd_printp_at (0,5,PSTR(" gelöscht "), 0); |
||
187 | lcd_puts_at(0, 5, strGet(START_LASTPOSDEL), 0); |
||
188 | |||
189 | lcd_cls_line (0, 6, 21); |
||
190 | lcd_cls_line (0, 7, 21); |
||
191 | |||
192 | _delay_ms(1000); |
||
193 | break; |
||
194 | } |
||
195 | if (get_key_press (1 << KEY_ENTER)) |
||
196 | { |
||
197 | lcd_cls_line (0, 4, 21); |
||
198 | lcd_cls_line (0, 5, 21); |
||
199 | lcd_cls_line (0, 6, 21); |
||
200 | lcd_cls_line (0, 7, 21); |
||
201 | break; |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | #endif |
||
206 | |||
207 | // switch to NC |
||
208 | USART_putc (0x1b); |
||
209 | USART_putc (0x1b); |
||
210 | USART_putc (0x55); |
||
211 | USART_putc (0xaa); |
||
212 | USART_putc (0x00); |
||
213 | |||
214 | mode = 'V'; |
||
215 | |||
216 | #ifndef DEBUG |
||
217 | |||
218 | do |
||
219 | { |
||
220 | timeout = 50; |
||
221 | |||
222 | lcd_cls(); |
||
223 | // lcd_printp_at (0,4,PSTR("Suche FC..."), 0); |
||
224 | // lcd_printp_at (12, 7, PSTR("Ende"), 0); |
||
225 | lcd_puts_at(0, 4, strGet(START_SEARCHFC), 0); |
||
226 | lcd_puts_at(12, 7, strGet(ENDE), 0); |
||
227 | |||
228 | while (!rxd_buffer_locked && timeout) |
||
229 | { |
||
230 | SendOutData('v', ADDRESS_ANY, 0); |
||
231 | |||
232 | timer = 20; |
||
233 | |||
234 | while (timer > 0); |
||
235 | timeout--; |
||
236 | |||
237 | if (spalte <= 20) |
||
238 | { |
||
239 | lcd_printp_at (spalte,6,PSTR("?"),0); |
||
240 | spalte++; |
||
241 | } |
||
242 | else |
||
243 | { |
||
244 | lcd_cls_line (0,6,21); |
||
245 | spalte=0; |
||
246 | } |
||
247 | |||
248 | if (get_key_press (1 << KEY_ESC)) |
||
249 | { |
||
250 | get_key_press(KEY_ALL); |
||
251 | for (;;) |
||
252 | { |
||
253 | Debug = 0; |
||
254 | hardware = NO; |
||
255 | main_menu (); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | } |
||
260 | |||
261 | if(timeout == 0) |
||
262 | { |
||
263 | // lcd_printp_at (0,5,PSTR("FC nicht gefunden!"), 0); |
||
264 | lcd_puts_at(0, 5, strGet(START_FCNOTFOUND), 0); |
||
265 | timer = 90; |
||
266 | while (timer > 0); |
||
267 | } |
||
268 | } |
||
269 | while(timeout == 0); |
||
270 | |||
271 | if (timeout != 0) |
||
272 | Decode64 (); |
||
273 | |||
274 | version = (Version_t *) pRxData; |
||
275 | |||
276 | if (PKT_StartInfo == true) |
||
277 | { |
||
278 | lcd_cls (); |
||
279 | // lcd_printp (PSTR("PKT-Tool GNU GPL\r\n"), 0); |
||
280 | // lcd_printp (PSTR("gefunden:\r\n\n"), 0); |
||
281 | lcd_puts_at(0, 0, strGet(START_FCFOUND), 0); |
||
282 | lcd_puts_at(0, 1, strGet(START_FCFOUND1), 0); |
||
283 | |||
284 | } |
||
285 | |||
286 | if ((rxd_buffer[1] - 'a') == ADDRESS_FC) |
||
287 | { |
||
288 | if (PKT_StartInfo == true) |
||
289 | { |
||
290 | // lcd_printp (PSTR("Flight-Ctrl\r\n"), 0); |
||
291 | lcd_puts_at(0, 1, strGet(START_FCFOUND2), 0); |
||
292 | } |
||
293 | hardware = FC; |
||
294 | current_hardware = hardware; |
||
295 | } |
||
296 | else if ((rxd_buffer[1] - 'a') == ADDRESS_NC) |
||
297 | { |
||
298 | if (PKT_StartInfo == true) |
||
299 | { |
||
300 | // lcd_printp (PSTR("Navi-Ctrl\r\n"), 0); |
||
301 | lcd_puts_at(0, 1, strGet(START_FCFOUND3), 0); |
||
302 | } |
||
303 | hardware = NC; |
||
304 | current_hardware = hardware; |
||
305 | } |
||
306 | |||
307 | if (PKT_StartInfo == true) |
||
308 | { |
||
309 | // lcd_printp (PSTR("Version: "), 0); |
||
310 | lcd_puts_at(0, 2, strGet(START_VERSIONCHECK), 0); |
||
311 | lcd_write_number_u (version->SWMajor); |
||
312 | lcd_printp (PSTR("."), 0); |
||
313 | lcd_write_number_u (version->SWMinor); |
||
314 | lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0); |
||
315 | _delay_ms(1500); |
||
316 | } |
||
317 | SwitchToFC(); |
||
318 | #else |
||
319 | if (PKT_StartInfo == true) |
||
320 | { |
||
321 | lcd_cls (); |
||
322 | lcd_printp (PSTR("PKT-Test DEBUG\r\n"), 0); |
||
323 | _delay_ms(1500); |
||
324 | } |
||
325 | |||
326 | #endif |
||
327 | |||
328 | |||
329 | #ifndef DEBUG |
||
330 | |||
331 | // EEprom Version / Struktur prüfen |
||
332 | // val = load_setting(1); // Parameterset 1 holen |
||
333 | val = load_setting(0xff); // aktuelles Parameterset holen |
||
334 | if (mk_param_struct->Revision != EEProm_Version) |
||
335 | { |
||
336 | lcd_cls (); |
||
337 | |||
338 | |||
339 | lcd_printp_at (0, 0, PSTR("EEPromRev.:"), 0); |
||
340 | lcd_write_number_u (EEProm_Version); |
||
341 | |||
342 | lcd_puts_at(0, 1, strGet(START_VERSIONCHECK1), 0); |
||
343 | // lcd_printp (PSTR(" erwartet\r\n"), 0); |
||
344 | |||
345 | lcd_printp_at (0, 1, PSTR("EEPromRev.:"), 0); |
||
346 | lcd_write_number_u (mk_param_struct->Revision); |
||
347 | lcd_puts_at(0, 2, strGet(START_VERSIONCHECK2), 0); |
||
348 | |||
349 | // lcd_printp (PSTR(" gefunden\r\n"), 0); |
||
350 | |||
351 | // lcd_printp (PSTR("PKT-Tool nur mit\r\n"), 0); |
||
352 | // lcd_printp (PSTR("FC Software "), 0); |
||
353 | lcd_puts_at(0, 3, strGet(START_VERSIONCHECK3), 0); |
||
354 | lcd_puts_at(0, 4, strGet(START_VERSIONCHECK4), 0); |
||
355 | |||
356 | lcd_printp (PSTR(FC_Version),0); |
||
357 | |||
358 | // lcd_printp (PSTR("\r\nkompatibel"), 0); |
||
359 | lcd_puts_at(0, 5, strGet(START_VERSIONCHECK5), 0); |
||
360 | hardware = NO; |
||
361 | BeepTime = 1500; |
||
362 | BeepMuster = 0x0040; |
||
363 | _delay_ms(4000); |
||
364 | } |
||
365 | |||
366 | #endif |
||
367 | mode = 0; |
||
368 | rxd_buffer_locked = FALSE; |
||
369 | |||
370 | timer = 50; |
||
371 | while (timer > 0); |
||
372 | |||
373 | for (;;) |
||
374 | { |
||
375 | main_menu (); |
||
376 | } |
||
377 | } |
||
378 |