Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1734 | - | 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 | |||
68 | #include "uart1.h" |
||
69 | #include "mk-data-structs.h" |
||
70 | #include "parameter.h" |
||
71 | #include "menu.h" |
||
72 | #include "display.h" |
||
73 | #include "timer.h" |
||
74 | #include "eeprom.h" |
||
75 | #include "Wi232.h" |
||
76 | #include "twimaster.h" |
||
77 | #include "messages.h" |
||
78 | |||
79 | //#define MTEST 0 // Menu Test (skip FC/NC detection) |
||
80 | |||
81 | Version_t *version; |
||
82 | |||
83 | volatile uint8_t mode = 0; |
||
84 | uint8_t hardware = 0; |
||
85 | uint8_t current_hardware = 0; |
||
86 | mk_param_struct_t *mk_param_struct; |
||
87 | |||
88 | |||
89 | //-------------------------------------------------------------- |
||
90 | int main (void) |
||
91 | { |
||
92 | #ifndef DEBUG |
||
93 | uint8_t timeout; |
||
94 | uint8_t val =0; |
||
95 | uint8_t spalte =0; |
||
96 | #endif |
||
97 | |||
98 | InitHWPorts(); // Hardwareanhängige Ports konfigurieren |
||
99 | // dafür wird je nach Hardware die HAL_HWxxx verwendet |
||
100 | // Define dazu in der main.h |
||
101 | |||
102 | hardware = NO; |
||
103 | current_hardware = 0; |
||
104 | |||
105 | |||
106 | if (PKT_StartInfo == true) |
||
107 | { |
||
108 | lcd_cls (); |
||
109 | // lcd_printp_at (0,0,PSTR("Portables Kopter Tool"), 0); |
||
110 | lcd_puts_at(0, 0, strGet(START_MSG1), 0); |
||
111 | lcd_puts_at(0, 1, strGet(START_MSG2), 0); |
||
112 | // lcd_printp_at (0,1,PSTR("für FC Ver "), 0); |
||
113 | // lcd_printp_at (11,1,PSTR(FC_Version),0); |
||
114 | // lcd_printp_at (0,3,PSTR("GNU GPL License"), 0); |
||
115 | lcd_puts_at(0, 3, strGet(GNU_GPL), 0); |
||
116 | |||
117 | #ifdef HWVERSION1_2 |
||
118 | // lcd_printp_at (0,4,PSTR("Hardware 1.2"), 0); |
||
119 | // lcd_printp_at (0,5,PSTR("ATmega 644"), 0); |
||
120 | lcd_puts_at(0, 4, strGet(HW12), 0); |
||
121 | lcd_puts_at(0, 5, strGet(ATMEGA644), 0); |
||
122 | #endif |
||
123 | |||
124 | #ifdef HWVERSION1_2W |
||
125 | // lcd_printp_at (0,4,PSTR("Hardware 1.2W"), 0); |
||
126 | // lcd_printp_at (0,5,PSTR("ATmega 644"), 0); |
||
127 | lcd_puts_at(0, 4, strGet(HW12W), 0); |
||
128 | lcd_puts_at(0, 5, strGet(ATMEGA644), 0); |
||
129 | #endif |
||
130 | |||
131 | #ifdef HWVERSION1_3 |
||
132 | // lcd_printp_at (0,4,PSTR("Hardware 1.3"), 0); |
||
133 | // lcd_printp_at (0,5,PSTR("ATmega 644P"), 0); |
||
134 | lcd_puts_at(0, 4, strGet(HW13), 0); |
||
135 | lcd_puts_at(0, 5, strGet(ATMEGA644P), 0); |
||
136 | #endif |
||
137 | |||
138 | #ifdef HWVERSION1_3W |
||
139 | // lcd_printp_at (0,4,PSTR("Hardware 1.3W"), 0); |
||
140 | // lcd_printp_at (0,5,PSTR("ATmega 644P"), 0); |
||
141 | lcd_puts_at(0, 4, strGet(HW13W), 0); |
||
142 | lcd_puts_at(0, 5, strGet(ATMEGA644P), 0); |
||
143 | #endif |
||
144 | |||
145 | #ifdef HWVERSION3_9 |
||
146 | // lcd_printp_at (0,4,PSTR("Hardware 3.9"), 0); |
||
147 | // lcd_printp_at (0,5,PSTR("ATmega 1284P"), 0); |
||
148 | lcd_puts_at(0, 4, strGet(HW39), 0); |
||
149 | lcd_puts_at(0, 5, strGet(ATMEGA1284P), 0); |
||
150 | #endif |
||
151 | |||
152 | _delay_ms(1500); |
||
153 | } |
||
154 | |||
155 | #ifndef DEBUG |
||
156 | |||
157 | ReadLastPosition (); |
||
158 | |||
159 | if (LastLongitude>0x00000000 && LastLatitude>0x00000000) |
||
160 | { |
||
161 | lcd_cls (); |
||
162 | // lcd_printp_at (0, 4, PSTR(" Letzte Position "), 2); |
||
163 | // lcd_printp_at (0, 5, PSTR(" Breitengr Längengr "), 2); |
||
164 | // lcd_printp_at (0, 7, PSTR("löschen weiter"), 0); |
||
165 | lcd_puts_at(0, 0, strGet(START_LASTPOS), 2); |
||
166 | lcd_puts_at(0, 1, strGet(START_LASTPOS3), 2); |
||
167 | lcd_puts_at(0, 2, strGet(START_LASTPOS1), 2); |
||
168 | lcd_puts_at(0, 7, strGet(START_LASTPOS2), 0); |
||
169 | |||
170 | |||
171 | write_ndigit_number_u (1, 4, (uint16_t)(LastLatitude/10000000), 2, 0,0); |
||
172 | lcd_printp_at (3, 4, PSTR("."), 0); |
||
173 | write_ndigit_number_u (4, 4, (uint16_t)((LastLatitude/1000) % 10000), 4, 1,0); |
||
174 | write_ndigit_number_u (8, 4, (uint16_t)((LastLatitude/10) % 100), 2, 1,0); |
||
175 | |||
176 | |||
177 | write_ndigit_number_u (12, 4, (uint16_t)(LastLongitude/10000000), 2, 0,0); |
||
178 | lcd_printp_at (14, 4, PSTR("."), 0); |
||
179 | write_ndigit_number_u (15, 4, (uint16_t)((LastLongitude/1000) % 10000), 4, 1,0); |
||
180 | write_ndigit_number_u (19, 4, (uint16_t)((LastLongitude/10) % 100), 2, 1,0); |
||
181 | |||
182 | for (;;) |
||
183 | { |
||
184 | if (get_key_press (1 << KEY_MINUS)) |
||
185 | { |
||
186 | WriteLastPosition(0x00000000,0x00000000); // Löschen |
||
187 | lcd_frect (0, (8*4), 128, 8, 0); // Zeile löschen (x, y, l, h, in Pixel) |
||
188 | lcd_frect (0, (8*5), 128, 8, 0); |
||
189 | // lcd_printp_at (0,5,PSTR(" gelöscht "), 0); |
||
190 | lcd_puts_at(0, 5, strGet(START_LASTPOSDEL), 0); |
||
191 | |||
192 | lcd_cls_line (0, 6, 21); |
||
193 | lcd_cls_line (0, 7, 21); |
||
194 | |||
195 | _delay_ms(1000); |
||
196 | break; |
||
197 | } |
||
198 | if (get_key_press (1 << KEY_ENTER)) |
||
199 | { |
||
200 | lcd_cls_line (0, 4, 21); |
||
201 | lcd_cls_line (0, 5, 21); |
||
202 | lcd_cls_line (0, 6, 21); |
||
203 | lcd_cls_line (0, 7, 21); |
||
204 | break; |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | #endif |
||
209 | |||
210 | // switch to NC |
||
211 | USART_putc (0x1b); |
||
212 | USART_putc (0x1b); |
||
213 | USART_putc (0x55); |
||
214 | USART_putc (0xaa); |
||
215 | USART_putc (0x00); |
||
216 | |||
217 | mode = 'V'; |
||
218 | |||
219 | #ifndef DEBUG |
||
220 | |||
221 | do |
||
222 | { |
||
223 | timeout = 50; |
||
224 | |||
225 | lcd_cls(); |
||
226 | // lcd_printp_at (0,4,PSTR("Suche FC..."), 0); |
||
227 | // lcd_printp_at (12, 7, PSTR("Ende"), 0); |
||
228 | lcd_puts_at(0, 4, strGet(START_SEARCHFC), 0); |
||
229 | lcd_puts_at(12, 7, strGet(ENDE), 0); |
||
230 | |||
231 | while (!rxd_buffer_locked && timeout) |
||
232 | { |
||
233 | SendOutData('v', ADDRESS_ANY, 0); |
||
234 | |||
235 | timer = 20; |
||
236 | |||
237 | while (timer > 0); |
||
238 | timeout--; |
||
239 | |||
240 | if (spalte <= 20) |
||
241 | { |
||
242 | lcd_printp_at (spalte,6,PSTR("?"),0); |
||
243 | spalte++; |
||
244 | } |
||
245 | else |
||
246 | { |
||
247 | lcd_cls_line (0,6,21); |
||
248 | spalte=0; |
||
249 | } |
||
250 | |||
251 | if (get_key_press (1 << KEY_ESC)) |
||
252 | { |
||
253 | get_key_press(KEY_ALL); |
||
254 | for (;;) |
||
255 | { |
||
256 | Debug = 0; |
||
257 | hardware = NO; |
||
258 | main_menu (); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | } |
||
263 | |||
264 | if(timeout == 0) |
||
265 | { |
||
266 | // lcd_printp_at (0,5,PSTR("FC nicht gefunden!"), 0); |
||
267 | lcd_puts_at(0, 5, strGet(START_FCNOTFOUND), 0); |
||
268 | timer = 90; |
||
269 | while (timer > 0); |
||
270 | } |
||
271 | } |
||
272 | while(timeout == 0); |
||
273 | |||
274 | if (timeout != 0) |
||
275 | Decode64 (); |
||
276 | |||
277 | version = (Version_t *) pRxData; |
||
278 | |||
279 | if (PKT_StartInfo == true) |
||
280 | { |
||
281 | lcd_cls (); |
||
282 | // lcd_printp (PSTR("PKT-Tool GNU GPL\r\n"), 0); |
||
283 | // lcd_printp (PSTR("gefunden:\r\n\n"), 0); |
||
284 | lcd_puts_at(0, 0, strGet(START_FCFOUND), 0); |
||
285 | lcd_puts_at(0, 1, strGet(START_FCFOUND1), 0); |
||
286 | |||
287 | } |
||
288 | |||
289 | if ((rxd_buffer[1] - 'a') == ADDRESS_FC) |
||
290 | { |
||
291 | if (PKT_StartInfo == true) |
||
292 | { |
||
293 | // lcd_printp (PSTR("Flight-Ctrl\r\n"), 0); |
||
294 | lcd_puts_at(0, 2, strGet(START_FCFOUND2), 0); |
||
295 | } |
||
296 | hardware = FC; |
||
297 | current_hardware = hardware; |
||
298 | } |
||
299 | else if ((rxd_buffer[1] - 'a') == ADDRESS_NC) |
||
300 | { |
||
301 | if (PKT_StartInfo == true) |
||
302 | { |
||
303 | // lcd_printp (PSTR("Navi-Ctrl\r\n"), 0); |
||
304 | lcd_puts_at(0, 2, strGet(START_FCFOUND3), 0); |
||
305 | } |
||
306 | hardware = NC; |
||
307 | current_hardware = hardware; |
||
308 | } |
||
309 | |||
310 | if (PKT_StartInfo == true) |
||
311 | { |
||
312 | // lcd_printp (PSTR("Version: "), 0); |
||
313 | lcd_puts_at(0, 3, strGet(START_VERSIONCHECK), 0); |
||
314 | lcd_write_number_u_at (9, 3, version->SWMajor); |
||
315 | lcd_printp_at (10,3,PSTR("."), 0); |
||
316 | lcd_write_number_u_at (11,3,version->SWMinor); |
||
317 | lcd_write_number_u_at (14,3, version->SWPatch + 'a'); |
||
318 | _delay_ms(2500); |
||
319 | } |
||
320 | SwitchToFC(); |
||
321 | #else |
||
322 | if (PKT_StartInfo == true) |
||
323 | { |
||
324 | lcd_cls (); |
||
325 | lcd_printp (PSTR("PKT-Test DEBUG\r\n"), 0); |
||
326 | _delay_ms(1500); |
||
327 | } |
||
328 | |||
329 | #endif |
||
330 | |||
331 | |||
332 | #ifndef DEBUG |
||
333 | |||
334 | // EEprom Version / Struktur prüfen |
||
335 | // val = load_setting(1); // Parameterset 1 holen |
||
336 | val = load_setting(0xff); // aktuelles Parameterset holen |
||
337 | if (mk_param_struct->Revision != EEProm_Version) |
||
338 | { |
||
339 | lcd_cls (); |
||
340 | |||
341 | lcd_printp_at (0, 0, PSTR("EEPromRev "), 0); |
||
342 | lcd_write_number_u (EEProm_Version); |
||
343 | |||
344 | lcd_puts_at(13, 0, strGet(START_VERSIONCHECK1), 0); |
||
345 | // lcd_printp (PSTR("erwartet\r\n"), 0); |
||
346 | |||
347 | lcd_printp_at (0, 2, PSTR("EEPromRev "), 0); |
||
348 | lcd_write_number_u (mk_param_struct->Revision); |
||
349 | |||
350 | lcd_puts_at(13, 2, strGet(START_VERSIONCHECK2), 0); |
||
351 | // lcd_printp (PSTR(" gefunden\r\n"), 0); |
||
352 | |||
353 | // lcd_printp (PSTR("PKT-Tool nur mit\r\n"), 0); |
||
354 | // lcd_printp (PSTR("FC Software "), 0); |
||
355 | lcd_puts_at(0, 4, strGet(START_VERSIONCHECK3), 0); |
||
356 | lcd_puts_at(0, 5, strGet(START_VERSIONCHECK4), 0); |
||
357 | |||
358 | // lcd_printp (PSTR(FC_Version), 0); |
||
359 | lcd_printp_at (12, 5, PSTR(FC_Version), 0); |
||
360 | |||
361 | // lcd_printp (PSTR("\r\nkompatibel"), 0); |
||
362 | lcd_puts_at(0, 6, strGet(START_VERSIONCHECK5), 0); |
||
363 | hardware = NO; |
||
364 | set_beep ( 1500, 0x0040, BeepNormal); |
||
365 | |||
366 | _delay_ms(4000); |
||
367 | } |
||
368 | |||
369 | #endif |
||
370 | mode = 0; |
||
371 | rxd_buffer_locked = FALSE; |
||
372 | |||
373 | timer = 50; |
||
374 | while (timer > 0); |
||
375 | |||
376 | for (;;) |
||
377 | { |
||
378 | main_menu (); |
||
379 | } |
||
380 | } |
||
381 |